Skip to content

Commit c8921d7

Browse files
committed
parisc: Fix and improve kernel stack unwinding
This patchset fixes and improves stack unwinding a lot: 1. Show backward stack traces with up to 30 callsites 2. Add callinfo to ENTRY_CFI() such that every assembler function will get an entry in the unwind table 3. Use constants instead of numbers in call_on_stack() 4. Do not depend on CONFIG_KALLSYMS to generate backtraces. 5. Speed up backtrace generation Make sure you have this patch to GNU as installed: https://sourceware.org/ml/binutils/2018-07/msg00474.html Without this patch, unwind info in the kernel is often wrong for various functions. Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 3b885ac commit c8921d7

10 files changed

Lines changed: 88 additions & 232 deletions

File tree

‎arch/parisc/include/asm/assembly.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define RP_OFFSET 16
3737
#define FRAME_SIZE 128
3838
#define CALLEE_REG_FRAME_SIZE 144
39+
#define REG_SZ 8
3940
#define ASM_ULONG_INSN .dword
4041
#else /* CONFIG_64BIT */
4142
#define LDREG ldw
@@ -50,6 +51,7 @@
5051
#define RP_OFFSET 20
5152
#define FRAME_SIZE 64
5253
#define CALLEE_REG_FRAME_SIZE 128
54+
#define REG_SZ 4
5355
#define ASM_ULONG_INSN .word
5456
#endif
5557

‎arch/parisc/include/asm/linkage.h‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#ifdef __ASSEMBLY__
1919

2020
#define ENTRY(name) \
21-
.export name !\
22-
ALIGN !\
23-
name:
21+
ALIGN !\
22+
name: ASM_NL\
23+
.export name
2424

2525
#ifdef CONFIG_64BIT
2626
#define ENDPROC(name) \
@@ -31,13 +31,18 @@
3131
END(name)
3232
#endif
3333

34-
#define ENTRY_CFI(name) \
34+
#define ENTRY_CFI(name, ...) \
3535
ENTRY(name) ASM_NL\
36+
.proc ASM_NL\
37+
.callinfo __VA_ARGS__ ASM_NL\
38+
.entry ASM_NL\
3639
CFI_STARTPROC
3740

3841
#define ENDPROC_CFI(name) \
39-
ENDPROC(name) ASM_NL\
40-
CFI_ENDPROC
42+
CFI_ENDPROC ASM_NL\
43+
.exit ASM_NL\
44+
.procend ASM_NL\
45+
ENDPROC(name)
4146

4247
#endif /* __ASSEMBLY__ */
4348

‎arch/parisc/include/asm/unwind.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include <linux/list.h>
66

7+
/* Max number of levels to backtrace */
8+
#define MAX_UNWIND_ENTRIES 30
9+
710
/* From ABI specifications */
811
struct unwind_table_entry {
912
unsigned int region_start;

‎arch/parisc/kernel/entry.S‎

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ END(fault_vector_11)
766766
#endif
767767
/* Fault vector is separately protected and *must* be on its own page */
768768
.align PAGE_SIZE
769-
ENTRY(end_fault_vector)
770769

771770
.import handle_interruption,code
772771
.import do_cpu_irq_mask,code
@@ -778,7 +777,6 @@ ENTRY(end_fault_vector)
778777
*/
779778

780779
ENTRY_CFI(ret_from_kernel_thread)
781-
782780
/* Call schedule_tail first though */
783781
BL schedule_tail, %r2
784782
nop
@@ -817,16 +815,17 @@ ENTRY_CFI(_switch_to)
817815
LDREG TASK_THREAD_INFO(%r25), %r25
818816
bv %r0(%r2)
819817
mtctl %r25,%cr30
818+
ENDPROC_CFI(_switch_to)
820819

821-
_switch_to_ret:
820+
ENTRY_CFI(_switch_to_ret)
822821
mtctl %r0, %cr0 /* Needed for single stepping */
823822
callee_rest
824823
callee_rest_float
825824

826825
LDREG -RP_OFFSET(%r30), %r2
827826
bv %r0(%r2)
828827
copy %r26, %r28
829-
ENDPROC_CFI(_switch_to)
828+
ENDPROC_CFI(_switch_to_ret)
830829

831830
/*
832831
* Common rfi return path for interruptions, kernel execve, and
@@ -887,12 +886,14 @@ ENTRY_CFI(syscall_exit_rfi)
887886
STREG %r19,PT_SR5(%r16)
888887
STREG %r19,PT_SR6(%r16)
889888
STREG %r19,PT_SR7(%r16)
889+
ENDPROC_CFI(syscall_exit_rfi)
890890

891-
intr_return:
891+
ENTRY_CFI(intr_return)
892892
/* check for reschedule */
893893
mfctl %cr30,%r1
894894
LDREG TI_FLAGS(%r1),%r19 /* sched.h: TIF_NEED_RESCHED */
895895
bb,<,n %r19,31-TIF_NEED_RESCHED,intr_do_resched /* forward */
896+
ENDPROC_CFI(intr_return)
896897

897898
.import do_notify_resume,code
898899
intr_check_sig:
@@ -1048,7 +1049,6 @@ intr_extint:
10481049

10491050
b do_cpu_irq_mask
10501051
ldo R%intr_return(%r2), %r2 /* return to intr_return, not here */
1051-
ENDPROC_CFI(syscall_exit_rfi)
10521052

10531053

10541054
/* Generic interruptions (illegal insn, unaligned, page fault, etc) */
@@ -1999,12 +1999,9 @@ ENDPROC_CFI(syscall_exit)
19991999
.align L1_CACHE_BYTES
20002000
.globl mcount
20012001
.type mcount, @function
2002-
ENTRY(mcount)
2002+
ENTRY_CFI(mcount, caller)
20032003
_mcount:
20042004
.export _mcount,data
2005-
.proc
2006-
.callinfo caller,frame=0
2007-
.entry
20082005
/*
20092006
* The 64bit mcount() function pointer needs 4 dwords, of which the
20102007
* first two are free. We optimize it here and put 2 instructions for
@@ -2026,18 +2023,13 @@ ftrace_stub:
20262023
.dword mcount
20272024
.dword 0 /* code in head.S puts value of global gp here */
20282025
#endif
2029-
.exit
2030-
.procend
2031-
ENDPROC(mcount)
2026+
ENDPROC_CFI(mcount)
20322027

20332028
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
20342029
.align 8
20352030
.globl return_to_handler
20362031
.type return_to_handler, @function
2037-
ENTRY_CFI(return_to_handler)
2038-
.proc
2039-
.callinfo caller,frame=FRAME_SIZE
2040-
.entry
2032+
ENTRY_CFI(return_to_handler, caller,frame=FRAME_SIZE)
20412033
.export parisc_return_to_handler,data
20422034
parisc_return_to_handler:
20432035
copy %r3,%r1
@@ -2076,8 +2068,6 @@ parisc_return_to_handler:
20762068
bv %r0(%rp)
20772069
#endif
20782070
LDREGM -FRAME_SIZE(%sp),%r3
2079-
.exit
2080-
.procend
20812071
ENDPROC_CFI(return_to_handler)
20822072

20832073
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
@@ -2087,41 +2077,40 @@ ENDPROC_CFI(return_to_handler)
20872077
#ifdef CONFIG_IRQSTACKS
20882078
/* void call_on_stack(unsigned long param1, void *func,
20892079
unsigned long new_stack) */
2090-
ENTRY_CFI(call_on_stack)
2080+
ENTRY_CFI(call_on_stack, FRAME=2*FRAME_SIZE,CALLS,SAVE_RP,SAVE_SP)
20912081
copy %sp, %r1
20922082

20932083
/* Regarding the HPPA calling conventions for function pointers,
20942084
we assume the PIC register is not changed across call. For
20952085
CONFIG_64BIT, the argument pointer is left to point at the
20962086
argument region allocated for the call to call_on_stack. */
2087+
2088+
/* Switch to new stack. We allocate two frames. */
2089+
ldo 2*FRAME_SIZE(%arg2), %sp
20972090
# ifdef CONFIG_64BIT
2098-
/* Switch to new stack. We allocate two 128 byte frames. */
2099-
ldo 256(%arg2), %sp
21002091
/* Save previous stack pointer and return pointer in frame marker */
2101-
STREG %rp, -144(%sp)
2092+
STREG %rp, -FRAME_SIZE-RP_OFFSET(%sp)
21022093
/* Calls always use function descriptor */
21032094
LDREG 16(%arg1), %arg1
21042095
bve,l (%arg1), %rp
2105-
STREG %r1, -136(%sp)
2106-
LDREG -144(%sp), %rp
2096+
STREG %r1, -FRAME_SIZE-REG_SZ(%sp)
2097+
LDREG -FRAME_SIZE-RP_OFFSET(%sp), %rp
21072098
bve (%rp)
2108-
LDREG -136(%sp), %sp
2099+
LDREG -FRAME_SIZE-REG_SZ(%sp), %sp
21092100
# else
2110-
/* Switch to new stack. We allocate two 64 byte frames. */
2111-
ldo 128(%arg2), %sp
21122101
/* Save previous stack pointer and return pointer in frame marker */
2113-
STREG %r1, -68(%sp)
2114-
STREG %rp, -84(%sp)
2102+
STREG %r1, -FRAME_SIZE-REG_SZ(%sp)
2103+
STREG %rp, -FRAME_SIZE-RP_OFFSET(%sp)
21152104
/* Calls use function descriptor if PLABEL bit is set */
21162105
bb,>=,n %arg1, 30, 1f
21172106
depwi 0,31,2, %arg1
21182107
LDREG 0(%arg1), %arg1
21192108
1:
21202109
be,l 0(%sr4,%arg1), %sr0, %r31
21212110
copy %r31, %rp
2122-
LDREG -84(%sp), %rp
2111+
LDREG -FRAME_SIZE-RP_OFFSET(%sp), %rp
21232112
bv (%rp)
2124-
LDREG -68(%sp), %sp
2113+
LDREG -FRAME_SIZE-REG_SZ(%sp), %sp
21252114
# endif /* CONFIG_64BIT */
21262115
ENDPROC_CFI(call_on_stack)
21272116
#endif /* CONFIG_IRQSTACKS */

0 commit comments

Comments
 (0)