Skip to content

Commit c4c0bdc

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
bpf: Set the number of exception entries properly for subprograms
Currently, if a bpf program has more than one subprograms, each program will be jitted separately. For programs with bpf-to-bpf calls the prog->aux->num_exentries is not setup properly. For example, with bpf_iter_netlink.c modified to force one function to be not inlined and with CONFIG_BPF_JIT_ALWAYS_ON the following error is seen: $ ./test_progs -n 3/3 ... libbpf: failed to load program 'iter/netlink' libbpf: failed to load object 'bpf_iter_netlink' libbpf: failed to load BPF skeleton 'bpf_iter_netlink': -4007 test_netlink:FAIL:bpf_iter_netlink__open_and_load skeleton open_and_load failed #3/3 netlink:FAIL The dmesg shows the following errors: ex gen bug which is triggered by the following code in arch/x86/net/bpf_jit_comp.c: if (excnt >= bpf_prog->aux->num_exentries) { pr_err("ex gen bug\n"); return -EFAULT; } This patch fixes the issue by computing proper num_exentries for each subprogram before calling JIT. Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 9c82a63 commit c4c0bdc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9801,7 +9801,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
98019801
int i, j, subprog_start, subprog_end = 0, len, subprog;
98029802
struct bpf_insn *insn;
98039803
void *old_bpf_func;
9804-
int err;
9804+
int err, num_exentries;
98059805

98069806
if (env->subprog_cnt <= 1)
98079807
return 0;
@@ -9876,6 +9876,14 @@ static int jit_subprogs(struct bpf_verifier_env *env)
98769876
func[i]->aux->nr_linfo = prog->aux->nr_linfo;
98779877
func[i]->aux->jited_linfo = prog->aux->jited_linfo;
98789878
func[i]->aux->linfo_idx = env->subprog_info[i].linfo_idx;
9879+
num_exentries = 0;
9880+
insn = func[i]->insnsi;
9881+
for (j = 0; j < func[i]->len; j++, insn++) {
9882+
if (BPF_CLASS(insn->code) == BPF_LDX &&
9883+
BPF_MODE(insn->code) == BPF_PROBE_MEM)
9884+
num_exentries++;
9885+
}
9886+
func[i]->aux->num_exentries = num_exentries;
98799887
func[i] = bpf_int_jit_compile(func[i]);
98809888
if (!func[i]->jited) {
98819889
err = -ENOTSUPP;

0 commit comments

Comments
 (0)