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 - 09:11:10 EST


On 07/29, Luis Claudio R. Goncalves wrote:
>
> On Tue, Jul 29, 2025 at 01:47:03PM +0200, Oleg Nesterov wrote:
> > On 07/29, Luis Claudio R. Goncalves wrote:
> > >
> > > + /* 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...
>
> I reverted that code to the previous state, commit 893cdaaa3977 ("sched:
> avoid false lockdep splat in put_task_struct()") and simplified the "if"
> statement.

Yes, yes, I see and I have already acked your patch.

> In the original code, PREEMPT_RT could call __put_task_struct()
> if the context was preemptible. But in the proposed code __put_task_struct()
> is only called if PREEMPT_RT is disabled. In this case I believe we could
> simply do:
>
> + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
> + __put_task_struct(t);
> + return;
> + }
>
> Does that make sense?

Hmm... But, again unless I am totally confused, we do need the
DEFINE_WAIT_OVERRIDE_MAP() trick even if !PREEMPT_RT ?

Looking at lockdep_wait_type, I think that with
CONFIG_PROVE_RAW_LOCK_NESTING=y lockdep enforces the PREEMPT_RT
locking rules even if PREEMPT_RT is not set?

But:

> > 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.

I still think LD_WAIT_CONFIG makes more sense.

Oleg.