From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
rostedt@goodmis.org, Ricardo Ribalda <ribalda@chromium.org>,
Dan Carpenter <dan.carpenter@linaro.org>,
Joel Fernandes <joelagnelf@nvidia.com>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH v2 10/10] rcu: Drop the address space qualifier from the dereference macros
Date: Wed, 7 Oct 2026 13:45:11 -0700 [thread overview]
Message-ID: <20261007204511.1982646-10-paulmck@kernel.org> (raw)
In-Reply-To: <df33a614-9c3d-423d-9d31-b1846cb1f1d6@paulmck-laptop>
From: Ricardo Ribalda <ribalda@chromium.org>
The RCU dereference macros end with a cast that is meant to hand back a
plain kernel pointer from a __rcu pointer.
For that it uses:
((typeof(*p) __force __kernel *)(local))
The problem is that typeof preserves every qualifier, including the
address space qualifiers (__rcu).
Recent versions of smatch[1] care about this and throw tens of warnings
like this one:
./include/trace/events/vb2.h:46:1: warning: incorrect type in assignment (different address spaces)
./include/trace/events/vb2.h:46:1: expected struct tracepoint_func *it_func_ptr
./include/trace/events/vb2.h:46:1: got struct tracepoint_func __rcu *
Use a new macro TYPEOF_NO_ADDRESS_SPACE() for the result type. This new
macro strips all the qualifiers when running with sparse (so const and
volatile are gone). But keeps all the qualifiers when running with the
compiler, caring about const/volatile mismatch.
[1] https://github.com/error27/smatch/commit/e53027a4e816a772403baafa83c09e4a94c1cb8f
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20260825-unqual-v1-1-7024fb81b4f9@chromium.org
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
include/linux/compiler.h | 17 +++++++++++++++++
include/linux/rcupdate.h | 10 +++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index cb2f6050bdf7d..70cb31d605384 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -239,6 +239,23 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
# define TYPEOF_UNQUAL(exp) __typeof__(exp)
#endif
+/*
+ * TYPEOF_NO_ADDRESS_SPACE() - typeof() without the address space qualifiers
+ *
+ * No operator strips only the address space qualifiers: typeof() keeps every
+ * qualifier and TYPEOF_UNQUAL() drops every qualifier, const and volatile
+ * included.
+ *
+ * Approximate one by dropping the qualifiers for sparse only, as it is the
+ * only one that knows about address spaces. The compiler keeps seeing the fully
+ * qualified type, so a missing const or volatile will still throw a warning.
+ */
+#ifdef __CHECKER__
+# define TYPEOF_NO_ADDRESS_SPACE(exp) TYPEOF_UNQUAL(exp)
+#else
+# define TYPEOF_NO_ADDRESS_SPACE(exp) __typeof__(exp)
+#endif
+
#endif /* __KERNEL__ */
#if defined(CONFIG_CFI) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 44c07a66edfff..3f74ae6d6e1f2 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -488,7 +488,7 @@ static __always_inline bool lockdep_assert_rcu_helper(bool c, const struct __ctx
context_unsafe( \
typeof(*p) *local = (typeof(*p) *__force)(p); \
rcu_check_sparse(p, __rcu); \
- ((typeof(*p) __force __kernel *)(local)) \
+ ((TYPEOF_NO_ADDRESS_SPACE(*p) __force __kernel *)(local)) \
)
/**
* unrcu_pointer - mark a pointer as not being RCU protected
@@ -503,7 +503,7 @@ context_unsafe( \
({ \
typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
rcu_check_sparse(p, space); \
- ((typeof(*p) __force __kernel *)(local)); \
+ ((TYPEOF_NO_ADDRESS_SPACE(*p) __force __kernel *)(local)); \
}) )
#define __rcu_dereference_check(p, local, c, space) \
({ \
@@ -511,19 +511,19 @@ context_unsafe( \
typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \
RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_check() usage"); \
rcu_check_sparse(p, space); \
- ((typeof(*p) __force __kernel *)(local)); \
+ ((TYPEOF_NO_ADDRESS_SPACE(*p) __force __kernel *)(local)); \
})
#define __rcu_dereference_protected(p, local, c, space) \
({ \
RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \
rcu_check_sparse(p, space); \
- ((typeof(*p) __force __kernel *)(p)); \
+ ((TYPEOF_NO_ADDRESS_SPACE(*p) __force __kernel *)(p)); \
})
#define __rcu_dereference_raw(p, local) \
({ \
/* Dependency order vs. p above. */ \
typeof(p) local = READ_ONCE(p); \
- ((typeof(*p) __force __kernel *)(local)); \
+ ((TYPEOF_NO_ADDRESS_SPACE(*p) __force __kernel *)(local)); \
})
#define rcu_dereference_raw(p) __rcu_dereference_raw(p, __UNIQUE_ID(rcu))
--
2.40.1
prev parent reply other threads:[~2026-10-07 20:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 20:45 [PATCH v2 0/10] Miscellaneous RCU updates for v7.4 Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 01/10] doc: Update stallwarn.rst based on RCU Tasks Trace as SRCU Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 02/10] rcu: fix shrink budget underflow in lazy_rcu_shrink_scan Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 03/10] rcu: Don't panic on already-ended RCU CPU stalls Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 04/10] rcu: Add running and boosted indications to RCU task stall dump Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 05/10] rcu: Fix typo "upto" in comment Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 06/10] rcu: Drop the private tick-internal.h include from tree.c Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 07/10] rcu: Make userspace barrier hook drain kvfree_rcu work Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 08/10] rcuref: Fix the rcuread_is_dead reference in rcuref_read() kernel-doc Paul E. McKenney
2026-10-07 20:45 ` [PATCH v2 09/10] rcu-tasks: Disable callback contend/collapse messages by default Paul E. McKenney
2026-10-07 20:45 ` Paul E. McKenney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261007204511.1982646-10-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=joelagnelf@nvidia.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rcu@vger.kernel.org \
--cc=ribalda@chromium.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®