lkml.org 
[lkml]   [2012]   [Jan]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] rcu: avoid checking for constant
On Thu, Jan 12, 2012 at 11:34:23AM +0100, Jan Engelhardt wrote:
> On Thursday 2012-01-12 10:52, Josh Triplett wrote:
> >> +#define __kfree_rcu(head, offset) \
> >> + call_rcu(head, (void (*)(struct rcu_head *))(unsigned long)(offset) + \
> >> + BUILD_BUG_ON_ZERO((offset) >= 4096))
> >> +
> >
> >I had to stare at this for a while, and look up the definition of
> >BUILD_BUG_ON_ZERO. Naturally I assumed that BUILD_BUG_ON_ZERO(arg)
> >meant BUILT_BUG_ON((arg) == 0), which would have made the logic
> >backwards here. However, per the definition it just provides a
> >zero-returning version of BUILD_BUG_ON. Ow.
>
> Same impression here. BUILD_BUG_ON_ZERO was introduced by
>
> commit 4552d5dc08b79868829b4be8951b29b07284753f
> Author: Jan Beulich <jbeulich@novell.com>
> Date: Mon Jun 26 13:57:28 2006 +0200
>
> while Rusty's CCAN archive calls it "BUILD_BUG_OR_ZERO" (since either
> it's a bug, or returning neutral zero).

Sounds like a good target for a fix at some point.

> rcu: avoid checking for constant
>
> When compiling kernel or module code with -O0, "offset" is no longer
> considered a constant, and therefore always triggers the build error
> that BUILD_BUG_ON is defined to yield.
>
> Therefore, change the innards of kfree_rcu so that the offset is not
> tunneled through a function argument before checking it.

The commit message looks good now.

> @@ -835,7 +817,20 @@ void __kfree_rcu(struct rcu_head *head, unsigned long offset)
> *
> * Note that the allowable offset might decrease in the future, for example,
> * to allow something like kmem_cache_free_rcu().
> + *
> + * The BUILD_BUG_ON check must not involve any function calls, hence the
> + * checks are done in macros here. __is_kfree_rcu_offset is also used by
> + * kernel/rcu.h.

The first sentence of that paragraph seems like a worthwhile addition.
Please drop the second, though, since it'll inevitably become outdated.

> +#define __is_kfree_rcu_offset(offset) ((offset) < 4096)
> +
> +#define __kfree_rcu(head, offset) \
> + do { \
> + typedef void (*rcu_callback)(struct rcu_head *); \
> + BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); \
> + call_rcu(head, (rcu_callback)(unsigned long)(offset)); \
> + } while (0)

No, you can't define that typedef here with that name. Unlike in the
inline function, in a macro you could introduce a name conflict.

- Josh Triplett


\
 
 \ /
  Last update: 2012-01-12 13:01    [from the cache]
©2003-2011 Jasper Spaans