From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>, "H.J. Lu" <hjl.tools@gmail.com>,
Ingo Molnar <mingo@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Jamie Lokier <jamie@shareable.org>,
ville.syrjala@linux.intel.com, Borislav Petkov <bp@alien8.de>,
Thomas Gleixner <tglx@linutronix.de>,
linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/mm] x86, mm: Use a bitfield to mask nuisance get_user() warnings
Date: Tue, 12 Feb 2013 17:57:09 +0000 [thread overview]
Message-ID: <20130212175709.GU17833@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <CA+55aFz=OnntmRvi6geuL7ccC6ncwQ7NvURDcwu87BkpS3H0TQ@mail.gmail.com>
On Tue, Feb 12, 2013 at 09:32:54AM -0800, Linus Torvalds wrote:
> On Tue, Feb 12, 2013 at 9:14 AM, H. Peter Anvin <hpa@zytor.com> wrote:
> >
> > No, I think what he is talking about it this bit:
>
> Ok, I agree that the bitfield code actually looks cleaner.
>
> That said, maybe gcc has an easier time using a few odd builtins and
> magic typeof's. But at least the bitfield trick looks half-way
> portable..
I've just been trying hpa's solution on ARM, and I can't get it to work,
because the compiler refuses to put the struct { unsigned long long ... }
into the register(s) we need for the out of line assembly:
#define get_user(x,p) \
({ \
register const typeof(*(p)) __user *__p asm("r0") = (p);\
register int __e asm("r0"); \
register struct { \
unsigned long long __r2:8 * sizeof(*(__p)); \
} __v asm("r2"); \
switch (sizeof(*(__p))) { \
case 1: \
__get_user_x(__v.__r2, __p, __e, 1, "lr"); \
break; \
case 2: \
__get_user_x(__v.__r2, __p, __e, 2, "r3", "lr");\
break; \
case 4: \
__get_user_x(__v.__r2, __p, __e, 4, "lr"); \
break; \
case 8: \
__get_user_x(__v.__r2, __p, __e, 8, "lr"); \
break; \
default: __e = __get_user_bad(); break; \
} \
x = (typeof(*(__p))) __v.__r2; \
__e; \
})
This ends up with __v.__r2 ending up in r1/(r2) not r2/(r3).
However, I do have a working solution for 32-bit ARM which seems to work
fine with my test cases here, though as I mentioned to hpa, it may not
be portable to other 32-bit architectures:
#ifdef BIG_ENDIAN
#define __get_user_xb(__r2,__p,__e,__s,__i...) \
__get_user_x(__r2,(unsigned)__p+4,__e,__s,__i)
#else
#define __get_user_xb __get_user_x
#endif
#define get_user(x,p) \
({ \
register const typeof(*(p)) __user *__p asm("r0") = (p);\
register int __e asm("r0"); \
register typeof(x) __r2 asm("r2"); \
switch (sizeof(*(__p))) { \
case 1: \
__get_user_x(__r2, __p, __e, 1, "lr"); \
break; \
case 2: \
__get_user_x(__r2, __p, __e, 2, "r3", "lr"); \
break; \
case 4: \
__get_user_x(__r2, __p, __e, 4, "lr"); \
break; \
case 8: \
{ \
if (sizeof((x)) < 8) \
__get_user_xb(__r2, __p, __e, 4, "lr"); \
else \
__get_user_x(__r2, __p, __e, 8, "lr"); \
} \
break; \
default: __e = __get_user_bad(); break; \
} \
x = (typeof(*(__p))) __r2; \
__e; \
})
It's risky because it relies upon a "register" being allocated as 32-bits
even if typeof(x) is 8-bit or 16-bit.
prev parent reply other threads:[~2013-02-12 17:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-12 11:34 [PATCH] x86: Add support for 64bit get_user() on x86-32 ville.syrjala
2012-12-12 16:15 ` H. Peter Anvin
2012-12-12 16:32 ` Ville Syrjälä
2012-12-12 16:45 ` H. Peter Anvin
2013-02-07 16:53 ` Ville Syrjälä
2013-02-07 17:59 ` H. Peter Anvin
2013-02-08 16:24 ` Ville Syrjälä
2013-02-08 17:30 ` H. Peter Anvin
2013-02-08 18:23 ` Ville Syrjälä
2013-02-08 19:08 ` H. Peter Anvin
2013-02-09 10:41 ` Borislav Petkov
2013-02-09 11:00 ` Russell King - ARM Linux
2013-02-12 1:37 ` [tip:x86/mm] x86, mm: Use a bitfield to mask nuisance get_user() warnings tip-bot for H. Peter Anvin
2013-02-12 3:33 ` Linus Torvalds
2013-02-12 4:21 ` H. Peter Anvin
2013-02-12 4:42 ` Linus Torvalds
2013-02-12 4:47 ` Linus Torvalds
2013-02-12 4:51 ` H. Peter Anvin
2013-02-12 7:12 ` H. Peter Anvin
2013-02-12 8:10 ` Ingo Molnar
2013-02-12 16:38 ` H.J. Lu
2013-02-12 17:00 ` Linus Torvalds
2013-02-12 17:14 ` H. Peter Anvin
2013-02-12 17:30 ` H.J. Lu
2013-02-12 18:25 ` H. Peter Anvin
2013-02-12 18:29 ` H.J. Lu
2013-02-12 18:46 ` Linus Torvalds
2013-02-12 18:58 ` H. Peter Anvin
2013-02-12 20:55 ` [tip:x86/mm] x86, mm: Redesign get_user with a __builtin_choose_expr hack tip-bot for H. Peter Anvin
2013-02-12 23:06 ` Linus Torvalds
2013-02-12 23:19 ` H. Peter Anvin
2013-02-12 23:49 ` Linus Torvalds
2013-02-12 23:52 ` H. Peter Anvin
2013-02-13 0:01 ` [tip:x86/mm] x86, doc: Clarify the use of asm("%edx") in uaccess.h tip-bot for H. Peter Anvin
2013-02-12 23:21 ` [tip:x86/mm] x86, mm: Redesign get_user with a __builtin_choose_expr hack Russell King - ARM Linux
2013-02-12 17:32 ` [tip:x86/mm] x86, mm: Use a bitfield to mask nuisance get_user() warnings Linus Torvalds
2013-02-12 17:35 ` H. Peter Anvin
2013-02-12 17:49 ` Linus Torvalds
2013-02-12 17:57 ` Russell King - ARM Linux [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130212175709.GU17833@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=bp@alien8.de \
--cc=hjl.tools@gmail.com \
--cc=hpa@zytor.com \
--cc=jamie@shareable.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=ville.syrjala@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®