All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Wanpeng Li <wanpeng.li@hotmail.com>
Cc: Ingo Molnar <mingo@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched: fix tsk->pi_lock isn't held when do_set_cpus_allowed()
Date: Tue, 25 Aug 2015 12:32:49 +0200	[thread overview]
Message-ID: <20150825103249.GJ18673@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150825101032.GI18673@twins.programming.kicks-ass.net>

On Tue, Aug 25, 2015 at 12:10:32PM +0200, Peter Zijlstra wrote:
> On Tue, Aug 25, 2015 at 12:05:27PM +0200, Peter Zijlstra wrote:
> > On Tue, Aug 25, 2015 at 03:59:54PM +0800, Wanpeng Li wrote:
> > > +++ b/kernel/cpuset.c
> > > @@ -2376,8 +2376,12 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
> > >  
> > >  void cpuset_cpus_allowed_fallback(struct task_struct *tsk)
> > >  {
> > > +	unsigned long flags;
> > > +
> > >  	rcu_read_lock();
> > > +	raw_spin_lock_irqsave(&tsk->pi_lock, flags);
> > >  	do_set_cpus_allowed(tsk, task_cs(tsk)->effective_cpus);
> > > +	raw_spin_lock_irqsave(&tsk->pi_lock, flags);
> > >  	rcu_read_unlock();
> > 
> > Aside from the double lock thing that was already pointed out, I think
> > this is wrong, because the select_task_rq() call can already have
> > pi_lock held.
> > 
> > Taking it again would result in a deadlock.
> > 
> > Consider for instance:
> > 
> > try_to_wake_up()
> >   raw_spin_lock_irqsave(->pi_lock)
> >   select_task_rq()
> >     select_ballback_rq()
> >       cpuset_cpus_allowed_fallback()
> >         raw_spin_lock_irqsave(->pi_lock)
> > 
> > 
> > The problem is with the migration path and should be fixed there.
> 
> Another problem, migration_call() will have rq->lock held, so you're
> proposing to acquire pi_lock while holding rq->lock, this is an
> inversion from the regular nesting order.
> 

So Possibly, Maybe (I'm still to wrecked to say for sure), something
like this would work:

	WARN_ON(debug_locks && (lockdep_is_held(&p->pi_lock) ||
				(p->on_rq && lockdep_is_held(&rq->lock))));

Instead of those two separate lockdep asserts.

Please consider carefully.

  reply	other threads:[~2015-08-25 10:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-25  7:59 [PATCH] sched: fix tsk->pi_lock isn't held when do_set_cpus_allowed() Wanpeng Li
2015-08-25  8:13 ` Leo Yan
2015-08-25  8:24   ` Wanpeng Li
2015-08-25  8:30     ` Ingo Molnar
2015-08-25  8:38       ` Wanpeng Li
2015-08-25 10:05 ` Peter Zijlstra
2015-08-25 10:10   ` Peter Zijlstra
2015-08-25 10:32     ` Peter Zijlstra [this message]
     [not found]       ` <BLU437-SMTP7261DF7A82716F49242C7B80610@phx.gbl>
2015-08-27 22:18         ` Peter Zijlstra
2015-08-28  1:49           ` Wanpeng Li
2015-08-25 10:18   ` Wanpeng Li
2015-08-27 13:47 ` T. Zhou
  -- strict thread matches above, loose matches on Subject: below --
2015-08-25  7:56 Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150825103249.GJ18673@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=wanpeng.li@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.