Received: by 2002:a05:7412:8d23:b0:f7:29d7:fb05 with SMTP id bj35csp403652rdb; Sat, 16 Dec 2023 13:17:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmcx96ZjHajxCNs+y2YWE6kmIC4v5TIGwph5MuKZrvs/HBxOu+AG0/4/mRiTEB1HMFqCRr X-Received: by 2002:a05:6358:5483:b0:172:c98d:75d4 with SMTP id v3-20020a056358548300b00172c98d75d4mr738311rwe.57.1702761450192; Sat, 16 Dec 2023 13:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702761450; cv=none; d=google.com; s=arc-20160816; b=LTvULXfgCzXmvwnboJFcM2rIH9pVnZrMGAA2Dhneqcbx8XA48Q5NJfOKL6CLIe8HO2 kuKUJBlsZ3lkbQ+T5NLQSXS2Pq4LXnGEU0PSBlGB+ATsl1lahVKIk0BOA+MtoJEEC9to CmQTxLS0Rbh+F1X/xORkHPFnnTlOuIvxYF9BHueKXB92fpqZtc9XGqJpa2/GxojBs677 U9u6Ad4sSYMnYVar8OpkT2+HomAI9R3ftspFTvWzG5dMhWoff2lkaoBky/O2BFdW5tAW B0FSpNqjYm9CGLbAPFYlXyA3XyYj1DW1Zufxdh/xOVYuRJk7Rw+w32qjtx9DZNHU/Slt 5riw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yHvxhyo6vLoqFbfAMRmY2TiVPeZ6Y0X4GmgttqJq3F0=; fh=T8G8gwNewJVtt6ZOY5WfLiqd18aBvARPvXcqIhTaiuo=; b=Dorl6lRrR/t8qNvLRLrRKY5csjdct1aje0irHDpcRj/bRv+Vi/Q1u69bnpXK05YA2Q 0aE/z8gDiXvKH9X5hIXiWGGSW+3hXzbeDVSi7lG3qOLtm08cHu2mVmLSMIJXyBiaP5Rs A8P20+cLBpaEHOPV5DOhE1z6daGy3gzNfEPCCrRz9BbUV/HgLsheF0//IlZIxCRElLbI 4tEZzSUhRfCBU/kMVmJ8HoWEMqdRL5L/oQPCxsYopiMeA7QNmemMzf2AGHtVADMfs0G1 p2vJuwZ7ywufrfJ7gupeBZONv0KRLRJ7xGget3sj8sp3zt08OD8a2D7WatI5UdWSMnoF 65tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BR3kSWoS; spf=pass (google.com: domain of linux-kernel+bounces-2372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c24-20020a17090ad91800b002865a80ceb3si333976pjv.2.2023.12.16.13.17.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 13:17:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BR3kSWoS; spf=pass (google.com: domain of linux-kernel+bounces-2372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2372-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CD675284F87 for ; Sat, 16 Dec 2023 21:17:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28BA135292; Sat, 16 Dec 2023 21:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BR3kSWoS" 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 5578235280; Sat, 16 Dec 2023 21:17:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94E0FC433C7; Sat, 16 Dec 2023 21:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702761444; bh=wbCb7V8TWLXWLW8MxcJ7qPWIEaOem3AcnmRfFX2rmA8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BR3kSWoS8OnHrcL5hEm2lXZG3sB12hceeVyLBjari4NMpLXOYePN/QDTFWzI9195P eqxj/EPR3V+O3Wvnx0u00KFm5QygsEJSga2X2/PMfPif1ZVt7+g0okfxCJEKPy2wg+ rMpSe8NLr4ikom0S4unHw7q/yJnmmkmyEGeYv1H5S9DPf2qgaEGO2rb4kFAyNh5F3V WyJWM6uziWjiGrL+CzoerPZwOTATuByWWwo6mQApSDU8rdIKv1B4BU8i7YBH3g8inm gRfxbry2VSOc8sRyXhUIkds17cPQeItegGe7BufMjSJ3uD7BJHAAdhozQcSsfozGza Ngwifx+19eDDg== Date: Sat, 16 Dec 2023 22:17:20 +0100 From: Frederic Weisbecker To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Neeraj Upadhyay , rcu@vger.kernel.org Subject: Re: [PATCH v2] srcu: Improve comments about acceleration leak Message-ID: References: <20231211015717.1067822-1-joel@joelfernandes.org> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231211015717.1067822-1-joel@joelfernandes.org> Le Mon, Dec 11, 2023 at 01:57:16AM +0000, Joel Fernandes (Google) a ?crit : > 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 first person doesn't exist :-) > 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 > 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(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. What do you mean by "state" here? If it's the gp_seq number, that doesn't look right. The situation raising the initial bug also involved a gp_seq used for advancing <= the gp_seq used for acceleration. Thanks. > + 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 >