arch/arm64/kernel/entry.S | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
__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
On Sat, Jul 18, 2026 at 06:54:47PM +0000, Bradley Morgan wrote: > __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(-) Looking at the patch below, the result is far less readable, and this has only saved a single line. I don't think this is worthwhile; please leave this as-is. Mark. > > 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 > >
On July 21, 2026 3:50:12 PM GMT+01:00, Mark Rutland <mark.rutland@arm.com> wrote: >On Sat, Jul 18, 2026 at 06:54:47PM +0000, Bradley Morgan wrote: >> __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(-) > >Looking at the patch below, the result is far less readable, and this >has only saved a single line. > >I don't think this is worthwhile; please leave this as-is. > >Mark. ok, fair enough, I wasn't highly expecting for this to get accepted, the one I think that would, would be [1] [1] https://lore.kernel.org/all/20260717114746.15109-1-include@grrlz.net/ Thanks for the review. >> >> 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 >> >> > Thanks!
© 2016 - 2026 Red Hat, Inc.