Linux Trace Kernel
 help / color / mirror / Atom feed
From: Fuyu Zhao <zhaofuyu@vivo.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	haoluo@google.com, jolsa@kernel.org, eddyz87@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, rostedt@goodmis.org,
	mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
	shuah@kernel.org, willemb@google.com, kerneljasonxing@gmail.com,
	paul.chaignon@gmail.com, chen.dylane@linux.dev, memxor@gmail.com,
	martin.kelly@crowdstrike.com, zhaofuyu@vivo.com,
	ameryhung@gmail.com, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Cc: yikai.lin@vivo.com
Subject: [RFC PATCH bpf-next v1 3/3] selftests/bpf: Add selftest for "raw_tp.o"
Date: Wed, 17 Sep 2025 15:22:42 +0800	[thread overview]
Message-ID: <20250917072242.674528-4-zhaofuyu@vivo.com> (raw)
In-Reply-To: <20250917072242.674528-1-zhaofuyu@vivo.com>

Add test for the new BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE program type.
This test verifies whether a BPF program can successfully override the
target tracepoint probe function.

Signed-off-by: Fuyu Zhao <zhaofuyu@vivo.com>
---
 .../bpf/prog_tests/raw_tp_override_test_run.c | 23 +++++++++++++++++++
 .../bpf/progs/test_raw_tp_override_test_run.c | 20 ++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    |  7 ++++++
 3 files changed, 50 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_run.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_raw_tp_override_test_run.c

diff --git a/tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_run.c b/tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_run.c
new file mode 100644
index 000000000000..02301253cd9b
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/raw_tp_override_test_run.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "bpf/libbpf_internal.h"
+#include "test_raw_tp_override_test_run.skel.h"
+
+void test_raw_tp_override_test_run(void)
+{
+	struct test_raw_tp_override_test_run *skel;
+
+	skel = test_raw_tp_override_test_run__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "test_raw_tp_override_test_run__open_and_load"))
+		return;
+
+	if (!ASSERT_OK(test_raw_tp_override_test_run__attach(skel),
+		       "test_raw_tp_override_test_run__attach"))
+		goto cleanup;
+	ASSERT_OK(trigger_module_test_write(1), "trigger_write");
+	ASSERT_EQ(skel->bss->flag, 1, "check_flag");
+
+cleanup:
+	test_raw_tp_override_test_run__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/test_raw_tp_override_test_run.c b/tools/testing/selftests/bpf/progs/test_raw_tp_override_test_run.c
new file mode 100644
index 000000000000..eb6d24e1c737
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_raw_tp_override_test_run.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+__u32 flag = 0;
+
+/**
+ * This program overrides raw_tp_override_probe handler in
+ * tracepoint bpf_testmode_test_raw_tp_null_tp.
+ */
+SEC("raw_tp.o/bpf_testmod_test_write_bare_tp:raw_tp_override_probe")
+int BPF_PROG(tp_override, struct task_struct *task, char *comm)
+{
+	flag = 1;
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 2beb9b2fcbd8..7a49178d2343 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -1628,6 +1628,11 @@ static struct bpf_testmod_multi_st_ops multi_st_ops_cfi_stubs = {
 	.test_1 = bpf_testmod_multi_st_ops__test_1,
 };
 
+static void raw_tp_override_probe(void *ignored, struct task_struct *task,
+				  struct bpf_testmod_test_write_ctx *ctx)
+{
+}
+
 struct bpf_struct_ops testmod_multi_st_ops = {
 	.verifier_ops = &bpf_testmod_verifier_ops,
 	.init = multi_st_ops_init,
@@ -1665,6 +1670,7 @@ static int bpf_testmod_init(void)
 	ret = ret ?: register_btf_id_dtor_kfuncs(bpf_testmod_dtors,
 						 ARRAY_SIZE(bpf_testmod_dtors),
 						 THIS_MODULE);
+	ret = ret ?: register_trace_bpf_testmod_test_write_bare_tp(raw_tp_override_probe, NULL);
 	if (ret < 0)
 		return ret;
 	if (bpf_fentry_test1(0) < 0)
@@ -1701,6 +1707,7 @@ static void bpf_testmod_exit(void)
 	bpf_kfunc_close_sock();
 	sysfs_remove_bin_file(kernel_kobj, &bin_attr_bpf_testmod_file);
 	unregister_bpf_testmod_uprobe();
+	unregister_trace_bpf_testmod_test_write_bare_tp(raw_tp_override_probe, NULL);
 }
 
 module_init(bpf_testmod_init);
-- 
2.43.0


  parent reply	other threads:[~2025-09-17  7:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17  7:22 [RFC PATCH bpf-next v1 0/3] bpf: Add BPF program type for overriding tracepoint probes Fuyu Zhao
2025-09-17  7:22 ` [RFC PATCH bpf-next v1 1/3] bpf: Introduce BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE Fuyu Zhao
2025-09-17  7:22 ` [RFC PATCH bpf-next v1 2/3] libbpf: Add support for BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE Fuyu Zhao
2025-09-17  7:22 ` Fuyu Zhao [this message]
2025-09-17 19:30 ` [RFC PATCH bpf-next v1 0/3] bpf: Add BPF program type for overriding tracepoint probes Steven Rostedt
2025-09-18 12:33   ` Fuyu Zhao
2025-09-18 15:24     ` Steven Rostedt
2025-09-19 12:54       ` Fuyu Zhao
2025-09-21 21:08       ` Chuck Wolber
2025-09-17 20:02 ` Song Liu
2025-09-18  8:05   ` Fuyu Zhao
2025-09-18  8:47     ` Jiri Olsa
2025-09-18 13:15       ` Fuyu Zhao
2025-09-18 15:32         ` Steven Rostedt
2025-09-19 13:00           ` Fuyu Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250917072242.674528-4-zhaofuyu@vivo.com \
    --to=zhaofuyu@vivo.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chen.dylane@linux.dev \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=jolsa@kernel.org \
    --cc=kerneljasonxing@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.kelly@crowdstrike.com \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=paul.chaignon@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=willemb@google.com \
    --cc=yikai.lin@vivo.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox