Skip to content

Commit

Permalink
kvm: x86: mmu: Use symbolic constants for EPT Violation Exit Qualific…
Browse files Browse the repository at this point in the history
…ations

This change adds some symbolic constants for VM Exit Qualifications
related to EPT Violations and updates handle_ept_violation() to use
these constants instead of hard-coded numbers.

Signed-off-by: Junaid Shahid <junaids@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Junaid Shahid authored and Radim Krčmář committed Jan 9, 2017
1 parent 114df30 commit 27959a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 16 additions & 0 deletions arch/x86/include/asm/vmx.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,22 @@ struct vmx_msr_entry {
#define ENTRY_FAIL_NMI 3
#define ENTRY_FAIL_VMCS_LINK_PTR 4

/*
* Exit Qualifications for EPT Violations
*/
#define EPT_VIOLATION_READ_BIT 0
#define EPT_VIOLATION_WRITE_BIT 1
#define EPT_VIOLATION_INSTR_BIT 2
#define EPT_VIOLATION_READABLE_BIT 3
#define EPT_VIOLATION_WRITABLE_BIT 4
#define EPT_VIOLATION_EXECUTABLE_BIT 5
#define EPT_VIOLATION_READ (1 << EPT_VIOLATION_READ_BIT)
#define EPT_VIOLATION_WRITE (1 << EPT_VIOLATION_WRITE_BIT)
#define EPT_VIOLATION_INSTR (1 << EPT_VIOLATION_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)

/*
* VM-instruction error numbers
*/
Expand Down
22 changes: 14 additions & 8 deletions arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6374,14 +6374,20 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
trace_kvm_page_fault(gpa, exit_qualification);

/* it is a read fault? */
error_code = (exit_qualification << 2) & PFERR_USER_MASK;
/* it is a write fault? */
error_code |= exit_qualification & PFERR_WRITE_MASK;
/* It is a fetch fault? */
error_code |= (exit_qualification << 2) & PFERR_FETCH_MASK;
/* ept page table is present? */
error_code |= (exit_qualification & 0x38) != 0;
/* Is it a read fault? */
error_code = (exit_qualification & EPT_VIOLATION_READ)
? PFERR_USER_MASK : 0;
/* Is it a write fault? */
error_code |= (exit_qualification & EPT_VIOLATION_WRITE)
? PFERR_WRITE_MASK : 0;
/* Is it a fetch fault? */
error_code |= (exit_qualification & EPT_VIOLATION_INSTR)
? PFERR_FETCH_MASK : 0;
/* ept page table entry is present? */
error_code |= (exit_qualification &
(EPT_VIOLATION_READABLE | EPT_VIOLATION_WRITABLE |
EPT_VIOLATION_EXECUTABLE))
? PFERR_PRESENT_MASK : 0;

vcpu->arch.exit_qualification = exit_qualification;

Expand Down

0 comments on commit 27959a4

Please sign in to comment.