All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bradley Morgan <include@grrlz.net>
To: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, ada.coupriediaz@arm.com,
	anshuman.khandual@arm.com, kees@kernel.org,
	Bradley Morgan <include@grrlz.net>
Subject: [PATCH] arm64: entry: dedup SDEI event priority selection
Date: Sat, 18 Jul 2026 18:54:47 +0000	[thread overview]
Message-ID: <20260718185447.25706-1-include@grrlz.net> (raw)

__sdei_asm_handler open codes the same branch ladder four times to pick
the normal or critical variant of a per CPU variable based on the SDEI
event priority: when recording the active event, when selecting the
SDEI stack, when selecting the shadow call stack, and when clearing the
active-event record on exit.

Add a sdei_choose macro, using \@ local labels like the files existing
macros, and replace the four open coded copies with it. This also drops
the repeated reuse of the 1:/2:/3:/4: numeric labels in this handler.

No functional change intended.

Signed-off-by: Bradley Morgan <include@grrlz.net>
---
 arch/arm64/kernel/entry.S | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index e0db14e9c843..29ef4a0d28a8 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -916,6 +916,15 @@ NOKPROBE(call_on_irq_stack)
 	b	.
 .endm
 
+/* Set \dst using \op and the \normal or \critical sym, based on \prio */
+.macro sdei_choose op:req, dst:req, prio:req, normal:req, critical:req, tmp:req
+	cbnz	\prio, .Lcritical\@
+	\op dst=\dst, sym=\normal, tmp=\tmp
+	b	.Ldone\@
+.Lcritical\@:	\op dst=\dst, sym=\critical, tmp=\tmp
+.Ldone\@:
+.endm
+
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
 /*
  * The regular SDEI entry point may have been unmapped along with the rest of
@@ -997,32 +1006,24 @@ SYM_CODE_START(__sdei_asm_handler)
 
 	/* Store the registered-event for crash_smp_send_stop() */
 	ldrb	w4, [x19, #SDEI_EVENT_PRIORITY]
-	cbnz	w4, 1f
-	adr_this_cpu dst=x5, sym=sdei_active_normal_event, tmp=x6
-	b	2f
-1:	adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6
-2:	str	x19, [x5]
+	sdei_choose adr_this_cpu, x5, w4, sdei_active_normal_event, \
+		    sdei_active_critical_event, x6
+	str	x19, [x5]
 
 	/*
 	 * entry.S may have been using sp as a scratch register, find whether
 	 * this is a normal or critical event and switch to the appropriate
 	 * stack for this CPU.
 	 */
-	cbnz	w4, 1f
-	ldr_this_cpu dst=x5, sym=sdei_stack_normal_ptr, tmp=x6
-	b	2f
-1:	ldr_this_cpu dst=x5, sym=sdei_stack_critical_ptr, tmp=x6
-2:	mov	x6, #SDEI_STACK_SIZE
+	sdei_choose ldr_this_cpu, x5, w4, sdei_stack_normal_ptr, sdei_stack_critical_ptr, x6
+	mov	x6, #SDEI_STACK_SIZE
 	add	x5, x5, x6
 	mov	sp, x5
 
 #ifdef CONFIG_SHADOW_CALL_STACK
 	/* Use a separate shadow call stack for normal and critical events */
-	cbnz	w4, 3f
-	ldr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_normal_ptr, tmp=x6
-	b	4f
-3:	ldr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_critical_ptr, tmp=x6
-4:
+	sdei_choose ldr_this_cpu, scs_sp, w4, sdei_shadow_call_stack_normal_ptr, \
+		    sdei_shadow_call_stack_critical_ptr, x6
 #endif
 
 	/*
@@ -1068,11 +1069,9 @@ SYM_CODE_START(__sdei_asm_handler)
 
 	/* Clear the registered-event seen by crash_smp_send_stop() */
 	ldrb	w3, [x4, #SDEI_EVENT_PRIORITY]
-	cbnz	w3, 1f
-	adr_this_cpu dst=x5, sym=sdei_active_normal_event, tmp=x6
-	b	2f
-1:	adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6
-2:	str	xzr, [x5]
+	sdei_choose adr_this_cpu, x5, w3, sdei_active_normal_event, \
+		    sdei_active_critical_event, x6
+	str	xzr, [x5]
 
 alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0
 	sdei_handler_exit exit_mode=x2
-- 
2.53.0


WARNING: multiple messages have this Message-ID (diff)
From: Bradley Morgan <include@grrlz.net>
To: catalin.marinas@arm.com, will@kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: kees@kernel.org, Bradley Morgan <include@grrlz.net>,
	linux-kernel@vger.kernel.org, anshuman.khandual@arm.com
Subject: [PATCH] arm64: entry: dedup SDEI event priority selection
Date: Sat, 18 Jul 2026 18:54:47 +0000	[thread overview]
Message-ID: <20260718185447.25706-1-include@grrlz.net> (raw)

__sdei_asm_handler open codes the same branch ladder four times to pick
the normal or critical variant of a per CPU variable based on the SDEI
event priority: when recording the active event, when selecting the
SDEI stack, when selecting the shadow call stack, and when clearing the
active-event record on exit.

Add a sdei_choose macro, using \@ local labels like the files existing
macros, and replace the four open coded copies with it. This also drops
the repeated reuse of the 1:/2:/3:/4: numeric labels in this handler.

No functional change intended.

Signed-off-by: Bradley Morgan <include@grrlz.net>
---
 arch/arm64/kernel/entry.S | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index e0db14e9c843..29ef4a0d28a8 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -916,6 +916,15 @@ NOKPROBE(call_on_irq_stack)
 	b	.
 .endm
 
+/* Set \dst using \op and the \normal or \critical sym, based on \prio */
+.macro sdei_choose op:req, dst:req, prio:req, normal:req, critical:req, tmp:req
+	cbnz	\prio, .Lcritical\@
+	\op dst=\dst, sym=\normal, tmp=\tmp
+	b	.Ldone\@
+.Lcritical\@:	\op dst=\dst, sym=\critical, tmp=\tmp
+.Ldone\@:
+.endm
+
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
 /*
  * The regular SDEI entry point may have been unmapped along with the rest of
@@ -997,32 +1006,24 @@ SYM_CODE_START(__sdei_asm_handler)
 
 	/* Store the registered-event for crash_smp_send_stop() */
 	ldrb	w4, [x19, #SDEI_EVENT_PRIORITY]
-	cbnz	w4, 1f
-	adr_this_cpu dst=x5, sym=sdei_active_normal_event, tmp=x6
-	b	2f
-1:	adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6
-2:	str	x19, [x5]
+	sdei_choose adr_this_cpu, x5, w4, sdei_active_normal_event, \
+		    sdei_active_critical_event, x6
+	str	x19, [x5]
 
 	/*
 	 * entry.S may have been using sp as a scratch register, find whether
 	 * this is a normal or critical event and switch to the appropriate
 	 * stack for this CPU.
 	 */
-	cbnz	w4, 1f
-	ldr_this_cpu dst=x5, sym=sdei_stack_normal_ptr, tmp=x6
-	b	2f
-1:	ldr_this_cpu dst=x5, sym=sdei_stack_critical_ptr, tmp=x6
-2:	mov	x6, #SDEI_STACK_SIZE
+	sdei_choose ldr_this_cpu, x5, w4, sdei_stack_normal_ptr, sdei_stack_critical_ptr, x6
+	mov	x6, #SDEI_STACK_SIZE
 	add	x5, x5, x6
 	mov	sp, x5
 
 #ifdef CONFIG_SHADOW_CALL_STACK
 	/* Use a separate shadow call stack for normal and critical events */
-	cbnz	w4, 3f
-	ldr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_normal_ptr, tmp=x6
-	b	4f
-3:	ldr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_critical_ptr, tmp=x6
-4:
+	sdei_choose ldr_this_cpu, scs_sp, w4, sdei_shadow_call_stack_normal_ptr, \
+		    sdei_shadow_call_stack_critical_ptr, x6
 #endif
 
 	/*
@@ -1068,11 +1069,9 @@ SYM_CODE_START(__sdei_asm_handler)
 
 	/* Clear the registered-event seen by crash_smp_send_stop() */
 	ldrb	w3, [x4, #SDEI_EVENT_PRIORITY]
-	cbnz	w3, 1f
-	adr_this_cpu dst=x5, sym=sdei_active_normal_event, tmp=x6
-	b	2f
-1:	adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6
-2:	str	xzr, [x5]
+	sdei_choose adr_this_cpu, x5, w3, sdei_active_normal_event, \
+		    sdei_active_critical_event, x6
+	str	xzr, [x5]
 
 alternative_if_not ARM64_UNMAP_KERNEL_AT_EL0
 	sdei_handler_exit exit_mode=x2
-- 
2.53.0



             reply	other threads:[~2026-07-18 18:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18 18:54 Bradley Morgan [this message]
2026-07-18 18:54 ` [PATCH] arm64: entry: dedup SDEI event priority selection Bradley Morgan

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=20260718185447.25706-1-include@grrlz.net \
    --to=include@grrlz.net \
    --cc=ada.coupriediaz@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=kees@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.