Re: [tip:x86/mm] x86, mm: Redesign get_user with a__builtin_choose_expr hack

From: Russell King - ARM Linux
Date: Tue Feb 12 2013 - 18:22:03 EST

On Tue, Feb 12, 2013 at 03:06:51PM -0800, Linus Torvalds wrote:
> So this looks clean, but I noticed something (that was true even of
> the old 64-bit accesses)
> On Tue, Feb 12, 2013 at 12:55 PM, tip-bot for H. Peter Anvin
> <hpa@xxxxxxxxxxxxxxx> wrote:
> > + register __inttype(*(ptr)) __val_gu asm("%edx"); \
> How does gcc even alllow this?
> On x86-32, you cannot put a 64-bit value in %edx.
> Where do the upper bits go? It clearly cannot be %edx:%eax, since we
> put the error value in %eax.

I can't talk for x86, but the ARM version is this:

register __inttype(*p) __r2 asm("r2");

r2 is only 32-bit, so you can ask the same question there. The answer
is, it ends up in r3, the next register, as required by the compiler
ABI. (64-bit values are always contained in a consecutive even, odd
register pair.)

> Also, come to think of it, we have tried the "named register
> variables" thing before, and it has resulted in problems with scope.
> In particular, two variables within the same scope and the same
> register have been problematic. And it *does* happen, when you have
> things like
> /* copy_user */
> put_user(get_user(.., addr), addr2);
> and then things go downhill.

Umm. Why would you want to put_user() the error code from get_user() ?
That's just weird, don't we normally want to return the error code?

But yes, I can see that kind of thing causing problems - I'll check
what the behaviour is on ARM. What we _do_ have is a bit of assembly
level checking which verifies that the arguments are passed in the
correct registers, so at least we get build errors should things go
wrong. We haven't seen that though.

> Maybe we do not have these issues, but there are good reasons why
> we've tried very hard on x86 to avoid named register variables.

Unfortunately on ARM there's no other way to get close to specifying
registers for asm code. :(
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at