Skip to content

Commit 90fe64a

Browse files
yanzhao56bonzini
authored andcommitted
KVM: TDX: KVM: TDX: Always honor guest PAT on TDX enabled guests
Always honor guest PAT in KVM-managed EPTs on TDX enabled guests by making self-snoop feature a hard dependency for TDX and making quirk KVM_X86_QUIRK_IGNORE_GUEST_PAT not a valid quirk once TDX is enabled. The quirk KVM_X86_QUIRK_IGNORE_GUEST_PAT only affects memory type of KVM-managed EPTs. For the TDX-module-managed private EPT, memory type is always forced to WB now. Honoring guest PAT in KVM-managed EPTs ensures KVM does not invoke kvm_zap_gfn_range() when attaching/detaching non-coherent DMA devices, which would cause mirrored EPTs for TDs to be zapped, leading to the TDX-module-managed private EPT being incorrectly zapped. As a new feature, TDX always comes with support for self-snoop, and does not have to worry about unmodifiable but buggy guests. So, simply ignore KVM_X86_QUIRK_IGNORE_GUEST_PAT on TDX guests just like kvm-amd.ko already does. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> Message-ID: <20250224071039.31511-1-yan.y.zhao@intel.com> [Only apply to TDX guests. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 3fee483 commit 90fe64a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ int tdx_vm_init(struct kvm *kvm)
625625

626626
kvm->arch.has_protected_state = true;
627627
kvm->arch.has_private_mem = true;
628+
kvm->arch.disabled_quirks |= KVM_X86_QUIRK_IGNORE_GUEST_PAT;
628629

629630
/*
630631
* Because guest TD is protected, VMM can't parse the instruction in TD.
@@ -3475,6 +3476,11 @@ int __init tdx_bringup(void)
34753476
goto success_disable_tdx;
34763477
}
34773478

3479+
if (!cpu_feature_enabled(X86_FEATURE_SELFSNOOP)) {
3480+
pr_err("Self-snoop is required for TDX\n");
3481+
goto success_disable_tdx;
3482+
}
3483+
34783484
if (!cpu_feature_enabled(X86_FEATURE_TDX_HOST_PLATFORM)) {
34793485
pr_err("tdx: no TDX private KeyIDs available\n");
34803486
goto success_disable_tdx;

0 commit comments

Comments
 (0)