From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH 2/4] KVM: nVMX: remove unnecessary code in prepare_vmcs02
Date: Wed, 27 May 2026 08:05:58 -0400 [thread overview]
Message-ID: <20260527120600.20696-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20260527120600.20696-1-pbonzini@redhat.com>
The late vmwrite of the PDPTRs in prepare_vmcs02() is redundant, because
every write it does was already performed by prepare_vmcs02_rare earlier
in the same prepare_vmcs02 call.
In particular:
- load_guest_pdptrs_vmcs12 == true implies that prepare_vmcs02_rare() ran
- the assignment to load_guest_pdptrs_vmcs12 matches the gate in
prepare_vmcs02_rare(), other than having one that checks
!hv_evmcs and the other !nested_vmx_is_evmptr12_valid(vmx)
- the condition for the late move is a strict subset of the one in
prepare_vmcs02_rare(), because the former checks
nested_cpu_has_ept(vmcs12), which implies enable_ept, and on top
it narrows it further by ANDing is_pae_paging(vcpu)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/vmx/nested.c | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index c1be8ef882b8..f86a12fc29ec 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2721,14 +2721,10 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct hv_enlightened_vmcs *evmcs = nested_vmx_evmcs(vmx);
- bool load_guest_pdptrs_vmcs12 = false;
if (vmx->nested.dirty_vmcs12 || nested_vmx_is_evmptr12_valid(vmx)) {
prepare_vmcs02_rare(vmx, vmcs12);
vmx->nested.dirty_vmcs12 = false;
-
- load_guest_pdptrs_vmcs12 = !nested_vmx_is_evmptr12_valid(vmx) ||
- !(evmcs->hv_clean_fields & HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1);
}
if (vcpu->arch.nested_run_pending &&
@@ -2831,15 +2827,6 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
if (enable_ept)
vmcs_writel(GUEST_CR3, vmcs12->guest_cr3);
- /* Late preparation of GUEST_PDPTRs now that EFER and CRs are set. */
- if (load_guest_pdptrs_vmcs12 && nested_cpu_has_ept(vmcs12) &&
- is_pae_paging(vcpu)) {
- vmcs_write64(GUEST_PDPTR0, vmcs12->guest_pdptr0);
- vmcs_write64(GUEST_PDPTR1, vmcs12->guest_pdptr1);
- vmcs_write64(GUEST_PDPTR2, vmcs12->guest_pdptr2);
- vmcs_write64(GUEST_PDPTR3, vmcs12->guest_pdptr3);
- }
-
if ((vmcs12->vm_entry_controls & VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL) &&
kvm_pmu_has_perf_global_ctrl(vcpu_to_pmu(vcpu)) &&
WARN_ON_ONCE(__kvm_emulate_msr_write(vcpu, MSR_CORE_PERF_GLOBAL_CTRL,
--
2.52.0
next prev parent reply other threads:[~2026-05-27 12:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 12:05 [PATCH 0/4] KVM: x86: small MMU-adjacent cleanups Paolo Bonzini
2026-05-27 12:05 ` [PATCH 1/4] KVM: x86: remove nested_mmu from mmu_is_nested() Paolo Bonzini
2026-05-27 12:05 ` Paolo Bonzini [this message]
2026-05-28 0:14 ` [PATCH 2/4] KVM: nVMX: remove unnecessary code in prepare_vmcs02 Sean Christopherson
2026-05-28 7:56 ` Paolo Bonzini
2026-05-27 12:05 ` [PATCH 3/4] KVM: nSVM: invalidate cached PDPTRs across nested NPT transitions Paolo Bonzini
2026-05-27 23:53 ` Sean Christopherson
2026-05-28 8:33 ` Paolo Bonzini
2026-05-28 18:33 ` Jim Mattson
2026-05-30 16:54 ` Paolo Bonzini
2026-05-27 12:06 ` [PATCH 4/4] KVM: x86: check that kvm_handle_invpcid is only invoked with shadow paging Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260527120600.20696-3-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®