Skip to content

Commit b1c24f0

Browse files
Abhishek Dubeymaddy-kerneldev
authored andcommitted
powerpc64/bpf: Add arch_bpf_stack_walk() for BPF JIT
This function is used by bpf_throw() to unwind the stack until frame of exception-boundary during BPF exception handling. This function is necessary to support BPF exceptions on PowerPC. Signed-off-by: Abhishek Dubey <adubey@linux.ibm.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/20260124075223.6033-5-adubey@linux.ibm.com
1 parent 88cb7f4 commit b1c24f0

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,47 @@ void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
247247
bpf_jit_build_fentry_stubs(image, ctx);
248248
}
249249

250+
/*
251+
* arch_bpf_stack_walk() - BPF stack walker for PowerPC
252+
*
253+
* Based on arch_stack_walk() from stacktrace.c.
254+
* PowerPC uses stack frames rather than stack pointers. See [1] for
255+
* the equivalence between frame pointers and stack pointers.
256+
* Additional reference at [2].
257+
* TODO: refactor with arch_stack_walk()
258+
*
259+
* [1]: https://lore.kernel.org/all/20200220115141.2707-1-mpe@ellerman.id.au/
260+
* [2]: https://lore.kernel.org/bpf/20260122211854.5508-5-adubey@linux.ibm.com/
261+
*/
262+
263+
void arch_bpf_stack_walk(bool (*consume_fn)(void *, u64, u64, u64), void *cookie)
264+
{
265+
// callback processing always in current context
266+
unsigned long sp = current_stack_frame();
267+
268+
for (;;) {
269+
unsigned long *stack = (unsigned long *) sp;
270+
unsigned long ip;
271+
272+
if (!validate_sp(sp, current))
273+
return;
274+
275+
ip = stack[STACK_FRAME_LR_SAVE];
276+
if (!ip)
277+
break;
278+
279+
/*
280+
* consume_fn common code expects stack pointer in third
281+
* argument. There is no sp in ppc64, rather pass frame
282+
* pointer(named sp here).
283+
*/
284+
if (ip && !consume_fn(cookie, ip, sp, sp))
285+
break;
286+
287+
sp = stack[0];
288+
}
289+
}
290+
250291
int bpf_jit_emit_func_call_rel(u32 *image, u32 *fimage, struct codegen_context *ctx, u64 func)
251292
{
252293
unsigned long func_addr = func ? ppc_function_entry((void *)func) : 0;

0 commit comments

Comments
 (0)