From patchwork Thu Jun 20 16:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13705801 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 C3D341B14FC; Thu, 20 Jun 2024 16:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718899903; cv=none; b=auW8lwsJsOOpjtoylAGRXQuMp0H3H5UL6MY8WtlhRyN0Ls7vKn+IVlnpznvJagNgvMuSGHNshsWV8cS+6zefIui2RvT0kYDFOmz22fumyRa0WUWNZX+zPxMA2C1mQfeBIDF1g+JnztnB48bLhepgE+NNfuaKyedVXy3nBeLvomo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718899903; c=relaxed/simple; bh=euBix38Jm8G67OEkavVkD0JdJFe2SQTY6LiqJ3ZgmuA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d1NEUNNQJbTmIF3GMPZ4yzhRBX066eJEfq5VYc24W6mNxA49kSQOHuf/oTEbrajvQLFUBFk5u51OC+BGGXHgIIBUDZfdOHm2ccr6RaXTei6aM4m+FEnrj1d4/R9i/Y2HvrWxs7WLbpsBw31E7/OZ2IBVxLH5EY6GMFh9etmEE7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mX9S0qMX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mX9S0qMX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93576C2BD10; Thu, 20 Jun 2024 16:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718899903; bh=euBix38Jm8G67OEkavVkD0JdJFe2SQTY6LiqJ3ZgmuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mX9S0qMXW3h9nUgO7SpvxqsaGe16oRmI0FE4yUbKvVlBY8rQM9zDOl/5tOjJQPWpI 52lLH8ax402ypYCC2Ngx3oN0YG3tyJ0k7Z0WM38FVjGVChSDHOzLjI94obCDY5NmMW H86JHs4s3fbl1gr4d5qR8QpzWVZXHAp6xFV2rgVIxHws5lADosRoUp3devUBbPgf7j nM8Nxc8RacqddjHY+SK7FdzEFH5C7jOSXqALSRwp/G4zEcAIye9ft/kDZB5CqvawtI vRUXwG13gVjagkpuCFIFqhaXNXbRT/tQ0nD4D4Vz2r3x/T+5rfFW84d5DpkJlVv6Wk yKg6dxOaiqlcA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 4D632CE0B67; Thu, 20 Jun 2024 09:11:43 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Kent Overstreet Subject: [PATCH rcu 1/3] srcu: Add NUM_ACTIVE_SRCU_POLL_OLDSTATE Date: Thu, 20 Jun 2024 09:11:40 -0700 Message-Id: <20240620161142.2057652-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8ec14282-a768-49eb-b870-c2ee51e91f8b@paulmck-laptop> References: <8ec14282-a768-49eb-b870-c2ee51e91f8b@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit adds NUM_ACTIVE_SRCU_POLL_OLDSTATE, which gives the maximum number of distinct return values from get_state_synchronize_rcu() that can, at a given point in time, correspond to not-completed SRCU grace periods. Reported-by: Kent Overstreet Closes: https://lore.kernel.org/all/irycqy4sinjdgm2hkyix2bffunpcmuwgeufsx6nlljvqme3wiu@ify3zdnrmzph/ Signed-off-by: Paul E. McKenney --- include/linux/srcu.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 236610e4a8fa5..f664cba7a80c2 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -61,6 +61,10 @@ unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp); unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp); bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie); +// Maximum number of unsigned long values corresponding to +// not-yet-completed SRCU grace periods. +#define NUM_ACTIVE_SRCU_POLL_OLDSTATE 2 + #ifdef CONFIG_NEED_SRCU_NMI_SAFE int __srcu_read_lock_nmisafe(struct srcu_struct *ssp) __acquires(ssp); void __srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx) __releases(ssp); From patchwork Thu Jun 20 16:11:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13705802 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 03ACE1B1518; Thu, 20 Jun 2024 16:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718899904; cv=none; b=YLx0LFqwm1OquML+tG3sJkROcvkjCLzhjht//7o8Z7AziowLM6SfvVNcOPOH7sGOQKWsgm6OsSJwnd3zqkmw2J3a5uOYEyrd9AIs3J+4uP4p/6zCw0UqhqV76sWg6hEj84VSkEyr7WQiuAcVJnwMrHxABAje6ZLDZk5L75tX9Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718899904; c=relaxed/simple; bh=4Xi9ciSTlq6j4E49TuJlERCWIvwfb9dALhACmcCI9pg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dcskf8V/xbZkOhAqo6jJ5g3CTya4bzeHyMzh+3WcntvUd0SzX9vRQ23VcEjFdOyFuAJCk6u3rzG5y1UlbxPYIA8X0QbOH+Jfvf91Vha0U/xin3+ITgr8imQ9ItuBiMvrFDgqV9AdyKFBwaYRi2/e2pjfmhgFJlWbFPAK5A7KPdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b9FeimLp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b9FeimLp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A365FC4AF08; Thu, 20 Jun 2024 16:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718899903; bh=4Xi9ciSTlq6j4E49TuJlERCWIvwfb9dALhACmcCI9pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b9FeimLp8lBYrd0+KNMBej57ppp0VMRRWSxCjdWxw9ewrbXJCxxjJ+0vBIG81uggQ DV93bSKTwrM60hOM/1rPmGyp1vQuLL2lamsjOWapQCeRIHLS3AMFZ7kAKbQmcx8xoN dq3pec0oHwtu/MjpY22ZIRpxzc4NS7NcoNYz4Hu9fgbR6pLZZV2CAGU8FbjaCZY0cp DmwscVract3JjRMT7u2GzYinDCfnkVvcrDtreIuGKeHw4h9v2EEPcPxuhxL0STsSB2 iejSZKGvAtWa5vwkHrVhZPteJkJQAaHyjOpCqILW/ZZyfTEOV3yJjpsY9/4g/GGKtR jIYMTBX+qr4bA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 50C51CE0BA3; Thu, 20 Jun 2024 09:11:43 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" Subject: [PATCH rcu 2/3] srcu: Update cleanup_srcu_struct() comment Date: Thu, 20 Jun 2024 09:11:41 -0700 Message-Id: <20240620161142.2057652-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8ec14282-a768-49eb-b870-c2ee51e91f8b@paulmck-laptop> References: <8ec14282-a768-49eb-b870-c2ee51e91f8b@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we have polled SRCU grace periods, a grace period can be started by start_poll_synchronize_srcu() as well as call_srcu(), synchronize_srcu(), and synchronize_srcu_expedited(). This commit therefore calls out this new start_poll_synchronize_srcu() possibility in the comment on the WARN_ON(). Signed-off-by: Paul E. McKenney --- kernel/rcu/srcutree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index bc4b58b0204e9..15dc22a8ff5ab 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -667,7 +667,10 @@ void cleanup_srcu_struct(struct srcu_struct *ssp) pr_info("%s: Active srcu_struct %p read state: %d gp state: %lu/%lu\n", __func__, ssp, rcu_seq_state(READ_ONCE(sup->srcu_gp_seq)), rcu_seq_current(&sup->srcu_gp_seq), sup->srcu_gp_seq_needed); - return; /* Caller forgot to stop doing call_srcu()? */ + return; // Caller forgot to stop doing call_srcu()? + // Or caller invoked start_poll_synchronize_srcu() + // and then cleanup_srcu_struct() before that grace + // period ended? } kfree(sup->node); sup->node = NULL; From patchwork Thu Jun 20 16:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13705803 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 03A741B1514; Thu, 20 Jun 2024 16:11:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718899904; cv=none; b=t4gPFNxBXsML8ZwYJ2yDl/scmwCLGm2r4/kU36kDxgmiERTX3ItDpaimxgVJKjbbZN+0lOwksB5MUd39PLf54Sghu29yVJz49MdMdb5etNnC5G9MbP9i76uv98/H53pCBc+Jbh+BFnxkDasXzgIMiuyyKiiqyQ0m/EkrdkADxgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718899904; c=relaxed/simple; bh=moqkrVqx95CFhHpEKKGXhdPr5fPQ9IbFq3m1fia5tT4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XCq880x7/fpH3NaVzdDgQqtTLubt73f8Um60tdqVTpX6zt2vF/BW2gyhJE1Ly5OnQ3nCgPuD9gfyKcl33N2XlwFxpWgWrkbnOewpfZvzDv5gBvQWsGWTst8PdANXHZ3JqdVbaBmu5LAZy8ILYX+qZt3/j2ZoPNTyorLsmttB1nk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hVwCxk7m; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hVwCxk7m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A72BBC4AF0A; Thu, 20 Jun 2024 16:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718899903; bh=moqkrVqx95CFhHpEKKGXhdPr5fPQ9IbFq3m1fia5tT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVwCxk7mflF3ByQBM3cGd6r6Lu94QLOknEe7PvZUcLYt/uiaYTUVGaBrYhS5FiwX7 kfxUJf0r2xhcRrcncw9rKnIFWR5uJYwGU75mAfaNh03kwBUohSctZqml6YJ2IJVamJ 8iS+ifUihbHnTvvpuDxtuOnTgSMnu7I1HQXHLIMp+k0an2KolZDorsHzU6dlX+KsqS M0OJEohb1TewF4FNja9lXSQzxhXycxtESiGBAqSF+VRCB55gDBaYDQ12WUClGPr1Vt ERCF0ISiIJGjFfxtIBYXSczhNjQ657rscHBlwAjCoXXdx5zMAuC6IdV9KFc8nUhkqp w5nHDytpDwrTw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 540D9CE0D11; Thu, 20 Jun 2024 09:11:43 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Kent Overstreet Subject: [PATCH rcu 3/3] srcu: Fill out polled grace-period APIs Date: Thu, 20 Jun 2024 09:11:42 -0700 Message-Id: <20240620161142.2057652-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <8ec14282-a768-49eb-b870-c2ee51e91f8b@paulmck-laptop> References: <8ec14282-a768-49eb-b870-c2ee51e91f8b@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit adds the get_completed_synchronize_srcu() and the same_state_synchronize_srcu() functions. The first returns a cookie that is always interpreted as corresponding to an expired grace period. The second does an equality comparison of a pair of cookies. Signed-off-by: Paul E. McKenney Cc: Kent Overstreet --- include/linux/srcu.h | 31 +++++++++++++++++++++++++++++++ kernel/rcu/srcutiny.c | 3 ++- kernel/rcu/srcutree.c | 3 ++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index f664cba7a80c2..6f6cb5fc12424 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -57,6 +57,20 @@ void cleanup_srcu_struct(struct srcu_struct *ssp); int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp); void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp); void synchronize_srcu(struct srcu_struct *ssp); + +#define SRCU_GET_STATE_COMPLETED 0x1 + +/** + * get_completed_synchronize_srcu - Return a pre-completed polled state cookie + * + * Returns a value that poll_state_synchronize_srcu() will always treat + * as a cookie whose grace period has already completed. + */ +static inline unsigned long get_completed_synchronize_srcu(void) +{ + return SRCU_GET_STATE_COMPLETED; +} + unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp); unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp); bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie); @@ -65,6 +79,23 @@ bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie); // not-yet-completed SRCU grace periods. #define NUM_ACTIVE_SRCU_POLL_OLDSTATE 2 +/** + * same_state_synchronize_srcu - Are two old-state values identical? + * @oldstate1: First old-state value. + * @oldstate2: Second old-state value. + * + * The two old-state values must have been obtained from either + * get_state_synchronize_srcu(), start_poll_synchronize_srcu(), or + * get_completed_synchronize_srcu(). Returns @true if the two values are + * identical and @false otherwise. This allows structures whose lifetimes + * are tracked by old-state values to push these values to a list header, + * allowing those structures to be slightly smaller. + */ +static inline bool same_state_synchronize_srcu(unsigned long oldstate1, unsigned long oldstate2) +{ + return oldstate1 == oldstate2; +} + #ifdef CONFIG_NEED_SRCU_NMI_SAFE int __srcu_read_lock_nmisafe(struct srcu_struct *ssp) __acquires(ssp); void __srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx) __releases(ssp); diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c index 5afd5cf494dba..549c03336ee97 100644 --- a/kernel/rcu/srcutiny.c +++ b/kernel/rcu/srcutiny.c @@ -277,7 +277,8 @@ bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie) unsigned long cur_s = READ_ONCE(ssp->srcu_idx); barrier(); - return ULONG_CMP_GE(cur_s, cookie) || ULONG_CMP_LT(cur_s, cookie - 3); + return cookie == SRCU_GET_STATE_COMPLETED || + ULONG_CMP_GE(cur_s, cookie) || ULONG_CMP_LT(cur_s, cookie - 3); } EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu); diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 15dc22a8ff5ab..d6a4047719cb0 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1543,7 +1543,8 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu); */ bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie) { - if (!rcu_seq_done(&ssp->srcu_sup->srcu_gp_seq, cookie)) + if (cookie != SRCU_GET_STATE_COMPLETED && + !rcu_seq_done(&ssp->srcu_sup->srcu_gp_seq, cookie)) return false; // Ensure that the end of the SRCU grace period happens before // any subsequent code that the caller might execute.