s390/bpf: Fix gotol with large offsets
Subsystems (5)
Ilya Leoshkevich
maintainercover s390/bpf: Fix gotol with large offsets
Hi,
While looking at a pyperf180 failure on s390x (must be related to [1], I'm not done with the investigation yet) I noticed that I have unfortunately messed up the gotol implementation. Patch 1 is the fix, patch 2 is a small test infrastructure tweak, and patch 3 adds a test.
[1] https://github.com/llvm/llvm-project/issues/55669
Best regards,
Ilya
Ilya Leoshkevich (3):
s390/bpf: Fix gotol with large offsets selftests/bpf: Double the size of test_loader log selftests/bpf: Test gotol with large offsets
arch/s390/net/bpf_jit_comp.c | 2 +- .../selftests/bpf/progs/verifier_gotol.c | 19 +++++++++++++++++++ tools/testing/selftests/bpf/test_loader.c | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
Ilya Leoshkevich
maintainerPATCH 1/3 s390/bpf: Fix gotol with large offsets
The gotol implementation uses a wrong data type for the offset: it should be s32, not s16.
--- arch/s390/net/bpf_jit_comp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/net/bpf_jit_comp.c +1 -1
@@ -779,7 +779,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i, bool extra_pass, u32 stack_depth) { struct bpf_insn *insn = &fp->insnsi[i]; -s16 branch_oc_off = insn->off; +s32 branch_oc_off = insn->off;u32 dst_reg = insn->dst_reg;u32 src_reg = insn->src_reg;int last, insn_count =1 ;
Signature · 1 line
2.43.0
Quoted 5 lines · Ilya Leoshkevich
The gotol implementation uses a wrong data type for the offset: it should be s32, not s16.
Fixes c690191e23d8 ("s390/bpf: Implement unconditional jump with 32-bit offset")Signed-off-by Ilya Leoshkevich <[email protected]>
Quoted 26 lines · Ilya Leoshkevich
The gotol implementation uses a wrong data type for the offset: it should be s32, not s16.
Fixes c690191e23d8 ("s390/bpf: Implement unconditional jump with 32-bit offset")Signed-off-by Ilya Leoshkevich <[email protected]>--- arch/s390/net/bpf_jit_comp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/s390/net/bpf_jit_comp.c +1
-1@@ -779,7 +779,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i, bool extra_pass, u32 stack_depth) { struct bpf_insn *insn = &fp->insnsi[i]; -s16 branch_oc_off = insn->off; +s32 branch_oc_off = insn->off;u32 dst_reg = insn->dst_reg;u32 src_reg = insn->src_reg;int last, insn_count =1 ;Signature · 1 line
2.43.0
Ilya Leoshkevich
maintainerPATCH 2/3 selftests/bpf: Double the size of test_loader log
In reply to Ilya LeoshkevichTesting long jumps requires having >32k instructions. That many instructions require the verifier log buffer of 2 megabytes.
--- tools/testing/selftests/bpf/test_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_loader.c +1 -1
@@ -12,7 +12,7 @@#define str_has_pfx (str, pfx) \ (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0) -#define TEST_LOADER_LOG_BUF_SZ 1048576 +#define TEST_LOADER_LOG_BUF_SZ 2097152#define TEST_TAG_EXPECT_FAILURE "comment:test_expect_failure"#define TEST_TAG_EXPECT_SUCCESS "comment:test_expect_success"
Signature · 1 line
2.43.0
Yonghong Song
reviewerRe: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
Quoted 13 lines · Ilya Leoshkevich
Testing long jumps requires having >32k instructions. That many instructions require the verifier log buffer of 2 megabytes.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tools/testing/selftests/bpf/test_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/test_loader.c +0
-0
tools/testing/selftests/bpf/test_loader.c line 15
Quoted 5 lines
tools/testing/selftests/bpf/test_loader.c +1
-1@@ -12,7 +12,7 @@#define str_has_pfx (str, pfx) \ (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0) -#define TEST_LOADER_LOG_BUF_SZ 1048576 +#define TEST_LOADER_LOG_BUF_SZ 2097152
I think this patch is not necessary.
If the log buffer size is not enough, the kernel verifier will wrap around and overwrite some initial states, but all later states are still preserved. In my opinion, there is really no need to increase the buffer size in this case, esp. it is a verification success case.
Quoted 3 lines
tools/testing/selftests/bpf/test_loader.c +0
-0#define TEST_TAG_EXPECT_FAILURE "comment:test_expect_failure"#define TEST_TAG_EXPECT_SUCCESS "comment:test_expect_success"
Ilya Leoshkevich
maintainerRe: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
Quoted 21 lines · Yonghong Song
Quoted 19 lines · Ilya Leoshkevich
Testing long jumps requires having >32k instructions. That many instructions require the verifier log buffer of 2 megabytes.
Signed-off-by Ilya Leoshkevich <[email protected]>---
tools/testing/selftests/bpf/test_loader.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/test_loader.c +0
-1@@ -12,7 +12,7 @@ #define str_has_pfx(str, pfx) \ (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)
-#defineTEST_LOADER_LOG_BUF_SZ1048576
Quoted 8 lines
Quoted 1 line
+#define
TEST_LOADER_LOG_BUF_SZ2097152I think this patch is not necessary.
If the log buffer size is not enough, the kernel verifier will wrap around and overwrite some initial states, but all later states are still preserved. In my opinion, there is really no need to increase the buffer size in this case, esp. it is a verification success case.
What I observed in this case was that bpf_check() still returned -ENOSPC and failed the prog load. IIUC you are referring to the functionality introduced by the following commit:
commit 1216640938035e63bdbd32438e91c9bcc1fd8ee1
Author: Andrii Nakryiko <[email protected]> Date: Thu Apr 6 16:41:49 2023 -0700
bpf: Switch BPF verifier log to be a rotating log by default
The commit message says, among other things:
The only user-visible change is which portion of verifier log user ends up seeing *if buffer is too small*.
So if we don't increase the log size, we would still have to deal with -ENOSPC. An alternative would be to reallocate the log buffer and try again. But I thought that for the test code we better keep it as simple as possible.
Quoted 2 lines
Quoted 2 lines
#define
TEST_TAG_EXPECT_FAILURE"comment:test_expect_failure" #defineTEST_TAG_EXPECT_SUCCESS"comment:test_expect_success"
Re: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
Quoted 40 lines · Ilya Leoshkevich
Quoted 19 lines · Yonghong Song
Quoted 18 lines · Ilya Leoshkevich
Testing long jumps requires having >32k instructions. That many instructions require the verifier log buffer of 2 megabytes.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tools/testing/selftests/bpf/test_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/test_loader.c +0
-1@@ -12,7 +12,7 @@ #define str_has_pfx(str, pfx) \ (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)Quoted 8 lines
tools/testing/selftests/bpf/test_loader.c line 15
Quoted 2 lines
tools/testing/selftests/bpf/test_loader.c +1
-1-#define TEST_LOADER_LOG_BUF_SZ 1048576 +#define TEST_LOADER_LOG_BUF_SZ 2097152I think this patch is not necessary.
If the log buffer size is not enough, the kernel verifier will wrap around and overwrite some initial states, but all later states are still preserved. In my opinion, there is really no need to increase the buffer size in this case, esp. it is a verification success case.What I observed in this case was that
bpf_check()still returned-ENOSPCand failed the prog load. IIUC you are referring to the functionality introduced by the following commit:commit
1216640938035e63bdbd32438e91c9bcc1fd8ee1Author: Andrii Nakryiko <[email protected]> Date: Thu Apr 6 16:41:49 2023 -0700bpf: Switch BPF verifier log to be a rotating log by default
The commit message says, among other things:
Quoted 7 lines
The only user-visible change is which portion of verifier log user ends up seeing *if buffer is too small*.
So if we don't increase the log size, we would still have to deal with
-ENOSPC. An alternative would be to reallocate the log buffer and try again. But I thought that for the test code we better keep it as simple as possible.
Okay, thanks for the explanation. I applied the patch set to my local env and indeed, with this patch, I can see libbpf returns an error. So as you suggested, let us increase the buffer size to avoid extra handling in test_progs. So
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
tools/testing/selftests/bpf/test_loader.c +0
-0#define TEST_TAG_EXPECT_FAILURE "comment:test_expect_failure" #define TEST_TAG_EXPECT_SUCCESS "comment:test_expect_success"
John Fastabend
Acked-byRe: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
Quoted 55 lines · Yonghong Song
Quoted 40 lines · Ilya Leoshkevich
Quoted 19 lines · Yonghong Song
Quoted 18 lines · Ilya Leoshkevich
Testing long jumps requires having >32k instructions. That many instructions require the verifier log buffer of 2 megabytes.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tools/testing/selftests/bpf/test_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/test_loader.c +0
-1@@ -12,7 +12,7 @@ #define str_has_pfx(str, pfx) \ (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)Quoted 8 lines
tools/testing/selftests/bpf/test_loader.c line 15
Quoted 2 lines
tools/testing/selftests/bpf/test_loader.c +1
-1-#define TEST_LOADER_LOG_BUF_SZ 1048576 +#define TEST_LOADER_LOG_BUF_SZ 2097152I think this patch is not necessary.
If the log buffer size is not enough, the kernel verifier will wrap around and overwrite some initial states, but all later states are still preserved. In my opinion, there is really no need to increase the buffer size in this case, esp. it is a verification success case.What I observed in this case was that
bpf_check()still returned-ENOSPCand failed the prog load. IIUC you are referring to the functionality introduced by the following commit:commit
1216640938035e63bdbd32438e91c9bcc1fd8ee1Author: Andrii Nakryiko <[email protected]> Date: Thu Apr 6 16:41:49 2023 -0700bpf: Switch BPF verifier log to be a rotating log by default
The commit message says, among other things:
Quoted 7 lines
The only user-visible change is which portion of verifier log user ends up seeing *if buffer is too small*.
So if we don't increase the log size, we would still have to deal with
-ENOSPC. An alternative would be to reallocate the log buffer and try again. But I thought that for the test code we better keep it as simple as possible.Okay, thanks for the explanation. I applied the patch set to my local env and indeed, with this patch, I can see libbpf returns an error. So as you suggested, let us increase the buffer size to avoid extra handling in
test_progs. So
Quoted 1 line
Acked-by Yonghong Song <[email protected]>
LGTM.
Re: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
In reply to Yonghong SongQuoted 5 lines · Yonghong Song
Okay, thanks for the explanation. I applied the patch set to my local env and indeed, with this patch, I can see libbpf returns an error.
How did you repro this?
I've tried reverting this patch, but the test in patch 3 still passes for me without errors.
Re: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
Quoted 11 lines · Alexei Starovoitov
Quoted 5 lines · Yonghong Song
Okay, thanks for the explanation. I applied the patch set to my local env and indeed, with this patch, I can see libbpf returns an error.
How did you repro this?
I've tried reverting this patch, but the test in patch 3 still passes for me without errors.
Took me a long time... I was able to repro with:
(quoted diff) +0 -0
b/tools/testing/selftests/bpf/progs/verifier_gotol.c index 05a329ee45ee..66bdb940a40b 100644
tools/testing/selftests/bpf/progs/verifier_gotol.c +1 -0
@@ -36,6 +36,7 @@ l3_%=: \ SEC("socket") __description("gotol, large_imm") __success __failure_unpriv __retval(40000) +__log_level(1) __naked void gotol_large_imm(void)
and then I finally realized that this patch is fixing the case when test_progs runs with -v. Like:
./test_progs -t gotol -v
I wish you mentioned this in the commit log.
Would have saved me a ton of time.
Yonghong Song
reviewerRe: [PATCH bpf 2/3] selftests/bpf: Double the size of test_loader log
Quoted 25 lines · Alexei Starovoitov
Quoted 8 lines · Alexei Starovoitov
Quoted 4 lines · Yonghong Song
Okay, thanks for the explanation. I applied the patch set to my local env and indeed, with this patch, I can see libbpf returns an error.
How did you repro this?
I've tried reverting this patch, but the test in patch 3 still passes for me without errors.Took me a long time... I was able to repro with:
tools/testing/selftests/bpf/progs/verifier_gotol.c +1
-0@@ -36,6 +36,7 @@ l3_%=: \ SEC("socket") __description("gotol, large_imm") __success __failure_unpriv __retval(40000) +__log_level(1) __naked void gotol_large_imm(void)
Quoted 3 lines
and then I finally realized that this patch is fixing the case when
test_progsruns with -v. Like:
./test_progs -t gotol -v
Sorry for replying later. Just taking a nap... I reproduced the issue when I tried to find out why unpriv failed with cpuv4 as I cannot remember why. IIRC, I am using is
./test_progs-cpuv4 -v -t gotol
Quoted 3 lines
I wish you mentioned this in the commit log.
Would have saved me a ton of time.
Ilya Leoshkevich
maintainerPATCH 3/3 selftests/bpf: Test gotol with large offsets
In reply to Ilya LeoshkevichTest gotol with offsets that don't fit into a short (i.e., larger than 32k or smaller than -32k).
--- .../selftests/bpf/progs/verifier_gotol.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
tools/testing/selftests/bpf/progs/verifier_gotol.c +19 -0
@@ -33,6 +33,25 @@ l3_%=: \ : __clobber_all); } +SEC("socket") +__description("gotol, large_imm") +__success __failure_unpriv __retval(40000) +__naked void gotol_large_imm(void) +{ + asmvolatile (" \ +gotol 1f; \ +0: \ +r0 = 0; \ +.rept 40000; \ +r0 += 1; \ +.endr; \ +exit; \ +1: gotol 0b; \ +" : + : + : __clobber_all); +} +#else SEC ("socket" )
Signature · 1 line
2.43.0
Re: [PATCH bpf 3/3] selftests/bpf: Test gotol with large offsets
Quoted 4 lines · Ilya Leoshkevich
Test gotol with offsets that don't fit into a short (i.e., larger than 32k or smaller than -32k).
Signed-off-by Ilya Leoshkevich <[email protected]>
It might be useful to explain why the test will fail with unpriv mode (4K insn limit) just in case that people are not aware of the reason.
Quoted 34 lines
--- .../selftests/bpf/progs/verifier_gotol.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)tools/testing/selftests/bpf/progs/verifier_gotol.c +19
-0@@ -33,6 +33,25 @@ l3_%=: \ : __clobber_all); } +SEC("socket") +__description("gotol, large_imm") +__success __failure_unpriv __retval(40000) +__naked void gotol_large_imm(void) +{ + asmvolatile (" \ +gotol 1f; \ +0: \ +r0 = 0; \ +.rept 40000; \ +r0 += 1; \ +.endr; \ +exit; \ +1: gotol 0b; \ +" : + : + : __clobber_all); +} +#else SEC ("socket" )
John Fastabend
Acked-byRe: [PATCH bpf 3/3] selftests/bpf: Test gotol with large offsets
Quoted 5 lines · Yonghong Song
Quoted 3 lines · Ilya Leoshkevich
Test gotol with offsets that don't fit into a short (i.e., larger than 32k or smaller than -32k).
Quoted 8 lines
Quoted 1 line
Signed-off-by Ilya Leoshkevich <[email protected]>It might be useful to explain why the test will fail with unpriv mode (4K insn limit) just in case that people are not aware of the reason.
Acked-by Yonghong Song <[email protected]>
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Tue, 2 Jan 2024 20:30:34 +0100 you wrote:
Hi,
While looking at a pyperf180 failure on s390x (must be related to [1], I'm not done with the investigation yet) I noticed that I have unfortunately messed up the gotol implementation. Patch 1 is the fix, patch 2 is a small test infrastructure tweak, and patch 3 adds a test.
[...]
Here is the summary with links:
- [bpf,1/3] s390/bpf: Fix gotol with large offsets
https://git.kernel.org/bpf/bpf-next/c/ecba66cb36e3 - [bpf,2/3] selftests/bpf: Double the size of test_loader log https://git.kernel.org/bpf/bpf-next/c/445aea5afda4 - [bpf,3/3] selftests/bpf: Test gotol with large offsets https://git.kernel.org/bpf/bpf-next/c/63fac34669e4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html