* [PATCH bpf v3 1/2] bpf: Reject bpf_timer for PREEMPT_RT
2025-09-10 12:57 [PATCH bpf v3 0/2] bpf: Reject bpf_timer for PREEMPT_RT Leon Hwang
@ 2025-09-10 12:57 ` Leon Hwang
2025-09-10 12:57 ` [PATCH bpf v3 2/2] selftests/bpf: Skip timer cases when bpf_timer is not supported Leon Hwang
2025-09-10 19:40 ` [PATCH bpf v3 0/2] bpf: Reject bpf_timer for PREEMPT_RT patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Leon Hwang @ 2025-09-10 12:57 UTC (permalink / raw)
To: bpf
Cc: ast, andrii, daniel, yepeilin, martin.lau, eddyz87, song,
yonghong.song, leon.hwang, kernel-patches-bot
When enable CONFIG_PREEMPT_RT, the kernel will warn when run timer
selftests by './test_progs -t timer':
BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
In order to avoid such warning, reject bpf_timer in verifier when
PREEMPT_RT is enabled.
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
kernel/bpf/verifier.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index c89e2b1bc644b..9fb1f957a0937 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -8547,6 +8547,10 @@ static int process_timer_func(struct bpf_verifier_env *env, int regno,
verifier_bug(env, "Two map pointers in a timer helper");
return -EFAULT;
}
+ if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ verbose(env, "bpf_timer cannot be used for PREEMPT_RT.\n");
+ return -EOPNOTSUPP;
+ }
meta->map_uid = reg->map_uid;
meta->map_ptr = map;
return 0;
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH bpf v3 2/2] selftests/bpf: Skip timer cases when bpf_timer is not supported
2025-09-10 12:57 [PATCH bpf v3 0/2] bpf: Reject bpf_timer for PREEMPT_RT Leon Hwang
2025-09-10 12:57 ` [PATCH bpf v3 1/2] " Leon Hwang
@ 2025-09-10 12:57 ` Leon Hwang
2025-09-10 19:40 ` [PATCH bpf v3 0/2] bpf: Reject bpf_timer for PREEMPT_RT patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Leon Hwang @ 2025-09-10 12:57 UTC (permalink / raw)
To: bpf
Cc: ast, andrii, daniel, yepeilin, martin.lau, eddyz87, song,
yonghong.song, leon.hwang, kernel-patches-bot
When enable CONFIG_PREEMPT_RT, verifier will reject bpf_timer with
returning -EOPNOTSUPP.
Therefore, skip test cases when errno is EOPNOTSUPP.
cd tools/testing/selftests/bpf
./test_progs -t timer
125 free_timer:SKIP
456 timer:SKIP
457/1 timer_crash/array:SKIP
457/2 timer_crash/hash:SKIP
457 timer_crash:SKIP
458 timer_lockup:SKIP
459 timer_mim:SKIP
Summary: 5/0 PASSED, 6 SKIPPED, 0 FAILED
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
tools/testing/selftests/bpf/prog_tests/free_timer.c | 4 ++++
tools/testing/selftests/bpf/prog_tests/timer.c | 4 ++++
tools/testing/selftests/bpf/prog_tests/timer_crash.c | 4 ++++
tools/testing/selftests/bpf/prog_tests/timer_lockup.c | 4 ++++
tools/testing/selftests/bpf/prog_tests/timer_mim.c | 4 ++++
5 files changed, 20 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/free_timer.c b/tools/testing/selftests/bpf/prog_tests/free_timer.c
index b7b77a6b29799..0de8facca4c5b 100644
--- a/tools/testing/selftests/bpf/prog_tests/free_timer.c
+++ b/tools/testing/selftests/bpf/prog_tests/free_timer.c
@@ -124,6 +124,10 @@ void test_free_timer(void)
int err;
skel = free_timer__open_and_load();
+ if (!skel && errno == EOPNOTSUPP) {
+ test__skip();
+ return;
+ }
if (!ASSERT_OK_PTR(skel, "open_load"))
return;
diff --git a/tools/testing/selftests/bpf/prog_tests/timer.c b/tools/testing/selftests/bpf/prog_tests/timer.c
index d66687f1ee6a8..56f660ca567ba 100644
--- a/tools/testing/selftests/bpf/prog_tests/timer.c
+++ b/tools/testing/selftests/bpf/prog_tests/timer.c
@@ -86,6 +86,10 @@ void serial_test_timer(void)
int err;
timer_skel = timer__open_and_load();
+ if (!timer_skel && errno == EOPNOTSUPP) {
+ test__skip();
+ return;
+ }
if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load"))
return;
diff --git a/tools/testing/selftests/bpf/prog_tests/timer_crash.c b/tools/testing/selftests/bpf/prog_tests/timer_crash.c
index f74b82305da8c..b841597c8a3a3 100644
--- a/tools/testing/selftests/bpf/prog_tests/timer_crash.c
+++ b/tools/testing/selftests/bpf/prog_tests/timer_crash.c
@@ -12,6 +12,10 @@ static void test_timer_crash_mode(int mode)
struct timer_crash *skel;
skel = timer_crash__open_and_load();
+ if (!skel && errno == EOPNOTSUPP) {
+ test__skip();
+ return;
+ }
if (!ASSERT_OK_PTR(skel, "timer_crash__open_and_load"))
return;
skel->bss->pid = getpid();
diff --git a/tools/testing/selftests/bpf/prog_tests/timer_lockup.c b/tools/testing/selftests/bpf/prog_tests/timer_lockup.c
index 1a2f99596916f..eb303fa1e09af 100644
--- a/tools/testing/selftests/bpf/prog_tests/timer_lockup.c
+++ b/tools/testing/selftests/bpf/prog_tests/timer_lockup.c
@@ -59,6 +59,10 @@ void test_timer_lockup(void)
}
skel = timer_lockup__open_and_load();
+ if (!skel && errno == EOPNOTSUPP) {
+ test__skip();
+ return;
+ }
if (!ASSERT_OK_PTR(skel, "timer_lockup__open_and_load"))
return;
diff --git a/tools/testing/selftests/bpf/prog_tests/timer_mim.c b/tools/testing/selftests/bpf/prog_tests/timer_mim.c
index 9ff7843909e7d..c930c7d7105b9 100644
--- a/tools/testing/selftests/bpf/prog_tests/timer_mim.c
+++ b/tools/testing/selftests/bpf/prog_tests/timer_mim.c
@@ -65,6 +65,10 @@ void serial_test_timer_mim(void)
goto cleanup;
timer_skel = timer_mim__open_and_load();
+ if (!timer_skel && errno == EOPNOTSUPP) {
+ test__skip();
+ return;
+ }
if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load"))
goto cleanup;
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH bpf v3 0/2] bpf: Reject bpf_timer for PREEMPT_RT
2025-09-10 12:57 [PATCH bpf v3 0/2] bpf: Reject bpf_timer for PREEMPT_RT Leon Hwang
2025-09-10 12:57 ` [PATCH bpf v3 1/2] " Leon Hwang
2025-09-10 12:57 ` [PATCH bpf v3 2/2] selftests/bpf: Skip timer cases when bpf_timer is not supported Leon Hwang
@ 2025-09-10 19:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-10 19:40 UTC (permalink / raw)
To: Leon Hwang
Cc: bpf, ast, andrii, daniel, yepeilin, martin.lau, eddyz87, song,
yonghong.song, kernel-patches-bot
Hello:
This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 10 Sep 2025 20:57:38 +0800 you wrote:
> While running './test_progs -t timer' to validate the test case from
> "selftests/bpf: Introduce experimental bpf_in_interrupt()"[0] for
> PREEMPT_RT, I encountered a kernel warning:
>
> BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
>
> To address this, reject bpf_timer usage in the verifier when
> PREEMPT_RT is enabled, and skip the corresponding timer selftests.
>
> [...]
Here is the summary with links:
- [bpf,v3,1/2] bpf: Reject bpf_timer for PREEMPT_RT
https://git.kernel.org/bpf/bpf/c/e25ddfb388c8
- [bpf,v3,2/2] selftests/bpf: Skip timer cases when bpf_timer is not supported
https://git.kernel.org/bpf/bpf/c/fbdd61c94bcb
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread