From: Jinu Kim <kimjw04271234@gmail.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] KVM: x86/mmu: Check all address spaces before skipping unsync
Date: Tue, 21 Jul 2026 19:35:12 +0900 [thread overview]
Message-ID: <20260721103512.2136240-3-kimjw04271234@gmail.com> (raw)
In-Reply-To: <20260721103512.2136240-1-kimjw04271234@gmail.com>
mmu_try_to_unsync_pages() skips the shadow-page lookup when the
supplied memslot allows a hugepage, because a shadow page would disallow
hugepages. But hugepage metadata is per-address-space while shadow pages
are shared across all address spaces. With SMM, the other address space
can therefore have a shadow page even when the supplied memslot allows a
hugepage.
Check the corresponding memslot in the other address space before
taking the fast path. Skip the shadow-page lookup only when all address
spaces allow a hugepage.
Fixes: b3ae3ceb5569 ("KVM: x86/mmu: KVM: x86/mmu: Skip unsync when large pages are allowed")
Assisted-by: Codex:GPT-5
Signed-off-by: Jinu Kim <kimjw04271234@gmail.com>
---
arch/x86/kvm/mmu/mmu.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 7757f0ad65c6f..1db6750992546 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -725,6 +725,25 @@ static struct kvm_lpage_info *lpage_info_slot(gfn_t gfn,
return &slot->arch.lpage_info[level - 2][idx];
}
+static bool kvm_gfn_is_lpage_allowed(struct kvm *kvm,
+ const struct kvm_memory_slot *slot,
+ gfn_t gfn, int level)
+{
+ const struct kvm_memory_slot *other_slot;
+
+ BUILD_BUG_ON(KVM_MAX_NR_ADDRESS_SPACES > 2);
+
+ if (lpage_info_slot(gfn, slot, level)->disallow_lpage)
+ return false;
+
+ if (kvm_arch_nr_memslot_as_ids(kvm) == 1)
+ return true;
+
+ other_slot = __gfn_to_memslot(__kvm_memslots(kvm, slot->as_id ^ 1), gfn);
+ return !other_slot ||
+ !lpage_info_slot(gfn, other_slot, level)->disallow_lpage;
+}
+
/*
* The most significant bit in disallow_lpage tracks whether or not memory
* attributes are mixed, i.e. not identical for all gfns at the current level.
@@ -2972,7 +2991,7 @@ int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
* write-protected (see above), thus if the gfn can be mapped with a
* hugepage and isn't write-tracked, it can't have a shadow page.
*/
- if (!lpage_info_slot(gfn, slot, PG_LEVEL_2M)->disallow_lpage)
+ if (kvm_gfn_is_lpage_allowed(kvm, slot, gfn, PG_LEVEL_2M))
return 0;
/*
--
2.43.0
next prev parent reply other threads:[~2026-07-21 10:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 10:35 [PATCH v2 0/2] KVM: x86/mmu: fix cross-address-space MMU metadata checks Jinu Kim
2026-07-21 10:35 ` [PATCH v2 1/2] KVM: x86/mmu: Check write tracking in all address spaces Jinu Kim
2026-07-21 10:35 ` Jinu Kim [this message]
2026-07-28 16:18 ` [PATCH v2 2/2] KVM: x86/mmu: Check all address spaces before skipping unsync 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=20260721103512.2136240-3-kimjw04271234@gmail.com \
--to=kimjw04271234@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/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®