From: Yosry Ahmed <yosry@kernel.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Yosry Ahmed <yosry@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH 1/4] KVM: x86/mmu: WARN, don't BUG, when walking a cached root with a PAE MMU
Date: Tue, 13 Oct 2026 23:17:25 +0000 [thread overview]
Message-ID: <20261013231728.883001-2-yosry@kernel.org> (raw)
In-Reply-To: <20261013231728.883001-1-yosry@kernel.org>
Replace the BUG_ON() in shadow_walk_init_using_root() that guards against
walking a cached (previous) root while the MMU is configured for PAE
paging with a WARN_ON_ONCE(), and terminate the walk if the WARN fires.
Walking a cached root with a PAE MMU is a KVM bug, as PAE roots are never
cached, but there's no need to bring down the host, as KVM can simply
bail from the walk.
Note, the BUG_ON() is currently reachable by a guest if TDP is disabled,
as KVM walks cached roots even if they were created for a different MMU
context, e.g. if L2 executes INVLPG while using PAE paging, L1 doesn't
intercept INVLPG, and L1's 64-bit root is cached.
Add a common error label for terminating the walk, and use it for the
existing invalid/dummy root check as well.
Fixes: 7eb77e9f5fcf ("kvm: x86: Add a root_hpa parameter to kvm_mmu->invlpg()")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
---
arch/x86/kvm/mmu/mmu.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index aadd5bdc2c97a..126faef5a6476 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -2558,10 +2558,8 @@ static void shadow_walk_init_using_root(struct kvm_shadow_walk_iterator *iterato
iterator->addr = addr;
iterator->shadow_addr = root;
- if (WARN_ON_ONCE(!VALID_PAGE(root)) || kvm_mmu_is_dummy_root(root)) {
- iterator->level = 0;
- return;
- }
+ if (WARN_ON_ONCE(!VALID_PAGE(root)) || kvm_mmu_is_dummy_root(root))
+ goto error;
iterator->level = vcpu->arch.mmu->root_role.level;
@@ -2575,7 +2573,8 @@ static void shadow_walk_init_using_root(struct kvm_shadow_walk_iterator *iterato
* prev_root is currently only used for 64-bit hosts. So only
* the active root_hpa is valid here.
*/
- BUG_ON(root != vcpu->arch.mmu->root.hpa);
+ if (WARN_ON_ONCE(root != vcpu->arch.mmu->root.hpa))
+ goto error;
iterator->shadow_addr
= vcpu->arch.mmu->pae_root[(addr >> 30) & 3];
@@ -2584,6 +2583,10 @@ static void shadow_walk_init_using_root(struct kvm_shadow_walk_iterator *iterato
if (!iterator->shadow_addr)
iterator->level = 0;
}
+ return;
+
+error:
+ iterator->level = 0;
}
static void shadow_walk_init(struct kvm_shadow_walk_iterator *iterator,
--
2.56.0.385.gd3acb90ef8-goog
next prev parent reply other threads:[~2026-10-13 23:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 23:17 [PATCH 0/4] KVM: x86/mmu: Don't sync cached roots created for a different MMU context Yosry Ahmed
2026-10-13 23:17 ` Yosry Ahmed [this message]
2026-10-14 12:48 ` [PATCH 1/4] KVM: x86/mmu: WARN, don't BUG, when walking a cached root with a PAE MMU Jim Mattson
2026-10-14 14:27 ` Yosry Ahmed
2026-10-14 14:40 ` Jim Mattson
2026-10-13 23:17 ` [PATCH 2/4] KVM: x86/mmu: Drop for_each_shadow_entry_using_root() Yosry Ahmed
2026-10-14 12:54 ` Jim Mattson
2026-10-13 23:17 ` [PATCH 3/4] KVM: x86/mmu: Don't sync cached roots created for a different MMU context Yosry Ahmed
2026-10-13 23:17 ` [PATCH 4/4] KVM: nVMX: Drop the TODO to sync only the affected SPTEs for INVVPID Yosry Ahmed
2026-12-04 0:01 ` [PATCH 0/4] KVM: x86/mmu: Don't sync cached roots created for a different MMU context Yosry Ahmed
2026-12-04 19:22 ` Sean Christopherson
2026-12-04 20:12 ` Yosry Ahmed
2026-12-04 20:47 ` Sean Christopherson
2026-12-04 20:52 ` Yosry Ahmed
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=20261013231728.883001-2-yosry@kernel.org \
--to=yosry@kernel.org \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.