diff --git a/fuzz/fuzz_targets/iommu.rs b/fuzz/fuzz_targets/iommu.rs index a93097d6c..8c9f26b26 100644 --- a/fuzz/fuzz_targets/iommu.rs +++ b/fuzz/fuzz_targets/iommu.rs @@ -66,6 +66,7 @@ fuzz_target!(|bytes: &[u8]| -> Corpus { SeccompAction::Allow, EventFd::new(EFD_NONBLOCK).unwrap(), ((MEM_SIZE - IOVA_SPACE_SIZE) as u64, (MEM_SIZE - 1) as u64), + 64, None, ) .unwrap(); diff --git a/virtio-devices/src/iommu.rs b/virtio-devices/src/iommu.rs index cd2e8efc6..0b8309a92 100644 --- a/virtio-devices/src/iommu.rs +++ b/virtio-devices/src/iommu.rs @@ -906,9 +906,10 @@ impl Iommu { seccomp_action: SeccompAction, exit_evt: EventFd, msi_iova_space: (u64, u64), + address_width_bits: u8, state: Option, ) -> io::Result<(Self, Arc)> { - let (avail_features, acked_features, endpoints, domains, paused) = + let (mut avail_features, acked_features, endpoints, domains, paused) = if let Some(state) = state { info!("Restoring virtio-iommu {}", id); ( @@ -939,12 +940,20 @@ impl Iommu { (avail_features, 0, BTreeMap::new(), BTreeMap::new(), false) }; - let config = VirtioIommuConfig { + let mut config = VirtioIommuConfig { page_size_mask: VIRTIO_IOMMU_PAGE_SIZE_MASK, probe_size: PROBE_PROP_SIZE, ..Default::default() }; + if address_width_bits < 64 { + avail_features |= 1u64 << VIRTIO_IOMMU_F_INPUT_RANGE; + config.input_range = VirtioIommuRange64 { + start: 0, + end: (1u64 << address_width_bits) - 1, + } + } + let mapping = Arc::new(IommuMapping { endpoints: Arc::new(RwLock::new(endpoints)), domains: Arc::new(RwLock::new(domains)), diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index e2ac0d236..830590b4f 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -100,7 +100,8 @@ use crate::pci_segment::PciSegment; use crate::serial_manager::{Error as SerialManagerError, SerialManager}; use crate::vm_config::{ ConsoleOutputMode, DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig, - VdpaConfig, VhostMode, VmConfig, VsockConfig, DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT, + VdpaConfig, VhostMode, VmConfig, VsockConfig, DEFAULT_IOMMU_ADDRESS_WIDTH_BITS, + DEFAULT_PCI_SEGMENT_APERTURE_WEIGHT, }; use crate::{device_node, GuestRegionMmap, PciDeviceInfo, DEVICE_MANAGER_SNAPSHOT_ID}; @@ -1365,6 +1366,13 @@ impl DeviceManager { ) -> DeviceManagerResult<()> { let iommu_id = String::from(IOMMU_DEVICE_NAME); + let iommu_address_width_bits = + if let Some(ref platform) = self.config.lock().unwrap().platform { + platform.iommu_address_width_bits + } else { + DEFAULT_IOMMU_ADDRESS_WIDTH_BITS + }; + let iommu_device = if self.config.lock().unwrap().iommu { let (device, mapping) = virtio_devices::Iommu::new( iommu_id.clone(), @@ -1373,6 +1381,7 @@ impl DeviceManager { .try_clone() .map_err(DeviceManagerError::EventFd)?, self.get_msi_iova_space(), + iommu_address_width_bits, state_from_id(self.snapshot.as_ref(), iommu_id.as_str()) .map_err(DeviceManagerError::RestoreGetState)?, )