From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1784EC07E9E for ; Tue, 6 Jul 2021 14:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05FEA61380 for ; Tue, 6 Jul 2021 14:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232650AbhGFOzb (ORCPT ); Tue, 6 Jul 2021 10:55:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26810 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232600AbhGFOzY (ORCPT ); Tue, 6 Jul 2021 10:55:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625583165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZlKHZBOFtzIcfww4JrhdQyRbEpi1c+RqFo/2UmsBVj0=; b=Pdg0IDnj3wpoFOxUvPzbeHCI3/9mnKmjdAz9rEeS7am84Qsw5XiEjSUVKAeznWE6Ti7GnO Ri8qsYW22jlJa4aJIc0ynU9Ly+fU9m38ID2f0/BMTh4qQcSU/3ha4Nlt16rdh5nw5ca6og QEPStG20k5dS4kM5UvaRijqELYcoyOk= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-RWxZJ2pmN3W5_0rtKV2lKQ-1; Tue, 06 Jul 2021 10:52:44 -0400 X-MC-Unique: RWxZJ2pmN3W5_0rtKV2lKQ-1 Received: by mail-ed1-f72.google.com with SMTP id i19-20020a05640200d3b02903948b71f25cso10927959edu.4 for ; Tue, 06 Jul 2021 07:52:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZlKHZBOFtzIcfww4JrhdQyRbEpi1c+RqFo/2UmsBVj0=; b=hlxhYeZ0LehzInf8U60T6qU9bvttolh0jepWHTKu+EHUNJLBhiryei1ELU+ZTOwu/0 7xLUITAbMtQtoxyksqSCiW3JMUfkoSGPZH6Jek+n3IyMBVRmvJ9I1I5W0Cf8d1if/1Hu gywygOWGQF7lnmPq+UxDyK/ciluF11nLJz/MCd97wTDMmlCM6NJCmzShUvN6i+y2eVcA e9tVLesaEU3yTdHJZI1k/SrstnSwEDbKNu/f+clrCt3sWVh1rZQn4eShdMDADyGujCLE pgyZqAGJaqHc8oQNlRtOxvyXjhabI+L7uCLP8maCiWqmybzqtR+0RaS9a7cvkK1iSR9A swUw== X-Gm-Message-State: AOAM532aN6VTlPlZbTAy5YeaFHikLBxhTov9v92lsYLUvlhyWoBtej7u GutucXSbOx2metGClaFtWjx3ePZNQ9Ffqdv8eAMvfSTALU98UNefAgdPEXXJX5GZyjNyQoie23p Mm7r5VKgoYp3xlOY+Ek9O5ODf X-Received: by 2002:a17:906:9b8f:: with SMTP id dd15mr14650117ejc.77.1625583163186; Tue, 06 Jul 2021 07:52:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybwVNPdcLr1AvMM3eRhz7ACzYUDsNh+IZyNcfinFweWQHgNjZLYge6y/4/pKirCODKxhQxLA== X-Received: by 2002:a17:906:9b8f:: with SMTP id dd15mr14650097ejc.77.1625583163024; Tue, 06 Jul 2021 07:52:43 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id y17sm1198961ejd.16.2021.07.06.07.52.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jul 2021 07:52:42 -0700 (PDT) Subject: Re: [RFC PATCH v2 52/69] KVM: VMX: Split out guts of EPT violation to common/exposed function To: isaku.yamahata@intel.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@gmail.com, Sean Christopherson References: <8e246d479e8986172d19704ef4ef4d2b666d5ac1.1625186503.git.isaku.yamahata@intel.com> From: Paolo Bonzini Message-ID: <6e129879-bb76-622e-19a9-afb62fcf864b@redhat.com> Date: Tue, 6 Jul 2021 16:52:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <8e246d479e8986172d19704ef4ef4d2b666d5ac1.1625186503.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/07/21 00:04, isaku.yamahata@intel.com wrote: > From: Sean Christopherson > > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > --- > arch/x86/kvm/vmx/common.h | 29 +++++++++++++++++++++++++++++ > arch/x86/kvm/vmx/vmx.c | 33 +++++---------------------------- > 2 files changed, 34 insertions(+), 28 deletions(-) > > diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h > index 81c73f30d01d..9e5865b05d47 100644 > --- a/arch/x86/kvm/vmx/common.h > +++ b/arch/x86/kvm/vmx/common.h > @@ -5,8 +5,11 @@ > #include > > #include > +#include > > +#include "mmu.h" > #include "vmcs.h" > +#include "vmx.h" > #include "x86.h" > > extern unsigned long vmx_host_idt_base; > @@ -49,4 +52,30 @@ static inline void vmx_handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu, > vmx_handle_interrupt_nmi_irqoff(vcpu, gate_offset(desc)); > } > > +static inline int __vmx_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa, > + unsigned long exit_qualification) > +{ > + u64 error_code; > + > + /* Is it a read fault? */ > + error_code = (exit_qualification & EPT_VIOLATION_ACC_READ) > + ? PFERR_USER_MASK : 0; > + /* Is it a write fault? */ > + error_code |= (exit_qualification & EPT_VIOLATION_ACC_WRITE) > + ? PFERR_WRITE_MASK : 0; > + /* Is it a fetch fault? */ > + 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)) > + ? PFERR_PRESENT_MASK : 0; > + > + error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ? > + PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; > + > + return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); > +} > + > #endif /* __KVM_X86_VMX_COMMON_H */ > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 452d4d1400db..8a104a54121b 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5328,11 +5328,10 @@ static int handle_task_switch(struct kvm_vcpu *vcpu) > > static int handle_ept_violation(struct kvm_vcpu *vcpu) > { > - unsigned long exit_qualification; > - gpa_t gpa; > - u64 error_code; > + unsigned long exit_qualification = vmx_get_exit_qual(vcpu); > + gpa_t gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); > > - exit_qualification = vmx_get_exit_qual(vcpu); > + trace_kvm_page_fault(gpa, exit_qualification); > > /* > * EPT violation happened while executing iret from NMI, > @@ -5341,31 +5340,9 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) > * AAK134, BY25. > */ > if (!(to_vmx(vcpu)->idt_vectoring_info & VECTORING_INFO_VALID_MASK) && > - enable_vnmi && > - (exit_qualification & INTR_INFO_UNBLOCK_NMI)) > + enable_vnmi && (exit_qualification & INTR_INFO_UNBLOCK_NMI)) > vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO, GUEST_INTR_STATE_NMI); > > - gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); > - trace_kvm_page_fault(gpa, exit_qualification); > - > - /* Is it a read fault? */ > - error_code = (exit_qualification & EPT_VIOLATION_ACC_READ) > - ? PFERR_USER_MASK : 0; > - /* Is it a write fault? */ > - error_code |= (exit_qualification & EPT_VIOLATION_ACC_WRITE) > - ? PFERR_WRITE_MASK : 0; > - /* Is it a fetch fault? */ > - 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)) > - ? PFERR_PRESENT_MASK : 0; > - > - error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ? > - PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; > - > vcpu->arch.exit_qualification = exit_qualification; > > /* > @@ -5379,7 +5356,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) > if (unlikely(allow_smaller_maxphyaddr && kvm_vcpu_is_illegal_gpa(vcpu, gpa))) > return kvm_emulate_instruction(vcpu, 0); > > - return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); > + return __vmx_handle_ept_violation(vcpu, gpa, exit_qualification); > } > > static int handle_ept_misconfig(struct kvm_vcpu *vcpu) > This should be in main.c, not in a header (and named __vt_handle_ept_qualification). Paolo