Linux Perf Users
 help / color / mirror / Atom feed
From: Andreas Grapentin <gra@linux.ibm.com>
To: Steffen Eiden <seiden@linux.ibm.com>,
	Marc Zyngier <maz@kernel.org>, Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@kernel.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andreas Grapentin <gra@linux.ibm.com>
Subject: [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests
Date: Fri, 04 Dec 2026 13:09:19 +0100	[thread overview]
Message-ID: <20261204-host-irq-v1-7-a8387ee8a380@linux.ibm.com> (raw)
In-Reply-To: <20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com>

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


  parent reply	other threads:[~2026-12-04 12:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Andreas Grapentin [this message]
2026-12-04 12:40   ` [PATCH 07/10] s390/nmi: Handle MCCKs for SAE guests 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
2026-12-04 12:40 ` [PATCH 00/10] s390: Host interrupt handling for " sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204-host-irq-v1-7-a8387ee8a380@linux.ibm.com \
    --to=gra@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=agordeev@linux.ibm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seiden@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox