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 04/10] s390/irq: Add kvm_exit callback for arm-on-s390
Date: Fri, 04 Dec 2026 13:09:16 +0100	[thread overview]
Message-ID: <20261204-host-irq-v1-4-a8387ee8a380@linux.ibm.com> (raw)
In-Reply-To: <20261204-host-irq-v1-0-a8387ee8a380@linux.ibm.com>

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


  parent reply	other threads:[~2026-12-04 12:10 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 ` Andreas Grapentin [this message]
2026-12-04 12:40   ` [PATCH 04/10] s390/irq: Add kvm_exit callback for arm-on-s390 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
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-4-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