Skip to content

tdx: mask CPUID.0xD using TDX supported_xfam - #18

Merged
guzongmin merged 1 commit into
mainfrom
zhoul1/dev/cpuid_2
Sep 7, 2026
Merged

tdx: mask CPUID.0xD using TDX supported_xfam#18
guzongmin merged 1 commit into
mainfrom
zhoul1/dev/cpuid_2

Conversation

@liangzhou121

Copy link
Copy Markdown
Contributor

No description provided.

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

The new TDX CPUID.0xD masking should also zero masked-out per-state subleafs (and align advertised XFAM with the CET-masked XFAM used during TDX init) to avoid exposing inconsistent/unsupported XSAVE component data to the guest.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates x86 CPUID generation to support TDX by masking CPUID leaf 0xD (XSAVE state) based on TDX supported_xfam, wiring a VM handle into the CPUID generation path when TDX is enabled.

Changes:

  • Extend arch::generate_common_cpuid() (under feature = "tdx") to optionally take a VM handle and apply TDX-specific CPUID.0xD masking.
  • Update VMM call sites to pass a VM handle when generating CPUID for TDX-capable builds, and pass None in snapshot/migration paths that explicitly disallow TDX.
  • Add TDX-specific CPUID configuration helper to apply the supported_xfam mask.
File summaries
File Description
arch/src/x86_64/mod.rs Adds TDX-aware CPUID generation by masking CPUID.0xD using TDX capabilities fetched from the VM.
vmm/src/cpu.rs Passes TDX mode (including VM handle) into common CPUID generation when TDX is enabled.
vmm/src/lib.rs Updates migration CPUID generation call sites for TDX-enabled builds (passing None since TDX migration is rejected).
vmm/src/vm.rs Updates snapshot CPUID generation call site for TDX-enabled builds (passing None since TDX snapshot is rejected).
Review details
  • Files reviewed: 4/4 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 arch/src/x86_64/mod.rs
Comment thread arch/src/x86_64/mod.rs Outdated
@liangzhou121
liangzhou121 force-pushed the zhoul1/dev/cpuid_2 branch 3 times, most recently from 0450269 to c44de53 Compare September 7, 2026 06:26

@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

Comment thread arch/src/x86_64/mod.rs
} else if entry.index == 1 {
entry.ecx &= (caps.supported_xfam as u32) & (xss_mask as u32);
entry.edx &= ((caps.supported_xfam & xss_mask) >> 32) as u32;
}

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.

// Bit 8: PT (Processor Trace)
// Bit 11: CET_U (User Shadow Stack)
// Bit 12: CET_S (Supervisor Shadow Stack)
// Bit 13: HDC
// Bit 14: UINTR (User Interrupts)
// Bit 15: LBR (Last Branch Record)
const XSS_PT_BIT: u64 = 8;
const XSS_CET_U_BIT: u64 = 11;
const XSS_CET_S_BIT: u64 = 12;
const XSS_HDC_BIT: u64 = 13;
const XSS_UINTR_BIT: u64 = 14;
const XSS_LBR_BIT: u64 = 15;

let xss_mask: u64 = (1 << XSS_PT_BIT)
| (1 << XSS_CET_U_BIT)
| (1 << XSS_CET_S_BIT)
| (1 << XSS_HDC_BIT)
| (1 << XSS_UINTR_BIT)
| (1 << XSS_LBR_BIT);

better than let xss_mask: u64 = !xcr0_mask;

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