All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, borntraeger@de.ibm.com,
	frankja@linux.ibm.com, david@kernel.org, nrb@linux.ibm.com,
	schlameuss@linux.ibm.com, gra@linux.ibm.com,
	seiden@linux.ibm.com
Subject: [PATCH v2 03/12] KVM: s390: Small miscellaneous CMMA fixes
Date: Wed,  2 Dec 2026 19:50:11 +0100	[thread overview]
Message-ID: <20261202185020.241132-4-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20261202185020.241132-1-imbrenda@linux.ibm.com>

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 comment 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>
---
 arch/s390/kvm/s390/priv.c | 8 +++++---
 arch/s390/kvm/s390/s390.c | 8 ++++++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c
index f22612a127c9..55fb1e3a8755 100644
--- a/arch/s390/kvm/s390/priv.c
+++ b/arch/s390/kvm/s390/priv.c
@@ -1243,9 +1243,9 @@ 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.
@@ -1264,6 +1264,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);
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index 4ef7ca960b46..09c43770296d 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -2349,6 +2349,8 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
 	if (r)
 		return -EFAULT;
 
+	set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags);
+
 	do {
 		r = kvm_s390_mmu_cache_topup(mc);
 		if (r)
@@ -2359,8 +2361,6 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
 		}
 	} while (r == -ENOMEM);
 
-	set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags);
-
 	return r <= 0 ? r : -EFAULT;
 }
 
@@ -2991,6 +2991,10 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
 		r = -EFAULT;
 		if (copy_from_user(&args, argp, sizeof(args)))
 			break;
+		if (kvm_is_ucontrol(kvm)) {
+			r = -EINVAL;
+			break;
+		}
 		mutex_lock(&kvm->slots_arch_lock);
 		r = kvm_s390_set_cmma_bits(kvm, &args);
 		mutex_unlock(&kvm->slots_arch_lock);
-- 
2.56.1


  parent reply	other threads:[~2026-12-02 18:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 18:50 [PATCH v2 00/12] KVM: s390: More fixes Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 01/12] KVM: s390: ucontrol: Do not mask -ENOMEM when translating Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 02/12] KVM: s390: Fix potential leak in kvm_s390_get_io_int() Claudio Imbrenda
2026-12-02 18:50 ` Claudio Imbrenda [this message]
2026-12-02 18:50 ` [PATCH v2 04/12] KVM: s390: Fix dat_entry_walk() with DAT_WALK_CONTINUE Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 05/12] KVM: s390: Fix soft-dirty handling in _gmap_link() Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 06/12] KVM: s390: Fix race in gmap_clear_young_pte() Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 07/12] KVM: s390: Properly adjust page size before calling _gmap_link() Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 08/12] KVM: s390: Fix *_test_and_clear_softdirty() functions Claudio Imbrenda
2026-12-02 19:11   ` sashiko-bot
2026-12-02 18:50 ` [PATCH v2 09/12] KVM: s390: Do not unnecessarily drop the soft-dirty bit Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 10/12] KVM: s390: Disallow 2G pages for guests up to 2G Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 11/12] KVM: s390: vsie: Fix improper shadowing of non-present host ptes Claudio Imbrenda
2026-12-02 18:50 ` [PATCH v2 12/12] KVM: s390: vsie: Drop shadow gmaps when a memslot is deleted or moved Claudio Imbrenda
2026-12-02 19:20 ` [PATCH v2 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=20261202185020.241132-4-imbrenda@linux.ibm.com \
    --to=imbrenda@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=gra@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    --cc=schlameuss@linux.ibm.com \
    --cc=seiden@linux.ibm.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 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.