From 5668f02eb6aabe2ef8c8fa6841259212b178cfef Mon Sep 17 00:00:00 2001 From: Andrew Carp Date: Thu, 21 Mar 2024 16:22:31 -0700 Subject: [PATCH] virtio-devices: Map previously attached endpoints Ensures that any endpoints already attached to the domain are properly mapped to a new endpoint on said endpoint's attach request. This is done by search for all previous mappings in the domain and then issuing map requests for the newly attached endpoint. Signed-off-by: Andrew Carp --- virtio-devices/src/iommu.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index e3db1662a..b5de6f274 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -414,6 +414,19 @@ impl Request { .unwrap() .insert(endpoint, domain_id); + // If any other mappings exist in the domain for other containers, + // make sure to issue these mappings for the new endpoint/container + if let Some(domain_mappings) = &mapping.domains.read().unwrap().get(&domain_id) + { + if let Some(ext_map) = ext_mapping.get(&endpoint) { + for (virt_start, addr_map) in &domain_mappings.mappings { + ext_map + .map(*virt_start, addr_map.gpa, addr_map.size) + .map_err(Error::ExternalUnmapping)?; + } + } + } + // Add new domain with no mapping if the entry didn't exist yet let mut domains = mapping.domains.write().unwrap(); let domain = Domain {