Skip to content

Commit

Permalink
powerpc/bpf: Use bctrl for making function calls
Browse files Browse the repository at this point in the history
blrl corrupts the link stack. Instead use bctrl when making function
calls from BPF programs.

Reported-by: Anton Blanchard <anton@ozlabs.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210609090024.1446800-1-naveen.n.rao@linux.vnet.ibm.com
  • Loading branch information
Naveen N. Rao authored and Michael Ellerman committed Jun 25, 2021
1 parent b8ee3e6 commit 20ccb00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions arch/powerpc/net/bpf_jit_comp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ void bpf_jit_emit_func_call_rel(u32 *image, struct codegen_context *ctx, u64 fun
/* Load function address into r0 */
EMIT(PPC_RAW_LIS(_R0, IMM_H(func)));
EMIT(PPC_RAW_ORI(_R0, _R0, IMM_L(func)));
EMIT(PPC_RAW_MTLR(_R0));
EMIT(PPC_RAW_BLRL());
EMIT(PPC_RAW_MTCTR(_R0));
EMIT(PPC_RAW_BCTRL());
}
}

Expand Down
12 changes: 6 additions & 6 deletions arch/powerpc/net/bpf_jit_comp64.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ static void bpf_jit_emit_func_call_hlp(u32 *image, struct codegen_context *ctx,
PPC_LI64(b2p[TMP_REG_2], func);
/* Load actual entry point from function descriptor */
PPC_BPF_LL(b2p[TMP_REG_1], b2p[TMP_REG_2], 0);
/* ... and move it to LR */
EMIT(PPC_RAW_MTLR(b2p[TMP_REG_1]));
/* ... and move it to CTR */
EMIT(PPC_RAW_MTCTR(b2p[TMP_REG_1]));
/*
* Load TOC from function descriptor at offset 8.
* We can clobber r2 since we get called through a
Expand All @@ -165,9 +165,9 @@ static void bpf_jit_emit_func_call_hlp(u32 *image, struct codegen_context *ctx,
#else
/* We can clobber r12 */
PPC_FUNC_ADDR(12, func);
EMIT(PPC_RAW_MTLR(12));
EMIT(PPC_RAW_MTCTR(12));
#endif
EMIT(PPC_RAW_BLRL());
EMIT(PPC_RAW_BCTRL());
}

void bpf_jit_emit_func_call_rel(u32 *image, struct codegen_context *ctx, u64 func)
Expand Down Expand Up @@ -202,8 +202,8 @@ void bpf_jit_emit_func_call_rel(u32 *image, struct codegen_context *ctx, u64 fun
PPC_BPF_LL(12, 12, 0);
#endif

EMIT(PPC_RAW_MTLR(12));
EMIT(PPC_RAW_BLRL());
EMIT(PPC_RAW_MTCTR(12));
EMIT(PPC_RAW_BCTRL());
}

static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 out)
Expand Down

0 comments on commit 20ccb00

Please sign in to comment.