arm: traps: move declaration for irq_stack_ptr to irq.h
A message that is not in the archive (sent off-list or not yet received): CGME20260427055219epcas5p433ac552f429a60e19865b7583040e456@epcas5p4.samsung.com
PATCH 1/2 arm: traps: move declaration for irq_stack_ptr to irq.h
Moving declaration for irq_stack_ptr to irq.h, because next patch will use it for IRQ STACK checking.
Also irq_stack_ptr is defined as READ_MOSTLY, so declaration should also be the same.
--- arch/arm/include/asm/irq.h | 4 ++++ arch/arm/kernel/traps.c | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/include/asm/irq.h +4 -0
@@ -41,6 +41,10 @@ static inline int nr_legacy_irqs(void)return NR_IRQS_LEGACY ; } +#ifdef CONFIG_IRQSTACKS +DECLARE_PER_CPU_READ_MOSTLY(u8 *, irq_stack_ptr); +#endif +#endif #endif
arch/arm/kernel/traps.c +0 -2
@@ -899,8 +899,6 @@ void __init early_trap_init(void *vectors_base)#ifdef CONFIG_VMAP_STACK -DECLARE_PER_CPU(u8 *, irq_stack_ptr); -asmlinkage DEFINE_PER_CPU (u8 *,overflow_stack_ptr );static int __init allocate_overflow_stacks (void )
Signature · 1 line
2.34.1
PATCH v2 2/2 arm: traps: add irq_stack checking for underflow detection
with IRQSTACKS fp can point outside of thread's stack. And when there is crash reported from IRQ side, it always report "frame pointer underflow", which is not real underflow.
Call trace: frame pointer underflow handle_irq_desc from generic_handle_domain_irq+0x18/0x1c generic_handle_domain_irq from gic_handle_irq+0x78/0x8c gic_handle_irq from generic_handle_arch_irq+0x3c/0x4c
..
..
Adding fp checking for IRQSTACK also to avoid this false reporting. Although it is valid only in case of current as of now, but added generic code to make it look simpler and for future usable.
---
https://lkml.org/lkml/2026/4/24/230
v1 -> v2: rather than removing fp underflow checking, added IRQSTACK checking
arch/arm/include/asm/irq.h | 13 +++++++++++++ arch/arm/kernel/traps.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
arch/arm/include/asm/irq.h +13 -0
@@ -43,6 +43,19 @@ static inline int nr_legacy_irqs(void)#ifdef CONFIG_IRQSTACKS DECLARE_PER_CPU_READ_MOSTLY(u8 *, irq_stack_ptr); + +static inline bool on_irq_stack (int cpu,unsigned long sp) +{ +unsigned long high = (unsigned long )per_cpu (irq_stack_ptr, cpu); +unsigned long low = high -THREAD_SIZE ; + +return (low <= sp && sp <= high); +} +#else +static inline bool on_irq_stack (int cpu,unsigned long sp) +{ +return false; +}#endif #endif
arch/arm/kernel/traps.c +14 -1
@@ -130,6 +130,19 @@ static int verify_stack(unsigned long sp) return 0; } + +static bool check_underflow (unsigned long fp,struct task_struct *tsk) +{ +int cpu =task_cpu (tsk); + +if (on_irq_stack (cpu, fp)) +return false; + +if (fp < (unsigned long )end_of_stack (tsk)) +return true; + +return false; +}#endif /*
@@ -243,7 +256,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, }else if (verify_stack (fp)) {pr_cont ("invalid frame pointer 0x%08x" , fp); ok =0 ; - }else if (fp < (unsigned long )end_of_stack (tsk)) + }else if (check_underflow (fp, tsk))pr_cont ("frame pointer underflow" );pr_cont ("\n" );
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] arm: traps: add irq_stack checking for underflow detection
ping!
Any comments for these patches?
Quoted 83 lines
with IRQSTACKS fp can point outside of thread's stack. And when there is crash reported from IRQ side, it always report "frame pointer underflow", which is not real underflow.
Call trace: frame pointer underflow handle_irq_desc from generic_handle_domain_irq+0x18/0x1c generic_handle_domain_irq from gic_handle_irq+0x78/0x8c gic_handle_irq from generic_handle_arch_irq+0x3c/0x4c..
..Adding fp checking for IRQSTACK also to avoid this false reporting. Although it is valid only in case of current as of now, but added generic code to make it look simpler and for future usable.
Signed-off-by Maninder Singh <[email protected]>---
https://lkml.org/lkml/2026/4/24/230
v1 -> v2: rather than removing fp underflow checking, added IRQSTACK checkingarch/arm/include/asm/irq.h | 13 +++++++++++++ arch/arm/kernel/traps.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)arch/arm/include/asm/irq.h +13
-0@@ -43,6 +43,19 @@ static inline int nr_legacy_irqs(void)#ifdef CONFIG_IRQSTACKS DECLARE_PER_CPU_READ_MOSTLY(u8 *, irq_stack_ptr); + +static inline bool on_irq_stack (int cpu,unsigned long sp) +{ + unsigned long high = (unsigned long)per_cpu(irq_stack_ptr, cpu); + unsigned long low = high - THREAD_SIZE; + + return (low <= sp && sp <= high); +} +#else +static inline bool on_irq_stack (int cpu,unsigned long sp) +{ + return false; +}#endif #endif arch/arm/kernel/traps.c +14
-1@@ -130,6 +130,19 @@ static int verify_stack(unsigned long sp) return 0; } + +static bool check_underflow (unsigned long fp,struct task_struct *tsk) +{ + int cpu = task_cpu(tsk); + + if (on_irq_stack(cpu, fp)) + return false; + + if (fp < (unsigned long)end_of_stack(tsk)) + return true; + + return false; +}#endif /* @@ -243,7 +256,7 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, } else if (verify_stack(fp)) { pr_cont("invalid frame pointer 0x%08x", fp); ok = 0; - } else if (fp < (unsigned long)end_of_stack(tsk)) + } else if (check_underflow(fp, tsk)) pr_cont("frame pointer underflow"); pr_cont("\n");Signature · 1 line
2.34.1
Hi Maninder,
thanks for your patch!
Quoted 2 lines · Maninder Singh
Moving declaration for
irq_stack_ptrtoirq.h, because next patch will use it for IRQ STACK checking.
OK
Quoted 2 lines
Also
irq_stack_ptris defined asREAD_MOSTLY, so declaration should also be the same.
But is that even right in the first place?
AFAIU a stack pointer is usually read exactly as much as it is written.
Yours,
Linus Walleij
Hi Linus Walleij,
Quoted 11 lines
Hi Maninder,
thanks for your patch!
Quoted 2 lines · Maninder Singh
Moving declaration for
irq_stack_ptrtoirq.h, because next patch will use it for IRQ STACK checking.OK
Quoted 8 lines
Quoted 2 lines
Also
irq_stack_ptris defined asREAD_MOSTLY, so declaration should also be the same.But is that even right in the first place?
AFAIU a stack pointer is usually read exactly as much as it is written.
I checked for ARM64 as well, and it was "not" defined as READ_MOSTLY. But instead of changing it, I kept it same.
Because I thought it is written during system boot only, and after that it is read only. That might be the reason ARM has kept it as READ_MOSTLY?
arch/arm/kernel/irq.c
static void __init init_irq_stacks(void)
{
..per_cpu(irq_stack_ptr, cpu) = &stack[THREAD_SIZE];
...
}
There is no other write to this after that I think.
stack can be read and write , but this pointer is read mostly after initial setup.
Thanks and Regards,
Maninder Singh