Commit d00c6473 authored by Song Liu's avatar Song Liu Committed by Alexei Starovoitov

bpf: Use prog->jited_len in bpf_prog_ksym_set_addr()

Using prog->jited_len is simpler and more accurate than current
estimation (header + header->size).

Also, fix missing prog->jited_len with multi function program. This hasn't
been a real issue before this.
Signed-off-by: default avatarSong Liu <song@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220204185742.271030-5-song@kernel.org
parent ed2d9e1a
...@@ -537,13 +537,10 @@ long bpf_jit_limit_max __read_mostly; ...@@ -537,13 +537,10 @@ long bpf_jit_limit_max __read_mostly;
static void static void
bpf_prog_ksym_set_addr(struct bpf_prog *prog) bpf_prog_ksym_set_addr(struct bpf_prog *prog)
{ {
const struct bpf_binary_header *hdr = bpf_jit_binary_hdr(prog);
unsigned long addr = (unsigned long)hdr;
WARN_ON_ONCE(!bpf_prog_ebpf_jited(prog)); WARN_ON_ONCE(!bpf_prog_ebpf_jited(prog));
prog->aux->ksym.start = (unsigned long) prog->bpf_func; prog->aux->ksym.start = (unsigned long) prog->bpf_func;
prog->aux->ksym.end = addr + hdr->size; prog->aux->ksym.end = prog->aux->ksym.start + prog->jited_len;
} }
static void static void
......
...@@ -13067,6 +13067,7 @@ static int jit_subprogs(struct bpf_verifier_env *env) ...@@ -13067,6 +13067,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)
prog->jited = 1; prog->jited = 1;
prog->bpf_func = func[0]->bpf_func; prog->bpf_func = func[0]->bpf_func;
prog->jited_len = func[0]->jited_len;
prog->aux->func = func; prog->aux->func = func;
prog->aux->func_cnt = env->subprog_cnt; prog->aux->func_cnt = env->subprog_cnt;
bpf_prog_jit_attempt_done(prog); bpf_prog_jit_attempt_done(prog);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment