From ec79820b3fc0ea5a367fb95a1b71af02748cd5c3 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Mon, 4 Dec 2023 16:57:22 -0800 Subject: [PATCH] hypervisor: Add api to retrieve CPUID leaf Add necessary API to retrieve cpuid leaf on MSHV. This API is used to update cpuid information during the parsing of the igvm file. Microsoft hypervisor does not provide common CpuID like KVM. That's why we need to call this API during the IGVM parsing. Signed-off-by: Muminul Islam --- hypervisor/src/cpu.rs | 18 ++++++++++++++++++ hypervisor/src/mshv/mod.rs | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index a67e2cb50..4820956af 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -267,6 +267,11 @@ pub enum HypervisorCpuError { /// #[error("Failed to write to GPA: {0}")] GpaWrite(#[source] anyhow::Error), + /// + /// Error getting CPUID leaf + /// + #[error("Failed to get CPUID entries: {0}")] + GetCpuidVales(#[source] anyhow::Error), } #[derive(Debug)] @@ -477,4 +482,17 @@ pub trait Vcpu: Send + Sync { fn set_tsc_khz(&self, _freq: u32) -> Result<()> { Ok(()) } + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call to retrieve cpuid leaf + /// + fn get_cpuid_values( + &self, + _function: u32, + _index: u32, + _xfem: u64, + _xss: u64, + ) -> Result<[u32; 4]> { + unimplemented!() + } } diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index acd20713b..e1419e5e8 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -1077,6 +1077,23 @@ impl cpu::Vcpu for MshvVcpu { fn get_cpuid2(&self, _num_entries: usize) -> cpu::Result> { Ok(self.cpuid.clone()) } + + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call to retrieve cpuid leaf + /// + fn get_cpuid_values( + &self, + function: u32, + index: u32, + xfem: u64, + xss: u64, + ) -> cpu::Result<[u32; 4]> { + self.fd + .get_cpuid_values(function, index, xfem, xss) + .map_err(|e| cpu::HypervisorCpuError::GetCpuidVales(e.into())) + } + #[cfg(target_arch = "x86_64")] /// /// Returns the state of the LAPIC (Local Advanced Programmable Interrupt Controller).