From 20eee9bacedcd7f55dd0e289ac711664e30b1edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Mon, 29 Jul 2024 15:42:40 +0100 Subject: [PATCH] kvm_sys: Move KVM_PVIOMMU_SET_CONFIG to lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the ioctl definition using a magic number with the appropriate macro call. Note that this commit also limits the availability of the constant to AArch64 Android, the only builds using it as per the cfg attributes of KvmVfioPviommu::ioctl_kvm_pviommu_set_config(). TEST=m crosvm # in AOSP, then validated the constant using decompilation Change-Id: I6099a69419c5c562b0c5ce5b27ac3f24b73c9244 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5750141 Commit-Queue: Daniel Verkamp Auto-Submit: Pierre-Clément Tosi Reviewed-by: Daniel Verkamp --- kvm_sys/bindgen.sh | 3 +-- kvm_sys/src/aarch64/bindings.rs | 1 - kvm_sys/src/lib.rs | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kvm_sys/bindgen.sh b/kvm_sys/bindgen.sh index 82af23b90b..0b417715ed 100755 --- a/kvm_sys/bindgen.sh +++ b/kvm_sys/bindgen.sh @@ -39,8 +39,7 @@ pub struct kvm_vfio_iommu_config { pub device_fd: i32, pub sid_idx: u32, pub vsid: u32, -} -pub const KVM_PVIOMMU_SET_CONFIG: i32 = 0xc00cae01u32 as i32;" +}" X86_64_EXTRAS=" // This is how zerocopy's author deal with bindings for __BindgenBitfieldUnit, see: diff --git a/kvm_sys/src/aarch64/bindings.rs b/kvm_sys/src/aarch64/bindings.rs index fec4105834..4790df5499 100644 --- a/kvm_sys/src/aarch64/bindings.rs +++ b/kvm_sys/src/aarch64/bindings.rs @@ -38,7 +38,6 @@ pub struct kvm_vfio_iommu_config { pub sid_idx: u32, pub vsid: u32, } -pub const KVM_PVIOMMU_SET_CONFIG: i32 = 0xc00cae01u32 as i32; #[repr(C)] #[derive(Default)] diff --git a/kvm_sys/src/lib.rs b/kvm_sys/src/lib.rs index 93e08b31dc..5962d42b91 100644 --- a/kvm_sys/src/lib.rs +++ b/kvm_sys/src/lib.rs @@ -69,6 +69,8 @@ pub mod aarch64 { pub mod bindings; use base::ioctl_ior_nr; use base::ioctl_iow_nr; + #[cfg(target_os = "android")] + use base::ioctl_iowr_nr; pub use bindings::*; ioctl_iow_nr!(KVM_ARM_SET_DEVICE_ADDR, KVMIO, 0xab, kvm_arm_device_addr); @@ -80,6 +82,9 @@ pub mod aarch64 { 0xb5, kvm_arm_counter_offset ); + + #[cfg(target_os = "android")] + ioctl_iowr_nr!(KVM_PVIOMMU_SET_CONFIG, KVMIO, 0x1, kvm_vfio_iommu_config); } #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] pub use crate::aarch64::*;