Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4891690rdb; Tue, 12 Dec 2023 12:11:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrjoQzP0p9LdoEuFATZm0485Bu7Qu6bDRPg46GmzjBWi6bxq20zAn+/ptIhVudWBvnHzBM X-Received: by 2002:a17:90a:9bc9:b0:28a:d085:29d3 with SMTP id b9-20020a17090a9bc900b0028ad08529d3mr730670pjw.48.1702411915985; Tue, 12 Dec 2023 12:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702411915; cv=none; d=google.com; s=arc-20160816; b=w4V6oMX2O5Kcuva3FeoiYPqTkhmuT41V51dtERwC4YiADvZE6wF484DhuXwUDuH3t6 flBwWbzvxuZX457HM2nc88EK1d1GHYrtwCqCXfPNuq8eJqGA2biPO9BfqJRVbReET8oO WJy8pnHK41Bc8roasCSHWtMwJOA0pnJIUFw9/LToviFg5sc8PHXidhy0vay/wgV9TJh4 66NwwiqdfDbDCnlt4zVIORCFsAkaP1gfJEeJBu22y26s404n05l/nEX1jbAVfMADeMsG krI9US0q13rFin6vtHEnS3rmQDMSV1pYWjSSMIhk9xgw2XYfL/LtYPLC8/iEVfJIxAAR JriQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:cc:references:message-id:date :subject:mime-version:from:content-transfer-encoding:dkim-signature; bh=gSpKT6X5vMJAjLjsDkyxKCkmYJugXH+FCSpfLk33Dag=; fh=TH3jOXkcX88LyRgPrGuMfQ4xz1LCLps6jMUSRCvGwpE=; b=GA4CbzOqNu7l4REIl5ZHuGEhiz0zZD2yG8rw632dpqJlMAZDPWHoQkLyatZnMz67Nr OA54+cMf7K/MJE6/0uBB+9Mn+Wb7Thli/ykmYRQOYGaVzAhQgBcF5lOblgxbb8+9967t RFJXTfRcETIswkhDnnXQoCf5khkSlQ5iNkXauHni0eU3e9yhNO8M4MGaGHame910cINF tgJSBiAVOgme7zCneuZFg1XTkk0Gcm81qj7OjHW5GIgKoKvCf+IMJaooIf222Wp3eNvq 0NaUqG5+CjSomYEa+irtM+8Ksg6oTWp1p/Yf4e8XUiPK0BAe7/sBSeWeaNK0Ni0FW+fm 1SUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=w3+nC2sT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p23-20020a17090b011700b0028ace20b8e7si820652pjz.187.2023.12.12.12.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 12:11:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=w3+nC2sT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 6FF4B809A833; Tue, 12 Dec 2023 12:11:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377201AbjLLULj (ORCPT + 99 others); Tue, 12 Dec 2023 15:11:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235047AbjLLULh (ORCPT ); Tue, 12 Dec 2023 15:11:37 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27B1CB9 for ; Tue, 12 Dec 2023 12:11:44 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6d8029dae41so4650767a34.0 for ; Tue, 12 Dec 2023 12:11:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1702411903; x=1703016703; darn=vger.kernel.org; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=gSpKT6X5vMJAjLjsDkyxKCkmYJugXH+FCSpfLk33Dag=; b=w3+nC2sTKUpst0pdzpvnIoV5kGTc2uRE4Vuucg0vS69vjlRpsXz0aJGS24K3QieTcZ AX9R6d64JHIu8S1PcneYvxO6oFzpINvvOXRAhJ/+171kDih5Refpp1etlZjPuvzsJwff 1rlXMJT+PwFDzGn7/pbnWluAuBNGCXHc9VDVE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702411903; x=1703016703; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gSpKT6X5vMJAjLjsDkyxKCkmYJugXH+FCSpfLk33Dag=; b=c3Ht/U/mQ+JYvnkvahF+o2ZaaLHZM2aJ5PYltdxkocPRC3xOzNX/WfxfMsCOfnxA8G lOISfJBzgtfiVPvNVIWQzXiFX7C3OO3jThWqjEMlte2pQodf1HhxgQm7NYu87Mk80O0S gKZ9LlhcZawEUHPgtFFuCgplorYiZEBstFQOXWsigr2hORD9rENWC0o/RiFfQ49Cog53 sD1q4mbkIIwlX5AVfM50oxrtKBOBjmj773f1pGpMHi8moD8ZA2m29ovymFYUmLBDZGUg VgpQ3gPmWubw14BG8FXJl7ns0T3pjaXdZ7nkot83O3KYb1PbWGbMKLJJHysEYTRtuuHC UHrg== X-Gm-Message-State: AOJu0YxiEH4I4uiryv6Jx2sm9Led8kwqAuno26PjGlaObGAU6RefOOcQ PA4kWGDOvJzHH90UFcmJnjSVTw== X-Received: by 2002:a9d:7384:0:b0:6d8:567d:ed18 with SMTP id j4-20020a9d7384000000b006d8567ded18mr6200200otk.7.1702411903442; Tue, 12 Dec 2023 12:11:43 -0800 (PST) Received: from smtpclient.apple ([185.189.25.71]) by smtp.gmail.com with ESMTPSA id da15-20020a0568306a8f00b006ce28044207sm118360otb.58.2023.12.12.12.11.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 12:11:43 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Joel Fernandes Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v2] srcu: Improve comments about acceleration leak Date: Tue, 12 Dec 2023 15:11:30 -0500 Message-Id: <48B36383-8849-4F52-8882-3B98AD0B9AF7@joelfernandes.org> References: <20231211015717.1067822-1-joel@joelfernandes.org> Cc: Frederic Weisbecker , Neeraj Upadhyay , rcu@vger.kernel.org In-Reply-To: <20231211015717.1067822-1-joel@joelfernandes.org> To: linux-kernel@vger.kernel.org, Lai Jiangshan , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers X-Mailer: iPhone Mail (20B101) X-Spam-Status: No, score=1.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 12:11:53 -0800 (PST) X-Spam-Level: * > On Dec 10, 2023, at 8:57 PM, Joel Fernandes (Google) wrote: >=20 > =EF=BB=BFThe 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. >=20 > 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 ;= -) Thanks, - Joel=20 > --- > v1->v2: Fix typo in change log. >=20 > kernel/rcu/srcutree.c | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) >=20 > 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(struc= t srcu_struct *ssp, > if (rhp) > rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp); > /* > - * The snapshot for acceleration must be taken _before_ the read of t= he > - * current gp sequence used for advancing, otherwise advancing may fa= il > - * 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 i= s > + * 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 =3D X + 4) and t= he > * RCU_NEXT_READY_TAIL also has callbacks (gp_num =3D 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 <=3D 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)) { > --=20 > 2.43.0.472.g3155946c3a-goog >=20