Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1807940rdb; Sun, 4 Feb 2024 02:09:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKoBB/E6EZh8VWpDXjTbHRYzTln74VqUWtk/SFoNMMfVM2pJ5QcFhmcPMYAZVFFqPPHmca X-Received: by 2002:a17:902:e892:b0:1d9:143b:eaf with SMTP id w18-20020a170902e89200b001d9143b0eafmr10438330plg.61.1707041370178; Sun, 04 Feb 2024 02:09:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707041370; cv=pass; d=google.com; s=arc-20160816; b=lRipSohZwtw7GaJhKSh/zOyEfohaZujPsiibhW4aEVsE+AH8dRevXE0cDY+zm9VJTO mp+EP/cot6wjXCG4qFUqxV6TmwncGKEeP/qPgdM/XdHe8RkIBMyh9icLj3tQvaAykoO2 MSgSBwFgYixUn3gSit149HjRqSV0njxuu9bUaJeoCZ7peJTJPKLSoFcubtn/P2JE/9es oI4FbGxmzymIDfR7Y2x+gOmaJkLcK7GihC/K69GO1UQuQcIMVg3mGOis43nF88SWNUoM wb+Oo3H3P3367DkDF5aB4TiyRR5WUZcY7/a1Rilfd2zamW/oSs3kH3rcfJMKLAxmfBmg i0Xg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=sqgrlUlafT+XaSDetUvHnRhqBmYDKL8SW9Qk1wN9238=; fh=6okx85G3lzG2SG4dqrcYftjYq0oVFFYGQ9LVTCBahbU=; b=iLHo463WBDoGEFETyheC1XcZWK4JmVDfrN+3KumTLDfyFRynMzr/yevt9xGLHoezeh Fi+F0hPc/fmbkmNkIp44wAvEfdYakwWgKeKNSLMy9+Gl1EFr6187YjIFfUpQpHxEP0Oy L2edfz7hoZGfEcavbwEpJ2ePSUHfFlp3dwiZmkf7h7XMVJf2tIJ6zr8cccP6oXeYtoKk 8UkwmcJoZkRI2UEjowIFpCpCz1AdgtKdr9zLvYIuzzcgTUbkxtt6qg1ipCP4oEXuXeVv DEpu0lCx+XSormQanIv2mITqZKYYwQjyHxsUE6iAAjhqC1A771JKDbp3ooZb2VqvHtb6 R45A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QrxWV6AL; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51535-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51535-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXZdHfs0rlIvikUsSubfVxH6QdLHSkgDYQtbkv8IIJ/sZZOPSbmVUhVQU/N6PqMkzBhQ7xN2ddVFw6Q7b//k7xr6MyZ6tK4IogURuaTSA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b6-20020a170903228600b001d98f0cd2fcsi2098729plh.299.2024.02.04.02.09.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 02:09:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51535-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QrxWV6AL; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-51535-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51535-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5F284B2315D for ; Sun, 4 Feb 2024 08:53:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C628F1640B; Sun, 4 Feb 2024 08:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QrxWV6AL" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41A9A14282; Sun, 4 Feb 2024 08:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707036814; cv=none; b=bZgZeg6GjHA3Kf+3bR/hOy0WJ6F2NvkbjVCxPIQWu1zBDg1Z7L4FHFEZhSYdsa07YdnUQwmyZp5j6NV83IhYuVgC2GRydFTORHSR0YgAdFG6Bg/sn6iKXtJM4hMTCTrGR3hTJSsP3Ptg2tHdaibauppRI/cYMCYY30kJm23dRSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707036814; c=relaxed/simple; bh=LLHRog0Y5BuI6tuJ+Il3SYEWFoFi5AyuuJd9z97WEi8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Yf81zpt0qn/YuGXC+ZPpurUyJOw+s4rpNC8p+82Ui9oDtEyaz7Y+VQA58gNoJzvjeFPQLiUIU2Qz7xe+GS+E84hmwVvgkc38BbSheGyw7QdcnW7vzmmLouevJPi05LxFGVetLmONl65/WVKWHyjAEfd7osxVGbw9j8jWEsQDWtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QrxWV6AL; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707036813; x=1738572813; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=LLHRog0Y5BuI6tuJ+Il3SYEWFoFi5AyuuJd9z97WEi8=; b=QrxWV6ALfnyD56hFWqEyKl9sOTgL2NVYJqPYpr6WzTQArUNYrJ5UTvAo MYSb/6jKHj6cKAGMWE+dmTdJ1q7DqrLUYdyI9EJkfwp9NVyHZs557Ip3o 8V96ALAEwv5vYRNPzleAcLrxrkMGczlAWnfWgPsHXxxzr83VZjv25dQ74 0/Yd1ZgHmZ6ry0DKoP4wTKSpCR9k/MK9zQpN4fXA11FkxD4FtCx/gv+WF vivvEAP7UyYJUCNYDAed1RRIaZRTzf9t/e7CCmCKa/YUIv026J2rzwKjG 6HwuShk3FKTShKZiW80viNUCY5+LrLXDbS54cr7eZg6frfgUMfCrn1gFF w==; X-IronPort-AV: E=McAfee;i="6600,9927,10973"; a="11022710" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="11022710" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 00:53:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10973"; a="932886723" X-IronPort-AV: E=Sophos;i="6.05,242,1701158400"; d="scan'208";a="932886723" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO [10.238.10.49]) ([10.238.10.49]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2024 00:53:29 -0800 Message-ID: <45b6ba60-276e-4826-b3e4-20d3854558b1@linux.intel.com> Date: Sun, 4 Feb 2024 16:53:27 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v18 054/121] KVM: VMX: Split out guts of EPT violation to common/exposed function 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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Sean Christopherson References: <4aa3aaa6d12640ee9948308116c6f57ad3a0c1ba.1705965635.git.isaku.yamahata@intel.com> From: Binbin Wu In-Reply-To: <4aa3aaa6d12640ee9948308116c6f57ad3a0c1ba.1705965635.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/23/2024 7:53 AM, 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. Reviewed-by: Binbin Wu > > Signed-off-by: Sean Christopherson > Signed-off-by: Isaku Yamahata > Reviewed-by: Paolo Bonzini > Reviewed-by: Kai Huang > --- > arch/x86/kvm/vmx/common.h | 33 +++++++++++++++++++++++++++++++++ > arch/x86/kvm/vmx/vmx.c | 25 +++---------------------- > 2 files changed, 36 insertions(+), 22 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 89f31263fe9c..185e22a2e101 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 "hyperv.h" > #include "kvm_onhyperv.h" > @@ -5779,11 +5780,8 @@ static int handle_task_switch(struct kvm_vcpu *vcpu) > > static int handle_ept_violation(struct kvm_vcpu *vcpu) > { > - unsigned long exit_qualification; > + unsigned long exit_qualification = vmx_get_exit_qual(vcpu); > gpa_t gpa; > - u64 error_code; > - > - exit_qualification = vmx_get_exit_qual(vcpu); > > /* > * EPT violation happened while executing iret from NMI, > @@ -5798,23 +5796,6 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) > > gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); > trace_kvm_page_fault(vcpu, 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; > > /* > @@ -5828,7 +5809,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) > if (unlikely(allow_smaller_maxphyaddr && !kvm_vcpu_is_legal_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)