Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp321740imw; Fri, 8 Jul 2022 03:44:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vjYzDL4Xb2Ds9B2PK/Zwy/pZfmN03znLb/W1fSqVw/qY9X1JKqGeKNJyDRuzaHQI0F1YKv X-Received: by 2002:a05:6402:358c:b0:435:9daf:e825 with SMTP id y12-20020a056402358c00b004359dafe825mr3813431edc.375.1657277049508; Fri, 08 Jul 2022 03:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657277049; cv=none; d=google.com; s=arc-20160816; b=xiabCGvGOZeeQOB+6e2DRJi5Aww7bs6eU0zJXWdJj6kLggHFxDWI7oL3zzrxmXvWtW avfteL+sMAmMAmfL2IBmtpLnc49F+lG3v8RxhUFJoqRZmqUvrRhOsjnPSTHeKqbzrCtm 5iWWZYnxyspkOZXqXDsMAUOfpCChV7q7MrSIs0oEFzK+L8iNoe27epOGUPKEGb+d7HQA +mhFITvKhFRNw3p32t6zSbdSqXCcuQGog6xuRbcXt9q4ti9qKlwcSzhnpsja1L4RIkwD DspPwYEDxfMCfHhBDqSvuubIDMFHuUwGGvwBPwparlkGOz4ZQYp+72XCEy0ZROYwcto4 nmOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=CwFoJ+e+2RCNNNphHbbMZXuWnfG2NrS5Kj5iwwgdAfQ=; b=BY67LGlYuabqt9VpsFjjLvO63YIPMfyDF7C+PQIKPB9DFD/tXtf/yiNbtiqdFCMOwi mH1Kq00sMoxBAgV9PYbqtoNtJbsKfzlypvpVAUnT8PHjuoD7Rw7CtmS+FTBeDKMt+iHT IS/ZqBupgk4qYJZjFiUPWWlqDlyQnugG3gMny0Wil+WZjprUA0bhTE5Vw1yZpN/vtwK7 hXP+EDBtaj1WH67JtivS1M3pgAADUQFJbKrnziQU02aNmQsQqacIwHVEhfrvbm1xcMvz cInluBpzy122IU68+kTDCMYF0dk2AMrbvM1tTa/SDz9Hb61lzBn+UV+cLS1h70XIiPdq cFuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Z2D4Vle8; 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 g11-20020a1709065d0b00b006fe9a0289d5si4648056ejt.885.2022.07.08.03.43.40; Fri, 08 Jul 2022 03:44:09 -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=Z2D4Vle8; 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 S237243AbiGHKZg (ORCPT + 99 others); Fri, 8 Jul 2022 06:25:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236895AbiGHKZe (ORCPT ); Fri, 8 Jul 2022 06:25:34 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670A322BFB; Fri, 8 Jul 2022 03:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657275933; x=1688811933; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=Q+E4LoDet/Mx5+pBeJs1uVYlUAFyEaQJKSz+LHQc2b4=; b=Z2D4Vle85WLNIJK3rtEYxeiMnqVuuezFYHveHVjXyXbUNaWg4Ir5nkJ3 6Bt7/wg/zBvP/rGUHTL049+eDbTk0ywjjgX5rzsiQStjmUtdGb4xQiY9M BLujtJ76dsOR9xEnFQtaANSvlbZ68G14Tw3v0E6j/uAJLmgQjc9jYPkOM okAhVh1+dK5CzrZXM5jQEgsF9K2iL+tiriKWwA2jd5ADiv48AE/xmVvaq 3ldqYoh9YhvX7UZmBDLx63wrL1iaIhFpcmX0pV15bEyhACx5q4/Db+Mcy 0MVwDa0Lvo71d41Xo85fcNRIBHVz7C7J0XlZRB9tv7YHd0lsja9xaIqT6 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10401"; a="285378336" X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="285378336" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 03:25:09 -0700 X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="626664222" Received: from pantones-mobl1.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.212.54.208]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 03:25:07 -0700 Message-ID: <5085857e16cdb133803ee3edf3b1e8b776b2a7b1.camel@intel.com> Subject: Re: [PATCH v7 050/102] KVM: VMX: Split out guts of EPT violation to common/exposed function From: Kai Huang To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson Date: Fri, 08 Jul 2022 22:25:05 +1200 In-Reply-To: <5202bef37eb1d9683891f29ccba182bbdceafca4.1656366338.git.isaku.yamahata@intel.com> References: <5202bef37eb1d9683891f29ccba182bbdceafca4.1656366338.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.2 (3.44.2-1.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 Mon, 2022-06-27 at 14:53 -0700, isaku.yamahata@intel.com wrote: > From: Sean Christopherson >=20 > 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 ca= ll > it after retrieving GPA and exit qualification. >=20 > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > Reviewed-by: Paolo Bonzini > --- > arch/x86/kvm/vmx/common.h | 33 +++++++++++++++++++++++++++++++++ > arch/x86/kvm/vmx/vmx.c | 32 ++++++-------------------------- > 2 files changed, 39 insertions(+), 26 deletions(-) > create mode 100644 arch/x86/kvm/vmx/common.h >=20 > 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 =3D (exit_qualification & EPT_VIOLATION_ACC_READ) > + ? PFERR_USER_MASK : 0; > + /* Is it a write fault? */ > + error_code |=3D (exit_qualification & EPT_VIOLATION_ACC_WRITE) > + ? PFERR_WRITE_MASK : 0; > + /* Is it a fetch fault? */ > + error_code |=3D (exit_qualification & EPT_VIOLATION_ACC_INSTR) > + ? PFERR_FETCH_MASK : 0; > + /* ept page table entry is present? */ > + error_code |=3D (exit_qualification & EPT_VIOLATION_RWX_MASK) > + ? PFERR_PRESENT_MASK : 0; > + > + error_code |=3D (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != =3D 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 e3d304b14df0..2f1dc06aec3c 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -50,6 +50,7 @@ > #include > =20 > #include "capabilities.h" > +#include "common.h" > #include "cpuid.h" > #include "evmcs.h" > #include "hyperv.h" > @@ -5578,11 +5579,10 @@ static int handle_task_switch(struct kvm_vcpu *vc= pu) > =20 > static int handle_ept_violation(struct kvm_vcpu *vcpu) > { > - unsigned long exit_qualification; > - gpa_t gpa; > - u64 error_code; > + unsigned long exit_qualification =3D vmx_get_exit_qual(vcpu); > + gpa_t gpa =3D vmcs_read64(GUEST_PHYSICAL_ADDRESS); > =20 > - exit_qualification =3D vmx_get_exit_qual(vcpu); > + trace_kvm_page_fault(gpa, exit_qualification); > =20 > /* > * EPT violation happened while executing iret from NMI, > @@ -5591,29 +5591,9 @@ static int handle_ept_violation(struct kvm_vcpu *v= cpu) > * 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)) Why this code change? With this removed: Reviewed-by: Kai Huang > vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO, GUEST_INTR_STATE_NMI); > =20 > - gpa =3D vmcs_read64(GUEST_PHYSICAL_ADDRESS); > - trace_kvm_page_fault(gpa, exit_qualification); > - > - /* Is it a read fault? */ > - error_code =3D (exit_qualification & EPT_VIOLATION_ACC_READ) > - ? PFERR_USER_MASK : 0; > - /* Is it a write fault? */ > - error_code |=3D (exit_qualification & EPT_VIOLATION_ACC_WRITE) > - ? PFERR_WRITE_MASK : 0; > - /* Is it a fetch fault? */ > - error_code |=3D (exit_qualification & EPT_VIOLATION_ACC_INSTR) > - ? PFERR_FETCH_MASK : 0; > - /* ept page table entry is present? */ > - error_code |=3D (exit_qualification & EPT_VIOLATION_RWX_MASK) > - ? PFERR_PRESENT_MASK : 0; > - > - error_code |=3D (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != =3D 0 ? > - PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; > - > vcpu->arch.exit_qualification =3D exit_qualification; > =20 > /* > @@ -5627,7 +5607,7 @@ static int handle_ept_violation(struct kvm_vcpu *vc= pu) > if (unlikely(allow_smaller_maxphyaddr && kvm_vcpu_is_illegal_gpa(vcpu, = gpa))) > return kvm_emulate_instruction(vcpu, 0); > =20 > - return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0); > + return __vmx_handle_ept_violation(vcpu, gpa, exit_qualification); > } > =20 > static int handle_ept_misconfig(struct kvm_vcpu *vcpu)