Re: [PATCH 16/17] rcu: assert static storage for RCU sync and SRCU definitions

From: Joel Fernandes

Date: Wed Oct 07 2026 - 14:41:47 EST


On Mon, Sep 14, 2026 at 11:13:31PM -0400, Yury Norov wrote:
> DEFINE_RCU_SYNC() contains a statically initialized wait queue. SRCU
> static definitions similarly rely on persistent lockdep keys and, in
> Tiny SRCU, a statically initialized work item.
>
> Add ASSERT_STATIC_STORAGE() to DEFINE_RCU_SYNC(), both Tree SRCU
> __DEFINE_SRCU() variants and Tiny SRCU's common DEFINE_SRCU() declaration.
> This covers the non-static FAST and FAST_UPDOWN wrappers too. Tiny SRCU's
> explicitly static declarations already enforce the required duration.
> The existing per-CPU restrictions on Tree SRCU declarations still apply.
>
> Assisted-by: OpenAI Codex
> Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>

All the changes make sense to me. I'm ok with carrying this for -rcu 7.5
unless you want to take it.

Reviewed-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>

thanks,

Joel Fernandes


> ---
> include/linux/rcu_sync.h | 4 +++-
> include/linux/srcutiny.h | 4 +++-
> include/linux/srcutree.h | 7 +++++--
> 3 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/rcu_sync.h b/include/linux/rcu_sync.h
> index 3860dbb9107a..c10b6d30561a 100644
> --- a/include/linux/rcu_sync.h
> +++ b/include/linux/rcu_sync.h
> @@ -10,6 +10,7 @@
> #ifndef _LINUX_RCU_SYNC_H_
> #define _LINUX_RCU_SYNC_H_
>
> +#include <linux/compiler.h>
> #include <linux/wait.h>
> #include <linux/rcupdate.h>
>
> @@ -48,6 +49,7 @@ extern void rcu_sync_dtor(struct rcu_sync *);
> }
>
> #define DEFINE_RCU_SYNC(name) \
> - struct rcu_sync name = __RCU_SYNC_INITIALIZER(name)
> + struct rcu_sync name = __RCU_SYNC_INITIALIZER(name); \
> + ASSERT_STATIC_STORAGE(name)
>
> #endif /* _LINUX_RCU_SYNC_H_ */
> diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
> index fbcf13bc12d1..40b592b4e2d8 100644
> --- a/include/linux/srcutiny.h
> +++ b/include/linux/srcutiny.h
> @@ -11,6 +11,7 @@
> #ifndef _LINUX_SRCU_TINY_H
> #define _LINUX_SRCU_TINY_H
>
> +#include <linux/compiler.h>
> #include <linux/irq_work_types.h>
> #include <linux/swait.h>
>
> @@ -48,7 +49,8 @@ void srcu_tiny_irq_work(struct irq_work *irq_work);
> * Tree SRCU, which needs some per-CPU data.
> */
> #define DEFINE_SRCU(name) \
> - struct srcu_struct name = __SRCU_STRUCT_INIT(name, name, name, name)
> + struct srcu_struct name = __SRCU_STRUCT_INIT(name, name, name, name); \
> + ASSERT_STATIC_STORAGE(name)
> #define DEFINE_STATIC_SRCU(name) \
> static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name, name, name)
> #define DEFINE_SRCU_FAST(name) DEFINE_SRCU(name)
> diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
> index 75e54e4f963f..8bea8044230a 100644
> --- a/include/linux/srcutree.h
> +++ b/include/linux/srcutree.h
> @@ -11,6 +11,7 @@
> #ifndef _LINUX_SRCU_TREE_H
> #define _LINUX_SRCU_TREE_H
>
> +#include <linux/compiler.h>
> #include <linux/rcu_node_tree.h>
> #include <linux/completion.h>
>
> @@ -217,13 +218,15 @@ struct srcu_struct {
> fast); \
> extern struct srcu_struct * const __srcu_struct_##name; \
> struct srcu_struct * const __srcu_struct_##name \
> - __section("___srcu_struct_ptrs") = &name
> + __section("___srcu_struct_ptrs") = &name; \
> + ASSERT_STATIC_STORAGE(name)
> #else
> # define __DEFINE_SRCU(name, fast, is_static) \
> static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data); \
> static struct srcu_usage name##_srcu_usage = __SRCU_USAGE_INIT(name##_srcu_usage); \
> is_static struct srcu_struct name = \
> - __SRCU_STRUCT_INIT(name, name##_srcu_usage, name##_srcu_data, fast)
> + __SRCU_STRUCT_INIT(name, name##_srcu_usage, name##_srcu_data, fast); \
> + ASSERT_STATIC_STORAGE(name)
> #endif
> #define DEFINE_SRCU(name) __DEFINE_SRCU(name, 0, /* not static */)
> #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, 0, static)
> --
> 2.53.0
>