Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Abhishek Dubey and committed by
Madhavan Srinivasan
b1c24f08 88cb7f40

+41
+41
arch/powerpc/net/bpf_jit_comp64.c
··· 247 247 bpf_jit_build_fentry_stubs(image, ctx); 248 248 } 249 249 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 + 250 291 int bpf_jit_emit_func_call_rel(u32 *image, u32 *fimage, struct codegen_context *ctx, u64 func) 251 292 { 252 293 unsigned long func_addr = func ? ppc_function_entry((void *)func) : 0;