Skip to content

Handle CPUID subleaves more precisely when using Bhyve defaults - #915

Merged
iximeow merged 2 commits into
masterfrom
ixi/subleaf-host-precision
Jul 3, 2025
Merged

iximeow merged 2 commits into
masterfrom
ixi/subleaf-host-precision

Conversation

@iximeow

@iximeow iximeow commented Jul 2, 2025

Copy link
Copy Markdown
Member

We would report a few CPUID leaves as not having subleaves at all. Guests that try to interrogate CPUID leaves according to the APM then could end up very confused since later "subleaves" would just be repetitions of the single first leaf we queried from the host.

For leaves F, 10, and 8000_0020, I've chosen to hide the otherwise-unsupported-anyway PQM and PQE features from PQoS. If a guest tried to use the PQM/PQE features as-advertised, it should get a #GP anyway. Presumably #GP from a "supported" feature may not be gracefully handled. For 8000_0026, I'm less committed to returning zeroes, but it seems like the least-unreasonable thing to present.

I noticed this from cpuid in a Linux guest printing thousands of bogus 0x8000_0020 leaves on dogfood. That's PQoS feature information, and the APM happens to mention that the appropriate way to query this is to check individual bits in a bit field (implicitly that there are no more than 32 subleaves on that function). In that case it was technically a cpuid bug that resulted in it trying all the other 2^32-32 leaves, but we should be better here.

0x8000_0026 is more likely to matter, but it isn't present on Zen 3 parts.

(while in the product this will be avoided by using the CPUID definitions from RFD 314, this would still crop up when hacking on Propolis locally and it's annoying for "use the host defaults" to result in bogus leaves)

We would report a few CPUID leaves as not having subleaves at all.
Guests that try to interrogate CPUID leaves according to the APM then
could end up very confused since later "subleaves" would just be
repetitions of the single first leaf we queried from the host.

For leaves F, 10, and 8000_0020, I've chosen to hide the
otherwise-unsupported-anyway PQM and PQE features from PQoS. If a guest
tried to use the PQM/PQE features as-advertised, it should get a #GP
anyway. Presumably #GP from a "supported" feature may not be gracefully
handled. For 8000_0026, I'm less committed to returning zeroes, but it
seems like the least-unreasonable thing to present.

I noticed this from `cpuid` in a Linux guest printing thousands of bogus
0x8000_0020 leaves on dogfood. That's PQoS feature information, and the
APM happens to mention that the appropriate way to query this is to
check individual bits in a bit field (implicitly that there are no more
than 32 subleaves on that function). In that case it was technically a
`cpuid` bug that resulted in it trying all the other 2^32-32 leaves, but
we should be better here.

0x8000_0026 is more likely to matter, but it isn't present on Zen 3
parts.
@iximeow
iximeow requested a review from pfmooney July 2, 2025 20:55
Comment thread crates/cpuid-utils/src/host.rs Outdated
let data = query(leaf, 0)?;
let mut data = query(leaf, 0)?;

// Leaf 7 EBX bits 12 and 15 indicate PQM and PQE support on AMD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: I think it would be nice to use the h suffix consistently, even for numbers (7, F) which do not require it for disambiguation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough. it turns out we use 0x prefixes for leaves elsewhere in Propolis anyway, so i've switched to those along the way.

Comment thread crates/cpuid-utils/src/host.rs Outdated
// > returned hierarchy level type (CPUID
// > Fn8000_0026_ECX[LevelType]) is equal to zero
//
// but if the sole leaf has a non-zero ECX[LevelType], it will

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: With this not starting a new sentence, it almost reads like part of the comment was chopped off.

@hawkw hawkw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concerns from me beyond Patrick's comment suggestions.

Comment thread crates/cpuid-utils/src/host.rs Outdated
)?;
}
}
// Leaf F describes Platform QoS Monitoring ("PQM").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for spelling out the acronym <3

@pfmooney pfmooney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

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.

3 participants