Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1388031pxb; Wed, 16 Feb 2022 18:48:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb/f07y2nGsGE2XyJQIEgTLDlPW8G+tlodTeuCVl4Op8Jb/R+h17gs1pQism5P/HJT/uL0 X-Received: by 2002:a17:90a:aa98:b0:1b8:5adb:e35f with SMTP id l24-20020a17090aaa9800b001b85adbe35fmr882843pjq.192.1645066115567; Wed, 16 Feb 2022 18:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645066115; cv=none; d=google.com; s=arc-20160816; b=QAicbk/l5SBDGsBwPo6LF75RTR1R0zjoc2jcSFhiB4cNy1thXfchUSMZpCUs0GVTJ2 UlcCOk9+VP8XDKG56dws0vLnpQCKBsrkoHWeHAl+A9m+hd5VMOTsVYABU/hzAaHUEDgE q0B0fsZNdxRWzKp0j+fS6uXa1PpAHoPDfPSCgWIGFQ36ZBhH8Jbl6+B69Q4sndnNM4KA 74uSbYRcvbvuI3Wa/wGXoq9ttyVDXHn7i2R346802J7RGcTvOKkhdApWZU5AQj4cBom4 np/Af57C5F1wJ6hDLgN8Z0aVr8aTvUnddXScP6QaJ3bXmP6gceE45yP5G29qcwkEcCcg 2IwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=3p29FBLMkFvJSknlGLJSjZZdJu24YfqNzjsslUADbY4=; b=rExfxTzl3NN5ThzBNyPMz6xr0EAZOCEvcqs5NQSkw3QihEP4HkXw0vf4CY4x2tG9Ui yctonHWmQXYgken8qqI1cfs3VCyvQksqSmTRzuLdOLwoV9iL0ySxgs+nFYteBWgNNQ/Y 4sLv5aTI2Wj0mIcHbaVYdkQuIuJzKFwyIgg41WWc/vu+z752kEhSjph5xj/oDiamQNB9 EZ5QnLlchmoxyCVizBlhzLZqt17Bd03qO9E5d5L91a6JXrTxiFLlNLa5FA7/r/9p98gJ 0TP77ojFYebKIEftm2kuUeoLyftN1/1iPaU4jiLgHKMtLVgRp7ufUjMWOERmYwNSEIOx NNaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LOf5dpqk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n22si610696pjn.176.2022.02.16.18.48.18; Wed, 16 Feb 2022 18:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LOf5dpqk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238022AbiBPTHU (ORCPT + 99 others); Wed, 16 Feb 2022 14:07:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237936AbiBPTHR (ORCPT ); Wed, 16 Feb 2022 14:07:17 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 931AD29CB1 for ; Wed, 16 Feb 2022 11:07:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E1F5BB81FBE for ; Wed, 16 Feb 2022 19:07:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EE32C004E1; Wed, 16 Feb 2022 19:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645038420; bh=O6rg2EA0mmSpBoicY2+Pis/uzSG9J5E6UibqILOjyKw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=LOf5dpqk49yNupWbhM4D9S7tOGpeM38BEzumCRrduLE79xfb93b/4OpN4bMO3T9fj SIKBTAWJEez+QFt2krProHGJPtVLZy8+vfg/M4Ll6JEc5UZawZ1N8USk6Ko5qBcXae TvSwSfJTko/mQdZHuicQnnGN3pM1+VlbVNm2DRpOOMm6KmNVEyTDJwRniCi6kP9nXC nNO9R4pgVHJaYKf8uEa/dW/H5DaQEPUs7RNhvcWeXjLMpWuAMacFSNrq8719AfbuJd 4xIsmr6bcuexOQZJDk2Dzb61DpCID4xMhmZ8ydIKGpiNj43A813e2naZPGRgYGptqU zHjsk43fRadVg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 33F275C064D; Wed, 16 Feb 2022 11:07:00 -0800 (PST) Date: Wed, 16 Feb 2022 11:07:00 -0800 From: "Paul E. McKenney" To: Padmanabha Srinivasaiah Cc: Tejun Heo , jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] workqueue: Fix race in schedule and flush work Message-ID: <20220216190700.GL4285@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220210184319.25009-1-treasure4paddy@gmail.com> <20220216184939.GA3868@pswork> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220216184939.GA3868@pswork> X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 16, 2022 at 07:49:39PM +0100, Padmanabha Srinivasaiah wrote: > On Mon, Feb 14, 2022 at 09:43:52AM -1000, Tejun Heo wrote: > > Hello, > > > > > diff --git a/kernel/workqueue.c b/kernel/workqueue.c > > > index 33f1106b4f99..a3f53f859e9d 100644 > > > --- a/kernel/workqueue.c > > > +++ b/kernel/workqueue.c > > > @@ -3326,28 +3326,38 @@ EXPORT_SYMBOL(cancel_delayed_work_sync); > > > */ > > > int schedule_on_each_cpu(work_func_t func) > > > { > > > - int cpu; > > > struct work_struct __percpu *works; > > > + cpumask_var_t sched_cpumask; > > > + int cpu, ret = 0; > > > > > > - works = alloc_percpu(struct work_struct); > > > - if (!works) > > > + if (!alloc_cpumask_var(&sched_cpumask, GFP_KERNEL)) > > > return -ENOMEM; > > > > > > + works = alloc_percpu(struct work_struct); > > > + if (!works) { > > > + ret = -ENOMEM; > > > + goto free_cpumask; > > > + } > > > + > > > cpus_read_lock(); > > > > > > - for_each_online_cpu(cpu) { > > > + cpumask_copy(sched_cpumask, cpu_online_mask); > > > + for_each_cpu_and(cpu, sched_cpumask, cpu_online_mask) { > > > > This definitely would need a comment explaining what's going on cuz it looks > > weird to be copying the cpumask which is supposed to stay stable due to the > > cpus_read_lock().Given that it can only happen during early boot and the > > online cpus can only be expanding, maybe just add sth like: > > > > if (early_during_boot) { > > for_each_possible_cpu(cpu) > > INIT_WORK(per_cpu_ptr(works, cpu), func); > > } > > > > Thanks tejun for the reply and suggestions. > > Yes, unfortunately cpus_read_lock not keeping cpumask stable at > secondary boot. Not sure, may be it only gurantee 'cpu' dont go down > under cpus_read_[lock/unlock]. > > As suggested will tryout something like: > if (system_state != RUNNING) { > : > } > > BTW, who's calling schedule_on_each_cpu() that early during boot. It makes > > no sense to do this while the cpumasks can't be stabilized. > > > It is implemenation of CONFIG_TASKS_RUDE_RCU. Another option would be to adjust CONFIG_TASKS_RUDE_RCU based on where things are in the boot process. For example: // Wait for one rude RCU-tasks grace period. static void rcu_tasks_rude_wait_gp(struct rcu_tasks *rtp) { if (num_online_cpus() <= 1) return; // Fastpath for only one CPU. rtp->n_ipis += cpumask_weight(cpu_online_mask); schedule_on_each_cpu(rcu_tasks_be_rude); } Easy enough either way! Thanx, Paul