Message ID | 20231229022652.300095-1-chao.gao@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-12912-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2343431dyb; Thu, 28 Dec 2023 18:27:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfo4TP0UKIRFZuZuU9v+xgmb60WFuTbKFqBd2UTzEkfkzRb/V2z44J/I0aKfKH9bPxcgni X-Received: by 2002:a2e:8445:0:b0:2cc:5e44:a8ee with SMTP id u5-20020a2e8445000000b002cc5e44a8eemr5423658ljh.105.1703816856346; Thu, 28 Dec 2023 18:27:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703816856; cv=none; d=google.com; s=arc-20160816; b=v0ATwTJKS8usCJ6rN3Ox66VR2g4O6/KSgkZSarcMw1u/usJjHT4MoGQFe+pU0LUhVz BQdJmldG7WotuCjRNbwPq/YZmSL9WqSdGLvZglpAu3wDESEsWGaw6pRLg0V4sbpAq0NP CZxmKQ+fBJVPr2PMXOk+rij5BTr6fT1b75VtnftHoAllPswAPHf3XMeVqr5F5zt8DUsh 369lMm+eEUfCsGpj7D3L8xpVnamaCxzndet+RceGcouSKHa2X8kYVoYQ08g500IfmVAv 3mN6qoYq5g4kyUSjUuwrx49KbtDTqKqrXcjdbmyYxvWE1U5oP26OadRzvXkuLzGq/J9+ hYow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=H+G5C/0oUKpRCn5RoO4SnaOXMIqzeIjseiqQmvKTteM=; fh=BCuAEXinjHCTICuAN1RKIlOP7NFfVPugI53jhUdzucw=; b=Kws9YAknrv/K5Dtc/wzYpoKfWwp83KQ/idj/eEoWD1KVyTnYsAcbUIfNoM912DbeSy tvaUsURnyBiljlZ8Q/3pjI/FmYY8ijVASRyEx0seoxnS/Zu7M5/dWIbAqerNmTvTHNU1 x+NAcat1ZLdB5HS/AkCwv9yjHEWhfABEYENgIvWtBVFx4no3gZr922sc5qnBZrPRtXGM mLj2ZAv+RA3vppJo/KE29zyIkg2UBURxKiH6gFqc1sn4/jEfRWioPVEMH22YI5mgp4gs WmseyIs8qX4xLtPoFW8VLKOJHH6bryRTue8glR4rDiC7gP+9Y8ptknnK6PFaRZmGCxVR neOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JNYxQ4ao; spf=pass (google.com: domain of linux-kernel+bounces-12912-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12912-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z5-20020a05640235c500b005548f2e0e55si5160634edc.222.2023.12.28.18.27.36 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 18:27:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12912-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JNYxQ4ao; spf=pass (google.com: domain of linux-kernel+bounces-12912-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12912-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id E6C451F240F8 for <ouuuleilei@gmail.com>; Fri, 29 Dec 2023 02:27:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E9052584; Fri, 29 Dec 2023 02:27:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JNYxQ4ao" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 54C4817C4; Fri, 29 Dec 2023 02:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703816832; x=1735352832; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=jO8UhDDE9XLWPmFjFMmJQX6DOZ0dsIfTQRQHqWpFqgQ=; b=JNYxQ4aoFewzKrykJpuMByWR4j1fD3gKj8EMN3UUSoI2TI2vWFJPog/q TFPVUN9bxmIouUYwDM/yRpB8moxs3/mju6h2ScdytFRcfZZgzE/w2uVV7 p4AsLXdsCuC16/efgJolpTNeIwtcQLfgCcuMu36dOMqII3BnhNY8tV9DB h4qfVSslAAbjjBZUpuXbPTugfj4Mp/a55gZcpugx7NU7ZAUQfHZg9+JEX PqiLQDX3VtEMqO7dh/60guHYuzvNZmdQCCt0RDbte2DWyEq9Pmun3NlLm nsEqsdDr1gqxHP8Uk0rl83Eeoh1m0Hil59hPrvt22MR3+0jlaL+qc3XOZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="10187546" X-IronPort-AV: E=Sophos;i="6.04,313,1695711600"; d="scan'208";a="10187546" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 18:27:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10937"; a="754909732" X-IronPort-AV: E=Sophos;i="6.04,313,1695711600"; d="scan'208";a="754909732" Received: from spr.sh.intel.com ([10.239.53.116]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Dec 2023 18:27:06 -0800 From: Chao Gao <chao.gao@intel.com> To: kvm@vger.kernel.org Cc: Chao Gao <chao.gao@intel.com>, Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: VMX: Report up-to-date exit qualification to userspace Date: Fri, 29 Dec 2023 10:26:52 +0800 Message-Id: <20231229022652.300095-1-chao.gao@intel.com> X-Mailer: git-send-email 2.40.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786581463935709179 X-GMAIL-MSGID: 1786581463935709179 |
Series |
KVM: VMX: Report up-to-date exit qualification to userspace
|
|
Commit Message
Chao Gao
Dec. 29, 2023, 2:26 a.m. UTC
Use vmx_get_exit_qual() to read the exit qualification.
vcpu->arch.exit_qualification is cached for EPT violation only and even
for EPT violation, it is stale at this point because the up-to-date
value is cached later in handle_ept_violation().
Fixes: 70bcd708dfd1 ("KVM: vmx: expose more information for KVM_INTERNAL_ERROR_DELIVERY_EV exits")
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
base-commit: 8ed26ab8d59111c2f7b86d200d1eb97d2a458fd1
Comments
On Fri, Dec 29, 2023, Chao Gao wrote: > Use vmx_get_exit_qual() to read the exit qualification. > > vcpu->arch.exit_qualification is cached for EPT violation only and even > for EPT violation, it is stale at this point because the up-to-date > value is cached later in handle_ept_violation(). Oof, vcpu->arch.exit_qualification is *gross*. At a glance, it should be straightforward to get rid of it and use the fault structure to pass the info that comes from the MMU. I'll post a patch, assuming it works. As for this patch, I'll get it applied for 6.9. --- arch/x86/include/asm/kvm_host.h | 3 --- arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/mmu/paging_tmpl.h | 14 +++++++------- arch/x86/kvm/vmx/nested.c | 5 ++++- arch/x86/kvm/vmx/vmx.c | 2 -- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index ad5319a503f0..7ef4715d43d6 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -993,9 +993,6 @@ struct kvm_vcpu_arch { u64 msr_kvm_poll_control; - /* set at EPT violation at this point */ - unsigned long exit_qualification; - /* pv related host specific info */ struct { bool pv_unhalted; diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index 4351149484fb..b5791a66637e 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -26,6 +26,7 @@ struct x86_exception { bool nested_page_fault; u64 address; /* cr2 or nested page fault gpa */ u8 async_page_fault; + unsigned long exit_qualification; }; /* diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 4d4e98fe4f35..7a87097cb45b 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -497,21 +497,21 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, * The other bits are set to 0. */ if (!(errcode & PFERR_RSVD_MASK)) { - vcpu->arch.exit_qualification &= (EPT_VIOLATION_GVA_IS_VALID | - EPT_VIOLATION_GVA_TRANSLATED); + walker->fault.exit_qualification = 0; + if (write_fault) - vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_WRITE; + walker->fault.exit_qualification |= EPT_VIOLATION_ACC_WRITE; if (user_fault) - vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_READ; + walker->fault.exit_qualification |= EPT_VIOLATION_ACC_READ; if (fetch_fault) - vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_INSTR; + walker->fault.exit_qualification |= EPT_VIOLATION_ACC_INSTR; /* * Note, pte_access holds the raw RWX bits from the EPTE, not * ACC_*_MASK flags! */ - vcpu->arch.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) << - EPT_VIOLATION_RWX_SHIFT; + walker->fault.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) << + EPT_VIOLATION_RWX_SHIFT; } #endif walker->fault.address = addr; diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 994e014f8a50..15141b08c604 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -407,10 +407,13 @@ static void nested_ept_invalidate_addr(struct kvm_vcpu *vcpu, gpa_t eptp, static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault) { + unsigned long exit_qualification = fault->exit_qualification; struct vmcs12 *vmcs12 = get_vmcs12(vcpu); struct vcpu_vmx *vmx = to_vmx(vcpu); u32 vm_exit_reason; - unsigned long exit_qualification = vcpu->arch.exit_qualification; + + exit_qualification |= vmx_get_exit_qual(vcpu) & + (EPT_VIOLATION_GVA_IS_VALID | EPT_VIOLATION_GVA_TRANSLATED); if (vmx->nested.pml_full) { vm_exit_reason = EXIT_REASON_PML_FULL; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e262bc2ba4e5..1de022af7dcb 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5771,8 +5771,6 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ? PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK; - vcpu->arch.exit_qualification = exit_qualification; - /* * Check that the GPA doesn't exceed physical memory limits, as that is * a guest page fault. We have to emulate the instruction here, because base-commit: 873eef46b33c86be414d60bd00390e64fc0f006f --
On Fri, 29 Dec 2023 10:26:52 +0800, Chao Gao wrote: > Use vmx_get_exit_qual() to read the exit qualification. > > vcpu->arch.exit_qualification is cached for EPT violation only and even > for EPT violation, it is stale at this point because the up-to-date > value is cached later in handle_ept_violation(). > > > [...] Applied to kvm-x86 vmx, thanks! [1/1] KVM: VMX: Report up-to-date exit qualification to userspace https://github.com/kvm-x86/linux/commit/d7f0a00e438d -- https://github.com/kvm-x86/linux/tree/next
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 40e3780d73ae..46d6ee3c52e5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6510,7 +6510,7 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_DELIVERY_EV; vcpu->run->internal.data[0] = vectoring_info; vcpu->run->internal.data[1] = exit_reason.full; - vcpu->run->internal.data[2] = vcpu->arch.exit_qualification; + vcpu->run->internal.data[2] = vmx_get_exit_qual(vcpu); if (exit_reason.basic == EXIT_REASON_EPT_MISCONFIG) { vcpu->run->internal.data[ndata++] = vmcs_read64(GUEST_PHYSICAL_ADDRESS);