From: sashiko-bot@kernel.org
To: liuqiangneo@163.com
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: Fix kvm_range_has_memory_attributes() for a zero mask
Date: Tue, 01 Dec 2026 01:29:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-242334@kernel.org> (raw)
In-Reply-To: <20261201012137.12592-1-liuqiangneo@163.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] KVM: x86/mmu: soft lockup in
kvm_mmu_init_memslot_memory_attributes() [1]
--
commit 26d303ac2ea9b5803694f4100f1c929f14b5809e
Author: Qiang Liu <liuqiang@kylinos.cn>
KVM: Fix kvm_range_has_memory_attributes() for a zero mask
This commit skips the xarray index check in
kvm_range_has_vm_memory_attributes() when attrs is 0 so that holes skipped
by xas_next_entry() are not rejected when mask is 0.
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 5a1a59d57e0b1..5367804209a2c 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2567,7 +2567,13 @@ bool kvm_range_has_vm_memory_attributes(struct kvm *kvm, gfn_t start, gfn_t end,
>
> WARN_ON_ONCE(!xa_to_value(entry));
>
> - if (xas.xa_index != index ||
> + /*
> + * With @attrs == 0, xas_next_entry() can land past @index.
> + * Skipped holes and reserved entries match; only real entries
> + * with bits in @mask set are rejected. Checking index wrongly
> + * rejects holes when @mask is 0.
> + */
> + if ((attrs && xas.xa_index != index) ||
> (xa_to_value(entry) & mask) != attrs)
> return false;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can scanning a large
memslot with non-zero attributes trigger CPU soft lockups and RCU stalls
[1]?
When initializing memory attributes for a memslot,
kvm_mmu_init_memslot_memory_attributes() loops over every potential
hugepage and calls hugepage_has_attrs() ->
kvm_range_has_vm_memory_attributes(), which walks every 4K gfn via
xas_next() when attrs is non-zero:
arch/x86/kvm/mmu/mmu.c:kvm_mmu_init_memslot_memory_attributes() {
...
for (level = PG_LEVEL_2M; level <= KVM_MAX_HUGEPAGE_LEVEL; level++) {
...
for (gfn = start; gfn < end; gfn += nr_pages) {
unsigned long attrs = kvm_get_vm_memory_attributes(kvm, gfn);
if (hugepage_has_attrs(kvm, slot, gfn, level, attrs))
hugepage_clear_mixed(slot, gfn, level);
...
}
Neither the outer hugepage loop in
kvm_mmu_init_memslot_memory_attributes() nor this inner xarray loop yields
with cond_resched(), so initializing a large memslot runs through millions
of pages without rescheduling.
[1] https://sashiko.dev/#/bug/linux-6205ce47-c25f-4976-b384-7c6b88c376d3
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201012137.12592-1-liuqiangneo@163.com?part=1
prev parent reply other threads:[~2026-12-01 1:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 1:21 [PATCH] KVM: Fix kvm_range_has_memory_attributes() for a zero mask liuqiangneo
2026-12-01 1:29 ` sashiko-bot [this message]
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=sashiko-outbox-242334@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=liuqiangneo@163.com \
--cc=sashiko-reviews@lists.linux.dev \
/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