Skip to content

Commit 5bc27dc

Browse files
fenrus75Ingo Molnar
authored andcommitted
x86: pull bp calculation earlier into the backtrace path
Right now, we take the stack pointer early during the backtrace path, but only calculate bp several functions deep later, making it hard to reconcile the stack and bp backtraces (as well as showing several internal backtrace functions on the stack with bp based backtracing). This patch moves the bp taking to the same place we take the stack pointer; sadly this ripples through several layers of the back tracing stack, but it's not all that bad in the end I hope. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent e9d4efd commit 5bc27dc

4 files changed

Lines changed: 23 additions & 27 deletions

File tree

‎arch/x86/kernel/process_32.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void __show_registers(struct pt_regs *regs, int all)
379379
void show_regs(struct pt_regs *regs)
380380
{
381381
__show_registers(regs, 1);
382-
show_trace(NULL, regs, &regs->sp);
382+
show_trace(NULL, regs, &regs->sp, regs->bp);
383383
}
384384

385385
/*

‎arch/x86/kernel/stacktrace.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ static void save_stack_address(void *data, unsigned long addr, int reliable)
3333
trace->entries[trace->nr_entries++] = addr;
3434
}
3535

36-
static void save_stack_address_nosched(void *data, unsigned long addr)
36+
static void
37+
save_stack_address_nosched(void *data, unsigned long addr, int reliable)
3738
{
3839
struct stack_trace *trace = (struct stack_trace *)data;
3940
if (in_sched_functions(addr))
@@ -65,14 +66,14 @@ static const struct stacktrace_ops save_stack_ops_nosched = {
6566
*/
6667
void save_stack_trace(struct stack_trace *trace)
6768
{
68-
dump_trace(current, NULL, NULL, &save_stack_ops, trace);
69+
dump_trace(current, NULL, NULL, 0, &save_stack_ops, trace);
6970
if (trace->nr_entries < trace->max_entries)
7071
trace->entries[trace->nr_entries++] = ULONG_MAX;
7172
}
7273

7374
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
7475
{
75-
dump_trace(tsk, NULL, NULL, &save_stack_ops_nosched, trace);
76+
dump_trace(tsk, NULL, NULL, 0, &save_stack_ops_nosched, trace);
7677
if (trace->nr_entries < trace->max_entries)
7778
trace->entries[trace->nr_entries++] = ULONG_MAX;
7879
}

‎arch/x86/kernel/traps_32.c‎

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,6 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
120120
{
121121
struct stack_frame *frame = (struct stack_frame *)bp;
122122

123-
/*
124-
* if EBP is "deeper" into the stack than the actual stack pointer,
125-
* we need to rewind the stack pointer a little to start at the
126-
* first stack frame, but only if EBP is in this stack frame.
127-
*/
128-
if (stack > (unsigned long *) bp
129-
&& valid_stack_ptr(tinfo, frame, sizeof(*frame)))
130-
stack = (unsigned long *) bp;
131-
132123
while (valid_stack_ptr(tinfo, stack, sizeof(*stack))) {
133124
unsigned long addr;
134125

@@ -139,7 +130,7 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
139130
frame = frame->next_frame;
140131
bp = (unsigned long) frame;
141132
} else {
142-
ops->address(data, addr, 0);
133+
ops->address(data, addr, bp == 0);
143134
}
144135
}
145136
stack++;
@@ -150,11 +141,9 @@ static inline unsigned long print_context_stack(struct thread_info *tinfo,
150141
#define MSG(msg) ops->warning(data, msg)
151142

152143
void dump_trace(struct task_struct *task, struct pt_regs *regs,
153-
unsigned long *stack,
144+
unsigned long *stack, unsigned long bp,
154145
const struct stacktrace_ops *ops, void *data)
155146
{
156-
unsigned long bp = 0;
157-
158147
if (!task)
159148
task = current;
160149

@@ -234,20 +223,20 @@ static const struct stacktrace_ops print_trace_ops = {
234223

235224
static void
236225
show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
237-
unsigned long * stack, char *log_lvl)
226+
unsigned long *stack, unsigned long bp, char *log_lvl)
238227
{
239-
dump_trace(task, regs, stack, &print_trace_ops, log_lvl);
228+
dump_trace(task, regs, stack, bp, &print_trace_ops, log_lvl);
240229
printk("%s =======================\n", log_lvl);
241230
}
242231

243232
void show_trace(struct task_struct *task, struct pt_regs *regs,
244-
unsigned long * stack)
233+
unsigned long *stack, unsigned long bp)
245234
{
246-
show_trace_log_lvl(task, regs, stack, "");
235+
show_trace_log_lvl(task, regs, stack, bp, "");
247236
}
248237

249238
static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
250-
unsigned long *sp, char *log_lvl)
239+
unsigned long *sp, unsigned long bp, char *log_lvl)
251240
{
252241
unsigned long *stack;
253242
int i;
@@ -268,13 +257,13 @@ static void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
268257
printk("%08lx ", *stack++);
269258
}
270259
printk("\n%sCall Trace:\n", log_lvl);
271-
show_trace_log_lvl(task, regs, sp, log_lvl);
260+
show_trace_log_lvl(task, regs, sp, bp, log_lvl);
272261
}
273262

274263
void show_stack(struct task_struct *task, unsigned long *sp)
275264
{
276265
printk(" ");
277-
show_stack_log_lvl(task, NULL, sp, "");
266+
show_stack_log_lvl(task, NULL, sp, 0, "");
278267
}
279268

280269
/*
@@ -283,13 +272,19 @@ void show_stack(struct task_struct *task, unsigned long *sp)
283272
void dump_stack(void)
284273
{
285274
unsigned long stack;
275+
unsigned long bp = 0;
276+
277+
#ifdef CONFIG_FRAME_POINTER
278+
if (!bp)
279+
asm("movl %%ebp, %0" : "=r" (bp):);
280+
#endif
286281

287282
printk("Pid: %d, comm: %.20s %s %s %.*s\n",
288283
current->pid, current->comm, print_tainted(),
289284
init_utsname()->release,
290285
(int)strcspn(init_utsname()->version, " "),
291286
init_utsname()->version);
292-
show_trace(current, NULL, &stack);
287+
show_trace(current, NULL, &stack, bp);
293288
}
294289

295290
EXPORT_SYMBOL(dump_stack);
@@ -314,7 +309,7 @@ void show_registers(struct pt_regs *regs)
314309
unsigned char c;
315310

316311
printk("\n" KERN_EMERG "Stack: ");
317-
show_stack_log_lvl(NULL, regs, &regs->sp, KERN_EMERG);
312+
show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
318313

319314
printk(KERN_EMERG "Code: ");
320315

‎arch/x86/oprofile/backtrace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
8181

8282
if (!user_mode_vm(regs)) {
8383
if (depth)
84-
dump_trace(NULL, regs, (unsigned long *)stack,
84+
dump_trace(NULL, regs, (unsigned long *)stack, 0,
8585
&backtrace_ops, &depth);
8686
return;
8787
}

0 commit comments

Comments
 (0)