Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6117045pxb; Mon, 14 Feb 2022 16:00:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbcD50/NQjB8bOby8ih0dNnTyvPiQjBlvv+bXjle0JA2CiBAZIeMQXanbALQC+tHjQRRVo X-Received: by 2002:a63:1262:: with SMTP id 34mr1276618pgs.194.1644883245256; Mon, 14 Feb 2022 16:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644883245; cv=none; d=google.com; s=arc-20160816; b=HLMBpE14zoAZCIppkbWpwWbFKBZy82r3ljCgPZgj7h/NFiiCD+lnKV/oo0b5AOT6TM rxjxpcttgcZfxpoE8xuvnGe8e1GdzJ7zplBwG4AYHDhTGv7ENTPyPvtmnhUv5oBR5qQD 7a6foghZUHW2YzCe0WgRRSclohXyHlUsg85T70MptWTm0wmeway82xHbrPl2nVM5rHmB e0UlLWNi43YkGL1iiTYuWcPEyQyt+5cE5ZdQ/sBgh3PqVSh/JPxQjYp4RxbcLLmEYlD9 JneOYLIyldi3sJMqTL+JNggZaBC7HyzMPmjuRv76jL4E/S6AB7gKK/pSlczf39I+h7cl p6JQ== 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:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=RIas+GyVDApC3xDrXULa8rp+llTjzXjwfENj9r1hIhE=; b=FHe9Zc9UoXjeFPinufGyNbRW/A5C5TStLYjKzoPDBT0FShtjytIigs9FnJZpY1uWe4 KAIFUb48FD/Y09rkJLcfCU91oZkt5xl1bhe8l4HNa6HcskEoITFFGFJ3ySLW1zKn5F4a 5bVe9DbtfyeFvdUCOq72T1nVVFod+7JPOX4ANC4SfMHp0gxPFVeeNVAbjYNy89DNpwPe rLTzxqU2LwMhpJGmYxj7niXTraqgVzX2Zm+y0R8kkDLQN6czUvO1kdR2FOFrAD3jout6 3CFXpREj0eFN5sawZlEtabbt6/btHFBo/c6fZ6QUmvEYoPOpp4LqnFKic+Big3yx6nnI hpmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qFTlR0PW; 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 f128si1127805pgc.440.2022.02.14.16.00.25; Mon, 14 Feb 2022 16:00:45 -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=@gmail.com header.s=20210112 header.b=qFTlR0PW; 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 S229436AbiBNUyT (ORCPT + 99 others); Mon, 14 Feb 2022 15:54:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:58582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbiBNUyR (ORCPT ); Mon, 14 Feb 2022 15:54:17 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E45BC9B for ; Mon, 14 Feb 2022 12:53:51 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id p7so15816449qvk.11 for ; Mon, 14 Feb 2022 12:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RIas+GyVDApC3xDrXULa8rp+llTjzXjwfENj9r1hIhE=; b=qFTlR0PWa747IABqwNN/t8GNIse7KZphJV5hb5vFFtsGpXNfVaZtn7Hyjm+JfpF+eM mwYqBmTgvYY3zZ4WSa+5bokDrFUpN7LCfTNJea82vfqeTF7DiUI/At97Ha0OfuhKOi2a kUslq1/4r5JPlE/qXy4lnJ633NCJXlUuUpnDPyHDOV/oan3sqPcVJtF9W/WJKHxQyIOW d9XCPDQq0pyvfqbLp2iRBcG388aYhHJSmKOKTiWQBPQF+0TwuuWX50jn02l1qrFbWPhM +5T3jqdNitbG8jENnTpfEbraUbFJMa6bB9obQOAIilKXLCuvDPYffS7y0NNe6N1qCirQ 9VVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=RIas+GyVDApC3xDrXULa8rp+llTjzXjwfENj9r1hIhE=; b=haYJ4q+lKuxiwELkAWkvWgrhi2OlnWSL1OFTotOaJzpNFmobMRozmsuvnm/K1yYQjv CidqtvhKc1LTZnc9L83pEzI0xqEYEeBUEUMb13iBXrSBe8CPO3r3Lv4gPifEeknovxLJ 9fWGg/SmndibRt9bWawYT7QvT7/eeG4ffXJ+bHCTuworzTgqNEi+9rpuOKbWdyeZ+RzR QZzqwbMbr2p/nsHKyLvpv5YxZKS2/ZyXFl1Whsn9kOZ2XpYTrnfdUFflCWZJXqg+lDgd X/3YroRD+SiSZXcR66sGHz5Op5cJcXtXpzj3xc0QMKVXAsPZ4uc4ageHf7QQHP/aZrVN fAAQ== X-Gm-Message-State: AOAM533GgKrPotYK5Mpfw27fRsYUhuB4vCVFbXmzcd90zvIBTjlI4cxo 0U9BhSXiEkC55wRsZal+oUE0KG02tec= X-Received: by 2002:a17:903:283:: with SMTP id j3mr393533plr.132.1644867834186; Mon, 14 Feb 2022 11:43:54 -0800 (PST) Received: from localhost (2603-800c-1a02-1bae-e24f-43ff-fee6-449f.res6.spectrum.com. [2603:800c:1a02:1bae:e24f:43ff:fee6:449f]) by smtp.gmail.com with ESMTPSA id q2sm39651861pfj.94.2022.02.14.11.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 11:43:53 -0800 (PST) Sender: Tejun Heo Date: Mon, 14 Feb 2022 09:43:52 -1000 From: Tejun Heo To: Padmanabha Srinivasaiah 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: References: <20220210184319.25009-1-treasure4paddy@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220210184319.25009-1-treasure4paddy@gmail.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 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); } 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. Thanks. -- tejun