From 8b13f979ef0e675fff02e9dfd3ef85507bbc60b0 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 9 Jun 2026 18:27:19 +0200 Subject: [PATCH] ioctls: Fix device fd ioctl numbers for kernel 6.18 The kernel 6.18 removed MSHV_GET_DEVICE_ATTR and renumbered MSHV_HAS_DEVICE_ATTR from 0x02 to 0x01. The crate still used the 6.6 layout (SET=0x00, GET=0x01, HAS=0x02), causing has_device_attr() to return -ENOTTY on 6.18. Update ioctl numbers to match the 6.18 UAPI: - Remove MSHV_GET_DEVICE_ATTR (0x01) - Renumber MSHV_HAS_DEVICE_ATTR from 0x02 to 0x01 - Remove get_device_attr() from DeviceFd Note: this breaks compatibility with the 6.6 kernel. Signed-off-by: Anatol Belski --- mshv-ioctls/CHANGELOG.md | 1 + mshv-ioctls/src/ioctls/device.rs | 36 ++------------------------------ mshv-ioctls/src/mshv_ioctls.rs | 3 +-- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/mshv-ioctls/CHANGELOG.md b/mshv-ioctls/CHANGELOG.md index 863cb173..db9ab816 100644 --- a/mshv-ioctls/CHANGELOG.md +++ b/mshv-ioctls/CHANGELOG.md @@ -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] diff --git a/mshv-ioctls/src/ioctls/device.rs b/mshv-ioctls/src/ioctls/device.rs index fc97bd31..6c01c7c2 100644 --- a/mshv-ioctls/src/ioctls/device.rs +++ b/mshv-ioctls/src/ioctls/device.rs @@ -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)] @@ -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. @@ -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); } diff --git a/mshv-ioctls/src/mshv_ioctls.rs b/mshv-ioctls/src/mshv_ioctls.rs index b052f993..91b495ac 100644 --- a/mshv-ioctls/src/mshv_ioctls.rs +++ b/mshv-ioctls/src/mshv_ioctls.rs @@ -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);