Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [GIT PULL 0/4] KVM: s390: Third round of fixes for 7.4
@ 2026-12-02 12:14 Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 1/4] KVM: s390: reserve mmu cache before stopping migration mode Janosch Frank
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Janosch Frank @ 2026-12-02 12:14 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda

Paolo,

another small haul of fixes for s390.
Two are fixing VSIE state manipulation behavior, one touches up my IRQ
kick code and the last one fixes MMU migration behavior.
The VSIE ESA fix also has a test patch which I moved to next.

Please pull.


The following changes since commit 6761f65e6823876534a9c3eec4cee1674dce415d:

  KVM: s390: vsie: Fix pinning using the wrong flag (2026-11-12 15:11:08 +0100)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-7.4-3

for you to fetch changes up to 7d0dce6d8913d06fd0789cafebc184ce96b4e631:

  KVM: s390: Don't kick vcpus for floating IRQs that are no longer pending (2026-12-01 10:04:55 +0100)

----------------------------------------------------------------
Memory, vsie and IRQ injection fixes:
 - Floating IRQ kick improvement (Christian)
 - VSIE ESA PSW manipulation fix (Yvan)
 - VSIE early validity state synchronization fix (Gautam)
 - Migration MMU fix (Gautam)
----------------------------------------------------------------

Christian Borntraeger (1):
  KVM: s390: Don't kick vcpus for floating IRQs that are no longer
    pending

Gautam Gala (2):
  KVM: s390: reserve mmu cache before stopping migration mode
  KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt

Yvan Janssens (1):
  KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format

 arch/s390/kvm/gmap/kvm_mmu.c   | 15 +++++++-----
 arch/s390/kvm/s390/interrupt.c | 14 ++++++++++++
 arch/s390/kvm/s390/vsie.c      | 42 ++++++++++++++++++++++++++--------
 3 files changed, 56 insertions(+), 15 deletions(-)

-- 
2.56.1


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

* [GIT PULL 1/4] KVM: s390: reserve mmu cache before stopping migration mode
  2026-12-02 12:14 [GIT PULL 0/4] KVM: s390: Third round of fixes for 7.4 Janosch Frank
@ 2026-12-02 12:14 ` Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 2/4] KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt Janosch Frank
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2026-12-02 12:14 UTC (permalink / raw)
  To: pbonzini
  Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda,
	Gautam Gala

From: Gautam Gala <ggala@linux.ibm.com>

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>
Signed-off-by: Christian Borntraeger <borntraeger@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..b9b56390ae6d 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.1


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

* [GIT PULL 2/4] KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt
  2026-12-02 12:14 [GIT PULL 0/4] KVM: s390: Third round of fixes for 7.4 Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 1/4] KVM: s390: reserve mmu cache before stopping migration mode Janosch Frank
@ 2026-12-02 12:14 ` Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 3/4] KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 4/4] KVM: s390: Don't kick vcpus for floating IRQs that are no longer pending Janosch Frank
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2026-12-02 12:14 UTC (permalink / raw)
  To: pbonzini
  Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda,
	Gautam Gala

From: Gautam Gala <ggala@linux.ibm.com>

shadow_scb() calls prepare_cpuflags() first, which can reject the SCB
provided by guest 2 with a validity interception. This happens before
the guest state (gpsw, gg14, gg15, gcr, cputm, ckc, todpr, pp) and the
control fields (gbea, fpf) are copied from the original SCB into the
shadow SCB.

The error path still calls unshadow_scb(), which copies that state from
the shadow SCB back into the original one. The shadow SCB does not hold
guest 3 state at this point:

 - For a new or recycled vsie page, get_vsie_page() has cleared the
   shadow SCB, so the guest 3 state in the guest 2 SCB is overwritten
   with zeroes.
 - For a cached vsie page that is looked up again by SCB address, the
   shadow SCB still holds the state from the end of the previous run,
   so the current guest 3 state is replaced by the old one.

No guest 3 instruction ran, yet guest 2 sees its guest 3 state (PSW,
GRs, CRs, timers) modified. unshadow_scb() also clears FPF_BPBC if
facility 82 is available, because fpf was cleared in the shadow SCB
just before, and copies back a stale ihcpu.

The SCB and the validity condition are controlled by guest 2, so this
is a correctness problem for guest 2 only and does not cross a guest or
host boundary.

Only the interception data needs to be passed on in this case. Add
unshadow_icpt() for that and use it from unshadow_scb() and from the
prepare_cpuflags() failure path, which now returns directly. The other
failure paths of shadow_scb() are reached after the guest state has
been copied and keep using unshadow_scb().

On a cached vsie page, the interception data in the shadow SCB still
holds the values of the previous run. set_validity_icpt() writes ipa,
ipb and icptcode, but not icptstatus, so a stale icptstatus would be
passed on together with the new validity interception. Also, it is not
defined what SIE stores in icptstatus, ipa and ipb when it exits without
an interception, so they must not be relied upon to be zero or unchanged.
Clear them together with icptcode when the shadow SCB is reused,
so that no stale interception data is passed on to guest 2.

Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
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>
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
---
 arch/s390/kvm/s390/vsie.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c
index 3ce133f20fa2..e2cb9bd411fd 100644
--- a/arch/s390/kvm/s390/vsie.c
+++ b/arch/s390/kvm/s390/vsie.c
@@ -425,6 +425,15 @@ static void prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	}
 }
 
+static void unshadow_icpt(struct kvm_s390_sie_block *scb_o,
+			  struct kvm_s390_sie_block *scb_s)
+{
+	scb_o->icptcode = scb_s->icptcode;
+	scb_o->icptstatus = scb_s->icptstatus;
+	scb_o->ipa = scb_s->ipa;
+	scb_o->ipb = scb_s->ipb;
+}
+
 /* unshadow the scb, copying parameters back to the real scb */
 static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 {
@@ -432,10 +441,7 @@ static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
 
 	/* interception */
-	scb_o->icptcode = scb_s->icptcode;
-	scb_o->icptstatus = scb_s->icptstatus;
-	scb_o->ipa = scb_s->ipa;
-	scb_o->ipb = scb_s->ipb;
+	unshadow_icpt(scb_o, scb_s);
 	scb_o->gbea = scb_s->gbea;
 
 	/* timer */
@@ -491,6 +497,9 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
 	/* make sure we don't have any leftovers when reusing the scb */
 	scb_s->icptcode = 0;
+	scb_s->icptstatus = 0;
+	scb_s->ipa = 0;
+	scb_s->ipb = 0;
 	scb_s->eca = 0;
 	scb_s->ecb = 0;
 	scb_s->ecb2 = 0;
@@ -500,8 +509,10 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	scb_s->fpf = 0;
 
 	rc = prepare_cpuflags(vcpu, vsie_page);
-	if (rc)
-		goto out;
+	if (rc) {
+		unshadow_icpt(scb_o, scb_s);
+		return rc;
+	}
 
 	/* timer */
 	scb_s->cputm = scb_o->cputm;
@@ -615,7 +626,6 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
 	prepare_ibc(vcpu, vsie_page);
 	rc = shadow_crycb(vcpu, vsie_page);
-out:
 	if (rc)
 		unshadow_scb(vcpu, vsie_page);
 	return rc;
-- 
2.56.1


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

* [GIT PULL 3/4] KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format
  2026-12-02 12:14 [GIT PULL 0/4] KVM: s390: Third round of fixes for 7.4 Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 1/4] KVM: s390: reserve mmu cache before stopping migration mode Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 2/4] KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt Janosch Frank
@ 2026-12-02 12:14 ` Janosch Frank
  2026-12-02 12:14 ` [GIT PULL 4/4] KVM: s390: Don't kick vcpus for floating IRQs that are no longer pending Janosch Frank
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2026-12-02 12:14 UTC (permalink / raw)
  To: pbonzini
  Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda,
	Yvan Janssens, stable

From: Yvan Janssens <yvanj@cyber.gent>

ESA-mode guests in vsie have existed since commit b0ad874d9852 ("KVM:
s390: vsie: Allow non-zarch guests"); they use the 8-byte short PSW -
the mask and instruction address share one doubleword.

vsie's PSW rewind originally still changed the second doubleword, which
is unused in ESA mode, so the instruction is skipped instead of
repeated. One visible effect is that the first STFLE after entering SIE
does nothing in a nested guest.

This patch adds a vsie-specific rewind function that handles both
formats; no short-PSW type is introduced - for ESA guests mask and
address are written into the mask field.

Fixes: b0ad874d9852 ("KVM: s390: vsie: Allow non-zarch guests")
Cc: stable@vger.kernel.org # 7.1+
Signed-off-by: Yvan Janssens <yvanj@cyber.gent>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
[frankja@de.ibm.com: Changed commit message as suggested by Christian]
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 arch/s390/kvm/s390/vsie.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c
index e2cb9bd411fd..426724830c58 100644
--- a/arch/s390/kvm/s390/vsie.c
+++ b/arch/s390/kvm/s390/vsie.c
@@ -958,6 +958,20 @@ static inline void clear_vsie_icpt(struct vsie_page *vsie_page)
 	vsie_page->scb_s.icptcode = 0;
 }
 
+static void vsie_rewind_psw(struct kvm_s390_sie_block *scb, int ilen)
+{
+	u64 addr_mask;
+
+	if (atomic_read(&scb->cpuflags) & CPUSTAT_ZARCH) {
+		scb->gpsw.addr = __rewind_psw(scb->gpsw, ilen);
+		return;
+	}
+	/* ESA short PSW: mask and address both live in gpsw.mask */
+	addr_mask = scb->gpsw.mask & PSW32_ADDR_AMODE ? PSW32_ADDR_INSN : 0x00ffffffUL;
+	scb->gpsw.mask = (scb->gpsw.mask & ~PSW32_ADDR_INSN) |
+			 ((scb->gpsw.mask - ilen) & addr_mask);
+}
+
 /* rewind the psw and clear the vsie icpt, so we can retry execution */
 static void retry_vsie_icpt(struct vsie_page *vsie_page)
 {
@@ -970,7 +984,7 @@ static void retry_vsie_icpt(struct vsie_page *vsie_page)
 		if (!ilen)
 			ilen = 4;
 	}
-	scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, ilen);
+	vsie_rewind_psw(scb_s, ilen);
 	clear_vsie_icpt(vsie_page);
 }
 
@@ -1423,7 +1437,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		scb_s->icptcode = ICPT_PROGI;
 		scb_s->iprcc = PGM_ADDRESSING;
 		scb_s->pgmilc = 4;
-		scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
+		vsie_rewind_psw(scb_s, 4);
 		rc = 1;
 	}
 	return rc;
-- 
2.56.1


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

* [GIT PULL 4/4] KVM: s390: Don't kick vcpus for floating IRQs that are no longer pending
  2026-12-02 12:14 [GIT PULL 0/4] KVM: s390: Third round of fixes for 7.4 Janosch Frank
                   ` (2 preceding siblings ...)
  2026-12-02 12:14 ` [GIT PULL 3/4] KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format Janosch Frank
@ 2026-12-02 12:14 ` Janosch Frank
  3 siblings, 0 replies; 5+ messages in thread
From: Janosch Frank @ 2026-12-02 12:14 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, frankja, david, borntraeger, cohuck, linux-s390, imbrenda

From: Christian Borntraeger <borntraeger@linux.ibm.com>

kick_cpu_irq() searches for a vcpu that can take the injected floating
IRQ, starting with last_sleep_cpu, and, if it does not find one that
is suitable it wakes up all vcpus to avoid starvation.

For GISA interrupts, __inject_io() only sets the IPM bit and the
hardware may deliver the interrupt to a vcpu running in SIE before
kick_cpu_irq() looks at it. The IPM bit is then already clear, so
deliverable_irqs() returns 0 for every vcpu and all vcpus are woken up
for an interrupt that has already been delivered.

Whenever a candidate vcpu cannot take the IRQ, check whether the IRQ is
still pending for the VM at all and skip the kick if it is not. The
common case, where the last_sleep_cpu guess works, is not affected:
deliverable_irqs() has already looked at the pending IRQs then.

Measured with a 12 vcpu guest doing 4k random reads (4 jobs, iodepth
32) on a host NVMe attached as virtio-blk with 4 queues mapped to 2
iothreads, all QEMU threads pinned to vertical high/medium CPUs of a
shared LPAR (function profile via ftrace, so absolute times include
tracing overhead):

                                   before          after
  vcpu wakeups per kick            9.05            1.40
  kick_cpu_irq() avg               4.77us          0.41us
  eventfd_write() avg (irqfd)      3.67us          0.70us
  IOPS                             773k - 774k     806k - 809k
  host CPU per I/O                 7.7us           7.1 - 7.3us

virtio-net also shows benefit.

Fixes: 370b3a89cbd9 ("KVM: s390: Improve floating IRQ injection behavior")
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 arch/s390/kvm/s390/interrupt.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/s390/kvm/s390/interrupt.c b/arch/s390/kvm/s390/interrupt.c
index 31a6074feffc..df0f89b33147 100644
--- a/arch/s390/kvm/s390/interrupt.c
+++ b/arch/s390/kvm/s390/interrupt.c
@@ -1963,6 +1963,17 @@ static void vcpu_intervention_kick(struct kvm_vcpu *vcpu, u64 type)
 	kvm_s390_vcpu_wakeup(vcpu);
 }
 
+/* Floating IRQs (including GISA IPM) pending for the VM */
+static unsigned long pending_float_irqs(struct kvm *kvm)
+{
+	struct kvm_s390_gisa_interrupt *gi = &kvm->arch.gisa_int;
+	unsigned long pending = kvm->arch.float_int.pending_irqs;
+
+	if (gi->origin)
+		pending |= (unsigned long)gisa_get_ipm(gi->origin) << IRQ_PEND_IO_ISC_7;
+	return pending & ~kvm->arch.float_int.masked_irqs;
+}
+
 static void kick_cpu_irq(struct kvm *kvm, u64 type, u64 parm)
 {
 	struct kvm_vcpu *dst_vcpu;
@@ -1981,6 +1992,9 @@ static void kick_cpu_irq(struct kvm *kvm, u64 type, u64 parm)
 		if (!is_vcpu_stopped(dst_vcpu) &&
 		    deliverable_irqs(dst_vcpu) & irq_pend_mask)
 			break;
+		/* IRQ already delivered (e.g. via GISA), nobody to kick */
+		if (!(pending_float_irqs(kvm) & irq_pend_mask))
+			return;
 		/* avoid endless loops if all vcpus are stopped */
 		if (nr_tries++ >= online_vcpus) {
 			dst_vcpu = NULL;
-- 
2.56.1


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

end of thread, other threads:[~2026-12-02 12:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:14 [GIT PULL 0/4] KVM: s390: Third round of fixes for 7.4 Janosch Frank
2026-12-02 12:14 ` [GIT PULL 1/4] KVM: s390: reserve mmu cache before stopping migration mode Janosch Frank
2026-12-02 12:14 ` [GIT PULL 2/4] KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt Janosch Frank
2026-12-02 12:14 ` [GIT PULL 3/4] KVM: s390: vsie: Rewind the PSW of ESA mode guests in the right format Janosch Frank
2026-12-02 12:14 ` [GIT PULL 4/4] KVM: s390: Don't kick vcpus for floating IRQs that are no longer pending Janosch Frank

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