Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1672333pxk; Fri, 2 Oct 2020 16:16:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvqEb7EEE17egO5xgIep6tNdzTAl+91hbOPiIMgbWG9Dok9isJONPN0Xpd3N2lYlGEivhu X-Received: by 2002:aa7:cf96:: with SMTP id z22mr5270745edx.120.1601680579979; Fri, 02 Oct 2020 16:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601680579; cv=none; d=google.com; s=arc-20160816; b=EkdtErS923ausGih6Acdmd5PB5W+8NncEmsEyl0yd1PVz37lpaZ6Hx8V5N93H7PimN 9TH4yBremzhijwzZ5YwLzdlwaVdftiySOWcbrsaFo+raV52TP44aj+wtgGBAT3T9QoGQ UuPgbi5M1wJ6dVUcOEVIlJg5H3mDo5c9A6Xz4QwtxT0JaV4SZRJoxwZHdm3+QP/a1AFR abojmWjyToprKSRcCfppha3J/EEed4fOimfjNZiCSZM109jB1HMmT4SsX4S0oi3tI4cP B2qHtcspdumYb9oBmoCsSjU58ED8b/kIpz1rNBe+wvuJ+G+IiHyjAW7cJUSZfUg1dS7r 7Xtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YfdsfR+vxnsAijYLXa6tOfA8KqdB4WmlnZuQhX/Ct4U=; b=yvbI13nQBXaxX7KLMW4GEZLiu5wn+L2T7/nRkCz5KeQTvpKboqbP+vUfUy9rwNL4Zz RJ3IMlbnvs/ze3CPA11+Kc8C7umvkouLYWoLlP4kFgdVr7nP/Ab8T6jKIpumt++rg94B GrpWLf9G4sAIYz7wEXFwIjqxUNYF1klEvTi0NmQAhL+/GAzD2AwfDu3nfa78USOTJlQg q873cnulr2kKNqnPCRVdlldB66G+w5p6sm/UUzsWfVdYLBTyByZrkyUU54yjSR5kgugP 12o8/dsES/17VhHMUQPkaxexoblT2vtRZMiMomFvOTforL3TWhYqh/i2dclYagSfG95i ocag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=saZdfCSz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g26si1997022edv.609.2020.10.02.16.15.57; Fri, 02 Oct 2020 16:16:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=saZdfCSz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725536AbgJBXPD (ORCPT + 99 others); Fri, 2 Oct 2020 19:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgJBXPD (ORCPT ); Fri, 2 Oct 2020 19:15:03 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 321F1C0613E2 for ; Fri, 2 Oct 2020 16:15:03 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id m17so3306382ioo.1 for ; Fri, 02 Oct 2020 16:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YfdsfR+vxnsAijYLXa6tOfA8KqdB4WmlnZuQhX/Ct4U=; b=saZdfCSzMzpYeJMISnJ7OJgpgSkR3+dgqgr4x7aqFlkgmCFEB5WQMLMXbvty5IZrfL oGcm1OkS3ioUuJSCsT6K3mKOgLMbujc0eMb/GgU34MS2ynpi0gTY74sS2EGavQ4LW9sv hS7nfUFrE/cHESWXEEih7Al6VHHM86PkPAX/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YfdsfR+vxnsAijYLXa6tOfA8KqdB4WmlnZuQhX/Ct4U=; b=sVU9Bk1aVP8Uf2WDgdkOciKJ9hN6expid55CrVL7811yKdLWlweFOlXUVe7SNPB/Fc /blHjkrFlPHCpg/X3FfLuBfoqMlyfOwWi2b/gu/TJqf6cFzkZYVKxiY6ZplezKGEsAVe wMAaH81WcjOjC7f5DC/oDlpbKsHNKNK9Mqs4dZRFJZDkxHfuQzgIqEnJHtgP0R7QPXIJ 1HWvEE4b248vFs2RAmE92HV8t38iWe9ODznIN/w5ktr+2g0ygsHTODI9Iwl6ghj9yAFv aa9iGHiYsePlfjyo8RvDpKcIfkOsDKtMOFuSvusKNkW+qXmA2+RGp63s8f8WYmknZTVs eTMA== X-Gm-Message-State: AOAM533k4wcHBa5oheoOWV/lQVdgz+bXkqaGCw+ZBa88Mn0Ei0AXrwkw geUHyaGY8B3NzXpGue+ks3WMGYQhBDCyMoIonRoubQ== X-Received: by 2002:a5d:80d6:: with SMTP id h22mr3677082ior.154.1601680502289; Fri, 02 Oct 2020 16:15:02 -0700 (PDT) MIME-Version: 1.0 References: <20200929192928.3749502-1-joel@joelfernandes.org> <20200929192928.3749502-2-joel@joelfernandes.org> <20200929193248.GA3749988@google.com> <20201002193412.GJ29330@paulmck-ThinkPad-P72> In-Reply-To: <20201002193412.GJ29330@paulmck-ThinkPad-P72> From: Joel Fernandes Date: Fri, 2 Oct 2020 19:14:49 -0400 Message-ID: Subject: Re: [PATCH 2/2] docs: Update RCU's hotplug requirements with a bit about design To: "Paul E. McKenney" Cc: LKML , Jonathan Corbet , Josh Triplett , Lai Jiangshan , "open list:DOCUMENTATION" , Mathieu Desnoyers , Mauro Carvalho Chehab , Neeraj Upadhyay , Randy Dunlap , rcu , Steven Rostedt , Will Deacon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 2, 2020 at 3:34 PM Paul E. McKenney wrote: > > On Tue, Sep 29, 2020 at 03:32:48PM -0400, Joel Fernandes wrote: > > Hi Paul, > > > > On Tue, Sep 29, 2020 at 03:29:28PM -0400, Joel Fernandes (Google) wrote: > > > RCU's hotplug design will help understand the requirements an RCU > > > implementation needs to fullfill, such as dead-lock avoidance. > > > > > > The rcu_barrier() section of the "Hotplug CPU" section already talks > > > about deadlocks, however the description of what else can deadlock other > > > than rcu_barrier is rather incomplete. > > > > > > This commit therefore continues the section by describing how RCU's > > > design handles CPU hotplug in a deadlock-free way. > > > > > > Signed-off-by: Joel Fernandes (Google) > > > --- > > > .../RCU/Design/Requirements/Requirements.rst | 30 +++++++++++++++++-- > > > 1 file changed, 28 insertions(+), 2 deletions(-) > > > > > > diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst b/Documentation/RCU/Design/Requirements/Requirements.rst > > > index 1ae79a10a8de..e0413aa989dd 100644 > > > --- a/Documentation/RCU/Design/Requirements/Requirements.rst > > > +++ b/Documentation/RCU/Design/Requirements/Requirements.rst > > > @@ -1929,8 +1929,10 @@ The Linux-kernel CPU-hotplug implementation has notifiers that are used > > > to allow the various kernel subsystems (including RCU) to respond > > > appropriately to a given CPU-hotplug operation. Most RCU operations may > > > be invoked from CPU-hotplug notifiers, including even synchronous > > > -grace-period operations such as ``synchronize_rcu()`` and > > > -``synchronize_rcu_expedited()``. > > > +grace-period operations such as. However, the synchronous variants > > > +(``synchronize_rcu()`` and ``synchronize_rcu_expedited()``) should not > > > +from notifiers that execute via ``stop_machine()`` -- specifically those > > > > The "should not from notifiers" should be "should not be used from > > notifiers" here. Sorry and hope you can fix it up. > > Thank you, and queued for further review. How does the below look > for a general fixup? Looks great, thanks! -Joel > > Thanx, Paul > > ------------------------------------------------------------------------ > > commit a93716177eeac726037828b28e6b1a45e828688a > Author: Joel Fernandes (Google) > Date: Tue Sep 29 15:29:28 2020 -0400 > > docs: Update RCU's hotplug requirements with a bit about design > > The rcu_barrier() section of the "Hotplug CPU" section discusses > deadlocks, however the description of deadlocks other than those involving > rcu_barrier() is rather incomplete. > > This commit therefore continues the section by describing how RCU's > design handles CPU hotplug in a deadlock-free way. > > Signed-off-by: Joel Fernandes (Google) > Signed-off-by: Paul E. McKenney > > diff --git a/Documentation/RCU/Design/Requirements/Requirements.rst b/Documentation/RCU/Design/Requirements/Requirements.rst > index 1ae79a1..98557fe 100644 > --- a/Documentation/RCU/Design/Requirements/Requirements.rst > +++ b/Documentation/RCU/Design/Requirements/Requirements.rst > @@ -1929,16 +1929,45 @@ The Linux-kernel CPU-hotplug implementation has notifiers that are used > to allow the various kernel subsystems (including RCU) to respond > appropriately to a given CPU-hotplug operation. Most RCU operations may > be invoked from CPU-hotplug notifiers, including even synchronous > -grace-period operations such as ``synchronize_rcu()`` and > -``synchronize_rcu_expedited()``. > - > -However, all-callback-wait operations such as ``rcu_barrier()`` are also > -not supported, due to the fact that there are phases of CPU-hotplug > -operations where the outgoing CPU's callbacks will not be invoked until > -after the CPU-hotplug operation ends, which could also result in > -deadlock. Furthermore, ``rcu_barrier()`` blocks CPU-hotplug operations > -during its execution, which results in another type of deadlock when > -invoked from a CPU-hotplug notifier. > +grace-period operations such as (``synchronize_rcu()`` and > +``synchronize_rcu_expedited()``). However, these synchronous operations > +do block and therefore cannot be invoked from notifiers that execute via > +``stop_machine()``, specifically those between the ``CPUHP_AP_OFFLINE`` > +and ``CPUHP_AP_ONLINE`` states. > + > +In addition, all-callback-wait operations such as ``rcu_barrier()`` may > +not be invoked from any CPU-hotplug notifier. This restriction is due > +to the fact that there are phases of CPU-hotplug operations where the > +outgoing CPU's callbacks will not be invoked until after the CPU-hotplug > +operation ends, which could also result in deadlock. Furthermore, > +``rcu_barrier()`` blocks CPU-hotplug operations during its execution, > +which results in another type of deadlock when invoked from a CPU-hotplug > +notifier. > + > +Finally, RCU must avoid deadlocks due to interaction between hotplug, > +timers and grace period processing. It does so by maintaining its own set > +of books that duplicate the centrally maintained ``cpu_online_mask``, > +and also by reporting quiescent states explictly when a CPU goes > +offline. This explicit reporting of quiescent states avoids any need > +for the force-quiescent-state loop (FQS) to report quiescent states for > +offline CPUs. However, as a debugging measure, the FQS loop does splat > +if offline CPUs block an RCU grace period for too long. > + > +An offline CPU's quiescent state will be reported either: > +1. As the CPU goes offline using RCU's hotplug notifier (``rcu_report_dead()``). > +2. When grace period initialization (``rcu_gp_init()``) detects a > + race either with CPU offlining or with a task unblocking on a leaf > + ``rcu_node`` structure whose CPUs are all offline. > + > +The CPU-online path (``rcu_cpu_starting()``) should never need to report > +a quiescent state for an offline CPU. However, as a debugging measure, > +it does emit a warning if a quiescent state was not already reported > +for that CPU. > + > +During the checking/modification of RCU's hotplug bookkeeping, the > +corresponding CPU's leaf node lock is held. This avoids race conditions > +between RCU's hotplug notifier hooks, the grace period initialization > +code, and the FQS loop, all of which refer to or modify this bookkeeping. > > Scheduler and RCU > ~~~~~~~~~~~~~~~~~