linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: fix the incorrect value of sp in __die()
@ 2022-04-18  3:45 Yuanzheng Song
  2022-04-18  8:03 ` Russell King (Oracle)
  0 siblings, 1 reply; 3+ messages in thread
From: Yuanzheng Song @ 2022-04-18  3:45 UTC (permalink / raw)
  To: linux, ardb, rmk+kernel, arnd, linus.walleij, akpm, ebiederm,
	wangkefeng.wang
  Cc: linux-arm-kernel, linux-kernel, Yuanzheng Song

The dump_mem() will output useless content that exceed the stack
in __die(), because sp will exceed the top of stack when the
CONFIG_VMAP_STACK=y.

Insufficient stack space to handle exception!
Task stack:     [0xf09dc000..0xf09de000]
IRQ stack:      [0xf0800000..0xf0802000]
Overflow stack: [0xc210e000..0xc210f000]
Internal error: kernel stack overflow: 0 [#1] SMP ARM
Modules linked in:
CPU: 0 PID: 81 Comm: sh Not tainted 5.18.0-rc3 #4
Hardware name: ARM-Versatile Express
PC is at mmioset+0x20/0xa8
LR is at recursive_loop+0x34/0x9c
pc : [<c0777080>]    lr : [<c0a90c6c>]    psr: 20000013
sp : f09dbf48  ip : f09dbf4c  fp : 00219644
...
Stack: (0xf09dbf48 to 0xf09de000)
bf40:                   ???????? ???????? ???????? ???????? ???????? ????????
bf60: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
bf80: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
bfa0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
bfc0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
bfe0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
c000: 57ac6e9d 00000000 00000000 00000000 00000000 00000000 00000000 00000000
...

So fix it by adding check for sp and modifying the value of sp
when sp exceed the top of stack.

Insufficient stack space to handle exception!
Task stack:     [0xf09d8000..0xf09da000]
IRQ stack:      [0xf0800000..0xf0802000]
Overflow stack: [0xc210e000..0xc210f000]
Internal error: kernel stack overflow: 0 [#1] SMP ARM
Modules linked in:
CPU: 0 PID: 81 Comm: sh Not tainted 5.18.0-rc3-dirty #3
Hardware name: ARM-Versatile Express
PC is at mmioset+0x20/0xa8
LR is at recursive_loop+0x34/0x9c
pc : [<c0777080>]    lr : [<c0a90c6c>]    psr: 20000013
sp : f09d7f48  ip : f09d7f4c  fp : 00219644
...
Stack: (0xf09d8000 to 0xf09da000)
8000: 57ac6e9d 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8020: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8040: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
8060: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
...

Fixes: a1c510d0adc6 ("ARM: implement support for vmap'ed stacks")
Signed-off-by: Yuanzheng Song <songyuanzheng@huawei.com>
---
 arch/arm/kernel/traps.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 9283dc65be31..e93d8f2296be 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -277,6 +277,7 @@ static int __die(const char *str, int err, struct pt_regs *regs)
 	struct task_struct *tsk = current;
 	static int die_counter;
 	int ret;
+	unsigned long sp;
 
 	pr_emerg("Internal error: %s: %x [#%d]" S_PREEMPT S_SMP S_ISA "\n",
 	         str, err, ++die_counter);
@@ -293,8 +294,11 @@ static int __die(const char *str, int err, struct pt_regs *regs)
 		 TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
 
 	if (!user_mode(regs) || in_interrupt()) {
-		dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
-			 ALIGN(regs->ARM_sp - THREAD_SIZE, THREAD_ALIGN)
+		sp = regs->ARM_sp;
+		if (sp < (unsigned long)tsk->stack)
+			sp = (unsigned long)tsk->stack;
+		dump_mem(KERN_EMERG, "Stack: ", sp,
+			 ALIGN(sp - THREAD_SIZE, THREAD_ALIGN)
 			 + THREAD_SIZE);
 		dump_backtrace(regs, tsk, KERN_EMERG);
 		dump_instr(KERN_EMERG, regs);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ARM: fix the incorrect value of sp in __die()
  2022-04-18  3:45 [PATCH] ARM: fix the incorrect value of sp in __die() Yuanzheng Song
@ 2022-04-18  8:03 ` Russell King (Oracle)
  2022-04-18  8:36   ` songyuanzheng
  0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2022-04-18  8:03 UTC (permalink / raw)
  To: Yuanzheng Song
  Cc: ardb, arnd, linus.walleij, akpm, ebiederm, wangkefeng.wang,
	linux-arm-kernel, linux-kernel

On Mon, Apr 18, 2022 at 03:45:16AM +0000, Yuanzheng Song wrote:
> The dump_mem() will output useless content that exceed the stack
> in __die(), because sp will exceed the top of stack when the
> CONFIG_VMAP_STACK=y.

However, regs->ARM_sp _is_ the value of the stack pointer of the parent
context when the exception was taken, and is the correct value to start
printing the stack from.

If the first few prints are unreadable, then that's useful information.

> Insufficient stack space to handle exception!
> Task stack:     [0xf09dc000..0xf09de000]
> IRQ stack:      [0xf0800000..0xf0802000]
> Overflow stack: [0xc210e000..0xc210f000]
> Internal error: kernel stack overflow: 0 [#1] SMP ARM
> Modules linked in:
> CPU: 0 PID: 81 Comm: sh Not tainted 5.18.0-rc3 #4
> Hardware name: ARM-Versatile Express
> PC is at mmioset+0x20/0xa8
> LR is at recursive_loop+0x34/0x9c
> pc : [<c0777080>]    lr : [<c0a90c6c>]    psr: 20000013
> sp : f09dbf48  ip : f09dbf4c  fp : 00219644
> ...
> Stack: (0xf09dbf48 to 0xf09de000)
> bf40:                   ???????? ???????? ???????? ???????? ???????? ????????
> bf60: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
> bf80: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
> bfa0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
> bfc0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
> bfe0: ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
> c000: 57ac6e9d 00000000 00000000 00000000 00000000 00000000 00000000 00000000

The above is useful information - it tells us that 0xf09dbf48 to
0xf09dc000 fault when accessed.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ARM: fix the incorrect value of sp in __die()
  2022-04-18  8:03 ` Russell King (Oracle)
@ 2022-04-18  8:36   ` songyuanzheng
  0 siblings, 0 replies; 3+ messages in thread
From: songyuanzheng @ 2022-04-18  8:36 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: ardb, arnd, linus.walleij, akpm, ebiederm, wangkefeng.wang,
	linux-arm-kernel, linux-kernel

Thanks for your reply.

I didn't fully understand these code, please ignore this patch.

Thanks.

On 2022/4/18 16:03, Russell King (Oracle) wrote:
> Insufficient stack space to handle exception!
> Task stack:     [0xf09dc000..0xf09de000]
> IRQ stack:      [0xf0800000..0xf0802000]
> Overflow stack: [0xc210e000..0xc210f000]
> Internal error: kernel stack overflow: 0 [#1] SMP ARM
> Modules linked in:
> CPU: 0 PID: 81 Comm: sh Not tainted 5.18.0-rc3 #4
> Hardware name: ARM-Versatile Express
> PC is at mmioset+0x20/0xa8
> LR is at recursive_loop+0x34/0x9c
> pc : [<c0777080>]    lr : [<c0a90c6c>]    psr: 20000013
> sp : f09dbf48  ip : f09dbf4c  fp : 00219644
> ...
> Stack: (0xf09dbf48 to 0xf09de000)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-18  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-18  3:45 [PATCH] ARM: fix the incorrect value of sp in __die() Yuanzheng Song
2022-04-18  8:03 ` Russell King (Oracle)
2022-04-18  8:36   ` songyuanzheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).