From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380253; b=HSHx2aNXya8kT0wvFsltRLkEk+YKbP/j7SochRzto4A7eqS9PdEs6QfXNW0JO3E+roSl 5v7vEfxGJNm3NMYBKCAXzwCmGxbcvhYpF8w4qCzwxsKLhkv+NcESpxrLexccbXPHDIKYt yZYyBXfLIf0dbx0vO+UzNfoM3M493jQ2BmwuO/JnbcK++Ye5QMjj2FK9BgqpmMBr1fvn3 g9p8Xmgl4p2z+pwwcnRs2wImiWUEfuBlUeq9lZdSIUjo22iBjaaNWO5biQZ+x8pg9MQyl NPVAphnio3/qqxFfpeNAhmtxyTPI28IQdvIZDxsllsSyw4NzllS8+YTzI1rpIk8FsiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380253; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=mCfL4tZ4F1YtU+r7QyXByrvvAGPepB23LouVq0ge+2k=; b=p6uLpiaHSW1nJcdwBZ7vD06AfcTYAk7CA0O3OivFhrYbhjTZGnynW2OwYtgt+NOzwIsy Kt+T5GZRXmiRVe7QYjX+hfc8YBe+S+rwF7mIUwO4TyFW1LlH3QhnfULzoC0cypsw7Xw9w fDg8fMI0b15S4slf3qGn90ZJwGwES0jdIGuLGGeSdgLaQ6XoXPLqwNNIePnp0fLZqkRIR uTktgHZxSQZmgH034pYGepQJf/O9Ru+YexKOcYQp9vEqW61C0BbtxJJvlWWIfhHUt+qxy VD7ZZWj5HAt1OeimlXvtD137dEJW+su/yoYlcZtXl0TDGDfpTPTk+KJyvfE2zghHPTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=C+J+yxiO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA08B606A322; Fri, 4 Dec 2026 10:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=C+J+yxiO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F2EB1F000CE; Fri, 4 Dec 2026 10:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380252; bh=mCfL4tZ4F1YtU+r7QyXByrvvAGPepB23LouVq0ge+2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=C+J+yxiO3N7BjU2Y5CYRLosMUgx1eXdIOGNEwSbPpDBXk03EEojSOXbJkWbt+vi73 5753LY/v/gOSMDaOlwqhqeNj/MX4Azvl1uRNCGzzumjFsek6c6NYTQQecfEdOC4uGD cikU9Z81VyafM0jf3aQJHUBugEfespf9NEf6CuWg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Paul E. McKenney" , Bart Van Assche , "Peter Zijlstra (Intel)" , Ingo Molnar , Sasha Levin Subject: [PATCH 7.3 194/742] srcu: Make the srcu_dereference_check() reader lock check conditional Date: Fri, 4 Dec 2026 19:00:58 +0900 Message-ID: <20261204100640.234386412@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche [ Upstream commit e2652119b5944e7732ff856ba8057afaa28f5ac8 ] Users of srcu_dereference_check() must either hold an SRCU reader lock or satisfy the lockdep condition 'c', e.g. by holding the update-side lock. However, srcu_dereference_check() calls __srcu_read_lock_must_hold(), which tells the Clang context analyzer that the SRCU reader lock must be held. That requirement is too strict for update-side callers. Hence, only call __srcu_read_lock_must_hold() from srcu_dereference_check() if 'c' is the compile-time constant 0, i.e. if there is no update-side protection. Keep the fake RCU acquire and release around __rcu_dereference_check() and also keep the runtime lockdep check in srcu_dereference_check(). Use const_true() instead of __builtin_constant_p() to test whether 'c' is the constant 0. const_true() is based on __is_constexpr(), a sizeof() trick that the compiler front end always evaluates, so the Clang context analysis sees an integer constant expression. If 'c' is a plain variable, function argument or structure member, Clang may leave __builtin_constant_p(c) for the optimizer to decide. The context analysis then considers the __srcu_read_lock_must_hold() call reachable and reports a false positive. Additionally, const_true() never evaluates a non-constant 'c' at runtime, so the runtime behavior does not change. srcu_dereference() passes 0 as 'c' and hence gets the compile-time check automatically. srcu_dereference_notrace() does not accept a lockdep condition and hence may only be used by SRCU readers. Since it passes 1 as 'c', call __srcu_read_lock_must_hold() explicitly from srcu_dereference_notrace() such that the Clang context analysis keeps verifying at compile time that its callers hold the SRCU reader lock. Fixes: f0b7ce22d718 ("srcu: Support Clang's context analysis") Suggested-by: Paul E. McKenney Signed-off-by: Bart Van Assche Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Paul E. McKenney Link: https://patch.msgid.link/459250d4f2a6aa38ebab3fb51f6d4a63815bb4a1.1795043161.git.bvanassche@acm.org Signed-off-by: Sasha Levin --- include/linux/srcu.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 1c221861ba43f..834d075f4ad5d 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -265,6 +265,10 @@ static inline int srcu_read_lock_held(const struct srcu_struct *ssp) * with __guarded_by(ssp) as it would complicate annotations for writers, we * choose the following strategy: srcu_dereference_check() calls this helper * that checks that the passed ssp is held, and then fake-acquires 'RCU'. + * srcu_dereference_check() only calls this helper if @c is the compile-time + * constant 0 because otherwise its callers may satisfy the condition @c + * instead of holding ssp, e.g. on the update side. srcu_dereference_notrace() + * passes 1 as @c and hence calls this helper explicitly. */ static inline void __srcu_read_lock_must_hold(const struct srcu_struct *ssp) __must_hold_shared(ssp) { } @@ -282,7 +286,8 @@ static inline void __srcu_read_lock_must_hold(const struct srcu_struct *ssp) __m */ #define srcu_dereference_check(p, ssp, c) \ ({ \ - __srcu_read_lock_must_hold(ssp); \ + if (const_true(!(c))) \ + __srcu_read_lock_must_hold(ssp); \ __acquire_shared_ctx_lock(RCU); \ __auto_type __v = __rcu_dereference_check((p), __UNIQUE_ID(rcu), \ (c) || srcu_read_lock_held(ssp), __rcu); \ @@ -308,7 +313,11 @@ static inline void __srcu_read_lock_must_hold(const struct srcu_struct *ssp) __m * @ssp: pointer to the srcu_struct, which is used to check that we * really are in an SRCU read-side critical section. */ -#define srcu_dereference_notrace(p, ssp) srcu_dereference_check((p), (ssp), 1) +#define srcu_dereference_notrace(p, ssp) \ +({ \ + __srcu_read_lock_must_hold(ssp); \ + srcu_dereference_check((p), (ssp), 1); \ +}) /** * srcu_read_lock - register a new reader for an SRCU-protected structure. -- 2.53.0