From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5204CC433DB for ; Wed, 13 Jan 2021 11:12:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F16DE22AAF for ; Wed, 13 Jan 2021 11:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728123AbhAMLMF (ORCPT ); Wed, 13 Jan 2021 06:12:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727884AbhAMLME (ORCPT ); Wed, 13 Jan 2021 06:12:04 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BBFC061575 for ; Wed, 13 Jan 2021 03:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=R/C+vi0ZhgENVD3jXY1szgMhn3Gfatr45WqdY9lWpeE=; b=BXPvsgb8VtnIQaEW6ecWhQ9kIO fg4Mn8MOtkQtfUCTxCJmVGWcQWTXhCXOHdI+txpdk680eeUDa7+HQUUTJaDq/o8G3axPNkOd04xge ZZa7I39GWNYaSvgIQVz6e0l5Etjv3FeztLKc+y6KSovKd5PE6kp1ywZwH5JDy/E9D3RcxiimWRTK+ 0+CCG2EtUko9S3CRtD4awvEh2uugnibuICGJkXYnoqXfOuJPyLXuW0ikCocLu/TDnSrQZSGLHVkhD hmWX62JXx2dONaC3yR05FWzMT5FSP8Of7a2YdZ277HoIX9OQTUCmbZq6CwvHk0ekO+Ty+sU3W48dd BmR85FSw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kze3M-000732-Qr; Wed, 13 Jan 2021 11:11:05 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 01317300238; Wed, 13 Jan 2021 12:10:59 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DC4FB211618D1; Wed, 13 Jan 2021 12:10:59 +0100 (CET) Date: Wed, 13 Jan 2021 12:10:59 +0100 From: Peter Zijlstra To: Lai Jiangshan Cc: Valentin Schneider , Thomas Gleixner , LKML , Qian Cai , Vincent Donnefort , Dexuan Cui , Lai Jiangshan , Paul McKenney , Vincent Guittot , Steven Rostedt , Jens Axboe Subject: Re: [PATCH -tip V3 0/8] workqueue: break affinity initiatively Message-ID: References: <20201226025117.2770-1-jiangshanlai@gmail.com> <87o8hv7pnd.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 11:38:12PM +0800, Lai Jiangshan wrote: > But the hard problem is "how to suppress the warning of > online&!active in __set_cpus_allowed_ptr()" for late spawned > unbound workers during hotplug. I cannot see create_worker() go bad like that. The thing is, it uses: kthread_bind_mask(, pool->attr->cpumask) worker_attach_to_pool() set_cpus_allowed_ptr(, pool->attr->cpumask) which means set_cpus_allowed_ptr() must be a NOP, because the affinity is already set by kthread_bind_mask(). Further, the first wakeup of that worker will then hit: select_task_rq() is_cpu_allowed() is_per_cpu_kthread() -- false select_fallback_rq() So normally that really isn't a problem. I can only see a tiny hole there, where someone changes the cpumask between kthread_bind_mask() and set_cpus_allowed_ptr(). AFAICT that can be fixed in two ways: - add wq_pool_mutex around things in create_worker(), or - move the set_cpus_allowed_ptr() out of worker_attach_to_pool() and into rescuer_thread(). Which then brings us to rescuer_thread... If we manage to trigger the rescuer during hotplug, then yes, I think that can go wobbly. Let me consider that a bit more while I try and make sense of that splat Paul reported. --- diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ec0771e4a3fb..fe05308dc472 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1844,15 +1844,19 @@ static struct worker *alloc_worker(int node) * cpu-[un]hotplugs. */ static void worker_attach_to_pool(struct worker *worker, - struct worker_pool *pool) + struct worker_pool *pool, + bool set_affinity) { mutex_lock(&wq_pool_attach_mutex); - /* - * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any - * online CPUs. It'll be re-applied when any of the CPUs come up. - */ - set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); + if (set_affinity) { + /* + * set_cpus_allowed_ptr() will fail if the cpumask doesn't have + * any online CPUs. It'll be re-applied when any of the CPUs + * come up. + */ + set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); + } /* * The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains @@ -1944,7 +1948,7 @@ static struct worker *create_worker(struct worker_pool *pool) kthread_bind_mask(worker->task, pool->attrs->cpumask); /* successful, attach the worker to the pool */ - worker_attach_to_pool(worker, pool); + worker_attach_to_pool(worker, pool, false); /* start the newly created worker */ raw_spin_lock_irq(&pool->lock); @@ -2509,7 +2513,11 @@ static int rescuer_thread(void *__rescuer) raw_spin_unlock_irq(&wq_mayday_lock); - worker_attach_to_pool(rescuer, pool); + /* + * XXX can go splat when running during hot-un-plug and + * the pool affinity is wobbly. + */ + worker_attach_to_pool(rescuer, pool, true); raw_spin_lock_irq(&pool->lock);