Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5496170rdb; Wed, 13 Dec 2023 10:11:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyeqFQxaOLGn1LN+LV+vaXYRdizEzt4gmZ+xTOzPY2DhuGvi/t3Ytq0oHu3j0b87ZdQkJm X-Received: by 2002:a05:6a20:244f:b0:190:2746:8bdf with SMTP id t15-20020a056a20244f00b0019027468bdfmr4118700pzc.73.1702491075210; Wed, 13 Dec 2023 10:11:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702491075; cv=none; d=google.com; s=arc-20160816; b=vVCsA1Uo1d9cFVShdlsJRFvnYEfZv+88ml5yES2ZVeqRo4YppAm8g+elFK4dO3E+dL cJPl1qL7nWducIFPiZ963ITRdkEfqg+JEnzZ1xUJCYYQFcCRtVTkGrYAmUiLlxGzDV6e TpYDoDsuGAqRxIC21x3H2WERmgxkuDrT65Gy9yjUXC4bIS7cesvrDCs+LKsq0ysTdxJK HupbiR56XTUjfed0/jkWGfPtYbY91VKeT/eOtUCTo+ayW8xe3USRkeH+u20EWyC7J9AE zCCpbP4g82N1VZG4o/KKv90NTObMeViwPp7Q4wGTauo1KmD+HhfkXwleIvVnLqMmPais mV/A== 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-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=4253hl1nkvqcRLxUSaSozrXSPVddGJ/ZTXWp9+oTlY4=; fh=M6M6QxME6nGcPFGiXObRtgVrNP7s79qiL255YEIrcBY=; b=UstkdICI5dJoi5gEVQvwVuqI+UAB9csnO7pKlAkp6Yj7csec1l1p1QyhGSeViwpUiG y1yXZHh52XBgpr5caveIINeVcVwj7njJ7/LBfYEyyboaOne2eRtIEQb9kaE/IVfV3Gjp JPx5ZQPsDlKhRHM/b56onrHkkLcJYTiwNjX8HpHpuXmK+6t+OFmWW71s7m5WlH05IqCs lJzSd333p9Fke25m4t4cd8HujMFHP+pb9IX0goaUfnAIphiBi+poGAnMhzJby5GtqMQb 9u2cIKGeC1ECZfyEwWpPp52Le/x/7b3plD6lKfeEPrLSzEEsjV6UbsH8mF2Gd9KCt7/O 6yHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ssMW5lZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id o2-20020a655202000000b005c666162406si10049829pgp.565.2023.12.13.10.11.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 10:11:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ssMW5lZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 36ABA807EAC0; Wed, 13 Dec 2023 10:10:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379326AbjLMSKG (ORCPT + 99 others); Wed, 13 Dec 2023 13:10:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjLMSKF (ORCPT ); Wed, 13 Dec 2023 13:10:05 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 049D1AC for ; Wed, 13 Dec 2023 10:10:12 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96F8FC433C8; Wed, 13 Dec 2023 18:10:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702491011; bh=Ibow/m3GEIZ8IbXREIXNaOr+KBGSFkWlItf/pSKXo4c=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=ssMW5lZJIZ5NkgTVS2CPSerSu2jRNbbVAQMzsq1elsgc+uvsg7FpqeseiFpjIgOzd xPYO9kMqRGH4nMcEa/Io2KeiyRXVRmhuZstS0RDleFb+oYGQkJKdvwU1GNLLZ3jC2L dl27/wYKQZbdsnsPx15szs2sxCYclPJA6663OmuN69hchuNg5wd1SwMw5m6i4CRJO7 vdVwsZBN/V28TYQGDM30RT4DhIAC6h6Phd41QN0EY6/kxpgZBRIFw3DwfBJdo4q4RC skmIisgdZ0wGWDFyN+kYeAH2LBWKgJ1vnwQ4pbU60sLhhTOY4tlc4ZGP4Ir9cZ+tIz ahBjiOpKnm4dw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 3608ACE0C4D; Wed, 13 Dec 2023 10:10:11 -0800 (PST) Date: Wed, 13 Dec 2023 10:10:11 -0800 From: "Paul E. McKenney" To: Joel Fernandes 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 v2] srcu: Improve comments about acceleration leak Message-ID: <41db96d6-db3f-4e17-87a1-744441ae56c5@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20231211015717.1067822-1-joel@joelfernandes.org> <48B36383-8849-4F52-8882-3B98AD0B9AF7@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <48B36383-8849-4F52-8882-3B98AD0B9AF7@joelfernandes.org> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 13 Dec 2023 10:10:21 -0800 (PST) On Tue, Dec 12, 2023 at 03:11:30PM -0500, Joel Fernandes wrote: > > > > On Dec 10, 2023, at 8:57 PM, Joel Fernandes (Google) wrote: > > > > The comments added in commit 1ef990c4b36b ("srcu: No need to > > advance/accelerate if no callback enqueued") are a bit confusing to me. > > 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 by acceleration can never > > fail. > > > > Cc: Frederic Weisbecker > > Cc: Neeraj Upadhyay > > Signed-off-by: Joel Fernandes (Google) > > Do we want to quick review and put it in Neeraj PR? > > Or next merge window ok with me. Just that then I have to keep track of it ;-) Or it could get an ack and I could pull it into -rcu. ;-) Thanx, Paul > Thanks, > > - Joel > > > > > --- > > v1->v2: Fix typo in change log. > > > > 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 state of gp_seq used > > + * for advancing is <= the state of gp_seq used for > > + * acceleration. 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 > >