Skip to content

Commit

Permalink
chore: adjust to api changes in rust-vmm crates
Browse files Browse the repository at this point in the history
vm-memory: GuestMemoryIterator is gone
kvm-ioctls: DeviceFd::get_device_attr is now unsafe.

Signed-off-by: Patrick Roy <[email protected]>
  • Loading branch information
roypat committed Oct 29, 2024
1 parent 1bc168e commit 22f316a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/vmm/src/arch/aarch64/gic/gicv2/regs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/vmm/src/arch/aarch64/gic/gicv3/regs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/vmm/src/arch/aarch64/gic/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ pub(crate) trait VgicRegEngine {
let mut data = Vec::with_capacity(reg.iter::<Self::RegChunk>().count());
for offset in reg.iter::<Self::RegChunk>() {
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);
}

Expand Down
8 changes: 1 addition & 7 deletions src/vmm/src/devices/virtio/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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
Expand All @@ -735,7 +729,7 @@ mod verification {
.map(|_| &self.the_region)
}

fn iter(&self) -> <Self::I as GuestMemoryIterator<Self::R>>::Iter {
fn iter(&self) -> impl Iterator<Item = &Self::R> {
std::iter::once(&self.the_region)
}

Expand Down

0 comments on commit 22f316a

Please sign in to comment.