linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
@ 2008-02-13 22:00 Paul E. McKenney
  2008-02-13 22:05 ` [PATCH 2/2] add rcu_assign_index() if ever needed Paul E. McKenney
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-13 22:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: shemminger, davem, netdev, dipankar, ego, herbert, akpm

Hello!

This is an updated version of the patch posted last November:

	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html

This new version permits arguments with side effects, for example:

	rcu_assign_pointer(global_p, p++);

and also verifies that the arguments are pointers, while still avoiding
the unnecessary memory barrier when assigning NULL to a pointer.
This memory-barrier avoidance means that rcu_assign_pointer() is now only
permitted for pointers (not array indexes), and so this version emits a
compiler warning if the first argument is not a pointer.  I built a "make
allyesconfig" version on an x86 system, and received no such warnings.
If RCU is ever applied to array indexes, then the second patch in this
series should be applied, and the resulting rcu_assign_index() be used.

Given the rather surprising history of subtlely broken implementations of
rcu_assign_pointer(), I took the precaution of generating a full set of
test cases and verified that memory barriers and compiler warnings were
emitted when required.  I guess it is the simple things that get you...

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 rcupdate.h |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
--- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
+++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
@@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
  * structure after the pointer assignment.  More importantly, this
  * call documents which pointers will be dereferenced by RCU read-side
  * code.
+ *
+ * Throws a compiler warning for non-pointer arguments.
+ *
+ * Does not insert a memory barrier for a NULL pointer.
  */
 
-#define rcu_assign_pointer(p, v)	({ \
-						smp_wmb(); \
-						(p) = (v); \
-					})
+#define rcu_assign_pointer(p, v)	\
+	({ \
+		typeof(*p) *_________p1 = (v); \
+		\
+		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
+			smp_wmb(); \
+		(p) = _________p1; \
+	})
 
 /**
  * synchronize_sched - block until all CPUs have exited any non-preemptive

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

* [PATCH 2/2] add rcu_assign_index() if ever needed
  2008-02-13 22:00 [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety Paul E. McKenney
@ 2008-02-13 22:05 ` Paul E. McKenney
  2008-02-14  3:32   ` Gautham R Shenoy
  2008-02-14 17:24   ` Randy Dunlap
  2008-02-13 22:11 ` [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety Andrew Morton
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-13 22:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: shemminger, davem, netdev, dipankar, ego, herbert, akpm

Hello again!

This is a speculative patch that as far as I can tell is not yet required.
If anyone applies RCU to a data structure allocated out of an array, using
array indexes in place of pointers to link the array elements together,
then the rcu_assign_index() function in this patch will be needed to
assign a given element's array index to the RCU-traversed index.  The
implementation is exactly that of the old rcu_assign_pointer(), so is
extremely well tested.

The existing rcu_assign_pointer() will emit a compiler warning in cases
where rcu_assign_index() is required.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 rcupdate.h |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff -urpNa -X dontdiff linux-2.6.24-rap/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
--- linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
+++ linux-2.6.24-rai/include/linux/rcupdate.h	2008-02-13 10:55:40.000000000 -0800
@@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
 	})
 
 /**
+ * rcu_assign_index - assign (publicize) a index of a newly
+ * initialized array elementg that will be dereferenced by RCU
+ * read-side critical sections.  Returns the value assigned.
+ *
+ * Inserts memory barriers on architectures that require them
+ * (pretty much all of them other than x86), and also prevents
+ * the compiler from reordering the code that initializes the
+ * structure after the index assignment.  More importantly, this
+ * call documents which indexes will be dereferenced by RCU read-side
+ * code.
+ */
+
+#define rcu_assign_index(p, v)	({ \
+					smp_wmb(); \
+					(p) = (v); \
+				})
+
+/**
  * synchronize_sched - block until all CPUs have exited any non-preemptive
  * kernel code sequences.
  *

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 22:00 [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety Paul E. McKenney
  2008-02-13 22:05 ` [PATCH 2/2] add rcu_assign_index() if ever needed Paul E. McKenney
@ 2008-02-13 22:11 ` Andrew Morton
       [not found] ` <20080213143537.1b806790@extreme>
  2008-02-16  0:40 ` Andrew Morton
  3 siblings, 0 replies; 23+ messages in thread
From: Andrew Morton @ 2008-02-13 22:11 UTC (permalink / raw)
  To: paulmck; +Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert

On Wed, 13 Feb 2008 14:00:24 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> Hello!
> 
> This is an updated version of the patch posted last November:
> 
> 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> 
> This new version permits arguments with side effects, for example:
> 
> 	rcu_assign_pointer(global_p, p++);
> 
> and also verifies that the arguments are pointers, while still avoiding
> the unnecessary memory barrier when assigning NULL to a pointer.
> This memory-barrier avoidance means that rcu_assign_pointer() is now only
> permitted for pointers (not array indexes), and so this version emits a
> compiler warning if the first argument is not a pointer.  I built a "make
> allyesconfig" version on an x86 system, and received no such warnings.
> If RCU is ever applied to array indexes, then the second patch in this
> series should be applied, and the resulting rcu_assign_index() be used.
> 
> Given the rather surprising history of subtlely broken implementations of
> rcu_assign_pointer(), I took the precaution of generating a full set of
> test cases and verified that memory barriers and compiler warnings were
> emitted when required.  I guess it is the simple things that get you...
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  rcupdate.h |   16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800

whoop, ancient kernel alert.

> @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
>   * structure after the pointer assignment.  More importantly, this
>   * call documents which pointers will be dereferenced by RCU read-side
>   * code.
> + *
> + * Throws a compiler warning for non-pointer arguments.
> + *
> + * Does not insert a memory barrier for a NULL pointer.
>   */
>  
> -#define rcu_assign_pointer(p, v)	({ \
> -						smp_wmb(); \
> -						(p) = (v); \
> -					})
> +#define rcu_assign_pointer(p, v)	\
> +	({ \
> +		typeof(*p) *_________p1 = (v); \
> +		\
> +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> +			smp_wmb(); \
> +		(p) = _________p1; \
> +	})

Someone already merged the dont-do-it-for-NULL patch so I reworked this
appropriately.  Was too lazy to update the changelog though.


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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
       [not found] ` <20080213143537.1b806790@extreme>
@ 2008-02-13 22:41   ` Paul E. McKenney
       [not found]     ` <20080213144233.05e860cb@extreme>
  0 siblings, 1 reply; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-13 22:41 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert, akpm

On Wed, Feb 13, 2008 at 02:35:37PM -0800, Stephen Hemminger wrote:
> On Wed, 13 Feb 2008 14:00:24 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> 
> > Hello!
> > 
> > This is an updated version of the patch posted last November:
> > 
> > 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> > 
> > This new version permits arguments with side effects, for example:
> > 
> > 	rcu_assign_pointer(global_p, p++);
> > 
> > and also verifies that the arguments are pointers, while still avoiding
> > the unnecessary memory barrier when assigning NULL to a pointer.
> > This memory-barrier avoidance means that rcu_assign_pointer() is now only
> > permitted for pointers (not array indexes), and so this version emits a
> > compiler warning if the first argument is not a pointer.  I built a "make
> > allyesconfig" version on an x86 system, and received no such warnings.
> > If RCU is ever applied to array indexes, then the second patch in this
> > series should be applied, and the resulting rcu_assign_index() be used.
> > 
> > Given the rather surprising history of subtlely broken implementations of
> > rcu_assign_pointer(), I took the precaution of generating a full set of
> > test cases and verified that memory barriers and compiler warnings were
> > emitted when required.  I guess it is the simple things that get you...
> > 
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  rcupdate.h |   16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> > --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> > +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
> >   * structure after the pointer assignment.  More importantly, this
> >   * call documents which pointers will be dereferenced by RCU read-side
> >   * code.
> > + *
> > + * Throws a compiler warning for non-pointer arguments.
> > + *
> > + * Does not insert a memory barrier for a NULL pointer.
> >   */
> >  
> > -#define rcu_assign_pointer(p, v)	({ \
> > -						smp_wmb(); \
> > -						(p) = (v); \
> > -					})
> > +#define rcu_assign_pointer(p, v)	\
> > +	({ \
> > +		typeof(*p) *_________p1 = (v); \
> > +		\
> > +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> > +			smp_wmb(); \
> > +		(p) = _________p1; \
> > +	})
> >  
> >  /**
> >   * synchronize_sched - block until all CPUs have exited any non-preemptive
> 
> Will this still work if p is unsigned long?

Hello, Steve,

If p is unsigned long, then use rcu_assign_index() from the next patch in
the set.  Looks like Andrew has applied it to -mm -- so please make sure
that he is aware if you do use it.

							Thanx, Paul

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
       [not found]     ` <20080213144233.05e860cb@extreme>
@ 2008-02-13 23:37       ` Paul E. McKenney
  2008-02-13 23:51         ` Stephen Hemminger
  2008-02-13 23:52         ` Andrew Morton
  0 siblings, 2 replies; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-13 23:37 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert, akpm

On Wed, Feb 13, 2008 at 02:42:33PM -0800, Stephen Hemminger wrote:
> On Wed, 13 Feb 2008 14:41:34 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> 
> > On Wed, Feb 13, 2008 at 02:35:37PM -0800, Stephen Hemminger wrote:
> > > On Wed, 13 Feb 2008 14:00:24 -0800
> > > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > 
> > > > Hello!
> > > > 
> > > > This is an updated version of the patch posted last November:
> > > > 
> > > > 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> > > > 
> > > > This new version permits arguments with side effects, for example:
> > > > 
> > > > 	rcu_assign_pointer(global_p, p++);
> > > > 
> > > > and also verifies that the arguments are pointers, while still avoiding
> > > > the unnecessary memory barrier when assigning NULL to a pointer.
> > > > This memory-barrier avoidance means that rcu_assign_pointer() is now only
> > > > permitted for pointers (not array indexes), and so this version emits a
> > > > compiler warning if the first argument is not a pointer.  I built a "make
> > > > allyesconfig" version on an x86 system, and received no such warnings.
> > > > If RCU is ever applied to array indexes, then the second patch in this
> > > > series should be applied, and the resulting rcu_assign_index() be used.
> > > > 
> > > > Given the rather surprising history of subtlely broken implementations of
> > > > rcu_assign_pointer(), I took the precaution of generating a full set of
> > > > test cases and verified that memory barriers and compiler warnings were
> > > > emitted when required.  I guess it is the simple things that get you...
> > > > 
> > > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > > ---
> > > > 
> > > >  rcupdate.h |   16 ++++++++++++----
> > > >  1 file changed, 12 insertions(+), 4 deletions(-)
> > > > 
> > > > diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> > > > --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> > > > +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > > > @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
> > > >   * structure after the pointer assignment.  More importantly, this
> > > >   * call documents which pointers will be dereferenced by RCU read-side
> > > >   * code.
> > > > + *
> > > > + * Throws a compiler warning for non-pointer arguments.
> > > > + *
> > > > + * Does not insert a memory barrier for a NULL pointer.
> > > >   */
> > > >  
> > > > -#define rcu_assign_pointer(p, v)	({ \
> > > > -						smp_wmb(); \
> > > > -						(p) = (v); \
> > > > -					})
> > > > +#define rcu_assign_pointer(p, v)	\
> > > > +	({ \
> > > > +		typeof(*p) *_________p1 = (v); \
> > > > +		\
> > > > +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> > > > +			smp_wmb(); \
> > > > +		(p) = _________p1; \
> > > > +	})
> > > >  
> > > >  /**
> > > >   * synchronize_sched - block until all CPUs have exited any non-preemptive
> > > 
> > > Will this still work if p is unsigned long?
> > 
> > Hello, Steve,
> > 
> > If p is unsigned long, then use rcu_assign_index() from the next patch in
> > the set.  Looks like Andrew has applied it to -mm -- so please make sure
> > that he is aware if you do use it.
> 
> Make sure fib_trie still works and doesn't get warnings.

Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
doesn't cut it.  Please accept my apologies for my confusion!!!

Once fib_trie is configured, I do indeed get:

    net/ipv4/fib_trie.c: In function ‘node_set_parent’:
    net/ipv4/fib_trie.c:182: warning: comparison between pointer and integer

So, given that node->parent is an unsigned long, I changed node_set_parent()
to the following:

static inline void node_set_parent(struct node *node, struct tnode *ptr)
{
	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
}

This removes the warnings.  I am a little ambivalent about this, as
this is really a pointer in disguise rather than an array index, but
patch below.  I suppose that another option would be to make node->parent
be a void* and provide appropriate accessor functions/macros.

Thoughts?

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 fib_trie.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
--- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
+++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 15:22:02.000000000 -0800
@@ -179,8 +179,7 @@ static inline struct tnode *node_parent_
 
 static inline void node_set_parent(struct node *node, struct tnode *ptr)
 {
-	rcu_assign_pointer(node->parent,
-			   (unsigned long)ptr | NODE_TYPE(node));
+	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
 }
 
 static inline struct node *tnode_get_child(struct tnode *tn, unsigned int i)

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 23:37       ` Paul E. McKenney
@ 2008-02-13 23:51         ` Stephen Hemminger
  2008-02-14  0:14           ` Paul E. McKenney
  2008-02-13 23:52         ` Andrew Morton
  1 sibling, 1 reply; 23+ messages in thread
From: Stephen Hemminger @ 2008-02-13 23:51 UTC (permalink / raw)
  To: paulmck
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, 13 Feb 2008 15:37:44 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> On Wed, Feb 13, 2008 at 02:42:33PM -0800, Stephen Hemminger wrote:
> > On Wed, 13 Feb 2008 14:41:34 -0800
> > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > 
> > > On Wed, Feb 13, 2008 at 02:35:37PM -0800, Stephen Hemminger wrote:
> > > > On Wed, 13 Feb 2008 14:00:24 -0800
> > > > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > > 
> > > > > Hello!
> > > > > 
> > > > > This is an updated version of the patch posted last November:
> > > > > 
> > > > > 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> > > > > 
> > > > > This new version permits arguments with side effects, for example:
> > > > > 
> > > > > 	rcu_assign_pointer(global_p, p++);
> > > > > 
> > > > > and also verifies that the arguments are pointers, while still avoiding
> > > > > the unnecessary memory barrier when assigning NULL to a pointer.
> > > > > This memory-barrier avoidance means that rcu_assign_pointer() is now only
> > > > > permitted for pointers (not array indexes), and so this version emits a
> > > > > compiler warning if the first argument is not a pointer.  I built a "make
> > > > > allyesconfig" version on an x86 system, and received no such warnings.
> > > > > If RCU is ever applied to array indexes, then the second patch in this
> > > > > series should be applied, and the resulting rcu_assign_index() be used.
> > > > > 
> > > > > Given the rather surprising history of subtlely broken implementations of
> > > > > rcu_assign_pointer(), I took the precaution of generating a full set of
> > > > > test cases and verified that memory barriers and compiler warnings were
> > > > > emitted when required.  I guess it is the simple things that get you...
> > > > > 
> > > > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > > > ---
> > > > > 
> > > > >  rcupdate.h |   16 ++++++++++++----
> > > > >  1 file changed, 12 insertions(+), 4 deletions(-)
> > > > > 
> > > > > diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> > > > > --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> > > > > +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > > > > @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
> > > > >   * structure after the pointer assignment.  More importantly, this
> > > > >   * call documents which pointers will be dereferenced by RCU read-side
> > > > >   * code.
> > > > > + *
> > > > > + * Throws a compiler warning for non-pointer arguments.
> > > > > + *
> > > > > + * Does not insert a memory barrier for a NULL pointer.
> > > > >   */
> > > > >  
> > > > > -#define rcu_assign_pointer(p, v)	({ \
> > > > > -						smp_wmb(); \
> > > > > -						(p) = (v); \
> > > > > -					})
> > > > > +#define rcu_assign_pointer(p, v)	\
> > > > > +	({ \
> > > > > +		typeof(*p) *_________p1 = (v); \
> > > > > +		\
> > > > > +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> > > > > +			smp_wmb(); \
> > > > > +		(p) = _________p1; \
> > > > > +	})
> > > > >  
> > > > >  /**
> > > > >   * synchronize_sched - block until all CPUs have exited any non-preemptive
> > > > 
> > > > Will this still work if p is unsigned long?
> > > 
> > > Hello, Steve,
> > > 
> > > If p is unsigned long, then use rcu_assign_index() from the next patch in
> > > the set.  Looks like Andrew has applied it to -mm -- so please make sure
> > > that he is aware if you do use it.
> > 
> > Make sure fib_trie still works and doesn't get warnings.
> 
> Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> doesn't cut it.  Please accept my apologies for my confusion!!!
> 
> Once fib_trie is configured, I do indeed get:
> 
>     net/ipv4/fib_trie.c: In function ‘node_set_parent’:
>     net/ipv4/fib_trie.c:182: warning: comparison between pointer and integer
> 
> So, given that node->parent is an unsigned long, I changed node_set_parent()
> to the following:
> 
> static inline void node_set_parent(struct node *node, struct tnode *ptr)
> {
> 	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
> }
> 
> This removes the warnings.  I am a little ambivalent about this, as
> this is really a pointer in disguise rather than an array index, but
> patch below.  I suppose that another option would be to make node->parent
> be a void* and provide appropriate accessor functions/macros.
> 
> Thoughts?
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

Maybe cast both sides to void * in this case:

static inline void node_set_parent(struct node *node, struct tnode *ptr)
{
 	rcu_assign_pointer((void *) node->parent, (void *)((unsigned long)ptr | NODE_TYPE(node)));
}

-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 23:37       ` Paul E. McKenney
  2008-02-13 23:51         ` Stephen Hemminger
@ 2008-02-13 23:52         ` Andrew Morton
  2008-02-13 23:55           ` Stephen Hemminger
  2008-02-13 23:57           ` David Miller
  1 sibling, 2 replies; 23+ messages in thread
From: Andrew Morton @ 2008-02-13 23:52 UTC (permalink / raw)
  To: paulmck
  Cc: stephen.hemminger@vyatta.com, linux-kernel, shemminger, davem,
	netdev, dipankar, ego, herbert

On Wed, 13 Feb 2008 15:37:44 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> doesn't cut it.

This is not good.  The sole purpose of allmodconfig and allyesconfig is for
compilation and linkage coverage testing.  Hence we should aim to get as
much code as possible included in those cases.


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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 23:52         ` Andrew Morton
@ 2008-02-13 23:55           ` Stephen Hemminger
  2008-02-13 23:57           ` David Miller
  1 sibling, 0 replies; 23+ messages in thread
From: Stephen Hemminger @ 2008-02-13 23:55 UTC (permalink / raw)
  To: Andrew Morton
  Cc: paulmck, stephen.hemminger@vyatta.com, linux-kernel, davem,
	netdev, dipankar, ego, herbert

On Wed, 13 Feb 2008 15:52:45 -0800
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Wed, 13 Feb 2008 15:37:44 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> 
> > Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> > doesn't cut it.
> 
> This is not good.  The sole purpose of allmodconfig and allyesconfig is for
> compilation and linkage coverage testing.  Hence we should aim to get as
> much code as possible included in those cases.
> 

The current model is compile time choice. It is on my long term list
to make this a runtime option.

-- 
Stephen Hemminger <stephen.hemminger@vyatta.com>

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 23:52         ` Andrew Morton
  2008-02-13 23:55           ` Stephen Hemminger
@ 2008-02-13 23:57           ` David Miller
  2008-02-14  0:09             ` Andrew Morton
  1 sibling, 1 reply; 23+ messages in thread
From: David Miller @ 2008-02-13 23:57 UTC (permalink / raw)
  To: akpm
  Cc: paulmck, stephen.hemminger@vyatta.com, linux-kernel, shemminger,
	netdev, dipankar, ego, herbert

From: Andrew Morton <akpm@linux-foundation.org>
Date: Wed, 13 Feb 2008 15:52:45 -0800

> On Wed, 13 Feb 2008 15:37:44 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> 
> > Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> > doesn't cut it.
> 
> This is not good.  The sole purpose of allmodconfig and allyesconfig is for
> compilation and linkage coverage testing.  Hence we should aim to get as
> much code as possible included in those cases.

Well, in this case there is a choice, either you use one routing
lookup datastructure or the other.  It's not purposefully being hidden
from the everything builds :-)

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 23:57           ` David Miller
@ 2008-02-14  0:09             ` Andrew Morton
  0 siblings, 0 replies; 23+ messages in thread
From: Andrew Morton @ 2008-02-14  0:09 UTC (permalink / raw)
  To: David Miller
  Cc: paulmck, stephen.hemminger@vyatta.com, linux-kernel, shemminger,
	netdev, dipankar, ego, herbert

On Wed, 13 Feb 2008 15:57:38 -0800 (PST)
David Miller <davem@davemloft.net> wrote:

> From: Andrew Morton <akpm@linux-foundation.org>
> Date: Wed, 13 Feb 2008 15:52:45 -0800
> 
> > On Wed, 13 Feb 2008 15:37:44 -0800
> > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > 
> > > Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> > > doesn't cut it.
> > 
> > This is not good.  The sole purpose of allmodconfig and allyesconfig is for
> > compilation and linkage coverage testing.  Hence we should aim to get as
> > much code as possible included in those cases.
> 
> Well, in this case there is a choice, either you use one routing
> lookup datastructure or the other.  It's not purposefully being hidden
> from the everything builds :-)

oic.  yes, that is a bit of a problem.  Oh well.

`make randconfig' seems to be able to enable CONFIG_IP_FIB_TRIE about one
time in eight ;)


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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 23:51         ` Stephen Hemminger
@ 2008-02-14  0:14           ` Paul E. McKenney
  2008-02-14  0:27             ` Stephen Hemminger
  0 siblings, 1 reply; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-14  0:14 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, Feb 13, 2008 at 03:51:58PM -0800, Stephen Hemminger wrote:
> On Wed, 13 Feb 2008 15:37:44 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > On Wed, Feb 13, 2008 at 02:42:33PM -0800, Stephen Hemminger wrote:
> > > On Wed, 13 Feb 2008 14:41:34 -0800
> > > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > 
> > > > On Wed, Feb 13, 2008 at 02:35:37PM -0800, Stephen Hemminger wrote:
> > > > > On Wed, 13 Feb 2008 14:00:24 -0800
> > > > > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > > > 
> > > > > > Hello!
> > > > > > 
> > > > > > This is an updated version of the patch posted last November:
> > > > > > 
> > > > > > 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> > > > > > 
> > > > > > This new version permits arguments with side effects, for example:
> > > > > > 
> > > > > > 	rcu_assign_pointer(global_p, p++);
> > > > > > 
> > > > > > and also verifies that the arguments are pointers, while still avoiding
> > > > > > the unnecessary memory barrier when assigning NULL to a pointer.
> > > > > > This memory-barrier avoidance means that rcu_assign_pointer() is now only
> > > > > > permitted for pointers (not array indexes), and so this version emits a
> > > > > > compiler warning if the first argument is not a pointer.  I built a "make
> > > > > > allyesconfig" version on an x86 system, and received no such warnings.
> > > > > > If RCU is ever applied to array indexes, then the second patch in this
> > > > > > series should be applied, and the resulting rcu_assign_index() be used.
> > > > > > 
> > > > > > Given the rather surprising history of subtlely broken implementations of
> > > > > > rcu_assign_pointer(), I took the precaution of generating a full set of
> > > > > > test cases and verified that memory barriers and compiler warnings were
> > > > > > emitted when required.  I guess it is the simple things that get you...
> > > > > > 
> > > > > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > > > > ---
> > > > > > 
> > > > > >  rcupdate.h |   16 ++++++++++++----
> > > > > >  1 file changed, 12 insertions(+), 4 deletions(-)
> > > > > > 
> > > > > > diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> > > > > > --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> > > > > > +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > > > > > @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
> > > > > >   * structure after the pointer assignment.  More importantly, this
> > > > > >   * call documents which pointers will be dereferenced by RCU read-side
> > > > > >   * code.
> > > > > > + *
> > > > > > + * Throws a compiler warning for non-pointer arguments.
> > > > > > + *
> > > > > > + * Does not insert a memory barrier for a NULL pointer.
> > > > > >   */
> > > > > >  
> > > > > > -#define rcu_assign_pointer(p, v)	({ \
> > > > > > -						smp_wmb(); \
> > > > > > -						(p) = (v); \
> > > > > > -					})
> > > > > > +#define rcu_assign_pointer(p, v)	\
> > > > > > +	({ \
> > > > > > +		typeof(*p) *_________p1 = (v); \
> > > > > > +		\
> > > > > > +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> > > > > > +			smp_wmb(); \
> > > > > > +		(p) = _________p1; \
> > > > > > +	})
> > > > > >  
> > > > > >  /**
> > > > > >   * synchronize_sched - block until all CPUs have exited any non-preemptive
> > > > > 
> > > > > Will this still work if p is unsigned long?
> > > > 
> > > > Hello, Steve,
> > > > 
> > > > If p is unsigned long, then use rcu_assign_index() from the next patch in
> > > > the set.  Looks like Andrew has applied it to -mm -- so please make sure
> > > > that he is aware if you do use it.
> > > 
> > > Make sure fib_trie still works and doesn't get warnings.
> > 
> > Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> > doesn't cut it.  Please accept my apologies for my confusion!!!
> > 
> > Once fib_trie is configured, I do indeed get:
> > 
> >     net/ipv4/fib_trie.c: In function ‘node_set_parent’:
> >     net/ipv4/fib_trie.c:182: warning: comparison between pointer and integer
> > 
> > So, given that node->parent is an unsigned long, I changed node_set_parent()
> > to the following:
> > 
> > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > {
> > 	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
> > }
> > 
> > This removes the warnings.  I am a little ambivalent about this, as
> > this is really a pointer in disguise rather than an array index, but
> > patch below.  I suppose that another option would be to make node->parent
> > be a void* and provide appropriate accessor functions/macros.
> > 
> > Thoughts?
> > 
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> 
> Maybe cast both sides to void * in this case:
> 
> static inline void node_set_parent(struct node *node, struct tnode *ptr)
> {
>  	rcu_assign_pointer((void *) node->parent, (void *)((unsigned long)ptr | NODE_TYPE(node)));
> }

That gets me the following:

	net/ipv4/fib_trie.c: In function ‘node_set_parent’:
	net/ipv4/fib_trie.c:182: error: invalid lvalue in assignment

However, as with much in computing, an extra level of indirection fixes
things.  Your call as to whether or not the cure is preferable to the
disease.  ;-)

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 fib_trie.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
--- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
+++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 16:10:07.000000000 -0800
@@ -179,8 +179,8 @@ static inline struct tnode *node_parent_
 
 static inline void node_set_parent(struct node *node, struct tnode *ptr)
 {
-	rcu_assign_pointer(node->parent,
-			   (unsigned long)ptr | NODE_TYPE(node));
+	rcu_assign_pointer((*(void **)&node->parent),
+			   (void *)((unsigned long)ptr | NODE_TYPE(node)));
 }
 
 static inline struct node *tnode_get_child(struct tnode *tn, unsigned int i)

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-14  0:14           ` Paul E. McKenney
@ 2008-02-14  0:27             ` Stephen Hemminger
  2008-02-14  0:42               ` Paul E. McKenney
  0 siblings, 1 reply; 23+ messages in thread
From: Stephen Hemminger @ 2008-02-14  0:27 UTC (permalink / raw)
  To: paulmck
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, 13 Feb 2008 16:14:04 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> On Wed, Feb 13, 2008 at 03:51:58PM -0800, Stephen Hemminger wrote:
> > On Wed, 13 Feb 2008 15:37:44 -0800
> > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > On Wed, Feb 13, 2008 at 02:42:33PM -0800, Stephen Hemminger wrote:
> > > > On Wed, 13 Feb 2008 14:41:34 -0800
> > > > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > > 
> > > > > On Wed, Feb 13, 2008 at 02:35:37PM -0800, Stephen Hemminger wrote:
> > > > > > On Wed, 13 Feb 2008 14:00:24 -0800
> > > > > > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > > > > 
> > > > > > > Hello!
> > > > > > > 
> > > > > > > This is an updated version of the patch posted last November:
> > > > > > > 
> > > > > > > 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> > > > > > > 
> > > > > > > This new version permits arguments with side effects, for example:
> > > > > > > 
> > > > > > > 	rcu_assign_pointer(global_p, p++);
> > > > > > > 
> > > > > > > and also verifies that the arguments are pointers, while still avoiding
> > > > > > > the unnecessary memory barrier when assigning NULL to a pointer.
> > > > > > > This memory-barrier avoidance means that rcu_assign_pointer() is now only
> > > > > > > permitted for pointers (not array indexes), and so this version emits a
> > > > > > > compiler warning if the first argument is not a pointer.  I built a "make
> > > > > > > allyesconfig" version on an x86 system, and received no such warnings.
> > > > > > > If RCU is ever applied to array indexes, then the second patch in this
> > > > > > > series should be applied, and the resulting rcu_assign_index() be used.
> > > > > > > 
> > > > > > > Given the rather surprising history of subtlely broken implementations of
> > > > > > > rcu_assign_pointer(), I took the precaution of generating a full set of
> > > > > > > test cases and verified that memory barriers and compiler warnings were
> > > > > > > emitted when required.  I guess it is the simple things that get you...
> > > > > > > 
> > > > > > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > > > > > ---
> > > > > > > 
> > > > > > >  rcupdate.h |   16 ++++++++++++----
> > > > > > >  1 file changed, 12 insertions(+), 4 deletions(-)
> > > > > > > 
> > > > > > > diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> > > > > > > --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> > > > > > > +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > > > > > > @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
> > > > > > >   * structure after the pointer assignment.  More importantly, this
> > > > > > >   * call documents which pointers will be dereferenced by RCU read-side
> > > > > > >   * code.
> > > > > > > + *
> > > > > > > + * Throws a compiler warning for non-pointer arguments.
> > > > > > > + *
> > > > > > > + * Does not insert a memory barrier for a NULL pointer.
> > > > > > >   */
> > > > > > >  
> > > > > > > -#define rcu_assign_pointer(p, v)	({ \
> > > > > > > -						smp_wmb(); \
> > > > > > > -						(p) = (v); \
> > > > > > > -					})
> > > > > > > +#define rcu_assign_pointer(p, v)	\
> > > > > > > +	({ \
> > > > > > > +		typeof(*p) *_________p1 = (v); \
> > > > > > > +		\
> > > > > > > +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> > > > > > > +			smp_wmb(); \
> > > > > > > +		(p) = _________p1; \
> > > > > > > +	})
> > > > > > >  
> > > > > > >  /**
> > > > > > >   * synchronize_sched - block until all CPUs have exited any non-preemptive
> > > > > > 
> > > > > > Will this still work if p is unsigned long?
> > > > > 
> > > > > Hello, Steve,
> > > > > 
> > > > > If p is unsigned long, then use rcu_assign_index() from the next patch in
> > > > > the set.  Looks like Andrew has applied it to -mm -- so please make sure
> > > > > that he is aware if you do use it.
> > > > 
> > > > Make sure fib_trie still works and doesn't get warnings.
> > > 
> > > Ah.  It does take a bit to get fib_trie into one's build -- allyesconfig
> > > doesn't cut it.  Please accept my apologies for my confusion!!!
> > > 
> > > Once fib_trie is configured, I do indeed get:
> > > 
> > >     net/ipv4/fib_trie.c: In function ‘node_set_parent’:
> > >     net/ipv4/fib_trie.c:182: warning: comparison between pointer and integer
> > > 
> > > So, given that node->parent is an unsigned long, I changed node_set_parent()
> > > to the following:
> > > 
> > > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > > {
> > > 	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
> > > }
> > > 
> > > This removes the warnings.  I am a little ambivalent about this, as
> > > this is really a pointer in disguise rather than an array index, but
> > > patch below.  I suppose that another option would be to make node->parent
> > > be a void* and provide appropriate accessor functions/macros.
> > > 
> > > Thoughts?
> > > 
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > 
> > Maybe cast both sides to void * in this case:
> > 
> > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > {
> >  	rcu_assign_pointer((void *) node->parent, (void *)((unsigned long)ptr | NODE_TYPE(node)));
> > }
> 
> That gets me the following:
> 
> 	net/ipv4/fib_trie.c: In function ‘node_set_parent’:
> 	net/ipv4/fib_trie.c:182: error: invalid lvalue in assignment
> 
> However, as with much in computing, an extra level of indirection fixes
> things.  Your call as to whether or not the cure is preferable to the
> disease.  ;-)
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  fib_trie.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
> --- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
> +++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 16:10:07.000000000 -0800
> @@ -179,8 +179,8 @@ static inline struct tnode *node_parent_
>  
>  static inline void node_set_parent(struct node *node, struct tnode *ptr)
>  {
> -	rcu_assign_pointer(node->parent,
> -			   (unsigned long)ptr | NODE_TYPE(node));
> +	rcu_assign_pointer((*(void **)&node->parent),
> +			   (void *)((unsigned long)ptr | NODE_TYPE(node)));
>  }

That is heading towards ugly...  Maybe not using the macro at all (for this case) would be best:

static inline void node_set_parent(struct node *node, struct tnode *ptr)
{
	smp_wmb();
	node->parent = (unsigned long)ptr | NODE_TYPE(node);
}

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-14  0:27             ` Stephen Hemminger
@ 2008-02-14  0:42               ` Paul E. McKenney
  2008-02-14  0:53                 ` Stephen Hemminger
  0 siblings, 1 reply; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-14  0:42 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, Feb 13, 2008 at 04:27:00PM -0800, Stephen Hemminger wrote:
> On Wed, 13 Feb 2008 16:14:04 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > On Wed, Feb 13, 2008 at 03:51:58PM -0800, Stephen Hemminger wrote:

[ . . . ]

> > > Maybe cast both sides to void * in this case:
> > > 
> > > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > > {
> > >  	rcu_assign_pointer((void *) node->parent, (void *)((unsigned long)ptr | NODE_TYPE(node)));
> > > }
> > 
> > That gets me the following:
> > 
> > 	net/ipv4/fib_trie.c: In function ‘node_set_parent’:
> > 	net/ipv4/fib_trie.c:182: error: invalid lvalue in assignment
> > 
> > However, as with much in computing, an extra level of indirection fixes
> > things.  Your call as to whether or not the cure is preferable to the
> > disease.  ;-)
> > 
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  fib_trie.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
> > --- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
> > +++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 16:10:07.000000000 -0800
> > @@ -179,8 +179,8 @@ static inline struct tnode *node_parent_
> >  
> >  static inline void node_set_parent(struct node *node, struct tnode *ptr)
> >  {
> > -	rcu_assign_pointer(node->parent,
> > -			   (unsigned long)ptr | NODE_TYPE(node));
> > +	rcu_assign_pointer((*(void **)&node->parent),
> > +			   (void *)((unsigned long)ptr | NODE_TYPE(node)));
> >  }
> 
> That is heading towards ugly...  Maybe not using the macro at all (for this case) would be best:
> 
> static inline void node_set_parent(struct node *node, struct tnode *ptr)
> {
> 	smp_wmb();
> 	node->parent = (unsigned long)ptr | NODE_TYPE(node);
> }

Or, alternatively, the rcu_assign_index() patch sent earlier to avoid
the bare memory barrier?

							Thanx, Paul

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-14  0:42               ` Paul E. McKenney
@ 2008-02-14  0:53                 ` Stephen Hemminger
  2008-02-14  1:34                   ` Paul E. McKenney
  0 siblings, 1 reply; 23+ messages in thread
From: Stephen Hemminger @ 2008-02-14  0:53 UTC (permalink / raw)
  To: paulmck
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, 13 Feb 2008 16:42:53 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> On Wed, Feb 13, 2008 at 04:27:00PM -0800, Stephen Hemminger wrote:
> > On Wed, 13 Feb 2008 16:14:04 -0800
> > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > On Wed, Feb 13, 2008 at 03:51:58PM -0800, Stephen Hemminger wrote:
> 
> [ . . . ]
> 
> > > > Maybe cast both sides to void * in this case:
> > > > 
> > > > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > > > {
> > > >  	rcu_assign_pointer((void *) node->parent, (void *)((unsigned long)ptr | NODE_TYPE(node)));
> > > > }
> > > 
> > > That gets me the following:
> > > 
> > > 	net/ipv4/fib_trie.c: In function ‘node_set_parent’:
> > > 	net/ipv4/fib_trie.c:182: error: invalid lvalue in assignment
> > > 
> > > However, as with much in computing, an extra level of indirection fixes
> > > things.  Your call as to whether or not the cure is preferable to the
> > > disease.  ;-)
> > > 
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > ---
> > > 
> > >  fib_trie.c |    4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
> > > --- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
> > > +++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 16:10:07.000000000 -0800
> > > @@ -179,8 +179,8 @@ static inline struct tnode *node_parent_
> > >  
> > >  static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > >  {
> > > -	rcu_assign_pointer(node->parent,
> > > -			   (unsigned long)ptr | NODE_TYPE(node));
> > > +	rcu_assign_pointer((*(void **)&node->parent),
> > > +			   (void *)((unsigned long)ptr | NODE_TYPE(node)));
> > >  }
> > 
> > That is heading towards ugly...  Maybe not using the macro at all (for this case) would be best:
> > 
> > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > {
> > 	smp_wmb();
> > 	node->parent = (unsigned long)ptr | NODE_TYPE(node);
> > }
> 
> Or, alternatively, the rcu_assign_index() patch sent earlier to avoid
> the bare memory barrier?
> 
> 							Thanx, Paul

I am fine with rcu_assign_index(), and add a comment in node_set_parent.

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-14  0:53                 ` Stephen Hemminger
@ 2008-02-14  1:34                   ` Paul E. McKenney
  2008-02-14  1:37                     ` Stephen Hemminger
  0 siblings, 1 reply; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-14  1:34 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, Feb 13, 2008 at 04:53:56PM -0800, Stephen Hemminger wrote:
> On Wed, 13 Feb 2008 16:42:53 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > On Wed, Feb 13, 2008 at 04:27:00PM -0800, Stephen Hemminger wrote:

[ . . . ]

> > > That is heading towards ugly...  Maybe not using the macro at all (for this case) would be best:
> > > 
> > > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > > {
> > > 	smp_wmb();
> > > 	node->parent = (unsigned long)ptr | NODE_TYPE(node);
> > > }
> > 
> > Or, alternatively, the rcu_assign_index() patch sent earlier to avoid
> > the bare memory barrier?
> > 
> > 							Thanx, Paul
> 
> I am fine with rcu_assign_index(), and add a comment in node_set_parent.

OK, how about the following?

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 fib_trie.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
--- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
+++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 17:31:16.000000000 -0800
@@ -96,6 +96,14 @@ typedef unsigned int t_key;
 #define IS_TNODE(n) (!(n->parent & T_LEAF))
 #define IS_LEAF(n) (n->parent & T_LEAF)
 
+/*
+ * The "parent" fields in struct node and struct leaf are really pointers,
+ * but with the possibility that the T_LEAF bit is set.  Therefore, both
+ * the C compiler and RCU see them as integers rather than pointers.
+ * This in turn means that rcu_assign_index() must be used to assign
+ * values to these fields, rather than the usual rcu_assign_pointer().
+ */
+
 struct node {
 	unsigned long parent;
 	t_key key;
@@ -179,8 +187,7 @@ static inline struct tnode *node_parent_
 
 static inline void node_set_parent(struct node *node, struct tnode *ptr)
 {
-	rcu_assign_pointer(node->parent,
-			   (unsigned long)ptr | NODE_TYPE(node));
+	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
 }
 
 static inline struct node *tnode_get_child(struct tnode *tn, unsigned int i)

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-14  1:34                   ` Paul E. McKenney
@ 2008-02-14  1:37                     ` Stephen Hemminger
  0 siblings, 0 replies; 23+ messages in thread
From: Stephen Hemminger @ 2008-02-14  1:37 UTC (permalink / raw)
  To: paulmck
  Cc: Stephen Hemminger, linux-kernel, davem, netdev, dipankar, ego,
	herbert, akpm

On Wed, 13 Feb 2008 17:34:27 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> On Wed, Feb 13, 2008 at 04:53:56PM -0800, Stephen Hemminger wrote:
> > On Wed, 13 Feb 2008 16:42:53 -0800
> > "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> > > On Wed, Feb 13, 2008 at 04:27:00PM -0800, Stephen Hemminger wrote:
> 
> [ . . . ]
> 
> > > > That is heading towards ugly...  Maybe not using the macro at all (for this case) would be best:
> > > > 
> > > > static inline void node_set_parent(struct node *node, struct tnode *ptr)
> > > > {
> > > > 	smp_wmb();
> > > > 	node->parent = (unsigned long)ptr | NODE_TYPE(node);
> > > > }
> > > 
> > > Or, alternatively, the rcu_assign_index() patch sent earlier to avoid
> > > the bare memory barrier?
> > > 
> > > 							Thanx, Paul
> > 
> > I am fine with rcu_assign_index(), and add a comment in node_set_parent.
> 
> OK, how about the following?
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  fib_trie.c |   11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff -urpNa -X dontdiff linux-2.6.25-rc1/net/ipv4/fib_trie.c linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c
> --- linux-2.6.25-rc1/net/ipv4/fib_trie.c	2008-02-13 14:38:12.000000000 -0800
> +++ linux-2.6.25-rc1-fib_trie-warn.compile/net/ipv4/fib_trie.c	2008-02-13 17:31:16.000000000 -0800
> @@ -96,6 +96,14 @@ typedef unsigned int t_key;
>  #define IS_TNODE(n) (!(n->parent & T_LEAF))
>  #define IS_LEAF(n) (n->parent & T_LEAF)
>  
> +/*
> + * The "parent" fields in struct node and struct leaf are really pointers,
> + * but with the possibility that the T_LEAF bit is set.  Therefore, both
> + * the C compiler and RCU see them as integers rather than pointers.
> + * This in turn means that rcu_assign_index() must be used to assign
> + * values to these fields, rather than the usual rcu_assign_pointer().
> + */
> +
>  struct node {
>  	unsigned long parent;
>  	t_key key;
> @@ -179,8 +187,7 @@ static inline struct tnode *node_parent_
>  
>  static inline void node_set_parent(struct node *node, struct tnode *ptr)
>  {
> -	rcu_assign_pointer(node->parent,
> -			   (unsigned long)ptr | NODE_TYPE(node));
> +	rcu_assign_index(node->parent, (unsigned long)ptr | NODE_TYPE(node));
>  }
>  
>  static inline struct node *tnode_get_child(struct tnode *tn, unsigned int i)

Yes, thats great.

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

* Re: [PATCH 2/2] add rcu_assign_index() if ever needed
  2008-02-13 22:05 ` [PATCH 2/2] add rcu_assign_index() if ever needed Paul E. McKenney
@ 2008-02-14  3:32   ` Gautham R Shenoy
  2008-02-14  3:41     ` Andrew Morton
  2008-02-14 17:08     ` Paul E. McKenney
  2008-02-14 17:24   ` Randy Dunlap
  1 sibling, 2 replies; 23+ messages in thread
From: Gautham R Shenoy @ 2008-02-14  3:32 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, herbert, akpm

On Wed, Feb 13, 2008 at 02:05:15PM -0800, Paul E. McKenney wrote:
> Hello again!
> 
> This is a speculative patch that as far as I can tell is not yet required.
> If anyone applies RCU to a data structure allocated out of an array, using
> array indexes in place of pointers to link the array elements together,
> then the rcu_assign_index() function in this patch will be needed to
> assign a given element's array index to the RCU-traversed index.  The
> implementation is exactly that of the old rcu_assign_pointer(), so is
> extremely well tested.
> 
> The existing rcu_assign_pointer() will emit a compiler warning in cases
> where rcu_assign_index() is required.
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  rcupdate.h |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff -urpNa -X dontdiff linux-2.6.24-rap/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
> --- linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> +++ linux-2.6.24-rai/include/linux/rcupdate.h	2008-02-13 10:55:40.000000000 -0800
> @@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
>  	})
> 
>  /**
> + * rcu_assign_index - assign (publicize) a index of a newly
> + * initialized array elementg that will be dereferenced by RCU
			^^^^^^^^ 

I hope Andrew got that one while porting against the latest -mm :)

Looks good otherwise.


> + * read-side critical sections.  Returns the value assigned.
> + *
> + * Inserts memory barriers on architectures that require them
> + * (pretty much all of them other than x86), and also prevents
> + * the compiler from reordering the code that initializes the
> + * structure after the index assignment.  More importantly, this
> + * call documents which indexes will be dereferenced by RCU read-side
> + * code.
> + */
> +
> +#define rcu_assign_index(p, v)	({ \
> +					smp_wmb(); \
> +					(p) = (v); \
> +				})
> +
> +/**
>   * synchronize_sched - block until all CPUs have exited any non-preemptive
>   * kernel code sequences.
>   *

-- 
Thanks and Regards
gautham

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

* Re: [PATCH 2/2] add rcu_assign_index() if ever needed
  2008-02-14  3:32   ` Gautham R Shenoy
@ 2008-02-14  3:41     ` Andrew Morton
  2008-02-14 17:08     ` Paul E. McKenney
  1 sibling, 0 replies; 23+ messages in thread
From: Andrew Morton @ 2008-02-14  3:41 UTC (permalink / raw)
  To: ego
  Cc: Paul E. McKenney, linux-kernel, shemminger, davem, netdev,
	dipankar, herbert

On Thu, 14 Feb 2008 09:02:09 +0530 Gautham R Shenoy <ego@in.ibm.com> wrote:

> >  /**
> > + * rcu_assign_index - assign (publicize) a index of a newly
> > + * initialized array elementg that will be dereferenced by RCU
> 			^^^^^^^^ 
> 
> I hope Andrew got that one while porting against the latest -mm :)

I don't actually read the comments - I just like to make sure they're
there ;)

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

* Re: [PATCH 2/2] add rcu_assign_index() if ever needed
  2008-02-14  3:32   ` Gautham R Shenoy
  2008-02-14  3:41     ` Andrew Morton
@ 2008-02-14 17:08     ` Paul E. McKenney
  1 sibling, 0 replies; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-14 17:08 UTC (permalink / raw)
  To: Gautham R Shenoy
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, herbert, akpm

On Thu, Feb 14, 2008 at 09:02:09AM +0530, Gautham R Shenoy wrote:
> On Wed, Feb 13, 2008 at 02:05:15PM -0800, Paul E. McKenney wrote:
> > Hello again!
> > 
> > This is a speculative patch that as far as I can tell is not yet required.
> > If anyone applies RCU to a data structure allocated out of an array, using
> > array indexes in place of pointers to link the array elements together,
> > then the rcu_assign_index() function in this patch will be needed to
> > assign a given element's array index to the RCU-traversed index.  The
> > implementation is exactly that of the old rcu_assign_pointer(), so is
> > extremely well tested.
> > 
> > The existing rcu_assign_pointer() will emit a compiler warning in cases
> > where rcu_assign_index() is required.
> > 
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  rcupdate.h |   18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> > 
> > diff -urpNa -X dontdiff linux-2.6.24-rap/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
> > --- linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > +++ linux-2.6.24-rai/include/linux/rcupdate.h	2008-02-13 10:55:40.000000000 -0800
> > @@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
> >  	})
> > 
> >  /**
> > + * rcu_assign_index - assign (publicize) a index of a newly
> > + * initialized array elementg that will be dereferenced by RCU
> 			^^^^^^^^ 
> 
> I hope Andrew got that one while porting against the latest -mm :)
> 
> Looks good otherwise.

Good catch!!!

							Thanx, Paul

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

* Re: [PATCH 2/2] add rcu_assign_index() if ever needed
  2008-02-13 22:05 ` [PATCH 2/2] add rcu_assign_index() if ever needed Paul E. McKenney
  2008-02-14  3:32   ` Gautham R Shenoy
@ 2008-02-14 17:24   ` Randy Dunlap
  2008-02-14 18:48     ` Paul E. McKenney
  1 sibling, 1 reply; 23+ messages in thread
From: Randy Dunlap @ 2008-02-14 17:24 UTC (permalink / raw)
  To: paulmck
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert, akpm

On Wed, 13 Feb 2008 14:05:15 -0800 Paul E. McKenney wrote:

> Hello again!
> 
> This is a speculative patch that as far as I can tell is not yet required.
> If anyone applies RCU to a data structure allocated out of an array, using
> array indexes in place of pointers to link the array elements together,
> then the rcu_assign_index() function in this patch will be needed to
> assign a given element's array index to the RCU-traversed index.  The
> implementation is exactly that of the old rcu_assign_pointer(), so is
> extremely well tested.
> 
> The existing rcu_assign_pointer() will emit a compiler warning in cases
> where rcu_assign_index() is required.
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  rcupdate.h |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff -urpNa -X dontdiff linux-2.6.24-rap/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
> --- linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> +++ linux-2.6.24-rai/include/linux/rcupdate.h	2008-02-13 10:55:40.000000000 -0800
> @@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
>  	})
>  
>  /**
> + * rcu_assign_index - assign (publicize) a index of a newly
> + * initialized array elementg that will be dereferenced by RCU
> + * read-side critical sections.  Returns the value assigned.
> + *
> + * Inserts memory barriers on architectures that require them
> + * (pretty much all of them other than x86), and also prevents
> + * the compiler from reordering the code that initializes the
> + * structure after the index assignment.  More importantly, this
> + * call documents which indexes will be dereferenced by RCU read-side
> + * code.
> + */

s/a index/index/

Along with Gautham's typo fix, you could also make this be passable
kernel-doc notation.  :)


See Documentation/kernel-doc-nano-HOWTO.txt for details.

Summary:
The function (or macro) name and short description must be on one line.
This is followed by the parameters, then a "blank" (actually " *") line,
then any (longer) description, notes, etc.  So basically:

/**
 * rcu_assign_index - assign (publicize) index of a newly initialized array element
 * @p: description of @p
 * @v: description of @v
 *
 * This function assigns (publicizes) the index of a newly
 * initialized array element that will be dereferenced by RCU
 * read-side critical sections.  Returns the value assigned.
 *
 * Inserts memory barriers on architectures that require them
 * (pretty much all of them other than x86), and also prevents
 * the compiler from reordering the code that initializes the
 * structure after the index assignment.  More importantly, this
 * call documents which indexes will be dereferenced by RCU read-side
 * code.
 */


> +
> +#define rcu_assign_index(p, v)	({ \
> +					smp_wmb(); \
> +					(p) = (v); \
> +				})
> +
> +/**
>   * synchronize_sched - block until all CPUs have exited any non-preemptive
>   * kernel code sequences.
>   *

---
~Randy

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

* Re: [PATCH 2/2] add rcu_assign_index() if ever needed
  2008-02-14 17:24   ` Randy Dunlap
@ 2008-02-14 18:48     ` Paul E. McKenney
  0 siblings, 0 replies; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-14 18:48 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert, akpm

On Thu, Feb 14, 2008 at 09:24:27AM -0800, Randy Dunlap wrote:
> On Wed, 13 Feb 2008 14:05:15 -0800 Paul E. McKenney wrote:
> 
> > Hello again!
> > 
> > This is a speculative patch that as far as I can tell is not yet required.
> > If anyone applies RCU to a data structure allocated out of an array, using
> > array indexes in place of pointers to link the array elements together,
> > then the rcu_assign_index() function in this patch will be needed to
> > assign a given element's array index to the RCU-traversed index.  The
> > implementation is exactly that of the old rcu_assign_pointer(), so is
> > extremely well tested.
> > 
> > The existing rcu_assign_pointer() will emit a compiler warning in cases
> > where rcu_assign_index() is required.
> > 
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  rcupdate.h |   18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> > 
> > diff -urpNa -X dontdiff linux-2.6.24-rap/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
> > --- linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > +++ linux-2.6.24-rai/include/linux/rcupdate.h	2008-02-13 10:55:40.000000000 -0800
> > @@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
> >  	})
> >  
> >  /**
> > + * rcu_assign_index - assign (publicize) a index of a newly
> > + * initialized array elementg that will be dereferenced by RCU
> > + * read-side critical sections.  Returns the value assigned.
> > + *
> > + * Inserts memory barriers on architectures that require them
> > + * (pretty much all of them other than x86), and also prevents
> > + * the compiler from reordering the code that initializes the
> > + * structure after the index assignment.  More importantly, this
> > + * call documents which indexes will be dereferenced by RCU read-side
> > + * code.
> > + */
> 
> s/a index/index/
> 
> Along with Gautham's typo fix, you could also make this be passable
> kernel-doc notation.  :)

Guess I should do the same for rcu_assign_pointer() and probably several
others as well...  Good catch!!!

							Thanx, Paul

> See Documentation/kernel-doc-nano-HOWTO.txt for details.
> 
> Summary:
> The function (or macro) name and short description must be on one line.
> This is followed by the parameters, then a "blank" (actually " *") line,
> then any (longer) description, notes, etc.  So basically:
> 
> /**
>  * rcu_assign_index - assign (publicize) index of a newly initialized array element
>  * @p: description of @p
>  * @v: description of @v
>  *
>  * This function assigns (publicizes) the index of a newly
>  * initialized array element that will be dereferenced by RCU
>  * read-side critical sections.  Returns the value assigned.
>  *
>  * Inserts memory barriers on architectures that require them
>  * (pretty much all of them other than x86), and also prevents
>  * the compiler from reordering the code that initializes the
>  * structure after the index assignment.  More importantly, this
>  * call documents which indexes will be dereferenced by RCU read-side
>  * code.
>  */
> 
> 
> > +
> > +#define rcu_assign_index(p, v)	({ \
> > +					smp_wmb(); \
> > +					(p) = (v); \
> > +				})
> > +
> > +/**
> >   * synchronize_sched - block until all CPUs have exited any non-preemptive
> >   * kernel code sequences.
> >   *
> 
> ---
> ~Randy

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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-13 22:00 [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety Paul E. McKenney
                   ` (2 preceding siblings ...)
       [not found] ` <20080213143537.1b806790@extreme>
@ 2008-02-16  0:40 ` Andrew Morton
  2008-02-16  1:23   ` Paul E. McKenney
  3 siblings, 1 reply; 23+ messages in thread
From: Andrew Morton @ 2008-02-16  0:40 UTC (permalink / raw)
  To: paulmck; +Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert

On Wed, 13 Feb 2008 14:00:24 -0800
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:

> Hello!
> 
> This is an updated version of the patch posted last November:
> 
> 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> 
> This new version permits arguments with side effects, for example:
> 
> 	rcu_assign_pointer(global_p, p++);
> 
> and also verifies that the arguments are pointers, while still avoiding
> the unnecessary memory barrier when assigning NULL to a pointer.
> This memory-barrier avoidance means that rcu_assign_pointer() is now only
> permitted for pointers (not array indexes), and so this version emits a
> compiler warning if the first argument is not a pointer.  I built a "make
> allyesconfig" version on an x86 system, and received no such warnings.
> If RCU is ever applied to array indexes, then the second patch in this
> series should be applied, and the resulting rcu_assign_index() be used.
> 
> Given the rather surprising history of subtlely broken implementations of
> rcu_assign_pointer(), I took the precaution of generating a full set of
> test cases and verified that memory barriers and compiler warnings were
> emitted when required.  I guess it is the simple things that get you...
> 
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  rcupdate.h |   16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
>   * structure after the pointer assignment.  More importantly, this
>   * call documents which pointers will be dereferenced by RCU read-side
>   * code.
> + *
> + * Throws a compiler warning for non-pointer arguments.
> + *
> + * Does not insert a memory barrier for a NULL pointer.
>   */
>  
> -#define rcu_assign_pointer(p, v)	({ \
> -						smp_wmb(); \
> -						(p) = (v); \
> -					})
> +#define rcu_assign_pointer(p, v)	\
> +	({ \
> +		typeof(*p) *_________p1 = (v); \
> +		\
> +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> +			smp_wmb(); \
> +		(p) = _________p1; \
> +	})
>  

umm...

net/netfilter/core.c: In function 'nf_register_afinfo':
net/netfilter/core.c:39: warning: initialization discards qualifiers from pointer target type
net/netfilter/nf_log.c: In function 'nf_log_register':
net/netfilter/nf_log.c:37: warning: initialization discards qualifiers from pointer target type
net/netfilter/nf_queue.c: In function 'nf_register_queue_handler':
net/netfilter/nf_queue.c:38: warning: initialization discards qualifiers from pointer target type



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

* Re: [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety
  2008-02-16  0:40 ` Andrew Morton
@ 2008-02-16  1:23   ` Paul E. McKenney
  0 siblings, 0 replies; 23+ messages in thread
From: Paul E. McKenney @ 2008-02-16  1:23 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, shemminger, davem, netdev, dipankar, ego, herbert

On Fri, Feb 15, 2008 at 04:40:24PM -0800, Andrew Morton wrote:
> On Wed, 13 Feb 2008 14:00:24 -0800
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
> 
> > Hello!
> > 
> > This is an updated version of the patch posted last November:
> > 
> > 	http://archives.free.net.ph/message/20071201.003721.cd6ff17c.en.html
> > 
> > This new version permits arguments with side effects, for example:
> > 
> > 	rcu_assign_pointer(global_p, p++);
> > 
> > and also verifies that the arguments are pointers, while still avoiding
> > the unnecessary memory barrier when assigning NULL to a pointer.
> > This memory-barrier avoidance means that rcu_assign_pointer() is now only
> > permitted for pointers (not array indexes), and so this version emits a
> > compiler warning if the first argument is not a pointer.  I built a "make
> > allyesconfig" version on an x86 system, and received no such warnings.
> > If RCU is ever applied to array indexes, then the second patch in this
> > series should be applied, and the resulting rcu_assign_index() be used.
> > 
> > Given the rather surprising history of subtlely broken implementations of
> > rcu_assign_pointer(), I took the precaution of generating a full set of
> > test cases and verified that memory barriers and compiler warnings were
> > emitted when required.  I guess it is the simple things that get you...
> > 
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> > 
> >  rcupdate.h |   16 ++++++++++++----
> >  1 file changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
> > --- linux-2.6.24/include/linux/rcupdate.h	2008-01-24 14:58:37.000000000 -0800
> > +++ linux-2.6.24-rap/include/linux/rcupdate.h	2008-02-13 13:36:47.000000000 -0800
> > @@ -270,12 +270,20 @@ extern struct lockdep_map rcu_lock_map;
> >   * structure after the pointer assignment.  More importantly, this
> >   * call documents which pointers will be dereferenced by RCU read-side
> >   * code.
> > + *
> > + * Throws a compiler warning for non-pointer arguments.
> > + *
> > + * Does not insert a memory barrier for a NULL pointer.
> >   */
> >  
> > -#define rcu_assign_pointer(p, v)	({ \
> > -						smp_wmb(); \
> > -						(p) = (v); \
> > -					})
> > +#define rcu_assign_pointer(p, v)	\
> > +	({ \
> > +		typeof(*p) *_________p1 = (v); \
> > +		\
> > +		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
> > +			smp_wmb(); \
> > +		(p) = _________p1; \
> > +	})
> >  
> 
> umm...
> 
> net/netfilter/core.c: In function 'nf_register_afinfo':
> net/netfilter/core.c:39: warning: initialization discards qualifiers from pointer target type
> net/netfilter/nf_log.c: In function 'nf_log_register':
> net/netfilter/nf_log.c:37: warning: initialization discards qualifiers from pointer target type
> net/netfilter/nf_queue.c: In function 'nf_register_queue_handler':
> net/netfilter/nf_queue.c:38: warning: initialization discards qualifiers from pointer target type

Hmmm...  Netfilter compiles cleanly here.  My guess is that your gcc
is more fastidious about const declarations.  Could you please either
let me know what arch/gcc-settings you are using, or, alternatively,
see if the following patch fixes things up?  The comparison against
NULL should at least emit warnings for non-pointer types -- not as
good as an error, but better than emitting bogus warnings.

So I guess I should stick with simple things like preemptable RCU instead
of the much more difficult task of outsmarting gcc...

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 rcupdate.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- rcupdate.h.old	2008-02-15 17:18:50.000000000 -0800
+++ rcupdate.h	2008-02-15 17:18:52.000000000 -0800
@@ -176,7 +176,7 @@ struct rcu_head {
 
 #define rcu_assign_pointer(p, v) \
 	({ \
-		typeof(*p) *_________p1 = (v); \
+		typeof(p) _________p1 = (v); \
 		\
 		if (!__builtin_constant_p(v) || ((_________p1) != NULL)) \
 			smp_wmb(); \

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

end of thread, other threads:[~2008-02-16  1:24 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-13 22:00 [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety Paul E. McKenney
2008-02-13 22:05 ` [PATCH 2/2] add rcu_assign_index() if ever needed Paul E. McKenney
2008-02-14  3:32   ` Gautham R Shenoy
2008-02-14  3:41     ` Andrew Morton
2008-02-14 17:08     ` Paul E. McKenney
2008-02-14 17:24   ` Randy Dunlap
2008-02-14 18:48     ` Paul E. McKenney
2008-02-13 22:11 ` [PATCH 1/2] remove rcu_assign_pointer(NULL) penalty with type/macro safety Andrew Morton
     [not found] ` <20080213143537.1b806790@extreme>
2008-02-13 22:41   ` Paul E. McKenney
     [not found]     ` <20080213144233.05e860cb@extreme>
2008-02-13 23:37       ` Paul E. McKenney
2008-02-13 23:51         ` Stephen Hemminger
2008-02-14  0:14           ` Paul E. McKenney
2008-02-14  0:27             ` Stephen Hemminger
2008-02-14  0:42               ` Paul E. McKenney
2008-02-14  0:53                 ` Stephen Hemminger
2008-02-14  1:34                   ` Paul E. McKenney
2008-02-14  1:37                     ` Stephen Hemminger
2008-02-13 23:52         ` Andrew Morton
2008-02-13 23:55           ` Stephen Hemminger
2008-02-13 23:57           ` David Miller
2008-02-14  0:09             ` Andrew Morton
2008-02-16  0:40 ` Andrew Morton
2008-02-16  1:23   ` Paul E. McKenney

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).