Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1616883rwe; Fri, 2 Sep 2022 00:17:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Oocnmj8WTFbpKF6xyr9UNcMze6YWAPogBaS2kKehOABQr3uhlZVU42XpUYOnsJOvQloi1 X-Received: by 2002:a05:6402:3485:b0:448:a1c8:d640 with SMTP id v5-20020a056402348500b00448a1c8d640mr16207252edc.279.1662103067881; Fri, 02 Sep 2022 00:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662103067; cv=none; d=google.com; s=arc-20160816; b=ldZHvoBqj5JJVrytRL+FTaE8T7PUVzJrxZ5smi7dtkH0E0+DdrxLsVZJZGCltfwZFC qz53q59QYKFPEy85QiRA/mGGr+mCisWH8ZhWofUUg9eMSv5PAP4G4n6KkkxdloHCTMJ1 xwqRjBPxdC78141buBh0e2+vnF8hPCL14q3VNE3up5mVmf3PxArJ8EgDpn6k42FzB+bf owWmEHXOtlmWVPg/O8cU5J6HsOU9DaxriqxfN0XAJNrc0+Wt99C8teb8voZy6k1v1/Fb Fn4ce0teoV3m/jAARbfNbYQ/vqH48y9Xmm/YWl10CjzvXeicFNYa4C50heeCzfzFHRKw uT7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CERYaPDW+1mGaUTwMLZc8ZfWVPoAPYW8aBwqfOaywJM=; b=ak59ZUO0ivZ6/4l0zpflknwd5uYxHbaxg2RyJFY5gvXnv1NlndevJsOYQVzUG3/iTx jg55hbZURGfMW8gvF1je5YEBdyvpTfeDh+6p+gEhxO3lTJXXbV+IU7nq+fqReIexALgx tDJh6laGNRYOPYLrNjHwlEid7L38tQP3tJfS5ZODoHH2Wz4xjW5FFfv58lCw8yBhoBRE t7drh2GUa8vnHjETxga4YkuaKNR7pFsKVokujSdcQkeAyXjI/YWLHaBK8QGY351lgcd1 s510TCIfcNpkN7fL1Gn1iL+gsfLpphJnNto7Fd5GO1oav2jcvBriQvsysSYxzMSwcN0u amFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HIMzcrbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr6-20020a1709073f8600b00738545f4076si1367509ejc.286.2022.09.02.00.17.20; Fri, 02 Sep 2022 00:17:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HIMzcrbZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235332AbiIBHGV (ORCPT + 99 others); Fri, 2 Sep 2022 03:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235475AbiIBHGN (ORCPT ); Fri, 2 Sep 2022 03:06:13 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C743ED6A; Fri, 2 Sep 2022 00:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662102320; x=1693638320; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=xcDo/D2QvP8U4j+89T0M37m9pNJoQwtOiHvvxnTTBGs=; b=HIMzcrbZeC5+AKOp8YtZ0dFRBDU50Q4tvHvGRXSlq/NMK9/s4486YDL1 r73ixEdBwVFMiZ6OiTqrjDoVuCL6pLHPzrI2uiTf+n5x3zBkxDhMkc41V qW5b+jLpbV+0zFrUIcXN6MlzUx/igoBYeWlXVkoq0VxzqLXKrUzGwQ7YP yQdhhLlSpG5PAv8+mzyMaIY0NfNyuqOyIdRMMvf6YV8+n9E8RY+M46R9T pvx/9zKbFOGHUGpcUVxNNmI/Iay2O5L72VpJCalfvmoq2vrEVhhhfZ2vV lqrmPiXKrPbXQF5vk3mpZBgaDXxT/FhJxy1XMY5WCQua89EuKTQMbt2n7 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10457"; a="293489203" X-IronPort-AV: E=Sophos;i="5.93,283,1654585200"; d="scan'208";a="293489203" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2022 00:05:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,283,1654585200"; d="scan'208";a="642795114" Received: from yy-desk-7060.sh.intel.com (HELO localhost) ([10.239.159.76]) by orsmga008.jf.intel.com with ESMTP; 02 Sep 2022 00:05:18 -0700 Date: Fri, 2 Sep 2022 15:05:17 +0800 From: Yuan Yao To: isaku.yamahata@intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar Subject: Re: [PATCH v8 048/103] KVM: VMX: Split out guts of EPT violation to common/exposed function Message-ID: <20220902070517.ijjciqdvx453bqha@yy-desk-7060> References: <43ba6d1e69e8379fa438fbe15f260c94e2ee8f0b.1659854790.git.isaku.yamahata@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43ba6d1e69e8379fa438fbe15f260c94e2ee8f0b.1659854790.git.isaku.yamahata@intel.com> User-Agent: NeoMutt/20171215 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 07, 2022 at 03:01:33PM -0700, isaku.yamahata@intel.com wrote: > From: Sean Christopherson > > The difference of TDX EPT violation is how to retrieve information, GPA, > and exit qualification. To share the code to handle EPT violation, split > out the guts of EPT violation handler so that VMX/TDX exit handler can call > it after retrieving GPA and exit qualification. > > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > Reviewed-by: Paolo Bonzini > Reviewed-by: Kai Huang Reviewed-by: Yuan Yao > --- > arch/x86/kvm/vmx/common.h | 33 +++++++++++++++++++++++++++++++++ > arch/x86/kvm/vmx/vmx.c | 29 +++++------------------------ > 2 files changed, 38 insertions(+), 24 deletions(-) > create mode 100644 arch/x86/kvm/vmx/common.h > > diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h > new file mode 100644 > index 000000000000..235908f3e044 > --- /dev/null > +++ b/arch/x86/kvm/vmx/common.h > @@ -0,0 +1,33 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +#ifndef __KVM_X86_VMX_COMMON_H > +#define __KVM_X86_VMX_COMMON_H > + > +#include > + > +#include "mmu.h" > + > +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_RWX_MASK) > + ? 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 4a3b3dc5d4d2..3af8cd164274 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -50,6 +50,7 @@ > #include > > #include "capabilities.h" > +#include "common.h" > #include "cpuid.h" > #include "evmcs.h" > #include "hyperv.h" > @@ -5646,11 +5647,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, > @@ -5663,25 +5663,6 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) > (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_RWX_MASK) > - ? 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; > > /* > @@ -5695,7 +5676,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) > -- > 2.25.1 >