Skip to content

ioctls: Fix device fd ioctl numbers to match kernel UAPI#324

Open
weltling wants to merge 1 commit into
rust-vmm:mainfrom
weltling:device-ioctl-numbers-6.18
Open

ioctls: Fix device fd ioctl numbers to match kernel UAPI#324
weltling wants to merge 1 commit into
rust-vmm:mainfrom
weltling:device-ioctl-numbers-6.18

Conversation

@weltling

@weltling weltling commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

The kernel 6.18 reorganized the mshv device fd UAPI. In 6.6:

#define MSHV_SET_DEVICE_ATTR  _IOW(MSHV_IOCTL, 0x00, struct mshv_device_attr)
#define MSHV_GET_DEVICE_ATTR  _IOW(MSHV_IOCTL, 0x01, struct mshv_device_attr)
#define MSHV_HAS_DEVICE_ATTR  _IOW(MSHV_IOCTL, 0x02, struct mshv_device_attr)

In 6.18, MSHV_GET_DEVICE_ATTR was removed and MSHV_HAS_DEVICE_ATTR was renumbered to 0x01:

#define MSHV_SET_DEVICE_ATTR  _IOW(MSHV_IOCTL, 0x00, struct mshv_device_attr)
#define MSHV_HAS_DEVICE_ATTR  _IOW(MSHV_IOCTL, 0x01, struct mshv_device_attr)

The crate still uses the 6.6 layout, causing has_device_attr() to send ioctl command 0x02 which the 6.18 kernel does not recognize, returning -ENOTTY. This makes test_create_device panic on:

assertion failed: device.has_device_attr(&dist_attr).is_ok()

Update the crate to match the 6.18 UAPI:

  • Remove MSHV_GET_DEVICE_ATTR ioctl definition
  • Fix MSHV_HAS_DEVICE_ATTR number from 0x02 to 0x01
  • Remove get_device_attr() method from DeviceFd
  • Update test_create_device accordingly

Note: this breaks compatibility with the 6.6 kernel.

@weltling weltling marked this pull request as draft June 9, 2026 19:48
@russell-islam

Copy link
Copy Markdown
Collaborator

@weltling The test failure seems due to Kernel version in test host. it is still 6.6. Right?

@weltling weltling force-pushed the device-ioctl-numbers-6.18 branch from d46ba6f to 33d3263 Compare June 12, 2026 08:51
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 <anbelski@linux.microsoft.com>
@weltling weltling force-pushed the device-ioctl-numbers-6.18 branch from 33d3263 to 8b13f97 Compare June 12, 2026 08:53
@weltling

Copy link
Copy Markdown
Collaborator Author

@weltling The test failure seems due to Kernel version in test host. it is still 6.6. Right?

Correct. 6.18 will have the mentioned IOCTLs changes which is incompatible. We can perhaps consider bumping the minor version of the crate after this change, as it's going to breach backward compatibility.

Thanks

@weltling

Copy link
Copy Markdown
Collaborator Author

Now confirmed through a manual run ioctls::device::tests::test_create_device is passing on a 6.18 powered host.

Thanks

@weltling weltling marked this pull request as ready for review June 12, 2026 09:00
@weltling

Copy link
Copy Markdown
Collaborator Author

Thinking more we need a strategy for this, because this kind of breach requires a swap on the CI side. The MSHV runner needs to use 6.18 based imag. Which would probably mean an impact on testability of the older versions of this crate. @gamora12 @anirudhrb WDYT?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants