From e9b1ad955875195768a2d001a91d5c06524d8098 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 4 Apr 2022 16:23:49 +0200 Subject: [PATCH] virtio-devices: iommu: Fix list of external mappings In case an external mapping would have been added after the virtio-iommu device has been activated, it would have simply be ignored because the code wasn't using a shared object between the vmm thread and the iommu thread. This behavior is only triggered on the hotplug codepath, and only if the hotplugged device is placed behind the virtual IOMMU. Signed-off-by: Sebastien Boeuf --- virtio-devices/src/iommu.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index e59683f65..25f513fde 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -20,7 +20,7 @@ use std::ops::Bound::Included; use std::os::unix::io::AsRawFd; use std::result; use std::sync::atomic::AtomicBool; -use std::sync::{Arc, Barrier, RwLock}; +use std::sync::{Arc, Barrier, Mutex, RwLock}; use versionize::{VersionMap, Versionize, VersionizeResult}; use versionize_derive::Versionize; use virtio_queue::{DescriptorChain, Queue}; @@ -572,7 +572,7 @@ struct IommuEpollHandler { kill_evt: EventFd, pause_evt: EventFd, mapping: Arc, - ext_mapping: BTreeMap>, + ext_mapping: Arc>>>, ext_domain_mapping: BTreeMap>, msi_iova_space: (u64, u64), } @@ -585,7 +585,7 @@ impl IommuEpollHandler { let len = match Request::parse( &mut desc_chain, &self.mapping, - &self.ext_mapping, + &self.ext_mapping.lock().unwrap(), &mut self.ext_domain_mapping, self.msi_iova_space, ) { @@ -751,7 +751,7 @@ pub struct Iommu { id: String, config: VirtioIommuConfig, mapping: Arc, - ext_mapping: BTreeMap>, + ext_mapping: Arc>>>, seccomp_action: SeccompAction, exit_evt: EventFd, msi_iova_space: (u64, u64), @@ -799,7 +799,7 @@ impl Iommu { }, config, mapping: mapping.clone(), - ext_mapping: BTreeMap::new(), + ext_mapping: Arc::new(Mutex::new(BTreeMap::new())), seccomp_action, exit_evt, msi_iova_space, @@ -845,7 +845,7 @@ impl Iommu { } pub fn add_external_mapping(&mut self, device_id: u32, mapping: Arc) { - self.ext_mapping.insert(device_id, mapping); + self.ext_mapping.lock().unwrap().insert(device_id, mapping); } }