linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hlist_add_tail_rcu disable sparse warning
@ 2017-02-10 17:39 Michael S. Tsirkin
  2017-02-27 18:26 ` Michael S. Tsirkin
  2017-02-27 18:40 ` Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2017-02-10 17:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, David Miller

sparse is unhappy about this code in hlist_add_tail_rcu:

        struct hlist_node *i, *last = NULL;

        for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
                last = i;

This is because hlist_next_rcu and hlist_next_rcu return
__rcu pointers.

It's a false positive - it's a write side primitive and so
does not need to be called in a read side critical section.

The following trivial patch disables the warning
without changing the behaviour in any way.

Note: __hlist_for_each_rcu would also remove the warning but it would be
confusing since it calls rcu_derefence and is designed to run in the rcu
read side critical section.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

changes since RFC
	added commit log text to explain why don't we use __hlist_for_each_rcu

 include/linux/rculist.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index 4f7a956..bf578e8 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -509,7 +509,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
 {
 	struct hlist_node *i, *last = NULL;
 
-	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
-- 
MST

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

* Re: [PATCH] hlist_add_tail_rcu disable sparse warning
  2017-02-10 17:39 [PATCH] hlist_add_tail_rcu disable sparse warning Michael S. Tsirkin
@ 2017-02-27 18:26 ` Michael S. Tsirkin
  2017-04-26 13:13   ` Steven Rostedt
  2017-02-27 18:40 ` Steven Rostedt
  1 sibling, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2017-02-27 18:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, David Miller

On Fri, Feb 10, 2017 at 07:39:49PM +0200, Michael S. Tsirkin wrote:
> sparse is unhappy about this code in hlist_add_tail_rcu:
> 
>         struct hlist_node *i, *last = NULL;
> 
>         for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
>                 last = i;
> 
> This is because hlist_next_rcu and hlist_next_rcu return
> __rcu pointers.
> 
> It's a false positive - it's a write side primitive and so
> does not need to be called in a read side critical section.
> 
> The following trivial patch disables the warning
> without changing the behaviour in any way.
> 
> Note: __hlist_for_each_rcu would also remove the warning but it would be
> confusing since it calls rcu_derefence and is designed to run in the rcu
> read side critical section.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---

ping

> changes since RFC
> 	added commit log text to explain why don't we use __hlist_for_each_rcu
> 
>  include/linux/rculist.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> index 4f7a956..bf578e8 100644
> --- a/include/linux/rculist.h
> +++ b/include/linux/rculist.h
> @@ -509,7 +509,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
>  {
>  	struct hlist_node *i, *last = NULL;
>  
> -	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
> +	for (i = h->first; i; i = i->next)
>  		last = i;
>  
>  	if (last) {
> -- 
> MST

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

* Re: [PATCH] hlist_add_tail_rcu disable sparse warning
  2017-02-10 17:39 [PATCH] hlist_add_tail_rcu disable sparse warning Michael S. Tsirkin
  2017-02-27 18:26 ` Michael S. Tsirkin
@ 2017-02-27 18:40 ` Steven Rostedt
  1 sibling, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2017-02-27 18:40 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, Paul E. McKenney, Josh Triplett, Mathieu Desnoyers,
	Lai Jiangshan, David Miller

On Fri, 10 Feb 2017 19:39:49 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> index 4f7a956..bf578e8 100644
> --- a/include/linux/rculist.h
> +++ b/include/linux/rculist.h
> @@ -509,7 +509,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
>  {
>  	struct hlist_node *i, *last = NULL;
>  
> -	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
> +	for (i = h->first; i; i = i->next)

Looks good to me, but I would probably add a comment above the loop
about this being in a write side section, and rcu conversions are not
needed.

Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

>  		last = i;
>  
>  	if (last) {

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

* Re: [PATCH] hlist_add_tail_rcu disable sparse warning
  2017-02-27 18:26 ` Michael S. Tsirkin
@ 2017-04-26 13:13   ` Steven Rostedt
  2017-04-26 14:02     ` Paul E. McKenney
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2017-04-26 13:13 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Michael S. Tsirkin, linux-kernel, Josh Triplett,
	Mathieu Desnoyers, Lai Jiangshan, David Miller


Paul,

Did you see this email?

-- Steve


On Mon, 27 Feb 2017 20:26:01 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> On Fri, Feb 10, 2017 at 07:39:49PM +0200, Michael S. Tsirkin wrote:
> > sparse is unhappy about this code in hlist_add_tail_rcu:
> > 
> >         struct hlist_node *i, *last = NULL;
> > 
> >         for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
> >                 last = i;
> > 
> > This is because hlist_next_rcu and hlist_next_rcu return
> > __rcu pointers.
> > 
> > It's a false positive - it's a write side primitive and so
> > does not need to be called in a read side critical section.
> > 
> > The following trivial patch disables the warning
> > without changing the behaviour in any way.
> > 
> > Note: __hlist_for_each_rcu would also remove the warning but it would be
> > confusing since it calls rcu_derefence and is designed to run in the rcu
> > read side critical section.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---  
> 
> ping
> 
> > changes since RFC
> > 	added commit log text to explain why don't we use __hlist_for_each_rcu
> > 
> >  include/linux/rculist.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> > index 4f7a956..bf578e8 100644
> > --- a/include/linux/rculist.h
> > +++ b/include/linux/rculist.h
> > @@ -509,7 +509,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
> >  {
> >  	struct hlist_node *i, *last = NULL;
> >  
> > -	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
> > +	for (i = h->first; i; i = i->next)
> >  		last = i;
> >  
> >  	if (last) {
> > -- 
> > MST  

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

* Re: [PATCH] hlist_add_tail_rcu disable sparse warning
  2017-04-26 13:13   ` Steven Rostedt
@ 2017-04-26 14:02     ` Paul E. McKenney
  0 siblings, 0 replies; 5+ messages in thread
From: Paul E. McKenney @ 2017-04-26 14:02 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Michael S. Tsirkin, linux-kernel, Josh Triplett,
	Mathieu Desnoyers, Lai Jiangshan, David Miller

On Wed, Apr 26, 2017 at 09:13:43AM -0400, Steven Rostedt wrote:
> 
> Paul,
> 
> Did you see this email?

Yep! Michael's patch is 48ac34666ff7 ("hlist_add_tail_rcu disable sparse
warning") in -rcu and now in -tip.

But I do appreciate the reminder -- way too easy to miss stuff on LKML!

							Thanx, Paul

> -- Steve
> 
> 
> On Mon, 27 Feb 2017 20:26:01 +0200
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > On Fri, Feb 10, 2017 at 07:39:49PM +0200, Michael S. Tsirkin wrote:
> > > sparse is unhappy about this code in hlist_add_tail_rcu:
> > > 
> > >         struct hlist_node *i, *last = NULL;
> > > 
> > >         for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
> > >                 last = i;
> > > 
> > > This is because hlist_next_rcu and hlist_next_rcu return
> > > __rcu pointers.
> > > 
> > > It's a false positive - it's a write side primitive and so
> > > does not need to be called in a read side critical section.
> > > 
> > > The following trivial patch disables the warning
> > > without changing the behaviour in any way.
> > > 
> > > Note: __hlist_for_each_rcu would also remove the warning but it would be
> > > confusing since it calls rcu_derefence and is designed to run in the rcu
> > > read side critical section.
> > > 
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > ---  
> > 
> > ping
> > 
> > > changes since RFC
> > > 	added commit log text to explain why don't we use __hlist_for_each_rcu
> > > 
> > >  include/linux/rculist.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/include/linux/rculist.h b/include/linux/rculist.h
> > > index 4f7a956..bf578e8 100644
> > > --- a/include/linux/rculist.h
> > > +++ b/include/linux/rculist.h
> > > @@ -509,7 +509,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
> > >  {
> > >  	struct hlist_node *i, *last = NULL;
> > >  
> > > -	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
> > > +	for (i = h->first; i; i = i->next)
> > >  		last = i;
> > >  
> > >  	if (last) {
> > > -- 
> > > MST  
> 

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

end of thread, other threads:[~2017-04-26 14:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 17:39 [PATCH] hlist_add_tail_rcu disable sparse warning Michael S. Tsirkin
2017-02-27 18:26 ` Michael S. Tsirkin
2017-04-26 13:13   ` Steven Rostedt
2017-04-26 14:02     ` Paul E. McKenney
2017-02-27 18:40 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).