Skip to content

Commit 8671bad

Browse files
lclaudioPeter Zijlstra
authored andcommitted
sched: Do not call __put_task_struct() on rt if pi_blocked_on is set
With PREEMPT_RT enabled, some of the calls to put_task_struct() coming from rt_mutex_adjust_prio_chain() could happen in preemptible context and with a mutex enqueued. That could lead to this sequence: rt_mutex_adjust_prio_chain() put_task_struct() __put_task_struct() sched_ext_free() spin_lock_irqsave() rtlock_lock() ---> TRIGGERS lockdep_assert(!current->pi_blocked_on); This is not a SCHED_EXT bug. The first cleanup function called by __put_task_struct() is sched_ext_free() and it happens to take a (RT) spin_lock, which in the scenario described above, would trigger the lockdep assertion of "!current->pi_blocked_on". Crystal Wood was able to identify the problem as __put_task_struct() being called during rt_mutex_adjust_prio_chain(), in the context of a process with a mutex enqueued. Instead of adding more complex conditions to decide when to directly call __put_task_struct() and when to defer the call, unconditionally resort to the deferred call on PREEMPT_RT to simplify the code. Fixes: 893cdaa ("sched: avoid false lockdep splat in put_task_struct()") Suggested-by: Crystal Wood <[email protected]> Signed-off-by: Luis Claudio R. Goncalves <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Wander Lairson Costa <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Reviewed-by: Sebastian Andrzej Siewior <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7de9d4f commit 8671bad

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

include/linux/sched/task.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,17 @@ static inline void put_task_struct(struct task_struct *t)
131131
return;
132132

133133
/*
134-
* In !RT, it is always safe to call __put_task_struct().
135-
* Under RT, we can only call it in preemptible context.
136-
*/
137-
if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) {
138-
static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP);
139-
140-
lock_map_acquire_try(&put_task_map);
141-
__put_task_struct(t);
142-
lock_map_release(&put_task_map);
143-
return;
144-
}
145-
146-
/*
147-
* under PREEMPT_RT, we can't call put_task_struct
134+
* Under PREEMPT_RT, we can't call __put_task_struct
148135
* in atomic context because it will indirectly
149-
* acquire sleeping locks.
136+
* acquire sleeping locks. The same is true if the
137+
* current process has a mutex enqueued (blocked on
138+
* a PI chain).
139+
*
140+
* In !RT, it is always safe to call __put_task_struct().
141+
* Though, in order to simplify the code, resort to the
142+
* deferred call too.
150143
*
151-
* call_rcu() will schedule delayed_put_task_struct_rcu()
144+
* call_rcu() will schedule __put_task_struct_rcu_cb()
152145
* to be called in process context.
153146
*
154147
* __put_task_struct() is called when
@@ -161,7 +154,7 @@ static inline void put_task_struct(struct task_struct *t)
161154
*
162155
* delayed_free_task() also uses ->rcu, but it is only called
163156
* when it fails to fork a process. Therefore, there is no
164-
* way it can conflict with put_task_struct().
157+
* way it can conflict with __put_task_struct().
165158
*/
166159
call_rcu(&t->rcu, __put_task_struct_rcu_cb);
167160
}

0 commit comments

Comments
 (0)