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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B937DC433EF for ; Wed, 16 Feb 2022 18:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wq7+HpkzICsYdt0gL7Rg/wXZRPUbEoivc0CHYNcr82M=; b=mDBm4SKN2Fti83 OUgTF2/R7IR17ZkTWLG833RnayetDbl4LLLwnAEkOPRBTY/dUpK84RKZegrkl8PeMEYiyZEHQLD0b Wp4IxXKaRqJ9kTVClF1K1RCiMb6iIP6PZ8dyu8DlrhteFC8ONQXcrh4g6SgRD77kMmhpw9TZvsq0/ LNTSRETlcZT6B+IFv+tQOee620RNwyLE+Y6o1BMCcAKhJUcD3LFFKufaLjxF61odZ0ejldeKL56X3 Vt61nxq+NHSRQyOqFx1d5N+akiZr9+0EcaIjHcGZlrZcVX859tgKnVPV+2ATdHbsvcQapZsdQrqm8 UrP1HdZUFpml2/Szf8Qw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKPN4-0089ow-Be; Wed, 16 Feb 2022 18:49:46 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKPN0-0089o0-Ts; Wed, 16 Feb 2022 18:49:44 +0000 Received: by mail-ed1-x52b.google.com with SMTP id q17so5539762edd.4; Wed, 16 Feb 2022 10:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/COvjkXtEZda9jeXezpZm3EMBCJ6hYD5ta53dGN4wSg=; b=GGcJ4b7eNFAQu7BjZhNj7Y+qpzoMz+YO6vahcslZQlidY8PCZR2CiKKcPcMiV+yVq8 pNyidYvGlW74UouySlIBVO3p4EP7oE0hutb+JEapQGUENaFmbrzzHEU/au0QGnU6w7p8 LH/4GH/Q89gGFZ7nJMF+ly2CEzivONVr9r1xBFzQ0q2nzXBRKEk+7AcEmU8notoJnoU8 smz9qieaiwOtCWuCqzwawTKO5QcfLdThFAhAjZGMuaIH14UYZ+ZQnlYnK4lWKiyvO1Ho m+m39gYnonib0e1dStq61ZX72kVlfK0QedSEsDBQ3gwTcv7tuI5JJmmoRHxjI+HcgTUE N88g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/COvjkXtEZda9jeXezpZm3EMBCJ6hYD5ta53dGN4wSg=; b=I3dmIozx3fM8k74dluL3ro6hxAc45JAIrCoOihiZ+xDZp0nGeJvhMag5BDSg6SDCS+ 5ETrZJ4NOlgBYPA5ahwjWHu+PluHU2wbVjKyYSTyTL7NfPGN71qWv1jGA/FaOEUYh/7n 20v/gnbIpEy0rdz/oWwQVwZF+jpwtiDCS4MYqPM0RQKKkH6KmVTJFUBhLZeH/NOOvyBn zKpP34wN0GE1M9D0HK2Jd1Bg75Bp3kcnJoPX8LRhecPrvnxbg249PNH160nXECc+eStF Ee+Ox1a8OEgYorro15W4YpZbBnl2U+MVKfNOfUSZ1T+qLGHHvS+VjhQSKSYCNDhmqCtR v2Vg== X-Gm-Message-State: AOAM53011aeUPZFyLnxo44jh/PipEkY3LSmRsenoTQPeVAJBYKgXoHcM fIC8QQzutbhYpD1K/YWwfQfCueOdbEfSacp+ X-Google-Smtp-Source: ABdhPJx041ZxjVCiSN74SkQP9Cu0BVADSNROH7zpshOsvMs5rKZ0JRbTt+5ScQ6YNIEG8907DKCBdQ== X-Received: by 2002:a50:e081:0:b0:401:8823:c9a8 with SMTP id f1-20020a50e081000000b004018823c9a8mr4459340edl.401.1645037380512; Wed, 16 Feb 2022 10:49:40 -0800 (PST) Received: from pswork ([62.96.250.75]) by smtp.gmail.com with ESMTPSA id m27sm214038ejn.134.2022.02.16.10.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 10:49:40 -0800 (PST) Date: Wed, 16 Feb 2022 19:49:39 +0100 From: Padmanabha Srinivasaiah To: Tejun Heo Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, paulmck@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: <20220216184939.GA3868@pswork> References: <20220210184319.25009-1-treasure4paddy@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_104942_988278_D90A90DB X-CRM114-Status: GOOD ( 19.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. > Thanks. > > -- > tejun _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel