Skip to content

Commit 82a592c

Browse files
madvenka786willdeacon
authored andcommitted
arm64: Copy the task argument to unwind_state
Copy the task argument passed to arch_stack_walk() to unwind_state so that it can be passed to unwind functions via unwind_state rather than as a separate argument. The task is a fundamental part of the unwind state. Signed-off-by: Madhavan T. Venkataraman <[email protected]> Reviewed-by: Mark Brown <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent a019d8a commit 82a592c

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

arch/arm64/kernel/stacktrace.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* @kr_cur: When KRETPROBES is selected, holds the kretprobe instance
3939
* associated with the most recently encountered replacement lr
4040
* value.
41+
*
42+
* @task: The task being unwound.
4143
*/
4244
struct unwind_state {
4345
unsigned long fp;
@@ -48,10 +50,13 @@ struct unwind_state {
4850
#ifdef CONFIG_KRETPROBES
4951
struct llist_node *kr_cur;
5052
#endif
53+
struct task_struct *task;
5154
};
5255

53-
static void unwind_init_common(struct unwind_state *state)
56+
static void unwind_init_common(struct unwind_state *state,
57+
struct task_struct *task)
5458
{
59+
state->task = task;
5560
#ifdef CONFIG_KRETPROBES
5661
state->kr_cur = NULL;
5762
#endif
@@ -80,7 +85,7 @@ static void unwind_init_common(struct unwind_state *state)
8085
static inline void unwind_init_from_regs(struct unwind_state *state,
8186
struct pt_regs *regs)
8287
{
83-
unwind_init_common(state);
88+
unwind_init_common(state, current);
8489

8590
state->fp = regs->regs[29];
8691
state->pc = regs->pc;
@@ -96,7 +101,7 @@ static inline void unwind_init_from_regs(struct unwind_state *state,
96101
*/
97102
static __always_inline void unwind_init_from_caller(struct unwind_state *state)
98103
{
99-
unwind_init_common(state);
104+
unwind_init_common(state, current);
100105

101106
state->fp = (unsigned long)__builtin_frame_address(1);
102107
state->pc = (unsigned long)__builtin_return_address(0);
@@ -115,7 +120,7 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state)
115120
static inline void unwind_init_from_task(struct unwind_state *state,
116121
struct task_struct *task)
117122
{
118-
unwind_init_common(state);
123+
unwind_init_common(state, task);
119124

120125
state->fp = thread_saved_fp(task);
121126
state->pc = thread_saved_pc(task);
@@ -128,9 +133,9 @@ static inline void unwind_init_from_task(struct unwind_state *state,
128133
* records (e.g. a cycle), determined based on the location and fp value of A
129134
* and the location (but not the fp value) of B.
130135
*/
131-
static int notrace unwind_next(struct task_struct *tsk,
132-
struct unwind_state *state)
136+
static int notrace unwind_next(struct unwind_state *state)
133137
{
138+
struct task_struct *tsk = state->task;
134139
unsigned long fp = state->fp;
135140
struct stack_info info;
136141

@@ -204,16 +209,15 @@ static int notrace unwind_next(struct task_struct *tsk,
204209
}
205210
NOKPROBE_SYMBOL(unwind_next);
206211

207-
static void notrace unwind(struct task_struct *tsk,
208-
struct unwind_state *state,
212+
static void notrace unwind(struct unwind_state *state,
209213
stack_trace_consume_fn consume_entry, void *cookie)
210214
{
211215
while (1) {
212216
int ret;
213217

214218
if (!consume_entry(cookie, state->pc))
215219
break;
216-
ret = unwind_next(tsk, state);
220+
ret = unwind_next(state);
217221
if (ret < 0)
218222
break;
219223
}
@@ -259,12 +263,15 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry,
259263
{
260264
struct unwind_state state;
261265

262-
if (regs)
266+
if (regs) {
267+
if (task != current)
268+
return;
263269
unwind_init_from_regs(&state, regs);
264-
else if (task == current)
270+
} else if (task == current) {
265271
unwind_init_from_caller(&state);
266-
else
272+
} else {
267273
unwind_init_from_task(&state, task);
274+
}
268275

269-
unwind(task, &state, consume_entry, cookie);
276+
unwind(&state, consume_entry, cookie);
270277
}

0 commit comments

Comments
 (0)