Skip to content

Commit 61146f6

Browse files
committed
KVM: nVMX: Decouple EPT RWX bits from EPT Violation protection bits
Define independent macros for the RWX protection bits that are enumerated via EXIT_QUALIFICATION for EPT Violations, and tie them to the RWX bits in EPT entries via compile-time asserts. Piggybacking the EPTE defines works for now, but it creates holes in the EPT_VIOLATION_xxx macros and will cause headaches if/when KVM emulates Mode-Based Execution (MBEC), or any other features that introduces additional protection information. Opportunistically rename EPT_VIOLATION_RWX_MASK to EPT_VIOLATION_PROT_MASK so that it doesn't become stale if/when MBEC support is added. No functional change intended. Cc: Jon Kohler <jon@nutanix.com> Cc: Nikolay Borisov <nik.borisov@suse.com> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Link: https://lore.kernel.org/r/20250227000705.3199706-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent fa6c8fc commit 61146f6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

arch/x86/include/asm/vmx.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,23 @@ enum vm_entry_failure_code {
580580
/*
581581
* Exit Qualifications for EPT Violations
582582
*/
583-
#define EPT_VIOLATION_RWX_SHIFT 3
584583
#define EPT_VIOLATION_ACC_READ BIT(0)
585584
#define EPT_VIOLATION_ACC_WRITE BIT(1)
586585
#define EPT_VIOLATION_ACC_INSTR BIT(2)
587-
#define EPT_VIOLATION_RWX_MASK (VMX_EPT_RWX_MASK << EPT_VIOLATION_RWX_SHIFT)
586+
#define EPT_VIOLATION_PROT_READ BIT(3)
587+
#define EPT_VIOLATION_PROT_WRITE BIT(4)
588+
#define EPT_VIOLATION_PROT_EXEC BIT(5)
589+
#define EPT_VIOLATION_PROT_MASK (EPT_VIOLATION_PROT_READ | \
590+
EPT_VIOLATION_PROT_WRITE | \
591+
EPT_VIOLATION_PROT_EXEC)
588592
#define EPT_VIOLATION_GVA_IS_VALID BIT(7)
589593
#define EPT_VIOLATION_GVA_TRANSLATED BIT(8)
590594

595+
#define EPT_VIOLATION_RWX_TO_PROT(__epte) (((__epte) & VMX_EPT_RWX_MASK) << 3)
596+
597+
static_assert(EPT_VIOLATION_RWX_TO_PROT(VMX_EPT_RWX_MASK) ==
598+
(EPT_VIOLATION_PROT_READ | EPT_VIOLATION_PROT_WRITE | EPT_VIOLATION_PROT_EXEC));
599+
591600
/*
592601
* Exit Qualifications for NOTIFY VM EXIT
593602
*/

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
510510
* Note, pte_access holds the raw RWX bits from the EPTE, not
511511
* ACC_*_MASK flags!
512512
*/
513-
walker->fault.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) <<
514-
EPT_VIOLATION_RWX_SHIFT;
513+
walker->fault.exit_qualification |= EPT_VIOLATION_RWX_TO_PROT(pte_access);
515514
}
516515
#endif
517516
walker->fault.address = addr;

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5822,7 +5822,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
58225822
error_code |= (exit_qualification & EPT_VIOLATION_ACC_INSTR)
58235823
? PFERR_FETCH_MASK : 0;
58245824
/* ept page table entry is present? */
5825-
error_code |= (exit_qualification & EPT_VIOLATION_RWX_MASK)
5825+
error_code |= (exit_qualification & EPT_VIOLATION_PROT_MASK)
58265826
? PFERR_PRESENT_MASK : 0;
58275827

58285828
if (error_code & EPT_VIOLATION_GVA_IS_VALID)

0 commit comments

Comments
 (0)