> diff --git a/tools/testing/selftests/bpf/jit_disasm_helpers.c 
> b/tools/testing/selftests/bpf/jit_disasm_helpers.c
> index 3558fe10e28c..11428cad5b2d 100644
> --- a/tools/testing/selftests/bpf/jit_disasm_helpers.c
> +++ b/tools/testing/selftests/bpf/jit_disasm_helpers.c
> @@ -178,10 +178,12 @@ int get_jited_program_text(int fd, char *text, size_t 
> text_sz)
>  {
>       struct bpf_prog_info info = {};
>       __u32 info_len = sizeof(info);
> -     __u32 jited_funcs, len, pc;
> +     __u32 jited_funcs, len, pc, disasm_len;
> +     __u32 trunc_len = 0;
>       __u32 *func_lens = NULL;
>       FILE *text_out = NULL;
>       uint8_t *image = NULL;
> +     char *triple = NULL;

This isn't a bug, but would it be clearer to follow the traditional C
style by grouping related variables together? The disasm_len variable
could be declared closer to where it's used along with trunc_len, and
adding a blank line before the fprintf() statement in the loop might
improve readability.

[ ... ]

> @@ -225,9 +227,30 @@ int get_jited_program_text(int fd, char *text, size_t 
> text_sz)
>       if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd #2"))
>               goto out;
>
> +     /*
> +      * last 8 bytes contains dummy_trampoline address in JIT
> +      * output on 64-bit and last 4 bytes on 32-bit powerpc,
> +      * which can't disassemble to a valid instruction.
> +      */
> +     triple = LLVMGetDefaultTargetTriple();
> +     if (triple) {
> +             if (strstr(triple, "powerpc64") || strstr(triple, "ppc64"))
> +                     trunc_len = 8;
> +             else if (strstr(triple, "powerpc") || strstr(triple, "ppc"))
> +                     trunc_len = 4;
> +             LLVMDisposeMessage(triple);
> +     }
> +
>       for (pc = 0, i = 0; i < jited_funcs; ++i) {
> +
>               fprintf(text_out, "func #%d:\n", i);
> -             disasm_one_func(text_out, image + pc, func_lens[i]);
> +             /*
> +              * Disabled JIT have zero func_lens, hence underflow
> +              */
> +             disasm_len = func_lens[i] > trunc_len ?
> +                                     func_lens[i] - trunc_len : 0;
> +             disasm_one_func(text_out, image + pc, disasm_len);
> +
>               fprintf(text_out, "\n");
>               pc += func_lens[i];
>       }


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/28051760380

Reply via email to