* [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state
@ 2026-05-23 18:51 Karl Mehltretter
2026-05-23 18:51 ` [PATCH 1/2] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT Karl Mehltretter
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Karl Mehltretter @ 2026-05-23 18:51 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Andrew Morton,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
linux-kernel, linux-rt-devel, Karl Mehltretter
Hi,
the lockdep selftests deliberately run broken locking patterns. On
PREEMPT_RT, some of those paths also leave task-local RT state behind, and
dotest() has to restore that state before the next testcase.
Patch 1 restores current->migration_disabled on all PREEMPT_RT builds.
The missing restore is visible with CONFIG_SMP=n as a pinned-lock warning,
"bad: scheduling from the idle thread!" and a panic after the selftests.
Patch 2 restores current->sched_rt_mutex after WW-mutex selftests. Without
that, stale RT-mutex scheduler state produces rt_mutex_pre_schedule()
warnings in later testcases.
Both changes are in dotest()'s PREEMPT_RT cleanup path in
lib/locking-selftest.c.
Tested on x86_64 QEMU with CONFIG_PREEMPT_RT=y,
CONFIG_DEBUG_LOCKING_API_SELFTESTS=y, CONFIG_LOCKDEP=y and
CONFIG_PROVE_LOCKING=y. Both CONFIG_SMP=n and CONFIG_SMP=y configurations
boot to userspace without the pinned-lock panic or rt_mutex_pre_schedule()
warnings.
Karl Mehltretter (2):
lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT
lockdep/selftests: Restore sched_rt_mutex state on PREEMPT_RT
lib/locking-selftest.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT
2026-05-23 18:51 [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Karl Mehltretter
@ 2026-05-23 18:51 ` Karl Mehltretter
2026-06-03 14:25 ` [tip: locking/core] " tip-bot2 for Karl Mehltretter
2026-05-23 18:51 ` [PATCH 2/2] lockdep/selftests: Restore sched_rt_mutex " Karl Mehltretter
2026-06-01 8:43 ` [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Sebastian Andrzej Siewior
2 siblings, 1 reply; 6+ messages in thread
From: Karl Mehltretter @ 2026-05-23 18:51 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Andrew Morton,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
linux-kernel, linux-rt-devel, Karl Mehltretter
The lockdep selftests deliberately run unbalanced locking patterns.
dotest() restores the task state they leave behind before running the
next testcase.
On PREEMPT_RT, spin_lock() uses migrate_disable() instead of disabling
preemption. dotest() cleans up the resulting migration-disabled state, but
that cleanup is still guarded by CONFIG_SMP.
That used to match the scheduler data model, where migration_disabled was
also CONFIG_SMP-only. The commit referenced below made SMP scheduler state
unconditional, so CONFIG_SMP=n PREEMPT_RT kernels with
CONFIG_DEBUG_LOCKING_API_SELFTESTS=y report success from the selftests and
then trip over stale current->migration_disabled state:
releasing a pinned lock
bad: scheduling from the idle thread!
Kernel panic - not syncing: Fatal exception
Save and restore current->migration_disabled for every PREEMPT_RT build.
Fixes: cac5cefbade9 ("sched/smp: Make SMP unconditional")
Assisted-by: Codex:gpt-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
lib/locking-selftest.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index d939403331b5..34554e26d477 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1431,9 +1431,7 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
{
int saved_preempt_count = preempt_count();
#ifdef CONFIG_PREEMPT_RT
-#ifdef CONFIG_SMP
int saved_mgd_count = current->migration_disabled;
-#endif
int saved_rcu_count = current->rcu_read_lock_nesting;
#endif
@@ -1471,10 +1469,8 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
preempt_count_set(saved_preempt_count);
#ifdef CONFIG_PREEMPT_RT
-#ifdef CONFIG_SMP
while (current->migration_disabled > saved_mgd_count)
migrate_enable();
-#endif
while (current->rcu_read_lock_nesting > saved_rcu_count)
rcu_read_unlock();
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] 6+ messages in thread* [tip: locking/core] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT
2026-05-23 18:51 ` [PATCH 1/2] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT Karl Mehltretter
@ 2026-06-03 14:25 ` tip-bot2 for Karl Mehltretter
0 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Karl Mehltretter @ 2026-06-03 14:25 UTC (permalink / raw)
To: linux-tip-commits
Cc: Karl Mehltretter, Peter Zijlstra (Intel),
Sebastian Andrzej Siewior, x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: d8c897b20bf4d4cbb1e935a8ceb666bcc0f82580
Gitweb: https://git.kernel.org/tip/d8c897b20bf4d4cbb1e935a8ceb666bcc0f82580
Author: Karl Mehltretter <kmehltretter@gmail.com>
AuthorDate: Sat, 23 May 2026 20:51:22 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 03 Jun 2026 11:38:47 +02:00
lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT
The lockdep selftests deliberately run unbalanced locking patterns.
dotest() restores the task state they leave behind before running the
next testcase.
On PREEMPT_RT, spin_lock() uses migrate_disable() instead of disabling
preemption. dotest() cleans up the resulting migration-disabled state, but
that cleanup is still guarded by CONFIG_SMP.
That used to match the scheduler data model, where migration_disabled was
also CONFIG_SMP-only. The commit referenced below made SMP scheduler state
unconditional, so CONFIG_SMP=n PREEMPT_RT kernels with
CONFIG_DEBUG_LOCKING_API_SELFTESTS=y report success from the selftests and
then trip over stale current->migration_disabled state:
releasing a pinned lock
bad: scheduling from the idle thread!
Kernel panic - not syncing: Fatal exception
Save and restore current->migration_disabled for every PREEMPT_RT build.
Fixes: cac5cefbade9 ("sched/smp: Make SMP unconditional")
Assisted-by: Codex:gpt-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/20260523185123.17482-2-kmehltretter@gmail.com
---
lib/locking-selftest.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index d939403..cb806b6 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1431,9 +1431,7 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
{
int saved_preempt_count = preempt_count();
#ifdef CONFIG_PREEMPT_RT
-#ifdef CONFIG_SMP
int saved_mgd_count = current->migration_disabled;
-#endif
int saved_rcu_count = current->rcu_read_lock_nesting;
#endif
@@ -1471,10 +1469,8 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
preempt_count_set(saved_preempt_count);
#ifdef CONFIG_PREEMPT_RT
-#ifdef CONFIG_SMP
while (current->migration_disabled > saved_mgd_count)
migrate_enable();
-#endif
while (current->rcu_read_lock_nesting > saved_rcu_count)
rcu_read_unlock();
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] lockdep/selftests: Restore sched_rt_mutex state on PREEMPT_RT
2026-05-23 18:51 [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Karl Mehltretter
2026-05-23 18:51 ` [PATCH 1/2] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT Karl Mehltretter
@ 2026-05-23 18:51 ` Karl Mehltretter
2026-06-03 14:25 ` [tip: locking/core] " tip-bot2 for Karl Mehltretter
2026-06-01 8:43 ` [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Sebastian Andrzej Siewior
2 siblings, 1 reply; 6+ messages in thread
From: Karl Mehltretter @ 2026-05-23 18:51 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Andrew Morton,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
linux-kernel, linux-rt-devel, Karl Mehltretter
The WW-mutex selftests deliberately exercise failing lock paths. On
PREEMPT_RT, some of those paths enter the RT-mutex scheduler helpers.
The change referenced by the Fixes tag made those helpers track RT-mutex
scheduling state in current->sched_rt_mutex. The bit is normally cleared by
the matching post-schedule helper, but some WW-mutex selftests disable
the runtime debug_locks flag before that happens. With debug_locks cleared,
lockdep_assert() does not evaluate the expression that clears the bit,
leaving stale state for the next testcase.
With CONFIG_PREEMPT_RT=y and CONFIG_DEBUG_LOCKING_API_SELFTESTS=y, that
stale state produces warnings such as:
WARNING: kernel/sched/core.c:7557 at rt_mutex_pre_schedule+0x26/0x2d
RIP: 0010:rt_mutex_pre_schedule+0x26/0x2d
Save and restore current->sched_rt_mutex around each testcase, matching the
existing PREEMPT_RT cleanup for task-local migration and RCU state.
Fixes: d14f9e930b90 ("locking/rtmutex: Use rt_mutex specific scheduler helpers")
Assisted-by: Codex:gpt-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
lib/locking-selftest.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index 34554e26d477..e7c3ccb23b58 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1433,6 +1433,7 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
#ifdef CONFIG_PREEMPT_RT
int saved_mgd_count = current->migration_disabled;
int saved_rcu_count = current->rcu_read_lock_nesting;
+ int saved_sched_rt_mutex = current->sched_rt_mutex;
#endif
WARN_ON(irqs_disabled());
@@ -1469,6 +1470,8 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
preempt_count_set(saved_preempt_count);
#ifdef CONFIG_PREEMPT_RT
+ current->sched_rt_mutex = saved_sched_rt_mutex;
+
while (current->migration_disabled > saved_mgd_count)
migrate_enable();
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] 6+ messages in thread* [tip: locking/core] lockdep/selftests: Restore sched_rt_mutex state on PREEMPT_RT
2026-05-23 18:51 ` [PATCH 2/2] lockdep/selftests: Restore sched_rt_mutex " Karl Mehltretter
@ 2026-06-03 14:25 ` tip-bot2 for Karl Mehltretter
0 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Karl Mehltretter @ 2026-06-03 14:25 UTC (permalink / raw)
To: linux-tip-commits
Cc: Karl Mehltretter, Peter Zijlstra (Intel),
Sebastian Andrzej Siewior, x86, linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 06961d60a0e410bf8df69ccff7eb1bd824912b8f
Gitweb: https://git.kernel.org/tip/06961d60a0e410bf8df69ccff7eb1bd824912b8f
Author: Karl Mehltretter <kmehltretter@gmail.com>
AuthorDate: Sat, 23 May 2026 20:51:23 +02:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 03 Jun 2026 11:38:47 +02:00
lockdep/selftests: Restore sched_rt_mutex state on PREEMPT_RT
The WW-mutex selftests deliberately exercise failing lock paths. On
PREEMPT_RT, some of those paths enter the RT-mutex scheduler helpers.
The change referenced by the Fixes tag made those helpers track RT-mutex
scheduling state in current->sched_rt_mutex. The bit is normally cleared by
the matching post-schedule helper, but some WW-mutex selftests disable
the runtime debug_locks flag before that happens. With debug_locks cleared,
lockdep_assert() does not evaluate the expression that clears the bit,
leaving stale state for the next testcase.
With CONFIG_PREEMPT_RT=y and CONFIG_DEBUG_LOCKING_API_SELFTESTS=y, that
stale state produces warnings such as:
WARNING: kernel/sched/core.c:7557 at rt_mutex_pre_schedule+0x26/0x2d
RIP: 0010:rt_mutex_pre_schedule+0x26/0x2d
Save and restore current->sched_rt_mutex around each testcase, matching the
existing PREEMPT_RT cleanup for task-local migration and RCU state.
Fixes: d14f9e930b90 ("locking/rtmutex: Use rt_mutex specific scheduler helpers")
Assisted-by: Codex:gpt-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/20260523185123.17482-3-kmehltretter@gmail.com
---
lib/locking-selftest.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index cb806b6..bfafe12 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1433,6 +1433,7 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
#ifdef CONFIG_PREEMPT_RT
int saved_mgd_count = current->migration_disabled;
int saved_rcu_count = current->rcu_read_lock_nesting;
+ int saved_sched_rt_mutex = current->sched_rt_mutex;
#endif
WARN_ON(irqs_disabled());
@@ -1469,6 +1470,8 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
preempt_count_set(saved_preempt_count);
#ifdef CONFIG_PREEMPT_RT
+ current->sched_rt_mutex = saved_sched_rt_mutex;
+
while (current->migration_disabled > saved_mgd_count)
migrate_enable();
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state
2026-05-23 18:51 [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Karl Mehltretter
2026-05-23 18:51 ` [PATCH 1/2] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT Karl Mehltretter
2026-05-23 18:51 ` [PATCH 2/2] lockdep/selftests: Restore sched_rt_mutex " Karl Mehltretter
@ 2026-06-01 8:43 ` Sebastian Andrzej Siewior
2 siblings, 0 replies; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-06-01 8:43 UTC (permalink / raw)
To: Karl Mehltretter
Cc: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
Waiman Long, Andrew Morton, Clark Williams, Steven Rostedt,
linux-kernel, linux-rt-devel
On 2026-05-23 20:51:21 [+0200], Karl Mehltretter wrote:
> Hi,
>
> the lockdep selftests deliberately run broken locking patterns. On
> PREEMPT_RT, some of those paths also leave task-local RT state behind, and
> dotest() has to restore that state before the next testcase.
…
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-03 14:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-23 18:51 [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Karl Mehltretter
2026-05-23 18:51 ` [PATCH 1/2] lockdep/selftests: Restore migrate_disable() state on PREEMPT_RT Karl Mehltretter
2026-06-03 14:25 ` [tip: locking/core] " tip-bot2 for Karl Mehltretter
2026-05-23 18:51 ` [PATCH 2/2] lockdep/selftests: Restore sched_rt_mutex " Karl Mehltretter
2026-06-03 14:25 ` [tip: locking/core] " tip-bot2 for Karl Mehltretter
2026-06-01 8:43 ` [PATCH 0/2] lockdep/selftests: Restore PREEMPT_RT task state Sebastian Andrzej Siewior
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®