Re: [PATCH v6] sched: do not call __put_task_struct() on rt if pi_blocked_on is set
From: Oleg Nesterov
Date: Tue Jul 29 2025 - 07:48:47 EST
On 07/29, Luis Claudio R. Goncalves wrote:
>
> From: Luis Claudio R. Goncalves <lgoncalv@xxxxxxxxxx>
> Subject: sched: restore the behavior of put_task_struct() for non-rt
>
> Commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt
> if pi_blocked_on is set") changed the behavior of put_task_struct()
> unconditionally, even when PREEMPT_RT was not enabled, in clear mismatch
> with the commit description.
>
> Restore the previous behavior of put_task_struct() for the PREEMPT_RT
> disabled case.
>
> Fixes: 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set")
> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@xxxxxxxxxx>
> ---
> diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
> index ea41795a352b..51678a541477 100644
> --- a/include/linux/sched/task.h
> +++ b/include/linux/sched/task.h
> @@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)
> if (!refcount_dec_and_test(&t->usage))
> return;
>
> + /* In !RT, it is always safe to call __put_task_struct(). */
> + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
> + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP);
> +
> + lock_map_acquire_try(&put_task_map);
> + __put_task_struct(t);
> + lock_map_release(&put_task_map);
> + return;
> + }
FWIW:
Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx>
At the same time... I don't understand this DEFINE_WAIT_OVERRIDE_MAP().
IIUC, we need to shut up lockdep when put_task_struct() is called under
raw_spinlock_t and __put_task_struct() paths take spinlock_t, right?
Perhaps this deserves a comment...
But if I am right, why LD_WAIT_SLEEP? LD_WAIT_CONFIG should equally work, no?
LD_WAIT_SLEEP can fool lockdep more than we need, suppose that __put_task_struct()
does mutex_lock(). Not really a problem, might_sleep/etc will complain in this
case, but still.
Or I am totally confused?
Oleg.