Skip to content

Commit afbfb52

Browse files
committed
sh: stacktrace/lockdep/irqflags tracing support.
Wire up all of the essentials for lockdep.. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent c03c696 commit afbfb52

11 files changed

Lines changed: 289 additions & 103 deletions

File tree

‎arch/sh/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ config GENERIC_TIME
5151
config ARCH_MAY_HAVE_PC_FDC
5252
bool
5353

54+
config STACKTRACE_SUPPORT
55+
bool
56+
default y
57+
58+
config LOCKDEP_SUPPORT
59+
bool
60+
default y
61+
5462
source "init/Kconfig"
5563

5664
menu "System type"

‎arch/sh/Kconfig.debug‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
menu "Kernel hacking"
22

3+
config TRACE_IRQFLAGS_SUPPORT
4+
bool
5+
default y
6+
37
source "lib/Kconfig.debug"
48

59
config SH_STANDARD_BIOS

‎arch/sh/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
2121
obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
2222
obj-$(CONFIG_APM) += apm.o
2323
obj-$(CONFIG_PM) += pm.o
24+
obj-$(CONFIG_STACKTRACE) += stacktrace.o

‎arch/sh/kernel/cpu/sh2/entry.S‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ trap_entry:
184184
add r15,r8
185185
mov.l r9,@r8
186186
mov r9,r8
187+
#ifdef CONFIG_TRACE_IRQFLAGS
188+
mov.l 5f, r9
189+
jsr @r9
190+
nop
191+
#endif
187192
sti
188193
bra system_call
189194
nop
@@ -193,6 +198,9 @@ trap_entry:
193198
2: .long break_point_trap_software
194199
3: .long NR_syscalls
195200
4: .long sys_call_table
201+
#ifdef CONFIG_TRACE_IRQFLAGS
202+
5: .long trace_hardirqs_on
203+
#endif
196204

197205
#if defined(CONFIG_SH_STANDARD_BIOS)
198206
/* Unwind the stack and jmp to the debug entry */
@@ -255,6 +263,11 @@ ENTRY(address_error_handler)
255263

256264
restore_all:
257265
cli
266+
#ifdef CONFIG_TRACE_IRQFLAGS
267+
mov.l 3f, r0
268+
jsr @r0
269+
nop
270+
#endif
258271
mov r15,r0
259272
mov.l $cpu_mode,r2
260273
mov #OFF_SR,r3
@@ -307,6 +320,9 @@ $current_thread_info:
307320
.long __current_thread_info
308321
$cpu_mode:
309322
.long __cpu_mode
323+
#ifdef CONFIG_TRACE_IRQFLAGS
324+
3: .long trace_hardirqs_off
325+
#endif
310326
311327
! common exception handler
312328
#include "../../entry-common.S"

‎arch/sh/kernel/cpu/sh3/entry.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ call_dpf:
140140
mov.l 1f, r0
141141
mov.l @r0, r6 ! address
142142
mov.l 3f, r0
143-
sti
143+
144144
jmp @r0
145145
mov r15, r4 ! regs
146146

‎arch/sh/kernel/entry-common.S‎

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ debug_trap:
100100
.align 2
101101
ENTRY(exception_error)
102102
!
103+
#ifdef CONFIG_TRACE_IRQFLAGS
104+
mov.l 3f, r0
105+
jsr @r0
106+
nop
107+
#endif
103108
sti
104109
mov.l 2f, r0
105110
jmp @r0
@@ -109,10 +114,18 @@ ENTRY(exception_error)
109114
.align 2
110115
1: .long break_point_trap_software
111116
2: .long do_exception_error
117+
#ifdef CONFIG_TRACE_IRQFLAGS
118+
3: .long trace_hardirqs_on
119+
#endif
112120

113121
.align 2
114122
ret_from_exception:
115123
preempt_stop()
124+
#ifdef CONFIG_TRACE_IRQFLAGS
125+
mov.l 4f, r0
126+
jsr @r0
127+
nop
128+
#endif
116129
ENTRY(ret_from_irq)
117130
!
118131
mov #OFF_SR, r0
@@ -143,28 +156,48 @@ need_resched:
143156
mov.l 1f, r0
144157
mov.l r0, @(TI_PRE_COUNT,r8)
145158

159+
#ifdef CONFIG_TRACE_IRQFLAGS
160+
mov.l 3f, r0
161+
jsr @r0
162+
nop
163+
#endif
146164
sti
147165
mov.l 2f, r0
148166
jsr @r0
149167
nop
150168
mov #0, r0
151169
mov.l r0, @(TI_PRE_COUNT,r8)
152170
cli
171+
#ifdef CONFIG_TRACE_IRQFLAGS
172+
mov.l 4f, r0
173+
jsr @r0
174+
nop
175+
#endif
153176

154177
bra need_resched
155178
nop
179+
156180
noresched:
157181
bra __restore_all
158182
nop
159183

160184
.align 2
161185
1: .long PREEMPT_ACTIVE
162186
2: .long schedule
187+
#ifdef CONFIG_TRACE_IRQFLAGS
188+
3: .long trace_hardirqs_on
189+
4: .long trace_hardirqs_off
190+
#endif
163191
#endif
164192

165193
ENTRY(resume_userspace)
166194
! r8: current_thread_info
167195
cli
196+
#ifdef CONFIG_TRACE_IRQFLAGS
197+
mov.l 5f, r0
198+
jsr @r0
199+
nop
200+
#endif
168201
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
169202
tst #_TIF_WORK_MASK, r0
170203
bt/s __restore_all
@@ -210,6 +243,11 @@ work_resched:
210243
jsr @r1 ! schedule
211244
nop
212245
cli
246+
#ifdef CONFIG_TRACE_IRQFLAGS
247+
mov.l 5f, r0
248+
jsr @r0
249+
nop
250+
#endif
213251
!
214252
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
215253
tst #_TIF_WORK_MASK, r0
@@ -221,6 +259,10 @@ work_resched:
221259
1: .long schedule
222260
2: .long do_notify_resume
223261
3: .long restore_all
262+
#ifdef CONFIG_TRACE_IRQFLAGS
263+
4: .long trace_hardirqs_on
264+
5: .long trace_hardirqs_off
265+
#endif
224266

225267
.align 2
226268
syscall_exit_work:
@@ -229,6 +271,11 @@ syscall_exit_work:
229271
tst #_TIF_SYSCALL_TRACE, r0
230272
bt/s work_pending
231273
tst #_TIF_NEED_RESCHED, r0
274+
#ifdef CONFIG_TRACE_IRQFLAGS
275+
mov.l 5f, r0
276+
jsr @r0
277+
nop
278+
#endif
232279
sti
233280
! XXX setup arguments...
234281
mov.l 4f, r0 ! do_syscall_trace
@@ -265,7 +312,7 @@ syscall_trace_entry:
265312
mov.l r0, @(OFF_R0,r15) ! Return value
266313

267314
__restore_all:
268-
mov.l 1f,r0
315+
mov.l 1f, r0
269316
jmp @r0
270317
nop
271318

@@ -331,7 +378,13 @@ ENTRY(system_call)
331378
mov #OFF_TRA, r9
332379
add r15, r9
333380
mov.l r8, @r9 ! set TRA value to tra
381+
#ifdef CONFIG_TRACE_IRQFLAGS
382+
mov.l 5f, r10
383+
jsr @r10
384+
nop
385+
#endif
334386
sti
387+
335388
!
336389
get_current_thread_info r8, r10
337390
mov.l @(TI_FLAGS,r8), r8
@@ -355,6 +408,11 @@ syscall_call:
355408
!
356409
syscall_exit:
357410
cli
411+
#ifdef CONFIG_TRACE_IRQFLAGS
412+
mov.l 6f, r0
413+
jsr @r0
414+
nop
415+
#endif
358416
!
359417
get_current_thread_info r8, r0
360418
mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
@@ -369,3 +427,7 @@ syscall_exit:
369427
2: .long NR_syscalls
370428
3: .long sys_call_table
371429
4: .long do_syscall_trace
430+
#ifdef CONFIG_TRACE_IRQFLAGS
431+
5: .long trace_hardirqs_on
432+
6: .long trace_hardirqs_off
433+
#endif

‎arch/sh/kernel/stacktrace.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* arch/sh/kernel/stacktrace.c
3+
*
4+
* Stack trace management functions
5+
*
6+
* Copyright (C) 2006 Paul Mundt
7+
*
8+
* This file is subject to the terms and conditions of the GNU General Public
9+
* License. See the file "COPYING" in the main directory of this archive
10+
* for more details.
11+
*/
12+
#include <linux/sched.h>
13+
#include <linux/stacktrace.h>
14+
#include <linux/thread_info.h>
15+
#include <asm/ptrace.h>
16+
17+
/*
18+
* Save stack-backtrace addresses into a stack_trace buffer.
19+
*/
20+
void save_stack_trace(struct stack_trace *trace, struct task_struct *task)
21+
{
22+
unsigned long *sp;
23+
24+
if (!task)
25+
task = current;
26+
if (task == current)
27+
sp = (unsigned long *)current_stack_pointer;
28+
else
29+
sp = (unsigned long *)task->thread.sp;
30+
31+
while (!kstack_end(sp)) {
32+
unsigned long addr = *sp++;
33+
34+
if (__kernel_text_address(addr)) {
35+
if (trace->skip > 0)
36+
trace->skip--;
37+
else
38+
trace->entries[trace->nr_entries++] = addr;
39+
if (trace->nr_entries >= trace->max_entries)
40+
break;
41+
}
42+
}
43+
}

‎arch/sh/mm/fault.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
3737
int si_code;
3838
siginfo_t info;
3939

40+
trace_hardirqs_on();
41+
local_irq_enable();
42+
4043
#ifdef CONFIG_SH_KGDB
4144
if (kgdb_nofault && kgdb_bus_err_hook)
4245
kgdb_bus_err_hook();

0 commit comments

Comments
 (0)