Skip to content

Commit d9ef13f

Browse files
Xu KuohaiAlexei Starovoitov
authored andcommitted
bpf: Pass bpf_verifier_env to JIT
Pass bpf_verifier_env to bpf_int_jit_compile(). The follow-up patch will use env->insn_aux_data in the JIT stage to detect indirect jump targets. Since bpf_prog_select_runtime() can be called by cbpf and lib/test_bpf.c code without verifier, introduce helper __bpf_prog_select_runtime() to accept the env parameter. Remove the call to bpf_prog_select_runtime() in bpf_prog_load(), and switch to call __bpf_prog_select_runtime() in the verifier, with env variable passed. The original bpf_prog_select_runtime() is preserved for cbpf and lib/test_bpf.c, where env is NULL. Now all constants blinding calls are moved into the verifier, except the cbpf and lib/test_bpf.c cases. The instructions arrays are adjusted by bpf_patch_insn_data() function for normal cases, so there is no need to call adjust_insn_arrays() in bpf_jit_blind_constants(). Remove it. Reviewed-by: Anton Protopopov <a.s.protopopov@gmail.com> # v8 Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> # v12 Acked-by: Hengqi Chen <hengqi.chen@gmail.com> # v14 Signed-off-by: Xu Kuohai <xukuohai@huawei.com> Link: https://lore.kernel.org/r/20260416064341.151802-3-xukuohai@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent d3e9452 commit d9ef13f

17 files changed

Lines changed: 84 additions & 71 deletions

File tree

arch/arc/net/bpf_jit_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ static struct bpf_prog *do_extra_pass(struct bpf_prog *prog)
14001400
* (re)locations involved that their addresses are not known
14011401
* during the first run.
14021402
*/
1403-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
1403+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
14041404
{
14051405
vm_dump(prog);
14061406

arch/arm/net/bpf_jit_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ bool bpf_jit_needs_zext(void)
21422142
return true;
21432143
}
21442144

2145-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
2145+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
21462146
{
21472147
struct bpf_binary_header *header;
21482148
struct jit_ctx ctx;

arch/arm64/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ struct arm64_jit_data {
20002000
struct jit_ctx ctx;
20012001
};
20022002

2003-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
2003+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
20042004
{
20052005
int image_size, prog_size, extable_size, extable_align, extable_offset;
20062006
struct bpf_binary_header *header;

arch/loongarch/net/bpf_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
19201920
return ret < 0 ? ret : ret * LOONGARCH_INSN_SIZE;
19211921
}
19221922

1923-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
1923+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
19241924
{
19251925
bool extra_pass = false;
19261926
u8 *image_ptr, *ro_image_ptr;

arch/mips/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ bool bpf_jit_needs_zext(void)
909909
return true;
910910
}
911911

912-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
912+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
913913
{
914914
struct bpf_binary_header *header = NULL;
915915
struct jit_context ctx;

arch/parisc/net/bpf_jit_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool bpf_jit_needs_zext(void)
4141
return true;
4242
}
4343

44-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
44+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
4545
{
4646
unsigned int prog_size = 0, extable_size = 0;
4747
bool extra_pass = false;

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static void priv_stack_check_guard(void __percpu *priv_stack_ptr, int alloc_size
162162
}
163163
}
164164

165-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
165+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *fp)
166166
{
167167
u32 proglen;
168168
u32 alloclen;

arch/riscv/net/bpf_jit_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool bpf_jit_needs_zext(void)
4141
return true;
4242
}
4343

44-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
44+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
4545
{
4646
unsigned int prog_size = 0, extable_size = 0;
4747
bool extra_pass = false;

arch/s390/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ static struct bpf_binary_header *bpf_jit_alloc(struct bpf_jit *jit,
23122312
/*
23132313
* Compile eBPF program "fp"
23142314
*/
2315-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
2315+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *fp)
23162316
{
23172317
struct bpf_binary_header *header;
23182318
struct s390_jit_data *jit_data;

arch/sparc/net/bpf_jit_comp_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ struct sparc64_jit_data {
14771477
struct jit_ctx ctx;
14781478
};
14791479

1480-
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
1480+
struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
14811481
{
14821482
struct sparc64_jit_data *jit_data;
14831483
struct bpf_binary_header *header;

0 commit comments

Comments
 (0)