From patchwork Thu Dec 12 18:51:24 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: 13905858 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 303CC1A7273; Thu, 12 Dec 2024 18:51:28 +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=1734029488; cv=none; b=Om2PQ6qlz0oWbsEElpI6Ck+LFNZFlAKt/hsJR2L9JoUQ7RUNMBdJ1Wf58trF2Kiv+mOmiS9nnjoYodga7dAr+E6bbR23K/CN8ZyHbo9f6fWtS2KeBtyG7pE+eTsKwhR9avY6y7NP0NFi+eBTu3jr+9KmYAtTyvXxImGXdHhPKWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734029488; c=relaxed/simple; bh=9LAc+KmzGouRxxmiYt4dsholAgVMkHQ0Pn+gD/Oc/CA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mwnSbaKsfa3CGUfNLmJZ2E6COZVONoxyLuYE+BeOTbXvLzv1VhoGnf3ALYlq3ri98iOrat25SMlh/EVIKL2l1nfLifBayHjtIBPfzolGy47hNCKnr1GcuA+dcYClAObCvbDo9dmyPaBTwhjRJO9kBWkT0Z9MbwE/ccBhmvgYOtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SXKQijTd; 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="SXKQijTd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D1E4C4CECE; Thu, 12 Dec 2024 18:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734029488; bh=9LAc+KmzGouRxxmiYt4dsholAgVMkHQ0Pn+gD/Oc/CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXKQijTdfcekib4r9pTkqLNtX5yrcOCqY/7AIRyaAnHxQhG/7KDpd5aD92vWYt6sf /HyRDtr9l40bz+zm7cXLUCMqnl44npV/yluIGfshWj2l8dWmAnT5coL8uxMxPeVvh6 /yA7h8p6J03Y/nzevGSRk3R2XuGV/2QTHQmxboZ1ifx9wqVtEtyFRocnFzhIOYN6Yg 7AEWH5kBvkkfb3g4DfU6d3lUaP58yfRLaGk/IY5U7UnaXGVlgQ+BCfSQdD7epCCQ7m ms9w2kfv2N03K+BgZgBs7irURy9gPSwTzua80eh77qunVmJRH97vS1SkjFG+CONFvq CdW64HbpfWdxw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C12FDCE0F53; Thu, 12 Dec 2024 10:51:27 -0800 (PST) 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" , Andrii Nakryiko , Peter Zijlstra Subject: [PATCH rcu 1/3] srcu: Guarantee non-negative return value from srcu_read_lock() Date: Thu, 12 Dec 2024 10:51:24 -0800 Message-Id: <20241212185126.2193701-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For almost 20 years, the int return value from srcu_read_lock() has been always either zero or one. This commit therefore documents the fact that it will be non-negative, and does the same for the underlying __srcu_read_lock(). [ paulmck: Apply Andrii Nakryiko feedback. ] Signed-off-by: Paul E. McKenney Acked-by: Andrii Nakryiko Acked-by: Peter Zijlstra (Intel) --- include/linux/srcu.h | 15 ++++++++------- kernel/rcu/srcutree.c | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 08339eb8a01c8..abaddd7e6ddf7 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -232,13 +232,14 @@ static inline int srcu_read_lock_held(const struct srcu_struct *ssp) * a mutex that is held elsewhere while calling synchronize_srcu() or * synchronize_srcu_expedited(). * - * The return value from srcu_read_lock() must be passed unaltered - * to the matching srcu_read_unlock(). Note that srcu_read_lock() and - * the matching srcu_read_unlock() must occur in the same context, for - * example, it is illegal to invoke srcu_read_unlock() in an irq handler - * if the matching srcu_read_lock() was invoked in process context. Or, - * for that matter to invoke srcu_read_unlock() from one task and the - * matching srcu_read_lock() from another. + * The return value from srcu_read_lock() is guaranteed to be + * non-negative. This value must be passed unaltered to the matching + * srcu_read_unlock(). Note that srcu_read_lock() and the matching + * srcu_read_unlock() must occur in the same context, for example, it is + * illegal to invoke srcu_read_unlock() in an irq handler if the matching + * srcu_read_lock() was invoked in process context. Or, for that matter to + * invoke srcu_read_unlock() from one task and the matching srcu_read_lock() + * from another. */ static inline int srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp) { diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 5e2e534647946..26ef58b481aae 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -738,7 +738,8 @@ EXPORT_SYMBOL_GPL(__srcu_check_read_flavor); /* * Counts the new reader in the appropriate per-CPU element of the * srcu_struct. - * Returns an index that must be passed to the matching srcu_read_unlock(). + * Returns a guaranteed non-negative index that must be passed to the + * matching __srcu_read_unlock(). */ int __srcu_read_lock(struct srcu_struct *ssp) { From patchwork Thu Dec 12 18:51:25 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: 13905859 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 30380189916; Thu, 12 Dec 2024 18:51:28 +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=1734029488; cv=none; b=Y5spPHacE/EwRALS3gEVXLBpZ6YgJWogdSsIh2PVaW998mtyaFFVVSxedhdxW1vQTbhkOe9R645nXsa52irAZiJqdye/fo3UZhPx80VxGTr/Z4NuQw3PfAcQtHbuVZFC3H8MYKNTAeO6EOqmIzTbzWM4sen5F/P6itEmjCJ0HCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734029488; c=relaxed/simple; bh=C7eNfOunp8AOccxcceOKWVykhMqpmtYNlnqR2il+3Gc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zf6iceB3C2ZsH++1/oU98KyxYpQmbaAIQ8zUMIdFE6BC66WOZqEXMSftdYJlwf5F/77nncElnZDBzodJrNfDHAnfl0zKY4aUIpmZZWIrBvfHqD726MEyM233b+X1mCaFZecL/H0oP51HInuqxBE5/GVAhoAsXi/3JaVx06aMBHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RN4VUq9O; 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="RN4VUq9O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D21EC4CED0; Thu, 12 Dec 2024 18:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734029488; bh=C7eNfOunp8AOccxcceOKWVykhMqpmtYNlnqR2il+3Gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RN4VUq9Oxsjo5YltAnWWVlFXi278Tsgtnyn/WOGxBNqiNBUV3CrgVZMxN3gm+1xQq zb/2qBcc1I1Rz/zW7i2GmWPRx/p+IUIMIfaj3D55cPfw1exEdJ1OstvZGtNGuI5KQS ucJPg7rUz0QiSV6EeJg3vJdVsbulyX+q6thXHcSyaNcxEvx1vk5TDK6PzR3nGPFCh1 NOeEsP6o1/eEKkhReGdTkkg3UiPQ9/R3r8rWt5jKGd0gwNqY7kmPrmxPap6yZJK07U DX4MEPwZ7Lb4+F7HwDgf/5RVlhYnAwP7h1qZbe7R3YCbx/N/o3sncr1om250BhjxRQ NB9OGX0BRv+6A== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C3B68CE0F78; Thu, 12 Dec 2024 10:51:27 -0800 (PST) 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" , Neeraj Upadhyay Subject: [PATCH rcu 2/3] srcu: Fix typo s/srcu_check_read_flavor()/__srcu_check_read_flavor()/ Date: Thu, 12 Dec 2024 10:51:25 -0800 Message-Id: <20241212185126.2193701-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This commit fixes a typo in which a comment needed to have been updated from srcu_check_read_flavor() to __srcu_check_read_flavor(). Reported-by: Neeraj Upadhyay Closes: https://lore.kernel.org/all/b75d1fcd-6fcd-4619-bb5c-507fa599ee28@amd.com/ Signed-off-by: Paul E. McKenney --- include/linux/srcutree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 490aeecc6bb47..4e69f88bcab9f 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -258,7 +258,7 @@ static inline void srcu_check_read_flavor_lite(struct srcu_struct *ssp) if (likely(READ_ONCE(sdp->srcu_reader_flavor) & SRCU_READ_FLAVOR_LITE)) return; - // Note that the cmpxchg() in srcu_check_read_flavor() is fully ordered. + // Note that the cmpxchg() in __srcu_check_read_flavor() is fully ordered. __srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_LITE); } From patchwork Thu Dec 12 18:51:26 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: 13905860 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 92B191ABECA; Thu, 12 Dec 2024 18:51:28 +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=1734029488; cv=none; b=Qh08vunu7uRBNtyLmak9FxmgocUmF7iToHgjbUOnPPB54uMr+D/JyAPCRkfGkIGBoMmgpmDYTeQNJQgjKNjheoL9huW514yRuZMXf6hBzJsIhGRod3SUxxvN9c1bbaKj8rCUgZOOZHFSata9snQ3eWCHYm+yp5t4DNsLMEN1KnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734029488; c=relaxed/simple; bh=gqxisnv0SFoQNhSBdAUzLSQ+6u7ZhkbzFupLt3evPrw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U9bEmH7YUbJOeFjlxnuVa15nv9aNXHWodM/6G7d8CPC3lxZogMWg9k3zaETfXxGMTvY9SM9IVDx0i93lAnQywCgMaJp9sXvcgVETgFcTasUI1MdhKossSs6gNyAaLmhsK1cBFOk5JQMbTi8b1sOznrC7Z4txBOGYj1xO361DAjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sI8N1JzH; 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="sI8N1JzH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12244C4CED3; Thu, 12 Dec 2024 18:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734029488; bh=gqxisnv0SFoQNhSBdAUzLSQ+6u7ZhkbzFupLt3evPrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sI8N1JzHB1gjKaUMNLXY5kJWkdc3efR5qvdqhDuVHIDndi1GRObGSVThbo3sfzCHV fhS+/sx2D8+CMJ3kRZJ+CVGjhQuxN3SmOqUIuQd7pvhuwYwyyq+rA9OQdsOMIxBRHb qzqx8reKkQmxENaTDjuvso04uqb0P1C9/pp6oyZ7413Yc/Y0HheCohQlTeTEO5HgDI swt8tuB/UIrTzPwSz712aVlDKpHSRPFP/2xxPzM/RebPvJbQqSQEThLWVCfar3FsZC MgJQ5XbhCCYknpHP4FAQYmvFkP8rMK53+dVUSB5zJ/Fb8zpu+EAJF8jbTJZdxzDPG5 5FI3m54nTg3aQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C66D3CE0F9A; Thu, 12 Dec 2024 10:51:27 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Feng Lee <379943137@qq.com>, "Paul E . McKenney" Subject: [PATCH rcu 3/3] srcu: Remove redundant GP sequence checks in srcu_funnel_gp_start Date: Thu, 12 Dec 2024 10:51:26 -0800 Message-Id: <20241212185126.2193701-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Feng Lee <379943137@qq.com> We will perform GP sequence checking at the beginning of srcu_gp_start, thus making it safe to remove duplicate GP sequence checks prior to calling srcu_gp_start. Signed-off-by: Feng Lee <379943137@qq.com> Signed-off-by: Paul E. McKenney --- kernel/rcu/srcutree.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 26ef58b481aae..b83c74c4dcc0d 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1077,7 +1077,6 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, /* If grace period not already in progress, start it. */ if (!WARN_ON_ONCE(rcu_seq_done(&sup->srcu_gp_seq, s)) && rcu_seq_state(sup->srcu_gp_seq) == SRCU_STATE_IDLE) { - WARN_ON_ONCE(ULONG_CMP_GE(sup->srcu_gp_seq, sup->srcu_gp_seq_needed)); srcu_gp_start(ssp); // And how can that list_add() in the "else" clause