From 22f316aa87d5a2af5cdc40476215fdf0ba03af44 Mon Sep 17 00:00:00 2001 From: Patrick Roy Date: Tue, 29 Oct 2024 14:55:05 +0000 Subject: [PATCH] chore: adjust to api changes in rust-vmm crates vm-memory: GuestMemoryIterator is gone kvm-ioctls: DeviceFd::get_device_attr is now unsafe. Signed-off-by: Patrick Roy --- src/vmm/src/arch/aarch64/gic/gicv2/regs/mod.rs | 6 +++++- src/vmm/src/arch/aarch64/gic/gicv3/regs/mod.rs | 6 +++++- src/vmm/src/arch/aarch64/gic/regs.rs | 8 ++++++-- src/vmm/src/devices/virtio/queue.rs | 8 +------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/vmm/src/arch/aarch64/gic/gicv2/regs/mod.rs b/src/vmm/src/arch/aarch64/gic/gicv2/regs/mod.rs index 6e85b144a26..a0c0e2c8fac 100644 --- a/src/vmm/src/arch/aarch64/gic/gicv2/regs/mod.rs +++ b/src/vmm/src/arch/aarch64/gic/gicv2/regs/mod.rs @@ -41,6 +41,8 @@ pub fn restore_state(fd: &DeviceFd, mpidrs: &[u64], state: &GicState) -> Result< #[cfg(test)] mod tests { + #![allow(clippy::undocumented_unsafe_blocks)] + use kvm_ioctls::Kvm; use super::*; @@ -79,7 +81,9 @@ mod tests { addr: &val as *const u32 as u64, flags: 0, }; - gic_fd.get_device_attr(&mut gic_dist_attr).unwrap(); + unsafe { + gic_fd.get_device_attr(&mut gic_dist_attr).unwrap(); + } // The second value from the list of distributor registers is the value of the GICD_STATUSR // register. We assert that the one saved in the bitmap is the same with the one we diff --git a/src/vmm/src/arch/aarch64/gic/gicv3/regs/mod.rs b/src/vmm/src/arch/aarch64/gic/gicv3/regs/mod.rs index ba1c78dadc9..31261f647fc 100644 --- a/src/vmm/src/arch/aarch64/gic/gicv3/regs/mod.rs +++ b/src/vmm/src/arch/aarch64/gic/gicv3/regs/mod.rs @@ -46,6 +46,8 @@ pub fn restore_state(fd: &DeviceFd, mpidrs: &[u64], state: &GicState) -> Result< #[cfg(test)] mod tests { + #![allow(clippy::undocumented_unsafe_blocks)] + use kvm_ioctls::Kvm; use super::*; @@ -81,7 +83,9 @@ mod tests { addr: &val as *const u32 as u64, flags: 0, }; - gic_fd.get_device_attr(&mut gic_dist_attr).unwrap(); + unsafe { + gic_fd.get_device_attr(&mut gic_dist_attr).unwrap(); + } // The second value from the list of distributor registers is the value of the GICD_STATUSR // register. We assert that the one saved in the bitmap is the same with the one we diff --git a/src/vmm/src/arch/aarch64/gic/regs.rs b/src/vmm/src/arch/aarch64/gic/regs.rs index 88c4d68c15c..60987cc973d 100644 --- a/src/vmm/src/arch/aarch64/gic/regs.rs +++ b/src/vmm/src/arch/aarch64/gic/regs.rs @@ -81,8 +81,12 @@ pub(crate) trait VgicRegEngine { let mut data = Vec::with_capacity(reg.iter::().count()); for offset in reg.iter::() { let mut val = Self::RegChunk::default(); - fd.get_device_attr(&mut Self::kvm_device_attr(offset, &mut val, mpidr)) - .map_err(|err| GicError::DeviceAttribute(err, false, Self::group()))?; + // SAFETY: `val` is a mutable memory location sized correctly for the attribute we're + // requesting + unsafe { + fd.get_device_attr(&mut Self::kvm_device_attr(offset, &mut val, mpidr)) + .map_err(|err| GicError::DeviceAttribute(err, false, Self::group()))?; + } data.push(val); } diff --git a/src/vmm/src/devices/virtio/queue.rs b/src/vmm/src/devices/virtio/queue.rs index b80b2571c12..39ccef1f1ee 100644 --- a/src/vmm/src/devices/virtio/queue.rs +++ b/src/vmm/src/devices/virtio/queue.rs @@ -700,7 +700,6 @@ mod verification { use std::mem::ManuallyDrop; use std::num::Wrapping; - use vm_memory::guest_memory::GuestMemoryIterator; use vm_memory::{GuestMemoryRegion, MemoryRegionAddress}; use super::*; @@ -717,13 +716,8 @@ mod verification { the_region: vm_memory::GuestRegionMmap, } - impl<'a> GuestMemoryIterator<'a, vm_memory::GuestRegionMmap> for ProofGuestMemory { - type Iter = std::iter::Once<&'a vm_memory::GuestRegionMmap>; - } - impl GuestMemory for ProofGuestMemory { type R = vm_memory::GuestRegionMmap; - type I = Self; fn num_regions(&self) -> usize { 1 @@ -735,7 +729,7 @@ mod verification { .map(|_| &self.the_region) } - fn iter(&self) -> >::Iter { + fn iter(&self) -> impl Iterator { std::iter::once(&self.the_region) }