Skip to contentSkip to conversation

riscv: stack: Fixup independent softirq/irq stack for CONFIG_FRAME_POINTER=n

PATCH Applied [email protected] 4 participants 6 messages Jul 16, 2023 – Aug 17, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover riscv: stack: Fixup independent softirq/irq stack for CONFIG_FRAME_POINTER=n

From: Guo Ren <[email protected]>

The independent softirq/irq stack uses s0 to save & restore sp, but s0 would be corrupted when CONFIG_FRAME_POINTER=n. So add s0 in the clobber list to fix the problem.

<+0>:     addi    sp,sp,-32
<+2>:     sd      s0,16(sp)
<+4>:     sd      s1,8(sp)
<+6>:     sd      ra,24(sp)
<+8>:     sd      s2,0(sp)
<+10>:    mv      s0,a0		--> compiler allocate s0 for a0 when CONFIG_FRAME_POINTER=n
<+12>:    jal     ra,0xffffffff800bc0ce <irqentry_enter>
<+16>:    ld      a5,56(tp) # 0x38
<+20>:    lui     a4,0x4
<+22>:    mv      s1,a0
<+24>:    xor     a5,a5,sp
<+28>:    bgeu    a5,a4,0xffffffff800bc092 <do_irq+88>
<+32>:    auipc   s2,0x5d
<+36>:    ld      s2,1118(s2) # 0xffffffff801194b8 <irq_stack_ptr>
<+40>:    add     s2,s2,a4
<+42>:    addi    sp,sp,-8
<+44>:    sd      ra,0(sp)
<+46>:    addi    sp,sp,-8
<+48>:    sd      s0,0(sp)
<+50>:    addi    s0,sp,16	--> our code clobber the s0
<+52>:    mv      sp,s2
<+54>:    mv      a0,s0		--> a0 got wrong value for handle_riscv_irq 
<+56>:    jal     ra,0xffffffff800bbb3a <handle_riscv_irq>

Changelog:
V2
- Fixup compile error with CONFIG_FRAME_POINTER=y
- FIxup [email protected] tag

Guo Ren (2):
riscv: stack: Fixup independent irq stack for CONFIG_FRAME_POINTER=n
riscv: stack: Fixup independent softirq stack for
CONFIG_FRAME_POINTER=n

 arch/riscv/kernel/irq.c   | 3 +++
 arch/riscv/kernel/traps.c | 3 +++
 2 files changed, 6 insertions(+)
Signature · 1 line
2.36.1
#1 lore raw

PATCH v2 1/2 riscv: stack: Fixup independent irq stack for CONFIG_FRAME_POINTER=n

From: Guo Ren <[email protected]>

The independent irq stack uses s0 to save & restore sp, but s0 would be corrupted when CONFIG_FRAME_POINTER=n. So add s0 in the clobber list to fix the problem.

Fixes 163e76cc6ef4 ("riscv: stack: Support HAVE_IRQ_EXIT_ON_IRQ_STACK")
---
 arch/riscv/kernel/traps.c | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/kernel/traps.c +3 -0
index f910dfccbf5d..927347a19847 100644
@@ -372,6 +372,9 @@ asmlinkage void noinstr do_irq(struct pt_regs *regs)
 		: [sp] "r" (sp), [regs] "r" (regs)
 		: "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
 		  "t0", "t1", "t2", "t3", "t4", "t5", "t6",
+#ifndef CONFIG_FRAME_POINTER
+		  "s0",
+#endif
 		  "memory");
 	} else
 #endif
Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH V2 1/2] riscv: stack: Fixup independent irq stack for CONFIG_FRAME_POINTER=n

Quoted 5 lines · Le sunnuntaina 16. heinäkuuta 2023, 3.15.05 EEST [email protected] a écrit :

From: Guo Ren <[email protected]>

The independent irq stack uses s0 to save & restore sp, but s0 would be corrupted when CONFIG_FRAME_POINTER=n. So add s0 in the clobber list to fix the problem.

Isn't it *always* corrupted? Shouldn't the clobber be always there? Am I guessing that the compiler whine that you can't mark the frame pointer as clobbered? If so, it would be worth mentioning in the commit log, IMO.

Quoted 25 lines
Fixes 163e76cc6ef4 ("riscv: stack: Support HAVE_IRQ_EXIT_ON_IRQ_STACK")
---
 arch/riscv/kernel/traps.c | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/kernel/traps.c +3 -0
index f910dfccbf5d..927347a19847 100644
@@ -372,6 +372,9 @@ asmlinkage void noinstr do_irq(struct pt_regs *regs)
 
 		: [sp] "r" (sp), [regs] "r" (regs)
 		: "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
 
 		  "t0", "t1", "t2", "t3", "t4", "t5", "t6",
+#ifndef CONFIG_FRAME_POINTER
+		  "s0",
+#endif
 		  "memory");

} else
#endif

Signature · 10 lines
レミ・デニ-クールモン
http://www.remlab.net/




_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

PATCH v2 2/2 riscv: stack: Fixup independent softirq stack for CONFIG_FRAME_POINTER=n

In reply to [email protected]

From: Guo Ren <[email protected]>

The independent softirq stack uses s0 to save & restore sp, but s0 would be corrupted when CONFIG_FRAME_POINTER=n. So add s0 in the clobber list to fix the problem.

Fixes dd69d07a5a6c ("riscv: stack: Support HAVE_SOFTIRQ_ON_OWN_STACK")
---
 arch/riscv/kernel/irq.c | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/kernel/irq.c +3 -0
index d0577cc6a081..a8efa053c4a5 100644
@@ -84,6 +84,9 @@ void do_softirq_own_stack(void)
 		: [sp] "r" (sp)
 		: "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
 		  "t0", "t1", "t2", "t3", "t4", "t5", "t6",
+#ifndef CONFIG_FRAME_POINTER
+		  "s0",
+#endif
 		  "memory");
 	} else
 #endif
Signature · 1 line
2.36.1
Tested-by on the v2 series
#4 lore raw
In reply to [email protected]
Quoted 35 lines · On Sat, Jul 15, 2023 at 08:15:04PM -0400, [email protected] wrote:

From: Guo Ren <[email protected]>

The independent softirq/irq stack uses s0 to save & restore sp, but s0 would be corrupted when CONFIG_FRAME_POINTER=n. So add s0 in the clobber list to fix the problem.

<+0>:     addi    sp,sp,-32
<+2>:     sd      s0,16(sp)
<+4>:     sd      s1,8(sp)
<+6>:     sd      ra,24(sp)
<+8>:     sd      s2,0(sp)
<+10>:    mv      s0,a0		--> compiler allocate s0 for a0 when CONFIG_FRAME_POINTER=n
<+12>:    jal     ra,0xffffffff800bc0ce <irqentry_enter>
<+16>:    ld      a5,56(tp) # 0x38
<+20>:    lui     a4,0x4
<+22>:    mv      s1,a0
<+24>:    xor     a5,a5,sp
<+28>:    bgeu    a5,a4,0xffffffff800bc092 <do_irq+88>
<+32>:    auipc   s2,0x5d
<+36>:    ld      s2,1118(s2) # 0xffffffff801194b8 <irq_stack_ptr>
<+40>:    add     s2,s2,a4
<+42>:    addi    sp,sp,-8
<+44>:    sd      ra,0(sp)
<+46>:    addi    sp,sp,-8
<+48>:    sd      s0,0(sp)
<+50>:    addi    s0,sp,16	--> our code clobber the s0
<+52>:    mv      sp,s2
<+54>:    mv      a0,s0		--> a0 got wrong value for handle_riscv_irq 
<+56>:    jal     ra,0xffffffff800bbb3a <handle_riscv_irq>

Changelog:
V2
- Fixup compile error with CONFIG_FRAME_POINTER=y
- FIxup [email protected] tag

Quoted 17 lines

Guo Ren (2):
riscv: stack: Fixup independent irq stack for CONFIG_FRAME_POINTER=n
riscv: stack: Fixup independent softirq stack for
CONFIG_FRAME_POINTER=n

 arch/riscv/kernel/irq.c   | 3 +++
 arch/riscv/kernel/traps.c | 3 +++
 2 files changed, 6 insertions(+)
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Xi Ruoyao noticed that the mainline kernel crashed when using a kernel config with CONFIG_FRAME_POINTER=n. I was able to reproduce this [1]. Emil suggested I trying this patche series. I can confirm that this resolves the kernel crash on the Sipeed Lichee Pi4a [2].

Thanks,
Drew

[1] https://lore.kernel.org/linux-riscv/ZMNojqwLxcG8FcHN@x1/
[2] https://lore.kernel.org/linux-riscv/ZMQAqUfb0y%2FigQs2@x1/

#5 lore raw
In reply to [email protected]
This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:

Hello:

This series was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:

Quoted 30 lines · On Sat, 15 Jul 2023 20:15:04 -0400 you wrote:

From: Guo Ren <[email protected]>

The independent softirq/irq stack uses s0 to save & restore sp, but s0 would be corrupted when CONFIG_FRAME_POINTER=n. So add s0 in the clobber list to fix the problem.

<+0>:     addi    sp,sp,-32
<+2>:     sd      s0,16(sp)
<+4>:     sd      s1,8(sp)
<+6>:     sd      ra,24(sp)
<+8>:     sd      s2,0(sp)
<+10>:    mv      s0,a0		--> compiler allocate s0 for a0 when CONFIG_FRAME_POINTER=n
<+12>:    jal     ra,0xffffffff800bc0ce <irqentry_enter>
<+16>:    ld      a5,56(tp) # 0x38
<+20>:    lui     a4,0x4
<+22>:    mv      s1,a0
<+24>:    xor     a5,a5,sp
<+28>:    bgeu    a5,a4,0xffffffff800bc092 <do_irq+88>
<+32>:    auipc   s2,0x5d
<+36>:    ld      s2,1118(s2) # 0xffffffff801194b8 <irq_stack_ptr>
<+40>:    add     s2,s2,a4
<+42>:    addi    sp,sp,-8
<+44>:    sd      ra,0(sp)
<+46>:    addi    sp,sp,-8
<+48>:    sd      s0,0(sp)
<+50>:    addi    s0,sp,16	--> our code clobber the s0
<+52>:    mv      sp,s2
<+54>:    mv      a0,s0		--> a0 got wrong value for handle_riscv_irq
<+56>:    jal     ra,0xffffffff800bbb3a <handle_riscv_irq>
Quoted 1 line

[...]

Here is the summary with links:
- [V2,1/2] riscv: stack: Fixup independent irq stack for CONFIG_FRAME_POINTER=n

    https://git.kernel.org/riscv/c/8d0be64154cf
  - [V2,2/2] riscv: stack: Fixup independent softirq stack for CONFIG_FRAME_POINTER=n
    https://git.kernel.org/riscv/c/ebc9cb03b21e

You are awesome, thank you!

Signature · 9 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv