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 09142C433EF for ; Thu, 17 Feb 2022 15:40:42 +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=Rq8JKS5OR4KwcZeyskCbIpk6YgDtWsdsskg3QKv6DXE=; b=gHZKxhjzB6CSLS 8G5ONT65sbI65q0Qxcr0dXVBMvftypz8jtt4bBakiPg98IJxilIYaI24cyay6UzUeXDejYlT7+gJZ nQU3Yk3Z5v1d3Ee34tlVN3CMdTbGkaZx/r/fMxjIccroL5QSQM5gqNKITGhb0x16AWIvHEiWFufET U5P8vkGVlhb0kqGONpp4/22/9WXupUo0SMfyVJ9FuLKllRCwrh+03LP9TNYpx0lSC6qZjFX7NH8pJ krvO3wqiNpRt2uxju0WYj3SZikS5QQY1wO61YxHrLBm4osBOpp1eiiSvqJXgUsInh+LAE7YvJuBqx aczXwGH0rK+sDV0snSPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKisV-00BI89-1R; Thu, 17 Feb 2022 15:39:31 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKisR-00BI71-8J; Thu, 17 Feb 2022 15:39:28 +0000 Received: by mail-ej1-x630.google.com with SMTP id p15so8197369ejc.7; Thu, 17 Feb 2022 07:39:26 -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=uspxbZfUGmLZDlE0gtJUW5Kh7h6indLorBvrarnojYo=; b=LbHf2tUeiPA9VAaV2oyKy6s/qf++ZBc9tR4kBx2n/xEEOsNvfXY8t6ej1mkSkeCZTr 91lkrKUYCK23FnWIz7uxygfsUc4Blu/ukIefDhxo5Oj3r6gIlbqW3QOIhHnnUoVRitcF 0KvxuHeyebdEnZ4CFso2exgstaCYM9NoT3xVaZz4m+0rZFk6MUH+tvQJn0JJvqZBGjYz kI0UHEZ3s18eFtk7fSZI1Nw+m8HRwsj6gVsRLieQmty9pjLXNU+KJUClATF1A9johMdA TmCQYsXQs1NLpgFcsmre7dM10mSR6mmZOgcXwM4SLUp1n0iMRROY2BmqwVHk7inbsBWW I70Q== 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=uspxbZfUGmLZDlE0gtJUW5Kh7h6indLorBvrarnojYo=; b=4rAhA+k4CE9FzZu4B35QY+3sci+9F0aEkYSo1eivEU5ZmUuDPRurMlaDEg38Qe3hjX 3HU4+Hk64jOr9ohiMnXB/K6Xh3D3rMun8f9ACDMTPOMwUCmk6Y3b+aAnj8Qn0BEQcFEq lFQGz5aCa6QSsbPhcvUDvyPaSZO2uoQC4rXCzNx7DNC6h3g/WU36bI9X/tMVbbkFVcdO RYlRMLzxr/6PBC0ScT4XRAs7iXQioDY6R8QqM7PAaPC/kQunVZ61kuuxIy2GcEIJ6FrB UvqoxurCEPG22AOkUDO2C9uxincDVUP39/a2cBjJcSGyXi5ZTT5aPy5Ly5O6n+uLF9a/ xSDg== X-Gm-Message-State: AOAM532U/2BjJXD2exER36Ri5AARToHNHMJZ4VF1EUik63guTRtjg+rC IohILJwnPXMJmakbGgxbLQ9V4IwYSWPSGiyOYM0= X-Google-Smtp-Source: ABdhPJwE2PjbQh76F0bG1uOct/j454LN1UJHA2GX7cM+2m49H88k00K2BzREIbtAVph9YhPD3VN5xw== X-Received: by 2002:a17:906:2695:b0:6cf:e1b4:118b with SMTP id t21-20020a170906269500b006cfe1b4118bmr2866493ejc.348.1645112365145; Thu, 17 Feb 2022 07:39:25 -0800 (PST) Received: from pswork ([62.96.250.75]) by smtp.gmail.com with ESMTPSA id f29sm1318153ejl.12.2022.02.17.07.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 07:39:24 -0800 (PST) Date: Thu, 17 Feb 2022 16:39:24 +0100 From: Padmanabha Srinivasaiah To: "Paul E. McKenney" 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: <20220217153924.GA19121@pswork> References: <20220210184319.25009-1-treasure4paddy@gmail.com> <20220216184939.GA3868@pswork> <20220216190700.GL4285@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220216190700.GL4285@paulmck-ThinkPad-P17-Gen-1> 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-20220217_073927_324188_F6CF6C59 X-CRM114-Status: GOOD ( 27.16 ) 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 Wed, Feb 16, 2022 at 11:07:00AM -0800, Paul E. McKenney wrote: > 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 Thank you Paul for suggestion, tried same and it fixes the issue. Have submitted same as suggested-by Paul. Link : https://lore.kernel.org/all/20220217152520.18972-1-treasure4paddy@gmail.com/T/#t _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel