dragonball: Adapt VFIO DMA calls to vfio-ioctls 0.6 API

The vfio-ioctls 0.6.0 crate changed the vfio_dma_map signature: the
host address parameter is now a raw pointer (*mut u8) instead of u64,
and the size parameter is usize instead of u64. Since the kernel uses
the host address to set up DMA mappings to physical memory — and the
caller must guarantee the memory behind that pointer remains valid for
the lifetime of the mapping — upstream marked vfio_dma_map as unsafe fn.

Wrap vfio_dma_map calls in unsafe blocks and adjust the type casts
accordingly. vfio_dma_unmap only needed the usize cast for the size
parameter (it does not take a host address, so it remains safe).

Bump workspace dependencies:
- vfio-bindings 0.6.1 -> 0.6.2
- vfio-ioctls 0.5.0 -> 0.6.0

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
This commit is contained in:
Alex Lyn
2026-04-12 16:01:19 +02:00
committed by Fabiano Fidêncio
parent f3f316966d
commit 4805eb2ec3
4 changed files with 386 additions and 242 deletions

586
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -77,8 +77,8 @@ kvm-bindings = "0.14.0"
kvm-ioctls = "0.24.0"
linux-loader = "0.13.0"
seccompiler = "0.5.0"
vfio-bindings = "0.6.1"
vfio-ioctls = "0.5.0"
vfio-bindings = "0.6.2"
vfio-ioctls = "0.6.0"
virtio-bindings = "0.2.0"
virtio-queue = "0.17.0"
vm-fdt = "0.3.0"

View File

@@ -706,11 +706,13 @@ impl Region {
// FIXME: add readonly flag into vfio_dma_map in future PR when it is needed.
// issue #8725
if let Err(e) = vfio_container.vfio_dma_map(
self.start.raw_value() + self.mmaps[i].mmap_offset,
self.mmaps[i].mmap_size,
host_addr as u64,
) {
if let Err(e) = unsafe {
vfio_container.vfio_dma_map(
self.start.raw_value() + self.mmaps[i].mmap_offset,
self.mmaps[i].mmap_size as usize,
host_addr as *mut u8,
)
} {
error!("vfio dma map failed, pci p2p dma may not work, due to {e:?}");
}
}
@@ -744,7 +746,7 @@ impl Region {
if let Err(e) = vfio_container.vfio_dma_unmap(
self.start.raw_value() + self.mmaps[i].mmap_offset,
self.mmaps[i].mmap_size,
self.mmaps[i].mmap_size as usize,
) {
error!("vfio dma unmap failed, pci p2p dma may not work, due to {e:?}");
}
@@ -771,7 +773,7 @@ impl Region {
for i in 0..self.mmaps.len() {
if let Err(e) = vfio_container.vfio_dma_unmap(
self.start.raw_value() + self.mmaps[i].mmap_offset,
self.mmaps[i].mmap_size,
self.mmaps[i].mmap_size as usize,
) {
error!("vfio dma unmap failed, pci p2p dma may not work, due to {e:?}");
}
@@ -779,11 +781,13 @@ impl Region {
self.set_user_memory_region(i, true, vm)?;
// FIXME: add readonly flag into vfio_dma_map in future PR when it is needed.
// issue #8725
if let Err(e) = vfio_container.vfio_dma_map(
self.start.raw_value() + self.mmaps[i].mmap_offset,
self.mmaps[i].mmap_size,
self.mmaps[i].mmap_host_addr,
) {
if let Err(e) = unsafe {
vfio_container.vfio_dma_map(
self.start.raw_value() + self.mmaps[i].mmap_offset,
self.mmaps[i].mmap_size as usize,
self.mmaps[i].mmap_host_addr as *mut u8,
)
} {
error!("vfio dma map failed, pci p2p dma may not work, due to {e:?}");
}
}

View File

@@ -499,9 +499,11 @@ impl VfioDeviceMgr {
"readonly" => readonly,
);
//FIXME: add readonly flag when related commit is pushed to upstream vfio-ioctls
self.get_vfio_container()?
.vfio_dma_map(iova, size, user_addr)
.map_err(VfioDeviceError::VfioIoctlError)?;
unsafe {
self.get_vfio_container()?
.vfio_dma_map(iova, size as usize, user_addr as *mut u8)
}
.map_err(VfioDeviceError::VfioIoctlError)?;
self.locked_vm_size += size;
Ok(())
}
@@ -516,7 +518,7 @@ impl VfioDeviceMgr {
let size = region.len();
self.get_vfio_container()?
.vfio_dma_unmap(gpa, size)
.vfio_dma_unmap(gpa, size as usize)
.map_err(VfioDeviceError::VfioIoctlError)?;
self.locked_vm_size -= size;