Skip to content

tdx: derive TD ATTRIBUTES/XFAM from guest CPUID and validate GPAW - #19

Merged
guzongmin merged 1 commit into
mainfrom
zhoul1/dev/cpuid_3
Sep 8, 2026
Merged

tdx: derive TD ATTRIBUTES/XFAM from guest CPUID and validate GPAW#19
guzongmin merged 1 commit into
mainfrom
zhoul1/dev/cpuid_3

Conversation

@liangzhou121

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 ATTRIBUTES and XFAM from CPUID via new helper functions and mask them against KVM_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.

Comment thread hypervisor/src/kvm/mod.rs
Comment thread hypervisor/src/kvm/mod.rs

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

LGTM

@guzongmin
guzongmin merged commit ffe8ef1 into main Sep 8, 2026
16 of 41 checks passed
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>
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