s390/bpf: Fix arch_prepare_bpf_trampoline
Subsystems (5)
Song Liu
reviewerPATCH 1/2 s390/bpf: Let arch_prepare_bpf_trampoline return program size
In reply to Song Liuarch_prepare_bpf_trampoline() for s390 currently returns 0 on success. This is not a problem for regular trampoline. However, struct_ops relies on the return value to advance "image" pointer:
bpf_struct_ops_map_update_elem() {
...
for_each_member(i, t, member) {
...
err = bpf_struct_ops_prepare_trampoline();
...
image += err;
}
}When arch_prepare_bpf_trampoline returns 0 on success, all members of the struct_ops will point to the same trampoline (the last one).
Fix this by returning the program size in arch_prepare_bpf_trampoline (on success). This is the same behavior as other architectures.
--- arch/s390/net/bpf_jit_comp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/net/bpf_jit_comp.c +1 -1
@@ -2513,7 +2513,7 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,return -E2BIG ; } -return ret; +return tjit.common.prg; }bool bpf_jit_supports_subprog_tailcalls (void )
Signature · 1 line
2.34.1
Song Liu
reviewercover s390/bpf: Fix arch_prepare_bpf_trampoline
While working on trampoline, I found s390's arch_prepare_bpf_trampoline returns 0 on success, which breaks struct_ops. However, the CI doesn't catch this issue. Turns out test_progs:bpf_tcp_ca doesn't really test members of a struct_ops are actually called via the trampolines.
1/2 fixes arch_prepare_bpf_trampoline for s390.
2/2 adds a check to test_progs:bpf_tcp_ca to verify bpf_cubic_acked() is indeed called by the trampoline. Without 1/2, this check would fail on s390.
Song Liu (2):
s390/bpf: Let arch_prepare_bpf_trampoline return program size selftests/bpf: Check bpf_cubic_acked() is called via struct_ops
arch/s390/net/bpf_jit_comp.c | 2 +- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 2 ++ tools/testing/selftests/bpf/progs/bpf_cubic.c | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-)
--
2.34.1
Song Liu
reviewerPATCH 2/2 selftests/bpf: Check bpf_cubic_acked() is called via struct_ops
Test bpf_tcp_ca (in test_progs) checks multiple tcp_congestion_ops. However, there isn't a test that verifies functions in the tcp_congestion_ops is actually called. Add a check to verify that bpf_cubic_acked is actually called during the test.
--- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 2 ++ tools/testing/selftests/bpf/progs/bpf_cubic.c | 3 +++ 2 files changed, 5 insertions(+)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +2 -0
@@ -185,6 +185,8 @@ static void test_cubic(void)do_test ("bpf_cubic" ,NULL ); +ASSERT_EQ (cubic_skel->bss->bpf_cubic_acked_called,1 ,"pkts_acked called" ); +bpf_link__destroy (link);bpf_cubic__destroy (cubic_skel); }
tools/testing/selftests/bpf/progs/bpf_cubic.c +3 -0
@@ -490,6 +490,8 @@ static __always_inline void hystart_update(struct sock *sk, __u32 delay) } } +int bpf_cubic_acked_called =0 ; +void BPF_STRUCT_OPS (bpf_cubic_acked ,struct sock *sk,const struct ack_sample *sample) {
@@ -497,6 +499,7 @@ void BPF_STRUCT_OPS(bpf_cubic_acked, struct sock *sk,struct bictcp *ca =inet_csk_ca (sk);__u32 delay; + bpf_cubic_acked_called =1 ;/* Some calls are for duplicates without timetamps */ if (sample->rtt_us <0 )return ;
Signature · 1 line
2.34.1
Re: [PATCH bpf 2/2] selftests/bpf: Check bpf_cubic_acked() is called via struct_ops
Quoted 11 lines · Song Liu
Test
bpf_tcp_ca(intest_progs) checks multipletcp_congestion_ops. However, there isn't a test that verifies functions in thetcp_congestion_opsis actually called. Add a check to verify thatbpf_cubic_ackedis actually called during the test.Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Song Liu <[email protected]>---
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 2 ++ tools/testing/selftests/bpf/progs/bpf_cubic.c | 3 +++2 files changed, 5 insertions(+)
Re: [PATCH bpf 1/2] s390/bpf: Let arch_prepare_bpf_trampoline return program size
In reply to Song LiuQuoted 20 lines · Song Liu
arch_prepare_bpf_trampoline()for s390 currently returns 0 on success. This
is not a problem for regular trampoline. However,struct_opsrelies on the
return value to advance "image" pointer:
bpf_struct_ops_map_update_elem(){
...
for_each_member(i, t, member){
...
err =bpf_struct_ops_prepare_trampoline();
...
image += err;
}
}When
arch_prepare_bpf_trampolinereturns 0 on success, all members of thestruct_opswill point to the same trampoline (the last one).
Quoted 8 lines
Fix this by returning the program size in
arch_prepare_bpf_trampoline(on
success). This is the same behavior as other architectures.Signed-off-by Song Liu <[email protected]>---
arch/s390/net/bpf_jit_comp.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Thanks!
arch_prepare_bpf_trampoline()")
This series was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Mon, 18 Sep 2023 23:02:56 -0700 you wrote:
While working on trampoline, I found s390's
arch_prepare_bpf_trampolinereturns 0 on success, which breaksstruct_ops. However, the CI doesn't catch this issue. Turns out test_progs:bpf_tcp_ca doesn't really test members of astruct_opsare actually called via the trampolines.1/2 fixes
arch_prepare_bpf_trampolinefor s390.
2/2 adds a check to test_progs:bpf_tcp_ca to verifybpf_cubic_acked()is indeed called by the trampoline. Without 1/2, this check would fail on s390.[...]
Here is the summary with links:
- [bpf,1/2] s390/bpf: Let arch_prepare_bpf_trampoline return program size
https://git.kernel.org/bpf/bpf/c/cf094baa3e0f - [bpf,2/2] selftests/bpf: Check bpf_cubic_acked() is called via struct_ops https://git.kernel.org/bpf/bpf/c/48f5e7d3f730
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html