diff options
-rw-r--r-- | Documentation/filesystems/proc.txt | 1 | ||||
-rw-r--r-- | arch/mips/kernel/stacktrace.c | 24 | ||||
-rw-r--r-- | fs/proc/base.c | 38 |
3 files changed, 57 insertions, 6 deletions
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt index 71df353e367c..334ef2f983fa 100644 --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt | |||
@@ -140,6 +140,7 @@ Table 1-1: Process specific entries in /proc | |||
140 | statm Process memory status information | 140 | statm Process memory status information |
141 | status Process status in human readable form | 141 | status Process status in human readable form |
142 | wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan | 142 | wchan If CONFIG_KALLSYMS is set, a pre-decoded wchan |
143 | stack Report full stack trace, enable via CONFIG_STACKTRACE | ||
143 | smaps Extension based on maps, the rss size for each mapped file | 144 | smaps Extension based on maps, the rss size for each mapped file |
144 | .............................................................................. | 145 | .............................................................................. |
145 | 146 | ||
diff --git a/arch/mips/kernel/stacktrace.c b/arch/mips/kernel/stacktrace.c index 0632e2a849c0..58f5cd76c8c3 100644 --- a/arch/mips/kernel/stacktrace.c +++ b/arch/mips/kernel/stacktrace.c | |||
@@ -32,7 +32,8 @@ static void save_raw_context_stack(struct stack_trace *trace, | |||
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | static void save_context_stack(struct stack_trace *trace, struct pt_regs *regs) | 35 | static void save_context_stack(struct stack_trace *trace, |
36 | struct task_struct *tsk, struct pt_regs *regs) | ||
36 | { | 37 | { |
37 | unsigned long sp = regs->regs[29]; | 38 | unsigned long sp = regs->regs[29]; |
38 | #ifdef CONFIG_KALLSYMS | 39 | #ifdef CONFIG_KALLSYMS |
@@ -41,7 +42,7 @@ static void save_context_stack(struct stack_trace *trace, struct pt_regs *regs) | |||
41 | 42 | ||
42 | if (raw_show_trace || !__kernel_text_address(pc)) { | 43 | if (raw_show_trace || !__kernel_text_address(pc)) { |
43 | unsigned long stack_page = | 44 | unsigned long stack_page = |
44 | (unsigned long)task_stack_page(current); | 45 | (unsigned long)task_stack_page(tsk); |
45 | if (stack_page && sp >= stack_page && | 46 | if (stack_page && sp >= stack_page && |
46 | sp <= stack_page + THREAD_SIZE - 32) | 47 | sp <= stack_page + THREAD_SIZE - 32) |
47 | save_raw_context_stack(trace, sp); | 48 | save_raw_context_stack(trace, sp); |
@@ -54,7 +55,7 @@ static void save_context_stack(struct stack_trace *trace, struct pt_regs *regs) | |||
54 | trace->entries[trace->nr_entries++] = pc; | 55 | trace->entries[trace->nr_entries++] = pc; |
55 | if (trace->nr_entries >= trace->max_entries) | 56 | if (trace->nr_entries >= trace->max_entries) |
56 | break; | 57 | break; |
57 | pc = unwind_stack(current, &sp, pc, &ra); | 58 | pc = unwind_stack(tsk, &sp, pc, &ra); |
58 | } while (pc); | 59 | } while (pc); |
59 | #else | 60 | #else |
60 | save_raw_context_stack(trace, sp); | 61 | save_raw_context_stack(trace, sp); |
@@ -66,12 +67,23 @@ static void save_context_stack(struct stack_trace *trace, struct pt_regs *regs) | |||
66 | */ | 67 | */ |
67 | void save_stack_trace(struct stack_trace *trace) | 68 | void save_stack_trace(struct stack_trace *trace) |
68 | { | 69 | { |
70 | save_stack_trace_tsk(current, trace); | ||
71 | } | ||
72 | EXPORT_SYMBOL_GPL(save_stack_trace); | ||
73 | |||
74 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) | ||
75 | { | ||
69 | struct pt_regs dummyregs; | 76 | struct pt_regs dummyregs; |
70 | struct pt_regs *regs = &dummyregs; | 77 | struct pt_regs *regs = &dummyregs; |
71 | 78 | ||
72 | WARN_ON(trace->nr_entries || !trace->max_entries); | 79 | WARN_ON(trace->nr_entries || !trace->max_entries); |
73 | 80 | ||
74 | prepare_frametrace(regs); | 81 | if (tsk != current) { |
75 | save_context_stack(trace, regs); | 82 | regs->regs[29] = tsk->thread.reg29; |
83 | regs->regs[31] = 0; | ||
84 | regs->cp0_epc = tsk->thread.reg31; | ||
85 | } else | ||
86 | prepare_frametrace(regs); | ||
87 | save_context_stack(trace, tsk, regs); | ||
76 | } | 88 | } |
77 | EXPORT_SYMBOL_GPL(save_stack_trace); | 89 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |
diff --git a/fs/proc/base.c b/fs/proc/base.c index ce7a6da1b6a0..eb7b4654d6aa 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -65,6 +65,7 @@ | |||
65 | #include <linux/mm.h> | 65 | #include <linux/mm.h> |
66 | #include <linux/rcupdate.h> | 66 | #include <linux/rcupdate.h> |
67 | #include <linux/kallsyms.h> | 67 | #include <linux/kallsyms.h> |
68 | #include <linux/stacktrace.h> | ||
68 | #include <linux/resource.h> | 69 | #include <linux/resource.h> |
69 | #include <linux/module.h> | 70 | #include <linux/module.h> |
70 | #include <linux/mount.h> | 71 | #include <linux/mount.h> |
@@ -337,6 +338,37 @@ static int proc_pid_wchan(struct task_struct *task, char *buffer) | |||
337 | } | 338 | } |
338 | #endif /* CONFIG_KALLSYMS */ | 339 | #endif /* CONFIG_KALLSYMS */ |
339 | 340 | ||
341 | #ifdef CONFIG_STACKTRACE | ||
342 | |||
343 | #define MAX_STACK_TRACE_DEPTH 64 | ||
344 | |||
345 | static int proc_pid_stack(struct seq_file *m, struct pid_namespace *ns, | ||
346 | struct pid *pid, struct task_struct *task) | ||
347 | { | ||
348 | struct stack_trace trace; | ||
349 | unsigned long *entries; | ||
350 | int i; | ||
351 | |||
352 | entries = kmalloc(MAX_STACK_TRACE_DEPTH * sizeof(*entries), GFP_KERNEL); | ||
353 | if (!entries) | ||
354 | return -ENOMEM; | ||
355 | |||
356 | trace.nr_entries = 0; | ||
357 | trace.max_entries = MAX_STACK_TRACE_DEPTH; | ||
358 | trace.entries = entries; | ||
359 | trace.skip = 0; | ||
360 | save_stack_trace_tsk(task, &trace); | ||
361 | |||
362 | for (i = 0; i < trace.nr_entries; i++) { | ||
363 | seq_printf(m, "[<%p>] %pS\n", | ||
364 | (void *)entries[i], (void *)entries[i]); | ||
365 | } | ||
366 | kfree(entries); | ||
367 | |||
368 | return 0; | ||
369 | } | ||
370 | #endif | ||
371 | |||
340 | #ifdef CONFIG_SCHEDSTATS | 372 | #ifdef CONFIG_SCHEDSTATS |
341 | /* | 373 | /* |
342 | * Provides /proc/PID/schedstat | 374 | * Provides /proc/PID/schedstat |
@@ -2500,6 +2532,9 @@ static const struct pid_entry tgid_base_stuff[] = { | |||
2500 | #ifdef CONFIG_KALLSYMS | 2532 | #ifdef CONFIG_KALLSYMS |
2501 | INF("wchan", S_IRUGO, proc_pid_wchan), | 2533 | INF("wchan", S_IRUGO, proc_pid_wchan), |
2502 | #endif | 2534 | #endif |
2535 | #ifdef CONFIG_STACKTRACE | ||
2536 | ONE("stack", S_IRUSR, proc_pid_stack), | ||
2537 | #endif | ||
2503 | #ifdef CONFIG_SCHEDSTATS | 2538 | #ifdef CONFIG_SCHEDSTATS |
2504 | INF("schedstat", S_IRUGO, proc_pid_schedstat), | 2539 | INF("schedstat", S_IRUGO, proc_pid_schedstat), |
2505 | #endif | 2540 | #endif |
@@ -2835,6 +2870,9 @@ static const struct pid_entry tid_base_stuff[] = { | |||
2835 | #ifdef CONFIG_KALLSYMS | 2870 | #ifdef CONFIG_KALLSYMS |
2836 | INF("wchan", S_IRUGO, proc_pid_wchan), | 2871 | INF("wchan", S_IRUGO, proc_pid_wchan), |
2837 | #endif | 2872 | #endif |
2873 | #ifdef CONFIG_STACKTRACE | ||
2874 | ONE("stack", S_IRUSR, proc_pid_stack), | ||
2875 | #endif | ||
2838 | #ifdef CONFIG_SCHEDSTATS | 2876 | #ifdef CONFIG_SCHEDSTATS |
2839 | INF("schedstat", S_IRUGO, proc_pid_schedstat), | 2877 | INF("schedstat", S_IRUGO, proc_pid_schedstat), |
2840 | #endif | 2878 | #endif |