Skip to content

Commit

Permalink
crates: move host CPUID queries from cpuid-gen to cpuid-utils
Browse files Browse the repository at this point in the history
The `cpuid-gen` utility contains logic that reads and pretty-prints
bhyve's default CPUID values (or the host proecssor's raw CPUID
outputs). Move the logic that reads these values into the `cpuid-utils`
crate, re-express it in terms of `cpuid-utils`'s CPUID types, and make
`cpuid-gen` call the new logic. Future changes will make propolis-server
use this logic to set default CPUID values for VMs whose instance specs
contain no CPUID settings.

Fix a bit shifting bug in `collect_cpuid`'s handler for standard leaf D:
this leaf outputs 64-bit values across two output registers, and the old
logic wasn't shifting edx into the high 32 bits before OR'ing it with
its counterpart register.

Finally, simplify PHD's `cpuid_boot_test`: since it can now ask bhyve
for CPUID settings that bhyve thinks are valid, it no longer needs to
try to stitch together its own minimum viable CPUID profile. This test
now passes with a Windows Server 2022 guest.
  • Loading branch information
gjcolombo committed Jan 28, 2025
1 parent e9db237 commit fbec66a
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 447 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/propolis-server/src/lib/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ impl MachineInitializer<'_> {
) -> Option<CpuidValues> {
let leaf = CpuidIdent::leaf(leaf);
let Some(cpuid) = &spec.cpuid else {
return Some(cpuid_utils::host_query(leaf));
return Some(cpuid_utils::host::query(leaf));
};

cpuid.get(leaf).copied()
Expand Down
12 changes: 6 additions & 6 deletions bin/propolis-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,10 @@ fn generate_smbios(params: SmbiosParams) -> anyhow::Result<smbios::TableBytes> {
..Default::default()
};

let cpuid_vendor = cpuid_utils::host_query(CpuidIdent::leaf(0));
let cpuid_vendor = cpuid_utils::host::query(CpuidIdent::leaf(0));
let cpuid_ident = params
.cpuid_ident
.unwrap_or_else(|| cpuid_utils::host_query(CpuidIdent::leaf(1)));
.unwrap_or_else(|| cpuid_utils::host::query(CpuidIdent::leaf(1)));
let family = match cpuid_ident.eax & 0xf00 {
// If family ID is 0xf, extended family is added to it
0xf00 => (cpuid_ident.eax >> 20 & 0xff) + 0xf,
Expand All @@ -894,13 +894,13 @@ fn generate_smbios(params: SmbiosParams) -> anyhow::Result<smbios::TableBytes> {
};
let proc_id = u64::from(cpuid_ident.eax) | u64::from(cpuid_ident.edx) << 32;
let procname_entries = params.cpuid_procname.or_else(|| {
if cpuid_utils::host_query(CpuidIdent::leaf(0x8000_0000)).eax
if cpuid_utils::host::query(CpuidIdent::leaf(0x8000_0000)).eax
>= 0x8000_0004
{
Some([
cpuid_utils::host_query(CpuidIdent::leaf(0x8000_0002)),
cpuid_utils::host_query(CpuidIdent::leaf(0x8000_0003)),
cpuid_utils::host_query(CpuidIdent::leaf(0x8000_0004)),
cpuid_utils::host::query(CpuidIdent::leaf(0x8000_0002)),
cpuid_utils::host::query(CpuidIdent::leaf(0x8000_0003)),
cpuid_utils::host::query(CpuidIdent::leaf(0x8000_0004)),
])
} else {
None
Expand Down
1 change: 1 addition & 0 deletions bin/propolis-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ doctest = false
[dependencies]
anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
cpuid_utils = { workspace = true, features = ["instance-spec"] }
serde = { workspace = true, features = ["derive"] }
propolis = { workspace = true, default-features = false }
propolis_api_types.workspace = true
Expand Down
Loading

0 comments on commit fbec66a

Please sign in to comment.