-
Notifications
You must be signed in to change notification settings - Fork 120
virt_mshv_vtl: add inspection support for cvm cpuid tables #1048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<CpuidFunction, CpuidEntry>, | ||
#[inspect(hex)] | ||
max_extended_state: u64, | ||
arch_support: Box<dyn CpuidArchSupport>, | ||
vps_per_socket: u32, | ||
|
@@ -188,9 +192,45 @@ pub struct CpuidResults { | |
type CpuidSubtable = HashMap<u32, CpuidResult>; | ||
|
||
/// 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<CpuidFunction, CpuidEntry>) -> impl Inspect + '_ { | ||
inspect::iter_by_key( | ||
table | ||
.iter() | ||
.map(|(key, value)| (format!("{:?} ({:x})", key, key.0), value)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just make the key the hex value in both cases? I don't want spaces and parens and open_enum identifiers in keys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah we can just make it the hex key, i found it useful to have both (but that's because i just started looking at cpuid so i don't have the idents memorized) |
||
) | ||
} | ||
|
||
pub(super) fn cpuid_subtable(table: &CpuidSubtable) -> impl Inspect + '_ { | ||
inspect::iter_by_key( | ||
table | ||
.iter() | ||
.map(|(key, value)| (format!("{:x?}", key), cpuid_result(value))), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like it should be |
||
) | ||
} | ||
} | ||
|
||
/// Guest state needed to compute the cpuid result for a specific execution | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still want this whole thing merged with the non-CVM cpuid handling. We shouldn't have two completely different table formats.
But anyway, that's certainly out of scope for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - it's really annoying that they're completely different.