KVM: x86/mmu: Derive EPT violation RWX bits from EPTE RWX bits
authorSean Christopherson <seanjc@google.com>
Tue, 29 Mar 2022 03:01:07 +0000 (11:01 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 13 Apr 2022 17:37:37 +0000 (13:37 -0400)
Derive the mask of RWX bits reported on EPT violations from the mask of
RWX bits that are shoved into EPT entries; the layout is the same, the
EPT violation bits are simply shifted by three.  Use the new shift and a
slight copy-paste of the mask derivation instead of completely open
coding the same to convert between the EPT entry bits and the exit
qualification when synthesizing a nested EPT Violation.

No functional change intended.

Cc: SU Hang <darcy.sh@antgroup.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220329030108.97341-3-darcy.sh@antgroup.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/vmx.h
arch/x86/kvm/mmu/paging_tmpl.h
arch/x86/kvm/vmx/vmx.c

index 3586d4a..6c343c6 100644 (file)
@@ -543,17 +543,13 @@ enum vm_entry_failure_code {
 #define EPT_VIOLATION_ACC_READ_BIT     0
 #define EPT_VIOLATION_ACC_WRITE_BIT    1
 #define EPT_VIOLATION_ACC_INSTR_BIT    2
-#define EPT_VIOLATION_READABLE_BIT     3
-#define EPT_VIOLATION_WRITABLE_BIT     4
-#define EPT_VIOLATION_EXECUTABLE_BIT   5
+#define EPT_VIOLATION_RWX_SHIFT                3
 #define EPT_VIOLATION_GVA_IS_VALID_BIT 7
 #define EPT_VIOLATION_GVA_TRANSLATED_BIT 8
 #define EPT_VIOLATION_ACC_READ         (1 << EPT_VIOLATION_ACC_READ_BIT)
 #define EPT_VIOLATION_ACC_WRITE                (1 << EPT_VIOLATION_ACC_WRITE_BIT)
 #define EPT_VIOLATION_ACC_INSTR                (1 << EPT_VIOLATION_ACC_INSTR_BIT)
-#define EPT_VIOLATION_READABLE         (1 << EPT_VIOLATION_READABLE_BIT)
-#define EPT_VIOLATION_WRITABLE         (1 << EPT_VIOLATION_WRITABLE_BIT)
-#define EPT_VIOLATION_EXECUTABLE       (1 << EPT_VIOLATION_EXECUTABLE_BIT)
+#define EPT_VIOLATION_RWX_MASK         (VMX_EPT_RWX_MASK << EPT_VIOLATION_RWX_SHIFT)
 #define EPT_VIOLATION_GVA_IS_VALID     (1 << EPT_VIOLATION_GVA_IS_VALID_BIT)
 #define EPT_VIOLATION_GVA_TRANSLATED   (1 << EPT_VIOLATION_GVA_TRANSLATED_BIT)
 
index 9c6bdab..1dad8f3 100644 (file)
@@ -523,7 +523,13 @@ error:
                        vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_READ;
                if (fetch_fault)
                        vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_INSTR;
-               vcpu->arch.exit_qualification |= (pte_access & 0x7) << 3;
+
+               /*
+                * Note, pte_access holds the raw RWX bits from the EPTE, not
+                * ACC_*_MASK flags!
+                */
+               vcpu->arch.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) <<
+                                                EPT_VIOLATION_RWX_SHIFT;
        }
 #endif
        walker->fault.address = addr;
index ef0aadb..fb0b0fa 100644 (file)
@@ -5405,9 +5405,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
        error_code |= (exit_qualification & EPT_VIOLATION_ACC_INSTR)
                      ? PFERR_FETCH_MASK : 0;
        /* ept page table entry is present? */
-       error_code |= (exit_qualification &
-                      (EPT_VIOLATION_READABLE | EPT_VIOLATION_WRITABLE |
-                       EPT_VIOLATION_EXECUTABLE))
+       error_code |= (exit_qualification & EPT_VIOLATION_RWX_MASK)
                      ? PFERR_PRESENT_MASK : 0;
 
        error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ?