From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Rob Clark <rob.clark@linaro.org>,
linux-arm-kernel@lists.infradead.org, patches@linaro.org,
linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] ARM: add get_user() support for 8 byte types
Date: Tue, 13 Nov 2012 11:24:30 +0000 [thread overview]
Message-ID: <20121113112430.GF28341@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <201211130911.09613.arnd@arndb.de>
On Tue, Nov 13, 2012 at 09:11:09AM +0000, Arnd Bergmann wrote:
> On Tuesday 13 November 2012, Rob Clark wrote:
> > right, that is what I was worried about.. but what about something
> > along the lines of:
> >
> > case 8: { \
> > if (sizeof(x) < 8) \
> > __get_user_x(__r2, __p, __e, __l, 4); \
> > else \
> > __get_user_x(__r2, __p, __e, __l, 8); \
> > break; \
> > } \
>
> I guess that's still broken if x is 8 or 16 bits wide.
Actually, it isn't - because if x is 8 or 16 bits wide, and we load
a 32-bit quantity, all that follows is a narrowing cast which is exactly
what happens today. We don't have a problem with register allocation
like we have in the 32-bit x vs 64-bit pointer target type, which is what
the above code works around.
> > maybe we need a special variant of __get_user_8() instead to get the
> > right 32bits on big vs little endian systems, but I think something
> > roughly along these lines could work.
> >
> > Or maybe in sizeof(x)<8 case, we just __get_user_bad().. I'm not 100%
> > sure on whether this is supposed to be treated as an error case at
> > compile time or not.
>
> We know that nobody is using that at the moment, so we could define
> it to be a compile-time error.
>
> But I still think this is a pointless exercise, a number of people have
> concluded independently that it's not worth trying to come up with a
> solution, whether one exists or not. Why can't you just use copy_from_user()
> anyway?
You're missing something; that is one of the greatest powers of open
source. The many eyes (and minds) effect. Someone out there probably
has a solution to whatever problem, the trick is to find that person. :)
I think we have a working solution for this for ARM. It won't be suitable
for every arch, where they have 8-bit and 16-bit registers able to be
allocated by the compiler, but for architectures where the minimum register
size is 32-bit, what we have below should work.
In other words, I don't think this will work for x86-32 where ax, al, ah
as well as eax are still available.
What I have currently in my test file, which appears to work correctly,
is (bear in mind this is based upon an older version of get_user() which
pre-dates Will's cleanups):
#define __get_user_x(__r2,__p,__e,__s,__i...) \
__asm__ __volatile__ ( \
"bl __get_user_" #__s \
: "=&r" (__e), "=r" (__r2) \
: "0" (__p) \
: __i, "cc")
#ifdef BIG_ENDIAN
#define __get_user_xb(__r2,__p,__e,__s,__i...) \
__get_user_x(__r2,(uintptr_t)__p + 4,__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; \
})
Tested with 8, 16, 32, 64 ints, 32bit int with const p, pointers, const
pointers, pointer to 64bit with 32bit target, pointer-to-const-pointer
to non-const pointer (which should and does warn).
WARNING: multiple messages have this Message-ID (diff)
From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: add get_user() support for 8 byte types
Date: Tue, 13 Nov 2012 11:24:30 +0000 [thread overview]
Message-ID: <20121113112430.GF28341@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <201211130911.09613.arnd@arndb.de>
On Tue, Nov 13, 2012 at 09:11:09AM +0000, Arnd Bergmann wrote:
> On Tuesday 13 November 2012, Rob Clark wrote:
> > right, that is what I was worried about.. but what about something
> > along the lines of:
> >
> > case 8: { \
> > if (sizeof(x) < 8) \
> > __get_user_x(__r2, __p, __e, __l, 4); \
> > else \
> > __get_user_x(__r2, __p, __e, __l, 8); \
> > break; \
> > } \
>
> I guess that's still broken if x is 8 or 16 bits wide.
Actually, it isn't - because if x is 8 or 16 bits wide, and we load
a 32-bit quantity, all that follows is a narrowing cast which is exactly
what happens today. We don't have a problem with register allocation
like we have in the 32-bit x vs 64-bit pointer target type, which is what
the above code works around.
> > maybe we need a special variant of __get_user_8() instead to get the
> > right 32bits on big vs little endian systems, but I think something
> > roughly along these lines could work.
> >
> > Or maybe in sizeof(x)<8 case, we just __get_user_bad().. I'm not 100%
> > sure on whether this is supposed to be treated as an error case at
> > compile time or not.
>
> We know that nobody is using that at the moment, so we could define
> it to be a compile-time error.
>
> But I still think this is a pointless exercise, a number of people have
> concluded independently that it's not worth trying to come up with a
> solution, whether one exists or not. Why can't you just use copy_from_user()
> anyway?
You're missing something; that is one of the greatest powers of open
source. The many eyes (and minds) effect. Someone out there probably
has a solution to whatever problem, the trick is to find that person. :)
I think we have a working solution for this for ARM. It won't be suitable
for every arch, where they have 8-bit and 16-bit registers able to be
allocated by the compiler, but for architectures where the minimum register
size is 32-bit, what we have below should work.
In other words, I don't think this will work for x86-32 where ax, al, ah
as well as eax are still available.
What I have currently in my test file, which appears to work correctly,
is (bear in mind this is based upon an older version of get_user() which
pre-dates Will's cleanups):
#define __get_user_x(__r2,__p,__e,__s,__i...) \
__asm__ __volatile__ ( \
"bl __get_user_" #__s \
: "=&r" (__e), "=r" (__r2) \
: "0" (__p) \
: __i, "cc")
#ifdef BIG_ENDIAN
#define __get_user_xb(__r2,__p,__e,__s,__i...) \
__get_user_x(__r2,(uintptr_t)__p + 4,__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; \
})
Tested with 8, 16, 32, 64 ints, 32bit int with const p, pointers, const
pointers, pointer to 64bit with 32bit target, pointer-to-const-pointer
to non-const pointer (which should and does warn).
next prev parent reply other threads:[~2012-11-13 11:24 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-09 21:17 [PATCH] ARM: add get_user() support for 8 byte types Rob Clark
2012-11-09 21:17 ` Rob Clark
2012-11-12 10:46 ` Will Deacon
2012-11-12 10:46 ` Will Deacon
2012-11-12 13:46 ` Rob Clark
2012-11-12 13:46 ` Rob Clark
2012-11-12 14:38 ` Will Deacon
2012-11-12 14:38 ` Will Deacon
2012-11-12 15:09 ` Rob Clark
2012-11-12 15:09 ` Rob Clark
2012-11-12 19:27 ` Russell King - ARM Linux
2012-11-12 19:27 ` Russell King - ARM Linux
2012-11-12 19:58 ` Rob Clark
2012-11-12 19:58 ` Rob Clark
2012-11-12 23:08 ` Russell King - ARM Linux
2012-11-12 23:08 ` Russell King - ARM Linux
2012-11-12 23:33 ` Rob Clark
2012-11-12 23:33 ` Rob Clark
2012-11-12 23:53 ` Russell King - ARM Linux
2012-11-12 23:53 ` Russell King - ARM Linux
2012-11-13 0:31 ` Rob Clark
2012-11-13 0:31 ` Rob Clark
2012-11-13 9:11 ` Arnd Bergmann
2012-11-13 9:11 ` Arnd Bergmann
2012-11-13 11:24 ` Russell King - ARM Linux [this message]
2012-11-13 11:24 ` Russell King - ARM Linux
2012-11-15 9:19 ` Arnd Bergmann
2012-11-15 9:19 ` Arnd Bergmann
2012-11-15 13:04 ` Rob Clark
2012-11-15 13:04 ` Rob Clark
2012-11-15 13:39 ` Arnd Bergmann
2012-11-15 13:39 ` Arnd Bergmann
2012-11-15 13:46 ` Rob Clark
2012-11-15 13:46 ` Rob Clark
2012-11-15 14:39 ` Arnd Bergmann
2012-11-15 14:39 ` Arnd Bergmann
2012-11-19 14:32 ` Ville Syrjälä
2012-11-19 14:32 ` Ville Syrjälä
2012-11-19 14:48 ` Russell King - ARM Linux
2012-11-19 14:48 ` Russell King - ARM Linux
2012-11-19 14:48 ` Russell King - ARM Linux
2012-11-19 15:18 ` Ville Syrjälä
2012-11-19 15:18 ` Ville Syrjälä
2012-11-19 15:18 ` Ville Syrjälä
2012-11-13 11:04 ` Russell King - ARM Linux
2012-11-13 11:04 ` Russell King - ARM Linux
-- strict thread matches above, loose matches on Subject: below --
2012-11-13 15:00 Rob Clark
2012-11-13 15:00 ` Rob Clark
2012-11-15 22:01 Rob Clark
2012-11-15 22:01 ` Rob Clark
2012-11-15 22:22 ` Nicolas Pitre
2012-11-15 22:22 ` Nicolas Pitre
2012-11-16 8:18 ` Arnd Bergmann
2012-11-16 8:18 ` Arnd Bergmann
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=20121113112430.GF28341@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=patches@linaro.org \
--cc=rob.clark@linaro.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.