From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbbHGPQO (ORCPT ); Fri, 7 Aug 2015 11:16:14 -0400 Received: from mail-yk0-f170.google.com ([209.85.160.170]:36717 "EHLO mail-yk0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753570AbbHGPQL (ORCPT ); Fri, 7 Aug 2015 11:16:11 -0400 Date: Fri, 7 Aug 2015 11:16:08 -0400 From: Tejun Heo To: Peter Zijlstra Cc: mingo@kernel.org, riel@redhat.com, dedekind1@gmail.com, linux-kernel@vger.kernel.org, mgorman@suse.de, rostedt@goodmis.org, juri.lelli@arm.com, Oleg Nesterov Subject: Re: [RFC][PATCH 1/4] sched: Fix a race between __kthread_bind() and sched_setaffinity() Message-ID: <20150807151608.GD14626@mtj.duckdns.org> References: <20150515154333.712161952@infradead.org> <20150515154833.545640346@infradead.org> <20150515155653.GA23692@htj.duckdns.org> <20150807142708.GK16853@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150807142708.GK16853@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 07, 2015 at 04:27:08PM +0200, Peter Zijlstra wrote: > Which is the rescue thread attaching itself to a pool that needs help, > and obviously the rescue thread isn't new so kthread_bind doesn't work > right. > > The best I could come up with is something like the below on top; does > that work for you? I'll go give it some runtime. > > --- a/kernel/workqueue.c > +++ b/kernel/workqueue.c > @@ -1622,11 +1622,15 @@ static struct worker *alloc_worker(int n > * cpu-[un]hotplugs. > */ > static void worker_attach_to_pool(struct worker *worker, > - struct worker_pool *pool) > + struct worker_pool *pool, > + bool new) > { > mutex_lock(&pool->attach_mutex); > > - kthread_bind_mask(worker->task, pool->attrs->cpumask); > + if (new) > + kthread_bind_mask(worker->task, pool->attrs->cpumask); > + else > + set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); > > /* > * The pool->attach_mutex ensures %POOL_DISASSOCIATED remains > @@ -1712,7 +1716,7 @@ static struct worker *create_worker(stru > set_user_nice(worker->task, pool->attrs->nice); > > /* successful, attach the worker to the pool */ > - worker_attach_to_pool(worker, pool); > + worker_attach_to_pool(worker, pool, true); > > /* start the newly created worker */ > spin_lock_irq(&pool->lock); > @@ -2241,7 +2245,7 @@ static int rescuer_thread(void *__rescue > > spin_unlock_irq(&wq_mayday_lock); > > - worker_attach_to_pool(rescuer, pool); > + worker_attach_to_pool(rescuer, pool, false); Hmmm... the race condition didn't exist for workqueue in the first place, right? As long as the flag is set before the affinity is configured, there's no race condition. I think the code was better before. Can't we just revert workqueue.c part? Thanks. -- tejun