openrisc / linux

Linux kernel source tree
Other
29 stars 14 forks source link

Failure when catting /proc/xxx/stack #13

Closed stffrdhrn closed 4 years ago

stffrdhrn commented 4 years ago

Seen with 5.7-rc2

Example:

/ # cat /proc/690/stack
[108997.050000] Unable to handle kernel access
[108997.050000]  at virtual address 0x7fc60f58
[108997.050000]
[108997.050000] Oops#: 0000
[108997.060000] CPU #: 0
[108997.060000]    PC: c00097fc    SR: 0000807f    SP: d6f09b9c
[108997.060000] GPR00: 00000000 GPR01: d6f09b9c GPR02: d6f09bb8 GPR03: d6f09bc4
[108997.060000] GPR04: 7fc60f5c GPR05: c00099b4 GPR06: 00000000 GPR07: d6f09ba3
[108997.060000] GPR08: ffffff00 GPR09: c0009804 GPR10: d6f08000 GPR11: 00000000
[108997.060000] GPR12: ffffe000 GPR13: dbb86000 GPR14: 00000001 GPR15: dbb86250
[108997.060000] GPR16: 7fc60f63 GPR17: 00000f5c GPR18: d6f09bc4 GPR19: 00000000
[108997.060000] GPR20: c00099b4 GPR21: ffffffc0 GPR22: 00000000 GPR23: 00000000
[108997.060000] GPR24: 00000001 GPR25: 000002c6 GPR26: d78b6850 GPR27: 00000001
[108997.060000] GPR28: 00000000 GPR29: dbb86000 GPR30: ffffffff GPR31: dbb862fc
[108997.060000]   RES: 00000000 oGPR11: ffffffff
[108997.060000] Process cat (pid: 702, stackpage=d79d6000)
[108997.060000]
[108997.060000] Stack:
[108997.060000] Call trace:
[108997.060000] [<598977f2>] save_stack_trace_tsk+0x40/0x74
[108997.060000] [<95063f0e>] stack_trace_save_tsk+0x44/0x58
[108997.060000] [<b557bfdd>] proc_pid_stack+0xd0/0x13c
[108997.060000] [<a2df8eda>] proc_single_show+0x6c/0xf0
[108997.060000] [<e5a737b7>] seq_read+0x1b4/0x688
[108997.060000] [<2d6c7480>] do_iter_read+0x208/0x248
[108997.060000] [<2182a2fb>] vfs_readv+0x64/0x90
[108997.060000] [<3ff02271>] ? iov_iter_get_pages_alloc+0x3d4/0x670
[108997.060000] [<bab8ec1a>] ? slob_alloc.isra.0+0xfc/0x348
[108997.070000] [<d58f9294>] ? __wake_up_common_lock+0x90/0xcc
[108997.070000] [<49544e36>] default_file_splice_read+0x1cc/0x3b0
[108997.070000] [<ab9ebd9e>] ? kmem_cache_alloc+0x48/0x104
[108997.070000] [<6dd300f2>] do_splice_to+0xa8/0x100
[108997.070000] [<caed44c0>] splice_direct_to_actor+0xf8/0x33c
[108997.070000] [<b2a5b2b1>] ? direct_splice_actor+0x0/0x70
[108997.070000] [<886bec27>] do_splice_direct+0xa4/0x100
[108997.070000] [<d3c7c436>] do_sendfile+0x2bc/0x4f0
[108997.070000] [<bd6b01e4>] sys_sendfile64+0x130/0x138
[108997.070000] [<7f032d7a>] ? _syscall_return+0x0/0x4
stffrdhrn commented 4 years ago

Failure in openrisc code:

< shorne@lianli ~/work/linux > ./scripts/faddr2line vmlinux save_stack_trace_tsk+0x40/0x74 stack_trace_save_tsk+0x44/0x58
save_stack_trace_tsk+0x40/0x74:
save_stack_trace_tsk at arch/openrisc/kernel/stacktrace.c:77

stack_trace_save_tsk+0x44/0x58:
stack_trace_save_tsk at kernel/stacktrace.c:308

Code:

void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
{
        unsigned long *sp = NULL;

        if (tsk == current)
                sp = (unsigned long *) &sp;
        else
                sp = (unsigned long *) KSTK_ESP(tsk);

        unwind_stack(trace, sp, save_stack_address_nosched);  <-- Failed calling this
}

From above the args are:

Confirmation on c00099b4

< shorne@lianli ~/work/linux > or1k-elf-objdump -d vmlinux| grep -A3 c00099b4                                                                                              
c00099b4 <save_stack_address_nosched>:                                                                                                                                     |
c00099b4:       9c 21 ff ec     l.addi r1,r1,-20                                                                                                                           |
c00099b8:       d4 01 a0 08     l.sw 8(r1),r20
c00099bc:       1a 80 00 00     l.movhi r20,0x0
c00099c0:       d4 01 10 0c     l.sw 12(r1),r2

PC reported c00097fc

c0009798 <unwind_stack>:
c0009798:       9e 24 00 03     l.addi r17,r4,3
c000979c:       a6 31 1f fc     l.andi r17,r17,0x1ffc
c00097a0:       1a 60 00 00     l.movhi r19,0x0
c00097a4:       e4 11 98 00     l.sfeq r17,r19
c00097a8:       10 00 00 49     l.bf c00098cc <unwind_stack+0x134>
c00097ac:       15 00 00 00     l.nop 0x0
c00097b0:       9c 21 ff e4     l.addi r1,r1,-28
c00097b4:       d4 01 80 00     l.sw 0(r1),r16
c00097b8:       d4 01 90 04     l.sw 4(r1),r18
c00097bc:       d4 01 a0 08     l.sw 8(r1),r20
c00097c0:       d4 01 b0 0c     l.sw 12(r1),r22
c00097c4:       d4 01 c0 10     l.sw 16(r1),r24
c00097c8:       d4 01 10 14     l.sw 20(r1),r2
c00097cc:       d4 01 48 18     l.sw 24(r1),r9
c00097d0:       9c 41 00 1c     l.addi r2,r1,28
c00097d4:       e2 43 18 04     l.or r18,r3,r3
c00097d8:       e2 85 28 04     l.or r20,r5,r5
c00097dc:       9e 04 00 07     l.addi r16,r4,7
c00097e0:       1a c0 00 00     l.movhi r22,0x0
c00097e4:       00 00 00 06     l.j c00097fc <unwind_stack+0x64>
c00097e8:       ab 00 00 01     l.ori r24,r0,0x1
c00097ec:       1a 60 00 00     l.movhi r19,0x0
c00097f0:       e4 31 98 00     l.sfne r17,r19
c00097f4:       0c 00 00 2a     l.bnf c000989c <unwind_stack+0x104>
c00097f8:       9e 10 00 04     l.addi r16,r16,4
c00097fc:       04 00 9b b7     l.jal c00306d8 <__kernel_text_address>  <--- PC is reported here
c0009800:       84 70 ff f5     l.lwz r3,-11(r16)
c0009804:       1a 20 00 00     l.movhi r17,0x0
stffrdhrn commented 4 years ago

This is fixed with the following patch. However, the stack traces don't look so hot.

For example:

 # cat /proc/2/stack 
[<0>] lock_acquire+0x118/0x4b8

Compared to the x86 stack for kthread:

# sudo cat /proc/2/stack
[<0>] kthreadd+0x2d0/0x2f0
[<0>] ret_from_fork+0x35/0x40
diff --git a/arch/openrisc/kernel/stacktrace.c b/arch/openrisc/kernel/stacktrace.c
index 43f140a28bc7..ac91614509c8 100644
--- a/arch/openrisc/kernel/stacktrace.c
+++ b/arch/openrisc/kernel/stacktrace.c
@@ -13,6 +13,7 @@
 #include <linux/export.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
+#include <linux/sched/task_stack.h>
 #include <linux/stacktrace.h>

 #include <asm/processor.h>
@@ -68,12 +69,17 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 {
        unsigned long *sp = NULL;

+       if (!try_get_task_stack(tsk))
+               return;
+
        if (tsk == current)
                sp = (unsigned long *) &sp;
        else
-               sp = (unsigned long *) KSTK_ESP(tsk);
+               sp = (unsigned long *) task_thread_info(tsk)->ksp;

        unwind_stack(trace, sp, save_stack_address_nosched);
+
+       put_task_stack(tsk);
 }
stffrdhrn commented 4 years ago

fix queued for merge in 5.9 window