Skip to content

Commit 848cd72

Browse files
committed
vmm: fix dma map when add-device after removing all vfio devices
Now cloud hypervisor do vfio dma map only when first vfio container created, this can be problematic in some cases. When remove-device VfioDevice::drop() will be called, which will call VFIO_GROUP_UNSET_CONTAINER ioctl. The vfio kernel driver detach vfio group and will unpin and unmap all guest memory when group_list is empty which means the last vfio device is removed. At this time if a new vfio device is added cloud hypervisor will not do dma map again and dma access will fail. Signed-off-by: Yi Wang <foxywang@tencent.com>
1 parent 10fb713 commit 848cd72

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ linux-loader = { git = "https://github.com/rust-vmm/linux-loader", branch = "mai
114114
mshv-bindings = "0.6.0"
115115
mshv-ioctls = "0.6.0"
116116
seccompiler = "0.5.0"
117-
vfio-bindings = { version = "0.6.0", default-features = false }
118-
vfio-ioctls = { version = "0.5.1", default-features = false }
119-
vfio_user = { version = "0.1.1", default-features = false }
117+
vfio-bindings = { git = "https://github.com/up2wing/vfio.git", branch = "group-ref", default-features = false }
118+
vfio-ioctls = { git = "https://github.com/up2wing/vfio.git", branch = "group-ref", default-features = false }
119+
vfio_user = { git = "https://github.com/up2wing/vfio.git", branch = "group-ref", default-features = false }
120120
vhost = { version = "0.14.0", default-features = false }
121121
vhost-user-backend = { version = "0.20.0", default-features = false }
122122
virtio-bindings = "0.2.6"

vmm/src/device_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,7 @@ impl DeviceManager {
37423742
let vfio_device = VfioDevice::new(&device_cfg.path, Arc::clone(&vfio_container))
37433743
.map_err(DeviceManagerError::VfioCreate)?;
37443744

3745-
if needs_dma_mapping {
3745+
if needs_dma_mapping || 1 == vfio_container.vfio_group_num() {
37463746
// Register DMA mapping in IOMMU.
37473747
// Do not register virtio-mem regions, as they are handled directly by
37483748
// virtio-mem device itself.

0 commit comments

Comments
 (0)