Skip to content
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

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

gjcolombo
Copy link
Contributor

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 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.

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.

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.
Copy link
Collaborator

@pfmooney pfmooney left a 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")]
Copy link
Collaborator

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

Copy link
Contributor Author

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.)

@gjcolombo
Copy link
Contributor Author

Thanks @pfmooney and @iximeow for the reviews! Will merge first thing tomorrow and (hopefully) will soon have a follow-up PR to put this code to work in propolis-server.

@gjcolombo gjcolombo merged commit d8e3921 into master Jan 28, 2025
11 checks passed
@gjcolombo gjcolombo deleted the gjcolombo/cpuid-gen-to-utils branch January 28, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cpuid_boot_test goes out to lunch on Windows Server 2022 guest
3 participants