Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp855403pxb; Thu, 5 Nov 2020 15:07:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcWdr++z/IoX1EnW32dSrePS4Rh0WiFTOe9Ajqq1tqoyy1qrXAFvs5eZ2DS0esQAuW7qS1 X-Received: by 2002:a17:906:a098:: with SMTP id q24mr4548406ejy.191.1604617624317; Thu, 05 Nov 2020 15:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604617624; cv=none; d=google.com; s=arc-20160816; b=lmL7IDTXYsnZOf2OxHOzsdigpv5c3YeQKOoMK4JoRZoFrU9VYClQlV+4NXBFW3/Sow X2gKLGG/2CPjD0BxHuBGLmOPNG2AoaxWjqSz5f7/izjbYhRR20cNuGJpecxlsWFxuhaa k0V6UvC+iiTTvKGru1qDEDZeV2jmO4WLWy+bONjpADWkXmbczmPKmp97P/XTUTahKJjN EnFDg8d8P3aG1xEtLJuwjUeG/UztUxSOnWGVaWOK+esG61euJj3lunpshEgvRvjjXaX6 itLpFT1fQvelouOrUNUYG7DiWdhUrHsVxLheQeRu/X03buHXgHbx6n3CrsxjieNDGYyu jWCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=mBPEHcOkxnP6vbgbIoeQRjCb/6R/Yh40z1plVbT7w4k=; b=DxWHtW1w0r3OjUTdr6gi/q2fLKoQSYXRvlOxit7n+FYEwrSG6U/fn+i+RlHzTJTrll KS69JyQPr4wT6x8dCDCiyLBNacXfFaUPyai4TqGbFErTRcbCGUQj1+3wC3PDJJS8xydV F1Ii7c0EoPBmDU0+BvRn2Nk/l+8HJz1ZNxPd+TRP6KG5nYDOUXefVDT2lxwZ77cKWvZo ehDJsEIZSryWImNw1UAyG7OcxWLF9anTfgkZ8ft5pEO9O+hklI8uLxNGAfuoabMb1oA4 +D0BAGil/CbVLcLb+5kQYv7tubcjvvawvbvK8UPvyEdBxSfwWicVKO3yWjaN7+9qi4u0 BG6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SETiUM32; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx24si2240436ejb.449.2020.11.05.15.06.41; Thu, 05 Nov 2020 15:07:04 -0800 (PST) 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=@kernel.org header.s=default header.b=SETiUM32; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732555AbgKEXFP (ORCPT + 99 others); Thu, 5 Nov 2020 18:05:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:33428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732396AbgKEXFO (ORCPT ); Thu, 5 Nov 2020 18:05:14 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-104-11.bvtn.or.frontiernet.net [50.39.104.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 034A421556; Thu, 5 Nov 2020 23:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604617513; bh=2BmXTko68ZDsIesT0vZJ3kqsugp9QBTU7Q1/k551dHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SETiUM3273kWF4T3HdHKAwxQtb+dcBQLUyUzjktwgOL/GAN7PxzjIHPTjXYKYCtPO kO/8fsmWkKLmUe7mM9koh5XS2s1WzEFXvfuxI0xyB9LR574NwgMQRRoTPmIOei9EVa iASdJBgSENitLKB9ghzFB8NPLpv3dA1u+S56+rps= From: paulmck@kernel.org To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, "Paul E . McKenney" Subject: [PATCH tip/core/rcu 2/4] docs: Update RCU's hotplug requirements with a bit about design Date: Thu, 5 Nov 2020 15:05:08 -0800 Message-Id: <20201105230510.18660-2-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20201105230444.GA18574@paulmck-ThinkPad-P72> References: <20201105230444.GA18574@paulmck-ThinkPad-P72> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Joel Fernandes (Google)" 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 --- .../RCU/Design/Requirements/Requirements.rst | 49 +++++++++++++++++----- 1 file changed, 39 insertions(+), 10 deletions(-) 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 ~~~~~~~~~~~~~~~~~ -- 2.9.5