Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4732986pxv; Tue, 6 Jul 2021 07:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMB7Svyng6ZCo08m5Djp1Y7ea27Csf3uAbYniyIfuNErqTwFKt+UKowoIqIJbyUe17I6jF X-Received: by 2002:aa7:d982:: with SMTP id u2mr23230544eds.230.1625583376993; Tue, 06 Jul 2021 07:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625583376; cv=none; d=google.com; s=arc-20160816; b=gGMZ75k9zdhcLPBZ9y5e1suoirTT9ebziurJV1FYFr3qUZBL3MCGIuXDofhd3U+sq8 Rcj/C5X4EV6DMZr5yNpuvaJ4lGLaWrk7FitySrfVdamqBJsa3VSNonRGBVdF3ccUSwvA slucXxgldCktP93BXao53CD0I0m9PDpTyApkpyqwXoeaDT4J0aNZxyE05fz/XujJWTx7 3qZjkn5YSLPuOb9hOkZK285QpXR1oRE8anmg2NE9DK7oMwi9XKWMsoe5qzaHuH6HFw14 rF/IH4RJY6yVM0RmObeBQrf0GDd41H78hV+U7HpHYN/XCR36vC/tgKsEoTWMOZ4Kc/te pWKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=ZlKHZBOFtzIcfww4JrhdQyRbEpi1c+RqFo/2UmsBVj0=; b=m0OPMsRgd9nMlOVAe7L9KBDNKpk0A75lUN937N+KvUzWzYwHCGQTVHHvhjpkGAv/Qg mpTUGFobPrTA63ypYy3z+xcnz49/c7pXp7XadnY00rhPv3vvzMH9OGjJgIdiQN0tkXeb /N26WtnUwv+04E8svlMgjas4A+ClxlJj3JTrF/2cV/mykwZ36l0o9nRVTy/uNQTzIc44 n20CPjhLKmwwuw2miybjtt261HwxpY9axfmZa4K0BJawb7zKfSrCocq2vg7fCsWVl/zl I71ca9qfqly0ntoh6cz/YTKes2q1/7jA3NbIhkYMi9xHTcqmsYGrxpg8JQm/qnFyOSAT 9z+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pdg0IDnj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si2093103edd.90.2021.07.06.07.55.54; Tue, 06 Jul 2021 07:56:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pdg0IDnj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232643AbhGFOz3 (ORCPT + 99 others); Tue, 6 Jul 2021 10:55:29 -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-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