diff --git a/Cargo.lock b/Cargo.lock index 9dbc86ae0..c23dc490f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,7 +403,7 @@ dependencies = [ [[package]] name = "kvm-ioctls" version = "0.11.0" -source = "git+https://github.com/rust-vmm/kvm-ioctls?branch=main#d22ef1f51852dfb055da38004e1a4fed81246f81" +source = "git+https://github.com/rust-vmm/kvm-ioctls?branch=main#8ab2e374e262612020fb0b9f7fbdec839ee7a76f" dependencies = [ "kvm-bindings", "libc", diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index 803eaccca..fd75b86d8 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -19,6 +19,8 @@ use crate::x86_64::{ ExtendedControlRegisters, FpuState, MsrEntries, SpecialRegisters, StandardRegisters, VcpuEvents, }; use crate::CpuState; +#[cfg(target_arch = "aarch64")] +use crate::DeviceAttr; #[cfg(feature = "kvm")] use crate::MpState; #[cfg(all(feature = "mshv", target_arch = "x86_64"))] @@ -223,6 +225,16 @@ pub enum HypervisorCpuError { #[error("Failed to translate GVA: {0}")] TranslateVirtualAddress(#[source] anyhow::Error), /// + /// Set cpu attribute error + /// + #[error("Failed to set vcpu attribute: {0}")] + SetVcpuAttribute(#[source] anyhow::Error), + /// + /// Check if cpu has a certain attribute error + /// + #[error("Failed to check if vcpu has attribute: {0}")] + HasVcpuAttribute(#[source] anyhow::Error), + /// /// Failed to initialize TDX on CPU /// #[cfg(feature = "tdx")] @@ -259,7 +271,16 @@ pub trait Vcpu: Send + Sync { /// Returns the vCPU general purpose registers. /// fn get_regs(&self) -> Result; - + #[cfg(target_arch = "aarch64")] + /// + /// Sets vcpu attribute + /// + fn set_vcpu_attr(&self, attr: &DeviceAttr) -> Result<()>; + #[cfg(target_arch = "aarch64")] + /// + /// Check if vcpu has attribute. + /// + fn has_vcpu_attr(&self, attr: &DeviceAttr) -> Result<()>; #[cfg(target_arch = "x86_64")] /// /// Sets the vCPU general purpose registers. diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 8e5a3fda6..c66a96c79 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -777,6 +777,27 @@ impl cpu::Vcpu for KvmVcpu { .set_regs(regs) .map_err(|e| cpu::HypervisorCpuError::SetStandardRegs(e.into())) } + + #[cfg(target_arch = "aarch64")] + /// + /// Set attribute for vcpu. + /// + fn set_vcpu_attr(&self, attr: &DeviceAttr) -> cpu::Result<()> { + self.fd + .set_device_attr(attr) + .map_err(|e| cpu::HypervisorCpuError::SetVcpuAttribute(e.into())) + } + + #[cfg(target_arch = "aarch64")] + /// + /// Check if vcpu has a certain attribute. + /// + fn has_vcpu_attr(&self, attr: &DeviceAttr) -> cpu::Result<()> { + self.fd + .has_device_attr(attr) + .map_err(|e| cpu::HypervisorCpuError::HasVcpuAttribute(e.into())) + } + #[cfg(target_arch = "x86_64")] /// /// Returns the vCPU special registers.