ARM: entry: Convert IRQ handling to generic IRQ entry
Subsystems (2)
PATCH v3 1/1 ARM: entry: Convert IRQ handling to generic IRQ entry
Bring ARM to the same level of generic-ness as ARM64 by enabling GENERIC_IRQ_ENTRY.
Route ARM IRQ entry through C wrappers that use the generic IRQ entry helpers. Conversely put the FIQ entry under the generic NMI-style entry helpers.
Select GENERIC_IRQ_ENTRY, add the ARM entry prototypes, and provide regs_irqs_disabled() for the generic IRQ entry return path.
The kernel-mode IRQ return path relies on the generic IRQ entry preemption handling, matching the arm64 structure and avoiding the old assembly reschedule check.
The reschedule check is now done in raw_irqentry_exit_cond_resched() in kernel/entry/common.c.
User-mode IRQs __irq_usr is neither calling ct_user_exit/enter or asm_trace_hardirqs_off/on anymore. The corresponding calls happen on irqentry_enter/exit() call paths, e.g the irq-disabled C variants __ct_user_exit/enter() are called instead.
As __irq_usr no longer returns by jumping to ret_to_user_from_irq, the corresponding code has been inlined, except the slow_work_pending part, which is now also handled by generic entry. ret_to_user_from_irq is only called from v7m so it has been renamed accordingly.
arch_do_signal_or_restart() is required, but we only need a very small stub, since we keep the existing syscall restart code around in assembly.
Selecting GENERIC_IRQ_ENTRY also enables optimized handling for extended rseq registrations. Record non-syscall user entry for data aborts, prefetch aborts and undefined instructions with rseq_note_user_irq_entry() so signal delivery aborts an interrupted rseq critical section. Clear the rseq events on the legacy return path after pending work completes, before returning to userspace, so user_irq cannot leak into a later syscall. Keep the existing assembly context-tracking calls on these paths.
Tested with a multi_v7_defconfig-based configuration on QEMU vexpress-a15 using vexpress-v2p-ca15-tc1.dtb. Extended-rseq signal-frame tests pass for data aborts, prefetch aborts and undefined instructions (100 cases each). Legacy rseq and ARM/Thumb userspace entry tests also pass, as does a Debian boot and clean poweroff.
A note on V7M: the reason we cannot switch the V7M entry over to generic entry is that it raises a "pendable service call" ("pendv") exception to process deferred work at the end of the interrupt handler. This is done so higher priority work can come in. This has no corresponding structure in other ARM cores.
This is a reduced patch based on the earlier generic entry series avoiding all the syscall handling changes.
---
Changes in v3:
- Rebased on v7.3-rc1.
- Fix rseq abort handling for synchronous userspace exceptions.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Rebase on v7.2-rc1
- Select GENERIC_IRQ_ENTRY also for V7M even if this platform is not
using it, in order to properly link the image.
- Link to v1: https://patch.msgid.link/[email protected]
--- arch/arm/Kconfig | 1 + arch/arm/include/asm/entry-common.h | 7 ++++ arch/arm/include/asm/entry.h | 12 ++++++ arch/arm/include/asm/ptrace.h | 7 +++- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/entry-armv.S | 78 +++++++++---------------------------- arch/arm/kernel/entry-common.S | 8 +++- arch/arm/kernel/entry-header.S | 7 +++- arch/arm/kernel/entry-v7m.S | 2 +- arch/arm/kernel/entry.c | 61 +++++++++++++++++++++++++++++ arch/arm/kernel/irq.c | 6 +++ arch/arm/kernel/irq.h | 2 + arch/arm/kernel/signal.c | 6 +++ 13 files changed, 134 insertions(+), 65 deletions(-)
arch/arm/Kconfig +1 -0
@@ -72,6 +72,7 @@ config ARM select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_DEVICES select GENERIC_EARLY_IOREMAP + select GENERIC_IRQ_ENTRY select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_MULTI_HANDLER select GENERIC_IRQ_PROBE
arch/arm/include/asm/entry-common.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_ARM_ENTRY_COMMON_H +#define __ASM_ARM_ENTRY_COMMON_H + +#include <asm/stacktrace.h> + +#endif
arch/arm/include/asm/entry.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_ENTRY_H__ +#define __ASM_ENTRY_H__ + +struct pt_regs ; + +void arm_rseq_user_enter (void ); +void arm_rseq_user_exit (void ); +void arm_irq_handler (struct pt_regs *regs,int mode); +void arm_fiq_handler (struct pt_regs *regs); + +#endif /* __ASM_ENTRY_H__ */
arch/arm/include/asm/ptrace.h +6 -1
@@ -46,8 +46,13 @@ struct svc_pt_regs {#define processor_mode (regs) \ ((regs)->ARM_cpsr & MODE_MASK) +static inline bool regs_irqs_disabled (const struct pt_regs *regs) +{ +return regs->ARM_cpsr &PSR_I_BIT ; +} +#define interrupts_enabled (regs) \ - (!((regs)->ARM_cpsr & PSR_I_BIT)) + (!regs_irqs_disabled(regs))#define fast_interrupts_enabled (regs) \ (!((regs)->ARM_cpsr & PSR_F_BIT))
arch/arm/kernel/Makefile +1 -1
@@ -17,7 +17,7 @@ CFLAGS_REMOVE_return_address.o = -pg # Object file lists. -obj-y := elf.o entry-common.o irq.o opcodes.o \ +obj-y := elf.o entry.o entry-common.o irq.o opcodes.o \ process.o ptrace.o reboot.o io.o \ setup.o signal.o sigreturn_codes.o \ stacktrace.o sys_arm.o time.o traps.o
arch/arm/kernel/entry-armv.S +19 -59
127 lines not on this page · raw message
arch/arm/kernel/entry-common.S +6 -2
@@ -110,11 +110,15 @@ ret_slow_syscall: bl do_rseq_syscall #endif disable_irq_notrace @ disable interrupts -ENTRY(ret_to_user_from_irq) +ENTRY(v7m_ret_to_user_from_irq) + /* Only the v7m jumps directly to v7m_ret_to_user_from_irq */ ldr r1, [tsk, #TI_FLAGS] movs r1, r1, lsl #16 bne slow_work_pending no_work_pending: +#ifdef CONFIG_RSEQ + bl arm_rseq_user_exit +#endif asm_trace_hardirqs_on save = 0 ct_user_enter save = 0
@@ -123,7 +127,7 @@ no_work_pending: bl stackleak_erase_on_task_stack #endif restore_user_regs fast = 0, offset = 0 -ENDPROC(ret_to_user_from_irq) +ENDPROC(v7m_ret_to_user_from_irq) ENDPROC(ret_to_user) /*
arch/arm/kernel/entry-header.S +6 -1
@@ -199,7 +199,11 @@ .endm - .macro svc_exit, rpsr, irq = 0 + .macro svc_exit, rpsr, irq = 0, irqentry = 0 + .if \irqentry != 0 + @ Generic IRQ entry already handled tracing and lockdep state. + disable_irq_notrace + .else .if \irq != 0 @ IRQs already off #ifdef CONFIG_TRACE_IRQFLAGS
@@ -216,6 +220,7 @@ tst \rpsr, #PSR_I_BIT blne trace_hardirqs_off #endif + .endif .endif uaccess_exit tsk, r0, r1
arch/arm/kernel/entry-v7m.S +1 -1
@@ -94,7 +94,7 @@ __pendsv_entry: @ execute the pending work, including reschedule get_thread_info tsk mov why, #0 - b ret_to_user_from_irq + b v7m_ret_to_user_from_irq ENDPROC(__pendsv_entry) /*
arch/arm/kernel/entry.c new file +61 -0
61 lines not on this page · raw message
arch/arm/kernel/irq.c +6 -0
@@ -43,6 +43,7 @@#include <asm/mach/irq.h> #include <asm/mach/time.h> +#include "irq.h" #include "reboot.h" unsigned long irq_err_count;
@@ -71,6 +72,11 @@ static void __init init_irq_stacks(void) } } +void call_on_irq_stack (void (*fn)(void *),void *arg) +{ +call_with_stack (fn, arg,__this_cpu_read (irq_stack_ptr)); +} +#ifdef CONFIG_SOFTIRQ_ON_OWN_STACK static void ____do_softirq (void *arg) {
arch/arm/kernel/irq.h new file +2 -0
@@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +void call_on_irq_stack (void (*fn)(void *),void *arg);
arch/arm/kernel/signal.c +6 -0
@@ -12,6 +12,7 @@#include <linux/resume_user_mode.h> #include <linux/uprobes.h> #include <linux/syscalls.h> +#include <linux/irq-entry-common.h> #include <asm/elf.h> #include <asm/cacheflush.h>
@@ -599,6 +600,11 @@ static int do_signal(struct pt_regs *regs, int syscall)return 0 ; } +void arch_do_signal_or_restart (struct pt_regs *regs) +{ +do_signal (regs,0 ); +} + asmlinkage intdo_work_pending (struct pt_regs *regs,unsigned int thread_flags,int syscall) {
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260622-arm-generic-irq-entry-v7-1-ff6c1d6c9c48
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Hi Linus,
I took a look at the Cortex-M (V7M) part.
Since V7M now selects GENERIC_IRQ_ENTRY as well, a call to arm_rseq_user_enter() is required near the V7M interrupt entry path for rseq to work correctly. It corresponds to the arm_rseq_user_exit() call you added in entry-common.S:no_work_pending, which V7M reaches via v7m_ret_to_user_from_irq.
A minimal fix would be:
arch/arm/kernel/entry-v7m.S +4 -0
@@ -87,6 +87,10 @@ ENDPROC(__irq_entry) __pendsv_entry: v7m_exception_entry +#ifdef CONFIG_RSEQ + bl arm_rseq_user_enter +#endif + ldr r1, =BASEADDR_V7M_SCB mov r0, #V7M_SCB_ICSR_PENDSVCLR str r0, [r1, V7M_SCB_ICSR] @ clear PendSV
This actually calls arm_rseq_user_enter() in PendSV rather than in __irq_entry. I think this is fine because the rseq.event.user_irq flag set by this function is only checked on the return path to user space, specifically, during rseq handling inside do_work_pending() on V7M.
However, applying this fix highlights the ongoing maintenance burden and motivates converting the V7M IRQ entry to use the generic IRQ entry. I'd like to take on this conversion work.
I already have a rough idea of how to implement it (it is somewhat complicated). I hope to implement the prototype within a week or two. I will send it out as a separate RFC on top of your patch series.
As a quick test for your patch series, I confirmed that Buildroot boots successfully with and without the rseq change above on QEMU MPS3-AN547 (Cortex-M55 / Arm v8.1-M). I will run more comprehensive tests on real hardware, like kselftests including rseq.
Best regards,
Yoshifumi