srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
Subsystems (2)
PATCH 1/1 srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
This patch fixes a sparse issue if DEFINE_STATIC_SRCU() of srcutree is used by a module. Sparse will show:
sparse: symbol '__srcu_struct_nodes_srcu' was not declared. Should it be static?
The problem is here that the DEFINE_STATIC_SRCU() of srcutree uses __DEFINE_SRCU() and define a non-static srcu_struct. This srcu_struct will be exported by inserting it in a special module section '__section("___srcu_struct_ptrs")'. During load/unloading srcutree runs their init/cleanup functionality. It seems sparse does not understand this connection. To avoid the sparse warning we make a prototype of the exported srcu_struct with an export keyword. This way we tell the that the srcu_struct might be used outside of the module.
--- include/linux/srcutree.h | 1 + 1 file changed, 1 insertion(+)
include/linux/srcutree.h +1 -0
@@ -121,6 +121,7 @@ struct srcu_struct {#ifdef MODULE # define __DEFINE_SRCU (name, is_static) \ is_static struct srcu_struct name; \ + extern struct srcu_struct * const __srcu_struct_##name; \ struct srcu_struct * const __srcu_struct_##name \ __section("___srcu_struct_ptrs") = &name#else
Signature · 1 line
2.31.1
Paul E. McKenney
maintainerPATCH 1/1 srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
Quoted 14 lines · Alexander Aring
This patch fixes a sparse issue if
DEFINE_STATIC_SRCU()of srcutree is used by a module. Sparse will show:sparse: symbol '
__srcu_struct_nodes_srcu' was not declared. Should it be static?The problem is here that the
DEFINE_STATIC_SRCU()of srcutree uses__DEFINE_SRCU()and define a non-staticsrcu_struct. Thissrcu_structwill be exported by inserting it in a special module section '__section("___srcu_struct_ptrs")'. During load/unloading srcutree runs their init/cleanup functionality. It seems sparse does not understand this connection. To avoid the sparse warning we make a prototype of the exportedsrcu_structwith an export keyword. This way we tell the that thesrcu_structmight be used outside of the module.
Quoted 1 line
Signed-off-by Alexander Aring <[email protected]>
Queued for further review and testing, thank you!!!
As usual, I could not resist the urge to wordsmith a bit. Could you please check below in case I messed something up?
Thanx, Paul
------------------------------------------------------------------------
commit fa92d727f94486195e12dc782fec17d103072101
Author: Alexander Aring <[email protected]> Date: Wed Jan 26 10:03:54 2022 -0500
srcutree: Use export for srcu_struct defined by DEFINE_STATIC_SRCU()
If an srcu_struct structure defined by tree SRCU's DEFINE_STATIC_SRCU() is used by a module, sparse will give the following diagnostic:
sparse: symbol '__srcu_struct_nodes_srcu' was not declared. Should it be static?
The problem is that a within-module DEFINE_STATIC_SRCU() must define a non-static srcu_struct because it is exported by referencing it in a special '__section("___srcu_struct_ptrs")'. This reference is needed so that module load and unloading can invoke init_srcu_struct() and cleanup_srcu_struct(), respectively. Unfortunately, sparse is unaware of '__section("___srcu_struct_ptrs")', resulting in the above false-positive diagnostic. To avoid this false positive, this commit therefore creates a prototype of the srcu_struct with an "extern" keyword.
include/linux/srcutree.h +1 -0
@@ -131,6 +131,7 @@ struct srcu_struct {#ifdef MODULE # define __DEFINE_SRCU (name, is_static) \ is_static struct srcu_struct name; \ + extern struct srcu_struct * const __srcu_struct_##name; \ struct srcu_struct * const __srcu_struct_##name \ __section("___srcu_struct_ptrs") = &name#else
PATCH 1/1 srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
Hi,
Quoted 38 lines · Paul E. McKenney
Quoted 14 lines · Alexander Aring
This patch fixes a sparse issue if
DEFINE_STATIC_SRCU()of srcutree is used by a module. Sparse will show:sparse: symbol '
__srcu_struct_nodes_srcu' was not declared. Should it be static?The problem is here that the
DEFINE_STATIC_SRCU()of srcutree uses__DEFINE_SRCU()and define a non-staticsrcu_struct. Thissrcu_structwill be exported by inserting it in a special module section '__section("___srcu_struct_ptrs")'. During load/unloading srcutree runs their init/cleanup functionality. It seems sparse does not understand this connection. To avoid the sparse warning we make a prototype of the exportedsrcu_structwith an export keyword. This way we tell the that thesrcu_structmight be used outside of the module.Quoted 1 line
Signed-off-by Alexander Aring <[email protected]>Queued for further review and testing, thank you!!!
As usual, I could not resist the urge to wordsmith a bit. Could you please check below in case I messed something up?
Thanx, Paul
------------------------------------------------------------------------
commit
fa92d727f94486195e12dc782fec17d103072101Author: Alexander Aring <[email protected]> Date: Wed Jan 26 10:03:54 2022 -0500srcutree: Use export for
srcu_structdefined byDEFINE_STATIC_SRCU()If an
srcu_structstructure defined by tree SRCU'sDEFINE_STATIC_SRCU()is used by a module, sparse will give the following diagnostic:sparse: symbol '
__srcu_struct_nodes_srcu' was not declared. Should it be static?
Quoted 9 lines
The problem is that a within-module
DEFINE_STATIC_SRCU()must define a non-staticsrcu_structbecause it is exported by referencing it in a special '__section("___srcu_struct_ptrs")'. This reference is needed so that module load and unloading can invokeinit_srcu_struct()andcleanup_srcu_struct(), respectively. Unfortunately, sparse is unaware of '__section("___srcu_struct_ptrs")', resulting in the above false-positive diagnostic. To avoid this false positive, this commit therefore creates a prototype of thesrcu_structwith an "extern" keyword.
perfect, thanks.
- Alex