Skip to content

Commit e74cb1b

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
arm64: stacktrace: Implement arch_bpf_stack_walk() for the BPF JIT
This will be used by bpf_throw() to unwind till the program marked as exception boundary and run the callback with the stack of the main program. This is required for supporting BPF exceptions on ARM64. Signed-off-by: Puranjay Mohan <puranjay12@gmail.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/20240201125225.72796-2-puranjay12@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 2ab256e commit e74cb1b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

arch/arm64/kernel/stacktrace.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/kernel.h>
88
#include <linux/efi.h>
99
#include <linux/export.h>
10+
#include <linux/filter.h>
1011
#include <linux/ftrace.h>
1112
#include <linux/kprobes.h>
1213
#include <linux/sched.h>
@@ -266,6 +267,31 @@ noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,
266267
kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, regs);
267268
}
268269

270+
struct bpf_unwind_consume_entry_data {
271+
bool (*consume_entry)(void *cookie, u64 ip, u64 sp, u64 fp);
272+
void *cookie;
273+
};
274+
275+
static bool
276+
arch_bpf_unwind_consume_entry(const struct kunwind_state *state, void *cookie)
277+
{
278+
struct bpf_unwind_consume_entry_data *data = cookie;
279+
280+
return data->consume_entry(data->cookie, state->common.pc, 0,
281+
state->common.fp);
282+
}
283+
284+
noinline noinstr void arch_bpf_stack_walk(bool (*consume_entry)(void *cookie, u64 ip, u64 sp,
285+
u64 fp), void *cookie)
286+
{
287+
struct bpf_unwind_consume_entry_data data = {
288+
.consume_entry = consume_entry,
289+
.cookie = cookie,
290+
};
291+
292+
kunwind_stack_walk(arch_bpf_unwind_consume_entry, &data, current, NULL);
293+
}
294+
269295
static bool dump_backtrace_entry(void *arg, unsigned long where)
270296
{
271297
char *loglvl = arg;

0 commit comments

Comments
 (0)