diff mbox series

[v5,24/32] ARM: run softirqs on the per-CPU IRQ stack

Message ID 20220124174744.1054712-25-ardb@kernel.org (mailing list archive)
State Superseded
Headers show
Series ARM vmap'ed and IRQ stacks roundup | expand

Commit Message

Ard Biesheuvel Jan. 24, 2022, 5:47 p.m. UTC
Now that we have enabled IRQ stacks, any softIRQs that are handled over
the back of a hard IRQ will run from the IRQ stack as well. However, any
synchronous softirq processing that happens when re-enabling softIRQs
from task context will still execute on that task's stack.

Since any call to local_bh_enable() at any level in the task's call
stack may trigger a softIRQ processing run, which could potentially
cause a task stack overflow if the combined stack footprints exceed the
stack's size, let's run these synchronous invocations of do_softirq() on
the IRQ stack as well.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Keith Packard <keithpac@amazon.com>
Tested-by: Marc Zyngier <maz@kernel.org>
Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
---
 arch/arm/Kconfig      |  2 ++
 arch/arm/kernel/irq.c | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

Comments

Sebastian Andrzej Siewior March 22, 2022, 9:04 a.m. UTC | #1
On 2022-01-24 18:47:36 [+0100], Ard Biesheuvel wrote:
> @@ -58,6 +61,17 @@ static void __init init_irq_stacks(void)
>  	}
>  }
>  
> +static void ____do_softirq(void *arg)
> +{
> +	__do_softirq();
> +}
> +
> +void do_softirq_own_stack(void)
> +{
> +	call_with_stack(____do_softirq, NULL,
> +			__this_cpu_read(irq_stack_ptr));
> +}
> +

Do I miss the obvious here or is the irq_stack_ptr only used for
softirqs and not for hardirqs?

>  int arch_show_interrupts(struct seq_file *p, int prec)
>  {
>  #ifdef CONFIG_FIQ

Sebastian
Ard Biesheuvel March 22, 2022, 9:35 a.m. UTC | #2
On Tue, 22 Mar 2022 at 10:04, Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
>
> On 2022-01-24 18:47:36 [+0100], Ard Biesheuvel wrote:
> > @@ -58,6 +61,17 @@ static void __init init_irq_stacks(void)
> >       }
> >  }
> >
> > +static void ____do_softirq(void *arg)
> > +{
> > +     __do_softirq();
> > +}
> > +
> > +void do_softirq_own_stack(void)
> > +{
> > +     call_with_stack(____do_softirq, NULL,
> > +                     __this_cpu_read(irq_stack_ptr));
> > +}
> > +
>
> Do I miss the obvious here or is the irq_stack_ptr only used for
> softirqs and not for hardirqs?
>
> >  int arch_show_interrupts(struct seq_file *p, int prec)
> >  {
> >  #ifdef CONFIG_FIQ
>

It is also used for hard IRQs - please refer to the irq_handler macro
in arch/arm/kernel/entry-armv.S
Sebastian Andrzej Siewior March 22, 2022, 11:29 a.m. UTC | #3
On 2022-03-22 10:35:18 [+0100], Ard Biesheuvel wrote:
> It is also used for hard IRQs - please refer to the irq_handler macro
> in arch/arm/kernel/entry-armv.S

Thank you, this makes sense.

Sebastian
diff mbox series

Patch

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 108a7a872084..b959249dd716 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -128,6 +128,8 @@  config ARM
 	select RTC_LIB
 	select SYS_SUPPORTS_APM_EMULATION
 	select THREAD_INFO_IN_TASK
+	select HAVE_IRQ_EXIT_ON_IRQ_STACK
+	select HAVE_SOFTIRQ_ON_OWN_STACK
 	select TRACE_IRQFLAGS_SUPPORT if !CPU_V7M
 	# Above selects are sorted alphabetically; please add new ones
 	# according to that.  Thanks.
diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c
index 92ae80a8e5b4..380376f55554 100644
--- a/arch/arm/kernel/irq.c
+++ b/arch/arm/kernel/irq.c
@@ -36,11 +36,14 @@ 
 #include <asm/hardware/cache-l2x0.h>
 #include <asm/hardware/cache-uniphier.h>
 #include <asm/outercache.h>
+#include <asm/softirq_stack.h>
 #include <asm/exception.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/irq.h>
 #include <asm/mach/time.h>
 
+#include "reboot.h"
+
 unsigned long irq_err_count;
 
 asmlinkage DEFINE_PER_CPU_READ_MOSTLY(u8 *, irq_stack_ptr);
@@ -58,6 +61,17 @@  static void __init init_irq_stacks(void)
 	}
 }
 
+static void ____do_softirq(void *arg)
+{
+	__do_softirq();
+}
+
+void do_softirq_own_stack(void)
+{
+	call_with_stack(____do_softirq, NULL,
+			__this_cpu_read(irq_stack_ptr));
+}
+
 int arch_show_interrupts(struct seq_file *p, int prec)
 {
 #ifdef CONFIG_FIQ