Skip to contentSkip to conversation

s390/bpf: Fix arch_prepare_bpf_trampoline

PATCH Applied Song Liu 3 participants 6 messages Sep 19, 2023

Subsystems (5)
Kselftest BPF s390 BPF selftests +1 more subsystems
lore
Share & tools
lore
author reviewer
#1 lore raw

PATCH 1/2 s390/bpf: Let arch_prepare_bpf_trampoline return program size

In reply to Song Liu

arch_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
index de2fb12120d2..2861e3360aff 100644
@@ -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

author reviewer
#0 lore raw

cover 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

author reviewer
#3 lore raw

PATCH 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
index a53c254c6058..4aabeaa525d4 100644
@@ -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
index d9660e7200e2..c997e3e3d3fb 100644
@@ -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
maintainer Acked-by on v1 2/2
#4 lore raw

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 (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(+)
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH bpf 1/2] s390/bpf: Let arch_prepare_bpf_trampoline return program size

In reply to Song Liu
Quoted 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_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).

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.

---
 arch/s390/net/bpf_jit_comp.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

Fixes 528eb2cb87bc ("s390/bpf: Implement

arch_prepare_bpf_trampoline()")

#5 lore raw
In reply to Song Liu
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_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.

[...]

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