diff --git a/Cargo.lock b/Cargo.lock index f4e667f77..bdfc5b7bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -545,8 +545,7 @@ dependencies = [ [[package]] name = "kvm-ioctls" version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8dc9c1896e5f144ec5d07169bc29f39a047686d29585a91f30489abfaeb6b" +source = "git+https://github.com/rust-vmm/kvm-ioctls?branch=main#23a3bb045a467e60bb00328a0b13cea13b5815d0" dependencies = [ "kvm-bindings", "libc", diff --git a/Cargo.toml b/Cargo.toml index 230bd4991..4f1fa48da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ vm-memory = "0.10.0" # List of patched crates [patch.crates-io] kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-v0.6.0-tdx" } +kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "main" } versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch" } [dev-dependencies] diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 62fe5bf03..34fbda425 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -330,7 +330,7 @@ impl KvmVm { Ok(VfioDeviceFd::new_from_kvm(device_fd)) } /// Checks if a particular `Cap` is available. - fn check_extension(&self, c: Cap) -> bool { + pub fn check_extension(&self, c: Cap) -> bool { self.fd.check_extension(c) } } diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 1de82e48f..b642e0442 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -52,6 +52,8 @@ use hypervisor::arch::x86::MsrEntry; use hypervisor::arch::x86::{SpecialRegisters, StandardRegisters}; #[cfg(target_arch = "aarch64")] use hypervisor::kvm::kvm_bindings; +#[cfg(all(target_arch = "aarch64", feature = "kvm"))] +use hypervisor::kvm::kvm_ioctls::Cap; #[cfg(feature = "tdx")] use hypervisor::kvm::{TdxExitDetails, TdxExitStatus}; use hypervisor::{CpuState, HypervisorCpuError, HypervisorType, VmExit, VmOps}; @@ -370,7 +372,14 @@ impl Vcpu { .map_err(Error::VcpuArmPreferredTarget)?; // We already checked that the capability is supported. kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PSCI_0_2; - kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PMU_V3; + if vm + .as_any() + .downcast_ref::() + .unwrap() + .check_extension(Cap::ArmPmuV3) + { + kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_PMU_V3; + } // Non-boot cpus are powered off initially. if self.id > 0 { kvi.features[0] |= 1 << kvm_bindings::KVM_ARM_VCPU_POWER_OFF;