diff mbox series

[v8,bpf-next,4/9] bpf: use prog->jited_len in bpf_prog_ksym_set_addr()

Message ID 20220201062803.2675204-5-song@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series bpf_prog_pack allocator | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 5 maintainers not CCed: kpsingh@kernel.org john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com yhs@fb.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 14 this patch: 14
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next fail VM_Test

Commit Message

Song Liu Feb. 1, 2022, 6:27 a.m. UTC
Using prog->jited_len is simpler and more accurate than current
estimation (header + header->size).

Signed-off-by: Song Liu <song@kernel.org>
---
 kernel/bpf/core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Song Liu Feb. 4, 2022, 7:41 a.m. UTC | #1
On Mon, Jan 31, 2022 at 10:31 PM Song Liu <song@kernel.org> wrote:
>
> Using prog->jited_len is simpler and more accurate than current
> estimation (header + header->size).
>
> Signed-off-by: Song Liu <song@kernel.org>

Hmm... CI [1] reports error on test_progs 159/tailcalls, and bisect points to
this one. However, I couldn't figure out why this breaks tail call.
round_up(PAGE_SIZE) does fix it though. But that won't be accurate, right?

Any suggestions on what could be the reason for these failures?

Thanks,
Song

[1] https://github.com/kernel-patches/bpf/runs/5060194776?check_suite_focus=true

> ---
>  kernel/bpf/core.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 14199228a6f0..e3fe53df0a71 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -537,13 +537,10 @@ long bpf_jit_limit_max __read_mostly;
>  static void
>  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));
>
>         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
> --
> 2.30.2
>
Song Liu Feb. 4, 2022, 6:05 p.m. UTC | #2
> On Feb 3, 2022, at 11:41 PM, Song Liu <song@kernel.org> wrote:
> 
> On Mon, Jan 31, 2022 at 10:31 PM Song Liu <song@kernel.org> wrote:
>> 
>> Using prog->jited_len is simpler and more accurate than current
>> estimation (header + header->size).
>> 
>> Signed-off-by: Song Liu <song@kernel.org>
> 
> Hmm... CI [1] reports error on test_progs 159/tailcalls, and bisect points to
> this one. However, I couldn't figure out why this breaks tail call.
> round_up(PAGE_SIZE) does fix it though. But that won't be accurate, right?
> 
> Any suggestions on what could be the reason for these failures?
> 
> Thanks,
> Song
> 
> [1] https://github.com/kernel-patches/bpf/runs/5060194776?check_suite_focus=true

I guess this is the missing piece:


diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1ae41d0cf96c..bbef86cb4e72 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -13067,6 +13067,7 @@ static int jit_subprogs(struct bpf_verifier_env *env)

        prog->jited = 1;
        prog->bpf_func = func[0]->bpf_func;
+       prog->jited_len = func[0]->jited_len;
        prog->aux->func = func;
        prog->aux->func_cnt = env->subprog_cnt;
        bpf_prog_jit_attempt_done(prog);


Will send v9 with this. 

> 
>> ---
>> kernel/bpf/core.c | 5 +----
>> 1 file changed, 1 insertion(+), 4 deletions(-)
>> 
>> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
>> index 14199228a6f0..e3fe53df0a71 100644
>> --- a/kernel/bpf/core.c
>> +++ b/kernel/bpf/core.c
>> @@ -537,13 +537,10 @@ long bpf_jit_limit_max __read_mostly;
>> static void
>> 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));
>> 
>>        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
>> --
>> 2.30.2
>>
diff mbox series

Patch

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 14199228a6f0..e3fe53df0a71 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -537,13 +537,10 @@  long bpf_jit_limit_max __read_mostly;
 static void
 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));
 
 	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