From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 1/4] kvm: x86: mmu: Use symbolic constants for EPT Violation Exit Qualifications Date: Wed, 2 Nov 2016 19:03:45 +0100 Message-ID: <78ff83b5-0694-a093-191b-ee6fabfbe1cc@redhat.com> References: <06c553d31bc838c33dc151f3ab038ecee2da305f.1476839873.git.junaids@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: andreslc@google.com, pfeiner@google.com To: Junaid Shahid , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:41760 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756505AbcKBSDt (ORCPT ); Wed, 2 Nov 2016 14:03:49 -0400 In-Reply-To: <06c553d31bc838c33dc151f3ab038ecee2da305f.1476839873.git.junaids@google.com> Sender: kvm-owner@vger.kernel.org List-ID: On 27/10/2016 04:19, Junaid Shahid wrote: > 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 > --- > arch/x86/include/asm/vmx.h | 16 ++++++++++++++++ > arch/x86/kvm/vmx.c | 20 ++++++++++++-------- > 2 files changed, 28 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h > index a002b07..60991fb 100644 > --- a/arch/x86/include/asm/vmx.h > +++ b/arch/x86/include/asm/vmx.h > @@ -465,6 +465,22 @@ struct vmx_msr_entry { > #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 > */ > enum vm_instruction_error_number { > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index cf1b16d..859da8e 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -6170,14 +6170,18 @@ 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_BIT) & 1) > + << PFERR_USER_BIT; > + /* Is it a write fault? */ > + error_code |= ((exit_qualification >> EPT_VIOLATION_WRITE_BIT) & 1) > + << PFERR_WRITE_BIT; > + /* Is it a fetch fault? */ > + error_code |= ((exit_qualification >> EPT_VIOLATION_INSTR_BIT) & 1) > + << PFERR_FETCH_BIT; > + /* ept page table entry is present? */ > + error_code |= ((exit_qualification >> EPT_VIOLATION_READABLE_BIT) & 1) This last line is not enough now that nested VMX supports execute-only pages. Paolo > + << PFERR_PRESENT_BIT; > > vcpu->arch.exit_qualification = exit_qualification; > >