Skip to content

Commit 9383191

Browse files
borkmanndavem330
authored andcommitted
bpf: remove stubs for cBPF from arch code
Remove the dummy bpf_jit_compile() stubs for eBPF JITs and make that a single __weak function in the core that can be overridden similarly to the eBPF one. Also remove stale pr_err() mentions of bpf_jit_compile. Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c78f8bd commit 9383191

File tree

6 files changed

+14
-27
lines changed

6 files changed

+14
-27
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,6 @@ static inline void bpf_flush_icache(void *start, void *end)
813813
flush_icache_range((unsigned long)start, (unsigned long)end);
814814
}
815815

816-
void bpf_jit_compile(struct bpf_prog *prog)
817-
{
818-
/* Nothing to do here. We support Internal BPF. */
819-
}
820-
821816
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
822817
{
823818
struct bpf_prog *tmp, *orig_prog = prog;

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,6 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
961961
return 0;
962962
}
963963

964-
void bpf_jit_compile(struct bpf_prog *fp) { }
965-
966964
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
967965
{
968966
u32 proglen;

arch/s390/net/bpf_jit_comp.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,14 +1262,6 @@ static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp)
12621262
return 0;
12631263
}
12641264

1265-
/*
1266-
* Classic BPF function stub. BPF programs will be converted into
1267-
* eBPF and then bpf_int_jit_compile() will be called.
1268-
*/
1269-
void bpf_jit_compile(struct bpf_prog *fp)
1270-
{
1271-
}
1272-
12731265
/*
12741266
* Compile eBPF program "fp"
12751267
*/

arch/x86/net/bpf_jit_comp.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,13 @@ xadd: if (is_imm8(insn->off))
10671067

10681068
ilen = prog - temp;
10691069
if (ilen > BPF_MAX_INSN_SIZE) {
1070-
pr_err("bpf_jit_compile fatal insn size error\n");
1070+
pr_err("bpf_jit: fatal insn size error\n");
10711071
return -EFAULT;
10721072
}
10731073

10741074
if (image) {
10751075
if (unlikely(proglen + ilen > oldproglen)) {
1076-
pr_err("bpf_jit_compile fatal error\n");
1076+
pr_err("bpf_jit: fatal error\n");
10771077
return -EFAULT;
10781078
}
10791079
memcpy(image + proglen, temp, ilen);
@@ -1085,10 +1085,6 @@ xadd: if (is_imm8(insn->off))
10851085
return proglen;
10861086
}
10871087

1088-
void bpf_jit_compile(struct bpf_prog *prog)
1089-
{
1090-
}
1091-
10921088
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
10931089
{
10941090
struct bpf_binary_header *header = NULL;

include/linux/filter.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp);
607607
u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
608608

609609
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog);
610+
void bpf_jit_compile(struct bpf_prog *prog);
610611
bool bpf_helper_changes_pkt_data(void *func);
611612

612613
struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
@@ -625,7 +626,6 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
625626
bpf_jit_fill_hole_t bpf_fill_ill_insns);
626627
void bpf_jit_binary_free(struct bpf_binary_header *hdr);
627628

628-
void bpf_jit_compile(struct bpf_prog *fp);
629629
void bpf_jit_free(struct bpf_prog *fp);
630630

631631
struct bpf_prog *bpf_jit_blind_constants(struct bpf_prog *fp);
@@ -669,10 +669,6 @@ static inline bool bpf_jit_blinding_enabled(void)
669669
return true;
670670
}
671671
#else
672-
static inline void bpf_jit_compile(struct bpf_prog *fp)
673-
{
674-
}
675-
676672
static inline void bpf_jit_free(struct bpf_prog *fp)
677673
{
678674
bpf_prog_unlock_free(fp);

kernel/bpf/core.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,12 +1154,22 @@ const struct bpf_func_proto bpf_tail_call_proto = {
11541154
.arg3_type = ARG_ANYTHING,
11551155
};
11561156

1157-
/* For classic BPF JITs that don't implement bpf_int_jit_compile(). */
1157+
/* Stub for JITs that only support cBPF. eBPF programs are interpreted.
1158+
* It is encouraged to implement bpf_int_jit_compile() instead, so that
1159+
* eBPF and implicitly also cBPF can get JITed!
1160+
*/
11581161
struct bpf_prog * __weak bpf_int_jit_compile(struct bpf_prog *prog)
11591162
{
11601163
return prog;
11611164
}
11621165

1166+
/* Stub for JITs that support eBPF. All cBPF code gets transformed into
1167+
* eBPF by the kernel and is later compiled by bpf_int_jit_compile().
1168+
*/
1169+
void __weak bpf_jit_compile(struct bpf_prog *prog)
1170+
{
1171+
}
1172+
11631173
bool __weak bpf_helper_changes_pkt_data(void *func)
11641174
{
11651175
return false;

0 commit comments

Comments
 (0)