diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs index 238adef349..46cf0453ef 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs @@ -9,6 +9,7 @@ use self::snp::SnpCpuidSupport; use self::tdx::TdxCpuidInitializer; use self::tdx::TdxCpuidSupport; use core::arch::x86_64::CpuidResult; +use inspect::Inspect; use masking::CpuidResultMask; use snp::SnpCpuidInitializer; use std::boxed::Box; @@ -88,7 +89,7 @@ trait CpuidArchInitializer { } /// Architecture-specific behaviors for cpuid results during runtime -trait CpuidArchSupport: Sync + Send { +trait CpuidArchSupport: Sync + Send + Inspect { /// Get the cpuid result of the leaf/subleaf but modified based on guest /// context fn process_guest_result( @@ -178,8 +179,11 @@ pub struct ParsedCpuidEntry { } /// Prepares and caches the results that should be returned for hardware CVMs. +#[derive(Inspect)] pub struct CpuidResults { + #[inspect(with = "inspect_helpers::cpuid_table")] results: HashMap, + #[inspect(hex)] max_extended_state: u64, arch_support: Box, vps_per_socket: u32, @@ -188,9 +192,45 @@ pub struct CpuidResults { type CpuidSubtable = HashMap; /// Entry in [`CpuidResults`] for caching leaf value or its subleaves. +#[derive(Inspect)] +#[inspect(tag = "type")] enum CpuidEntry { - Leaf(CpuidResult), - Subtable(CpuidSubtable), + #[inspect(transparent)] + Leaf(#[inspect(with = "inspect_helpers::cpuid_result")] CpuidResult), + #[inspect(transparent)] + Subtable(#[inspect(with = "inspect_helpers::cpuid_subtable")] CpuidSubtable), +} + +mod inspect_helpers { + use super::*; + use inspect::AsHex; + use inspect::Inspect; + + pub(super) fn cpuid_result(result: &CpuidResult) -> impl Inspect + '_ { + inspect::adhoc(|req| { + req.respond() + .field("eax", AsHex(result.eax)) + .field("ebx", AsHex(result.ebx)) + .field("ecx", AsHex(result.ecx)) + .field("edx", AsHex(result.edx)); + }) + } + + pub(super) fn cpuid_table(table: &HashMap) -> impl Inspect + '_ { + inspect::iter_by_key( + table + .iter() + .map(|(key, value)| (format!("{:?} ({:x})", key, key.0), value)), + ) + } + + pub(super) fn cpuid_subtable(table: &CpuidSubtable) -> impl Inspect + '_ { + inspect::iter_by_key( + table + .iter() + .map(|(key, value)| (format!("{:x?}", key), cpuid_result(value))), + ) + } } /// Guest state needed to compute the cpuid result for a specific execution diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/snp.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/snp.rs index 3470ec2393..9d9db7c3a8 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/snp.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/snp.rs @@ -14,6 +14,7 @@ use super::ParsedCpuidEntry; use super::TopologyError; use super::ZERO_CPUID_RESULT; use core::arch::x86_64::CpuidResult; +use inspect::Inspect; use x86defs::cpuid; use x86defs::cpuid::CpuidFunction; use x86defs::snp::HvPspCpuidPage; @@ -494,6 +495,12 @@ impl CpuidArchSupport for SnpCpuidSupport { } } +impl Inspect for SnpCpuidSupport { + fn inspect(&self, req: inspect::Request<'_>) { + req.respond().field("type", "snp-cpuid"); + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs index ce07454072..c2538015cf 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs @@ -13,6 +13,7 @@ use super::CpuidSubtable; use super::ParsedCpuidEntry; use super::TopologyError; use core::arch::x86_64::CpuidResult; +use inspect::Inspect; use x86defs::cpuid; use x86defs::cpuid::CpuidFunction; use x86defs::xsave; @@ -252,3 +253,9 @@ impl CpuidArchSupport for TdxCpuidSupport { // Nothing extra to do for TDX } } + +impl Inspect for TdxCpuidSupport { + fn inspect(&self, req: inspect::Request<'_>) { + req.respond().field("type", "tdx-cpuid"); + } +} diff --git a/openhcl/virt_mshv_vtl/src/lib.rs b/openhcl/virt_mshv_vtl/src/lib.rs index 8a5b4bfb8f..cacd2f1a70 100644 --- a/openhcl/virt_mshv_vtl/src/lib.rs +++ b/openhcl/virt_mshv_vtl/src/lib.rs @@ -393,7 +393,6 @@ impl UhCvmVpState { /// Partition-wide state for CVMs. struct UhCvmPartitionState { #[cfg(guest_arch = "x86_64")] - #[inspect(skip)] cpuid: cvm_cpuid::CpuidResults, /// VPs that have locked their TLB. #[inspect(