Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 00/10] s390: Host interrupt handling for SAE guests
@ 2026-12-04 12:09 Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution Andreas Grapentin
                   ` (9 more replies)
  0 siblings, 10 replies; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

This series makes host interrupts that occur during SAE (Start Arm
Execution) guest execution not terminating its host. It is based on the
arm-on-s390 sysreg series 2 [1].

So far, SAE guests ran with host interrupts disabled, with a temporary
raw_local_irq_enable()/disable() workaround in the C run loop, and
machine checks during SAE execution were treated as host conditions.
This means, that a guest triggering mccks killed the host.

This series mirrors the SIE irq handling to SAE.

The host interrupt mask is managed in assembly around the SAE
instruction with stosm/stnsm, and the SAE stack frame carries the SAE
control block, the vCPU pointer and the interrupt state (patches 1-2).

The external and I/O interrupt entry code detects the SAE case with an
address range check, fixes the return address to sae_exit, extracts the
vCPU pointer from the stack frame and notifies KVM via a callback
(patches 3-5). This mirrors the existing SIE handling in the same code
paths.

The arm64 equivalent of a machine check is an SError ("System Error")
asynchronous exception. Its exception syndrome (ESR) classifies the
error severity in the AET field; KVM injects it into the guest as a
virtual SError with VSESR_EL2.

Machine checks are handled the same way in the NMI entry code and are
forwarded to the guest. The s390 machine check interruption code is
translated to an arm64 SError ESR in mci_to_esr() and injected as a
virtual SError, including HCR_EL2.VSE shadow register tracking so that a
pended SError the guest has not yet taken stays pended (patches 6-9).

mci_to_esr() will in this first iteration translate all machine checks
forwarded to the guest as UEU (Uncorrected Error Unrecoverable):

    An uncorrected error was consumed and the affected context cannot
    continue; the data is wrong and retrying does not help.

Lastly, Patch 10 lets perf recognize interrupted SAE guest execution via
the saved SAE control block.

Thanks,
-A

[1] https://lore.kernel.org/all/20261127-sysreg-v4-0-a6318d18aab5@linux.ibm.com

Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
Andreas Grapentin (1):
      s390/perf: Recognize SAE guests

Steffen Eiden (7):
      s390/sae: Prepare handling host interrupts during SAE execution
      s390/sae: Add sae_entry and sae_exit symbols
      KVM: s390: Share mcck_volatile_info between KVMs
      s390: Rename CIF_MCCK_GUEST to CIF_MCCK_SIE
      s390/nmi: Handle MCCKs for SAE guests
      KVM: s390: arm64: Enable SError injection
      KVM: s390: arm64: Enable mcck forwarding

Sven Schnelle (2):
      s390/irq: Add kvm_exit callback for arm-on-s390
      KVM: s390: arm64: Enable host irq

 arch/s390/include/asm/irq.h                 |   2 +
 arch/s390/include/asm/kvm_host.h            |   3 +
 arch/s390/include/asm/kvm_host_arm64.h      |   3 +
 arch/s390/include/asm/kvm_host_s390.h       |   2 -
 arch/s390/include/asm/kvm_host_s390_types.h |  14 ----
 arch/s390/include/asm/kvm_host_types.h      |  14 ++++
 arch/s390/include/asm/nmi.h                 |   6 +-
 arch/s390/include/asm/processor.h           |   6 +-
 arch/s390/include/asm/ptrace.h              |   3 +
 arch/s390/include/asm/sae.h                 |   2 +-
 arch/s390/include/asm/stacktrace.h          |   3 +
 arch/s390/include/asm/thread_info.h         |   8 ++-
 arch/s390/kernel/asm-offsets.c              |   6 +-
 arch/s390/kernel/entry.S                    |  68 ++++++++++++++++---
 arch/s390/kernel/irq.c                      |   9 +++
 arch/s390/kernel/nmi.c                      |  58 +++++++++++++---
 arch/s390/kernel/perf_event.c               |  62 +++++++++++++----
 arch/s390/kvm/arm64/arm.c                   | 100 +++++++++++++++++++++++-----
 arch/s390/kvm/arm64/inject_fault.c          |  15 +++++
 arch/s390/kvm/arm64/reset.c                 |   3 +
 20 files changed, 317 insertions(+), 70 deletions(-)
---
base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48
change-id: 20261204-host-irq-462e1ef598d5
prerequisite-message-id: 20261127-sysreg-v4-0-a6318d18aab5@linux.ibm.com
prerequisite-patch-id: 4f6b2386967522be268f77ca6eb9487a3503dc96
prerequisite-patch-id: 539f1138a427fddb952a5f7a0691e8acd974d0fb
prerequisite-patch-id: 3e9b8384f07ff18911f48eabe625a1c0507a5e96
prerequisite-patch-id: fc58c00a1006ecffd045728020ef01308022ac03
prerequisite-patch-id: 2c22bad7059a38c4ea01ca774d0c0b49cea27fba
prerequisite-patch-id: c809f818609fed0a0f8ccb1721b96f5329505543
prerequisite-patch-id: b35581eba719557148ea84232698457adc8c8cc4
prerequisite-patch-id: 0b8792bac82c24bfac0b5912d2eec5da32413747
prerequisite-patch-id: 58fb40b78dd793ca3b24cadadad8868bc54aa20e
prerequisite-patch-id: d986b0811f1feac0678eb135ce5c44140748431b
prerequisite-patch-id: 0e3d84b8259a175fceb67b01bc37c1830805636b
prerequisite-patch-id: 53a6741f3c6ec60c798995ccbf4d2b293619ec34
prerequisite-patch-id: b71ccf22e4cb8fccf4ca9eea558af14163b256db
prerequisite-patch-id: bba91e0c077b1f308e2ec914a54399f775d9090d
prerequisite-patch-id: 9be57897346558cd0bea61d946d85d3ba9a17f2e
prerequisite-patch-id: f4ae3a54ce24b78e335eb1f019b971419d82720a
prerequisite-patch-id: cc8dfe5b2b8a3f28b3c29b1a10827d99f987694d
prerequisite-patch-id: f27d96dacb5c7dadc01f1cc72158b8b3f64d7053
prerequisite-patch-id: 1c69a0380267279633c8ba33bf1d30c13877e033
prerequisite-patch-id: 20ac948d6ec4bfd4b9c3d053bcb0fcb3fe067486
prerequisite-patch-id: db6b83091a6107dbfd9c4311af14fadf1534375f
prerequisite-patch-id: af30d541a7cabea0981dfe79276d1e9991a8c91a
prerequisite-patch-id: 5eead648d962cbdc9f45ce40538f174faedd5775
prerequisite-patch-id: 97589af6c7ac9efe15c371883511fc05d4f1c870
prerequisite-patch-id: f661ef5923e8026fab81d73e596006ac30d5cbac

Best regards,
-- 
Andreas Grapentin <gra@linux.ibm.com>


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

* [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:31   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols Andreas Grapentin
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

Manage the host interrupt mask directly in assembly. Remove the
temporary raw_local_irq enable/ disable workaround from C code to
prepare to eliminate entry/exit races later.

Add a pointer to the current vCPU, SAE control block, and an IRQ state
slot to the SAE stack frame. The vCPU pointer can be used by s390 kernel
handlers to forward work to the arm on s390 module. The control block
can be used for correctly handling perf events for SAE guests. The IRQ
stack slot is used by the stosm/stnsm instructions to enable and disable
interrupts around SAE execution like SIE does.

Co-developed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/include/asm/sae.h        |  2 +-
 arch/s390/include/asm/stacktrace.h |  3 +++
 arch/s390/kernel/asm-offsets.c     |  3 +++
 arch/s390/kernel/entry.S           | 11 ++++++++++-
 arch/s390/kvm/arm64/arm.c          | 18 ++++--------------
 5 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/arch/s390/include/asm/sae.h b/arch/s390/include/asm/sae.h
index d1b9af770108..fd3f042fb497 100644
--- a/arch/s390/include/asm/sae.h
+++ b/arch/s390/include/asm/sae.h
@@ -9,7 +9,7 @@
 #ifndef __ASSEMBLER__
 
 /* defined in arch/s390/kernel/entry.S */
-asmlinkage void sae(phys_addr_t sae_block_phys);
+asmlinkage void sae(phys_addr_t sae_block_phys, void *sae_block, void *vcpu);
 
 #include <linux/io.h>
 #include <asm/extable.h>
diff --git a/arch/s390/include/asm/stacktrace.h b/arch/s390/include/asm/stacktrace.h
index 2d332d7c8145..d0cc948444d6 100644
--- a/arch/s390/include/asm/stacktrace.h
+++ b/arch/s390/include/asm/stacktrace.h
@@ -72,6 +72,9 @@ struct stack_frame {
 		/* SAE stack frame */
 		struct {
 			unsigned long sae_bear;
+			unsigned long sae_block;
+			unsigned long sae_vcpu;
+			unsigned long sae_irq;
 		};
 	};
 	unsigned long gprs[10];
diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c
index f9f9c2246074..e09158248248 100644
--- a/arch/s390/kernel/asm-offsets.c
+++ b/arch/s390/kernel/asm-offsets.c
@@ -71,6 +71,9 @@ int main(void)
 	OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce);
 	OFFSET(__SF_SIE_IRQ, stack_frame, sie_irq);
 	OFFSET(__SF_SAE_BEAR, stack_frame, sae_bear);
+	OFFSET(__SF_SAE_BLOCK, stack_frame, sae_block);
+	OFFSET(__SF_SAE_VCPU, stack_frame, sae_vcpu);
+	OFFSET(__SF_SAE_IRQ, stack_frame, sae_irq);
 	DEFINE(STACK_FRAME_OVERHEAD, sizeof(struct stack_frame));
 	BLANK();
 	OFFSET(__SFUSER_BACKCHAIN, stack_frame_user, back_chain);
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 999dc7d0c637..14dea207b30e 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -248,12 +248,21 @@ EXPORT_SYMBOL(sie_exit)
 #if IS_ENABLED(CONFIG_KVM)
 /*
  * SAE calling convention:
- * %r2 physical address of the SAE control block
+ * %r2 pointer to sae control block phys
+ * %r3 pointer to sae control block virt
+ * %r4 vcpu pointer
  */
 SYM_FUNC_START(sae)
 	stmg	%r6,%r14,__SF_GPRS(%r15)	# store kernel registers
 	STBEAR	__SF_SAE_BEAR(%r15)		# save breaking event address register
+	stg	%r3,__SF_SAE_BLOCK(%r15)	# save sae block for perf
+	stg	%r4,__SF_SAE_VCPU(%r15)		# save vcpu ptr for interrupt handling
+	stosm	__SF_SAE_IRQ(%r15),0x03
 	.insn	rre,0xb9a50000,%r2,0		# Start Arm Execution
+# Let the next instruction be NOP to avoid triggering a machine check
+# and handling it in a guest as result of the instruction execution.
+	nopr	7
+	stnsm	__SF_SAE_IRQ(%r15),0xfc
 	LBEAR	__SF_SAE_BEAR(%r15)		# restore breaking event address register
 	lmg	%r6,%r14,__SF_GPRS(%r15)	# restore kernel registers
 	xgr	%r0,%r0				# clear guest registers to
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index cd59a382a70c..547f77be7e3c 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -425,23 +425,13 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
 	return -EINVAL;
 }
 
-static noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block)
+static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block,
+					struct kvm_vcpu *vcpu)
 {
 	guest_timing_enter_irqoff();
 	guest_state_enter_irqoff();
 
-	/*
-	 * External interrupts may occur while the SAE instruction is executing
-	 * and must preempt guest execution to maintain responsiveness of the
-	 * host.
-	 *
-	 * As a temporary workaround, run SAE with interrupts enabled so that any
-	 * interrupt is taken via the normal host interrupt path rather than
-	 * being subsumed inside the SAE window.
-	 */
-	raw_local_irq_enable();
-	sae(sae_block);
-	raw_local_irq_disable();
+	sae(virt_to_phys(sae_block), sae_block, vcpu);
 
 	guest_state_exit_irqoff();
 	guest_timing_exit_irqoff();
@@ -522,7 +512,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		_vcpu_write_sys_reg(vcpu, vcpu->arch.ctxt.elr_el1, SYS_ELR_EL1);
 		_vcpu_write_sys_reg(vcpu, vcpu->arch.ctxt.spsr_el1, SYS_SPSR_EL1);
 
-		arm_vcpu_enter_exit(virt_to_phys(&vcpu->arch.sae_block));
+		arm_vcpu_enter_exit(&vcpu->arch.sae_block, vcpu);
 
 		vcpu->arch.ctxt.elr_el1 = _vcpu_read_sys_reg(vcpu, SYS_ELR_EL1);
 		vcpu->arch.ctxt.spsr_el1 = _vcpu_read_sys_reg(vcpu, SYS_SPSR_EL1);

-- 
2.55.0


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

* [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:30   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 03/10] KVM: s390: Share mcck_volatile_info between KVMs Andreas Grapentin
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

Define sae_entry and sae_exit boundary labels in entry.S around the SAE
instruction and declare sae_exit in asm/kvm_host.h alongside sie_exit.
This allows interrupt handlers, machine checks, and perf to identify
when the CPU was interrupted during SAE guest execution.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/include/asm/kvm_host.h      | 3 +++
 arch/s390/include/asm/kvm_host_s390.h | 2 --
 arch/s390/kernel/entry.S              | 3 +++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index ac3440a617c1..e689abac5b32 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -9,6 +9,9 @@
 #include <asm/kvm_host_s390.h>
 #endif
 
+extern char sie_exit;
+extern char sae_exit;
+
 #define PGM_OPERATION			0x01
 #define PGM_PRIVILEGED_OP		0x02
 #define PGM_EXECUTE			0x03
diff --git a/arch/s390/include/asm/kvm_host_s390.h b/arch/s390/include/asm/kvm_host_s390.h
index f7802600b3fb..6fc38813bac5 100644
--- a/arch/s390/include/asm/kvm_host_s390.h
+++ b/arch/s390/include/asm/kvm_host_s390.h
@@ -701,8 +701,6 @@ static inline int sie64a(struct kvm_s390_sie_block *sie_block, u64 *rsa, unsigne
 	return __sie64a(virt_to_phys(sie_block), sie_block, rsa, gasce);
 }
 
-extern char sie_exit;
-
 bool kvm_s390_pv_is_protected(struct kvm *kvm);
 bool kvm_s390_pv_cpu_is_protected(struct kvm_vcpu *vcpu);
 
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 14dea207b30e..8ef6fc13fc08 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -258,10 +258,12 @@ SYM_FUNC_START(sae)
 	stg	%r3,__SF_SAE_BLOCK(%r15)	# save sae block for perf
 	stg	%r4,__SF_SAE_VCPU(%r15)		# save vcpu ptr for interrupt handling
 	stosm	__SF_SAE_IRQ(%r15),0x03
+SYM_INNER_LABEL(sae_entry, SYM_L_LOCAL)
 	.insn	rre,0xb9a50000,%r2,0		# Start Arm Execution
 # Let the next instruction be NOP to avoid triggering a machine check
 # and handling it in a guest as result of the instruction execution.
 	nopr	7
+SYM_INNER_LABEL(sae_exit, SYM_L_GLOBAL)
 	stnsm	__SF_SAE_IRQ(%r15),0xfc
 	LBEAR	__SF_SAE_BEAR(%r15)		# restore breaking event address register
 	lmg	%r6,%r14,__SF_GPRS(%r15)	# restore kernel registers
@@ -274,6 +276,7 @@ SYM_FUNC_START(sae)
 	BR_EX	%r14
 SYM_FUNC_END(sae)
 EXPORT_SYMBOL(sae)
+EXPORT_SYMBOL(sae_exit)
 #endif
 
 /*

-- 
2.55.0


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

* [PATCH 03/10] KVM: s390: Share mcck_volatile_info between KVMs
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390 Andreas Grapentin
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

Move mcck_volatile_info from asm/kvm_host_s390_types.h to
asm/kvm_host_types.h such that both KVMs can use the machine check
information to be able to handle machine checks while the CPU is in the
guest mode.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
 arch/s390/include/asm/kvm_host_s390_types.h | 14 --------------
 arch/s390/include/asm/kvm_host_types.h      | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host_s390_types.h b/arch/s390/include/asm/kvm_host_s390_types.h
index 9e348a530421..d7a5eecf0444 100644
--- a/arch/s390/include/asm/kvm_host_s390_types.h
+++ b/arch/s390/include/asm/kvm_host_s390_types.h
@@ -88,20 +88,6 @@ struct esca_block {
 	struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
 };
 
-/*
- * This struct is used to store some machine check info from lowcore
- * for machine checks that happen while the guest is running.
- * This info in host's lowcore might be overwritten by a second machine
- * check from host when host is in the machine check's high-level handling.
- * The size is 24 bytes.
- */
-struct mcck_volatile_info {
-	__u64 mcic;
-	__u64 failing_storage_address;
-	__u32 ext_damage_code;
-	__u32 reserved;
-};
-
 #define CR0_INITIAL_MASK (CR0_UNUSED_56 | CR0_INTERRUPT_KEY_SUBMASK | \
 			  CR0_MEASUREMENT_ALERT_SUBMASK)
 #define CR14_INITIAL_MASK (CR14_UNUSED_32 | CR14_UNUSED_33 | \
diff --git a/arch/s390/include/asm/kvm_host_types.h b/arch/s390/include/asm/kvm_host_types.h
index d308739ebcf5..4cb7c35f11d4 100644
--- a/arch/s390/include/asm/kvm_host_types.h
+++ b/arch/s390/include/asm/kvm_host_types.h
@@ -3,6 +3,20 @@
 #ifndef ASM_KVM_HOST_TYPES_H
 #define ASM_KVM_HOST_TYPES_H
 
+#include <linux/types.h>
+
+/*
+ * Stores machine check info from the lowcore for machine checks that occur
+ * while a guest is running. The lowcore fields may be overwritten by a
+ * subsequent host machine check before high-level handling runs.
+ */
+struct mcck_volatile_info {
+	__u64 mcic;
+	__u64 failing_storage_address;
+	__u32 ext_damage_code;
+	__u32 reserved;
+};
+
 #ifdef KVM_S390_ARM64
 #include <asm/kvm_host_arm64_types.h>
 #else

-- 
2.55.0


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

* [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (2 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 03/10] KVM: s390: Share mcck_volatile_info between KVMs Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:40   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 05/10] KVM: s390: arm64: Enable host irq Andreas Grapentin
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Sven Schnelle <svens@linux.ibm.com>

Detect host interrupts occurring during SAE execution, fix up the return
address to sae_exit, and extract the interrupted vCPU pointer from the
stack frame. Pass the vCPU pointer to the interrupt handlers to invoke
the new kvm_s390_arm64_vcpu_exit callback. This notifies KVM ARM64 of
guest exits caused by external or I/O interrupts.

Co-developed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
 arch/s390/include/asm/irq.h         |  2 ++
 arch/s390/include/asm/ptrace.h      |  3 +++
 arch/s390/include/asm/thread_info.h |  8 +++++++-
 arch/s390/kernel/asm-offsets.c      |  3 ++-
 arch/s390/kernel/entry.S            | 37 +++++++++++++++++++++++++++++--------
 arch/s390/kernel/irq.c              |  9 +++++++++
 6 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h
index 697497e7d13e..485c5f57c077 100644
--- a/arch/s390/include/asm/irq.h
+++ b/arch/s390/include/asm/irq.h
@@ -70,6 +70,8 @@ enum interruption_class {
 	NR_ARCH_IRQS
 };
 
+extern void (*kvm_s390_arm64_vcpu_exit)(unsigned long vcpu);
+
 struct irq_stat {
 	unsigned int irqs[NR_ARCH_IRQS];
 };
diff --git a/arch/s390/include/asm/ptrace.h b/arch/s390/include/asm/ptrace.h
index d8f3a2dbe689..7821efcd68cd 100644
--- a/arch/s390/include/asm/ptrace.h
+++ b/arch/s390/include/asm/ptrace.h
@@ -19,6 +19,7 @@
 #define PIF_FTRACE_FULL_REGS		3	/* all register contents valid (ftrace) */
 #define PIF_WARN_TRAP_SKIPPED		4	/* __WARN_trap() was skipped */
 #define PIF_PGM_CHECK			5	/* inside a program check */
+#define PIF_GUEST_SAE			6	/* interrupted SAE guest, regs->sae_vcpu valid */
 
 #define _PIF_SYSCALL			BIT(PIF_SYSCALL)
 #define _PIF_ADDR_PSW_ADJUSTED		BIT(PIF_PSW_ADDR_ADJUSTED)
@@ -26,6 +27,7 @@
 #define _PIF_FTRACE_FULL_REGS		BIT(PIF_FTRACE_FULL_REGS)
 #define _PIF_WARN_TRAP_SKIPPED		BIT(PIF_WARN_TRAP_SKIPPED)
 #define _PIF_PGM_CHECK			BIT(PIF_PGM_CHECK)
+#define _PIF_GUEST_SAE			BIT(PIF_GUEST_SAE)
 
 #define PSW32_MASK_PER		_AC(0x40000000, UL)
 #define PSW32_MASK_DAT		_AC(0x04000000, UL)
@@ -125,6 +127,7 @@ struct pt_regs {
 	union {
 		unsigned long orig_gpr2;
 		unsigned long monitor_code;
+		unsigned long sae_vcpu;
 	};
 	union {
 		struct {
diff --git a/arch/s390/include/asm/thread_info.h b/arch/s390/include/asm/thread_info.h
index 2554cef3a6a5..d6ef8196a46f 100644
--- a/arch/s390/include/asm/thread_info.h
+++ b/arch/s390/include/asm/thread_info.h
@@ -24,6 +24,12 @@
 
 #define STACK_INIT_OFFSET (THREAD_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE)
 
+/* thread_info.guest bits */
+#define TI_GUEST_NONE		0
+#define TI_GUEST_SIE		0x1
+#define TI_GUEST_SAE		0x2
+#define TI_GUEST_MASK		(TI_GUEST_SIE | TI_GUEST_SAE)
+
 #ifndef __ASSEMBLER__
 
 /*
@@ -36,7 +42,7 @@ struct thread_info {
 	unsigned long		flags;		/* low level flags */
 	unsigned long		syscall_work;	/* SYSCALL_WORK_ flags */
 	unsigned int		cpu;		/* current CPU */
-	unsigned char		sie;		/* running in SIE context */
+	unsigned char		guest;		/* running in guest context (SIE/SAE) */
 };
 
 /*
diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c
index e09158248248..82248f5b69a2 100644
--- a/arch/s390/kernel/asm-offsets.c
+++ b/arch/s390/kernel/asm-offsets.c
@@ -32,7 +32,7 @@ int main(void)
 	BLANK();
 	/* thread info offsets */
 	OFFSET(__TI_flags, task_struct, thread_info.flags);
-	OFFSET(__TI_sie, task_struct, thread_info.sie);
+	OFFSET(__TI_guest, task_struct, thread_info.guest);
 	BLANK();
 	/* pt_regs offsets */
 	OFFSET(__PT_PSW, pt_regs, psw);
@@ -54,6 +54,7 @@ int main(void)
 	OFFSET(__PT_R14, pt_regs, gprs[14]);
 	OFFSET(__PT_R15, pt_regs, gprs[15]);
 	OFFSET(__PT_ORIG_GPR2, pt_regs, orig_gpr2);
+	OFFSET(__PT_SAE_VCPU, pt_regs, sae_vcpu);
 	OFFSET(__PT_INT_CODE, pt_regs, int_code);
 	OFFSET(__PT_FLAGS, pt_regs, flags);
 	OFFSET(__PT_LAST_BREAK, pt_regs, last_break);
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 8ef6fc13fc08..bee1083ff214 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -120,7 +120,7 @@ _LPP_OFFSET	= __LC_LPP
 	ni	__SIE_PROG0C+3(%r9),0xfe		# no longer in SIE
 	lctlg	%c1,%c1,__LC_USER_ASCE(\lowcore)	# load primary asce
 	lg	%r9,__LC_CURRENT(\lowcore)
-	mvi	__TI_sie(%r9),0
+	mvi	__TI_guest(%r9),TI_GUEST_NONE
 	larl	%r9,sie_exit			# skip forward to sie_exit
 	.endm
 #endif
@@ -204,7 +204,7 @@ SYM_FUNC_START(__sie64a)
 	xc	__SF_SIE_RETURN(8,%r15),__SF_SIE_RETURN(%r15) # return code = 0
 	mvc	__SF_SIE_FLAGS(8,%r15),__TI_flags(%r14) # copy thread flags
 	lmg	%r0,%r13,0(%r4)			# load guest gprs 0-13
-	mvi	__TI_sie(%r14),1
+	mvi	__TI_guest(%r14),TI_GUEST_SIE
 	stosm	__SF_SIE_IRQ(%r15),0x03		# enable interrupts
 	lctlg	%c1,%c1,__SF_SIE_GUEST_ASCE(%r15) # load primary asce
 	lg	%r14,__SF_SIE_CONTROL(%r15)	# get control block pointer
@@ -227,7 +227,7 @@ SYM_FUNC_START(__sie64a)
 	GET_LC	%r14
 	lctlg	%c1,%c1,__LC_USER_ASCE(%r14)	# load primary asce
 	lg	%r14,__LC_CURRENT(%r14)
-	mvi	__TI_sie(%r14),0
+	mvi	__TI_guest(%r14),TI_GUEST_NONE
 SYM_INNER_LABEL(sie_exit, SYM_L_GLOBAL)
 	stnsm	__SF_SIE_IRQ(%r15),0xfc		# disable interrupts
 	lg	%r14,__SF_SIE_SAVEAREA(%r15)	# load guest register save area
@@ -257,12 +257,19 @@ SYM_FUNC_START(sae)
 	STBEAR	__SF_SAE_BEAR(%r15)		# save breaking event address register
 	stg	%r3,__SF_SAE_BLOCK(%r15)	# save sae block for perf
 	stg	%r4,__SF_SAE_VCPU(%r15)		# save vcpu ptr for interrupt handling
+	GET_LC	%r13
+	lg	%r14,__LC_CURRENT(%r13)
+	mvi	__TI_guest(%r14),TI_GUEST_SAE
 	stosm	__SF_SAE_IRQ(%r15),0x03
 SYM_INNER_LABEL(sae_entry, SYM_L_LOCAL)
 	.insn	rre,0xb9a50000,%r2,0		# Start Arm Execution
 # Let the next instruction be NOP to avoid triggering a machine check
 # and handling it in a guest as result of the instruction execution.
 	nopr	7
+.Lsae_leave:
+	GET_LC	%r13
+	lg	%r14,__LC_CURRENT(%r13)
+	mvi	__TI_guest(%r14),TI_GUEST_NONE
 SYM_INNER_LABEL(sae_exit, SYM_L_GLOBAL)
 	stnsm	__SF_SAE_IRQ(%r15),0xfc
 	LBEAR	__SF_SAE_BEAR(%r15)		# restore breaking event address register
@@ -352,8 +359,9 @@ SYM_CODE_START(pgm_check_handler)
 	jo	3f			# -> fault in user space
 #if IS_ENABLED(CONFIG_KVM)
 	lg	%r11,__LC_CURRENT(%r13)
-	tm	__TI_sie(%r11),0xff
+	tm	__TI_guest(%r11),TI_GUEST_SIE
 	jz	1f
+	# program check during SIE execution
 	BPENTER	__SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
 	SIEEXIT __SF_SIE_CONTROL(%r15),%r13
 	lghi	%r10,PGM_FLAG_GUEST_FAULT
@@ -429,21 +437,34 @@ SYM_CODE_START(\name)
 #endif
 	STBEAR	__LC_LAST_BREAK(%r13)
 	BPOFF
+	# clear r12 and r14 here, will be assigned vcpu pointer
+	xgr	%r12,%r12
+	xgr	%r14,%r14
 	lmg	%r8,%r9,\lc_old_psw(%r13)
 	tmhh	%r8,0x0001			# interrupting from user ?
 	jnz	1f
 #if IS_ENABLED(CONFIG_KVM)
 	lg	%r10,__LC_CURRENT(%r13)
-	tm	__TI_sie(%r10),0xff
+	tm	__TI_guest(%r10),TI_GUEST_MASK
 	jz	0f
+	tm	__TI_guest(%r10),TI_GUEST_SIE
+	jz	4f
+	# Interrupt during SIE execution
 	BPENTER	__SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
 	SIEEXIT __SF_SIE_CONTROL(%r15),%r13
+	j	0f
+4:	# Interrupt during SAE execution
+	larl	%r9,sae_exit
+	lg	%r12,__SF_SAE_VCPU(%r15)
+	lghi	%r14,_PIF_GUEST_SAE
+	mvi	__TI_guest(%r10),TI_GUEST_NONE
 #endif
 0:	aghi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
 	j	2f
 1:	lg	%r15,__LC_KERNEL_STACK(%r13)
 2:	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
 	la	%r11,STACK_FRAME_OVERHEAD(%r15)
+	stg	%r12,__PT_SAE_VCPU(%r11)		# store vcpu ptr, 0 if not in SAE
 	stmg	%r0,%r7,__PT_R0(%r11)
 	# clear user controlled registers to prevent speculative use
 	xgr	%r0,%r0
@@ -454,7 +475,7 @@ SYM_CODE_START(\name)
 	xgr	%r6,%r6
 	xgr	%r7,%r7
 	xgr	%r12,%r12
-	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
+	stg	%r14,__PT_FLAGS(%r11)
 	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA(%r13)
 	MBEAR	%r11,%r13
 	stmg	%r8,%r9,__PT_PSW(%r11)
@@ -512,9 +533,9 @@ SYM_CODE_START(mcck_int_handler)
 	jno	.Lmcck_panic
 #if IS_ENABLED(CONFIG_KVM)
 	lg	%r10,__LC_CURRENT(%r13)
-	tm	__TI_sie(%r10),0xff
+	tm	__TI_guest(%r10),TI_GUEST_SIE
 	jz	.Lmcck_user
-	# Need to compare the address instead of __TI_SIE flag.
+	# Need to compare the address instead of __TI_guest flag.
 	# Otherwise there would be a race between setting the flag
 	# and entering SIE (or leaving and clearing the flag). This
 	# would cause machine checks targeted at the guest to be
diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index 8f21bea349a6..4cc30ae63794 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -142,6 +142,9 @@ static int irq_pending(struct pt_regs *regs)
 	return CC_TRANSFORM(cc);
 }
 
+void (*kvm_s390_arm64_vcpu_exit)(unsigned long vcpu);
+EXPORT_SYMBOL_FOR_MODULES(kvm_s390_arm64_vcpu_exit, "kvm_arm64");
+
 void noinstr do_io_irq(struct pt_regs *regs)
 {
 	struct pt_regs *old_regs;
@@ -163,6 +166,9 @@ void noinstr do_io_irq(struct pt_regs *regs)
 			current->thread.last_break = regs->last_break;
 	}
 
+	if (test_pt_regs_flag(regs, PIF_GUEST_SAE))
+		kvm_s390_arm64_vcpu_exit(regs->sae_vcpu);
+
 	if (from_idle)
 		account_idle_time_irq();
 
@@ -204,6 +210,9 @@ void noinstr do_ext_irq(struct pt_regs *regs)
 			current->thread.last_break = regs->last_break;
 	}
 
+	if (test_pt_regs_flag(regs, PIF_GUEST_SAE))
+		kvm_s390_arm64_vcpu_exit(regs->sae_vcpu);
+
 	regs->int_code = get_lowcore()->ext_int_code_addr;
 	regs->int_parm = get_lowcore()->ext_params;
 	regs->int_parm_long = get_lowcore()->ext_params2;

-- 
2.55.0


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

* [PATCH 05/10] KVM: s390: arm64: Enable host irq
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (3 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390 Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:35   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 06/10] s390: Rename CIF_MCCK_GUEST to CIF_MCCK_SIE Andreas Grapentin
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Sven Schnelle <svens@linux.ibm.com>

Register KVM callbacks for host interrupt guest exits. If a host
interrupt happened during guest execution set the MODE to outside guets
mode.

Co-developed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
 arch/s390/kvm/arm64/arm.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 547f77be7e3c..cc8453bd820c 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -6,6 +6,7 @@
 #include <linux/kvm.h>
 #include <linux/kvm_types.h>
 #include <linux/kvm_host.h>
+#include <linux/rcupdate.h>
 #include <linux/cleanup.h>
 #include <linux/fpu.h>
 #include <linux/bitfield.h>
@@ -425,6 +426,13 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
 	return -EINVAL;
 }
 
+static noinstr void kvm_sae_exit_handler(unsigned long v)
+{
+	struct kvm_vcpu *vcpu = (struct kvm_vcpu *)v;
+
+	WRITE_ONCE(vcpu->mode, OUTSIDE_GUEST_MODE);
+}
+
 static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block,
 					struct kvm_vcpu *vcpu)
 {
@@ -517,7 +525,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		vcpu->arch.ctxt.elr_el1 = _vcpu_read_sys_reg(vcpu, SYS_ELR_EL1);
 		vcpu->arch.ctxt.spsr_el1 = _vcpu_read_sys_reg(vcpu, SYS_SPSR_EL1);
 
-		vcpu->mode = OUTSIDE_GUEST_MODE;
+		if (vcpu->mode != OUTSIDE_GUEST_MODE)
+			kvm_sae_exit_handler((unsigned long)vcpu);
 		vcpu->stat.exits++;
 
 		local_irq_enable();
@@ -798,6 +807,13 @@ static bool __init machine_supports_arm64_kvm(void)
 	return true;
 }
 
+static void unregister_callbacks(void)
+{
+	kvm_s390_arm64_vcpu_exit = NULL;
+	/* wait for all possible users of the callback to quiesce */
+	synchronize_rcu();
+}
+
 static int __init kvm_s390_arm64_init(void)
 {
 	int ret;
@@ -813,11 +829,23 @@ static int __init kvm_s390_arm64_init(void)
 		return ret;
 	}
 
-	return kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
+	kvm_s390_arm64_vcpu_exit = kvm_sae_exit_handler;
+
+	/*
+	 *  kvm_init _must_ be the very last thing done, as this exposes
+	 * /dev/kvm_arm64 to userspace, i.e. all infrastructure must be setup!
+	 */
+	ret = kvm_init(sizeof(struct kvm_vcpu), 0, THIS_MODULE);
+	if (ret) {
+		unregister_callbacks();
+		return ret;
+	}
+	return 0;
 }
 
 static __exit void kvm_s390_arm64_exit(void)
 {
+	unregister_callbacks();
 	kvm_exit();
 }
 

-- 
2.55.0


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

* [PATCH 06/10] s390: Rename CIF_MCCK_GUEST to CIF_MCCK_SIE
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (4 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 05/10] KVM: s390: arm64: Enable host irq Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests Andreas Grapentin
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

This change is a preparation for introducing CIF_MCCK_SAE as a new type
of guest for which MCCKs can be forwarded, so specify the guest type
explicitly in the name.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/include/asm/processor.h |  4 ++--
 arch/s390/kernel/entry.S          |  2 +-
 arch/s390/kernel/nmi.c            | 14 +++++++-------
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
index 9434c76c25b8..757b0b56d50c 100644
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@ -15,11 +15,11 @@
 #include <linux/bits.h>
 
 #define CIF_ENABLED_WAIT	5	/* in enabled wait state */
-#define CIF_MCCK_GUEST		6	/* machine check happening in guest */
+#define CIF_MCCK_SIE		6	/* machine check happening in SIE guest */
 #define CIF_DEDICATED_CPU	7	/* this CPU is dedicated */
 
 #define _CIF_ENABLED_WAIT	BIT(CIF_ENABLED_WAIT)
-#define _CIF_MCCK_GUEST		BIT(CIF_MCCK_GUEST)
+#define _CIF_MCCK_SIE		BIT(CIF_MCCK_SIE)
 #define _CIF_DEDICATED_CPU	BIT(CIF_DEDICATED_CPU)
 
 #define RESTART_FLAG_CTLREGS	_AC(1 << 0, U)
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index bee1083ff214..b53193deff93 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -545,7 +545,7 @@ SYM_CODE_START(mcck_int_handler)
 	larl	%r14,.Lsie_leave
 	clgrjhe	%r9,%r14, 4f
 	lg	%r10,__LC_PCPU(%r13)
-	oi	__PCPU_FLAGS+7(%r10), _CIF_MCCK_GUEST
+	oi	__PCPU_FLAGS+7(%r10),_CIF_MCCK_SIE
 4:	BPENTER	__SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
 	SIEEXIT __SF_SIE_CONTROL(%r15),%r13
 #endif
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index 56a15edc65d7..5ff85bb01d94 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -302,7 +302,7 @@ static bool notrace nmi_registers_valid(union mci mci)
 	 * appropriate actions. The host vector or FPU values have been
 	 * saved by KVM and will be restored by KVM.
 	 */
-	if (!mci.vr && !test_cpu_flag(CIF_MCCK_GUEST))
+	if (!mci.vr && !test_cpu_flag(CIF_MCCK_SIE))
 		return false;
 	if (!mci.ar)
 		return false;
@@ -319,7 +319,7 @@ static bool notrace nmi_registers_valid(union mci mci)
 	 * KVM and are not affected.
 	 */
 	cr2.reg = get_lowcore()->cregs_save_area[2];
-	if (cr2.gse && !mci.gs && !test_cpu_flag(CIF_MCCK_GUEST))
+	if (cr2.gse && !mci.gs && !test_cpu_flag(CIF_MCCK_SIE))
 		return false;
 	if (!mci.ms || !mci.pm || !mci.ia)
 		return false;
@@ -386,7 +386,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * including Delayed Access Exception into the guest
 	 * instead of damaging the host if they happen in the guest.
 	 */
-	if (mci.pd && !test_cpu_flag(CIF_MCCK_GUEST)) {
+	if (mci.pd && !test_cpu_flag(CIF_MCCK_SIE)) {
 		if (mci.b) {
 			/* Processing backup -> verify if we can survive this */
 			u64 z_mcic, o_mcic, t_mcic;
@@ -437,7 +437,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * Backup the machine check's info if it happens when the guest
 	 * is running.
 	 */
-	if (test_cpu_flag(CIF_MCCK_GUEST))
+	if (test_cpu_flag(CIF_MCCK_SIE))
 		s390_backup_mcck_info(regs);
 
 	if (mci.cd) {
@@ -456,7 +456,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * Reinject storage related machine checks into the guest if they
 	 * happen when the guest is running.
 	 */
-	if (!test_cpu_flag(CIF_MCCK_GUEST)) {
+	if (!test_cpu_flag(CIF_MCCK_SIE)) {
 		/* Storage error uncorrected */
 		if (mci.se)
 			s390_handle_damage();
@@ -484,12 +484,12 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * because they refer to host conditions only.
 	 */
 	mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK);
-	if (test_cpu_flag(CIF_MCCK_GUEST) &&
+	if (test_cpu_flag(CIF_MCCK_SIE) &&
 	(mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code) {
 		/* Set sie return code for host's later handling */
 		((struct stack_frame *)regs->gprs[15])->sie_return = SIE64_RETURN_MCCK;
 	}
-	clear_cpu_flag(CIF_MCCK_GUEST);
+	clear_cpu_flag(CIF_MCCK_SIE);
 
 	if (mcck_pending)
 		schedule_mcck_handler();

-- 
2.55.0


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

* [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (5 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 06/10] s390: Rename CIF_MCCK_GUEST to CIF_MCCK_SIE Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:40   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 08/10] KVM: s390: arm64: Enable SError injection Andreas Grapentin
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

Detect machine checks occurring during SAE execution, fix up the return
address to sae_exit, and pass the vCPU pointer to s390_do_machine_check().
Forward the machine check details to KVM ARM64 via a new backup callback
for later guest injection. Prevent host damage termination for errors
that are caused by the guest.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
 arch/s390/include/asm/nmi.h       |  6 ++++-
 arch/s390/include/asm/processor.h |  2 ++
 arch/s390/kernel/entry.S          | 17 ++++++++++++-
 arch/s390/kernel/nmi.c            | 50 +++++++++++++++++++++++++++++++++++----
 4 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/arch/s390/include/asm/nmi.h b/arch/s390/include/asm/nmi.h
index 7919b2b9ac9c..e4020deee997 100644
--- a/arch/s390/include/asm/nmi.h
+++ b/arch/s390/include/asm/nmi.h
@@ -77,7 +77,9 @@ union mci {
 		u64 da :  1; /* 34 delayed access exception */
 		u64    :  1; /* 35 */
 		u64 gs :  1; /* 36 guarded storage registers validity */
-		u64    :  5; /* 37-41 */
+		u64    :  1; /* 37 */
+		u64 au :  1; /* 38 Arm unique CPU register validity */
+		u64    :  3; /* 39-41 */
 		u64 pr :  1; /* 42 tod programmable register validity */
 		u64 fc :  1; /* 43 fp control register validity */
 		u64 ap :  1; /* 44 ancillary report */
@@ -100,6 +102,8 @@ struct mcesa {
 
 struct pt_regs;
 
+struct mcck_volatile_info;
+extern void (*kvm_sae_backup_mci)(void *vcpu, struct mcck_volatile_info *mcck_info);
 void nmi_alloc_mcesa_early(u64 *mcesad);
 int nmi_alloc_mcesa(u64 *mcesad);
 void nmi_free_mcesa(u64 *mcesad);
diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
index 757b0b56d50c..6f887f349412 100644
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@ -14,6 +14,7 @@
 
 #include <linux/bits.h>
 
+#define CIF_MCCK_SAE		0	/* machine check happening in SAE guest */
 #define CIF_ENABLED_WAIT	5	/* in enabled wait state */
 #define CIF_MCCK_SIE		6	/* machine check happening in SIE guest */
 #define CIF_DEDICATED_CPU	7	/* this CPU is dedicated */
@@ -21,6 +22,7 @@
 #define _CIF_ENABLED_WAIT	BIT(CIF_ENABLED_WAIT)
 #define _CIF_MCCK_SIE		BIT(CIF_MCCK_SIE)
 #define _CIF_DEDICATED_CPU	BIT(CIF_DEDICATED_CPU)
+#define _CIF_MCCK_SAE		BIT(CIF_MCCK_SAE)
 
 #define RESTART_FLAG_CTLREGS	_AC(1 << 0, U)
 
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index b53193deff93..7691d0cb6e42 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -506,6 +506,7 @@ INT_HANDLER io_int_handler,__LC_IO_OLD_PSW,do_io_irq
 SYM_CODE_START(mcck_int_handler)
 	BPOFF
 	GET_LC	%r13
+	xgr	%r12,%r12
 	lmg	%r8,%r9,__LC_MCK_OLD_PSW(%r13)
 	TSTMSK	__LC_MCCK_CODE(%r13),MCCK_CODE_SYSTEM_DAMAGE
 	jo	.Lmcck_panic		# yes -> rest of mcck code invalid
@@ -533,8 +534,10 @@ SYM_CODE_START(mcck_int_handler)
 	jno	.Lmcck_panic
 #if IS_ENABLED(CONFIG_KVM)
 	lg	%r10,__LC_CURRENT(%r13)
-	tm	__TI_guest(%r10),TI_GUEST_SIE
+	tm	__TI_guest(%r10),TI_GUEST_MASK
 	jz	.Lmcck_user
+	tm	__TI_guest(%r10),TI_GUEST_SIE
+	jz	.Lmcck_sae
 	# Need to compare the address instead of __TI_guest flag.
 	# Otherwise there would be a race between setting the flag
 	# and entering SIE (or leaving and clearing the flag). This
@@ -548,10 +551,22 @@ SYM_CODE_START(mcck_int_handler)
 	oi	__PCPU_FLAGS+7(%r10),_CIF_MCCK_SIE
 4:	BPENTER	__SF_SIE_FLAGS(%r15),_TIF_ISOLATE_BP_GUEST
 	SIEEXIT __SF_SIE_CONTROL(%r15),%r13
+	j	.Lmcck_user
+.Lmcck_sae:
+	larl	%r14,sae_entry
+	clgrjl	%r9,%r14,.Lmcck_user
+	larl	%r14,.Lsae_leave
+	clgrjhe	%r9,%r14,.Lmcck_user
+	mvi	__TI_guest(%r10),TI_GUEST_NONE
+	lg	%r10,__LC_PCPU(%r13)
+	oi	__PCPU_FLAGS+7(%r10),_CIF_MCCK_SAE
+	larl	%r9,sae_exit
+	lg	%r12,__SF_SAE_VCPU(%r15)
 #endif
 .Lmcck_user:
 	lg	%r15,__LC_MCCK_STACK(%r13)
 	la	%r11,STACK_FRAME_OVERHEAD(%r15)
+	stg	%r12,__PT_SAE_VCPU(%r11)		# store vcpu ptr, 0 if not in SAE
 	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
 	lay	%r14,__LC_GPREGS_SAVE_AREA(%r13)
 	mvc	__PT_R0(128,%r11),0(%r14)
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index 5ff85bb01d94..5cc0bfe221ed 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -269,6 +269,11 @@ void s390_handle_mcck(void)
 	}
 }
 
+static __always_inline bool mcck_in_guest(void)
+{
+	return test_cpu_flag(CIF_MCCK_SIE) || test_cpu_flag(CIF_MCCK_SAE);
+}
+
 /**
  * nmi_registers_valid - verify if registers are valid
  * @mci: machine check interruption code
@@ -302,7 +307,7 @@ static bool notrace nmi_registers_valid(union mci mci)
 	 * appropriate actions. The host vector or FPU values have been
 	 * saved by KVM and will be restored by KVM.
 	 */
-	if (!mci.vr && !test_cpu_flag(CIF_MCCK_SIE))
+	if (!mci.vr && !mcck_in_guest())
 		return false;
 	if (!mci.ar)
 		return false;
@@ -317,6 +322,8 @@ static bool notrace nmi_registers_valid(union mci mci)
 	 * guest. The guest will be notified by KVM code and the guests machine
 	 * check handling must take care of this. The host values are saved by
 	 * KVM and are not affected.
+	 * For SAE, the guest does not use GS, and KVM does not save / restore
+	 * the host values, so they can not be recreated.
 	 */
 	cr2.reg = get_lowcore()->cregs_save_area[2];
 	if (cr2.gse && !mci.gs && !test_cpu_flag(CIF_MCCK_SIE))
@@ -327,6 +334,31 @@ static bool notrace nmi_registers_valid(union mci mci)
 }
 NOKPROBE_SYMBOL(nmi_registers_valid);
 
+void (*kvm_sae_backup_mci)(void *vcpu, struct mcck_volatile_info *mcck_info);
+EXPORT_SYMBOL_FOR_MODULES(kvm_sae_backup_mci, "kvm_arm64");
+
+/*
+ * Backup the arm guest's machine check info to its vCPU
+ * For arm guests the vcpu pointer is stored to the sf during SAE
+ * The handling is forwarded via a callback.
+ */
+static void notrace sae_backup_mci(void *vcpu)
+{
+	struct mcck_volatile_info mcck_backup = { 0 };
+
+	if (!vcpu || !kvm_sae_backup_mci) {
+		/* Something's seriously wrong, stop system. */
+		s390_handle_damage();
+	}
+
+	mcck_backup.mcic = get_lowcore()->mcck_interruption_code & ~MCCK_CODE_NO_GUEST;
+	mcck_backup.ext_damage_code = get_lowcore()->external_damage_code;
+	mcck_backup.failing_storage_address = get_lowcore()->failing_storage_address;
+
+	kvm_sae_backup_mci(vcpu, &mcck_backup);
+}
+NOKPROBE_SYMBOL(sae_backup_mci);
+
 /*
  * Backup the guest's machine check info to its description block
  */
@@ -386,7 +418,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * including Delayed Access Exception into the guest
 	 * instead of damaging the host if they happen in the guest.
 	 */
-	if (mci.pd && !test_cpu_flag(CIF_MCCK_SIE)) {
+	if (mci.pd && !mcck_in_guest()) {
 		if (mci.b) {
 			/* Processing backup -> verify if we can survive this */
 			u64 z_mcic, o_mcic, t_mcic;
@@ -440,6 +472,16 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	if (test_cpu_flag(CIF_MCCK_SIE))
 		s390_backup_mcck_info(regs);
 
+	mcck_dam_code = mci.val & MCIC_SUBCLASS_MASK;
+	/*
+	 * Backup the machine check info for the arm64 guest only if it
+	 * is not a host-only condition, see the CIF_MCCK_SIE handling
+	 * below.
+	 */
+	if (test_cpu_flag(CIF_MCCK_SAE) &&
+	    (mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code)
+		sae_backup_mci((void *)regs->sae_vcpu);
+
 	if (mci.cd) {
 		/* Timing facility damage */
 		s390_handle_damage();
@@ -456,7 +498,7 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * Reinject storage related machine checks into the guest if they
 	 * happen when the guest is running.
 	 */
-	if (!test_cpu_flag(CIF_MCCK_SIE)) {
+	if (!mcck_in_guest()) {
 		/* Storage error uncorrected */
 		if (mci.se)
 			s390_handle_damage();
@@ -483,13 +525,13 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
 	 * machine checks, they will not be reinjected into the guest
 	 * because they refer to host conditions only.
 	 */
-	mcck_dam_code = (mci.val & MCIC_SUBCLASS_MASK);
 	if (test_cpu_flag(CIF_MCCK_SIE) &&
 	(mcck_dam_code & MCCK_CODE_NO_GUEST) != mcck_dam_code) {
 		/* Set sie return code for host's later handling */
 		((struct stack_frame *)regs->gprs[15])->sie_return = SIE64_RETURN_MCCK;
 	}
 	clear_cpu_flag(CIF_MCCK_SIE);
+	clear_cpu_flag(CIF_MCCK_SAE);
 
 	if (mcck_pending)
 		schedule_mcck_handler();

-- 
2.55.0


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

* [PATCH 08/10] KVM: s390: arm64: Enable SError injection
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (6 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:34   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding Andreas Grapentin
  2026-12-04 12:09 ` [PATCH 10/10] s390/perf: Recognize SAE guests Andreas Grapentin
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

Allow KVM to inject an Serror into its guest. On SAE exit re-sync the
SError bit HCR_EL2.VSE bit with the HCR_EL2 value saved on SAE exit, as
hardware clears VSE when the guest takes the virtual SError.

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
 arch/s390/kvm/arm64/arm.c          |  6 ++++++
 arch/s390/kvm/arm64/inject_fault.c | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index cc8453bd820c..49e2ffcfdf22 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -525,6 +525,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		vcpu->arch.ctxt.elr_el1 = _vcpu_read_sys_reg(vcpu, SYS_ELR_EL1);
 		vcpu->arch.ctxt.spsr_el1 = _vcpu_read_sys_reg(vcpu, SYS_SPSR_EL1);
 
+		/* Cleared by hardware once the guest takes the vSError. */
+		if (vcpu->arch.hcr_el2 & HCR_EL2_VSE) {
+			vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE;
+			vcpu->arch.hcr_el2 |= vcpu_read_host_sys_reg(vcpu, SYS_HCR_EL2) & HCR_EL2_VSE;
+		}
+
 		if (vcpu->mode != OUTSIDE_GUEST_MODE)
 			kvm_sae_exit_handler((unsigned long)vcpu);
 		vcpu->stat.exits++;
diff --git a/arch/s390/kvm/arm64/inject_fault.c b/arch/s390/kvm/arm64/inject_fault.c
index 33f40c5188c9..82c924c45a81 100644
--- a/arch/s390/kvm/arm64/inject_fault.c
+++ b/arch/s390/kvm/arm64/inject_fault.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <arm64/kvm_emulate.h>
+#include <arm64/esr.h>
 
 static void pend_sync_exception(struct kvm_vcpu *vcpu)
 {
@@ -80,3 +81,17 @@ void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr)
 	pend_sync_exception(vcpu);
 	vcpu_write_sys_reg(vcpu, esr, ESR_EL1);
 }
+
+/**
+ * kvm_inject_serror_esr() - inject a virtual SError into the guest
+ * @vcpu: The vCPU in which to inject the SError
+ * @esr: The ESR ISS value describing the SError
+ */
+int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)
+{
+	lockdep_assert_held(&vcpu->mutex);
+
+	vcpu_write_host_sys_reg(vcpu, esr & ESR_ELx_ISS_MASK, SYS_VSESR_EL2);
+	vcpu->arch.hcr_el2 |= HCR_EL2_VSE;
+	return 1;
+}

-- 
2.55.0


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

* [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (7 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 08/10] KVM: s390: arm64: Enable SError injection Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:33   ` sashiko-bot
  2026-12-04 12:09 ` [PATCH 10/10] s390/perf: Recognize SAE guests Andreas Grapentin
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

From: Steffen Eiden <seiden@linux.ibm.com>

Register KVM callback for machine check backup info. On resume,
translate saved machine check conditions into ARM64 SError exceptions
and reinject them into the guest via kvm_inject_serror_esr().

Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Co-developed-by: Andreas Grapentin <gra@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
---
 arch/s390/include/asm/kvm_host_arm64.h |  3 +++
 arch/s390/kvm/arm64/arm.c              | 44 ++++++++++++++++++++++++++++++++++
 arch/s390/kvm/arm64/reset.c            |  3 +++
 3 files changed, 50 insertions(+)

diff --git a/arch/s390/include/asm/kvm_host_arm64.h b/arch/s390/include/asm/kvm_host_arm64.h
index a76e1bfc64bb..5d9487f37482 100644
--- a/arch/s390/include/asm/kvm_host_arm64.h
+++ b/arch/s390/include/asm/kvm_host_arm64.h
@@ -116,6 +116,9 @@ struct kvm_vcpu_arch {
 
 	struct kvm_s390_mmu_cache *mc;
 
+	/* Saved machine check info when mcck occurs during SAE execution */
+	struct mcck_volatile_info mcck_info;
+
 	void *debugfs_state_data;
 };
 
diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
index 49e2ffcfdf22..22ed1109f7b8 100644
--- a/arch/s390/kvm/arm64/arm.c
+++ b/arch/s390/kvm/arm64/arm.c
@@ -13,8 +13,11 @@
 
 #include <asm/access-regs.h>
 #include <asm/aef.h>
+#include <asm/irq.h>
+#include <asm/nmi.h>
 
 #include <arm64/kvm_emulate.h>
+#include <arm64/esr.h>
 #include <arm64/sysreg.h>
 #include <arm64/sys_regs.h>
 
@@ -433,6 +436,42 @@ static noinstr void kvm_sae_exit_handler(unsigned long v)
 	WRITE_ONCE(vcpu->mode, OUTSIDE_GUEST_MODE);
 }
 
+static noinstr void
+kvm_sae_backup_mcck_info(void *v, struct mcck_volatile_info *mcck_info)
+{
+	struct kvm_vcpu *vcpu = v;
+
+	vcpu->arch.mcck_info = *mcck_info;
+}
+
+static u64 mci_to_esr(union mci mci)
+{
+	/* for now, as a reasonable approximation, consider any host
+	 * machine check during arm64 guest execution a fatal uncontainable
+	 * event for the arm64 guest.
+	 */
+	return ESR_ELx_AET_UEU | ESR_ELx_FSC_SERROR;
+}
+
+static void reinject_mcck(struct kvm_vcpu *vcpu)
+{
+	struct mcck_volatile_info *mcck;
+	union mci mci;
+	u64 esr;
+
+	mcck = &vcpu->arch.mcck_info;
+	mci.val = mcck->mcic;
+
+	if (!mcck->mcic)
+		return;
+
+	esr = mci_to_esr(mci);
+
+	memset(mcck, 0, sizeof(*mcck));
+
+	kvm_inject_serror_esr(vcpu, esr);
+}
+
 static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block,
 					struct kvm_vcpu *vcpu)
 {
@@ -492,6 +531,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		if (ret > 0)
 			ret = check_vcpu_requests(vcpu);
 
+		if (ret > 0)
+			reinject_mcck(vcpu);
+
 		vcpu->arch.sae_block.icptr = 0;
 
 		local_irq_disable();
@@ -816,6 +858,7 @@ static bool __init machine_supports_arm64_kvm(void)
 static void unregister_callbacks(void)
 {
 	kvm_s390_arm64_vcpu_exit = NULL;
+	kvm_sae_backup_mci = NULL;
 	/* wait for all possible users of the callback to quiesce */
 	synchronize_rcu();
 }
@@ -836,6 +879,7 @@ static int __init kvm_s390_arm64_init(void)
 	}
 
 	kvm_s390_arm64_vcpu_exit = kvm_sae_exit_handler;
+	kvm_sae_backup_mci = kvm_sae_backup_mcck_info;
 
 	/*
 	 *  kvm_init _must_ be the very last thing done, as this exposes
diff --git a/arch/s390/kvm/arm64/reset.c b/arch/s390/kvm/arm64/reset.c
index 2ae363f6821a..206f42ba3256 100644
--- a/arch/s390/kvm/arm64/reset.c
+++ b/arch/s390/kvm/arm64/reset.c
@@ -109,6 +109,9 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)
 	vcpu_reset_cnthctl(vcpu);
 	vcpu_reset_icc(vcpu);
 
+	/* Discard any pending mcck's */
+	memset(&vcpu->arch.mcck_info, 0, sizeof(vcpu->arch.mcck_info));
+
 	if (reset_state.reset) {
 		*vcpu_pc(vcpu) = reset_state.pc;
 		vcpu_clear_flag(vcpu, PENDING_EXCEPTION);

-- 
2.55.0


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

* [PATCH 10/10] s390/perf: Recognize SAE guests
  2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
                   ` (8 preceding siblings ...)
  2026-12-04 12:09 ` [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding Andreas Grapentin
@ 2026-12-04 12:09 ` Andreas Grapentin
  2026-12-04 12:30   ` sashiko-bot
  9 siblings, 1 reply; 19+ messages in thread
From: Andreas Grapentin @ 2026-12-04 12:09 UTC (permalink / raw)
  To: Steffen Eiden, Marc Zyngier, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger, Sven Schnelle,
	Janosch Frank, Claudio Imbrenda, David Hildenbrand, Oleg Nesterov,
	Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark
  Cc: kvm, linux-s390, linux-perf-users, linux-kernel,
	Andreas Grapentin

Recognize interrupted ARM64 guest execution for perf by checking whether
the interruption happened in an SAE guest.

For ease of implementation, duplicate the relevant arm64 architected PSR
bits, since the s390 kernel has no access to arm64 sysreg defines.

Values extracted from: arch/arm64/include/uapi/asm/ptrace.h

Co-developed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Andreas Grapentin <gra@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/kernel/perf_event.c | 62 +++++++++++++++++++++++++++++++++----------
 1 file changed, 48 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
index 606750bae508..00464fbe33ea 100644
--- a/arch/s390/kernel/perf_event.c
+++ b/arch/s390/kernel/perf_event.c
@@ -18,6 +18,7 @@
 #include <asm/stacktrace.h>
 #include <asm/irq.h>
 #include <asm/cpu_mf.h>
+#include <asm/kvm_host_arm64_types.h>
 #include <asm/lowcore.h>
 #include <asm/processor.h>
 #include <asm/sysinfo.h>
@@ -33,31 +34,64 @@ static struct kvm_s390_sie_block *sie_block(struct pt_regs *regs)
 	return (struct kvm_s390_sie_block *)stack->sie_control_block;
 }
 
-static bool is_in_guest(struct pt_regs *regs)
+static struct kvm_sae_block *sae_block(struct pt_regs *regs)
 {
-	if (user_mode(regs))
-		return false;
-#if IS_ENABLED(CONFIG_KVM)
-	return instruction_pointer(regs) == (unsigned long) &sie_exit;
-#else
-	return false;
-#endif
+	struct stack_frame *stack = (struct stack_frame *)regs->gprs[15];
+
+	if (!stack)
+		return NULL;
+
+	return (struct kvm_sae_block *)stack->sae_block;
 }
 
-static unsigned long guest_is_user_mode(struct pt_regs *regs)
+enum guest_type {
+	GUEST_TYPE_NONE = 0,
+	GUEST_TYPE_SIE,
+	GUEST_TYPE_SAE,
+};
+
+static enum guest_type is_in_guest(struct pt_regs *regs)
 {
-	return sie_block(regs)->gpsw.mask & PSW_MASK_PSTATE;
+#if IS_ENABLED(CONFIG_KVM)
+	if (user_mode(regs))
+		return GUEST_TYPE_NONE;
+	if (instruction_pointer(regs) == (unsigned long)&sie_exit)
+		return GUEST_TYPE_SIE;
+	if (instruction_pointer(regs) == (unsigned long)&sae_exit)
+		return GUEST_TYPE_SAE;
+#endif
+	return GUEST_TYPE_NONE;
 }
 
-static unsigned long instruction_pointer_guest(struct pt_regs *regs)
+/*
+ * Duplicate of relevant arm64 architected PSR bits.
+ * S390 kernel has no access to arm64 sysreg values.
+ */
+#define PSR_MODE_EL0t	0x00000000
+#define PSR_MODE_MASK	0x0000000f
+
+static bool guest_is_user_mode(struct pt_regs *regs)
 {
-	return sie_block(regs)->gpsw.addr;
+	switch (is_in_guest(regs)) {
+	case GUEST_TYPE_SIE:
+		return sie_block(regs)->gpsw.mask & PSW_MASK_PSTATE;
+	case GUEST_TYPE_SAE:
+		return (sae_block(regs)->pstate & PSR_MODE_MASK) == PSR_MODE_EL0t;
+	default:
+		return false;
+	}
 }
 
 unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
 {
-	return is_in_guest(regs) ? instruction_pointer_guest(regs)
-				 : instruction_pointer(regs);
+	switch (is_in_guest(regs)) {
+	case GUEST_TYPE_SIE:
+		return sie_block(regs)->gpsw.addr;
+	case GUEST_TYPE_SAE:
+		return sae_block(regs)->pc;
+	default:
+		return instruction_pointer(regs);
+	}
 }
 
 static unsigned long perf_misc_guest_flags(struct pt_regs *regs)

-- 
2.55.0


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

* Re: [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols
  2026-12-04 12:09 ` [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols Andreas Grapentin
@ 2026-12-04 12:30   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:30 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: s390: instrumentable virt_to_phys() in noinstr
  arm_vcpu_enter_exit()
--

commit 155c5874ac9bbb93ac7fc196ae66f83afc0d9d94
Author: Steffen Eiden <seiden@linux.ibm.com>

s390/sae: Add sae_entry and sae_exit symbols

This commit adds sae_entry and sae_exit boundary labels around the SAE
instruction in entry.S, exports sae_exit, and moves the sie_exit declaration
alongside sae_exit in asm/kvm_host.h.

> diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
> index 14dea207b30e8..8ef6fc13fc08c 100644
> --- a/arch/s390/kernel/entry.S
> +++ b/arch/s390/kernel/entry.S
> @@ -258,10 +258,12 @@ SYM_FUNC_START(sae)
>  	stg	%r3,__SF_SAE_BLOCK(%r15)	# save sae block for perf
>  	stg	%r4,__SF_SAE_VCPU(%r15)		# save vcpu ptr for interrupt handling
>  	stosm	__SF_SAE_IRQ(%r15),0x03
> +SYM_INNER_LABEL(sae_entry, SYM_L_LOCAL)
>  	.insn	rre,0xb9a50000,%r2,0		# Start Arm Execution

[Severity: Low]
Can calling virt_to_phys(sae_block) inside noinstr arm_vcpu_enter_exit()
violate the non-instrumentable guest-entry window under CONFIG_DEBUG_VIRTUAL?

In commit "s390/sae: Prepare handling host interrupts during SAE execution",
virt_to_phys(sae_block) was moved into arm_vcpu_enter_exit() between
guest_state_enter_irqoff() and sae():

arch/s390/kvm/arm64/arm.c:arm_vcpu_enter_exit() {
	guest_timing_enter_irqoff();
	guest_state_enter_irqoff();

	sae(virt_to_phys(sae_block), sae_block, vcpu);

	guest_state_exit_irqoff();
	guest_timing_exit_irqoff();
}

With CONFIG_DEBUG_VIRTUAL=y, virt_to_phys() expands through __pa() to the
out-of-line __phys_addr() and is_vmalloc_or_module_addr(), neither of which
is marked noinstr, notrace, or NOKPROBE_SYMBOL.

If a kprobe fires on __phys_addr() here while hardware IRQs are still
disabled, __do_pgm_check() -> irqentry_enter_from_kernel_mode() calls
lockdep_hardirqs_off(), and irqentry_exit_to_kernel_mode_after_preempt()
skips lockdep_hardirqs_on() because regs_irqs_disabled(regs) is true.

That leaves lockdep hardirq state disabled when sae() enables hardware IRQs
via stosm, leading to lockdep hardirq-state desynchronization and splats.
Computing virt_to_phys(sae_block) before guest_timing_enter_irqoff() or in
kvm_arch_vcpu_ioctl_run() avoids calling instrumentable code in this window.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=2

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

* Re: [PATCH 10/10] s390/perf: Recognize SAE guests
  2026-12-04 12:09 ` [PATCH 10/10] s390/perf: Recognize SAE guests Andreas Grapentin
@ 2026-12-04 12:30   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:30 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] s390/perf: NULL dereference of sae_block() in
  perf_arch_instruction_pointer()
--

commit 4b5d91e0d26617e654b0c5cf570e3076efc5d4a8
Author: Andreas Grapentin <gra@linux.ibm.com>

s390/perf: Recognize SAE guests

This commit extends s390 perf guest detection to recognize ARM64 SAE
guests alongside SIE guests, retrieving the guest instruction pointer and
user/kernel mode from struct kvm_sae_block.

> diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c
> index 606750bae508d..00464fbe33ead 100644
> --- a/arch/s390/kernel/perf_event.c
> +++ b/arch/s390/kernel/perf_event.c

[ ... ]

> @@ -33,31 +34,64 @@ static struct kvm_s390_sie_block *sie_block(struct pt_regs *regs)
>  	return (struct kvm_s390_sie_block *)stack->sie_control_block;
>  }
>  
> -static bool is_in_guest(struct pt_regs *regs)
> +static struct kvm_sae_block *sae_block(struct pt_regs *regs)
>  {
> -	if (user_mode(regs))
> -		return false;
> -#if IS_ENABLED(CONFIG_KVM)
> -	return instruction_pointer(regs) == (unsigned long) &sie_exit;
> -#else
> -	return false;
> -#endif
> +	struct stack_frame *stack = (struct stack_frame *)regs->gprs[15];
> +
> +	if (!stack)
> +		return NULL;
> +
> +	return (struct kvm_sae_block *)stack->sae_block;
>  }
>  
> -static unsigned long guest_is_user_mode(struct pt_regs *regs)
> +enum guest_type {
> +	GUEST_TYPE_NONE = 0,
> +	GUEST_TYPE_SIE,
> +	GUEST_TYPE_SAE,
> +};
> +
> +static enum guest_type is_in_guest(struct pt_regs *regs)
>  {
> -	return sie_block(regs)->gpsw.mask & PSW_MASK_PSTATE;
> +#if IS_ENABLED(CONFIG_KVM)
> +	if (user_mode(regs))
> +		return GUEST_TYPE_NONE;
> +	if (instruction_pointer(regs) == (unsigned long)&sie_exit)
> +		return GUEST_TYPE_SIE;
> +	if (instruction_pointer(regs) == (unsigned long)&sae_exit)
> +		return GUEST_TYPE_SAE;
> +#endif
> +	return GUEST_TYPE_NONE;
>  }

[ ... ]

>  unsigned long perf_arch_instruction_pointer(struct pt_regs *regs)
>  {
> -	return is_in_guest(regs) ? instruction_pointer_guest(regs)
> -				 : instruction_pointer(regs);
> +	switch (is_in_guest(regs)) {
> +	case GUEST_TYPE_SIE:
> +		return sie_block(regs)->gpsw.addr;
> +	case GUEST_TYPE_SAE:
> +		return sae_block(regs)->pc;
> +	default:
> +		return instruction_pointer(regs);
> +	}
>  }

[Severity: High]
Can sae_block(regs)->pc cause a NULL pointer dereference when called with
synthetic pt_regs from CPU-MF sampling?

In arch/s390/kernel/perf_cpum_sf.c, perf_push_sample() builds a
zero-initialized pt_regs (leaving regs.gprs[15] == 0) with the sampled
instruction address and pstate in regs.psw, then calls
perf_event_overflow() -> ... -> perf_arch_instruction_pointer().

Unlike perf_arch_misc_flags(), which checks !regs->gprs[15] before calling
is_in_guest(), neither is_in_guest() nor perf_arch_instruction_pointer()
guards against a zero stack pointer.

When a supervisor-mode hardware sample lands on sae_exit, is_in_guest()
returns GUEST_TYPE_SAE, sae_block() returns NULL, and sae_block(regs)->pc
dereferences a NULL pointer.  With relocated lowcore enabled, address 0 is
unmapped and this crashes the host in hardirq context.

Returning GUEST_TYPE_NONE from is_in_guest() when !regs->gprs[15] (or
checking the returned block pointer for NULL) would prevent this and also
close the same pre-existing hazard on the GUEST_TYPE_SIE path.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=10

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

* Re: [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution
  2026-12-04 12:09 ` [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution Andreas Grapentin
@ 2026-12-04 12:31   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:31 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: s390: arm64: virt_to_phys() called in noinstr
  arm_vcpu_enter_exit()
--

commit fb3ea3faefcae4e47369e4eafbb03a10f1609380
Author: Steffen Eiden <seiden@linux.ibm.com>

s390/sae: Prepare handling host interrupts during SAE execution

This commit moves host interrupt enable/disable handling around SAE
execution into entry.S and extends the SAE stack frame and sae() calling
convention to carry the SAE control block, vCPU pointer, and IRQ state.

> diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
> index cd59a382a70ca..547f77be7e3cb 100644
> --- a/arch/s390/kvm/arm64/arm.c
> +++ b/arch/s390/kvm/arm64/arm.c
> @@ -425,23 +425,13 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
>  	return -EINVAL;
>  }
>  
> -static noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block)
> +static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block,
> +					struct kvm_vcpu *vcpu)
>  {
>  	guest_timing_enter_irqoff();
>  	guest_state_enter_irqoff();
>  
> -	/*
> -	 * External interrupts may occur while the SAE instruction is executing
> -	 * and must preempt guest execution to maintain responsiveness of the
> -	 * host.
> -	 *
> -	 * As a temporary workaround, run SAE with interrupts enabled so that any
> -	 * interrupt is taken via the normal host interrupt path rather than
> -	 * being subsumed inside the SAE window.
> -	 */
> -	raw_local_irq_enable();
> -	sae(sae_block);
> -	raw_local_irq_disable();
> +	sae(virt_to_phys(sae_block), sae_block, vcpu);
>  
>  	guest_state_exit_irqoff();
>  	guest_timing_exit_irqoff();

[Severity: Medium]
Is it safe to call virt_to_phys() inside the noinstr arm_vcpu_enter_exit()
window?

With CONFIG_DEBUG_VIRTUAL enabled, virt_to_phys() expands via __pa() to the
out-of-line __phys_addr() and is_vmalloc_or_module_addr(), neither of which
is noinstr.  At this point guest_state_enter_irqoff() has already marked
lockdep hardirqs enabled while hardware IRQs remain disabled until sae().

If a tracer or kprobe on __phys_addr() or is_vmalloc_or_module_addr() takes
a lockdep-tracked lock, check_flags() hits
DEBUG_LOCKS_WARN_ON(lockdep_hardirqs_enabled()) and disables lockdep.

Computing virt_to_phys(&vcpu->arch.sae_block) in kvm_arch_vcpu_ioctl_run()
before calling arm_vcpu_enter_exit() would keep this window
non-instrumentable.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=1

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

* Re: [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding
  2026-12-04 12:09 ` [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding Andreas Grapentin
@ 2026-12-04 12:33   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:33 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] KVM: s390: arm64: fatal SError injected for non-fatal s390
  machine checks
- [Low] KVM: s390: arm64: mci_to_esr() encodes AET_UEU instead of AET_UC
--

commit ed3b42734c8b960c56a23fa774b7d0e1c9dc90bc
Author: Steffen Eiden <seiden@linux.ibm.com>

KVM: s390: arm64: Enable mcck forwarding

This commit registers the KVM machine check backup callback for arm64
guests on s390 and reinjects saved machine checks as virtual SError
exceptions before resuming the guest.

> diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
> index 49e2ffcfdf22f..22ed1109f7b8f 100644
> --- a/arch/s390/kvm/arm64/arm.c
> +++ b/arch/s390/kvm/arm64/arm.c

[ ... ]

> @@ -433,6 +436,42 @@ static noinstr void kvm_sae_exit_handler(unsigned long v)

[ ... ]

> +static u64 mci_to_esr(union mci mci)
> +{
> +	/* for now, as a reasonable approximation, consider any host
> +	 * machine check during arm64 guest execution a fatal uncontainable
> +	 * event for the arm64 guest.
> +	 */
> +	return ESR_ELx_AET_UEU | ESR_ELx_FSC_SERROR;
> +}

[Severity: Low]
Should this return ESR_ELx_AET_UC instead of ESR_ELx_AET_UEU?

The comment describes an uncontainable event, and forwarded machine checks
can leave guest state corrupted without verifying containment, but
ESR_ELx_AET_UEU encodes a contained Unrecoverable error while
ESR_ELx_AET_UC encodes Uncontainable.

Linux arm64 guests currently panic on both, but a RAS-compliant guest OS
or firmware that distinguishes the two could assume the error was
contained.

> +
> +static void reinject_mcck(struct kvm_vcpu *vcpu)
> +{
> +	struct mcck_volatile_info *mcck;
> +	union mci mci;
> +	u64 esr;
> +
> +	mcck = &vcpu->arch.mcck_info;
> +	mci.val = mcck->mcic;
> +
> +	if (!mcck->mcic)
> +		return;
> +
> +	esr = mci_to_esr(mci);
> +
> +	memset(mcck, 0, sizeof(*mcck));
> +
> +	kvm_inject_serror_esr(vcpu, esr);
> +}

[Severity: Medium]
Can this inject a fatal SError into a healthy arm64 guest on a non-fatal
s390 machine check?

machine_check_init() enables recovery (mci.sr, mci.sc, mci.ds) and
warning (mci.w) subclasses in CR14, and s390_do_machine_check() backs up
every subclass outside MCCK_CODE_NO_GUEST via sae_backup_mci().

When an ECC-corrected storage error or power/thermal warning fires during
sae(), reinject_mcck() sees a non-zero mcic and injects a fatal SError
via mci_to_esr().  An arm64 Linux guest treats that SError as fatal in
arm64_is_fatal_ras_serror() and panics via arm64_serror_panic().

Should reinject_mcck() filter out host warnings and already-corrected or
hardware-recovered conditions before injecting an SError?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=9

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

* Re: [PATCH 08/10] KVM: s390: arm64: Enable SError injection
  2026-12-04 12:09 ` [PATCH 08/10] KVM: s390: arm64: Enable SError injection Andreas Grapentin
@ 2026-12-04 12:34   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:34 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: s390: arm64: missing Return doc in kvm_inject_serror_esr()
--

commit 6ed9dfe85ab1085bc1d412968b2749877826595b
Author: Steffen Eiden <seiden@linux.ibm.com>

KVM: s390: arm64: Enable SError injection

This commit adds kvm_inject_serror_esr() to inject a virtual SError into
an arm64 guest on s390 and re-syncs HCR_EL2.VSE on SAE exit.

> diff --git a/arch/s390/kvm/arm64/inject_fault.c b/arch/s390/kvm/arm64/inject_fault.c
> index 33f40c5188c98..82c924c45a816 100644
> --- a/arch/s390/kvm/arm64/inject_fault.c
> +++ b/arch/s390/kvm/arm64/inject_fault.c

[ ... ]

> @@ -80,3 +81,17 @@ void kvm_inject_sync(struct kvm_vcpu *vcpu, u64 esr)
>  	pend_sync_exception(vcpu);
>  	vcpu_write_sys_reg(vcpu, esr, ESR_EL1);
>  }
> +
> +/**
> + * kvm_inject_serror_esr() - inject a virtual SError into the guest
> + * @vcpu: The vCPU in which to inject the SError
> + * @esr: The ESR ISS value describing the SError
> + */
> +int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)
> +{
> +	lockdep_assert_held(&vcpu->mutex);
> +
> +	vcpu_write_host_sys_reg(vcpu, esr & ESR_ELx_ISS_MASK, SYS_VSESR_EL2);
> +	vcpu->arch.hcr_el2 |= HCR_EL2_VSE;
> +	return 1;
> +}

[Severity: Low]
Should this kernel-doc comment include a Return: section?  Since
kvm_inject_serror_esr() returns int (always 1), omitting it triggers a
kernel-doc warning under make W=2 (kernel-doc -Wall) and leaves the
return value convention undocumented.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=8

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

* Re: [PATCH 05/10] KVM: s390: arm64: Enable host irq
  2026-12-04 12:09 ` [PATCH 05/10] KVM: s390: arm64: Enable host irq Andreas Grapentin
@ 2026-12-04 12:35   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:35 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: s390: arm64: unmarked read of vcpu->mode in
  kvm_arch_vcpu_ioctl_run()
--

commit cd099a1f6eb2106dc6e363b5d88e5f2fb9f40c3e
Author: Sven Schnelle <svens@linux.ibm.com>

KVM: s390: arm64: Enable host irq

This commit registers a KVM callback to set vcpu->mode to OUTSIDE_GUEST_MODE
when a host interrupt exits a guest, and updates kvm_arch_vcpu_ioctl_run() to
call it if the vCPU is not already in OUTSIDE_GUEST_MODE.

> diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c
> index 547f77be7e3cb..cc8453bd820c6 100644
> --- a/arch/s390/kvm/arm64/arm.c
> +++ b/arch/s390/kvm/arm64/arm.c

[ ... ]

> @@ -517,7 +525,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
>  		vcpu->arch.ctxt.elr_el1 = _vcpu_read_sys_reg(vcpu, SYS_ELR_EL1);
>  		vcpu->arch.ctxt.spsr_el1 = _vcpu_read_sys_reg(vcpu, SYS_SPSR_EL1);
>  
> -		vcpu->mode = OUTSIDE_GUEST_MODE;
> +		if (vcpu->mode != OUTSIDE_GUEST_MODE)
> +			kvm_sae_exit_handler((unsigned long)vcpu);
>  		vcpu->stat.exits++;
>  
>  		local_irq_enable();

[Severity: Low]
Can this unmarked read of vcpu->mode trigger a KCSAN data-race report?

After a synchronous guest exit without a host interrupt, vcpu->mode is still
IN_GUEST_MODE.  Concurrently, another CPU can run kvm_flush_remote_tlbs() ->
kvm_make_all_cpus_request() -> kvm_vcpu_exiting_guest_mode(), updating
vcpu->mode from IN_GUEST_MODE to EXITING_GUEST_MODE via cmpxchg().

On s390 kernels built with CONFIG_KCSAN, racing this plain load against that
cmpxchg() produces a data-race splat.  Using READ_ONCE(vcpu->mode) or calling
kvm_sae_exit_handler() unconditionally avoids the race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=5

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

* Re: [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests
  2026-12-04 12:09 ` [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests Andreas Grapentin
@ 2026-12-04 12:40   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:40 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] s390/nmi: kvm_sae_backup_mci lacks const, NMI docs, and naming
  consistency
--

commit ea1da7bd08ff16877c0f02eb0a0733ca402a0fd8
Author: Steffen Eiden <seiden@linux.ibm.com>

s390/nmi: Handle MCCKs for SAE guests

This commit detects machine checks during SAE guest execution, redirects
the return address to sae_exit, and forwards guest-relevant machine check
information to KVM ARM64 through a new kvm_sae_backup_mci callback.

> diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
> index 5ff85bb01d946..5cc0bfe221eda 100644
> --- a/arch/s390/kernel/nmi.c
> +++ b/arch/s390/kernel/nmi.c
[ ... ]
> @@ -327,6 +334,31 @@ static bool notrace nmi_registers_valid(union mci mci)
>  }
>  NOKPROBE_SYMBOL(nmi_registers_valid);
>  
> +void (*kvm_sae_backup_mci)(void *vcpu, struct mcck_volatile_info *mcck_info);
> +EXPORT_SYMBOL_FOR_MODULES(kvm_sae_backup_mci, "kvm_arm64");
> +
> +/*
> + * Backup the arm guest's machine check info to its vCPU
> + * For arm guests the vcpu pointer is stored to the sf during SAE
> + * The handling is forwarded via a callback.
> + */
> +static void notrace sae_backup_mci(void *vcpu)
> +{
> +	struct mcck_volatile_info mcck_backup = { 0 };
> +
> +	if (!vcpu || !kvm_sae_backup_mci) {
> +		/* Something's seriously wrong, stop system. */
> +		s390_handle_damage();
> +	}
> +
> +	mcck_backup.mcic = get_lowcore()->mcck_interruption_code & ~MCCK_CODE_NO_GUEST;
> +	mcck_backup.ext_damage_code = get_lowcore()->external_damage_code;
> +	mcck_backup.failing_storage_address = get_lowcore()->failing_storage_address;
> +
> +	kvm_sae_backup_mci(vcpu, &mcck_backup);
> +}
> +NOKPROBE_SYMBOL(sae_backup_mci);

[Severity: Low]
Should the NMI-context and lifetime contract for kvm_sae_backup_mci be
documented in arch/s390/include/asm/nmi.h or arch/s390/kernel/nmi.c?

sae_backup_mci() calls it from NMI context (notrace, NOKPROBE_SYMBOL)
with a stack-local mcck_backup, so the handler must be NMI-safe (no
sleeping or normal locks), copy *mcck_info before returning, and stay
registered while any SAE vCPU can run.

Since mcck_backup is a read-only input, mcck_info could also be const
struct mcck_volatile_info *.

Finally, the name and vcpu parameter type (kvm_sae_backup_mci(void *vcpu,
...)) differ from the sibling kvm_arm64 callback in
arch/s390/include/asm/irq.h added by commit "s390/irq: Add kvm_exit
callback for arm-on-s390" (kvm_s390_arm64_vcpu_exit(unsigned long vcpu)).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=7

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

* Re: [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390
  2026-12-04 12:09 ` [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390 Andreas Grapentin
@ 2026-12-04 12:40   ` sashiko-bot
  0 siblings, 0 replies; 19+ messages in thread
From: sashiko-bot @ 2026-12-04 12:40 UTC (permalink / raw)
  To: Andreas Grapentin
  Cc: kvm, linux-s390, linux-perf-users, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Christian Borntraeger

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] s390/irq: unchecked NULL callback call in do_io_irq() and
  do_ext_irq()
--

commit e528519193b93752293d4af6e726617d00f21faf
Author: Sven Schnelle <svens@linux.ibm.com>

s390/irq: Add kvm_exit callback for arm-on-s390

This commit tracks SAE guest execution in thread_info.guest, redirects
host external and I/O interrupts during SAE to sae_exit, and invokes a
new kvm_s390_arm64_vcpu_exit callback from do_io_irq() and do_ext_irq().

> diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
> index 8f21bea349a65..4cc30ae637943 100644
> --- a/arch/s390/kernel/irq.c
> +++ b/arch/s390/kernel/irq.c
> @@ -142,6 +142,9 @@ static int irq_pending(struct pt_regs *regs)
>  	return CC_TRANSFORM(cc);
>  }
>  
> +void (*kvm_s390_arm64_vcpu_exit)(unsigned long vcpu);
> +EXPORT_SYMBOL_FOR_MODULES(kvm_s390_arm64_vcpu_exit, "kvm_arm64");
> +
>  void noinstr do_io_irq(struct pt_regs *regs)
>  {
>  	struct pt_regs *old_regs;
> @@ -163,6 +166,9 @@ void noinstr do_io_irq(struct pt_regs *regs)
>  			current->thread.last_break = regs->last_break;
>  	}
>  
> +	if (test_pt_regs_flag(regs, PIF_GUEST_SAE))
> +		kvm_s390_arm64_vcpu_exit(regs->sae_vcpu);
> +
>  	if (from_idle)
>  		account_idle_time_irq();
>  
> @@ -204,6 +210,9 @@ void noinstr do_ext_irq(struct pt_regs *regs)
>  			current->thread.last_break = regs->last_break;
>  	}
>  
> +	if (test_pt_regs_flag(regs, PIF_GUEST_SAE))
> +		kvm_s390_arm64_vcpu_exit(regs->sae_vcpu);
> +
>  	regs->int_code = get_lowcore()->ext_int_code_addr;
>  	regs->int_parm = get_lowcore()->ext_params;
>  	regs->int_parm_long = get_lowcore()->ext_params2;

[Severity: Medium]
Can do_io_irq() and do_ext_irq() call kvm_s390_arm64_vcpu_exit while it
is still NULL at this commit?

arm_vcpu_enter_exit() already invokes sae(), and this patch sets
TI_GUEST_SAE and _PIF_GUEST_SAE before anything assigns
kvm_s390_arm64_vcpu_exit.  A host timer or I/O interrupt during SAE
execution will dereference NULL in hardirq context and break git bisect.

Commit "KVM: s390: arm64: Enable host irq" registers the callback later
in the series, so checking kvm_s390_arm64_vcpu_exit for NULL here would
keep this commit bisectable.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com?part=4

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

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

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 12:09 [PATCH 00/10] s390: Host interrupt handling for SAE guests Andreas Grapentin
2026-12-04 12:09 ` [PATCH 01/10] s390/sae: Prepare handling host interrupts during SAE execution Andreas Grapentin
2026-12-04 12:31   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 02/10] s390/sae: Add sae_entry and sae_exit symbols Andreas Grapentin
2026-12-04 12:30   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 03/10] KVM: s390: Share mcck_volatile_info between KVMs Andreas Grapentin
2026-12-04 12:09 ` [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390 Andreas Grapentin
2026-12-04 12:40   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 05/10] KVM: s390: arm64: Enable host irq Andreas Grapentin
2026-12-04 12:35   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 06/10] s390: Rename CIF_MCCK_GUEST to CIF_MCCK_SIE Andreas Grapentin
2026-12-04 12:09 ` [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests Andreas Grapentin
2026-12-04 12:40   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 08/10] KVM: s390: arm64: Enable SError injection Andreas Grapentin
2026-12-04 12:34   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 09/10] KVM: s390: arm64: Enable mcck forwarding Andreas Grapentin
2026-12-04 12:33   ` sashiko-bot
2026-12-04 12:09 ` [PATCH 10/10] s390/perf: Recognize SAE guests Andreas Grapentin
2026-12-04 12:30   ` sashiko-bot

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