* [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again
@ 2025-07-16 19:35 Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 1/2] " Ilya Leoshkevich
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2025-07-16 19:35 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich
Hi,
This series fixes a regression causing perf on s390 to trigger a kernel
panic.
Patch 1 fixes the issue, patch 2 adds a test to make sure this doesn't
happen again.
Best regards,
Ilya
Ilya Leoshkevich (2):
s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again
selftests/bpf: Stress test attaching a BPF prog to another BPF prog
arch/s390/net/bpf_jit_comp.c | 10 ++-
.../bpf/prog_tests/recursive_attach.c | 67 +++++++++++++++++++
2 files changed, 76 insertions(+), 1 deletion(-)
--
2.50.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again
2025-07-16 19:35 [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again Ilya Leoshkevich
@ 2025-07-16 19:35 ` Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 2/2] selftests/bpf: Stress test attaching a BPF prog to another BPF prog Ilya Leoshkevich
2025-07-17 1:40 ` [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2025-07-16 19:35 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich, stable
Commit 7ded842b356d ("s390/bpf: Fix bpf_plt pointer arithmetic") has
accidentally removed the critical piece of commit c730fce7c70c
("s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL"), causing
intermittent kernel panics in e.g. perf's on_switch() prog to reappear.
Restore the fix and add a comment.
Fixes: 7ded842b356d ("s390/bpf: Fix bpf_plt pointer arithmetic")
Cc: stable@vger.kernel.org
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
arch/s390/net/bpf_jit_comp.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 8bb738f1b1b6..bb17efe29d65 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -576,7 +576,15 @@ static void bpf_jit_plt(struct bpf_plt *plt, void *ret, void *target)
{
memcpy(plt, &bpf_plt, sizeof(*plt));
plt->ret = ret;
- plt->target = target;
+ /*
+ * (target == NULL) implies that the branch to this PLT entry was
+ * patched and became a no-op. However, some CPU could have jumped
+ * to this PLT entry before patching and may be still executing it.
+ *
+ * Since the intention in this case is to make the PLT entry a no-op,
+ * make the target point to the return label instead of NULL.
+ */
+ plt->target = target ?: ret;
}
/*
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] selftests/bpf: Stress test attaching a BPF prog to another BPF prog
2025-07-16 19:35 [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 1/2] " Ilya Leoshkevich
@ 2025-07-16 19:35 ` Ilya Leoshkevich
2025-07-17 1:40 ` [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2025-07-16 19:35 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
Ilya Leoshkevich
Add a test that invokes a BPF prog in a loop, while concurrently
attaching and detaching another BPF prog to and from it. This helps
identifying race conditions in bpf_arch_text_poke().
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
.../bpf/prog_tests/recursive_attach.c | 67 +++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/recursive_attach.c b/tools/testing/selftests/bpf/prog_tests/recursive_attach.c
index 8100509e561b..0ffa01d54ce2 100644
--- a/tools/testing/selftests/bpf/prog_tests/recursive_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/recursive_attach.c
@@ -149,3 +149,70 @@ void test_fentry_attach_btf_presence(void)
fentry_recursive_target__destroy(target_skel);
fentry_recursive__destroy(tracing_skel);
}
+
+static void *fentry_target_test_run(void *arg)
+{
+ for (;;) {
+ int prog_fd = __atomic_load_n((int *)arg, __ATOMIC_SEQ_CST);
+ LIBBPF_OPTS(bpf_test_run_opts, topts);
+ int err;
+
+ if (prog_fd == -1)
+ break;
+ err = bpf_prog_test_run_opts(prog_fd, &topts);
+ if (!ASSERT_OK(err, "fentry_target test_run"))
+ break;
+ }
+
+ return NULL;
+}
+
+void test_fentry_attach_stress(void)
+{
+ struct fentry_recursive_target *target_skel = NULL;
+ struct fentry_recursive *tracing_skel = NULL;
+ struct bpf_program *prog;
+ int err, i, tgt_prog_fd;
+ pthread_t thread;
+
+ target_skel = fentry_recursive_target__open_and_load();
+ if (!ASSERT_OK_PTR(target_skel,
+ "fentry_recursive_target__open_and_load"))
+ goto close_prog;
+ tgt_prog_fd = bpf_program__fd(target_skel->progs.fentry_target);
+ err = pthread_create(&thread, NULL,
+ fentry_target_test_run, &tgt_prog_fd);
+ if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
+ goto close_prog;
+
+ for (i = 0; i < 1000; i++) {
+ tracing_skel = fentry_recursive__open();
+ if (!ASSERT_OK_PTR(tracing_skel, "fentry_recursive__open"))
+ goto stop_thread;
+
+ prog = tracing_skel->progs.recursive_attach;
+ err = bpf_program__set_attach_target(prog, tgt_prog_fd,
+ "fentry_target");
+ if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
+ goto stop_thread;
+
+ err = fentry_recursive__load(tracing_skel);
+ if (!ASSERT_OK(err, "fentry_recursive__load"))
+ goto stop_thread;
+
+ err = fentry_recursive__attach(tracing_skel);
+ if (!ASSERT_OK(err, "fentry_recursive__attach"))
+ goto stop_thread;
+
+ fentry_recursive__destroy(tracing_skel);
+ tracing_skel = NULL;
+ }
+
+stop_thread:
+ __atomic_store_n(&tgt_prog_fd, -1, __ATOMIC_SEQ_CST);
+ err = pthread_join(thread, NULL);
+ ASSERT_OK(err, "pthread_join");
+close_prog:
+ fentry_recursive__destroy(tracing_skel);
+ fentry_recursive_target__destroy(target_skel);
+}
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again
2025-07-16 19:35 [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 1/2] " Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 2/2] selftests/bpf: Stress test attaching a BPF prog to another BPF prog Ilya Leoshkevich
@ 2025-07-17 1:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-17 1:40 UTC (permalink / raw)
To: Ilya Leoshkevich; +Cc: ast, daniel, andrii, bpf, hca, gor, agordeev
Hello:
This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 16 Jul 2025 21:35:05 +0200 you wrote:
> Hi,
>
> This series fixes a regression causing perf on s390 to trigger a kernel
> panic.
>
> Patch 1 fixes the issue, patch 2 adds a test to make sure this doesn't
> happen again.
>
> [...]
Here is the summary with links:
- [1/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again
https://git.kernel.org/bpf/bpf/c/6a5abf8cf182
- [2/2] selftests/bpf: Stress test attaching a BPF prog to another BPF prog
https://git.kernel.org/bpf/bpf/c/d459dbbbfa32
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-17 1:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 19:35 [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 1/2] " Ilya Leoshkevich
2025-07-16 19:35 ` [PATCH 2/2] selftests/bpf: Stress test attaching a BPF prog to another BPF prog Ilya Leoshkevich
2025-07-17 1:40 ` [PATCH 0/2] s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL again patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).