Skip to content

Commit

Permalink
x86: avoid avoid passing around 'thread_info' in stack dumping code
Browse files Browse the repository at this point in the history
None of the code actually wants a thread_info, it all wants a
task_struct, and it's just converting to a thread_info pointer much too
early.

No semantic change.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Jun 23, 2016
1 parent 6720a30 commit da01e18
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions arch/x86/include/asm/stacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern int kstack_depth_to_print;
struct thread_info;
struct stacktrace_ops;

typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
typedef unsigned long (*walk_stack_t)(struct task_struct *task,
unsigned long *stack,
unsigned long bp,
const struct stacktrace_ops *ops,
Expand All @@ -23,13 +23,13 @@ typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
int *graph);

extern unsigned long
print_context_stack(struct thread_info *tinfo,
print_context_stack(struct task_struct *task,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data,
unsigned long *end, int *graph);

extern unsigned long
print_context_stack_bp(struct thread_info *tinfo,
print_context_stack_bp(struct task_struct *task,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data,
unsigned long *end, int *graph);
Expand Down
22 changes: 10 additions & 12 deletions arch/x86/kernel/dumpstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ void printk_address(unsigned long address)
static void
print_ftrace_graph_addr(unsigned long addr, void *data,
const struct stacktrace_ops *ops,
struct thread_info *tinfo, int *graph)
struct task_struct *task, int *graph)
{
struct task_struct *task;
unsigned long ret_addr;
int index;

if (addr != (unsigned long)return_to_handler)
return;

task = tinfo->task;
index = task->curr_ret_stack;

if (!task->ret_stack || index < *graph)
Expand All @@ -68,7 +66,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
static inline void
print_ftrace_graph_addr(unsigned long addr, void *data,
const struct stacktrace_ops *ops,
struct thread_info *tinfo, int *graph)
struct task_struct *task, int *graph)
{ }
#endif

Expand All @@ -79,10 +77,10 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
* severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
*/

static inline int valid_stack_ptr(struct thread_info *tinfo,
static inline int valid_stack_ptr(struct task_struct *task,
void *p, unsigned int size, void *end)
{
void *t = tinfo;
void *t = task_thread_info(task);
if (end) {
if (p < end && p >= (end-THREAD_SIZE))
return 1;
Expand All @@ -93,14 +91,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
}

unsigned long
print_context_stack(struct thread_info *tinfo,
print_context_stack(struct task_struct *task,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data,
unsigned long *end, int *graph)
{
struct stack_frame *frame = (struct stack_frame *)bp;

while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
while (valid_stack_ptr(task, stack, sizeof(*stack), end)) {
unsigned long addr;

addr = *stack;
Expand All @@ -112,7 +110,7 @@ print_context_stack(struct thread_info *tinfo,
} else {
ops->address(data, addr, 0);
}
print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
print_ftrace_graph_addr(addr, data, ops, task, graph);
}
stack++;
}
Expand All @@ -121,15 +119,15 @@ print_context_stack(struct thread_info *tinfo,
EXPORT_SYMBOL_GPL(print_context_stack);

unsigned long
print_context_stack_bp(struct thread_info *tinfo,
print_context_stack_bp(struct task_struct *task,
unsigned long *stack, unsigned long bp,
const struct stacktrace_ops *ops, void *data,
unsigned long *end, int *graph)
{
struct stack_frame *frame = (struct stack_frame *)bp;
unsigned long *ret_addr = &frame->return_address;

while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
while (valid_stack_ptr(task, ret_addr, sizeof(*ret_addr), end)) {
unsigned long addr = *ret_addr;

if (!__kernel_text_address(addr))
Expand All @@ -139,7 +137,7 @@ print_context_stack_bp(struct thread_info *tinfo,
break;
frame = frame->next_frame;
ret_addr = &frame->return_address;
print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
print_ftrace_graph_addr(addr, data, ops, task, graph);
}

return (unsigned long)frame;
Expand Down
4 changes: 1 addition & 3 deletions arch/x86/kernel/dumpstack_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
bp = stack_frame(task, regs);

for (;;) {
struct thread_info *context;
void *end_stack;

end_stack = is_hardirq_stack(stack, cpu);
if (!end_stack)
end_stack = is_softirq_stack(stack, cpu);

context = task_thread_info(task);
bp = ops->walk_stack(context, stack, bp, ops, data,
bp = ops->walk_stack(task, stack, bp, ops, data,
end_stack, &graph);

/* Stop if not on irq stack */
Expand Down
8 changes: 3 additions & 5 deletions arch/x86/kernel/dumpstack_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
const struct stacktrace_ops *ops, void *data)
{
const unsigned cpu = get_cpu();
struct thread_info *tinfo;
unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
unsigned long dummy;
unsigned used = 0;
Expand All @@ -179,7 +178,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
* current stack address. If the stacks consist of nested
* exceptions
*/
tinfo = task_thread_info(task);
while (!done) {
unsigned long *stack_end;
enum stack_type stype;
Expand All @@ -202,7 +200,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
if (ops->stack(data, id) < 0)
break;

bp = ops->walk_stack(tinfo, stack, bp, ops,
bp = ops->walk_stack(task, stack, bp, ops,
data, stack_end, &graph);
ops->stack(data, "<EOE>");
/*
Expand All @@ -218,7 +216,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,

if (ops->stack(data, "IRQ") < 0)
break;
bp = ops->walk_stack(tinfo, stack, bp,
bp = ops->walk_stack(task, stack, bp,
ops, data, stack_end, &graph);
/*
* We link to the next stack (which would be
Expand All @@ -240,7 +238,7 @@ 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);
bp = ops->walk_stack(task, stack, bp, ops, data, NULL, &graph);
put_cpu();
}
EXPORT_SYMBOL(dump_trace);
Expand Down

0 comments on commit da01e18

Please sign in to comment.