From 9ebb1a55bc92ecf2bd8dd2b2981f09841871d8d6 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 2 Oct 2019 11:18:39 -0700 Subject: [PATCH] vm-virtio: Add IOMMU support to virtio-blk Adding virtio feature VIRTIO_F_IOMMU_PLATFORM when explicitly asked by the user. The need for this feature is to be able to attach the virtio device to a virtual IOMMU. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/block.rs | 5 +++++ vmm/src/device_manager.rs | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/vm-virtio/src/block.rs b/vm-virtio/src/block.rs index 80927078c..b4271584b 100755 --- a/vm-virtio/src/block.rs +++ b/vm-virtio/src/block.rs @@ -503,6 +503,7 @@ impl Block { mut disk_image: T, disk_path: PathBuf, is_disk_read_only: bool, + iommu: bool, ) -> io::Result> { let disk_size = disk_image.seek(SeekFrom::End(0))? as u64; if disk_size % SECTOR_SIZE != 0 { @@ -515,6 +516,10 @@ impl Block { let mut avail_features = (1u64 << VIRTIO_F_VERSION_1) | (1u64 << VIRTIO_BLK_F_FLUSH); + if iommu { + avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM; + } + if is_disk_read_only { avail_features |= 1u64 << VIRTIO_BLK_F_RO; }; diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 62c9151a0..cf5504d4c 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -580,15 +580,17 @@ impl DeviceManager { let block = match image_type { ImageType::Raw => { let raw_img = vm_virtio::RawFile::new(raw_img); - let dev = vm_virtio::Block::new(raw_img, disk_cfg.path.clone(), false) - .map_err(DeviceManagerError::CreateVirtioBlock)?; + let dev = + vm_virtio::Block::new(raw_img, disk_cfg.path.clone(), false, false) + .map_err(DeviceManagerError::CreateVirtioBlock)?; Box::new(dev) as Box } ImageType::Qcow2 => { let qcow_img = QcowFile::from(raw_img) .map_err(DeviceManagerError::QcowDeviceCreate)?; - let dev = vm_virtio::Block::new(qcow_img, disk_cfg.path.clone(), false) - .map_err(DeviceManagerError::CreateVirtioBlock)?; + let dev = + vm_virtio::Block::new(qcow_img, disk_cfg.path.clone(), false, false) + .map_err(DeviceManagerError::CreateVirtioBlock)?; Box::new(dev) as Box } };