Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3517311rdb; Wed, 27 Dec 2023 09:47:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeuKRLum0sDqmCidrZLhUTeuB7aWPu5qUQnrTkoKCyO4y66RGZVEpDNKS1Q9RSJs8HnTDA X-Received: by 2002:a05:6602:17c4:b0:7b7:96aa:70b4 with SMTP id z4-20020a05660217c400b007b796aa70b4mr10521866iox.9.1703699269265; Wed, 27 Dec 2023 09:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703699269; cv=none; d=google.com; s=arc-20160816; b=zX6FsPtlYVS8qyFnda48P39QwXvs5UtljisTT+MaSCqYW8J/t5YOM8BmJNCOkOo/lY etcZpGBaesXdpAgSiSb/WWlBr0zRbJCmDxO5gUoaqWV6j320qzxVjCvoGl3qccupNQDp U7fVqrixRlUQYAES4yw7yATwJ4SGgrP3b+YhTDTek3DKCEQ6y/ZUKOpswdl2OK4D7N8F jPTiqo8xlPzMp6ZvaDSLcnObOxW22hCiMCsQ26n11zO8+qdEWfbnS6PZ1Jrn6Xl4OjQr ShyE+OEk7pCgJU4Q6adRvopn/nhF7l3B6u3Y5K3bALAbqZjXZn/70t++mhu/uDr4mj7a KQbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:subject:cc:to:from:date:message-id :dkim-signature; bh=JCZ69uSbcTjkg8dgoQT15Hv1NXMMjojf76ZK+8F+h+A=; fh=BnbAwVfaF3tWfO2YnZVpfq4cR+VTwjdVCnJMMHddqn4=; b=f/gLRJOOhgfTYv724hHU4+wGffaF02VYD+re+uJcHqPmfAj0J0vJwz1EbLcFUBF6gK 8wbe8OrAEu7rs6Q8E+VC1yLWxzjoFRN5B4LH92Ozq5X1owWTLAGs473W5i8FY4W/kQh3 XB/8kvUCZu2WhXN7hD1NA2b/sppsfTRJ5eMGEBeR94MaR857sCKaP8R63sEimYUYKIk+ Dpp9+itYUdQxuMDMksqHnSIbvSXkxaPzb6fdKikEr1Sw9rkT6ZEMejg87XilAKIsbxEn VfuIiNdDVEVrpnui45MhHgLt2mP8FZlntXxGmS/PkmVCxy4iqj9yn6Uy0yG1d94PiAth HKLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="GGlNg/gz"; spf=pass (google.com: domain of linux-kernel+bounces-12187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12187-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s5-20020a637705000000b005ce17149bb0si6041472pgc.843.2023.12.27.09.47.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 09:47:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="GGlNg/gz"; spf=pass (google.com: domain of linux-kernel+bounces-12187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12187-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E03F0281639 for ; Wed, 27 Dec 2023 17:47:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A03AE46540; Wed, 27 Dec 2023 17:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="GGlNg/gz" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 4E3A34652F for ; Wed, 27 Dec 2023 17:47:41 +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-qt1-f179.google.com with SMTP id d75a77b69052e-427e55a172bso9209431cf.2 for ; Wed, 27 Dec 2023 09:47:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1703699259; x=1704304059; darn=vger.kernel.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JCZ69uSbcTjkg8dgoQT15Hv1NXMMjojf76ZK+8F+h+A=; b=GGlNg/gzkY8fU2RQA4hMvY1Y3O09ip2hlt0mXTYyn06FyOTZSbBGmE0wU3pYl6RLS/ Buaaemp1DqNPBLegGvd9aQDVItfRZJRwiFQwilTzh/HsB+tFCWj27xNCyIHDK7VD2HGE ZwrFofNIaehL9H+xTDTYkCLNsFiEZP0gejGGg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703699259; x=1704304059; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JCZ69uSbcTjkg8dgoQT15Hv1NXMMjojf76ZK+8F+h+A=; b=fuPeVXkaM8LJSOMz5Shzym+m4P8Ab8rhHMIGfpZBWoLPSTx3zejploAEs+YnVpUdMj do/q7VdZRCh7n7muPg1U4FadfHzZPwrEG2HLGbIUvtIIZypID8cx+Pbrqc9gRDL1u1U5 ibcSFJx0OonL6+iKK9GynwOBLSD3vPwJ3PGjPoO7uCb5fnir5gDkBpCCh1JEm+TSS06Y 0+sUeYZpN2dU/u7ETFYmFJQEQ4Hc3t5nBXsKOYeMyGM1nhB6Kx5Hgo8WuaJPBnEC8WcX v4O9gVBZvc6e2MK89OVaOIF3dIlV+5j4MFKJnMS4cz90G/cGZcdJDKGR54qn1IF2OBvo 0mwQ== X-Gm-Message-State: AOJu0Yxq2TW/Jgv8PB1cGqjIx7QRIUvCxHJsNIfWCSNOzErJ8psZ+sE/ mhv/4R0J6vq4exsWLrBNS8Xddec64lvETAASunxlgUrHB1I= X-Received: by 2002:a05:622a:590:b0:427:8fcf:52c3 with SMTP id c16-20020a05622a059000b004278fcf52c3mr14161093qtb.86.1703699258974; Wed, 27 Dec 2023 09:47:38 -0800 (PST) Received: from localhost (c-98-249-43-138.hsd1.va.comcast.net. [98.249.43.138]) by smtp.gmail.com with ESMTPSA id fc17-20020a05622a489100b00427d0be9ca3sm3855689qtb.80.2023.12.27.09.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 09:47:38 -0800 (PST) Message-ID: <658c633a.050a0220.d8198.83e8@mx.google.com> X-Google-Original-Message-ID: <20231227174738.GA1119@JoelBox.> Date: Wed, 27 Dec 2023 12:47:38 -0500 From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, Lai Jiangshan , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers Cc: "Joel Fernandes (Google)" , Frederic Weisbecker , Neeraj Upadhyay , rcu@vger.kernel.org Subject: [PATCH v3] srcu: Improve comments about acceleration leak 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 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog 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) --- 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