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: Support exceptions

The modified prologue/epilogue generation code now
enables exception-callback to use the stack frame of
the program marked as exception boundary, where callee
saved registers are stored.

As per ppc64 ABIv2 documentation[1], r14-r31 are callee
saved registers. BPF programs on ppc64 already saves
r26-r31 registers. Saving the remaining set of callee
saved registers(r14-r25) is handled in the next patch.

[1] https://ftp.rtems.org/pub/rtems/people/sebh/ABI64BitOpenPOWERv1.1_16July2015_pub.pdf

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-6-adubey@linux.ibm.com

authored by

Abhishek Dubey and committed by
Madhavan Srinivasan
c1699302 b1c24f08

+50 -18
+2
arch/powerpc/net/bpf_jit.h
··· 179 179 u64 arena_vm_start; 180 180 u64 user_vm_start; 181 181 bool is_subprog; 182 + bool exception_boundary; 183 + bool exception_cb; 182 184 }; 183 185 184 186 #define bpf_to_ppc(r) (ctx->b2p[r])
+7
arch/powerpc/net/bpf_jit_comp.c
··· 207 207 cgctx.arena_vm_start = bpf_arena_get_kern_vm_start(fp->aux->arena); 208 208 cgctx.user_vm_start = bpf_arena_get_user_vm_start(fp->aux->arena); 209 209 cgctx.is_subprog = bpf_is_subprog(fp); 210 + cgctx.exception_boundary = fp->aux->exception_boundary; 211 + cgctx.exception_cb = fp->aux->exception_cb; 210 212 211 213 /* Scouting faux-generate pass 0 */ 212 214 if (bpf_jit_build_body(fp, NULL, NULL, &cgctx, addrs, 0, false)) { ··· 436 434 } 437 435 438 436 bpf_prog_unlock_free(fp); 437 + } 438 + 439 + bool bpf_jit_supports_exceptions(void) 440 + { 441 + return IS_ENABLED(CONFIG_PPC64); 439 442 } 440 443 441 444 bool bpf_jit_supports_subprog_tailcalls(void)
+41 -18
arch/powerpc/net/bpf_jit_comp64.c
··· 89 89 * - the bpf program uses its stack area 90 90 * The latter condition is deduced from the usage of BPF_REG_FP 91 91 */ 92 - return ctx->seen & SEEN_FUNC || bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_FP)); 92 + return ctx->seen & SEEN_FUNC || 93 + bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_FP)) || 94 + ctx->exception_cb; 93 95 } 94 96 95 97 /* ··· 163 161 EMIT(PPC_RAW_LI(bpf_to_ppc(TMP_REG_1), 0)); 164 162 /* this goes in the redzone */ 165 163 EMIT(PPC_RAW_STD(bpf_to_ppc(TMP_REG_1), _R1, -(BPF_PPC_TAILCALL))); 166 - } else { 164 + } else if (!ctx->exception_cb) { 167 165 /* 166 + * Tailcall jitting for non exception_cb progs only. 167 + * exception_cb won't require tail_call_info to be setup. 168 + * 169 + * tail_call_info interpretation logic: 170 + * 168 171 * if tail_call_info < MAX_TAIL_CALL_CNT 169 172 * main prog calling first subprog -> copy reference 170 173 * else ··· 184 177 EMIT(PPC_RAW_STD(bpf_to_ppc(TMP_REG_1), _R1, -(BPF_PPC_TAILCALL))); 185 178 } 186 179 187 - if (bpf_has_stack_frame(ctx)) { 180 + if (bpf_has_stack_frame(ctx) && !ctx->exception_cb) { 188 181 /* 182 + * exception_cb uses boundary frame after stack walk. 183 + * It can simply use redzone, this optimization reduces 184 + * stack walk loop by one level. 185 + * 189 186 * We need a stack frame, but we don't necessarily need to 190 187 * save/restore LR unless we call other functions 191 188 */ ··· 201 190 EMIT(PPC_RAW_STDU(_R1, _R1, -(BPF_PPC_STACKFRAME + ctx->stack_size))); 202 191 } 203 192 204 - /* 205 - * Back up non-volatile regs -- BPF registers 6-10 206 - * If we haven't created our own stack frame, we save these 207 - * in the protected zone below the previous stack frame 208 - */ 209 - for (i = BPF_REG_6; i <= BPF_REG_10; i++) 210 - if (bpf_is_seen_register(ctx, bpf_to_ppc(i))) 211 - EMIT(PPC_RAW_STD(bpf_to_ppc(i), _R1, bpf_jit_stack_offsetof(ctx, bpf_to_ppc(i)))); 193 + if (!ctx->exception_cb) { 194 + /* 195 + * Back up non-volatile regs -- BPF registers 6-10 196 + * If we haven't created our own stack frame, we save these 197 + * in the protected zone below the previous stack frame 198 + */ 199 + for (i = BPF_REG_6; i <= BPF_REG_10; i++) 200 + if (ctx->exception_boundary || bpf_is_seen_register(ctx, bpf_to_ppc(i))) 201 + EMIT(PPC_RAW_STD(bpf_to_ppc(i), _R1, 202 + bpf_jit_stack_offsetof(ctx, bpf_to_ppc(i)))); 212 203 213 - if (ctx->arena_vm_start) 214 - EMIT(PPC_RAW_STD(bpf_to_ppc(ARENA_VM_START), _R1, 204 + if (ctx->exception_boundary || ctx->arena_vm_start) 205 + EMIT(PPC_RAW_STD(bpf_to_ppc(ARENA_VM_START), _R1, 215 206 bpf_jit_stack_offsetof(ctx, bpf_to_ppc(ARENA_VM_START)))); 207 + } else { 208 + /* 209 + * Exception callback receives Frame Pointer of boundary 210 + * program(main prog) as third arg 211 + */ 212 + EMIT(PPC_RAW_MR(_R1, _R5)); 213 + } 216 214 217 - /* Setup frame pointer to point to the bpf stack area */ 215 + /* 216 + * Exception_cb not restricted from using stack area or arena. 217 + * Setup frame pointer to point to the bpf stack area 218 + */ 218 219 if (bpf_is_seen_register(ctx, bpf_to_ppc(BPF_REG_FP))) 219 220 EMIT(PPC_RAW_ADDI(bpf_to_ppc(BPF_REG_FP), _R1, 220 - STACK_FRAME_MIN_SIZE + ctx->stack_size)); 221 + STACK_FRAME_MIN_SIZE + ctx->stack_size)); 221 222 222 223 if (ctx->arena_vm_start) 223 224 PPC_LI64(bpf_to_ppc(ARENA_VM_START), ctx->arena_vm_start); ··· 241 218 242 219 /* Restore NVRs */ 243 220 for (i = BPF_REG_6; i <= BPF_REG_10; i++) 244 - if (bpf_is_seen_register(ctx, bpf_to_ppc(i))) 221 + if (ctx->exception_cb || bpf_is_seen_register(ctx, bpf_to_ppc(i))) 245 222 EMIT(PPC_RAW_LD(bpf_to_ppc(i), _R1, bpf_jit_stack_offsetof(ctx, bpf_to_ppc(i)))); 246 223 247 - if (ctx->arena_vm_start) 224 + if (ctx->exception_cb || ctx->arena_vm_start) 248 225 EMIT(PPC_RAW_LD(bpf_to_ppc(ARENA_VM_START), _R1, 249 226 bpf_jit_stack_offsetof(ctx, bpf_to_ppc(ARENA_VM_START)))); 250 227 251 228 /* Tear down our stack frame */ 252 229 if (bpf_has_stack_frame(ctx)) { 253 230 EMIT(PPC_RAW_ADDI(_R1, _R1, BPF_PPC_STACKFRAME + ctx->stack_size)); 254 - if (ctx->seen & SEEN_FUNC) { 231 + if (ctx->seen & SEEN_FUNC || ctx->exception_cb) { 255 232 EMIT(PPC_RAW_LD(_R0, _R1, PPC_LR_STKOFF)); 256 233 EMIT(PPC_RAW_MTLR(_R0)); 257 234 }