diff options
| author | Sean Christopherson <seanjc@google.com> | 2026-09-02 16:09:31 -0700 |
|---|---|---|
| committer | Sean Christopherson <seanjc@google.com> | 2026-09-11 15:41:59 -0700 |
| commit | cc8a8f2a90b45cd4c8509db7bc61c2ac9dbd2cf2 (patch) | |
| tree | 4b611cf112a324d9957423f78404e7d24fde429b /tools/perf/scripts/python/task-analyzer.py | |
| parent | 7ed619909773d1cc2d026b63b003010693ef0c5f (diff) | |
KVM: VMX: Explicitly track TDX VMs' root level instead of guessing it from CPUID
Explicitly track the root level for TDX VMs instead of trying to infer the
depth of the paging tree based on an individual vCPU's CPUID information.
Applying KVM's existing logic to select the root level to TDX is flawed as
nothing *requires* userspace to fill in the correct guest.MAXPHYADDR for a
vCPU's CPUID. Guessing at the correct root level is also ridiculous given
that userspace has already told KVM the root level during TD initialization.
Relying on userspace to set the expected/correct CPUID lets a misbehaving
userspace trip the KVM_BUG_ON() in tdx_load_mmu_pgd() by configuring guest
CPUID to use an "incorrect" guest.MAXPHYADDR.
Don't use kvm_gfn_direct_bits() to infer the mirror root level, as the
connection between TDX's one and only "direct" bit and the predetermined
root level is a TDX implementation detail. I.e. avoid baking in the
assumption that there is exactly one "direct bits", that the one bit is a
pivot between normal and mirror roots, and that the pivot bit is the most
significant bit of the effective GPA space. For the same reason, set the
root level and direct bits in TDX code, i.e. don't provide a helper in the
MMU, because from the MMU's perspective, they are two separate concepts.
Keep gfn_direct_bits even though it can be trivially derived from
mirror_root_level as saving a whole eight bytes per VM is meaningless,
keeping the TDX details buried in TDX would require a kvm_x86_ops hook, and
the value is queried fairly often and in hot paths.
And for the moment, keep the S-bit sanity check in tdx_load_mmu_pgd(), even
though it really only needs to ensure the incoming level matches the
preconfigured mirror root level. Because KVM manually configures the
S-bit location, there's technically a risk that the S-bit location and
mirror root level could get out of sync. That can be addressed by more
programmatically computing the S-bit, but that doesn't need to be done now.
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: Kai Huang <kai.huang@intel.com>
Cc: Yan Zhao <yan.y.zhao@intel.com>
Fixes: 20d913729c11 ("KVM: x86/mmu: Taking guest pa into consideration when calculate tdp level")
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Tested-by: Yan Zhao <yan.y.zhao@intel.com>
Tested-by: Binbin Wu <binbin.wu@linux.intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://patch.msgid.link/20260902230932.2760127-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/perf/scripts/python/task-analyzer.py')
0 files changed, 0 insertions, 0 deletions
