diff mbox series

[bpf] bpf: Fix a bpf_jit_dump issue for x86_64 with sysctl bpf_jit_enable.

Message ID 20230609005439.3173569-1-yhs@fb.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series [bpf] bpf: Fix a bpf_jit_dump issue for x86_64 with sysctl bpf_jit_enable. | expand

Checks

Context Check Description
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-13 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for veristat
bpf/vmtest-bpf-VM_Test-26 success Logs for test_verifier on s390x with gcc
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers fail 1 blamed authors not CCed: song@kernel.org; 16 maintainers not CCed: tglx@linutronix.de hpa@zytor.com dsahern@kernel.org mingo@redhat.com kpsingh@kernel.org x86@kernel.org john.fastabend@gmail.com sdf@google.com netdev@vger.kernel.org martin.lau@linux.dev song@kernel.org dave.hansen@linux.intel.com davem@davemloft.net jolsa@kernel.org haoluo@google.com bp@alien8.de
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 10 this patch: 10
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-12 fail Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on s390x with gcc

Commit Message

Yonghong Song June 9, 2023, 12:54 a.m. UTC
The sysctl net/core/bpf_jit_enable does not work now due to Commit
1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc").
The commit saved the jitted insns into 'rw_image' instead of 'image'
which caused bpf_jit_dump not dumping proper content.

With 'echo 2 > /proc/sys/net/core/bpf_jit_enable', run
'./test_progs -t fentry_test'. Without this patch, one of jitted
image for one particular prog is:
  flen=17 proglen=92 pass=4 image=0000000014c64883 from=test_progs pid=1807
  00000000: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
  00000010: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
  00000020: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
  00000030: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
  00000040: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
  00000050: cc cc cc cc cc cc cc cc cc cc cc cc

With this patch, the jitte image for the same prog is:
  flen=17 proglen=92 pass=4 image=00000000b90254b7 from=test_progs pid=1809
  00000000: f3 0f 1e fa 0f 1f 44 00 00 66 90 55 48 89 e5 f3
  00000010: 0f 1e fa 31 f6 48 8b 57 00 48 83 fa 07 75 2b 48
  00000020: 8b 57 10 83 fa 09 75 22 48 8b 57 08 48 81 e2 ff
  00000030: 00 00 00 48 83 fa 08 75 11 48 8b 7f 18 be 01 00
  00000040: 00 00 48 83 ff 0a 74 02 31 f6 48 bf 18 d0 14 00
  00000050: 00 c9 ff ff 48 89 77 00 31 c0 c9 c3

Fixes: 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 arch/x86/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Song Liu June 9, 2023, 4:18 p.m. UTC | #1
On Thu, Jun 8, 2023 at 5:54 PM Yonghong Song <yhs@fb.com> wrote:
>
> The sysctl net/core/bpf_jit_enable does not work now due to Commit
> 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc").
> The commit saved the jitted insns into 'rw_image' instead of 'image'
> which caused bpf_jit_dump not dumping proper content.
>
> With 'echo 2 > /proc/sys/net/core/bpf_jit_enable', run
> './test_progs -t fentry_test'. Without this patch, one of jitted
> image for one particular prog is:
>   flen=17 proglen=92 pass=4 image=0000000014c64883 from=test_progs pid=1807
>   00000000: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>   00000010: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>   00000020: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>   00000030: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>   00000040: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>   00000050: cc cc cc cc cc cc cc cc cc cc cc cc
>
> With this patch, the jitte image for the same prog is:
>   flen=17 proglen=92 pass=4 image=00000000b90254b7 from=test_progs pid=1809
>   00000000: f3 0f 1e fa 0f 1f 44 00 00 66 90 55 48 89 e5 f3
>   00000010: 0f 1e fa 31 f6 48 8b 57 00 48 83 fa 07 75 2b 48
>   00000020: 8b 57 10 83 fa 09 75 22 48 8b 57 08 48 81 e2 ff
>   00000030: 00 00 00 48 83 fa 08 75 11 48 8b 7f 18 be 01 00
>   00000040: 00 00 48 83 ff 0a 74 02 31 f6 48 bf 18 d0 14 00
>   00000050: 00 c9 ff ff 48 89 77 00 31 c0 c9 c3
>
> Fixes: 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")
> Signed-off-by: Yonghong Song <yhs@fb.com>

Acked-by: Song Liu <song@kernel.org>

Thanks for the fix!
Song

> ---
>  arch/x86/net/bpf_jit_comp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 1056bbf55b17..438adb695daa 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -2570,7 +2570,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
>         }
>
>         if (bpf_jit_enable > 1)
> -               bpf_jit_dump(prog->len, proglen, pass + 1, image);
> +               bpf_jit_dump(prog->len, proglen, pass + 1, rw_image);
>
>         if (image) {
>                 if (!prog->is_func || extra_pass) {
> --
> 2.34.1
>
>
Daniel Borkmann June 12, 2023, 2:52 p.m. UTC | #2
On 6/9/23 2:54 AM, Yonghong Song wrote:
> The sysctl net/core/bpf_jit_enable does not work now due to Commit
> 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc").
> The commit saved the jitted insns into 'rw_image' instead of 'image'
> which caused bpf_jit_dump not dumping proper content.
> 
> With 'echo 2 > /proc/sys/net/core/bpf_jit_enable', run
> './test_progs -t fentry_test'. Without this patch, one of jitted
> image for one particular prog is:
>    flen=17 proglen=92 pass=4 image=0000000014c64883 from=test_progs pid=1807
>    00000000: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>    00000010: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>    00000020: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>    00000030: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>    00000040: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc
>    00000050: cc cc cc cc cc cc cc cc cc cc cc cc
> 
> With this patch, the jitte image for the same prog is:
>    flen=17 proglen=92 pass=4 image=00000000b90254b7 from=test_progs pid=1809
>    00000000: f3 0f 1e fa 0f 1f 44 00 00 66 90 55 48 89 e5 f3
>    00000010: 0f 1e fa 31 f6 48 8b 57 00 48 83 fa 07 75 2b 48
>    00000020: 8b 57 10 83 fa 09 75 22 48 8b 57 08 48 81 e2 ff
>    00000030: 00 00 00 48 83 fa 08 75 11 48 8b 7f 18 be 01 00
>    00000040: 00 00 48 83 ff 0a 74 02 31 f6 48 bf 18 d0 14 00
>    00000050: 00 c9 ff ff 48 89 77 00 31 c0 c9 c3
> 
> Fixes: 1022a5498f6f ("bpf, x86_64: Use bpf_jit_binary_pack_alloc")
> Signed-off-by: Yonghong Song <yhs@fb.com>

LGTM, applied, thanks!
diff mbox series

Patch

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 1056bbf55b17..438adb695daa 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -2570,7 +2570,7 @@  struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
 	}
 
 	if (bpf_jit_enable > 1)
-		bpf_jit_dump(prog->len, proglen, pass + 1, image);
+		bpf_jit_dump(prog->len, proglen, pass + 1, rw_image);
 
 	if (image) {
 		if (!prog->is_func || extra_pass) {