Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4823271rdb; Fri, 29 Dec 2023 15:10:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQKRsj4K1pce7jeoEoGhmdaCWIyFypdwbjDjqr5EFAUhfFHxk2jFZN6Z+bEEqCftnIp1ev X-Received: by 2002:a17:906:e958:b0:a26:ee0d:1c02 with SMTP id jw24-20020a170906e95800b00a26ee0d1c02mr1332457ejb.39.1703891459116; Fri, 29 Dec 2023 15:10:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703891459; cv=none; d=google.com; s=arc-20160816; b=etSPgyH1eLrIBrfFRVk/W1bR/15yN1Lp/YebymdV4JIVm7H/q9Fii6suRlb9C4oFxH SP9GNCYjBygNM7yKwi2cy2FTYNRqFW86GDjXPRFnHGQfn9QMcK938D6rRZtCYsfpWqkI ybOCLNGwPQDc/RG3tt2TiUSTTGBKmlzYo6ienebwwrLIWlzxZHE87NSY9LZegT9fT5NW YqYB7d2/raR3bL1ucXK0EbPpo+zuVRqnmFXq9BhixN0LufYYJ6U7CAlSpzkyCd4qjKc3 DyzJIAzprcPdui+O3r2/NhGCDJT/Njh5xN1TkG3xvffDVHVlgto8rBMUsWSs2drtYZQz 3HGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=v4+8LlpsyYaYmN7Ely6sIBbQelosVAHNNXvUYBCTxzo=; fh=S9NgC/qpGS1bxNfMfbb1CjdhQs+8X+2fQJGHtZu3IAw=; b=rlOBAKJ6bnNtX25nl7K2BEYQxqpaDaJWAF3C5pcTAtKiWshc5RVxO07uiTeUBqyAV9 xH8LEnzAPjeYnJ+7YxvE/TBwpqm7QagG+TJXkH5ewXYVIhbYDaNWv6VFGRUWzpRzckvV 3mJ6vXdobEEiE9CjuTyjenUUB+TdR9ySWJGyhNce6PISGPJx8kanaZwTsnldwgjFJx1N qcUZuAuf3Vmoc8tdDh6lXbcgfYkTmJZZ4orVgryz9e0tZ+JTJsXMKNoOz8R/nes6QIh5 5fBV2Ld1zSw1uV+klt/b9I9jowYTi1IoNiu7vWO3bNSC+3mi1l1/EqnvpIfkwcnyh2Mf wWUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CWWKooOG; spf=pass (google.com: domain of linux-kernel+bounces-13274-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13274-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lk19-20020a170906cb1300b00a270e03e3besi3355025ejb.344.2023.12.29.15.10.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 15:10:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13274-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CWWKooOG; spf=pass (google.com: domain of linux-kernel+bounces-13274-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13274-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D88021F21630 for ; Fri, 29 Dec 2023 23:10:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26AB014AB9; Fri, 29 Dec 2023 23:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CWWKooOG" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5035F14AA0; Fri, 29 Dec 2023 23:10:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFB52C433C7; Fri, 29 Dec 2023 23:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703891449; bh=oQ0cC+ys/gAbywY/xLvEs4Ij2i9YNn4Y5Y6XD6BUnlQ=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=CWWKooOGrSQvXImZJeYqdNpdE06TDVraQkQbZHyXr0I8hADv9liu3CJNiYyFyvgcW EZqtj9iRO8PhlctrTvSDeGW9g+cagDwVThMxIZ80c+cBpwnpnPq/e53xOTT/xMH+r6 LcLizpr4jQyWLeqLBG7wqgZZeoB6SHBgTskeT5wXy/7pwPMiiS9F1a7n01JhHle4fR 0jWVmrdVCc6f5nscEUn7ZBUtRf7mULGVW7SIMCw5l2n+X2ekt3yRI9YSNeqBkAH7zu BX87NZ0TgxkRDA9A619atyGBg3Y5wa0YRazx1NTXNHM85Ut1M9zsawhdLf+arvRUnp MWxroPNwPRK7A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 30656CE095F; Fri, 29 Dec 2023 15:10:49 -0800 (PST) Date: Fri, 29 Dec 2023 15:10:49 -0800 From: "Paul E. McKenney" To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Frederic Weisbecker , Neeraj Upadhyay , rcu@vger.kernel.org Subject: Re: [PATCH v3] srcu: Improve comments about acceleration leak Message-ID: <5d55ef20-4720-42aa-9f86-2f43444911fb@paulmck-laptop> Reply-To: paulmck@kernel.org References: <658c633a.050a0220.d8198.83e8@mx.google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <658c633a.050a0220.d8198.83e8@mx.google.com> On Wed, Dec 27, 2023 at 12:47:38PM -0500, Joel Fernandes (Google) wrote: > The comments added in commit 1ef990c4b36b ("srcu: No need to > advance/accelerate if no callback enqueued") are a bit confusing. > The comments are describing a scenario for code that was moved and is > no longer the way it was (snapshot after advancing). Improve the code > comments to reflect this and also document why acceleration can never > fail. > > Cc: Frederic Weisbecker > Cc: Neeraj Upadhyay > Reviewed-by: Frederic Weisbecker > Signed-off-by: Joel Fernandes (Google) Queued, thank you all! Thanx, Paul > --- > v1->v2: Fix typo in change log. > v2->v3: Improvement to acceleration comment. > > kernel/rcu/srcutree.c | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c > index 0351a4e83529..051e149490d1 100644 > --- a/kernel/rcu/srcutree.c > +++ b/kernel/rcu/srcutree.c > @@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp, > if (rhp) > rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp); > /* > - * The snapshot for acceleration must be taken _before_ the read of the > - * current gp sequence used for advancing, otherwise advancing may fail > - * and acceleration may then fail too. > + * It's crucial to capture the snapshot 's' for acceleration before > + * reading the current gp_seq that is used for advancing. This is > + * essential because if the acceleration snapshot is taken after a > + * failed advancement attempt, there's a risk that a grace period may > + * conclude and a new one may start in the interim. If the snapshot is > + * captured after this sequence of events, the acceleration snapshot 's' > + * could be excessively advanced, leading to acceleration failure. > + * In such a scenario, an 'acceleration leak' can occur, where new > + * callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment. > + * Also note that encountering advancing failures is a normal > + * occurrence when the grace period for RCU_WAIT_TAIL is in progress. > * > - * This could happen if: > + * To see this, consider the following events which occur if > + * rcu_seq_snap() were to be called after advance: > * > * 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the > * RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8). > @@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp, > if (rhp) { > rcu_segcblist_advance(&sdp->srcu_cblist, > rcu_seq_current(&ssp->srcu_sup->srcu_gp_seq)); > + /* > + * Acceleration can never fail because the base current gp_seq > + * used for acceleration is <= the value of gp_seq used for > + * advancing. This means that RCU_NEXT_TAIL segment will > + * always be able to be emptied by the acceleration into the > + * RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL segments. > + */ > WARN_ON_ONCE(!rcu_segcblist_accelerate(&sdp->srcu_cblist, s)); > } > if (ULONG_CMP_LT(sdp->srcu_gp_seq_needed, s)) { > -- > 2.43.0.472.g3155946c3a-goog >