mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/2] KVM: s390: fix migration mode teardown in memslot handling
@ 2026-11-20  7:53 Gautam Gala
  2026-11-20  7:53 ` [PATCH v1 1/2] KVM: s390: reserve mmu cache before stopping migration mode Gautam Gala
  2026-11-20  7:53 ` [PATCH v1 2/2] KVM: s390: make kvm_s390_vm_stop_migration() void Gautam Gala
  0 siblings, 2 replies; 3+ messages in thread
From: Gautam Gala @ 2026-11-20  7:53 UTC (permalink / raw)
  To: kvm
  Cc: linux-s390, linux-kernel, Christian Borntraeger, Janosch Frank,
	Claudio Imbrenda, David Hildenbrand, Steffen Eiden,
	Andreas Grapentin, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Sven Schnelle

Two small fixes for migration mode handling in
s390_kvm_mmu_prepare_memory_region().

Patch 1 fixes an error-path bug: if the mmu cache reservation fails
after migration mode was already stopped, the ioctl fails but the CMMA
state cleared by kvm_s390_vm_stop_migration() cannot be restored, so an
in-flight migration aborts over an unrelated allocation failure.
Reserving the cache first keeps both memslots and migration state
untouched on failure.

Patch 2 is a cleanup on top: kvm_s390_vm_stop_migration() cannot fail,
so it returns void and the always-false WARN() at its call site is
dropped.

Gautam Gala (2):
  KVM: s390: reserve mmu cache before stopping migration mode
  KVM: s390: make kvm_s390_vm_stop_migration() void

 arch/s390/kvm/arm64/arm.h    |  3 +--
 arch/s390/kvm/gmap/kvm_mmu.c | 18 ++++++++++--------
 arch/s390/kvm/s390/s390.c    | 10 +++++-----
 arch/s390/kvm/s390/s390.h    |  2 +-
 4 files changed, 17 insertions(+), 16 deletions(-)

-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 1/2] KVM: s390: reserve mmu cache before stopping migration mode
  2026-11-20  7:53 [PATCH v1 0/2] KVM: s390: fix migration mode teardown in memslot handling Gautam Gala
@ 2026-11-20  7:53 ` Gautam Gala
  2026-11-20  7:53 ` [PATCH v1 2/2] KVM: s390: make kvm_s390_vm_stop_migration() void Gautam Gala
  1 sibling, 0 replies; 3+ messages in thread
From: Gautam Gala @ 2026-11-20  7:53 UTC (permalink / raw)
  To: kvm
  Cc: linux-s390, linux-kernel, Christian Borntraeger, Janosch Frank,
	Claudio Imbrenda, David Hildenbrand, Steffen Eiden,
	Andreas Grapentin, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Sven Schnelle

Creating or moving a memslot without KVM_MEM_LOG_DIRTY_PAGES stops
migration mode in s390_kvm_mmu_prepare_memory_region(). If the mmu
cache reservation fails afterwards, the ioctl returns -ENOMEM with
the memslots unchanged, but migration mode stays stopped: the CMMA
state cleared by kvm_s390_vm_stop_migration() cannot be restored,
so an in-flight migration aborts over an unrelated allocation
failure.

Reserve the mmu cache before tearing down migration mode so the
error path leaves both memslots and migration state untouched.

Fixes: 19192a404327 ("KVM: s390: Move all code into s390_kvm_mmu_prepare_memory_region()")
Reported-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 arch/s390/kvm/gmap/kvm_mmu.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/s390/kvm/gmap/kvm_mmu.c b/arch/s390/kvm/gmap/kvm_mmu.c
index 4e2da60b9859..120980cf6ac6 100644
--- a/arch/s390/kvm/gmap/kvm_mmu.c
+++ b/arch/s390/kvm/gmap/kvm_mmu.c
@@ -78,6 +78,14 @@ int s390_kvm_mmu_prepare_memory_region(struct kvm *kvm,
 			return -EINVAL;
 		if (!asce_contains_gfn(kvm->arch.gmap->asce, new->base_gfn + new->npages - 1))
 			return -EINVAL;
+
+		/*
+		 * Must be allocated before migration mode is stopped below:
+		 * kvm_s390_vm_stop_migration() is not rolled back on failure.
+		 */
+		mc = kvm_s390_new_mmu_cache();
+		if (!mc)
+			return -ENOMEM;
 	}
 
 	if (kvm_s390_is_migration_mode(kvm)) {
@@ -97,12 +105,7 @@ int s390_kvm_mmu_prepare_memory_region(struct kvm *kvm,
 
 	if (change == KVM_MR_FLAGS_ONLY)
 		return 0;
-	if (change != KVM_MR_DELETE) {
-		/* Enough capacity to add a new memslot */
-		mc = kvm_s390_new_mmu_cache();
-		if (!mc)
-			return -ENOMEM;
-	}
+
 	scoped_guard(write_lock, &kvm->mmu_lock) {
 		kvm_s390_update_cmma_dirty(kvm, old);
 		if (change == KVM_MR_DELETE || change == KVM_MR_MOVE)
-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] KVM: s390: make kvm_s390_vm_stop_migration() void
  2026-11-20  7:53 [PATCH v1 0/2] KVM: s390: fix migration mode teardown in memslot handling Gautam Gala
  2026-11-20  7:53 ` [PATCH v1 1/2] KVM: s390: reserve mmu cache before stopping migration mode Gautam Gala
@ 2026-11-20  7:53 ` Gautam Gala
  1 sibling, 0 replies; 3+ messages in thread
From: Gautam Gala @ 2026-11-20  7:53 UTC (permalink / raw)
  To: kvm
  Cc: linux-s390, linux-kernel, Christian Borntraeger, Janosch Frank,
	Claudio Imbrenda, David Hildenbrand, Steffen Eiden,
	Andreas Grapentin, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Sven Schnelle

kvm_s390_vm_stop_migration() returns 0 on all paths; it cannot fail.
Its caller in s390_kvm_mmu_prepare_memory_region() wraps it in
WARN(), producing a condition that is always false. The arm64 stub
returns -EINVAL but is unreachable because
kvm_s390_is_migration_mode() returns false there.

Change the return type to void and drop the dead WARN(). The
KVM_S390_VM_MIGRATION_STOP attribute handler sets its result to 0
explicitly; userspace behavior is unchanged since stopping
migration never failed.

Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 arch/s390/kvm/arm64/arm.h    |  3 +--
 arch/s390/kvm/gmap/kvm_mmu.c |  3 +--
 arch/s390/kvm/s390/s390.c    | 10 +++++-----
 arch/s390/kvm/s390/s390.h    |  2 +-
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/arch/s390/kvm/arm64/arm.h b/arch/s390/kvm/arm64/arm.h
index 760230685ca1..e60801e4a467 100644
--- a/arch/s390/kvm/arm64/arm.h
+++ b/arch/s390/kvm/arm64/arm.h
@@ -50,9 +50,8 @@ static __always_inline void kvm_s390_update_cmma_dirty(struct kvm *kvm, const st
 }
 
 /* should never be called */
-static __always_inline int kvm_s390_vm_stop_migration(struct kvm *kvm)
+static __always_inline void kvm_s390_vm_stop_migration(struct kvm *kvm)
 {
-	return -EINVAL;
 }
 
 #endif /* ARCH_S390_KVM_ARM64_H */
diff --git a/arch/s390/kvm/gmap/kvm_mmu.c b/arch/s390/kvm/gmap/kvm_mmu.c
index 120980cf6ac6..f1d1374c92a1 100644
--- a/arch/s390/kvm/gmap/kvm_mmu.c
+++ b/arch/s390/kvm/gmap/kvm_mmu.c
@@ -99,8 +99,7 @@ int s390_kvm_mmu_prepare_memory_region(struct kvm *kvm,
 		 */
 		if (change != KVM_MR_DELETE &&
 		    !(new->flags & KVM_MEM_LOG_DIRTY_PAGES))
-			WARN(kvm_s390_vm_stop_migration(kvm),
-			     "Failed to stop migration mode");
+			kvm_s390_vm_stop_migration(kvm);
 	}
 
 	if (change == KVM_MR_FLAGS_ONLY)
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index 18fb200f854a..04e4fa7dfd1d 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -1242,11 +1242,11 @@ static int kvm_s390_vm_start_migration(struct kvm *kvm)
  * Must be called with kvm->slots_arch_lock to avoid races with ourselves,
  * kvm_s390_vm_start_migration() and kvm_s390_get_cmma_bits().
  */
-int kvm_s390_vm_stop_migration(struct kvm *kvm)
+void kvm_s390_vm_stop_migration(struct kvm *kvm)
 {
 	/* migration mode already disabled */
 	if (!kvm->arch.migration_mode)
-		return 0;
+		return;
 	/*
 	 * Unset the flag and propagate to all vCPUs. From now on the cmma_d
 	 * bit will not be touched on any PGSTE.
@@ -1255,7 +1255,7 @@ int kvm_s390_vm_stop_migration(struct kvm *kvm)
 	 */
 	WRITE_ONCE(kvm->arch.migration_mode, 0);
 	if (!kvm->arch.use_cmma)
-		return 0;
+		return;
 
 	kvm_s390_sync_request_broadcast(kvm, KVM_REQ_STOP_MIGRATION);
 	/* Clear cmma_d on all existing PGSTEs and set cmma_dirty_pages to 0. */
@@ -1266,7 +1266,6 @@ int kvm_s390_vm_stop_migration(struct kvm *kvm)
 	 * cmma_dirty_pages is 0, and all existing PGSTEs have their cmma_d bit
 	 * set to 0.
 	 */
-	return 0;
 }
 
 static int kvm_s390_vm_set_migration(struct kvm *kvm,
@@ -1282,7 +1281,8 @@ static int kvm_s390_vm_set_migration(struct kvm *kvm,
 		res = kvm_s390_vm_start_migration(kvm);
 		break;
 	case KVM_S390_VM_MIGRATION_STOP:
-		res = kvm_s390_vm_stop_migration(kvm);
+		kvm_s390_vm_stop_migration(kvm);
+		res = 0;
 		break;
 	default:
 		break;
diff --git a/arch/s390/kvm/s390/s390.h b/arch/s390/kvm/s390/s390.h
index 9ed1af5583e3..45f397663d5f 100644
--- a/arch/s390/kvm/s390/s390.h
+++ b/arch/s390/kvm/s390/s390.h
@@ -474,7 +474,7 @@ int __kvm_s390_mprotect_many(struct gmap *gmap, gpa_t gpa, u8 npages, unsigned i
 
 bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu);
 void kvm_s390_update_cmma_dirty(struct kvm *kvm, const struct kvm_memory_slot *old);
-int kvm_s390_vm_stop_migration(struct kvm *kvm);
+void kvm_s390_vm_stop_migration(struct kvm *kvm);
 
 
 /* implemented in diag.c */
-- 
2.56.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-20  7:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  7:53 [PATCH v1 0/2] KVM: s390: fix migration mode teardown in memslot handling Gautam Gala
2026-11-20  7:53 ` [PATCH v1 1/2] KVM: s390: reserve mmu cache before stopping migration mode Gautam Gala
2026-11-20  7:53 ` [PATCH v1 2/2] KVM: s390: make kvm_s390_vm_stop_migration() void Gautam Gala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®