From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>, kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH v1 03/12] KVM: s390: Introduce gmap_enable_cmm()
Date: Fri, 27 Nov 2026 15:47:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-237781@kernel.org> (raw)
In-Reply-To: <20261127150411.221072-4-imbrenda@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] KVM: s390: missing vSIE unshadow in
gmap_enable_cmm_already_locked()
- [Medium] KVM: s390: premature flag set in
gmap_enable_cmm_already_locked()
- [Medium] KVM: s390: gmap_enable_cmm_already_locked() leaves hugepage
flags set
--
commit 0b86eaed62523c8498a79fd700936cedd248584a
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>
KVM: s390: Introduce gmap_enable_cmm()
This commit introduces gmap_enable_cmm_already_locked() and
gmap_enable_cmm() to mark a gmap as using CMMA, split existing large page
mappings, and pre-allocate 4K page tables across guest memslots on a best
effort basis.
> diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c
> index ef1243ad4e541..c7af1ad9f7c12 100644
> --- a/arch/s390/kvm/gmap/gmap.c
> +++ b/arch/s390/kvm/gmap/gmap.c
> @@ -1527,3 +1527,51 @@ struct gmap *gmap_create_shadow(struct kvm_s390_mmu_cache *mc, struct gmap *pare
> }
> return new;
> }
> +
> +#if KVM_S390_MANAGES_S390_GUEST
> +/* Bail out for any allocation failure. This is only a best effort to allocate all page tables. */
> +void gmap_enable_cmm_already_locked(struct kvm_s390_mmu_cache *mc, struct gmap *gmap)
> +{
> + struct kvm_memory_slot *ms;
> + struct kvm_memslots *slots;
> + gfn_t gfn, start, end;
> + union crste *crstep;
> + union pte *ptep;
> + int flags, bkt;
> +
> + lockdep_assert_held(&gmap->kvm->srcu);
> + lockdep_assert_held(&gmap->kvm->slots_arch_lock);
> +
> + if (uses_cmm(gmap))
> + return;
> +
> + set_bit(GMAP_FLAG_USES_CMM, &gmap->flags);
[Severity: Medium]
Should gmap_enable_cmm_already_locked() also clear
GMAP_FLAG_ALLOW_HPAGE_1M and GMAP_FLAG_ALLOW_HPAGE_2G on gmap->flags?
Because those flags remain set, any segment that does not keep a
pre-allocated 4K page table (for instance, when a memslot is created or
moved after CMMA is enabled, or when kvm_s390_mmu_cache_topup() fails
mid-loop) will still satisfy gmap_1m_allowed() or gmap_2g_allowed() in
gmap_link() and be mapped with 1M or 2G large pages, causing subsequent
CMMA operations such as dat_set_cmma_bits() to fail with -EFBIG.
> +
> + slots = kvm_memslots(gmap->kvm);
> + if (!slots || kvm_memslots_empty(slots))
> + return;
> +
> + if (WARN_ON_ONCE(is_ucontrol(gmap)))
> + return;
[Severity: Medium]
Does setting GMAP_FLAG_USES_CMM before the memslot walk allow concurrent
callers of gmap_enable_cmm() to return early before page tables are
allocated and large pages are split?
CPU0 CPU1
gmap_enable_cmm()
mutex_lock(&kvm->slots_arch_lock)
gmap_enable_cmm_already_locked()
set_bit(GMAP_FLAG_USES_CMM, ...)
gmap_enable_cmm()
if (uses_cmm(gmap))
return; <-- skips lock
for (gfn = start; gfn < end; ...)
kvm_s390_mmu_cache_topup(mc)
dat_entry_walk(...)
Because gmap_enable_cmm() checks uses_cmm(gmap) without holding
slots_arch_lock, CPU1 observes GMAP_FLAG_USES_CMM while CPU0 is still
splitting large pages and sleeping in kvm_s390_mmu_cache_topup().
Setting the flag before the is_ucontrol(gmap) check also leaves
GMAP_FLAG_USES_CMM set if is_ucontrol(gmap) triggers.
> +
> + flags = DAT_WALK_ALLOC | DAT_WALK_SPLIT;
> +
> + kvm_for_each_memslot(ms, bkt, slots) {
> + start = ALIGN(ms->base_gfn, _PAGE_ENTRIES);
> + end = ALIGN_DOWN(ms->base_gfn + ms->npages, _PAGE_ENTRIES);
> +
> + for (gfn = start; gfn < end; gfn += _PAGE_ENTRIES) {
> + if (kvm_s390_mmu_cache_topup(mc))
> + return;
> +
> + guard(write_lock)(&gmap->kvm->mmu_lock);
> +
> + if (uses_skeys(gmap))
> + flags |= DAT_WALK_USES_SKEYS;
> +
> + dat_entry_walk(mc, gfn, gmap->asce, flags, TABLE_TYPE_PAGE_TABLE,
> + &crstep, &ptep);
> + }
> + }
> +}
> +#endif /* KVM_S390_MANAGES_S390_GUEST */
[Severity: High]
Can splitting large pages via dat_entry_walk() with DAT_WALK_SPLIT leave
stale 1M or 2G mappings in vSIE shadow gmaps?
When _do_shadow_crste() shadows a 1M or 2G large page, it records the
rmap entry in sg->host_to_rmap only at the 1M-aligned or 2G-aligned base
GFN (f->gfn & mask) and sets s.fc1.vsie_notif on the large CRSTE.
Unlike gmap_split_huge_pages() -> _gmap_split_crste(), which calls
gmap_handle_vsie_unshadow_event() before splitting, dat_entry_walk()
with DAT_WALK_SPLIT calls dat_split_crste() and dat_split_ste()
directly, copying vsie_notif into all 4K PGSTEs without unshadowing sg:
arch/s390/kvm/gmap/dat.c:dat_split_ste() {
...
pgste_init.prefix_notif = old.s.fc1.prefix_notif;
pgste_init.vsie_notif = old.s.fc1.vsie_notif;
pgste_init.vsie_gmem = old.s.fc1.vsie_notif;
...
}
If a 4K subpage at a non-zero offset within that former large page is
later unmapped or write-protected, _gmap_handle_vsie_unshadow_event()
looks up that exact 4K GFN in sg->host_to_rmap, misses the rmap entry at
the aligned base GFN, and leaves the stale large mapping active in
sg->asce.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127150411.221072-1-imbrenda@linux.ibm.com?part=3
next prev parent reply other threads:[~2026-11-27 15:47 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:03 [PATCH v1 00/12] KVM: s390: More fixes Claudio Imbrenda
2026-11-27 15:04 ` [PATCH v1 01/12] KVM: s390: ucontrol: Do not mask -ENOMEM when translating Claudio Imbrenda
2026-11-27 15:04 ` [PATCH v1 02/12] KVM: s390: Fix potential leak in kvm_s390_get_io_int() Claudio Imbrenda
2026-11-30 8:23 ` Christian Borntraeger
2026-11-30 14:04 ` Claudio Imbrenda
2026-11-30 14:10 ` Christian Borntraeger
2026-11-27 15:04 ` [PATCH v1 03/12] KVM: s390: Introduce gmap_enable_cmm() Claudio Imbrenda
2026-11-27 15:47 ` sashiko-bot [this message]
2026-12-01 12:52 ` Steffen Eiden
2026-11-27 15:04 ` [PATCH v1 04/12] KVM: s390: Allocate page tables when CMMA is used Claudio Imbrenda
2026-11-27 15:34 ` sashiko-bot
2026-11-27 15:04 ` [PATCH v1 05/12] KVM: s390: Fix dat_entry_walk() with DAT_WALK_CONTINUE Claudio Imbrenda
2026-11-27 15:04 ` [PATCH v1 06/12] KVM: s390: Fix soft-dirty handling in _gmap_link() Claudio Imbrenda
2026-11-30 9:43 ` Janosch Frank
2026-11-27 15:04 ` [PATCH v1 07/12] KVM: s390: Fix race in gmap_clear_young_pte() Claudio Imbrenda
2026-11-30 12:05 ` Janosch Frank
2026-11-27 15:04 ` [PATCH v1 08/12] KVM: s390: Properly adjust page size before calling _gmap_link() Claudio Imbrenda
2026-12-01 13:20 ` Janosch Frank
2026-11-27 15:04 ` [PATCH v1 09/12] KVM: s390: Fix *_test_and_clear_softdirty() functions Claudio Imbrenda
2026-11-27 15:30 ` sashiko-bot
2026-11-27 15:04 ` [PATCH v1 10/12] KVM: s390: Do not unnecessarily drop the soft-dirty bit Claudio Imbrenda
2026-11-27 15:27 ` sashiko-bot
2026-11-27 15:04 ` [PATCH v1 11/12] KVM: s390: Disallow 2G pages for guests up to 2G Claudio Imbrenda
2026-11-27 15:04 ` [PATCH v1 12/12] KVM: s390: vsie: Fix improper shadowing of non-present host ptes Claudio Imbrenda
2026-11-27 15:47 ` [PATCH v1 00/12] KVM: s390: More fixes sashiko-bot
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-237781@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--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 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.