From: Arnd Bergmann <arnd@arndb.de>
To: Arun Sharma <arun.sharma@intel.com>
Cc: Andrew Morton <akpm@osdl.org>,
"David S. Miller" <davem@redhat.com>,
linux-arch@vger.kernel.org
Subject: Re: sys getdents64 needs compat wrapper ?
Date: Fri, 18 Jun 2004 01:36:31 +0200 [thread overview]
Message-ID: <200406180136.34384.arnd@arndb.de> (raw)
In-Reply-To: <40D21B17.4060603@intel.com>
[-- Attachment #1: Type: text/plain, Size: 5306 bytes --]
On Freitag, 18. Juni 2004 00:28, Arun Sharma wrote:
> It took us a bit longer :) But here's the promised patch. Using
> __put_user_unaligned() on ia64 may still cause unaligned faults,
> but we chose to optimize for the common case, where it's 4 byte
> aligned.
Isn't it legal for i386 code to pass syscall arguments with
an arbitrary alignment? I guess gcc normally aligns everything
to 32 bit unless you force it not to but you might still return
error for syscalls that work fine on a native i386 system.
> + */
> +#define __get_user_unaligned(x, ptr) \
> +({ \
> + __typeof__ (*(ptr)) __x = (x); \
> + copy_from_user(&__x, (ptr), sizeof(*(ptr))) ? -EFAULT : 0; \
> +})
This should be __copy_from_user instead of copy_from_user, right?
> +
> +
> +/*
> + * This macro should be used instead of __put_user() when accessing
> + * values at locations that are unknown to be aligned.
> + */
> +#define __put_user_unaligned(x, ptr) \
> +({ \
> + __typeof__ (*(ptr)) __x = (x); \
> + copy_to_user((ptr), &__x, sizeof(*(ptr))) ? -EFAULT : 0; \
> +})
same here.
> +extern long __put_user_unaligned_unknown (void);
> +
> +#define __put_user_unaligned(x, ptr) \
> +({ \
> + long __ret; \
> + switch (sizeof(*(ptr))) { \
> + case 1: __ret = __put_user((x), (ptr)); break; \
> + case 2: __ret = (__put_user((x), (u8 __user *)(ptr))) \
> + || (__put_user((x) >> 8, ((u8 __user *)(ptr) + 1))); break; \
> + case 4: __ret = (__put_user((x), (u16 __user *)(ptr))) \
> + || (__put_user((x) >> 16, ((u16 __user *)(ptr) + 1))); break; \
> + case 8: __ret = (__put_user((x), (u32 __user *)(ptr))) \
> + || (__put_user((x) >> 32, ((u32 __user *)(ptr) + 1))); break; \
> + default: __ret = __put_user_unaligned_unknown(); \
> + } \
> + __ret; \
> +})
Under what circumstances would you need to break down a 4 byte
alignment into 2 bytes? I can understand that you want to optimize
the unaligned-64 bit case because i386-gcc aligns them only to 32 bit
in user space, but the other special cases are bogus. Why not
just do:
#define __put_user_unaligned(x, ptr) \
( \
(sizeof(*(ptr)) == 8) ? \
((__put_user((x), (u32 __user *)(ptr))) \
| (__put_user((x) >> 32, ((u32 __user *)(ptr) + 1)))) \
: __put_user(x,ptr) \
)
Note also the use of | instead of || to get the correct value on error
(-EFAULT, not 1).
> diff -purN -X dontdiff linux-2.6.7-rc3-getdents/include/asm-ppc64/uaccess.h linux-2.6.7-rc3-getdents-user_unaligned/include/asm-ppc64/uaccess.h
> --- linux-2.6.7-rc3-getdents/include/asm-ppc64/uaccess.h 2004-06-15 13:41:35.000000000 +0800
> +++ linux-2.6.7-rc3-getdents-user_unaligned/include/asm-ppc64/uaccess.h 2004-06-17 14:51:42.020600447 +0800
> @@ -12,6 +12,7 @@
> #include <linux/sched.h>
> #include <linux/errno.h>
> #include <asm/processor.h>
> +#include <asm-generic/uaccess.h>
>
> #define VERIFY_READ 0
> #define VERIFY_WRITE 1
> diff -purN -X dontdiff linux-2.6.7-rc3-getdents/include/asm-s390/uaccess.h linux-2.6.7-rc3-getdents-user_unaligned/include/asm-s390/uaccess.h
> --- linux-2.6.7-rc3-getdents/include/asm-s390/uaccess.h 2004-06-15 13:41:39.000000000 +0800
> +++ linux-2.6.7-rc3-getdents-user_unaligned/include/asm-s390/uaccess.h 2004-06-17 14:51:42.021577010 +0800
> @@ -16,6 +16,7 @@
> */
> #include <linux/sched.h>
> #include <linux/errno.h>
> +#include <asm-generic/uaccess.h>
>
> #define VERIFY_READ 0
> #define VERIFY_WRITE 1
ppc64 and s390 both don't care about alignment, so simply using
#define __get_user_unaligned __get_user
#define __put_user_unaligned __put_user
would make more sense here. See include/asm-*/unaligned.h
> diff -purN -X dontdiff linux-2.6.7-rc3-getdents/include/asm-x86_64/uaccess.h linux-2.6.7-rc3-getdents-user_unaligned/include/asm-x86_64/uaccess.h
> --- linux-2.6.7-rc3-getdents/include/asm-x86_64/uaccess.h 2004-06-15 13:41:34.000000000 +0800
> +++ linux-2.6.7-rc3-getdents-user_unaligned/include/asm-x86_64/uaccess.h 2004-06-17 14:51:42.022553572 +0800
> @@ -10,6 +10,7 @@
> #include <linux/sched.h>
> #include <linux/prefetch.h>
> #include <asm/page.h>
> +#include <asm-generic/uaccess.h>
>
> #define VERIFY_READ 0
> #define VERIFY_WRITE 1
Same on x86_64.
Arnd <><
[-- Attachment #2: signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2004-06-17 23:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-20 21:06 =?iso-8859-1?Q?Re:_sys_getdents64_needs_compat_wrapper_??= Arnd Bergmann
2004-06-05 0:16 ` =?iso-8859-1?Q?Re:_sys_getdents64_needs_compat_wrapper_??= Arun Sharma
2004-06-05 0:28 ` sys getdents64 needs compat wrapper ? David S. Miller
2004-06-07 21:13 ` Arun Sharma
2004-06-07 21:58 ` David S. Miller
2004-06-11 15:09 ` Arnd Bergmann
2004-06-14 18:15 ` Arun Sharma
2004-06-17 22:28 ` Arun Sharma
2004-06-17 23:36 ` Arnd Bergmann [this message]
2004-06-18 0:56 ` Arun Sharma
2004-06-18 17:05 ` Arun Sharma
2004-06-20 21:50 ` Arnd Bergmann
2004-06-22 18:21 ` Arun Sharma
-- strict thread matches above, loose matches on Subject: below --
2004-06-05 14:52 =?iso-8859-1?Q?Re:_Re:_Re:_sys_getdents64_needs_compat_wrapper_??= Arnd Bergmann
2004-06-05 18:41 ` sys getdents64 needs compat wrapper ? Andrew Morton
2004-06-05 19:31 ` David S. Miller
2004-05-20 18:32 sys_getdents64 " Arun Sharma
2004-05-20 20:58 ` David S. Miller
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=200406180136.34384.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=akpm@osdl.org \
--cc=arun.sharma@intel.com \
--cc=davem@redhat.com \
--cc=linux-arch@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox