Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4036842pxk; Tue, 29 Sep 2020 12:31:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaG8k+zK1wHeJO8xzlaXh4PlnJdmcW/ZIe/D0IEP9c+KNwelZGL+jpkMAOonjKeJTdEMJx X-Received: by 2002:a17:906:a1d4:: with SMTP id bx20mr5362346ejb.262.1601407902064; Tue, 29 Sep 2020 12:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601407902; cv=none; d=google.com; s=arc-20160816; b=uWpUIM160WGWqcHozaPGLfzGBV8udO9ku/G8mk4/9JHazB8G+q3E7ldA2m0GOhnX5N lEhr5Syf74pmYj7r9i6qhxEaVpIyq9Xz8eHCLVOxpu+4Shc50ocdlx8oaBr64N7aWHJR MFqJKq233GfsvoYBqy4xCrFMXWHBWU1D7eJX0p9TkeziOhC7S+agL5eubLp5p7fwK4jj /oV73AuBTKhff2tr0WGpzBgVLriimUWNkfVHstTJ7ec5cdDfjp51hoyv88j0sfLguViw tOllS9Vum3KwyfkkeYzJn/+hr8i4d9c1hBTn3+oXAbTbdn1SFQK5ZWQYNWN+TwnrdWa4 /Q0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9LlVi65DFKcmHpSl55kNBX6MX6XVcwkGpRStKg3hTtA=; b=aKn/kVnO4yT+rUDuxMZ2JeE5NzuBFaEGg5E0bU3qaWdN3CzTqgxuRwj+G0Zx4snzLA F79geH1n1n6v1m+xzLumCK1ZCxQ1Tj3hy0gQhHDg+E+4BPg8ghpnWDA0XHAH9Zwqv2ja CuZRZ5mmNI8KJN3vEP5wOdGNCuUYLEYYOuZMnNH75ATejpxKF8NybpmPmEBON44Bd5lN ZoSg2HMmY+UdxDBXZByuPdR2942E0mt2IEOxqOOKcWPBsZNF+nYruocbPbBFtQbhrs+5 OsPaVDeFvbDSloQyQDcDnBUZKYdKDp8OTNJnDqCRmajV3f0XKizI6CrWJSZOveXxJWTI Gljw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=KMLp25Jd; 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 j4si3447388ejt.277.2020.09.29.12.31.18; Tue, 29 Sep 2020 12:31:42 -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=KMLp25Jd; 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 S1728602AbgI2T3v (ORCPT + 99 others); Tue, 29 Sep 2020 15:29:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728710AbgI2T3r (ORCPT ); Tue, 29 Sep 2020 15:29:47 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937ECC0613D1 for ; Tue, 29 Sep 2020 12:29:47 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id o21so4577228qtp.2 for ; Tue, 29 Sep 2020 12:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9LlVi65DFKcmHpSl55kNBX6MX6XVcwkGpRStKg3hTtA=; b=KMLp25JdemeZRH9YnTPgRau3PxpNUKZq7kB0DPB21iYmy+yjkBVDENJMBggwthBmaC oEelKwJNbiIi8Yz4Rc1QzAOqASky6C7C1Sw3/UQReYKEnQDCP4w9bp2WrOBg5qNlKdYX 5Y6dbTF4VqO3o1DVVju9/khoO4DpODz+jWbc8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9LlVi65DFKcmHpSl55kNBX6MX6XVcwkGpRStKg3hTtA=; b=XqSfsmB1RrNNAEnWaxiHFmu4/BzxiFzbfwPvz5SpvIIxM/NLhkcaqji3V4ugkFoFUh 4IckhUzjIHkd1d729afs3AUfVcjDvMscSC5T7jv7YPH5CGQx9alE8Np7Z5/uRB+PFk/t Or4Y8WkdsEwG06hDuBlJwa0p/y9B/vT2ILeh42Om/i/7tJgDSHwgQZ+kIMr4P0qbBwhH c8pyJQ60Rq8ajtrTxnQN4jBLluKvRSt+5z82wFSPHf5NJX96mqzaNXyRKKwOwHDR4bW8 XkWmfpQBHRWxEtcnpCZdt2aLEb0Ba+82DwaHYd5KGD1r8q5faochlV9diJpaIfMrUnBD S+lg== X-Gm-Message-State: AOAM53040le4q0GlkmPHk25ZrDoJcbMQDKUuyYA3nKacFaAk0vbLe3S2 MQCKCjdTj4RXMLk7A38Q/hZylRuRZrUEsQ== X-Received: by 2002:ac8:7b3d:: with SMTP id l29mr5171700qtu.366.1601407786577; Tue, 29 Sep 2020 12:29:46 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id n7sm6892887qtf.27.2020.09.29.12.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 12:29:46 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Jonathan Corbet , Josh Triplett , Lai Jiangshan , linux-doc@vger.kernel.org, Mathieu Desnoyers , Mauro Carvalho Chehab , Neeraj Upadhyay , "Paul E. McKenney" , Randy Dunlap , rcu@vger.kernel.org, Steven Rostedt , Will Deacon Subject: [PATCH 2/2] docs: Update RCU's hotplug requirements with a bit about design Date: Tue, 29 Sep 2020 15:29:28 -0400 Message-Id: <20200929192928.3749502-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog In-Reply-To: <20200929192928.3749502-1-joel@joelfernandes.org> References: <20200929192928.3749502-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 +between the ``CPUHP_AP_OFFLINE`` and ``CPUHP_AP_ONLINE`` states. However, all-callback-wait operations such as ``rcu_barrier()`` are also not supported, due to the fact that there are phases of CPU-hotplug @@ -1940,6 +1942,30 @@ 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. +Also, RCU's implementation avoids serious deadlocks which could occur due to +interaction between hotplug, timers and grace period processing. It does so by +maintaining its own books of every CPU's hotplug state, independent of +the existing general-purpose CPU masks and by reporting quiescent states +explictly when an online CPU is going down. Due to this design, the force +quiescent state loop (FQS) is not required to report quiescent states for +offline CPUs, like it does for idle CPUs, but it does splat if offline CPUs are +stalling the RCU grace period for too long. + +For an offline CPU, the quiescent state will be reported in either of: +1. During CPU offlining, using RCU's hotplug notifier (``rcu_report_dead()``). +2. During grace period initialization (``rcu_gp_init()``) if it detected a race + with CPU offlining, or a race with a task unblocking on a node which + previously had all of its CPUs offlined. + +The CPU onlining path (``rcu_cpu_starting()``) does not need to report a +quiescent state for an offline CPU; in fact it would trigger 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, grace period initialization code and the FQS loop +which can concurrently refer to or modify the bookkeeping. + Scheduler and RCU ~~~~~~~~~~~~~~~~~ -- 2.28.0.709.gb0816b6eb0-goog