From: Karl Mehltretter <kmehltretter@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Alexei Starovoitov <ast@kernel.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
Jonathan Corbet <corbet@lwn.net>,
David Hildenbrand <david@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
David Stevens <stevensd@google.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Shuah Khan <shuah@kernel.org>, Amery Hung <ameryhung@gmail.com>,
Swaraj Gaikwad <swarajgaikwad1925@gmail.com>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
linux-mm@kvack.org, linux-rt-devel@lists.linux.dev,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
cgroups@vger.kernel.org
Subject: [RFC PATCH v2 3/3] selftests/bpf: exercise task storage from hrtimer_start
Date: Mon, 5 Oct 2026 09:06:25 +0200 [thread overview]
Message-ID: <20261005070625.8871-4-kmehltretter@gmail.com> (raw)
In-Reply-To: <20261005070625.8871-1-kmehltretter@gmail.com>
No BPF selftest creates task-local storage from a tracepoint which runs
while an hrtimer base raw lock is held. On PREEMPT_RT, this can exercise
allocator rtmutexes inside a raw-lock section.
Attach a program to tp_btf/hrtimer_start for the test process. Create and
delete task storage on every event and trigger 1,000 events with
timerfd_settime(). Detach the program before reading its counters, then
require at least one successful allocation and balanced attempt and
outcome counters. Allocation failure remains valid for the best-effort
no-lock API.
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
.../bpf/prog_tests/task_storage_hrtimer.c | 50 +++++++++++++++++++
.../bpf/progs/task_storage_hrtimer.c | 48 ++++++++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/task_storage_hrtimer.c
create mode 100644 tools/testing/selftests/bpf/progs/task_storage_hrtimer.c
diff --git a/tools/testing/selftests/bpf/prog_tests/task_storage_hrtimer.c b/tools/testing/selftests/bpf/prog_tests/task_storage_hrtimer.c
new file mode 100644
index 000000000000..216e66263bf6
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/task_storage_hrtimer.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <sys/timerfd.h>
+#include <unistd.h>
+
+#include <test_progs.h>
+#include "task_storage_hrtimer.skel.h"
+
+#define TRIGGER_COUNT 1000
+
+void test_task_storage_hrtimer(void)
+{
+ struct itimerspec timer = {
+ .it_value.tv_nsec = 1000000,
+ };
+ struct task_storage_hrtimer *skel;
+ int err, fd = -1, i;
+
+ skel = task_storage_hrtimer__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+ return;
+
+ skel->bss->target_tgid = getpid();
+ err = task_storage_hrtimer__attach(skel);
+ if (!ASSERT_OK(err, "skel_attach"))
+ goto cleanup;
+
+ fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
+ if (!ASSERT_GE(fd, 0, "timerfd_create"))
+ goto cleanup;
+
+ for (i = 0; i < TRIGGER_COUNT; i++) {
+ err = timerfd_settime(fd, 0, &timer, NULL);
+ if (!ASSERT_OK(err, "timerfd_settime"))
+ goto cleanup;
+ }
+
+ task_storage_hrtimer__detach(skel);
+
+ ASSERT_GE(skel->bss->seen, TRIGGER_COUNT, "seen");
+ ASSERT_EQ(skel->bss->attempted, skel->bss->seen, "attempted");
+ ASSERT_GT(skel->bss->succeeded, 0, "succeeded");
+ ASSERT_EQ(skel->bss->delete_errors, 0, "delete_errors");
+ ASSERT_EQ(skel->bss->attempted,
+ skel->bss->succeeded + skel->bss->failed, "attempts");
+
+cleanup:
+ if (fd >= 0)
+ close(fd);
+ task_storage_hrtimer__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/task_storage_hrtimer.c b/tools/testing/selftests/bpf/progs/task_storage_hrtimer.c
new file mode 100644
index 000000000000..a53c966f15b5
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/task_storage_hrtimer.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+struct {
+ __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
+ __uint(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, long);
+} task_storage SEC(".maps");
+
+u32 target_tgid;
+u64 seen;
+u64 attempted;
+u64 succeeded;
+u64 failed;
+u64 delete_errors;
+
+SEC("tp_btf/hrtimer_start")
+int BPF_PROG(on_hrtimer_start, struct hrtimer *timer,
+ enum hrtimer_mode mode, bool was_armed)
+{
+ struct task_struct *task;
+ long *storage;
+
+ if (bpf_get_current_pid_tgid() >> 32 != target_tgid)
+ return 0;
+
+ seen++;
+ attempted++;
+ task = bpf_get_current_task_btf();
+ storage = bpf_task_storage_get(&task_storage, task, NULL,
+ BPF_LOCAL_STORAGE_GET_F_CREATE);
+ if (!storage) {
+ failed++;
+ return 0;
+ }
+
+ if (bpf_task_storage_delete(&task_storage, task))
+ delete_errors++;
+ else
+ succeeded++;
+
+ return 0;
+}
--
2.53.0
next prev parent reply other threads:[~2026-10-05 7:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 7:06 [RFC PATCH v2 0/3] locking, mm: Add atomic allocator trylocks on RT Karl Mehltretter
2026-10-05 7:06 ` [RFC PATCH v2 1/3] locking/rtmutex: Support atomic PREEMPT_RT spin trylocks Karl Mehltretter
2026-10-05 7:06 ` [RFC PATCH v2 2/3] mm: use atomic RT trylocks for no-lock allocation Karl Mehltretter
2026-10-05 7:06 ` Karl Mehltretter [this message]
2026-10-05 7:53 ` [RFC PATCH v2 3/3] selftests/bpf: exercise task storage from hrtimer_start bot+bpf-ci
2026-10-07 17:15 ` [RFC PATCH v2 0/3] locking, mm: Add atomic allocator trylocks on RT Harry Yoo
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=20261005070625.8871-4-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=clrkwllms@kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=harry@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=martin.lau@linux.dev \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=stevensd@google.com \
--cc=swarajgaikwad1925@gmail.com \
--cc=tglx@linutronix.de \
--cc=vbabka@kernel.org \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®