Re: [PATCH v4] kernel/fork: beware of __put_task_struct calling context

From: Oleg Nesterov
Date: Mon Feb 06 2023 - 11:28:58 EST


On 02/06, Sebastian Andrzej Siewior wrote:
>
> On 2023-02-06 16:27:12 [+0100], Oleg Nesterov wrote:
>
> > > If so why not use it
> > > unconditionally?
> >
> > performance ?
>
> All the free() part is moved from the caller into rcu.

sorry, I don't understand,

>
> >
> > And... I still don't like the name of delayed_put_task_struct_rcu() to me
> > ___put_task_struct_rcu() looks a bit less confusing, note that we already
> > have delayed_put_task_struct(). But this is minor.
>
> So if we do it unconditionally then we could get rid of
> put_task_struct_rcu_user().

Yes. But the whole purpose of rcu_users is that we want to avoid the unconditional
rcu grace period before free_task() ?

Just in case... please note that delayed_put_task_struct() delays
refcount_sub(t->usage), not free_task().

Why do we need this? Consider

rcu_read_lock();

task = find-task-in-rcu-protected-list;

// Safe, task->usage can't be zero
get_task_struct(task);

rcu_read_unlock();


> Otherwise we could use put_task_struct_rcu_user() in that timer
> callback because it will lead to lockdep warnings once printk is fixed.

IIUC there are more in-atomic callers of put_task_struct(). But perhaps
I misunderstood you...

Oleg.