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

From: Oleg Nesterov
Date: Thu Jun 01 2023 - 14:15:36 EST


On 06/01, Wander Lairson Costa wrote:
>
> On Mon, May 29, 2023 at 9:23 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > On 05/17, Wander Lairson Costa wrote:
> > >
> > > On Wed, May 17, 2023 at 12:26 PM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> > > >
> > > > 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.
> >
> > Strange... FYI, I am running the kernel with this patch
> >
> > diff --git a/kernel/sys.c b/kernel/sys.c
> > index 339fee3eff6a..3169cceddf3b 100644
> > --- a/kernel/sys.c
> > +++ b/kernel/sys.c
> > @@ -2412,6 +2412,17 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
> >
> > error = 0;
> > switch (option) {
> > + case 666: {
> > + static DEFINE_SPINLOCK(l);
> > + static DEFINE_RAW_SPINLOCK(r);
> > +
> > + raw_spin_lock(&r);
> > + spin_lock(&l);
> > + spin_unlock(&l);
> > + raw_spin_unlock(&r);
> > +
> > + break;
> > + }
> > case PR_SET_PDEATHSIG:
> > if (!valid_signal(arg2)) {
> > error = -EINVAL;
> >
> > applied (because I am too lazy to compile a module ;) and
> >
>
> FWIW, I converted it to a module [1]

where is [1] ? not that I think this matters though...

> > # perl -e 'syscall 157,666'
> >
> > triggers the lockdep bug
> >
> > =============================
> > [ BUG: Invalid wait context ]
> > 6.4.0-rc2-00018-g4d6d4c7f541d-dirty #1176 Not tainted
> > -----------------------------
> > perl/35 is trying to lock:
> > ffffffff81c4cc18 (l){....}-{3:3}, at: __do_sys_prctl+0x21b/0x87b
> > other info that might help us debug this:
> > context-{5:5}
> > ...
> >
> > as expected.
> >
>
> Yeah, I tried it here and I had the same results,

OK,

> but only in the RT kernel

this again suggests that your testing was wrong or I am totally confused (quite
possible, I know nothing about RT). I did the testing without CONFIG_PREEMPT_RT.

> But running the reproducer for put_task_struct(), works fine.

which reproducer ?

Oleg.