Received: by 2002:a05:7412:b112:b0:f9:3106:f1c0 with SMTP id az18csp4254rdb; Sun, 17 Dec 2023 18:00:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGds3EIGAxpaf0DLII3mjIZB01ujIeakawmDj00g6YTPMMpkPzKlkbeCmcyj9R/+eaNzmP3 X-Received: by 2002:a05:6214:d85:b0:67f:162c:b22a with SMTP id e5-20020a0562140d8500b0067f162cb22amr7953768qve.48.1702864838627; Sun, 17 Dec 2023 18:00:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702864838; cv=none; d=google.com; s=arc-20160816; b=NJ3B5cqyV+R/0o+aigkvKfteCv+CASDUTa/7toSjPCiMdbw2QRZAYm/9KjjhhX68cg ZIAxrykyWoe/RiRsCR813PuI6NcrJL9x6OIgckDOUruqrKd70Q9VR+8wuf+Xu8I4Tnvz 37zfDz1oj4YmnS4YleT0aJXIIzoi0C4pFmesDuJ7g9nvhhyz/aUDL6woPIHdU9SbFIOR KbFKozD1O+tS44s/0gRe78O7ufzHUMK1swuLrEkhvOXYtlaYpwufbieF8F9pVWDIzYre dGPaG/vzh08TbPgCQvisBy1Wy4sZyf+mApa2BIOPipgEj6qausIoPen0mjE8/yn06aTE /g9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=YTpv7YoKKoT23nETYSezOT1AFCoo447JfaozaqzS3bc=; fh=qhhMR+E3TL/auXOP7S02sQ5Yl0P0uH8KKCcixygM1MQ=; b=HOysfgZDacRrpdGr1zJqCe3iXbgdW8hRdnt83REjkkfvUQH93L744pb+dOZ/7I8oHn gxUmg4bqjKEhB6I9bG7dwbWb7KbJY8uqvPNLvUso9qP2CB6kFanBFFmu6Hc20DoElobK +0fUUTnof+8uSWL9a2ZRegSx4uXtfEcQNWKGvTG0AAlYFG9X8qBCyG8tdu+5j2vvUD98 ByZfnZn4epsRYu+1Yp7vyH+v5rq0a64+0DZtynaTERm32/XVSdZjaH2vb1UBtUART0BG 6U0pDgv9SICX5V++cT4XTplzhAbtpnP23HDMr/VujZD/kjpwIjphI4ezM9jABripQ+ey /CVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Q42p60Rn; spf=pass (google.com: domain of linux-kernel+bounces-2917-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2917-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w15-20020a0ce10f000000b0067f286f3523si4571248qvk.219.2023.12.17.18.00.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 18:00:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2917-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Q42p60Rn; spf=pass (google.com: domain of linux-kernel+bounces-2917-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2917-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 557E71C2105E for ; Mon, 18 Dec 2023 02:00:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDC4523BC; Mon, 18 Dec 2023 02:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="Q42p60Rn" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F44020E6 for ; Mon, 18 Dec 2023 02:00:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joelfernandes.org Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2cc7087c6c4so4828851fa.2 for ; Sun, 17 Dec 2023 18:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1702864827; x=1703469627; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YTpv7YoKKoT23nETYSezOT1AFCoo447JfaozaqzS3bc=; b=Q42p60Rn4HGfX2wyDy36gyT0Q0qJV7fD//4yHj6GsbJTmGZhjc1FL7pGfNHN8GzAX8 3fCnFBZqCdqW5GETLHbIi7rHwJdG6gLH1X1smWYtQOcYGdyiksZe0ah/Jnj+zo36D76Y rteSZoWYf0WdHhebz/FavcNRRBz3ls+EatgZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702864827; x=1703469627; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YTpv7YoKKoT23nETYSezOT1AFCoo447JfaozaqzS3bc=; b=i7ztwGBY5AqZ/smDSRTTbYdCV0HveIA/714n2PtwoN96RhcBvdxP4JGaRPvQMLH9H5 Rt4MIj5OpGbISU9mzDIfafQlSusP1Lvkg+Qq14R+dCamLFk3km26dgB6wwGHtUDZpGck z7xArnBAMkSddd5qVlIuydgk33XCF2D1x298MFUuMQ5PDkBSzIkzrG8CucFDRSWQ+lj6 zZQsqZ2IEJHODh8iCz6R1XpvessZtT+tyWJAdQmEtlntOvXGueJvx+9rUp8Hr47Me1Zu Re0jqWiaxAxDyVpWZgFis3QpDPjEmyhQe/Mei7kj/UX1RBkRZL0gPKcpGeyXYzG64lW4 7gPg== X-Gm-Message-State: AOJu0Yx9QndjN9mQsUhjq16HMSi/LmgeQzJHOLxFla7DZoJx/vh3QETr t5PeyoxZQWpxKBENqCcXzQGahAJObZdZvGRHIoBuVQ== X-Received: by 2002:a2e:9989:0:b0:2cc:60dc:42bb with SMTP id w9-20020a2e9989000000b002cc60dc42bbmr971453lji.68.1702864827297; Sun, 17 Dec 2023 18:00:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231211015717.1067822-1-joel@joelfernandes.org> In-Reply-To: From: Joel Fernandes Date: Sun, 17 Dec 2023 21:00:15 -0500 Message-ID: Subject: Re: [PATCH v2] srcu: Improve comments about acceleration leak To: Frederic Weisbecker Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Neeraj Upadhyay , rcu@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Dec 16, 2023 at 4:17=E2=80=AFPM Frederic Weisbecker wrote: > > Le Mon, Dec 11, 2023 at 01:57:16AM +0000, Joel Fernandes (Google) a =C3= =A9crit : > > The comments added in commit 1ef990c4b36b ("srcu: No need to > > advance/accelerate if no callback enqueued") are a bit confusing to me. > > I know some maintainers who may argue that in the changelog world, the fi= rst > person doesn't exist :-) Heh, that's fair. Ok I can drop the '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 > > s/by/why Ok. > > fail. > > > > Cc: Frederic Weisbecker > > Cc: Neeraj Upadhyay > > Signed-off-by: Joel Fernandes (Google) > > --- > > 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(st= ruct 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 ma= y fail > > - * and acceleration may then fail too. > > + * It's crucial to capture the snapshot 's' for acceleration befo= re > > + * 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 snapsh= ot is > > + * captured after this sequence of events, the acceleration snaps= hot 's' > > + * could be excessively advanced, leading to acceleration failure= . > > + * In such a scenario, an 'acceleration leak' can occur, where ne= w > > + * callbacks become indefinitely stuck in the RCU_NEXT_TAIL segme= nt. > > + * Also note that encountering advancing failures is a normal > > + * occurrence when the grace period for RCU_WAIT_TAIL is in progr= ess. > > * > > - * 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 =3D X + 4)= and the > > * RCU_NEXT_READY_TAIL also has callbacks (gp_num =3D X + 8). > > @@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(str= uct srcu_struct *ssp, > > if (rhp) { > > rcu_segcblist_advance(&sdp->srcu_cblist, > > rcu_seq_current(&ssp->srcu_sup->src= u_gp_seq)); > > + /* > > + * Acceleration can never fail because the state of gp_se= q used > > + * for advancing is <=3D the state of gp_seq used for > > + * acceleration. > > What do you mean by "state" here? State means "value at a certain point in time" here. > If it's the gp_seq number, that doesn't look right. Uff, I screwed up the comment. I swapped "acceleration" and "advancing". I should say: "Acceleration can never fail because the state of gp_seq value used for acceleration is <=3D the state of gp_seq used for advancing." Does that sound correct now? > The situation raising the initial bug also involved a gp_seq used for adv= ancing <=3D the gp_seq used for acceleration. Right, which I understand is the bug. thanks, - Joel