From a32409cc7bcb32087199882f671fa3d0cdcea276 Mon Sep 17 00:00:00 2001 From: Nick Rogers <1903140+rogersnm@users.noreply.github.com> Date: Sat, 15 Aug 2026 15:20:23 +0000 Subject: [PATCH] Expose VmFd::enable_cap on all architectures The KVM_ENABLE_CAP vm ioctl is architecture independent, but both the ioctl definition and VmFd::enable_cap were compiled only for x86_64, s390x and powerpc. aarch64 now needs them: Linux 6.15 gates writes to the implementation ID registers (MIDR_EL1, REVIDR_EL1, AIDR_EL1) behind KVM_CAP_ARM_WRITABLE_IMP_ID_REGS, which a VMM must enable on the VM before creating vCPUs. Without enable_cap, VMMs fall back to issuing the raw ioctl themselves (see firecracker-microvm/firecracker#6116). Remove the cfg gates and guard the x86 specific portion of the doc example so it builds and runs on every architecture. Signed-off-by: Nick Rogers <1903140+rogersnm@users.noreply.github.com> --- kvm-ioctls/CHANGELOG.md | 9 +++++++++ kvm-ioctls/src/ioctls/vm.rs | 2 +- kvm-ioctls/src/kvm_ioctls.rs | 1 - 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kvm-ioctls/CHANGELOG.md b/kvm-ioctls/CHANGELOG.md index e0fd7430..42956c48 100644 --- a/kvm-ioctls/CHANGELOG.md +++ b/kvm-ioctls/CHANGELOG.md @@ -2,6 +2,15 @@ ## Upcoming Release +### Changed + +- [[#382]](https://github.com/rust-vmm/kvm/pull/382) `VmFd::enable_cap` and the + `KVM_ENABLE_CAP` ioctl definition are now available on all architectures + instead of only x86_64, s390x and powerpc. aarch64 needs them to enable + `KVM_CAP_ARM_WRITABLE_IMP_ID_REGS` (Linux 6.15), without which writes to the + implementation ID registers (for example `MIDR_EL1` through a VMM CPU + template) fail with EINVAL. + ## v0.25.0 ### Added diff --git a/kvm-ioctls/src/ioctls/vm.rs b/kvm-ioctls/src/ioctls/vm.rs index 466dd8ff..3e5f7b99 100644 --- a/kvm-ioctls/src/ioctls/vm.rs +++ b/kvm-ioctls/src/ioctls/vm.rs @@ -1521,9 +1521,9 @@ impl VmFd { /// // Because an IOAPIC supports 24 pins, that's the reason why this test /// // picked this number as reference. /// cap.args[0] = 24; + /// #[cfg(target_arch = "x86_64")] /// vm.enable_cap(&cap).unwrap(); /// ``` - #[cfg(any(target_arch = "x86_64", target_arch = "s390x", target_arch = "powerpc"))] pub fn enable_cap(&self, cap: &kvm_enable_cap) -> Result<()> { // SAFETY: The ioctl is safe because we allocated the struct and we know the // kernel will write exactly the size of the struct. diff --git a/kvm-ioctls/src/kvm_ioctls.rs b/kvm-ioctls/src/kvm_ioctls.rs index b294c57e..af802307 100644 --- a/kvm-ioctls/src/kvm_ioctls.rs +++ b/kvm-ioctls/src/kvm_ioctls.rs @@ -226,7 +226,6 @@ ioctl_io_nr!(KVM_SET_TSC_KHZ, KVMIO, 0xa2); ioctl_io_nr!(KVM_GET_TSC_KHZ, KVMIO, 0xa3); /* Available with KVM_CAP_ENABLE_CAP */ -#[cfg(not(any(target_arch = "aarch64", target_arch = "riscv64")))] ioctl_iow_nr!(KVM_ENABLE_CAP, KVMIO, 0xa3, kvm_enable_cap); /* Available with KVM_CAP_SIGNAL_MSI */ #[cfg(any(