[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260109153420.32181-4-leon.hwang@linux.dev>
Date: Fri, 9 Jan 2026 23:34:20 +0800
From: Leon Hwang <leon.hwang@...ux.dev>
To: bpf@...r.kernel.org
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
"David S . Miller" <davem@...emloft.net>,
David Ahern <dsahern@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
x86@...nel.org,
"H . Peter Anvin" <hpa@...or.com>,
Matt Bobrowski <mattbobrowski@...gle.com>,
Steven Rostedt <rostedt@...dmis.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Shuah Khan <shuah@...nel.org>,
Leon Hwang <leon.hwang@...ux.dev>,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org,
kernel-patches-bot@...com
Subject: [PATCH bpf-next 3/3] selftests/bpf: Add BPF_BRANCH_SNAPSHOT_F_COPY test
Add test for BPF_BRANCH_SNAPSHOT_F_COPY flag by adding flag to the
callsite of bpf_get_branch_snapshot helper.
Signed-off-by: Leon Hwang <leon.hwang@...ux.dev>
---
.../bpf/prog_tests/get_branch_snapshot.c | 26 ++++++++++++++++---
.../selftests/bpf/progs/get_branch_snapshot.c | 3 ++-
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
index 0394a1156d99..6b8ab1655ab0 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_branch_snapshot.c
@@ -73,7 +73,7 @@ static void close_perf_events(void)
free(pfd_array);
}
-void serial_test_get_branch_snapshot(void)
+static void test_branch_snapshot(int flags)
{
struct get_branch_snapshot *skel = NULL;
int err;
@@ -89,8 +89,14 @@ void serial_test_get_branch_snapshot(void)
goto cleanup;
}
- skel = get_branch_snapshot__open_and_load();
- if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open_and_load"))
+ skel = get_branch_snapshot__open();
+ if (!ASSERT_OK_PTR(skel, "get_branch_snapshot__open"))
+ goto cleanup;
+
+ skel->rodata->flags = flags;
+
+ err = get_branch_snapshot__load(skel);
+ if (!ASSERT_OK(err, "get_branch_snapshot__load"))
goto cleanup;
err = kallsyms_find("bpf_testmod_loop_test", &skel->bss->address_low);
@@ -128,3 +134,17 @@ void serial_test_get_branch_snapshot(void)
get_branch_snapshot__destroy(skel);
close_perf_events();
}
+
+void serial_test_get_branch_snapshot(void)
+{
+ test_branch_snapshot(0);
+}
+
+enum {
+ BPF_BRANCH_SNAPSHOT_F_COPY = 1, /* Copy branch snapshot from bpf_branch_snapshot. */
+};
+
+void serial_test_copy_branch_snapshot(void)
+{
+ test_branch_snapshot(BPF_BRANCH_SNAPSHOT_F_COPY);
+}
diff --git a/tools/testing/selftests/bpf/progs/get_branch_snapshot.c b/tools/testing/selftests/bpf/progs/get_branch_snapshot.c
index 511ac634eef0..47a1984bdf46 100644
--- a/tools/testing/selftests/bpf/progs/get_branch_snapshot.c
+++ b/tools/testing/selftests/bpf/progs/get_branch_snapshot.c
@@ -6,6 +6,7 @@
char _license[] SEC("license") = "GPL";
+volatile const int flags = 0;
__u64 test1_hits = 0;
__u64 address_low = 0;
__u64 address_high = 0;
@@ -25,7 +26,7 @@ int BPF_PROG(test1, int n, int ret)
{
long i;
- total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), 0);
+ total_entries = bpf_get_branch_snapshot(entries, sizeof(entries), flags);
total_entries /= sizeof(struct perf_branch_entry);
for (i = 0; i < ENTRY_CNT; i++) {
--
2.52.0
Powered by blists - more mailing lists