From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guenter Roeck Subject: Re: linux-next: tracebacks in workqueue.c/__flush_work() Date: Wed, 6 Feb 2019 06:36:25 -0800 Message-ID: <20190206143625.GA25998@roeck-us.net> References: <72e7d782-85f2-b499-8614-9e3498106569@i-love.sakura.ne.jp> <87munc306z.fsf@rustcorp.com.au> <201902060631.x166V9J8014750@www262.sakura.ne.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <201902060631.x166V9J8014750@www262.sakura.ne.jp> Sender: linux-kernel-owner@vger.kernel.org To: Tetsuo Handa Cc: Rusty Russell , Chris Metcalf , linux-kernel , Tejun Heo , linux-mm , linux-arch List-Id: linux-arch.vger.kernel.org On Wed, Feb 06, 2019 at 03:31:09PM +0900, Tetsuo Handa wrote: > (Adding linux-arch ML.) > > Rusty Russell wrote: > > Tetsuo Handa writes: > > > (Adding Chris Metcalf and Rusty Russell.) > > > > > > If NR_CPUS == 1 due to CONFIG_SMP=n, for_each_cpu(cpu, &has_work) loop does not > > > evaluate "struct cpumask has_work" modified by cpumask_set_cpu(cpu, &has_work) at > > > previous for_each_online_cpu() loop. Guenter Roeck found a problem among three > > > commits listed below. > > > > > > Commit 5fbc461636c32efd ("mm: make lru_add_drain_all() selective") > > > expects that has_work is evaluated by for_each_cpu(). > > > > > > Commit 2d3854a37e8b767a ("cpumask: introduce new API, without changing anything") > > > assumes that for_each_cpu() does not need to evaluate has_work. > > > > > > Commit 4d43d395fed12463 ("workqueue: Try to catch flush_work() without INIT_WORK().") > > > expects that has_work is evaluated by for_each_cpu(). > > > > > > What should we do? Do we explicitly evaluate has_work if NR_CPUS == 1 ? > > > > No, fix the API to be least-surprise. Fix 2d3854a37e8b767a too. > > > > Doing anything else would be horrible, IMHO. > > > > Fixing 2d3854a37e8b767a might involve subtle changes. If we do > Why not fix the macros ? #define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) does not really make sense since it does not evaluate mask. #define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1 && cpumask_test_cpu((cpu), (mask)); (cpu)++) or something similar might do it. Guenter From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f195.google.com ([209.85.215.195]:38389 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726914AbfBFOg2 (ORCPT ); Wed, 6 Feb 2019 09:36:28 -0500 Date: Wed, 6 Feb 2019 06:36:25 -0800 From: Guenter Roeck Subject: Re: linux-next: tracebacks in workqueue.c/__flush_work() Message-ID: <20190206143625.GA25998@roeck-us.net> References: <72e7d782-85f2-b499-8614-9e3498106569@i-love.sakura.ne.jp> <87munc306z.fsf@rustcorp.com.au> <201902060631.x166V9J8014750@www262.sakura.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201902060631.x166V9J8014750@www262.sakura.ne.jp> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Tetsuo Handa Cc: Rusty Russell , Chris Metcalf , linux-kernel , Tejun Heo , linux-mm , linux-arch Message-ID: <20190206143625.hvEUpTPGs5aA9mSchD0YmWRWsaq2bEWmU_E16dq_81k@z> On Wed, Feb 06, 2019 at 03:31:09PM +0900, Tetsuo Handa wrote: > (Adding linux-arch ML.) > > Rusty Russell wrote: > > Tetsuo Handa writes: > > > (Adding Chris Metcalf and Rusty Russell.) > > > > > > If NR_CPUS == 1 due to CONFIG_SMP=n, for_each_cpu(cpu, &has_work) loop does not > > > evaluate "struct cpumask has_work" modified by cpumask_set_cpu(cpu, &has_work) at > > > previous for_each_online_cpu() loop. Guenter Roeck found a problem among three > > > commits listed below. > > > > > > Commit 5fbc461636c32efd ("mm: make lru_add_drain_all() selective") > > > expects that has_work is evaluated by for_each_cpu(). > > > > > > Commit 2d3854a37e8b767a ("cpumask: introduce new API, without changing anything") > > > assumes that for_each_cpu() does not need to evaluate has_work. > > > > > > Commit 4d43d395fed12463 ("workqueue: Try to catch flush_work() without INIT_WORK().") > > > expects that has_work is evaluated by for_each_cpu(). > > > > > > What should we do? Do we explicitly evaluate has_work if NR_CPUS == 1 ? > > > > No, fix the API to be least-surprise. Fix 2d3854a37e8b767a too. > > > > Doing anything else would be horrible, IMHO. > > > > Fixing 2d3854a37e8b767a might involve subtle changes. If we do > Why not fix the macros ? #define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) does not really make sense since it does not evaluate mask. #define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1 && cpumask_test_cpu((cpu), (mask)); (cpu)++) or something similar might do it. Guenter