Linux s390 Architecture development
 help / color / mirror / Atom feed
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 04/12] KVM: s390: Allocate page tables when CMMA is used
Date: Fri, 27 Nov 2026 15:34:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-237754@kernel.org> (raw)
In-Reply-To: <20261127150411.221072-5-imbrenda@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: s390: premature GMAP_FLAG_USES_CMM publication in
  gmap_enable_cmm()
--

commit 4eafe3dbf444099ded4397c5a1073f2aff0effc2
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>

KVM: s390: Allocate page tables when CMMA is used

This commit calls gmap_enable_cmm() on the first ESSA intercept or
KVM_S390_SET_CMMA_BITS ioctl to preallocate page tables and split large
page mappings, and rejects KVM_S390_SET_CMMA_BITS on ucontrol VMs.

> diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c
> index f22612a127c96..e66fec89ac788 100644
> --- a/arch/s390/kvm/s390/priv.c
> +++ b/arch/s390/kvm/s390/priv.c
> @@ -1243,14 +1243,15 @@ static int handle_essa(struct kvm_vcpu *vcpu)
>  	if (!READ_ONCE(vcpu->kvm->arch.migration_mode)) {
>  		/*
>  		 * CMMA is enabled in the KVM settings, but is disabled in
> -		 * the SIE block and in the mm_context, and we are not doing
> -		 * a migration. Enable CMMA in the mm_context.
> -		 * Since we need to take a write lock to write to the context
> +		 * the SIE block and in the gmap, and we are not doing a
> +		 * migration. Enable CMMA in the gmap.
> +		 * Since we need to take a mutex to write to the gmap
>  		 * to avoid races with storage keys handling, we check if the
>  		 * value really needs to be written to; if the value is
>  		 * already correct, we do nothing and avoid the lock.
>  		 */
> -		set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags);
> +		if (!uses_cmm(vcpu->arch.gmap))
> +			gmap_enable_cmm(vcpu->arch.mc, vcpu->arch.gmap);
>  		/*
>  		 * If we are here, we are supposed to have CMMA enabled in
>  		 * the SIE block. Enabling CMMA works on a per-CPU basis,

[Severity: Medium]
Can a second vCPU observe uses_cmm(vcpu->arch.gmap) == true before
gmap_enable_cmm() has finished allocating page tables and splitting large
pages?

gmap_enable_cmm_already_locked() sets GMAP_FLAG_USES_CMM before walking
the memslots:

arch/s390/kvm/gmap/gmap.c:gmap_enable_cmm_already_locked() {
	if (uses_cmm(gmap))
		return;

	set_bit(GMAP_FLAG_USES_CMM, &gmap->flags);
	...
	kvm_for_each_memslot(ms, bkt, slots) {
		...
		for (gfn = start; gfn < end; gfn += _PAGE_ENTRIES) {
			if (kvm_s390_mmu_cache_topup(mc))
				return;
			guard(write_lock)(&gmap->kvm->mmu_lock);
			...
			dat_entry_walk(mc, gfn, gmap->asce, flags, ...);
		}
	}
}

Because both handle_essa() and gmap_enable_cmm() check uses_cmm()
locklessly before taking slots_arch_lock, another vCPU intercepting on
ESSA while the memslot walk is in progress can skip gmap_enable_cmm() and
re-enter SIE with ECB2_CMMA enabled:

CPU0                                  CPU1
handle_essa()
  gmap_enable_cmm()
    mutex_lock(&slots_arch_lock)
    gmap_enable_cmm_already_locked()
      set_bit(GMAP_FLAG_USES_CMM, ...)
                                      handle_essa()
                                        if (!uses_cmm(...)) -> false
                                        sie_block->ecb2 |= ECB2_CMMA
                                        kvm_s390_retry_instr()
                                        <re-enters SIE and runs ESSA
                                         on unvisited segments>
      kvm_for_each_memslot(...)
        dat_entry_walk(...)

CPU1 then executes ESSA in hardware on segments that still lack page
tables or have unsplit large pages, triggering segment translation faults
and faulting in backing hugepages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127150411.221072-1-imbrenda@linux.ibm.com?part=4

  reply	other threads:[~2026-11-27 15:34 UTC|newest]

Thread overview: 18+ 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-27 15:04 ` [PATCH v1 03/12] KVM: s390: Introduce gmap_enable_cmm() Claudio Imbrenda
2026-11-27 15:47   ` sashiko-bot
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 [this message]
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-27 15:04 ` [PATCH v1 07/12] KVM: s390: Fix race in gmap_clear_young_pte() Claudio Imbrenda
2026-11-27 15:04 ` [PATCH v1 08/12] KVM: s390: Properly adjust page size before calling _gmap_link() Claudio Imbrenda
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-237754@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox