LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
[not found] <20080211165954.2f1b3a9b@extreme>
@ 2008-02-12 1:16 ` David Miller
2008-02-12 8:57 ` Jarek Poplawski
[not found] ` <20080212012741.GD29254@linux.vnet.ibm.com>
1 sibling, 1 reply; 8+ messages in thread
From: David Miller @ 2008-02-12 1:16 UTC (permalink / raw)
To: shemminger; +Cc: paulmck, netdev, linux-kernel
From: Stephen Hemminger <shemminger@vyatta.com>
Date: Mon, 11 Feb 2008 16:59:54 -0800
linux-kernel added to CC:, any change to generic kernel infrastructure
should be posted there
> Eliminate warnings when rcu_assign_pointer is used with unsigned long.
> It is reasonable to use RCU with non-pointer values so allow it for general
> use. Add a comment to explain the if test.
>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> ---
> include/linux/rcupdate.h | 13 +++++++------
> 1 files changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index 37a642c..c44ac87 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -172,14 +172,15 @@ struct rcu_head {
> * structure after the pointer assignment. More importantly, this
> * call documents which pointers will be dereferenced by RCU read-side
> * code.
> + *
> + * If value is the NULL (constant 0), then no barrier is needed.
> */
>
> -#define rcu_assign_pointer(p, v) \
> - ({ \
> - if (!__builtin_constant_p(v) || \
> - ((v) != NULL)) \
> - smp_wmb(); \
> - (p) = (v); \
> +#define rcu_assign_pointer(p, v) \
> + ({ \
> + if (!(__builtin_constant_p(v) && v)) \
> + smp_wmb(); \
> + (p) = (v); \
> })
>
> /**
> --
> 1.5.3.8
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
[not found] ` <20080212012741.GD29254@linux.vnet.ibm.com>
@ 2008-02-12 5:15 ` David Miller
0 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2008-02-12 5:15 UTC (permalink / raw)
To: paulmck; +Cc: shemminger, netdev, linux-kernel
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date: Mon, 11 Feb 2008 17:27:41 -0800
> On Mon, Feb 11, 2008 at 04:59:54PM -0800, Stephen Hemminger wrote:
> > Eliminate warnings when rcu_assign_pointer is used with unsigned long.
> > It is reasonable to use RCU with non-pointer values so allow it for general
> > use. Add a comment to explain the if test.
>
> Good catch!!! (An apologies for the hassle!!!)
>
> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Thanks for reviewing Paul, I'll apply this.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
2008-02-12 1:16 ` [PATCH] fib_trie: rcu_assign_pointer warning fix David Miller
@ 2008-02-12 8:57 ` Jarek Poplawski
2008-02-12 16:07 ` Paul E. McKenney
0 siblings, 1 reply; 8+ messages in thread
From: Jarek Poplawski @ 2008-02-12 8:57 UTC (permalink / raw)
To: David Miller; +Cc: shemminger, paulmck, netdev, linux-kernel
On 12-02-2008 02:16, David Miller wrote:
> From: Stephen Hemminger <shemminger@vyatta.com>
> Date: Mon, 11 Feb 2008 16:59:54 -0800
>
> linux-kernel added to CC:, any change to generic kernel infrastructure
> should be posted there
>
>> Eliminate warnings when rcu_assign_pointer is used with unsigned long.
>> It is reasonable to use RCU with non-pointer values so allow it for general
>> use. Add a comment to explain the if test.
>>
>> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>> ---
>> include/linux/rcupdate.h | 13 +++++++------
>> 1 files changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
>> index 37a642c..c44ac87 100644
>> --- a/include/linux/rcupdate.h
>> +++ b/include/linux/rcupdate.h
>> @@ -172,14 +172,15 @@ struct rcu_head {
>> * structure after the pointer assignment. More importantly, this
>> * call documents which pointers will be dereferenced by RCU read-side
>> * code.
>> + *
>> + * If value is the NULL (constant 0), then no barrier is needed.
>> */
>>
>> -#define rcu_assign_pointer(p, v) \
>> - ({ \
>> - if (!__builtin_constant_p(v) || \
>> - ((v) != NULL)) \
>> - smp_wmb(); \
>> - (p) = (v); \
>> +#define rcu_assign_pointer(p, v) \
>> + ({ \
>> + if (!(__builtin_constant_p(v) && v)) \
...But, "If value is the NULL (constant 0)" we have:
if (!(1 && NULL != 0)) ==> if (!(0)) and the barrier is used?!
>> + smp_wmb(); \
>> + (p) = (v); \
>> })
>>
>> /**
Regards,
Jarek P.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
2008-02-12 8:57 ` Jarek Poplawski
@ 2008-02-12 16:07 ` Paul E. McKenney
2008-02-12 19:32 ` Jarek Poplawski
0 siblings, 1 reply; 8+ messages in thread
From: Paul E. McKenney @ 2008-02-12 16:07 UTC (permalink / raw)
To: Jarek Poplawski; +Cc: David Miller, shemminger, netdev, linux-kernel
On Tue, Feb 12, 2008 at 08:57:14AM +0000, Jarek Poplawski wrote:
> On 12-02-2008 02:16, David Miller wrote:
> > From: Stephen Hemminger <shemminger@vyatta.com>
> > Date: Mon, 11 Feb 2008 16:59:54 -0800
> >
> > linux-kernel added to CC:, any change to generic kernel infrastructure
> > should be posted there
> >
> >> Eliminate warnings when rcu_assign_pointer is used with unsigned long.
> >> It is reasonable to use RCU with non-pointer values so allow it for general
> >> use. Add a comment to explain the if test.
> >>
> >> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> >> ---
> >> include/linux/rcupdate.h | 13 +++++++------
> >> 1 files changed, 7 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> >> index 37a642c..c44ac87 100644
> >> --- a/include/linux/rcupdate.h
> >> +++ b/include/linux/rcupdate.h
> >> @@ -172,14 +172,15 @@ struct rcu_head {
> >> * structure after the pointer assignment. More importantly, this
> >> * call documents which pointers will be dereferenced by RCU read-side
> >> * code.
> >> + *
> >> + * If value is the NULL (constant 0), then no barrier is needed.
> >> */
> >>
> >> -#define rcu_assign_pointer(p, v) \
> >> - ({ \
> >> - if (!__builtin_constant_p(v) || \
> >> - ((v) != NULL)) \
> >> - smp_wmb(); \
> >> - (p) = (v); \
> >> +#define rcu_assign_pointer(p, v) \
> >> + ({ \
> >> + if (!(__builtin_constant_p(v) && v)) \
>
> ...But, "If value is the NULL (constant 0)" we have:
>
> if (!(1 && NULL != 0)) ==> if (!(0)) and the barrier is used?!
"All programmers are blind, especially me."
You are right, Jarek. I ran this through gcc, and the following
comes close:
#define rcu_assign_pointer(p, v) \
({ \
if (!__builtin_constant_p(v) || (v)) \
smp_wmb(); \
(p) = (v); \
})
But I am concerned about the following case:
rcu_assign_pointer(global_index, 0);
. . .
x = global_array[rcu_dereference(global_index)];
Since arrays have a zero-th element, we would really want a memory
barrier in this case.
So how about leaving the index-unfriendly version of rcu_assign_pointer()
and adding an rcu_assign_index() as follows?
Thanx, Paul
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/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
--- linux-2.6.24/include/linux/rcupdate.h 2008-01-24 14:58:37.000000000 -0800
+++ linux-2.6.24-rai/include/linux/rcupdate.h 2008-02-12 08:04:59.000000000 -0800
@@ -278,6 +278,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] 8+ messages in thread
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
2008-02-12 16:07 ` Paul E. McKenney
@ 2008-02-12 19:32 ` Jarek Poplawski
2008-02-12 19:46 ` Jarek Poplawski
0 siblings, 1 reply; 8+ messages in thread
From: Jarek Poplawski @ 2008-02-12 19:32 UTC (permalink / raw)
To: Paul E. McKenney; +Cc: David Miller, shemminger, netdev, linux-kernel
On Tue, Feb 12, 2008 at 08:07:29AM -0800, Paul E. McKenney wrote:
...
> "All programmers are blind, especially me."
Hmm... I got it my way: you - superheroes - sometimes seem to be just
like us - common people... (Probably early in the morning, before
dressing your funny costumes?)
> You are right, Jarek. I ran this through gcc, and the following
> comes close:
>
> #define rcu_assign_pointer(p, v) \
> ({ \
> if (!__builtin_constant_p(v) || (v)) \
> smp_wmb(); \
> (p) = (v); \
> })
>
> But I am concerned about the following case:
>
> rcu_assign_pointer(global_index, 0);
>
> . . .
>
> x = global_array[rcu_dereference(global_index)];
>
> Since arrays have a zero-th element, we would really want a memory
> barrier in this case.
It seems the above version of this macro uses the barrier for 0, but
if I miss something, or for these other: documenting reasons, then of
course you are right.
>
> So how about leaving the index-unfriendly version of rcu_assign_pointer()
> and adding an rcu_assign_index() as follows?
>
> Thanx, Paul
>
> 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/include/linux/rcupdate.h linux-2.6.24-rai/include/linux/rcupdate.h
> --- linux-2.6.24/include/linux/rcupdate.h 2008-01-24 14:58:37.000000000 -0800
> +++ linux-2.6.24-rai/include/linux/rcupdate.h 2008-02-12 08:04:59.000000000 -0800
> @@ -278,6 +278,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
---------------------------^
+ * initialized array element that will be dereferenced by RCU
Regards,
Jarek P.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
2008-02-12 19:32 ` Jarek Poplawski
@ 2008-02-12 19:46 ` Jarek Poplawski
2008-02-13 22:55 ` Paul E. McKenney
0 siblings, 1 reply; 8+ messages in thread
From: Jarek Poplawski @ 2008-02-12 19:46 UTC (permalink / raw)
To: Paul E. McKenney; +Cc: David Miller, shemminger, netdev, linux-kernel
On Tue, Feb 12, 2008 at 08:32:18PM +0100, Jarek Poplawski wrote:
...
> It seems the above version of this macro uses the barrier for 0, but
> if I miss something, or for these other: documenting reasons,
...or __builtin_constants could be used for indexing (?!),
> then of
> course you are right.
Jarek P.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fib_trie: rcu_assign_pointer warning fix
2008-02-12 19:46 ` Jarek Poplawski
@ 2008-02-13 22:55 ` Paul E. McKenney
0 siblings, 0 replies; 8+ messages in thread
From: Paul E. McKenney @ 2008-02-13 22:55 UTC (permalink / raw)
To: Jarek Poplawski; +Cc: David Miller, shemminger, netdev, linux-kernel
On Tue, Feb 12, 2008 at 08:46:30PM +0100, Jarek Poplawski wrote:
> On Tue, Feb 12, 2008 at 08:32:18PM +0100, Jarek Poplawski wrote:
> ...
> > It seems the above version of this macro uses the barrier for 0, but
> > if I miss something, or for these other: documenting reasons,
>
> ...or __builtin_constants could be used for indexing (?!),
Yep. For example:
elem[0].next = 1;
rcu_assign_index(global_index, 0);
Thanx, Paul
> > then of
> > course you are right.
>
> Jarek P.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] fib_trie: rcu_assign_pointer warning fix
@ 2008-02-12 1:18 Stephen Hemminger
0 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2008-02-12 1:18 UTC (permalink / raw)
To: linux-kernel
Eliminate warnings when rcu_assign_pointer is used with unsigned long.
It is reasonable to use RCU with non-pointer values so allow it for general
use. Add a comment to explain the if test.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
---
include/linux/rcupdate.h | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 37a642c..c44ac87 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -172,14 +172,15 @@ struct rcu_head {
* structure after the pointer assignment. More importantly, this
* call documents which pointers will be dereferenced by RCU read-side
* code.
+ *
+ * If value is the NULL (constant 0), then no barrier is needed.
*/
-#define rcu_assign_pointer(p, v) \
- ({ \
- if (!__builtin_constant_p(v) || \
- ((v) != NULL)) \
- smp_wmb(); \
- (p) = (v); \
+#define rcu_assign_pointer(p, v) \
+ ({ \
+ if (!(__builtin_constant_p(v) && v)) \
+ smp_wmb(); \
+ (p) = (v); \
})
/**
--
1.5.3.8
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-02-13 22:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20080211165954.2f1b3a9b@extreme>
2008-02-12 1:16 ` [PATCH] fib_trie: rcu_assign_pointer warning fix David Miller
2008-02-12 8:57 ` Jarek Poplawski
2008-02-12 16:07 ` Paul E. McKenney
2008-02-12 19:32 ` Jarek Poplawski
2008-02-12 19:46 ` Jarek Poplawski
2008-02-13 22:55 ` Paul E. McKenney
[not found] ` <20080212012741.GD29254@linux.vnet.ibm.com>
2008-02-12 5:15 ` David Miller
2008-02-12 1:18 Stephen Hemminger
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).