Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp947550pxb; Wed, 6 Apr 2022 05:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn9yF1JFB7eTBnRHuK+Qze1YuiNMmeAmbq8LKcnpjbjUfcjSCSZOf4XScYprWd/1iFnxjO X-Received: by 2002:a05:6a00:300d:b0:4fa:8327:88c7 with SMTP id ay13-20020a056a00300d00b004fa832788c7mr8663082pfb.16.1649246690542; Wed, 06 Apr 2022 05:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246690; cv=none; d=google.com; s=arc-20160816; b=dtptyVN3oDyiHlzUpnBhsRsHX30kKoe7aOVpWEcvQgIR2WT5UwrzOW6evXYXwm8wFX JN/WbZ5HvYN7ZH+xGLgNXzNj8spSZfmukLIhlKB1np9b7jOKdfSVA7ywGzvdSi2Ze7dB 4seD9+YF3ERXxRHA8bRGngIuuMdPAptwxJe9GSpYGtm2JvNMvvHT07RksgzxWA/mu8jK q7Rf7uzt1BjKwqYEo6vim5o3n9KMbwm4kevA+CTj8eCCyvxiN01aDVlYG7rTu4XWfuqS fK6jY4Ee+QZwGUE/wToa7UQUxzXfQhcfRHdlfNqiA3sJ65Ae19n6EuVbUdpgBNkoHhot vDRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:sender:dkim-signature; bh=1mH+YSU50fajcvK1QNZ8qQyJ60qjkNCXhuT3a6pQSAs=; b=XbPf7cL/NGD6RduSh4vkqfGyPQgyofMG37agtTCp6cGPkdQQtZ5FwaTxbjR5A9dUh2 eLZJjqADtha+MhrNaMDA07Z+6/4iDc+h6JW4HqAzPpijOJcYbZlv7lHQPO5NffTR6kZF O+8BGVoPIyHCDSgLx2PPXDTY9mUr9wR6qc0t+u2FsT+gB+iLr0mMbiU4heI7+2ZB3mm5 59AFqeYd6w8E0DGFurNKIQw1qPt8X/ogcqwCeUHFhmxKJSbjePGofRp2qEqMjn7u0wnp CIAhpxZqcLQ5wz+QIKnycjYCHexuo38T8FJ+swcTSr38LHJ0nTuTJqGEAFhGhzUHqoPm HbeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dltkjXVB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y15-20020a056a00190f00b004fa8f507068si16657415pfi.96.2022.04.06.05.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:04:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dltkjXVB; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A69D647E886; Wed, 6 Apr 2022 03:32:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381975AbiDEViX (ORCPT + 99 others); Tue, 5 Apr 2022 17:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1450796AbiDEPwK (ORCPT ); Tue, 5 Apr 2022 11:52:10 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCE456262; Tue, 5 Apr 2022 07:43:46 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id p26-20020a05600c1d9a00b0038ccbff1951so1399892wms.1; Tue, 05 Apr 2022 07:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=1mH+YSU50fajcvK1QNZ8qQyJ60qjkNCXhuT3a6pQSAs=; b=dltkjXVB9Tl6/EfD0+STBcgxcVKiIwbPMdp6xBZ1L7eR30tp6KCooqhhNUqCzubXXL jOn35Yz8NwUy5wRAjj3u174P0gayVAu/KowJOr1sVrtp2RH67Lj8sU/aqWsQ67PzTqV5 OzK6ODu2jV/DY97GmbBnnTBYEIx7xbyEbvUKt5YDYmBqnjuh4DY6y65j7roSZGZCD5tT nRK4JJfAqAIeFGfeMAnibNrbaZY2A4ecnXZ4RyjlChCXHfRZM2vT3Ax2fZZ+w9KsztA+ pyr81udTeSjugi9UqC6jyGVq3XyULYSsxu8q7i4UcDhOjILBCk/4+gVgR2fEIncR402O yypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=1mH+YSU50fajcvK1QNZ8qQyJ60qjkNCXhuT3a6pQSAs=; b=vRhGnJQqLihIfiJY3r2Sl06D7uNXqTXT88KKsNBmXZRs21Q8Y14y7Yv/XwalW8QHAH EjLZK/c0UZKSwe9dqSNXQeiT4r9v7aZmNX1bdshwpy/LEHRPayvltad/IZQ6CSRXQy3n LChIJdjGMrWuEc1TGbMGu4AwtNPStj+d3QRY0T+hHO8kSGVtXUihr7EYvptDkvTVeq5B eV5SmhYHfARbQiu2TV1FQGqXV8oAKnu6iRV8kMpC4HUaw1JUUTsy6I7+7vXzOhNcuX34 OGw8uC5iJAe6wzrGCw7HiFddqmMz6kg35pZn4NlLqgdo3Zajk64c0GK3B/sTkaRITmPs mqjQ== X-Gm-Message-State: AOAM532FinHgaNW6AfhOKQsPstSowkvX84wJmISOX/VBpv9BsJznaTzq CVluwyrGZDQsgXxp9Qer+qw= X-Received: by 2002:a7b:ce0a:0:b0:38e:761a:1c76 with SMTP id m10-20020a7bce0a000000b0038e761a1c76mr3472870wmc.198.1649169824612; Tue, 05 Apr 2022 07:43:44 -0700 (PDT) Received: from [10.32.181.87] (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.googlemail.com with ESMTPSA id 3-20020a05600c248300b0038e7e94bbc2sm2399857wms.3.2022.04.05.07.43.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Apr 2022 07:43:44 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <71005293-95cd-ec52-83f4-d93947d16af0@redhat.com> Date: Tue, 5 Apr 2022 16:43:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [RFC PATCH v5 040/104] KVM: VMX: Split out guts of EPT violation to common/exposed function Content-Language: en-US To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson References: From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 3/4/22 20:48, 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 > --- > arch/x86/kvm/vmx/common.h | 35 +++++++++++++++++++++++++++++++++++ > arch/x86/kvm/vmx/vmx.c | 34 ++++++---------------------------- > 2 files changed, 41 insertions(+), 28 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..1052b3c93eb8 > --- /dev/null > +++ b/arch/x86/kvm/vmx/common.h > @@ -0,0 +1,35 @@ > +/* 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_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 7838cd177f0e..0edeeed0b4c8 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" > @@ -5381,11 +5382,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, > @@ -5394,31 +5394,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; > > /* > @@ -5432,7 +5410,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) Reviewed-by: Paolo Bonzini