aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunaid Shahid <junaids@google.com>2016-12-06 19:46:10 -0500
committerRadim Krčmář <rkrcmar@redhat.com>2017-01-09 08:46:05 -0500
commit27959a4415a5a00881a7b9353ab9b1274da2ca47 (patch)
tree5f0a762bd7a1e43e7062c88d446bf4e99259d806
parent114df303a7eeae8b50ebf68229b7e647714a9bea (diff)
kvm: x86: mmu: Use symbolic constants for EPT Violation Exit Qualifications
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>
-rw-r--r--arch/x86/include/asm/vmx.h16
-rw-r--r--arch/x86/kvm/vmx.c22
2 files changed, 30 insertions, 8 deletions
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 2b5b2d4b924e..25a482fb5241 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -500,6 +500,22 @@ struct vmx_msr_entry {
500#define ENTRY_FAIL_VMCS_LINK_PTR 4 500#define ENTRY_FAIL_VMCS_LINK_PTR 4
501 501
502/* 502/*
503 * Exit Qualifications for EPT Violations
504 */
505#define EPT_VIOLATION_READ_BIT 0
506#define EPT_VIOLATION_WRITE_BIT 1
507#define EPT_VIOLATION_INSTR_BIT 2
508#define EPT_VIOLATION_READABLE_BIT 3
509#define EPT_VIOLATION_WRITABLE_BIT 4
510#define EPT_VIOLATION_EXECUTABLE_BIT 5
511#define EPT_VIOLATION_READ (1 << EPT_VIOLATION_READ_BIT)
512#define EPT_VIOLATION_WRITE (1 << EPT_VIOLATION_WRITE_BIT)
513#define EPT_VIOLATION_INSTR (1 << EPT_VIOLATION_INSTR_BIT)
514#define EPT_VIOLATION_READABLE (1 << EPT_VIOLATION_READABLE_BIT)
515#define EPT_VIOLATION_WRITABLE (1 << EPT_VIOLATION_WRITABLE_BIT)
516#define EPT_VIOLATION_EXECUTABLE (1 << EPT_VIOLATION_EXECUTABLE_BIT)
517
518/*
503 * VM-instruction error numbers 519 * VM-instruction error numbers
504 */ 520 */
505enum vm_instruction_error_number { 521enum vm_instruction_error_number {
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index a236decb81e4..81159a3878f4 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -6374,14 +6374,20 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
6374 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); 6374 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
6375 trace_kvm_page_fault(gpa, exit_qualification); 6375 trace_kvm_page_fault(gpa, exit_qualification);
6376 6376
6377 /* it is a read fault? */ 6377 /* Is it a read fault? */
6378 error_code = (exit_qualification << 2) & PFERR_USER_MASK; 6378 error_code = (exit_qualification & EPT_VIOLATION_READ)
6379 /* it is a write fault? */ 6379 ? PFERR_USER_MASK : 0;
6380 error_code |= exit_qualification & PFERR_WRITE_MASK; 6380 /* Is it a write fault? */
6381 /* It is a fetch fault? */ 6381 error_code |= (exit_qualification & EPT_VIOLATION_WRITE)
6382 error_code |= (exit_qualification << 2) & PFERR_FETCH_MASK; 6382 ? PFERR_WRITE_MASK : 0;
6383 /* ept page table is present? */ 6383 /* Is it a fetch fault? */
6384 error_code |= (exit_qualification & 0x38) != 0; 6384 error_code |= (exit_qualification & EPT_VIOLATION_INSTR)
6385 ? PFERR_FETCH_MASK : 0;
6386 /* ept page table entry is present? */
6387 error_code |= (exit_qualification &
6388 (EPT_VIOLATION_READABLE | EPT_VIOLATION_WRITABLE |
6389 EPT_VIOLATION_EXECUTABLE))
6390 ? PFERR_PRESENT_MASK : 0;
6385 6391
6386 vcpu->arch.exit_qualification = exit_qualification; 6392 vcpu->arch.exit_qualification = exit_qualification;
6387 6393