From: Maxim Khmelevskii <max@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, Ilya Leoshkevich <iii@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>
Subject: [PATCH bpf-next 2/2] selftests/bpf: Add test for bpf_get_smp_processor_id
Date: Fri, 3 Jul 2026 14:51:36 +0200 [thread overview]
Message-ID: <20260703125648.919196-6-max@linux.ibm.com> (raw)
In-Reply-To: <20260703125648.919196-4-max@linux.ibm.com>
Add a test which checks on each CPU that the
bpf_get_smp_processor_id BPF helper is returning
the correct CPU number.
Signed-off-by: Maxim Khmelevskii <max@linux.ibm.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
.../bpf/prog_tests/get_smp_processor_id.c | 45 +++++++++++++++++++
.../bpf/progs/get_smp_processor_id.c | 20 +++++++++
2 files changed, 65 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/get_smp_processor_id.c
create mode 100644 tools/testing/selftests/bpf/progs/get_smp_processor_id.c
diff --git a/tools/testing/selftests/bpf/prog_tests/get_smp_processor_id.c b/tools/testing/selftests/bpf/prog_tests/get_smp_processor_id.c
new file mode 100644
index 000000000000..1b5c738ab81f
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/get_smp_processor_id.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "bpf/libbpf_internal.h"
+#include "get_smp_processor_id.skel.h"
+
+void test_get_smp_processor_id(void)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, opts,
+ .flags = BPF_F_TEST_RUN_ON_CPU,
+ .cpu = 0,
+ );
+ struct get_smp_processor_id *skel;
+ int prog_fd, err, online_cpu_nr, i;
+ bool *online = NULL;
+
+ err = parse_cpu_mask_file("/sys/devices/system/cpu/online",
+ &online, &online_cpu_nr);
+ if (!ASSERT_OK(err, "parse_cpu_mask_file"))
+ return;
+
+ skel = get_smp_processor_id__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "get_smp_processor_id__open_and_load"))
+ goto cleanup;
+
+ prog_fd = bpf_program__fd(skel->progs.call_bpf_get_smp_processor_id);
+
+ for (i = 0; i < online_cpu_nr; i++) {
+ if (!online[i])
+ continue;
+
+ opts.cpu = i;
+ skel->bss->cpu_nr_result = -1;
+
+ err = bpf_prog_test_run_opts(prog_fd, &opts);
+ if (!ASSERT_OK(err, "bpf_prog_test_run_opts"))
+ goto cleanup;
+
+ ASSERT_EQ(skel->bss->cpu_nr_result, opts.cpu, "cpu_nr_result");
+ }
+
+cleanup:
+ free(online);
+ get_smp_processor_id__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/get_smp_processor_id.c b/tools/testing/selftests/bpf/progs/get_smp_processor_id.c
new file mode 100644
index 000000000000..cf4791a5cf07
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/get_smp_processor_id.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+__u64 cpu_nr_result;
+
+SEC("raw_tp")
+void call_bpf_get_smp_processor_id(void)
+{
+ register __u64 r0 asm("r0") = -1;
+ asm volatile ("call %[bpf_get_smp_processor_id];"
+ : "+r"(r0)
+ : __imm(bpf_get_smp_processor_id)
+ : "r1", "r2", "r3", "r4", "r5", "memory");
+ cpu_nr_result = r0;
+}
+
+char _license[] SEC("license") = "GPL";
--
2.54.0
prev parent reply other threads:[~2026-07-03 12:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 12:51 [PATCH bpf-next 0/2] s390/bpf: Replace ly instruction with llgf Maxim Khmelevskii
2026-07-03 12:51 ` [PATCH bpf-next 1/2] " Maxim Khmelevskii
2026-07-03 12:51 ` Maxim Khmelevskii [this message]
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=20260703125648.919196-6-max@linux.ibm.com \
--to=max@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
/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