[PATCH 2/2] x86: Make the x86-64 stacktrace code safely callable from scheduler

From: Frederic Weisbecker
Date: Thu May 12 2011 - 16:32:31 EST


Avoid potential scheduler recursion and deadlock from the
stacktrace code by avoiding rescheduling when we re-enable
preemption.

This robustifies some scheduler trace events like sched switch
when they are used to produce callchains in perf or ftrace.

Signed-off-by: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
arch/x86/kernel/dumpstack_64.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index e71c98d..8e4f1d0 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -143,13 +143,16 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data)
{
- const unsigned cpu = get_cpu();
- unsigned long *irq_stack_end =
- (unsigned long *)per_cpu(irq_stack_ptr, cpu);
+ unsigned long *irq_stack_end;
unsigned used = 0;
struct thread_info *tinfo;
int graph = 0;
unsigned long dummy;
+ int cpu;
+
+ preempt_disable();
+
+ cpu = smp_processor_id();

if (!task)
task = current;
@@ -168,6 +171,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
* exceptions
*/
tinfo = task_thread_info(task);
+ irq_stack_end = (unsigned long *)__get_cpu_var(irq_stack_ptr);
for (;;) {
char *id;
unsigned long *estack_end;
@@ -219,7 +223,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
* This handles the process stack:
*/
bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
- put_cpu();
+
+ /* We want stacktrace to be computable anywhere, even in the scheduler */
+ preempt_enable_no_resched();
}
EXPORT_SYMBOL(dump_trace);

--
1.7.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/