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 c00e46bcbc
commit fe5b267326
4 changed files with 42 additions and 47 deletions

47
Cargo.lock generated
View File

@@ -1522,7 +1522,7 @@ checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea"
name = "dbs-acpi"
version = "0.1.0"
dependencies = [
"vm-memory 0.17.1",
"vm-memory",
]
[[package]]
@@ -1534,7 +1534,7 @@ dependencies = [
"libc",
"nix 0.23.2",
"thiserror 1.0.69",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -1556,7 +1556,7 @@ dependencies = [
"nix 0.26.4",
"test-utils",
"thiserror 1.0.69",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -1575,7 +1575,7 @@ dependencies = [
"test-utils",
"thiserror 1.0.69",
"vm-fdt",
"vm-memory 0.17.1",
"vm-memory",
]
[[package]]
@@ -1637,7 +1637,7 @@ dependencies = [
"vfio-bindings",
"vfio-ioctls",
"virtio-queue",
"vm-memory 0.17.1",
"vm-memory",
]
[[package]]
@@ -1712,7 +1712,7 @@ dependencies = [
"vhost",
"virtio-bindings",
"virtio-queue",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -1904,7 +1904,7 @@ dependencies = [
"vfio-bindings",
"vfio-ioctls",
"virtio-queue",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -2320,7 +2320,7 @@ dependencies = [
"nix 0.24.3",
"radix_trie",
"virtio-queue",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -3978,7 +3978,7 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de72cb02c55ecffcf75fe78295926f872eb6eb0a58d629c58a8c324dc26380f6"
dependencies = [
"vm-memory 0.17.1",
"vm-memory",
]
[[package]]
@@ -4647,7 +4647,7 @@ dependencies = [
"serde",
"serde_json",
"thiserror 1.0.69",
"vm-memory 0.17.1",
"vm-memory",
]
[[package]]
@@ -4676,7 +4676,7 @@ dependencies = [
"tar",
"tokio",
"url",
"vm-memory 0.17.1",
"vm-memory",
]
[[package]]
@@ -8561,15 +8561,15 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "vfio-bindings"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4bc5b4aade27640cea4ee1ce50ef3614598050dc97e44714b9daea779d1b59a"
checksum = "188dac3057a0cbc94470085204c84b82ff7ec5dac629a514323cd133d1f9abe0"
[[package]]
name = "vfio-ioctls"
version = "0.5.2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c85bf46a63452d82e7df8e3ed052f07969507aeb5685ef9bf01d8db3ea74c36"
checksum = "d4b1d98dff7f0d219278e406323e7eda4d426447bd203c7828189baf0d8c07b7"
dependencies = [
"byteorder",
"kvm-bindings",
@@ -8578,7 +8578,7 @@ dependencies = [
"log",
"thiserror 2.0.18",
"vfio-bindings",
"vm-memory 0.16.2",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -8591,7 +8591,7 @@ dependencies = [
"bitflags 2.11.0",
"libc",
"uuid 1.22.0",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -8643,7 +8643,7 @@ dependencies = [
"libc",
"log",
"virtio-bindings",
"vm-memory 0.17.1",
"vm-memory",
"vmm-sys-util 0.15.0",
]
@@ -8653,17 +8653,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e21282841a059bb62627ce8441c491f09603622cd5a21c43bfedc85a2952f23"
[[package]]
name = "vm-memory"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd5e56d48353c5f54ef50bd158a0452fc82f5383da840f7b8efc31695dd3b9d"
dependencies = [
"libc",
"thiserror 1.0.69",
"winapi",
]
[[package]]
name = "vm-memory"
version = "0.17.1"

View File

@@ -83,8 +83,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;