]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lockdep/selftests: Restore sched_rt_mutex state on PREEMPT_RT
authorKarl Mehltretter <kmehltretter@gmail.com>
Sat, 23 May 2026 18:51:23 +0000 (20:51 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 3 Jun 2026 09:38:47 +0000 (11:38 +0200)
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

index cb806b628352b92f07037318daa651d9113647d7..bfafe1204c7b6f757afa773f2321202084d701b5 100644 (file)
@@ -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();