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

bpf, arm64: save 4 bytes in prologue when ebpf insns came from cbpf

We can trivially save 4 bytes in prologue for cBPF since tail calls
can never be used from there. The register push/pop is pairwise,
here, x25 (fp) and x26 (tcc), so no point in changing that, only
reset to zero is not needed.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Daniel Borkmann and committed by
Alexei Starovoitov
56ea6a8b 6d2eea6f

+13 -10
+13 -10
arch/arm64/net/bpf_jit_comp.c
··· 185 185 /* Tail call offset to jump into */ 186 186 #define PROLOGUE_OFFSET 7 187 187 188 - static int build_prologue(struct jit_ctx *ctx) 188 + static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf) 189 189 { 190 190 const struct bpf_prog *prog = ctx->prog; 191 191 const u8 r6 = bpf2a64[BPF_REG_6]; ··· 232 232 /* Set up BPF prog stack base register */ 233 233 emit(A64_MOV(1, fp, A64_SP), ctx); 234 234 235 - /* Initialize tail_call_cnt */ 236 - emit(A64_MOVZ(1, tcc, 0, 0), ctx); 235 + if (!ebpf_from_cbpf) { 236 + /* Initialize tail_call_cnt */ 237 + emit(A64_MOVZ(1, tcc, 0, 0), ctx); 237 238 238 - cur_offset = ctx->idx - idx0; 239 - if (cur_offset != PROLOGUE_OFFSET) { 240 - pr_err_once("PROLOGUE_OFFSET = %d, expected %d!\n", 241 - cur_offset, PROLOGUE_OFFSET); 242 - return -1; 239 + cur_offset = ctx->idx - idx0; 240 + if (cur_offset != PROLOGUE_OFFSET) { 241 + pr_err_once("PROLOGUE_OFFSET = %d, expected %d!\n", 242 + cur_offset, PROLOGUE_OFFSET); 243 + return -1; 244 + } 243 245 } 244 246 245 247 ctx->stack_size = STACK_ALIGN(prog->aux->stack_depth); ··· 808 806 struct bpf_prog *tmp, *orig_prog = prog; 809 807 struct bpf_binary_header *header; 810 808 struct arm64_jit_data *jit_data; 809 + bool was_classic = bpf_prog_was_classic(prog); 811 810 bool tmp_blinded = false; 812 811 bool extra_pass = false; 813 812 struct jit_ctx ctx; ··· 863 860 goto out_off; 864 861 } 865 862 866 - if (build_prologue(&ctx)) { 863 + if (build_prologue(&ctx, was_classic)) { 867 864 prog = orig_prog; 868 865 goto out_off; 869 866 } ··· 886 883 skip_init_ctx: 887 884 ctx.idx = 0; 888 885 889 - build_prologue(&ctx); 886 + build_prologue(&ctx, was_classic); 890 887 891 888 if (build_body(&ctx)) { 892 889 bpf_jit_binary_free(header);