diff mbox

[RFC,tip/core/rcu,04/41] rcu: Add diagnostic for misaligned rcu_head structures

Message ID 1328125319-5205-4-git-send-email-paulmck@linux.vnet.ibm.com
State Superseded
Headers show

Commit Message

Paul E. McKenney Feb. 1, 2012, 7:41 p.m. UTC
From: "Paul E. McKenney" <paul.mckenney@linaro.org>

The push for energy efficiency will require that RCU tag rcu_head
structures to indicate whether or not their invocation is time critical.
This tagging is best carried out in the bottom bits of the ->next
pointers in the rcu_head structures.  This tagging requires that the
rcu_head structures be properly aligned, so this commit adds the required
diagnostics.

Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcutree.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

Comments

Josh Triplett Feb. 2, 2012, 1 a.m. UTC | #1
On Wed, Feb 01, 2012 at 11:41:22AM -0800, Paul E. McKenney wrote:
> The push for energy efficiency will require that RCU tag rcu_head
> structures to indicate whether or not their invocation is time critical.
> This tagging is best carried out in the bottom bits of the ->next
> pointers in the rcu_head structures.  This tagging requires that the
> rcu_head structures be properly aligned, so this commit adds the required
> diagnostics.

> --- a/kernel/rcutree.c
> +++ b/kernel/rcutree.c
> @@ -1707,6 +1707,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
>  	unsigned long flags;
>  	struct rcu_data *rdp;
>  
> +	WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */

I wonder if this should go out in one of the wrapper macros, so that the
_ONCE means once per call site?

- Josh Triplett
Josh Triplett Feb. 2, 2012, 1:01 a.m. UTC | #2
On Wed, Feb 01, 2012 at 11:41:22AM -0800, Paul E. McKenney wrote:
> From: "Paul E. McKenney" <paul.mckenney@linaro.org>
> 
> The push for energy efficiency will require that RCU tag rcu_head
> structures to indicate whether or not their invocation is time critical.
> This tagging is best carried out in the bottom bits of the ->next
> pointers in the rcu_head structures.  This tagging requires that the
> rcu_head structures be properly aligned, so this commit adds the required
> diagnostics.
> 
> Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org>
> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
>  kernel/rcutree.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/kernel/rcutree.c b/kernel/rcutree.c
> index d0f8e64..4655f3e 100644
> --- a/kernel/rcutree.c
> +++ b/kernel/rcutree.c
> @@ -1707,6 +1707,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
>  	unsigned long flags;
>  	struct rcu_data *rdp;
>  
> +	WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
>  	debug_rcu_head_queue(head);

Upon further checking:

static inline void debug_rcu_head_queue(struct rcu_head *head)
{
        WARN_ON_ONCE((unsigned long)head & 0x3);

:)

- Josh Triplett
Paul E. McKenney Feb. 2, 2012, 4:22 p.m. UTC | #3
On Wed, Feb 01, 2012 at 05:00:26PM -0800, Josh Triplett wrote:
> On Wed, Feb 01, 2012 at 11:41:22AM -0800, Paul E. McKenney wrote:
> > The push for energy efficiency will require that RCU tag rcu_head
> > structures to indicate whether or not their invocation is time critical.
> > This tagging is best carried out in the bottom bits of the ->next
> > pointers in the rcu_head structures.  This tagging requires that the
> > rcu_head structures be properly aligned, so this commit adds the required
> > diagnostics.
> 
> > --- a/kernel/rcutree.c
> > +++ b/kernel/rcutree.c
> > @@ -1707,6 +1707,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
> >  	unsigned long flags;
> >  	struct rcu_data *rdp;
> >  
> > +	WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
> 
> I wonder if this should go out in one of the wrapper macros, so that the
> _ONCE means once per call site?

Certainly past experience introducing lockdep-RCU would argue that way.  ;-)

However, my testing thus far (famous last words!) has found no
misalignments.  So I expect that these will be caught as they are
inserted, so one at a time should be fine.

								Thanx, Paul
Paul E. McKenney Feb. 2, 2012, 4:27 p.m. UTC | #4
On Wed, Feb 01, 2012 at 05:01:46PM -0800, Josh Triplett wrote:
> On Wed, Feb 01, 2012 at 11:41:22AM -0800, Paul E. McKenney wrote:
> > From: "Paul E. McKenney" <paul.mckenney@linaro.org>
> > 
> > The push for energy efficiency will require that RCU tag rcu_head
> > structures to indicate whether or not their invocation is time critical.
> > This tagging is best carried out in the bottom bits of the ->next
> > pointers in the rcu_head structures.  This tagging requires that the
> > rcu_head structures be properly aligned, so this commit adds the required
> > diagnostics.
> > 
> > Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org>
> > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > ---
> >  kernel/rcutree.c |    1 +
> >  1 files changed, 1 insertions(+), 0 deletions(-)
> > 
> > diff --git a/kernel/rcutree.c b/kernel/rcutree.c
> > index d0f8e64..4655f3e 100644
> > --- a/kernel/rcutree.c
> > +++ b/kernel/rcutree.c
> > @@ -1707,6 +1707,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
> >  	unsigned long flags;
> >  	struct rcu_data *rdp;
> >  
> > +	WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
> >  	debug_rcu_head_queue(head);
> 
> Upon further checking:
> 
> static inline void debug_rcu_head_queue(struct rcu_head *head)
> {
>         WARN_ON_ONCE((unsigned long)head & 0x3);
> 
> :)

Fair point!  I guess that we really only need one of these.  ;-)

I have kept the unconditional one and removed the one hidden under
CONFIG_DEBUG_OBJECTS_RCU_HEAD, but in a separate commit with
your Reported-by.

							Thanx, Paul
Josh Triplett Feb. 2, 2012, 8:11 p.m. UTC | #5
On Thu, Feb 02, 2012 at 08:22:35AM -0800, Paul E. McKenney wrote:
> On Wed, Feb 01, 2012 at 05:00:26PM -0800, Josh Triplett wrote:
> > On Wed, Feb 01, 2012 at 11:41:22AM -0800, Paul E. McKenney wrote:
> > > The push for energy efficiency will require that RCU tag rcu_head
> > > structures to indicate whether or not their invocation is time critical.
> > > This tagging is best carried out in the bottom bits of the ->next
> > > pointers in the rcu_head structures.  This tagging requires that the
> > > rcu_head structures be properly aligned, so this commit adds the required
> > > diagnostics.
> > 
> > > --- a/kernel/rcutree.c
> > > +++ b/kernel/rcutree.c
> > > @@ -1707,6 +1707,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
> > >  	unsigned long flags;
> > >  	struct rcu_data *rdp;
> > >  
> > > +	WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
> > 
> > I wonder if this should go out in one of the wrapper macros, so that the
> > _ONCE means once per call site?
> 
> Certainly past experience introducing lockdep-RCU would argue that way.  ;-)
> 
> However, my testing thus far (famous last words!) has found no
> misalignments.  So I expect that these will be caught as they are
> inserted, so one at a time should be fine.

Fair enough.  Doesn't seem worth introducing a new wrapper macro for,
then, since it doesn't look like an appropriate one currently exists.

- Josh Triplett
diff mbox

Patch

diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index d0f8e64..4655f3e 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1707,6 +1707,7 @@  __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
 	unsigned long flags;
 	struct rcu_data *rdp;
 
+	WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
 	debug_rcu_head_queue(head);
 	head->func = func;
 	head->next = NULL;