-
Notifications
You must be signed in to change notification settings - Fork 22
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
crates: move host CPUID queries from cpuid-gen to cpuid-utils #843
Conversation
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.
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.
Nice clean-up
} | ||
|
||
/// Queries the supplied CPUID leaf on the caller's machine. | ||
#[cfg(target_arch = "x86_64")] |
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.
nit: could use x86 here, rather than demanding x86-64, but it's not the first thing the cpuid area to be like that
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 gave this a try but discovered that rustc
appears to have no 32-bit illumos target!
$ rustc --version
rustc 1.84.0 (9fc6b4312 2025-01-07)
$ rustc --print=target-list | grep illumos
aarch64-unknown-illumos
x86_64-unknown-illumos
I don't think we're actually querying host CPUID in any platform-agnostic tests that one might want to run against an i686 target, so I left this as-is. (I think supporting x86 would also require defining these functions twice, since the CPUID intrinsic is in core::arch::x86
when compiling against that target, unless there's some subtlety that I'm missing.)
The
cpuid-gen
utility contains logic that reads and pretty-prints bhyve's default CPUID values (or the host processor's raw CPUID outputs). Move the logic that reads these values into thecpuid-utils
crate, re-express it in terms ofcpuid-utils
's CPUID types, and makecpuid-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.Tests: cargo test; PHD with Debian 11 and WS2022 guests; manually compared text and TOML output from the old and new cpuid-gen binaries.
Fixes #793. Related to #835.