Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755267AbbHYKc4 (ORCPT ); Tue, 25 Aug 2015 06:32:56 -0400 Received: from casper.infradead.org ([85.118.1.10]:33259 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751935AbbHYKcw (ORCPT ); Tue, 25 Aug 2015 06:32:52 -0400 Date: Tue, 25 Aug 2015 12:32:49 +0200 From: Peter Zijlstra To: Wanpeng Li Cc: Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched: fix tsk->pi_lock isn't held when do_set_cpus_allowed() Message-ID: <20150825103249.GJ18673@twins.programming.kicks-ass.net> References: <20150825100527.GO16853@twins.programming.kicks-ass.net> <20150825101032.GI18673@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150825101032.GI18673@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1908 Lines: 53 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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/