[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAq0SUkE_4qF5RuWE7MxnzcbchE4SHkyMvJxHAQeJ+=ZTEwdgg@mail.gmail.com>
Date: Wed, 17 May 2023 13:57:09 -0300
From: Wander Lairson Costa <wander@...hat.com>
To: Oleg Nesterov <oleg@...hat.com>
Cc: "Russell King (Oracle)" <rmk+kernel@...linux.org.uk>,
Brian Cain <bcain@...cinc.com>,
Michael Ellerman <mpe@...erman.id.au>,
Stafford Horne <shorne@...il.com>,
Kefeng Wang <wangkefeng.wang@...wei.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Andrei Vagin <avagin@...il.com>,
Peter Zijlstra <peterz@...radead.org>,
"Paul E. McKenney" <paulmck@...nel.org>,
Daniel Bristot de Oliveira <bristot@...nel.org>,
Yu Zhao <yuzhao@...gle.com>,
Alexey Gladkov <legion@...nel.org>,
Mike Kravetz <mike.kravetz@...cle.com>,
Yang Shi <shy828301@...il.com>,
open list <linux-kernel@...r.kernel.org>,
Hu Chunyu <chuhu@...hat.com>,
Valentin Schneider <vschneid@...hat.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Steven Rostedt <rostedt@...dmis.org>,
Luis Goncalves <lgoncalv@...hat.com>
Subject: Re: [PATCH v9] kernel/fork: beware of __put_task_struct calling context
On Wed, May 17, 2023 at 12:26 PM Oleg Nesterov <oleg@...hat.com> wrote:
>
> On 05/16, Wander Lairson Costa wrote:
> >
> > static inline void put_task_struct(struct task_struct *t)
> > {
> > - if (refcount_dec_and_test(&t->usage))
> > + if (!refcount_dec_and_test(&t->usage))
> > + return;
> > +
> > + /*
> > + * under PREEMPT_RT, we can't call put_task_struct
> > + * in atomic context because it will indirectly
> > + * acquire sleeping locks.
> > + *
> > + * call_rcu() will schedule delayed_put_task_struct_rcu()
> > + * to be called in process context.
> > + *
> > + * __put_task_struct() is called when
> > + * refcount_dec_and_test(&t->usage) succeeds.
> > + *
> > + * This means that it can't "conflict" with
> > + * put_task_struct_rcu_user() which abuses ->rcu the same
> > + * way; rcu_users has a reference so task->usage can't be
> > + * zero after rcu_users 1 -> 0 transition.
> > + *
> > + * delayed_free_task() also uses ->rcu, but it is only called
> > + * when it fails to fork a process. Therefore, there is no
> > + * way it can conflict with put_task_struct().
> > + */
> > + if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
> > + call_rcu(&t->rcu, __put_task_struct_rcu_cb);
> > + else
> > __put_task_struct(t);
> > }
>
> LGTM but we still need to understand the possible problems with CONFIG_PROVE_RAW_LOCK_NESTING ...
>
> Again, I'll try to investigate when I have time although I am not sure I can really help.
>
> Perhaps you too can try to do this ? ;)
>
FWIW, I tested this patch with CONFIG_PROVE_LOCK_NESTING in RT and
stock kernels. No splat happened.
> Oleg.
>
Powered by blists - more mailing lists