All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
@ 2022-01-26 15:03 ` Alexander Aring
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2022-01-26 15:03 UTC (permalink / raw)
  To: jiangshanlai
  Cc: paulmck, josh, rostedt, mathieu.desnoyers, rcu, cluster-devel

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.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
 include/linux/srcutree.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
index cb1f4351e8ba..f81be0749484 100644
--- a/include/linux/srcutree.h
+++ b/include/linux/srcutree.h
@@ -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
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
@ 2022-01-26 15:03 ` Alexander Aring
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2022-01-26 15:03 UTC (permalink / raw)
  To: cluster-devel.redhat.com

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.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
 include/linux/srcutree.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
index cb1f4351e8ba..f81be0749484 100644
--- a/include/linux/srcutree.h
+++ b/include/linux/srcutree.h
@@ -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
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
  2022-01-26 15:03 ` [Cluster-devel] " Alexander Aring
@ 2022-01-26 20:07   ` Paul E. McKenney
  -1 siblings, 0 replies; 6+ messages in thread
From: Paul E. McKenney @ 2022-01-26 20:07 UTC (permalink / raw)
  To: Alexander Aring
  Cc: jiangshanlai, josh, rostedt, mathieu.desnoyers, rcu, cluster-devel

On Wed, Jan 26, 2022 at 10:03:54AM -0500, Alexander Aring wrote:
> 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.
> 
> Signed-off-by: Alexander Aring <aahringo@redhat.com>

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 <aahringo@redhat.com>
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.
    
    Signed-off-by: Alexander Aring <aahringo@redhat.com>
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
index 8501b6b459411..44e998643f483 100644
--- a/include/linux/srcutree.h
+++ b/include/linux/srcutree.h
@@ -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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
@ 2022-01-26 20:07   ` Paul E. McKenney
  0 siblings, 0 replies; 6+ messages in thread
From: Paul E. McKenney @ 2022-01-26 20:07 UTC (permalink / raw)
  To: cluster-devel.redhat.com

On Wed, Jan 26, 2022 at 10:03:54AM -0500, Alexander Aring wrote:
> 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.
> 
> Signed-off-by: Alexander Aring <aahringo@redhat.com>

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 <aahringo@redhat.com>
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.
    
    Signed-off-by: Alexander Aring <aahringo@redhat.com>
    Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
index 8501b6b459411..44e998643f483 100644
--- a/include/linux/srcutree.h
+++ b/include/linux/srcutree.h
@@ -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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
  2022-01-26 20:07   ` [Cluster-devel] " Paul E. McKenney
@ 2022-01-26 20:25     ` Alexander Aring
  -1 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2022-01-26 20:25 UTC (permalink / raw)
  To: paulmck
  Cc: jiangshanlai, josh, rostedt, mathieu.desnoyers, rcu, cluster-devel

Hi,

On Wed, Jan 26, 2022 at 3:13 PM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> On Wed, Jan 26, 2022 at 10:03:54AM -0500, Alexander Aring wrote:
> > 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.
> >
> > Signed-off-by: Alexander Aring <aahringo@redhat.com>
>
> 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 <aahringo@redhat.com>
> 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.
>

perfect, thanks.

- Alex


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Cluster-devel] [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU()
@ 2022-01-26 20:25     ` Alexander Aring
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2022-01-26 20:25 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Hi,

On Wed, Jan 26, 2022 at 3:13 PM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> On Wed, Jan 26, 2022 at 10:03:54AM -0500, Alexander Aring wrote:
> > 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.
> >
> > Signed-off-by: Alexander Aring <aahringo@redhat.com>
>
> 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 <aahringo@redhat.com>
> 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.
>

perfect, thanks.

- Alex



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-26 20:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 15:03 [PATCH] srcutree: use export for srcu_struct defined by DEFINE_STATIC_SRCU() Alexander Aring
2022-01-26 15:03 ` [Cluster-devel] " Alexander Aring
2022-01-26 20:07 ` Paul E. McKenney
2022-01-26 20:07   ` [Cluster-devel] " Paul E. McKenney
2022-01-26 20:25   ` Alexander Aring
2022-01-26 20:25     ` [Cluster-devel] " Alexander Aring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.