Skip to content

Commit 1aba06e

Browse files
Mark Rutlandwilldeacon
Mark Rutland
authored andcommitted
arm64: stacktrace: factor out kunwind_stack_walk()
Currently arm64 uses the generic arch_stack_walk() interface for all stack walking code. This only passes a PC value and cookie to the unwind callback, whereas we'd like to pass some additional information in some cases. For example, the BPF exception unwinder wants the FP, for reliable stacktrace we'll want to perform additional checks on other portions of unwind state, and we'd like to expand the information printed by dump_backtrace() to include provenance and reliability information. As preparation for all of the above, this patch factors the core unwind logic out of arch_stack_walk() and into a new kunwind_stack_walk() function which provides all of the unwind state to a callback function. The existing arch_stack_walk() interface is implemented atop this. The kunwind_stack_walk() function is intended to be a private implementation detail of unwinders in stacktrace.c, and not something to be exported generally to kernel code. It is __always_inline'd into its caller so that neither it or its caller appear in stactraces (which is the existing/required behavior for arch_stack_walk() and friends) and so that the compiler can optimize away some of the indirection. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Kalesh Singh <[email protected]> Cc: Madhavan T. Venkataraman <[email protected]> Cc: Mark Brown <[email protected]> Cc: Puranjay Mohan <[email protected]> Cc: Will Deacon <[email protected]> Reviewed-by: Kalesh Singh <[email protected]> Reviewed-by: Puranjay Mohan <[email protected]> Reviewed-by: Madhavan T. Venkataraman <[email protected]> Reviewed-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 1beef60 commit 1aba06e

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

arch/arm64/kernel/stacktrace.c

+33-6
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ kunwind_next(struct kunwind_state *state)
154154
return kunwind_recover_return_address(state);
155155
}
156156

157+
typedef bool (*kunwind_consume_fn)(const struct kunwind_state *state, void *cookie);
158+
157159
static __always_inline void
158-
do_kunwind(struct kunwind_state *state, stack_trace_consume_fn consume_entry,
160+
do_kunwind(struct kunwind_state *state, kunwind_consume_fn consume_state,
159161
void *cookie)
160162
{
161163
if (kunwind_recover_return_address(state))
@@ -164,7 +166,7 @@ do_kunwind(struct kunwind_state *state, stack_trace_consume_fn consume_entry,
164166
while (1) {
165167
int ret;
166168

167-
if (!consume_entry(cookie, state->common.pc))
169+
if (!consume_state(state, cookie))
168170
break;
169171
ret = kunwind_next(state);
170172
if (ret < 0)
@@ -201,9 +203,10 @@ do_kunwind(struct kunwind_state *state, stack_trace_consume_fn consume_entry,
201203
: stackinfo_get_unknown(); \
202204
})
203205

204-
noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,
205-
void *cookie, struct task_struct *task,
206-
struct pt_regs *regs)
206+
static __always_inline void
207+
kunwind_stack_walk(kunwind_consume_fn consume_state,
208+
void *cookie, struct task_struct *task,
209+
struct pt_regs *regs)
207210
{
208211
struct stack_info stacks[] = {
209212
stackinfo_get_task(task),
@@ -236,7 +239,31 @@ noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,
236239
kunwind_init_from_task(&state, task);
237240
}
238241

239-
do_kunwind(&state, consume_entry, cookie);
242+
do_kunwind(&state, consume_state, cookie);
243+
}
244+
245+
struct kunwind_consume_entry_data {
246+
stack_trace_consume_fn consume_entry;
247+
void *cookie;
248+
};
249+
250+
static bool
251+
arch_kunwind_consume_entry(const struct kunwind_state *state, void *cookie)
252+
{
253+
struct kunwind_consume_entry_data *data = cookie;
254+
return data->consume_entry(data->cookie, state->common.pc);
255+
}
256+
257+
noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,
258+
void *cookie, struct task_struct *task,
259+
struct pt_regs *regs)
260+
{
261+
struct kunwind_consume_entry_data data = {
262+
.consume_entry = consume_entry,
263+
.cookie = cookie,
264+
};
265+
266+
kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, regs);
240267
}
241268

242269
static bool dump_backtrace_entry(void *arg, unsigned long where)

0 commit comments

Comments
 (0)