tdx: derive TD ATTRIBUTES/XFAM from guest CPUID and validate GPAW - #19
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
ATTRIBUTES/XFAM are currently derived from the unfiltered CPUID slice while KVM_TDX_INIT_VM is passed a filtered CPUID set, which can create inconsistencies and lead to EINVAL rejections.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the TDX VM initialization flow to derive TD parameters from the guest CPUID view and to align CPUID filtering with what the TDX module/KVM expects, improving compatibility and making failures easier to diagnose.
Changes:
- Clear unsupported CPUID feature bits for TDX (TSX and WAITPKG) on leaf 7 subleaf 0.
- Preserve/encode and validate the TDX GPAW value via CPUID.0x80000008.EAX[23:16] before calling
KVM_TDX_INIT_VM. - Derive TD
ATTRIBUTESandXFAMfrom CPUID via new helper functions and mask them againstKVM_TDX_CAPABILITIES.
File summaries
| File | Description |
|---|---|
| hypervisor/src/kvm/mod.rs | Updates TDX CPUID filtering and derives/masks TD ATTRIBUTES+XFAM for KVM_TDX_INIT_VM, including GPAW validation. |
Review details
Suppressed comments (1)
hypervisor/src/kvm/mod.rs:1143
- This comment is grammatically incorrect and currently misleading: the code derives PERFMON/PKS from whatever CPUID slice is passed in. After switching the derivation to use the filtered CPUID view, update the wording to reflect that PERFMON is currently not requested because the filtered CPUID leaf 0xA is zeroed.
/// The PERFMON never set currently, `KVM_TDX_CAPABILITIES` reports
/// CPUID.(EAX=0xA) as all-zero, so `tdx_filter_cpuid()` always zeroes this
/// leaf before it reaches here.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
liangzhou121
force-pushed
the
zhoul1/dev/cpuid_3
branch
from
September 8, 2026 05:43
46c0ad5 to
1385aca
Compare
tdx_filter_cpuid(): - Clear TSX (HLE bit 4 / RTM bit 11 in EBX) and WAITPKG (bit 5 in ECX) from CPUID leaf 7 subleaf 0, mirroring the kernel's tdx_clear_unsupported_cpuid(). - Encode the TD's GPAW in CPUID.0x80000008.EAX[23:16], the field KVM repurposes for setup_tdparams_eptp_controls(), and validate it is 48 or 52 before submitting it, instead of failing later with an opaque KVM_TDX_INIT_VM EINVAL. tdx_init(): - Derive TD ATTRIBUTES (SEPT_VE_DISABLE, PKS, PERFMON) and XFAM from the guest CPUID view via new tdx_attributes_from_cpuid()/ tdx_xfam_from_cpuid() helpers, replacing the previous hardcoded attributes value (SEPT_VE_DISABLE only). Both are still masked to the configurable set reported by KVM_TDX_CAPABILITIES before being submitted to KVM_TDX_INIT_VM. Signed-off-by: Liang, Zhou <liang1.zhou@intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tdx_filter_cpuid():
tdx_init():