From: "Thiébaud Weksteen" <tweek@google.com>
To: Quentin Monnet <qmo@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Shuah Khan <shuah@kernel.org>, Leon Hwang <leon.hwang@linux.dev>
Cc: "Thiébaud Weksteen" <tweek@google.com>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Sid Nayyar" <sidnayyar@google.com>
Subject: [PATCH bpf 1/3] selftests/bpf: Move verifier failure tests out of test_global_percpu_data
Date: Wed, 25 Nov 2026 11:49:09 +1100 [thread overview]
Message-ID: <20261125004911.3937193-2-tweek@google.com> (raw)
In-Reply-To: <20261125004911.3937193-1-tweek@google.com>
Commit 4c9241bd731a ("selftests/bpf: Add tests to verify global percpu
data") added test_global_percpu_data.c to LSKELS_EXTRA. Later, commit
1ed2294b31fc ("selftests/bpf: Test verifier log for global percpu data")
added two verifier failure tests (verifier_strncmp and
verifier_snprintf), both marked as non-autoload (SEC("?kprobe")).
When bpftool generates light skeletons, non-autoload programs are
skipped during loading, causing the loader program to store subsequent
program FDs into incorrect skeleton struct fields (for example,
dump_percpu_data's FD was stored into verifier_strncmp's descriptor,
leaving dump_percpu_data.prog_fd unpopulated).
Move the two verifier failure tests to a dedicated test file,
test_global_percpu_data_failure.c, and run them via RUN_TESTS in
global_data_init.c. This leaves test_global_percpu_data.c with only
autoloaded programs, allowing its light skeleton to be generated cleanly
and preparing selftests for rejecting non-autoload programs in light
skeletons.
Fixes: 1ed2294b31fc ("selftests/bpf: Test verifier log for global percpu data")
Signed-off-by: Thiébaud Weksteen <tweek@google.com>
---
.../bpf/prog_tests/global_data_init.c | 3 +-
.../bpf/progs/test_global_percpu_data.c | 23 --------------
.../progs/test_global_percpu_data_failure.c | 30 +++++++++++++++++++
3 files changed, 32 insertions(+), 24 deletions(-)
create mode 100644 tools/testing/selftests/bpf/progs/test_global_percpu_data_failure.c
diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 7c539cbcf3a1..dbb7de534f7d 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -3,6 +3,7 @@
#include "bpf/libbpf_internal.h"
#include "test_global_percpu_data.skel.h"
#include "test_global_percpu_data.lskel.h"
+#include "test_global_percpu_data_failure.skel.h"
void test_global_data_init(void)
{
@@ -372,7 +373,7 @@ static void test_global_percpu_data_rdonly_direct_write(void)
static void test_global_percpu_data_verifier_log(void)
{
- RUN_TESTS(test_global_percpu_data);
+ RUN_TESTS(test_global_percpu_data_failure);
}
static void test_global_percpu_data_iter(void)
diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
index 2765cd46e9af..bc748df4a6cc 100644
--- a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
+++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
@@ -42,29 +42,6 @@ int update_percpu_data(void *ctx)
return 0;
}
-static const char fmt[] SEC(".percpu.fmt") = "data %d\n";
-
-SEC("?kprobe")
-__failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string")
-int verifier_strncmp(void *ctx)
-{
- return bpf_strncmp("test", 5, fmt);
-}
-
-SEC("?kprobe")
-__failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string")
-int verifier_snprintf(void *ctx)
-{
- u64 args[] = { data };
- char buf[128];
- int len;
-
- len = bpf_snprintf(buf, sizeof(buf), fmt, args, sizeof(args));
- if (len > 0)
- bpf_printk("snprintf: %s\n", buf);
- return 0;
-}
-
volatile const __u32 num_cpus = 0;
volatile const int num_off;
volatile const int elem_sz;
diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data_failure.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data_failure.c
new file mode 100644
index 000000000000..3a823acb42d7
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data_failure.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+int data SEC(".percpu") = -1;
+static const char fmt[] SEC(".percpu.fmt") = "data %d\n";
+
+SEC("?kprobe")
+__failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string")
+int verifier_strncmp(void *ctx)
+{
+ return bpf_strncmp("test", 5, fmt);
+}
+
+SEC("?kprobe")
+__failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string")
+int verifier_snprintf(void *ctx)
+{
+ u64 args[] = { data };
+ char buf[128];
+ int len;
+
+ len = bpf_snprintf(buf, sizeof(buf), fmt, args, sizeof(args));
+ if (len > 0)
+ bpf_printk("snprintf: %s\n", buf);
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
--
2.56.1.831.g720f3f5937-goog
next prev parent reply other threads:[~2026-11-25 0:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 0:49 [PATCH bpf 0/3] bpftool: Reject non-autoload programs for light skeletons Thiébaud Weksteen
2026-11-25 0:49 ` Thiébaud Weksteen [this message]
2026-11-26 15:33 ` [PATCH bpf 1/3] selftests/bpf: Move verifier failure tests out of test_global_percpu_data Quentin Monnet
2026-11-25 0:49 ` [PATCH bpf 2/3] bpftool: Reject non-autoload programs for light skeletons Thiébaud Weksteen
2026-11-25 0:59 ` sashiko-bot
2026-11-26 15:34 ` Quentin Monnet
2026-11-25 0:49 ` [PATCH bpf 3/3] selftests/bpf: Test non-autoload rejection in " Thiébaud Weksteen
2026-11-26 15:33 ` Quentin Monnet
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=20261125004911.3937193-2-tweek@google.com \
--to=tweek@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=leon.hwang@linux.dev \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=qmo@kernel.org \
--cc=shuah@kernel.org \
--cc=sidnayyar@google.com \
--cc=song@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.