Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mshv-ioctls/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### Deprecated

### Fixed
* mshv-ioctls: Fix device fd ioctl numbers for kernel 6.18 (remove MSHV_GET_DEVICE_ATTR, renumber MSHV_HAS_DEVICE_ATTR from 0x02 to 0x01)

## [v0.6.9]

Expand Down
36 changes: 2 additions & 34 deletions mshv-ioctls/src/ioctls/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::fs::File;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};

use crate::ioctls::Result;
use crate::mshv_ioctls::{MSHV_GET_DEVICE_ATTR, MSHV_HAS_DEVICE_ATTR, MSHV_SET_DEVICE_ATTR};
use crate::mshv_ioctls::{MSHV_HAS_DEVICE_ATTR, MSHV_SET_DEVICE_ATTR};
use mshv_bindings::mshv_device_attr;
use vmm_sys_util::errno;
use vmm_sys_util::ioctl::{ioctl_with_mut_ref, ioctl_with_ref};
use vmm_sys_util::ioctl::ioctl_with_ref;

/// Wrapper over the file descriptor obtained when creating an emulated device in the kernel.
#[derive(Debug)]
Expand Down Expand Up @@ -83,35 +83,6 @@ impl DeviceFd {
}
Ok(())
}

/// Gets a specified piece of device configuration and/or state.
///
/// See the documentation for `MSHV_GET_DEVICE_ATTR`.
///
/// # Arguments
///
/// * `device_attr` - The device attribute to be get.
/// Note: This argument serves as both input and output.
/// When calling this function, the user should explicitly provide
/// valid values for the `group` and the `attr` field of the
/// `mshv_device_attr` structure, and a valid userspace address
/// (i.e. the `addr` field) to access the returned device attribute
/// data.
///
/// # Returns
///
/// * Returns the last occured `errno` wrapped in an `Err`.
/// * `device_attr` - The `addr` field of the `device_attr` structure will point to
/// the device attribute data.
pub fn get_device_attr(&self, device_attr: &mut mshv_device_attr) -> Result<()> {
// SAFETY: IOCTL. We're sure parameters are of the correct types and meet safety
// requirements.
let ret = unsafe { ioctl_with_mut_ref(self, MSHV_GET_DEVICE_ATTR(), device_attr) };
if ret != 0 {
return Err(errno::Error::last().into());
}
Ok(())
}
}

/// Helper function for creating a new device.
Expand Down Expand Up @@ -177,12 +148,9 @@ mod tests {
flags: 0,
};

let mut dist_attr_mut = dist_attr;

// We are just creating a test device. Creating a real device would make the CI dependent
// on host configuration (like having /dev/vfio). We expect this to fail.
assert!(device.has_device_attr(&dist_attr).is_ok());
assert!(device.get_device_attr(&mut dist_attr_mut).is_err());
assert!(device.set_device_attr(&dist_attr).is_err());
assert_eq!(errno::Error::last().errno(), 14);
}
Expand Down
3 changes: 1 addition & 2 deletions mshv-ioctls/src/mshv_ioctls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,4 @@ ioctl_iow_nr!(MSHV_WRITE_GPA, MSHV_IOCTL, 0xF6, mshv_read_write_gpa);

// device fd
ioctl_iow_nr!(MSHV_SET_DEVICE_ATTR, MSHV_IOCTL, 0x00, mshv_device_attr);
ioctl_iow_nr!(MSHV_GET_DEVICE_ATTR, MSHV_IOCTL, 0x01, mshv_device_attr);
ioctl_iow_nr!(MSHV_HAS_DEVICE_ATTR, MSHV_IOCTL, 0x02, mshv_device_attr);
ioctl_iow_nr!(MSHV_HAS_DEVICE_ATTR, MSHV_IOCTL, 0x01, mshv_device_attr);
Loading