Skip to content

Commit dd69d07

Browse files
guoren83palmer-dabbelt
authored andcommitted
riscv: stack: Support HAVE_SOFTIRQ_ON_OWN_STACK
Add the HAVE_SOFTIRQ_ON_OWN_STACK feature for the IRQ_STACKS config, and the irq and softirq use the same irq_stack of percpu. Tested-by: Jisheng Zhang <[email protected]> Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Guo Ren <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 163e76c commit dd69d07

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

arch/riscv/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,13 @@ config FPU
591591
If you don't know what to do here, say Y.
592592

593593
config IRQ_STACKS
594-
bool "Independent irq stacks" if EXPERT
594+
bool "Independent irq & softirq stacks" if EXPERT
595595
default y
596596
select HAVE_IRQ_EXIT_ON_IRQ_STACK
597+
select HAVE_SOFTIRQ_ON_OWN_STACK
597598
help
598-
Add independent irq stacks for percpu to prevent kernel stack overflows.
599+
Add independent irq & softirq stacks for percpu to prevent kernel stack
600+
overflows. We may save some memory footprint by disabling IRQ_STACKS.
599601

600602
endmenu # "Platform type"
601603

arch/riscv/kernel/irq.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <linux/module.h>
1212
#include <linux/seq_file.h>
1313
#include <asm/sbi.h>
14+
#include <asm/smp.h>
15+
#include <asm/softirq_stack.h>
16+
#include <asm/stacktrace.h>
1417

1518
static struct fwnode_handle *(*__get_intc_node)(void);
1619

@@ -56,6 +59,38 @@ static void init_irq_stacks(void)
5659
per_cpu(irq_stack_ptr, cpu) = per_cpu(irq_stack, cpu);
5760
}
5861
#endif /* CONFIG_VMAP_STACK */
62+
63+
#ifdef CONFIG_HAVE_SOFTIRQ_ON_OWN_STACK
64+
void do_softirq_own_stack(void)
65+
{
66+
#ifdef CONFIG_IRQ_STACKS
67+
if (on_thread_stack()) {
68+
ulong *sp = per_cpu(irq_stack_ptr, smp_processor_id())
69+
+ IRQ_STACK_SIZE/sizeof(ulong);
70+
__asm__ __volatile(
71+
"addi sp, sp, -"RISCV_SZPTR "\n"
72+
REG_S" ra, (sp) \n"
73+
"addi sp, sp, -"RISCV_SZPTR "\n"
74+
REG_S" s0, (sp) \n"
75+
"addi s0, sp, 2*"RISCV_SZPTR "\n"
76+
"move sp, %[sp] \n"
77+
"call __do_softirq \n"
78+
"addi sp, s0, -2*"RISCV_SZPTR"\n"
79+
REG_L" s0, (sp) \n"
80+
"addi sp, sp, "RISCV_SZPTR "\n"
81+
REG_L" ra, (sp) \n"
82+
"addi sp, sp, "RISCV_SZPTR "\n"
83+
:
84+
: [sp] "r" (sp)
85+
: "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
86+
"t0", "t1", "t2", "t3", "t4", "t5", "t6",
87+
"memory");
88+
} else
89+
#endif
90+
__do_softirq();
91+
}
92+
#endif /* CONFIG_HAVE_SOFTIRQ_ON_OWN_STACK */
93+
5994
#else
6095
static void init_irq_stacks(void) {}
6196
#endif /* CONFIG_IRQ_STACKS */

0 commit comments

Comments
 (0)