Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto
@ 2026-11-04  8:38 Feng Yang
  2026-11-04  8:38 ` [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint Feng Yang
  2026-11-04  9:10 ` [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto bot+bpf-ci
  0 siblings, 2 replies; 5+ messages in thread
From: Feng Yang @ 2026-11-04  8:38 UTC (permalink / raw)
  To: song, jolsa, ihor.solodrai, kpsingh, matt, ast, daniel, andrii,
	eddyz87, memxor, martin.lau, yonghong.song, emil, rostedt,
	mhiramat, mathieu.desnoyers
  Cc: bpf, linux-trace-kernel, linux-kselftest

From: Feng Yang <yangfeng@kylinos.cn>

bpf_get_stack() has two implementations.  bpf_get_stack() passes
may_fault == false and resolves build IDs with build_id_parse_nofault(),
so an IP whose backing file page is not resident falls back to
BPF_STACK_BUILD_ID_IP.  bpf_get_stack_sleepable() passes may_fault == true
and uses build_id_parse(), which faults the page in and returns a real
build ID.

Only kprobe/uprobe programs are routed to the sleepable implementation
today, so the other program types that can be sleepable keep losing
build IDs for non-resident pages:

 - tracing_prog_func_proto() serves BPF_TRACE_ITER, fentry/fexit/fmod_ret
   and BPF_TRACE_RAW_TP programs, and falls back to
   raw_tp_prog_func_proto() for BPF_FUNC_get_stack, which is also the
   get_func_proto() of BPF_PROG_TYPE_RAW_TRACEPOINT and is reached by
   BPF_PROG_TYPE_LSM and BPF_PROG_TYPE_SYSCALL through the default cases
   of bpf_lsm_func_proto() and syscall_prog_func_proto().

 - tp_prog_func_proto() serves BPF_PROG_TYPE_TRACEPOINT programs.

Route them to bpf_get_stack_sleepable() as well and mark the new
prototypes might_sleep, following
commit 9d02927fdf4e ("bpf: Mark faultable stack helpers as sleepable"),
which did the same for bpf_get_task_stack() and uprobe programs.

The verifier then rejects bpf_get_stack() from these program types
whenever in_sleepable_context() is false: inside bpf_rcu_read_lock(),
bpf_preempt_disable(), bpf_local_irq_save() and bpf_spin_lock() regions,
and in callback subprograms running under rcu_read_lock().  This also
covers calls that do not pass BPF_F_USER_BUILD_ID and would not sleep;
such programs load today.  This is the same trade off that making the
faultable stack helpers sleepable made for bpf_get_task_stack().

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
v3: Add selftest. Update commit messages.

v2: Move regs onto the stack.
https://lore.kernel.org/all/20261102073714.1103088-1-yangfeng59949@163.com/

v1: https://lore.kernel.org/all/20261028093548.790977-1-yangfeng59949@163.com/
---
 kernel/trace/bpf_trace.c | 54 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2aec56d7f3d3..87f7758ffd04 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -84,6 +84,7 @@ static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name)
 
 u64 bpf_get_stackid(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
 u64 bpf_get_stack(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
+u64 bpf_get_stack_sleepable(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
 
 static int bpf_btf_printf_prepare(struct btf_ptr *ptr, u32 btf_ptr_size,
 				  u64 flags, const struct btf **btf,
@@ -1477,6 +1478,26 @@ static const struct bpf_func_proto bpf_get_stack_proto_tp = {
 	.arg4_type	= ARG_ANYTHING,
 };
 
+BPF_CALL_4(bpf_get_stack_tp_sleepable, void *, tp_buff, void *, buf, u32, size,
+	   u64, flags)
+{
+	struct pt_regs *regs = *(struct pt_regs **)tp_buff;
+
+	return bpf_get_stack_sleepable((unsigned long) regs, (unsigned long) buf,
+				       (unsigned long) size, flags, 0);
+}
+
+static const struct bpf_func_proto bpf_get_stack_proto_tp_sleepable = {
+	.func		= bpf_get_stack_tp_sleepable,
+	.gpl_only	= true,
+	.might_sleep	= true,
+	.ret_type	= RET_INTEGER,
+	.arg1_type	= ARG_PTR_TO_CTX,
+	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
+	.arg3_type	= ARG_MEM_SIZE_OR_ZERO,
+	.arg4_type	= ARG_ANYTHING,
+};
+
 static const struct bpf_func_proto *
 tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 {
@@ -1486,7 +1507,8 @@ tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 	case BPF_FUNC_get_stackid:
 		return &bpf_get_stackid_proto_tp;
 	case BPF_FUNC_get_stack:
-		return &bpf_get_stack_proto_tp;
+		return prog->sleepable ? &bpf_get_stack_proto_tp_sleepable
+				       : &bpf_get_stack_proto_tp;
 	case BPF_FUNC_get_attach_cookie:
 		return &bpf_get_attach_cookie_proto_trace;
 	default:
@@ -1716,6 +1738,33 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
 	.arg4_type	= ARG_ANYTHING,
 };
 
+BPF_CALL_4(bpf_get_stack_raw_tp_sleepable, struct bpf_raw_tracepoint_args *, args,
+	   void *, buf, u32, size, u64, flags)
+{
+	/*
+	 * Don't take a per-CPU bpf_raw_tp_regs slot here: those slots are a
+	 * LIFO nest counter and cannot be held across the sleep that
+	 * build_id_parse() may take.  Sleepable programs never run in
+	 * IRQ/NMI context, so a stack copy is sufficient.
+	 */
+	struct pt_regs regs = {};
+
+	perf_fetch_caller_regs(&regs);
+	return bpf_get_stack_sleepable((unsigned long) &regs, (unsigned long) buf,
+				       (unsigned long) size, flags, 0);
+}
+
+static const struct bpf_func_proto bpf_get_stack_proto_raw_tp_sleepable = {
+	.func		= bpf_get_stack_raw_tp_sleepable,
+	.gpl_only	= true,
+	.might_sleep	= true,
+	.ret_type	= RET_INTEGER,
+	.arg1_type	= ARG_PTR_TO_CTX,
+	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
+	.arg3_type	= ARG_MEM_SIZE_OR_ZERO,
+	.arg4_type	= ARG_ANYTHING,
+};
+
 static const struct bpf_func_proto *
 raw_tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 {
@@ -1725,7 +1774,8 @@ raw_tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 	case BPF_FUNC_get_stackid:
 		return &bpf_get_stackid_proto_raw_tp;
 	case BPF_FUNC_get_stack:
-		return &bpf_get_stack_proto_raw_tp;
+		return prog->sleepable ? &bpf_get_stack_proto_raw_tp_sleepable
+				       : &bpf_get_stack_proto_raw_tp;
 	case BPF_FUNC_get_attach_cookie:
 		return &bpf_get_attach_cookie_proto_tracing;
 	default:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint
  2026-11-04  8:38 [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto Feng Yang
@ 2026-11-04  8:38 ` Feng Yang
  2026-11-04  8:57   ` sashiko-bot
  2026-11-04  9:24   ` bot+bpf-ci
  2026-11-04  9:10 ` [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto bot+bpf-ci
  1 sibling, 2 replies; 5+ messages in thread
From: Feng Yang @ 2026-11-04  8:38 UTC (permalink / raw)
  To: song, jolsa, ihor.solodrai, kpsingh, matt, ast, daniel, andrii,
	eddyz87, memxor, martin.lau, yonghong.song, emil, rostedt,
	mhiramat, mathieu.desnoyers
  Cc: bpf, linux-trace-kernel, linux-kselftest

From: Feng Yang <yangfeng@kylinos.cn>

Extend the test with a sleepable raw tracepoint on sys_enter.  A helper
process pages out the build ID page, issues a getpid() syscall and then
stops itself, so that the recorded stack cannot be overwritten.  The BPF
program filters on the target tgid and syscall id, captures the user
stack with BPF_F_USER_BUILD_ID, and the test asserts that one of the
frames carries uprobe_multi's build ID.  A non-sleepable raw tracepoint
is used as a control: the same frame must be reported as IP, which also
proves that the page was really evicted.

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 .../selftests/bpf/prog_tests/build_id.c       | 138 ++++++++++++++++++
 .../selftests/bpf/progs/test_build_id.c       |  38 +++++
 tools/testing/selftests/bpf/uprobe_multi.c    |  37 ++++-
 3 files changed, 210 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/build_id.c b/tools/testing/selftests/bpf/prog_tests/build_id.c
index aec9c8d6bc96..885dc3da5900 100644
--- a/tools/testing/selftests/bpf/prog_tests/build_id.c
+++ b/tools/testing/selftests/bpf/prog_tests/build_id.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+#include <signal.h>
+#include <sys/syscall.h>
 #include <test_progs.h>
 
 #include "test_build_id.skel.h"
@@ -104,6 +106,138 @@ static void subtest_sleepable(void)
 	test_build_id__destroy(skel);
 }
 
+static bool stack_has_build_id(const struct bpf_stack_build_id *stack, int frame_cnt,
+			       const char *id, int id_sz)
+{
+	int i;
+
+	for (i = 0; i < frame_cnt; i++)
+		if (stack[i].status == BPF_STACK_BUILD_ID_VALID &&
+		    !memcmp(stack[i].build_id, id, id_sz))
+			return true;
+
+	return false;
+}
+
+/*
+ * Run uprobe_multi, let it page out the build ID page and stop itself on
+ * SIGSTOP, so that the recorded stack cannot be overwritten by a later
+ * syscall while the caller inspects it.  target_tgid is set before the
+ * child is released, so only its syscalls are recorded.
+ */
+static int run_uprobe_multi_stopped(const char *mode, struct test_build_id *skel,
+				    pid_t *pid_out)
+{
+	char c = 'x';
+	int pfd[2], status, err;
+	pid_t pid;
+
+	*pid_out = -1;
+
+	if (pipe(pfd))
+		return -errno;
+
+	pid = fork();
+	if (pid < 0) {
+		err = -errno;
+		close(pfd[0]);
+		close(pfd[1]);
+		return err;
+	}
+	if (pid == 0) {
+		close(pfd[1]);
+		if (read(pfd[0], &c, 1) != 1)
+			_exit(127);
+		close(pfd[0]);
+		execl("./uprobe_multi", "uprobe_multi", mode, NULL);
+		_exit(127);
+	}
+
+	close(pfd[0]);
+	skel->bss->target_tgid = pid;
+	skel->bss->target_syscall = SYS_getpid;
+	if (write(pfd[1], &c, 1) != 1) {
+		err = -errno;
+		close(pfd[1]);
+		kill(pid, SIGKILL);
+		waitpid(pid, NULL, 0);
+		return err;
+	}
+	close(pfd[1]);
+
+	if (waitpid(pid, &status, WUNTRACED) < 0) {
+		err = -errno;
+		kill(pid, SIGKILL);
+		waitpid(pid, NULL, 0);
+		return err;
+	}
+
+	if (WIFSTOPPED(status)) {
+		*pid_out = pid;
+		return 0;
+	}
+	if (WIFEXITED(status))
+		return WEXITSTATUS(status);
+	return -1;
+}
+
+static void subtest_raw_tp(bool sleepable)
+{
+	struct test_build_id *skel;
+	struct bpf_stack_build_id *stack;
+	int frame_cnt, err, res;
+	pid_t pid = -1;
+
+	skel = test_build_id__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open"))
+		return;
+
+	if (sleepable) {
+		skel->links.rawtp_sleepable = bpf_program__attach(skel->progs.rawtp_sleepable);
+		if (!ASSERT_OK_PTR(skel->links.rawtp_sleepable, "attach_rawtp_sleepable"))
+			goto cleanup;
+	} else {
+		skel->links.rawtp_nofault = bpf_program__attach(skel->progs.rawtp_nofault);
+		if (!ASSERT_OK_PTR(skel->links.rawtp_nofault, "attach_rawtp_nofault"))
+			goto cleanup;
+	}
+
+	err = run_uprobe_multi_stopped("uprobe-paged-out-stop", skel, &pid);
+	if (err == 2) {
+		/* could not evict the build ID page, nothing to test */
+		test__skip();
+		goto cleanup;
+	}
+	if (!ASSERT_OK(err, "trigger_uprobe_multi"))
+		goto cleanup;
+
+	if (sleepable) {
+		res = skel->bss->res_rawtp_sleepable;
+		stack = skel->bss->stack_rawtp_sleepable;
+	} else {
+		res = skel->bss->res_rawtp_nofault;
+		stack = skel->bss->stack_rawtp_nofault;
+	}
+	frame_cnt = res / sizeof(struct bpf_stack_build_id);
+	if (env.verbosity >= VERBOSE_NORMAL)
+		print_stack(stack, frame_cnt);
+
+	ASSERT_GT(frame_cnt, 0, "frames");
+	if (sleepable)
+		ASSERT_TRUE(stack_has_build_id(stack, frame_cnt, build_id, build_id_sz),
+			    "sleepable_build_id");
+	else
+		ASSERT_FALSE(stack_has_build_id(stack, frame_cnt, build_id, build_id_sz),
+			     "nofault_build_id");
+
+cleanup:
+	if (pid > 0) {
+		kill(pid, SIGKILL);
+		waitpid(pid, NULL, 0);
+	}
+	test_build_id__destroy(skel);
+}
+
 void serial_test_build_id(void)
 {
 	build_id_sz = read_build_id("uprobe_multi", build_id, sizeof(build_id));
@@ -115,4 +249,8 @@ void serial_test_build_id(void)
 		subtest_nofault(true /* resident */);
 	if (test__start_subtest("sleepable"))
 		subtest_sleepable();
+	if (test__start_subtest("raw-tp-nofault-paged-out"))
+		subtest_raw_tp(false /* non-sleepable */);
+	if (test__start_subtest("raw-tp-sleepable-paged-out"))
+		subtest_raw_tp(true /* sleepable */);
 }
diff --git a/tools/testing/selftests/bpf/progs/test_build_id.c b/tools/testing/selftests/bpf/progs/test_build_id.c
index 32ce59f9aa27..a6d6712888dc 100644
--- a/tools/testing/selftests/bpf/progs/test_build_id.c
+++ b/tools/testing/selftests/bpf/progs/test_build_id.c
@@ -3,6 +3,7 @@
 
 #include "vmlinux.h"
 #include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
 
 struct bpf_stack_build_id stack_sleepable[128];
 int res_sleepable;
@@ -28,4 +29,41 @@ int uprobe_sleepable(struct pt_regs *ctx)
 	return 0;
 }
 
+struct bpf_stack_build_id stack_rawtp_sleepable[128];
+int res_rawtp_sleepable;
+
+struct bpf_stack_build_id stack_rawtp_nofault[128];
+int res_rawtp_nofault;
+
+int target_tgid;
+int target_syscall;
+
+SEC("raw_tp/sys_enter")
+int BPF_PROG(rawtp_nofault, struct pt_regs *regs, long id)
+{
+	if ((u32)(bpf_get_current_pid_tgid() >> 32) != (u32)target_tgid ||
+	    id != target_syscall)
+		return 0;
+
+	res_rawtp_nofault = bpf_get_stack(ctx, stack_rawtp_nofault,
+					  sizeof(stack_rawtp_nofault),
+					  BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
+
+	return 0;
+}
+
+SEC("raw_tp.s/sys_enter")
+int BPF_PROG(rawtp_sleepable, struct pt_regs *regs, long id)
+{
+	if ((u32)(bpf_get_current_pid_tgid() >> 32) != (u32)target_tgid ||
+	    id != target_syscall)
+		return 0;
+
+	res_rawtp_sleepable = bpf_get_stack(ctx, stack_rawtp_sleepable,
+					    sizeof(stack_rawtp_sleepable),
+					    BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
+
+	return 0;
+}
+
 char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
index 0af330b6c364..ef44d86962c1 100644
--- a/tools/testing/selftests/bpf/uprobe_multi.c
+++ b/tools/testing/selftests/bpf/uprobe_multi.c
@@ -4,7 +4,9 @@
 #include <string.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <signal.h>
 #include <sys/mman.h>
+#include <sys/syscall.h>
 #include <unistd.h>
 #include <sdt.h>
 
@@ -95,12 +97,12 @@ static int usdt(void)
 extern char build_id_start[];
 extern char build_id_end[];
 
-int __attribute__((weak)) trigger_uprobe(bool build_id_resident)
+/* Returns 2 if the build ID page could not be evicted. */
+static int prep_build_id_page(bool build_id_resident)
 {
 	int page_sz = sysconf(_SC_PAGESIZE);
-	void *addr;
-
 	unsigned char vec[1];
+	void *addr;
 	int poll = 0;
 
 	/* page-align build ID start */
@@ -123,12 +125,39 @@ int __attribute__((weak)) trigger_uprobe(bool build_id_resident)
 			poll++;
 			usleep(100);
 		} while (poll < 500);
+		if (vec[0] & 1)
+			return 2;
 	}
+	return 0;
+}
+
+int __attribute__((weak)) trigger_uprobe(bool build_id_resident)
+{
+	(void)prep_build_id_page(build_id_resident);
+
 	(void)uprobe();
 
 	return 0;
 }
 
+int __attribute__((weak)) trigger_stop(void)
+{
+	int err = prep_build_id_page(false /* page-out build ID */);
+
+	if (err)
+		return err;
+
+	/*
+	 * Make one syscall that the BPF program under test filters on, then
+	 * stop this process so that the recorded stack cannot be overwritten
+	 * by another syscall while the caller inspects it.
+	 */
+	(void)syscall(SYS_getpid);
+	raise(SIGSTOP);
+
+	return 0;
+}
+
 int main(int argc, char **argv)
 {
 	if (argc != 2)
@@ -142,6 +171,8 @@ int main(int argc, char **argv)
 		return trigger_uprobe(false /* page-out build ID */);
 	if (!strcmp("uprobe-paged-in", argv[1]))
 		return trigger_uprobe(true /* page-in build ID */);
+	if (!strcmp("uprobe-paged-out-stop", argv[1]))
+		return trigger_stop();
 
 error:
 	fprintf(stderr,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint
  2026-11-04  8:38 ` [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint Feng Yang
@ 2026-11-04  8:57   ` sashiko-bot
  2026-11-04  9:24   ` bot+bpf-ci
  1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-04  8:57 UTC (permalink / raw)
  To: Feng Yang; +Cc: bpf, linux-trace-kernel

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests/bpf: raise(SIGSTOP) in trigger_stop() overwrites recorded stack
- [Medium] selftests/bpf: broken s390x unwind and missing IP check in subtest_raw_tp()
--

commit f32a6f825aa7edd03a124636be8381204465d887
Author: Feng Yang <yangfeng@kylinos.cn>

selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint

This commit extends the build_id selftest with sleepable and non-sleepable
raw tracepoints on sys_enter to test faulting in build IDs when the build
ID page of uprobe_multi has been evicted.

> diff --git a/tools/testing/selftests/bpf/prog_tests/build_id.c b/tools/testing/selftests/bpf/prog_tests/build_id.c
> index aec9c8d6bc96b..885dc3da5900b 100644
> --- a/tools/testing/selftests/bpf/prog_tests/build_id.c
> +++ b/tools/testing/selftests/bpf/prog_tests/build_id.c

[ ... ]

> @@ -104,6 +106,138 @@ static void subtest_sleepable(void)
>  	test_build_id__destroy(skel);
>  }
>  
> +static bool stack_has_build_id(const struct bpf_stack_build_id *stack, int frame_cnt,
> +			       const char *id, int id_sz)
> +{
> +	int i;
> +
> +	for (i = 0; i < frame_cnt; i++)
> +		if (stack[i].status == BPF_STACK_BUILD_ID_VALID &&
> +		    !memcmp(stack[i].build_id, id, id_sz))
> +			return true;
> +
> +	return false;
> +}

[ ... ]

> +static void subtest_raw_tp(bool sleepable)
> +{

[ ... ]

> +	ASSERT_GT(frame_cnt, 0, "frames");
> +	if (sleepable)
> +		ASSERT_TRUE(stack_has_build_id(stack, frame_cnt, build_id, build_id_sz),
> +			    "sleepable_build_id");
> +	else
> +		ASSERT_FALSE(stack_has_build_id(stack, frame_cnt, build_id, build_id_sz),
> +			     "nofault_build_id");

[Severity: Medium]
In trigger_stop(), uprobe_multi invokes the syscall via libc's syscall()
wrapper:

    subtest_raw_tp()
      -> run_uprobe_multi_stopped()
        -> trigger_stop()
          -> syscall(SYS_getpid)

When rawtp_nofault or rawtp_sleepable fires on sys_enter and calls
bpf_get_stack() with BPF_F_USER_STACK | BPF_F_USER_BUILD_ID, stack[0] is
inside libc.so rather than uprobe_multi, so reaching uprobe_multi requires
perf_callchain_user() to unwind user stack frames past libc.so.

On s390x, arch_stack_walk_user_common() in arch/s390/kernel/stacktrace.c
unwinds user stacks via sf->back_chain. Because uprobe_multi is built with
-fno-omit-frame-pointer but without -mbackchain in
tools/testing/selftests/bpf/Makefile, sf->back_chain is 0 and unwinding
stops after stack[0] in libc.so. Will raw-tp-sleepable-paged-out fail on
s390x because stack_has_build_id() never sees a frame from uprobe_multi?

Also, the commit message states that for the non-sleepable control:

    the same frame must be reported as IP, which also proves that the page
    was really evicted.

However, the non-sleepable branch in subtest_raw_tp() only asserts that
stack_has_build_id() is false without checking that any frame has status
BPF_STACK_BUILD_ID_IP. If unwinding stops at stack[0] in libc.so (whose
build ID is resident and valid), won't the non-sleepable subtest pass even
though uprobe_multi was never reached and no frame was reported with
BPF_STACK_BUILD_ID_IP?

[ ... ]

> diff --git a/tools/testing/selftests/bpf/progs/test_build_id.c b/tools/testing/selftests/bpf/progs/test_build_id.c
> index 32ce59f9aa27b..a6d6712888dc9 100644
> --- a/tools/testing/selftests/bpf/progs/test_build_id.c
> +++ b/tools/testing/selftests/bpf/progs/test_build_id.c
> @@ -3,6 +3,7 @@
>  
>  #include "vmlinux.h"
>  #include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
>  
>  struct bpf_stack_build_id stack_sleepable[128];
>  int res_sleepable;
> @@ -28,4 +29,41 @@ int uprobe_sleepable(struct pt_regs *ctx)
>  	return 0;
>  }
>  
> +struct bpf_stack_build_id stack_rawtp_sleepable[128];
> +int res_rawtp_sleepable;
> +
> +struct bpf_stack_build_id stack_rawtp_nofault[128];
> +int res_rawtp_nofault;
> +
> +int target_tgid;
> +int target_syscall;
> +
> +SEC("raw_tp/sys_enter")
> +int BPF_PROG(rawtp_nofault, struct pt_regs *regs, long id)
> +{
> +	if ((u32)(bpf_get_current_pid_tgid() >> 32) != (u32)target_tgid ||
> +	    id != target_syscall)
> +		return 0;
> +
> +	res_rawtp_nofault = bpf_get_stack(ctx, stack_rawtp_nofault,
> +					  sizeof(stack_rawtp_nofault),
> +					  BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
> +
> +	return 0;
> +}
> +
> +SEC("raw_tp.s/sys_enter")
> +int BPF_PROG(rawtp_sleepable, struct pt_regs *regs, long id)
> +{
> +	if ((u32)(bpf_get_current_pid_tgid() >> 32) != (u32)target_tgid ||
> +	    id != target_syscall)
> +		return 0;
> +
> +	res_rawtp_sleepable = bpf_get_stack(ctx, stack_rawtp_sleepable,
> +					    sizeof(stack_rawtp_sleepable),
> +					    BPF_F_USER_STACK | BPF_F_USER_BUILD_ID);
> +
> +	return 0;
> +}
> +
>  char _license[] SEC("license") = "GPL";
> diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
> index 0af330b6c3646..ef44d86962c13 100644
> --- a/tools/testing/selftests/bpf/uprobe_multi.c
> +++ b/tools/testing/selftests/bpf/uprobe_multi.c

[ ... ]

> @@ -123,12 +125,39 @@ int __attribute__((weak)) trigger_uprobe(bool build_id_resident)

[ ... ]

> +int __attribute__((weak)) trigger_stop(void)
> +{
> +	int err = prep_build_id_page(false /* page-out build ID */);
> +
> +	if (err)
> +		return err;
> +
> +	/*
> +	 * Make one syscall that the BPF program under test filters on, then
> +	 * stop this process so that the recorded stack cannot be overwritten
> +	 * by another syscall while the caller inspects it.
> +	 */
> +	(void)syscall(SYS_getpid);
> +	raise(SIGSTOP);

[Severity: Medium]
Does raise(SIGSTOP) here end up issuing a second SYS_getpid syscall that
overwrites stack_rawtp_nofault and stack_rawtp_sleepable?

In glibc, raise(SIGSTOP) calls __pthread_kill_implementation(), which calls
__getpid() and executes SYS_getpid before invoking tgkill(). Because
rawtp_nofault and rawtp_sleepable in
tools/testing/selftests/bpf/progs/test_build_id.c only filter on
target_tgid and target_syscall without disarming after the first hit, the
SYS_getpid inside raise(SIGSTOP) will trigger the BPF program a second
time.

In raw-tp-sleepable-paged-out, the first syscall(SYS_getpid) has already
faulted in uprobe_multi's build ID page, so the second call records the
stack when the page is already resident. Furthermore, when libc.so is built
with -fomit-frame-pointer, unwinding out of __pthread_kill_implementation()
during the second SYS_getpid can fail to reach uprobe_multi, overwriting
the valid trace captured during syscall(SYS_getpid) and causing the
sleepable_build_id assertion in subtest_raw_tp() to fail.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104083833.971911-1-yangfeng59949@163.com?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto
  2026-11-04  8:38 [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto Feng Yang
  2026-11-04  8:38 ` [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint Feng Yang
@ 2026-11-04  9:10 ` bot+bpf-ci
  1 sibling, 0 replies; 5+ messages in thread
From: bot+bpf-ci @ 2026-11-04  9:10 UTC (permalink / raw)
  To: yangfeng59949, song, jolsa, ihor.solodrai, kpsingh, matt, ast,
	daniel, andrii, eddyz87, memxor, martin.lau, yonghong.song, emil,
	rostedt, mhiramat, mathieu.desnoyers
  Cc: bpf, linux-trace-kernel, linux-kselftest, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 4208 bytes --]

> bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto

TL;DR: Commit message and a code comment only: they say
bpf_get_stack_sleepable() uses build_id_parse(), but it appears to use
build_id_parse_file(), and the bpf_spin_lock() rejection claim looks wrong,
since locks already reject helper calls.

> bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto
>
> bpf_get_stack() has two implementations.  bpf_get_stack() passes
> may_fault == false and resolves build IDs with build_id_parse_nofault(),
> so an IP whose backing file page is not resident falls back to
> BPF_STACK_BUILD_ID_IP.  bpf_get_stack_sleepable() passes may_fault == true
> and uses build_id_parse(), which faults the page in and returns a real
> build ID.
>
> Only kprobe/uprobe programs are routed to the sleepable implementation
> today, so the other program types that can be sleepable keep losing
> build IDs for non-resident pages:
>
>  - tracing_prog_func_proto() serves BPF_TRACE_ITER, fentry/fexit/fmod_ret
>    and BPF_TRACE_RAW_TP programs, and falls back to
>    raw_tp_prog_func_proto() for BPF_FUNC_get_stack, which is also the
>    get_func_proto() of BPF_PROG_TYPE_RAW_TRACEPOINT and is reached by
>    BPF_PROG_TYPE_LSM and BPF_PROG_TYPE_SYSCALL through the default cases
>    of bpf_lsm_func_proto() and syscall_prog_func_proto().
>
>  - tp_prog_func_proto() serves BPF_PROG_TYPE_TRACEPOINT programs.
>
> Route them to bpf_get_stack_sleepable() as well and mark the new
> prototypes might_sleep, following
> commit 9d02927fdf4e ("bpf: Mark faultable stack helpers as sleepable"),
> which did the same for bpf_get_task_stack() and uprobe programs.
>
> The verifier then rejects bpf_get_stack() from these program types
> whenever in_sleepable_context() is false: inside bpf_rcu_read_lock(),
> bpf_preempt_disable(), bpf_local_irq_save() and bpf_spin_lock() regions,
> and in callback subprograms running under rcu_read_lock().  This also
> covers calls that do not pass BPF_F_USER_BUILD_ID and would not sleep;
> such programs load today.  This is the same trade off that making the
> faultable stack helpers sleepable made for bpf_get_task_stack().
>
> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
>

Two statements here don't seem to match the code.

The changelog says bpf_get_stack_sleepable() "uses build_id_parse()", and
the new comment in bpf_get_stack_raw_tp_sleepable() says the slot "cannot
be held across the sleep that build_id_parse() may take".  Is that accurate?

With may_fault set, stack_map_get_build_id_offset() takes this path:

    if (may_fault && has_user_ctx) {
            stack_map_get_build_id_offset_sleepable(id_offs, trace_nr);
            return;
    }

and stack_map_get_build_id_offset_sleepable() calls build_id_parse_file(),
not build_id_parse().  The only build_id_parse() call is in
fetch_build_id(), reached from the mmap_read_trylock() loop that is never
entered when may_fault is set.  Should the changelog and the comment name
build_id_parse_file() instead?

The changelog also lists bpf_spin_lock() regions among those where
bpf_get_stack() is now rejected, and says such programs "load today".
Is that right?  While active_locks is nonzero, do_check_insn() already
rejects helper calls before check_helper_call() is reached:

    if (env->cur_state->active_locks) {
            ...
                    insn->imm != BPF_FUNC_spin_unlock &&
                    insn->imm != BPF_FUNC_kptr_xchg) ||
            ...
                    "function calls are not allowed while holding a lock\n");

so bpf_get_stack() inside a bpf_spin_lock() region is not accepted today
either, and this patch changes nothing for that case.  The user-visible
change appears limited to RCU, preempt-disabled and IRQ-disabled regions,
RCU callbacks, and non-sleepable async callbacks such as bpf_timer
callbacks.  Could the bpf_spin_lock() mention be dropped from the
changelog?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41802507259

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint
  2026-11-04  8:38 ` [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint Feng Yang
  2026-11-04  8:57   ` sashiko-bot
@ 2026-11-04  9:24   ` bot+bpf-ci
  1 sibling, 0 replies; 5+ messages in thread
From: bot+bpf-ci @ 2026-11-04  9:24 UTC (permalink / raw)
  To: yangfeng59949, song, jolsa, ihor.solodrai, kpsingh, matt, ast,
	daniel, andrii, eddyz87, memxor, martin.lau, yonghong.song, emil,
	rostedt, mhiramat, mathieu.desnoyers
  Cc: bpf, linux-trace-kernel, linux-kselftest, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]

> selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint

TL;DR:
- Test issue: raise() may call getpid again, so the BPF programs may overwrite
  the stack the test inspects; results may depend on libc
- Nit: usage message omits the new uprobe-paged-out-stop mode

> diff --git a/tools/testing/selftests/bpf/uprobe_multi.c b/tools/testing/selftests/bpf/uprobe_multi.c
> --- a/tools/testing/selftests/bpf/uprobe_multi.c
> +++ b/tools/testing/selftests/bpf/uprobe_multi.c

[ ... ]

> +int __attribute__((weak)) trigger_stop(void)
> +{
> +	int err = prep_build_id_page(false /* page-out build ID */);
> +
> +	if (err)
> +		return err;
> +
> +	/*
> +	 * Make one syscall that the BPF program under test filters on, then
> +	 * stop this process so that the recorded stack cannot be overwritten
> +	 * by another syscall while the caller inspects it.
> +	 */
> +	(void)syscall(SYS_getpid);
> +	raise(SIGSTOP);

With glibc, raise() goes through pthread_kill() which calls __getpid() to
get the tgid for tgkill().  So rawtp_nofault and rawtp_sleepable can match
a second time on id == SYS_getpid, from inside raise(), before SIGSTOP
takes effect.

That second match overwrites stack_rawtp_* and res_rawtp_*, so the stack
that subtest_raw_tp() inspects comes from the getpid stub called by
__pthread_kill_implementation(), not from the explicit syscall(SYS_getpid).
In the sleepable case, that stack is also captured after the first match
has already faulted the build ID page back in.

Whether a uprobe_multi frame shows up then depends on how libc compiles
raise()/pthread_kill().

Could the BPF programs keep only the first match, for example by returning
early once res_rawtp_* is non-zero?  Or could the comment and commit
message mention that raise() issues a matching getpid() as well?

[ ... ]

> +	if (!strcmp("uprobe-paged-out-stop", argv[1]))
> +		return trigger_stop();
>  
>  error:
>  	fprintf(stderr,

This isn't a bug, but main() now accepts "uprobe-paged-out-stop" while the
usage message that follows still lists only
<bench|usdt|uprobe-paged-out|uprobe-paged-in>.  Should the new mode be
added there?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41802507259

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-04  9:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  8:38 [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto Feng Yang
2026-11-04  8:38 ` [PATCH bpf-next v3 2/2] selftests/bpf: Test faulting build IDs from a sleepable raw tracepoint Feng Yang
2026-11-04  8:57   ` sashiko-bot
2026-11-04  9:24   ` bot+bpf-ci
2026-11-04  9:10 ` [PATCH bpf-next v3 1/2] bpf: Add sleepable version of bpf_get_stack in tracing_prog_func_proto and tp_prog_func_proto bot+bpf-ci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox