Re: [PATCH/RFC 7/7] kernel: Force ACCESS_ONCE to work only on scalar types

From: Paul E. McKenney
Date: Mon Nov 24 2014 - 14:42:13 EST


On Mon, Nov 24, 2014 at 11:14:42AM -0800, Linus Torvalds wrote:
> On Mon, Nov 24, 2014 at 11:07 AM, Christian Borntraeger
> <borntraeger@xxxxxxxxxx> wrote:
> >
> > Looks really nice, but does not work with ACCESS_ONCE is on the left-hand side:
>
> Oh, I forgot about that. And that was indeed why I had done that whole
> helper macro originally, with ACCESS_ONCE() itself just being the
> dereference of the pointer.

OK, how about the following?

It complains if the variable is too large, for example, long long on
32-bit systems or large structures. It is OK loading from and storing
to small structures as well, which I am having a hard time thinking of
as a disadvantage.

Thanx, Paul

------------------------------------------------------------------------

#define get_scalar_volatile_pointer(x) ({ \
volatile typeof(x) *__vp = &(x); \
BUILD_BUG_ON(sizeof(*__vp) != sizeof(char) && \
sizeof(*__vp) != sizeof(short) && \
sizeof(*__vp) != sizeof(int) && \
sizeof(*__vp) != sizeof(long)); \
__vp; })
#define ACCESS_ONCE(x) (*get_scalar_volatile_pointer(x))

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/