Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp569017rwb; Wed, 16 Nov 2022 04:58:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4zN5a59ZyWsauxTdg8IJ8eHVI+V+gNGndEohTSBlCSzvJf2KsQJ8Cj8YFX6dIvrgLIiGju X-Received: by 2002:a17:906:793:b0:78c:ad86:d3 with SMTP id l19-20020a170906079300b0078cad8600d3mr17683003ejc.643.1668603526090; Wed, 16 Nov 2022 04:58:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668603526; cv=none; d=google.com; s=arc-20160816; b=Xjwd4/6ouF2bdbm14LzAvYRhfSYTDSSiVD7ss9TseEWrhkbnUD/vFlYz8LPGCK5cda 2Kx+D/Vt1XrAZkiZyfZ3lXgBYc9DspDhgwjkap29D0KiaELNasxUIyy7XW6Myks/HmJV BnOAOzF/A9uinaIxeROhyiQ3LXVeUqku/18K2pK0o/nEHE926HUXNsO7glPkxqdg40wv RVEJi49JmE9w6C3TZ5TzfE1UwTcRAzQYeiek5BgxEzLIOy/1TxguObp0k8jba9ilGgej 09W+6M1O2pEZKQ+D+UvSpdso69PQcdTwIRYKM++mOKsLN9KWK6VfYeUMKgO4gMrfybWG 3IgA== 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:dkim-signature; bh=IdNMpJR0snxIGnu8NTDAhCjaEOSUGK8iifnApPpUjSw=; b=rTvtrQr9T9oTE1llebyY1Wc7tofUsR3rRAFPW9ISqiDGq4sz1PdZaQyp0a1ySG3OSm WnaJL1JCmuY5EDZ23RCwqGw/MI7TBqlPApEs3PI8Ek+XoZ9ODDFQBbWTbTx0MKzVDmB+ NnUTGYw7YcTVSF0kIUdvLkJ47FYaOgqeqEptTn/keh2jVEghjbSpbc8pVeqGeYQfCP6u rWatwOJtszYf17isepQtTVePchRl7mQCdVVfnBww1VFsfd0z9MeRpStKLmzNLGjArbtK mLdTkmcpNtCk1LoRWbgY3jqrm0IXcDGvSIVl0E0cgDwK5lW/tg46Gdzp61mLsux/LCqX SsvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bqm9xOt5; 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 dz10-20020a0564021d4a00b00458b71488bdsi16287219edb.388.2022.11.16.04.58.23; Wed, 16 Nov 2022 04:58:46 -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=Bqm9xOt5; 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 S233534AbiKPMr1 (ORCPT + 91 others); Wed, 16 Nov 2022 07:47:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbiKPMrY (ORCPT ); Wed, 16 Nov 2022 07:47:24 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC221167EA; Wed, 16 Nov 2022 04:47:23 -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 sin.source.kernel.org (Postfix) with ESMTPS id EFB5FCE19DA; Wed, 16 Nov 2022 12:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82BF5C433C1; Wed, 16 Nov 2022 12:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668602840; bh=tKLpMlH43+Qp3G1HljC8JkJIT/xBjIxdBYhEplhIlas=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Bqm9xOt5Hv+xGuCPRbdv5wlwB9N2yJWiNBxdnZ3qZmrzMupjjucPh4HkTAgBMgQcb 6NqGw1DmG1z0tdFbwB8Cl2CWdHlaRc2JqjQL/gWQaH2a4EY2Durhp/Ijglc8qjWvDq /fmCJqMJAcQKDxEhkFaocn+S/TQ0poysS/pFil5LQCo1GtjlF4ClH3SO63RdSSrYPf UG1amBzpILy5qDMvEovh4WDPxl+FGJBduIF0fkEoYQcgc6w/pcTEE8JlSgQfg45+WL WSyLKj8p4h+MTTc+MpqlV5tl+QzpvVAvHB1yzg+jOz66XCIzF9sdo6+a/6+FJmuixK FYDrB2lSe7Png== Date: Wed, 16 Nov 2022 13:47:16 +0100 From: Frederic Weisbecker To: Zqiang Cc: paulmck@kernel.org, joel@joelfernandes.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rcu: Avoid invalid wakeup for rcuc kthreads in RCU_KTHREAD_OFFCPU status Message-ID: <20221116124716.GA813995@lothringen> References: <20221115131926.3409974-1-qiang1.zhang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221115131926.3409974-1-qiang1.zhang@intel.com> X-Spam-Status: No, score=-7.1 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 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 Tue, Nov 15, 2022 at 09:19:26PM +0800, Zqiang wrote: > For CONFIG_PREEMPT_RT=y kernel, the "use_softirq=0" will be set, the > RCU_SOFTIRQ processing is moved to per-CPU rcuc kthreads which created > by smpboot_register_percpu_thread(). when CPU is going offline, the > corresponding rcu_data.rcu_cpu_kthread_status is set RCU_KTHREAD_OFFCPU, > and the rcuc kthreads enter TASK_PARKED state, kthreads in TASK_PARKED > state only accept kthread_unpark() to wakeup. > > Therefore, This commit avoid invoke wake_up_process() to rcuc kthreads > in TASK_PARKED state. > > Signed-off-by: Zqiang > --- > kernel/rcu/tree.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index 3ccad468887e..49dd87356851 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -2375,7 +2375,8 @@ static void rcu_wake_cond(struct task_struct *t, int status) > * If the thread is yielding, only wake it when this > * is invoked from idle > */ > - if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current))) > + if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)) && > + status != RCU_KTHREAD_OFFCPU) > wake_up_process(t); There is a tiny window where this can happen (between CPUHP_TEARDOWN_CPU and CPUHP_AP_SMPBOOT_THREADS) and it can't cause a spurious unpark because wake_up_process() only wakes up from TASK_[UN]INTERRUPTIBLE states. And even if it did, the KTHREAD_SHOULD_PARK bit would still be on. And more important! On unpark time RCU_KTHREAD_OFFCPU isn't cleared. Only the rcuc kthread does it, and after your patch it couldn't be awaken to perform that, unless rcuc is lucky enough to have rcu_data.rcu_cpu_has_work = 1 by the time it unparks and that isn't guaranteed. So rcuc may sleep forever. OTOH one cleanup that could be done is to make rcu_cpu_kthread_park() to use __this_cpu_write as it's guaranteed that cpu == smp_processor_id(). Thanks.