Skip to content

Commit 3b725e9

Browse files
rpedgecobonzini
authored andcommitted
KVM: VMX: Teach EPT violation helper about private mem
Teach EPT violation helper to check shared mask of a GPA to find out whether the GPA is for private memory. When EPT violation is triggered after TD accessing a private GPA, KVM will exit to user space if the corresponding GFN's attribute is not private. User space will then update GFN's attribute during its memory conversion process. After that, TD will re-access the private GPA and trigger EPT violation again. Only with GFN's attribute matches to private, KVM will fault in private page, map it in mirrored TDP root, and propagate changes to private EPT to resolve the EPT violation. Relying on GFN's attribute tracking xarray to determine if a GFN is private, as for KVM_X86_SW_PROTECTED_VM, may lead to endless EPT violations. Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Co-developed-by: Yan Zhao <yan.y.zhao@intel.com> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> Message-ID: <20241112073539.22056-1-yan.y.zhao@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent c8563d1 commit 3b725e9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

arch/x86/kvm/vmx/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
#include "mmu.h"
88

9+
static inline bool vt_is_tdx_private_gpa(struct kvm *kvm, gpa_t gpa)
10+
{
11+
/* For TDX the direct mask is the shared mask. */
12+
return !kvm_is_addr_direct(kvm, gpa);
13+
}
14+
915
static inline int __vmx_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa,
1016
unsigned long exit_qualification)
1117
{
@@ -28,6 +34,9 @@ static inline int __vmx_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa,
2834
error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) ?
2935
PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK;
3036

37+
if (vt_is_tdx_private_gpa(vcpu->kvm, gpa))
38+
error_code |= PFERR_PRIVATE_ACCESS;
39+
3140
return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
3241
}
3342

0 commit comments

Comments
 (0)