Kernel KVM virtualization 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 v3 03/12] KVM: s390: Small miscellaneous CMMA fixes
Date: Thu, 03 Dec 2026 17:24:36 +0000	[thread overview]
Message-ID: <sashiko-outbox-248255@kernel.org> (raw)
In-Reply-To: <20261203161527.188235-4-imbrenda@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] KVM: s390: unconditional set_bit() in handle_essa() bounces
  gmap cacheline
- [Low] KVM: s390: duplicate set_bit() and misleading comment in
  handle_essa()
- [Low] KVM: s390: commit message lacks rationale and omits Fixes tag
  190df4a212a7
--

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

> KVM: s390: Small miscellaneous CMMA fixes
>
> Set the CMMA flag also when the first ESSA instruction was performed in
> migration mode.
>
> Set the CMMA flag in kvm_s390_set_cmma_bits() before starting to set
> the CMMA values, instead of afterwards.
>
> Fix the stale comments in handle_essa().
>
> Fence UCONTROL VMs from using the KVM_S390_SET_CMMA_BITS ioctl,
> returning -EINVAL.
>
> Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
> Cc: stable@vger.kernel.org
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

[Severity: Low]
The commit message describes what each change does, but not why (for
example, why missing GMAP_FLAG_USES_CMM in migration mode breaks
kvm_s390_get_cmma_bits(), or why UCONTROL VMs must now be fenced from
KVM_S390_SET_CMMA_BITS).

Also, failing to mark CMMA as used in the migration-mode branch of
handle_essa() was introduced in 190df4a212a7 ("KVM: s390: CMMA
tracking, ESSA emulation, migration mode"), not e38c884df921 ("KVM:
s390: Switch to new gmap").  Omitting 190df4a212a7 prevents stable
backporting to kernels prior to e38c884df921.

> diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c
> index f22612a127c96..4b590c09240cf 100644
> --- a/arch/s390/kvm/s390/priv.c
> +++ b/arch/s390/kvm/s390/priv.c
> @@ -1243,19 +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
> -		 * 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.
> +		 * the SIE block and in the gmap, and we are not doing a
> +		 * migration. Enable CMMA in the gmap.
>  		 */
>  		set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags);

[Severity: Low]
Both branches of the migration_mode check now start with
set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags); could this be
hoisted above the if?

The updated comment here also implies CMMA is only enabled in the gmap
outside migration mode, which contradicts the else branch below.

[ ... ]

> @@ -1264,6 +1260,8 @@ static int handle_essa(struct kvm_vcpu *vcpu)
>  		/* Retry the ESSA instruction */
>  		kvm_s390_retry_instr(vcpu);
>  	} else {
> +		set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags);
> +
>  		scoped_guard(mutex, &vcpu->kvm->slots_arch_lock)
>  			scoped_guard(read_lock, &vcpu->kvm->mmu_lock)
>  				i = __do_essa(vcpu, orc);

[Severity: Medium]
Can this unconditional set_bit() bounce the struct gmap cacheline
across vCPUs during live migration?

In migration mode, ECB2_CMMA is cleared so every guest ESSA instruction
enters this else branch.  On s390, set_bit() unconditionally executes
an atomic laog, taking exclusive ownership of the struct gmap cacheline
even when GMAP_FLAG_USES_CMM is already set.

Because struct gmap fits in a single 256-byte cacheline, this
invalidates it for other vCPUs reading gmap->flags on every SIE entry
(vcpu_pre_run() -> kvm_is_ucontrol()).

Guarding the write with if (!uses_cmm(vcpu->arch.gmap)), as
_gmap_enable_skeys() does with uses_skeys(), would keep the cacheline
shared after the first ESSA.

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

  reply	other threads:[~2026-12-03 17:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:15 [PATCH v3 00/12] KVM: s390: More fixes Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 01/12] KVM: s390: ucontrol: Do not mask -ENOMEM when translating Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 02/12] KVM: s390: Fix potential leak in kvm_s390_get_io_int() Claudio Imbrenda
2026-12-03 16:49   ` sashiko-bot
2026-12-03 16:15 ` [PATCH v3 03/12] KVM: s390: Small miscellaneous CMMA fixes Claudio Imbrenda
2026-12-03 17:24   ` sashiko-bot [this message]
2026-12-03 16:15 ` [PATCH v3 04/12] KVM: s390: Fix dat_entry_walk() with DAT_WALK_CONTINUE Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 05/12] KVM: s390: Fix soft-dirty handling in _gmap_link() Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 06/12] KVM: s390: Fix race in gmap_clear_young_pte() Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 07/12] KVM: s390: Properly adjust page size before calling _gmap_link() Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 08/12] KVM: s390: Fix *_test_and_clear_softdirty() functions Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 09/12] KVM: s390: Do not unnecessarily drop the soft-dirty bit Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 10/12] KVM: s390: Disallow 2G pages for guests up to 2G Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 11/12] KVM: s390: vsie: Fix improper shadowing of non-present host ptes Claudio Imbrenda
2026-12-03 16:15 ` [PATCH v3 12/12] KVM: s390: vsie: Drop shadow gmaps when a memslot is deleted or moved Claudio Imbrenda

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-248255@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