From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v1 2/2] selftests/bpf: Test res spin locks in tracing programs
Date: Fri, 24 Jul 2026 22:16:32 +0200 [thread overview]
Message-ID: <20260724201634.3025247-3-memxor@gmail.com> (raw)
In-Reply-To: <20260724201634.3025247-1-memxor@gmail.com>
Exercise bpf_res_spin_lock() from kprobe, tracepoint, perf event, and raw
tracepoint programs. Keep the existing bpf_spin_lock() rejection checks so
the tests cover the split verifier policy for the two lock types.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
.../bpf/progs/verifier_helper_restricted.c | 66 +++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_helper_restricted.c b/tools/testing/selftests/bpf/progs/verifier_helper_restricted.c
index 889c9b78b912..b3beb8f6dd19 100644
--- a/tools/testing/selftests/bpf/progs/verifier_helper_restricted.c
+++ b/tools/testing/selftests/bpf/progs/verifier_helper_restricted.c
@@ -10,6 +10,18 @@ struct val {
struct bpf_spin_lock l;
};
+struct bpf_res_spin_lock {
+ __u32 val;
+};
+
+struct res_val {
+ int cnt;
+ struct bpf_res_spin_lock l;
+};
+
+extern int bpf_res_spin_lock(struct bpf_res_spin_lock *lock) __ksym;
+extern void bpf_res_spin_unlock(struct bpf_res_spin_lock *lock) __ksym;
+
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
@@ -17,6 +29,28 @@ struct {
__type(value, struct val);
} map_spin_lock SEC(".maps");
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, int);
+ __type(value, struct res_val);
+} map_res_spin_lock SEC(".maps");
+
+static __always_inline int use_res_spin_lock(void)
+{
+ struct res_val *val;
+ int key = 0;
+
+ val = bpf_map_lookup_elem(&map_res_spin_lock, &key);
+ if (!val)
+ return 0;
+ if (bpf_res_spin_lock(&val->l))
+ return 0;
+ val->cnt++;
+ bpf_res_spin_unlock(&val->l);
+ return 0;
+}
+
SEC("kprobe")
__description("bpf_ktime_get_coarse_ns is forbidden in BPF_PROG_TYPE_KPROBE")
__failure __msg("program of this type cannot use helper bpf_ktime_get_coarse_ns")
@@ -165,4 +199,36 @@ l0_%=: exit; \
: __clobber_all);
}
+SEC("kprobe")
+__description("bpf_res_spin_lock is allowed in BPF_PROG_TYPE_KPROBE")
+__success
+int res_spin_lock_bpf_prog_type_kprobe(void *ctx)
+{
+ return use_res_spin_lock();
+}
+
+SEC("tracepoint")
+__description("bpf_res_spin_lock is allowed in BPF_PROG_TYPE_TRACEPOINT")
+__success
+int res_spin_lock_bpf_prog_type_tracepoint(void *ctx)
+{
+ return use_res_spin_lock();
+}
+
+SEC("perf_event")
+__description("bpf_res_spin_lock is allowed in BPF_PROG_TYPE_PERF_EVENT")
+__success
+int res_spin_lock_bpf_prog_type_perf_event(void *ctx)
+{
+ return use_res_spin_lock();
+}
+
+SEC("raw_tracepoint")
+__description("bpf_res_spin_lock is allowed in BPF_PROG_TYPE_RAW_TRACEPOINT")
+__success
+int res_spin_lock_bpf_prog_type_raw_tracepoint(void *ctx)
+{
+ return use_res_spin_lock();
+}
+
char _license[] SEC("license") = "GPL";
--
2.53.0
prev parent reply other threads:[~2026-07-24 20:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 20:16 [PATCH bpf-next v1 0/2] Open up res_spin_lock() in all contexts Kumar Kartikeya Dwivedi
2026-07-24 20:16 ` [PATCH bpf-next v1 1/2] bpf: Allow bpf_res_spin_lock() " Kumar Kartikeya Dwivedi
2026-07-24 20:16 ` Kumar Kartikeya Dwivedi [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=20260724201634.3025247-3-memxor@gmail.com \
--to=memxor@gmail.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=kernel-team@meta.com \
--cc=kkd@meta.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