From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Stefan Teodorescu <fane@google.com>,
Sashiko Bot <sashiko-bot@kernel.org>,
syzbot@syzkaller.appspotmail.com, Chris Mason <mason@kernel.org>
Subject: Re: [PATCH v2 4/5] KVM: x86: Consolidate nVMX vs. nSVM logic for loading CR3 on nested xfer
Date: Thu, 3 Dec 2026 09:28:32 -0800 [thread overview]
Message-ID: <axGmwGmzPFutbKHD@seanjc-mac.roam.internal> (raw)
In-Reply-To: <CAO9r8zMTVS+8SroFTemKR4V35zCE6HumtyBdpk_E5WDdHDKKfw@mail.gmail.com>
On Wed, Nov 25, 2026, Yosry Ahmed wrote:
> On Tue, Nov 17, 2026 at 1:09 PM Sean Christopherson <seanjc@google.com> wrote:
> > -/*
> > - * Load guest's/host's cr3 on nested vmentry or vmexit. @nested_npt is true
> > - * if we are emulating VM-Entry into a guest with NPT enabled.
> > - */
> > static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
> > bool nested_npt, bool reload_pdptrs)
> > {
> > - if (reload_pdptrs && is_pae_paging(vcpu)) {
> > - if (nested_npt)
> > - kvm_register_mark_for_reload(vcpu, VCPU_REG_PDPTR);
> > - else if (CC(!load_pdptrs(vcpu, cr3)))
> > - return -EINVAL;
> > - }
> > + if (reload_pdptrs && is_pae_paging(vcpu) && nested_npt)
>
> Check nested_npt first like kvm_nested_load_cr3()?
Hmm, sure. I wanted to keep the ordering of this code, but that's more than a
little extreme in terms of not introducing unrelated changed.
> > + kvm_register_mark_for_reload(vcpu, VCPU_REG_PDPTR);
> >
> > - vcpu->arch.cr3 = cr3;
> > - kvm_register_mark_dirty(vcpu, VCPU_REG_CR3);
> > -
> > - /* Re-initialize the MMU, e.g. to pick up CR4 MMU role changes. */
> > - kvm_init_mmu(vcpu);
> > -
> > - if (!nested_npt)
> > - kvm_mmu_new_pgd(vcpu, cr3);
> > -
> > - return 0;
> > + return kvm_nested_load_cr3(vcpu, cr3, nested_npt, reload_pdptrs);
>
> We dropped CC() here. Do we also want KVM_BUG_ON(!reload_pdptrs) here?
No, the KVM_BUG_ON() in the VMX code is there specifically to guard setting the
failure code to ENTRY_FAIL_PDPTE. To keep the CC(), I'll squash this (plus
an include of trace.h in regs.c).
diff --git arch/x86/kvm/regs.c arch/x86/kvm/regs.c
index cd4ddda44c40..5d298793b7ca 100644
--- arch/x86/kvm/regs.c
+++ arch/x86/kvm/regs.c
@@ -209,7 +209,7 @@ int kvm_nested_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
* or are read from memory on-demand (NPT), i.e. aren't loaded here.
*/
if (reload_pdptrs && !nested_tdp && is_pae_paging(vcpu) &&
- !load_pdptrs(vcpu, cr3))
+ KVM_NESTED_VMENTER_CONSISTENCY_CHECK(!load_pdptrs(vcpu, cr3)))
return -EINVAL;
vcpu->arch.cr3 = cr3;
diff --git arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/nested.c
index 589bd8db30c4..95cfef17010f 100644
--- arch/x86/kvm/vmx/nested.c
+++ arch/x86/kvm/vmx/nested.c
@@ -1224,7 +1224,7 @@ static int nested_vmx_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
bool nested_ept, bool reload_pdptrs,
enum vm_entry_failure_code *entry_failure_code)
{
- if (CC(kvm_nested_load_cr3(vcpu, cr3, nested_ept, reload_pdptrs))) {
+ if (kvm_nested_load_cr3(vcpu, cr3, nested_ept, reload_pdptrs)) {
KVM_BUG_ON(!reload_pdptrs, vcpu->kvm);
*entry_failure_code = ENTRY_FAIL_PDPTE;
return -EINVAL;
next prev parent reply other threads:[~2026-12-03 17:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 21:09 [PATCH v2 0/5] KVM: x86: Fix nested CR3 load bugs Sean Christopherson
2026-11-17 21:09 ` [PATCH v2 1/5] KVM: nSVM: Pre-check current (L2's) CR3 during KVM_SET_NESTED_STATE Sean Christopherson
2026-11-25 21:26 ` Yosry Ahmed
2026-11-17 21:09 ` [PATCH v2 2/5] KVM: nVMX/nSVM: check unconditionally whether CR3 is valid Sean Christopherson
2026-11-25 21:35 ` Yosry Ahmed
2026-11-17 21:09 ` [PATCH v2 3/5] KVM: nSVM: Mark CR3 as dirty when loading CR3 on nested transitions Sean Christopherson
2026-11-25 21:36 ` Yosry Ahmed
2026-11-17 21:09 ` [PATCH v2 4/5] KVM: x86: Consolidate nVMX vs. nSVM logic for loading CR3 on nested xfer Sean Christopherson
2026-11-25 21:40 ` Yosry Ahmed
2026-12-03 17:28 ` Sean Christopherson [this message]
2026-11-17 21:09 ` [PATCH v2 5/5] KVM: x86: Initialize MMU+PGD before loading PDPTRs on nested transitions Sean Christopherson
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=axGmwGmzPFutbKHD@seanjc-mac.roam.internal \
--to=seanjc@google.com \
--cc=fane@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=pbonzini@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=syzbot@syzkaller.appspotmail.com \
--cc=yosry@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®