Skip to contentSkip to conversation

remove rcu_assign_pointer(NULL) penalty with type/macro safety

PATCH In review Paul E. McKenney 6 participants 23 messages Feb 13, 2008 – Feb 16, 2008 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 remove rcu_assign_pointer(NULL) penalty with type/macro safety

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

---

 rcupdate.h |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
include/linux/rcupdate.h +12 -4
diff -urpNa -X dontdiff linux-2.6.24/include/linux/rcupdate.h linux-2.6.24-rap/include/linux/rcupdate.h
@@ -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
#1 lore raw

PATCH 2/2 add rcu_assign_index() if ever needed

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.

---

 rcupdate.h |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -0
diff -urpNa -X dontdiff linux-2.6.24-rap/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
@@ -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.
  *
#2 lore raw

Re: [PATCH 2/2] add rcu_assign_index() if ever needed

Quoted 23 lines · Paul E. McKenney

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.

---

 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

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 290

Quoted 5 lines
include/linux/rcupdate.h +2 -0
@@ -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.

Quoted 19 lines
include/linux/rcupdate.h +16 -0
+ * 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.
  *
Signature · 2 lines
Thanks and Regards
gautham
#3 lore raw

Re: [PATCH 2/2] add rcu_assign_index() if ever needed

Quoted 6 lines · On Thu, 14 Feb 2008 09:02:09 +0530 Gautham R Shenoy <[email protected]> wrote:
Quoted 3 lines

/**
+ * 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 ;)

#4 lore raw

Re: [PATCH 2/2] add rcu_assign_index() if ever needed

In reply to Gautham R Shenoy
Quoted 26 lines · Gautham R Shenoy
Quoted 25 lines · Paul E. McKenney

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.

---

 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

include/linux/rcupdate.h +0 -0
@@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
 	})
 
Quoted 8 lines

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 290

Quoted 3 lines
include/linux/rcupdate.h +2 -0
 /**
+ * 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

#5 lore raw

Re: [PATCH 2/2] add rcu_assign_index() if ever needed

In reply to Paul E. McKenney
Quoted 27 lines · 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.

---

 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

include/linux/rcupdate.h +1 -0
@@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
 	})
 
 /**
+ * rcu_assign_index - assign (publicize) a index of a newly

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 299

Quoted 10 lines
include/linux/rcupdate.h +10 -0
+ * 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.
*/

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 309

Quoted 10 lines
include/linux/rcupdate.h +7 -0
+
+#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

#6 lore raw

Re: [PATCH 2/2] add rcu_assign_index() if ever needed

Quoted 42 lines · Randy Dunlap
Quoted 27 lines · 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.

---

 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

include/linux/rcupdate.h +1 -0
@@ -286,6 +286,24 @@ extern struct lockdep_map rcu_lock_map;
 	})
 
 /**
+ * rcu_assign_index - assign (publicize) a index of a newly

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 299

Quoted 10 lines
include/linux/rcupdate.h +10 -0
+ * 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/

Quoted 2 lines

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

Quoted 38 lines

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.
*/

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 309

Quoted 10 lines
include/linux/rcupdate.h +7 -0
+
+#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

#7 lore raw
In reply to Paul E. McKenney

include/linux/rcupdate.h

Quoted 33 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +0 -0

whoop, ancient kernel alert.

Quoted 12 lines
include/linux/rcupdate.h +4 -2
@@ -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(); \

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 286

Quoted 10 lines
include/linux/rcupdate.h +8 -2
-						(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.

A message that is not in the archive (sent off-list or not yet received): 20080213143537.1b806790@extreme

#9 lore raw
Quoted 59 lines · Stephen Hemminger
Quoted 56 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +12 -4
@@ -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; \
+	})
 
Quoted 4 lines

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 289

Quoted 2 lines
include/linux/rcupdate.h +0 -0
 /**
  * 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

A message that is not in the archive (sent off-list or not yet received): 20080213144233.05e860cb@extreme

#11 lore raw
Quoted 68 lines · Stephen Hemminger
Quoted 65 lines · On Wed, 13 Feb 2008 14:41:34 -0800 "Paul E. McKenney"…
Quoted 63 lines · Stephen Hemminger
Quoted 48 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +5 -4
@@ -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)	\

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 289

Quoted 10 lines
include/linux/rcupdate.h +7 -0
+	({ \
+		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?

Quoted 7 lines
Quoted 5 lines

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?

---

 fib_trie.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv4/fib_trie.c +1 -2
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
@@ -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)
#12 lore raw
Quoted 93 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…
Quoted 68 lines · Stephen Hemminger
Quoted 65 lines · On Wed, 13 Feb 2008 14:41:34 -0800 "Paul E. McKenney"…
Quoted 63 lines · Stephen Hemminger
Quoted 48 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +5 -4
@@ -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)	\

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 289

Quoted 10 lines
include/linux/rcupdate.h +7 -0
+	({ \
+		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?

Quoted 7 lines
Quoted 5 lines

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));
}
Quoted 8 lines

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?

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)));
}

Signature · 1 line
Stephen Hemminger <[email protected]>
#13 lore raw
Quoted 102 lines · Stephen Hemminger
Quoted 100 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…
Quoted 68 lines · Stephen Hemminger
Quoted 65 lines · On Wed, 13 Feb 2008 14:41:34 -0800 "Paul E. McKenney"…
Quoted 63 lines · Stephen Hemminger
Quoted 48 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +5 -4
@@ -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)	\

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 289

Quoted 10 lines
include/linux/rcupdate.h +7 -0
+	({ \
+		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?

Quoted 7 lines
Quoted 5 lines

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?

Quoted 8 lines
Quoted 1 line

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

---

 fib_trie.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/fib_trie.c +2 -2
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
@@ -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)
#14 lore raw
Quoted 131 lines · On Wed, 13 Feb 2008 16:14:04 -0800 "Paul E. McKenney"…
Quoted 102 lines · Stephen Hemminger
Quoted 100 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…
Quoted 68 lines · Stephen Hemminger
Quoted 65 lines · On Wed, 13 Feb 2008 14:41:34 -0800 "Paul E. McKenney"…
Quoted 63 lines · Stephen Hemminger
Quoted 48 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +5 -4
@@ -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)	\

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 289

Quoted 10 lines
include/linux/rcupdate.h +7 -0
+	({ \
+		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?

Quoted 7 lines
Quoted 5 lines

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?

Quoted 8 lines
Quoted 1 line

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

---

 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

net/ipv4/fib_trie.c static inline struct tnode *node_parent_ · line 184

Quoted 8 lines
net/ipv4/fib_trie.c +2 -2
@@ -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);
}
#15 lore raw
Quoted 3 lines · Stephen Hemminger
Quoted 1 line · On Wed, 13 Feb 2008 16:14:04 -0800 "Paul E. McKenney"…

On Wed, Feb 13, 2008 at 03:51:58PM -0800, Stephen Hemminger wrote:

[ . . . ]

Quoted 37 lines
Quoted 26 lines
Quoted 6 lines

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

---

 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

net/ipv4/fib_trie.c static inline struct tnode *node_parent_ · line 184

Quoted 8 lines
net/ipv4/fib_trie.c +2 -2
@@ -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:

Quoted 5 lines

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

#16 lore raw
Quoted 50 lines · On Wed, 13 Feb 2008 16:42:53 -0800 "Paul E. McKenney"…
Quoted 3 lines · Stephen Hemminger
Quoted 1 line · On Wed, 13 Feb 2008 16:14:04 -0800 "Paul E. McKenney"…

On Wed, Feb 13, 2008 at 03:51:58PM -0800, Stephen Hemminger wrote:

[ . . . ]

Quoted 37 lines
Quoted 26 lines
Quoted 6 lines

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

---

 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

net/ipv4/fib_trie.c static inline struct tnode *node_parent_ · line 184

Quoted 8 lines
net/ipv4/fib_trie.c +2 -2
@@ -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:

Quoted 5 lines

static inline void node_set_parent(struct node *node, struct tnode *ptr)

{
	smp_wmb();
	node->parent = (unsigned long)ptr | NODE_TYPE(node);
}
Quoted 4 lines

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.

#17 lore raw
Quoted 3 lines · Stephen Hemminger
Quoted 1 line · On Wed, 13 Feb 2008 16:42:53 -0800 "Paul E. McKenney"…

On Wed, Feb 13, 2008 at 04:27:00PM -0800, Stephen Hemminger wrote:

[ . . . ]

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

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);
}
Quoted 6 lines
Quoted 4 lines

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?

---

 fib_trie.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
net/ipv4/fib_trie.c +9 -2
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
@@ -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)
#18 lore raw
Quoted 49 lines · On Wed, 13 Feb 2008 17:34:27 -0800 "Paul E. McKenney"…
Quoted 3 lines · Stephen Hemminger
Quoted 1 line · On Wed, 13 Feb 2008 16:42:53 -0800 "Paul E. McKenney"…

On Wed, Feb 13, 2008 at 04:27:00PM -0800, Stephen Hemminger wrote:

[ . . . ]

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

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);
}
Quoted 6 lines
Quoted 4 lines

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?

---

 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

net/ipv4/fib_trie.c +8 -0
@@ -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;

net/ipv4/fib_trie.c static inline struct tnode *node_parent_ · line 193

Quoted 9 lines
net/ipv4/fib_trie.c +1 -2
@@ -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.

#19 lore raw
In reply to Paul E. McKenney
Quoted 2 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…

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.

#20 lore raw
Quoted 10 lines · On Wed, 13 Feb 2008 15:52:45 -0800 Andrew Morton <[email protected]>…
Quoted 2 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…

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.

Signature · 1 line
Stephen Hemminger <[email protected]>
maintainer
#21 lore raw
In reply to Andrew Morton

From: Andrew Morton <[email protected]>
Date: Wed, 13 Feb 2008 15:52:45 -0800

Quoted 9 lines
Quoted 2 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…

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

#22 lore raw
Quoted 9 lines · On Wed, 13 Feb 2008 15:57:38 -0800 (PST) David Miller <[email protected]>…

From: Andrew Morton <[email protected]>
Date: Wed, 13 Feb 2008 15:52:45 -0800

Quoted 6 lines
Quoted 2 lines · On Wed, 13 Feb 2008 15:37:44 -0800 "Paul E. McKenney"…

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

Quoted 7 lines
Quoted 3 lines

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

#23 lore raw
In reply to Paul E. McKenney
Quoted 46 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +4 -3
@@ -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); \

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 287

Quoted 10 lines
include/linux/rcupdate.h +8 -1
-					})
+#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

#24 lore raw
Quoted 62 lines · Andrew Morton
Quoted 46 lines · On Wed, 13 Feb 2008 14:00:24 -0800 "Paul E. McKenney"…

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

---

 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

include/linux/rcupdate.h +4 -3
@@ -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); \

include/linux/rcupdate.h extern struct lockdep_map rcu_lock_map; · line 287

Quoted 10 lines
include/linux/rcupdate.h +8 -1
-					})
+#define rcu_assign_pointer(p, v)	\
+	({ \
+		typeof(*p) *_________p1 = (v); \
+		\
+		if (!__builtin_constant_p(v) || (_________p1 != NULL)) \
+			smp_wmb(); \
+		(p) = _________p1; \
+	})
 

umm...

Quoted 6 lines

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

---

 rcupdate.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rcupdate.h renamed from rcupdate.h.old +1 -1
@@ -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(); \