Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-13 Thread Catalin Marinas
On Thu, Sep 13, 2012 at 12:03:27PM +0100, Arnd Bergmann wrote:
> On Thursday 13 September 2012, Catalin Marinas wrote:
> > +#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
> > +asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
> > +  compat_off_t __user *offset, s32 count)
> > +{
> > +   mm_segment_t old_fs = get_fs();
> > +   int ret;
> > +   off_t of;
> > +
> > +   if (offset && get_user(of, offset))
> > +   return -EFAULT;
> > +
> > +   set_fs(KERNEL_DS);
> > +   ret = sys_sendfile(out_fd, in_fd,
> > +  offset ? (off_t __user *) : NULL, count);
> > +   set_fs(old_fs);
> > +
> > +   if (offset && put_user(of, offset))
> > +   return -EFAULT;
> > +   return ret;
> > +}
> > +#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
> 
> Looking at this code in detail now, I think it's better to move the functions 
> to
> fs/read_write.c and get rid of the get_fs/set_fs hack, like
> 
> asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
>compat_off_t __user *offset, s32 count)
...

It makes sense (copied below, just for compat_sys_sendfile until my
comments below are clarified). One minor improvement, I think we should
use compat_size_t for the count, it is a u32 in all cases.

> This implementation is smaller and more efficient than the common one.
> 
> Same for compat_sys_sendfile64, although I don't think there is ever
> a case where loff_t is defined differently from compat_loff_t, so
> you can probably just use the native sys_sendfile64 for the compat
> case.

That's what we do on AArch64, though powerpc and sparc define their own.
The "count" argument would be different between compat and non-compat
versions and I'm not sure what assumptions are made on the syscall entry
path on these architectures (on AArch64 we ensure that the top 32-bit
part of an X register is always 0 for 32-bit syscalls).

Another difference is that the "count" argument for
compat_sys_sendfile64 is s32 on powerpc and u32 on sparc. I can't tell
whether it would make a difference in practice but if we use
compat_size_t for the generic version the powerpc wouldn't get the sign
extension.

Powerpc has some comment about a need to treat in_fd/out_fd arguments as
signed ints but I don't fully understand it (well, maybe powerpc needs
the sign to be fully extended to 64-bit even for int).

--8<---

>From 7c6747fc9f69d20f445e4af69c644acb04a74f45 Mon Sep 17 00:00:00 2001
From: Catalin Marinas 
Date: Thu, 13 Sep 2012 09:51:10 +0100
Subject: [PATCH 1/3] Add generic compat_sys_sendfile implementation

This function is used by other architectures requiring compat support,
so just make it generic.

Signed-off-by: Catalin Marinas 
Cc: Arnd Bergmann 
---
 fs/read_write.c|   22 ++
 include/linux/compat.h |3 +++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 1adfb69..91b91c4 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1007,3 +1007,25 @@ SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, 
loff_t __user *, offset, si
 
return do_sendfile(out_fd, in_fd, NULL, count, 0);
 }
+
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, compat_size_t 
count)
+{
+   loff_t pos;
+   off_t off;
+   ssize_t ret;
+
+   if (offset) {
+   if (unlikely(get_user(off, offset)))
+   return -EFAULT;
+   pos = off;
+   ret = do_sendfile(out_fd, in_fd, , count, MAX_NON_LFS);
+   if (unlikely(put_user(pos, offset)))
+   return -EFAULT;
+   return ret;
+   }
+
+   return do_sendfile(out_fd, in_fd, NULL, count, 0);
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
diff --git a/include/linux/compat.h b/include/linux/compat.h
index c4be3f5..f386e82 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -594,6 +594,9 @@ asmlinkage ssize_t 
compat_sys_process_vm_writev(compat_pid_t pid,
unsigned long liovcnt, const struct compat_iovec __user *rvec,
unsigned long riovcnt, unsigned long flags);
 
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, s32 count);
+
 #else
 
 #define is_compat_task() (0)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-13 Thread Arnd Bergmann
On Thursday 13 September 2012, Catalin Marinas wrote:
> Here they are. For converting the other architectures, I'll post
> separate patches as I don't want to add an extra dependency to the
> arm64 series.

Ok, thanks!


> diff --git a/kernel/compat.c b/kernel/compat.c
> index c28a306..5f07388 100644
> --- a/kernel/compat.c
> +++ b/kernel/compat.c
> @@ -1215,6 +1215,50 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
> return 0;
>  }
>  
> +#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
> +asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
> +  compat_off_t __user *offset, s32 count)
> +{
> +   mm_segment_t old_fs = get_fs();
> +   int ret;
> +   off_t of;
> +
> +   if (offset && get_user(of, offset))
> +   return -EFAULT;
> +
> +   set_fs(KERNEL_DS);
> +   ret = sys_sendfile(out_fd, in_fd,
> +  offset ? (off_t __user *) : NULL, count);
> +   set_fs(old_fs);
> +
> +   if (offset && put_user(of, offset))
> +   return -EFAULT;
> +   return ret;
> +}
> +#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */

Looking at this code in detail now, I think it's better to move the functions to
fs/read_write.c and get rid of the get_fs/set_fs hack, like

asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
   compat_off_t __user *offset, s32 count)
{   
loff_t pos;
compat_off_t off;
ssize_t ret;

if (offset) {
if (unlikely(get_user(off, offset)))
return -EFAULT;
pos = off;
ret = do_sendfile(out_fd, in_fd, , count, MAX_NON_LFS);
if (unlikely(put_user(pos, offset)))
return -EFAULT;
return ret;
}

return do_sendfile(out_fd, in_fd, NULL, count, 0);
}

This implementation is smaller and more efficient than the common one.

Same for compat_sys_sendfile64, although I don't think there is ever
a case where loff_t is defined differently from compat_loff_t, so
you can probably just use the native sys_sendfile64 for the compat
case.

>  
> +#ifdef __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL
> +asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
> +   struct compat_timespec __user 
> *interval)
> +{
> +   struct timespec t;
> +   int ret;
> +   mm_segment_t old_fs = get_fs();
> +
> +   set_fs(KERNEL_DS);
> +   ret = sys_sched_rr_get_interval(pid, (struct timespec __user *));
> +   set_fs(old_fs);
> +   if (put_compat_timespec(, interval))
> +   return -EFAULT;
> +   return ret;
> +}
> +#endif /* __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL */
> +

This one looks reasonable. It would be nice to kill the get_fs/set_fs but here
it would just make the native code slower or duplicate a lot of it.

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


Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-13 Thread Catalin Marinas
On Fri, Sep 07, 2012 at 08:47:45PM +0100, Arnd Bergmann wrote:
> On Friday 07 September 2012, Catalin Marinas wrote:
> > 
> > From: Will Deacon 
> > 
> > This patch adds support for 32-bit applications. The vectors page is a
> > binary blob mapped into the application user space at 0x (the
> > AArch64 toolchain does not support compilation of AArch32 code). Full
> > compatibility with ARMv7 user space is supported. The use of deprecated
> > ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on
> > AArch64 kernels and unaligned LDM/STM is not supported.
> > 
> > Please note that only the ARM 32-bit EABI is supported, so no OABI
> > compatibility.
> > 
> > Signed-off-by: Will Deacon 
> > Signed-off-by: Catalin Marinas 
> > Acked-by: Tony Lindgren 
> 
> I guess you haven't had time to turn any of these into architecture
> independent functions as discussed last time?

Here they are. For converting the other architectures, I'll post
separate patches as I don't want to add an extra dependency to the
arm64 series.


>From 87fb5301a44ac05b4e6d7245db02acc2dedde831 Mon Sep 17 00:00:00 2001
From: Catalin Marinas 
Date: Thu, 13 Sep 2012 09:51:10 +0100
Subject: [PATCH 1/3] Add generic compat_sys_sendfile and
 compat_sys_sendfile64

These functions are used by other architectures requiring compat
support, so just make them generic.

Signed-off-by: Catalin Marinas 
Cc: Arnd Bergmann 
---
 include/linux/compat.h |5 +
 kernel/compat.c|   44 
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index c4be3f5..e2f5e9a 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -594,6 +594,11 @@ asmlinkage ssize_t 
compat_sys_process_vm_writev(compat_pid_t pid,
unsigned long liovcnt, const struct compat_iovec __user *rvec,
unsigned long riovcnt, unsigned long flags);
 
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, s32 count);
+asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
+compat_loff_t __user *offset, s32 count);
+
 #else
 
 #define is_compat_task() (0)
diff --git a/kernel/compat.c b/kernel/compat.c
index c28a306..5f07388 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -1215,6 +1215,50 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
return 0;
 }
 
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, s32 count)
+{
+   mm_segment_t old_fs = get_fs();
+   int ret;
+   off_t of;
+
+   if (offset && get_user(of, offset))
+   return -EFAULT;
+
+   set_fs(KERNEL_DS);
+   ret = sys_sendfile(out_fd, in_fd,
+  offset ? (off_t __user *) : NULL, count);
+   set_fs(old_fs);
+
+   if (offset && put_user(of, offset))
+   return -EFAULT;
+   return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
+
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE64
+asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
+compat_loff_t __user *offset, s32 count)
+{
+   mm_segment_t old_fs = get_fs();
+   int ret;
+   loff_t of;
+
+   if (offset && get_user(of, offset))
+   return -EFAULT;
+
+   set_fs(KERNEL_DS);
+   ret = sys_sendfile(out_fd, in_fd,
+  offset ? (loff_t __user *) : NULL, count);
+   set_fs(old_fs);
+
+   if (offset && put_user(of, offset))
+   return -EFAULT;
+   return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE64 */
+
 /*
  * Allocate user-space memory for the duration of a single system call,
  * in order to marshall parameters inside a compat thunk.


>From fa734f9523e35d7a6e9ab5e252ab344133111c1f Mon Sep 17 00:00:00 2001
From: Catalin Marinas 
Date: Thu, 13 Sep 2012 09:55:17 +0100
Subject: [PATCH 2/3] Add generic compat_sys_sched_rr_get_interval
 implementation

This patch adds a generic implementation for
compat_sys_sched_rr_get_interval as it is used by other architectures.

Signed-off-by: Catalin Marinas 
Cc: Arnd Bergmann 
---
 include/linux/compat.h |3 +++
 kernel/compat.c|   17 +
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index e2f5e9a..bbe89b8 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -599,6 +599,9 @@ asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
 asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
 compat_loff_t __user *offset, s32 count);
 
+asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
+   struct compat_timespec __user 
*interval);
+
 

Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-13 Thread Catalin Marinas
On Fri, Sep 07, 2012 at 08:47:45PM +0100, Arnd Bergmann wrote:
 On Friday 07 September 2012, Catalin Marinas wrote:
  
  From: Will Deacon will.dea...@arm.com
  
  This patch adds support for 32-bit applications. The vectors page is a
  binary blob mapped into the application user space at 0x (the
  AArch64 toolchain does not support compilation of AArch32 code). Full
  compatibility with ARMv7 user space is supported. The use of deprecated
  ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on
  AArch64 kernels and unaligned LDM/STM is not supported.
  
  Please note that only the ARM 32-bit EABI is supported, so no OABI
  compatibility.
  
  Signed-off-by: Will Deacon will.dea...@arm.com
  Signed-off-by: Catalin Marinas catalin.mari...@arm.com
  Acked-by: Tony Lindgren t...@atomide.com
 
 I guess you haven't had time to turn any of these into architecture
 independent functions as discussed last time?

Here they are. For converting the other architectures, I'll post
separate patches as I don't want to add an extra dependency to the
arm64 series.


From 87fb5301a44ac05b4e6d7245db02acc2dedde831 Mon Sep 17 00:00:00 2001
From: Catalin Marinas catalin.mari...@arm.com
Date: Thu, 13 Sep 2012 09:51:10 +0100
Subject: [PATCH 1/3] Add generic compat_sys_sendfile and
 compat_sys_sendfile64

These functions are used by other architectures requiring compat
support, so just make them generic.

Signed-off-by: Catalin Marinas catalin.mari...@arm.com
Cc: Arnd Bergmann a...@arndb.de
---
 include/linux/compat.h |5 +
 kernel/compat.c|   44 
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index c4be3f5..e2f5e9a 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -594,6 +594,11 @@ asmlinkage ssize_t 
compat_sys_process_vm_writev(compat_pid_t pid,
unsigned long liovcnt, const struct compat_iovec __user *rvec,
unsigned long riovcnt, unsigned long flags);
 
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, s32 count);
+asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
+compat_loff_t __user *offset, s32 count);
+
 #else
 
 #define is_compat_task() (0)
diff --git a/kernel/compat.c b/kernel/compat.c
index c28a306..5f07388 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -1215,6 +1215,50 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
return 0;
 }
 
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, s32 count)
+{
+   mm_segment_t old_fs = get_fs();
+   int ret;
+   off_t of;
+
+   if (offset  get_user(of, offset))
+   return -EFAULT;
+
+   set_fs(KERNEL_DS);
+   ret = sys_sendfile(out_fd, in_fd,
+  offset ? (off_t __user *)of : NULL, count);
+   set_fs(old_fs);
+
+   if (offset  put_user(of, offset))
+   return -EFAULT;
+   return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
+
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE64
+asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
+compat_loff_t __user *offset, s32 count)
+{
+   mm_segment_t old_fs = get_fs();
+   int ret;
+   loff_t of;
+
+   if (offset  get_user(of, offset))
+   return -EFAULT;
+
+   set_fs(KERNEL_DS);
+   ret = sys_sendfile(out_fd, in_fd,
+  offset ? (loff_t __user *)of : NULL, count);
+   set_fs(old_fs);
+
+   if (offset  put_user(of, offset))
+   return -EFAULT;
+   return ret;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE64 */
+
 /*
  * Allocate user-space memory for the duration of a single system call,
  * in order to marshall parameters inside a compat thunk.


From fa734f9523e35d7a6e9ab5e252ab344133111c1f Mon Sep 17 00:00:00 2001
From: Catalin Marinas catalin.mari...@arm.com
Date: Thu, 13 Sep 2012 09:55:17 +0100
Subject: [PATCH 2/3] Add generic compat_sys_sched_rr_get_interval
 implementation

This patch adds a generic implementation for
compat_sys_sched_rr_get_interval as it is used by other architectures.

Signed-off-by: Catalin Marinas catalin.mari...@arm.com
Cc: Arnd Bergmann a...@arndb.de
---
 include/linux/compat.h |3 +++
 kernel/compat.c|   17 +
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index e2f5e9a..bbe89b8 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -599,6 +599,9 @@ asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
 asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd,
 compat_loff_t __user *offset, s32 count);
 
+asmlinkage 

Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-13 Thread Arnd Bergmann
On Thursday 13 September 2012, Catalin Marinas wrote:
 Here they are. For converting the other architectures, I'll post
 separate patches as I don't want to add an extra dependency to the
 arm64 series.

Ok, thanks!


 diff --git a/kernel/compat.c b/kernel/compat.c
 index c28a306..5f07388 100644
 --- a/kernel/compat.c
 +++ b/kernel/compat.c
 @@ -1215,6 +1215,50 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
 return 0;
  }
  
 +#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
 +asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
 +  compat_off_t __user *offset, s32 count)
 +{
 +   mm_segment_t old_fs = get_fs();
 +   int ret;
 +   off_t of;
 +
 +   if (offset  get_user(of, offset))
 +   return -EFAULT;
 +
 +   set_fs(KERNEL_DS);
 +   ret = sys_sendfile(out_fd, in_fd,
 +  offset ? (off_t __user *)of : NULL, count);
 +   set_fs(old_fs);
 +
 +   if (offset  put_user(of, offset))
 +   return -EFAULT;
 +   return ret;
 +}
 +#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */

Looking at this code in detail now, I think it's better to move the functions to
fs/read_write.c and get rid of the get_fs/set_fs hack, like

asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
   compat_off_t __user *offset, s32 count)
{   
loff_t pos;
compat_off_t off;
ssize_t ret;

if (offset) {
if (unlikely(get_user(off, offset)))
return -EFAULT;
pos = off;
ret = do_sendfile(out_fd, in_fd, pos, count, MAX_NON_LFS);
if (unlikely(put_user(pos, offset)))
return -EFAULT;
return ret;
}

return do_sendfile(out_fd, in_fd, NULL, count, 0);
}

This implementation is smaller and more efficient than the common one.

Same for compat_sys_sendfile64, although I don't think there is ever
a case where loff_t is defined differently from compat_loff_t, so
you can probably just use the native sys_sendfile64 for the compat
case.

  
 +#ifdef __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL
 +asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
 +   struct compat_timespec __user 
 *interval)
 +{
 +   struct timespec t;
 +   int ret;
 +   mm_segment_t old_fs = get_fs();
 +
 +   set_fs(KERNEL_DS);
 +   ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)t);
 +   set_fs(old_fs);
 +   if (put_compat_timespec(t, interval))
 +   return -EFAULT;
 +   return ret;
 +}
 +#endif /* __ARCH_WANT_COMPAT_SYS_SCHED_RR_GET_INTERVAL */
 +

This one looks reasonable. It would be nice to kill the get_fs/set_fs but here
it would just make the native code slower or duplicate a lot of it.

Acked-by: Arnd Bergmann a...@arndb.de
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-13 Thread Catalin Marinas
On Thu, Sep 13, 2012 at 12:03:27PM +0100, Arnd Bergmann wrote:
 On Thursday 13 September 2012, Catalin Marinas wrote:
  +#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
  +asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
  +  compat_off_t __user *offset, s32 count)
  +{
  +   mm_segment_t old_fs = get_fs();
  +   int ret;
  +   off_t of;
  +
  +   if (offset  get_user(of, offset))
  +   return -EFAULT;
  +
  +   set_fs(KERNEL_DS);
  +   ret = sys_sendfile(out_fd, in_fd,
  +  offset ? (off_t __user *)of : NULL, count);
  +   set_fs(old_fs);
  +
  +   if (offset  put_user(of, offset))
  +   return -EFAULT;
  +   return ret;
  +}
  +#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
 
 Looking at this code in detail now, I think it's better to move the functions 
 to
 fs/read_write.c and get rid of the get_fs/set_fs hack, like
 
 asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
compat_off_t __user *offset, s32 count)
...

It makes sense (copied below, just for compat_sys_sendfile until my
comments below are clarified). One minor improvement, I think we should
use compat_size_t for the count, it is a u32 in all cases.

 This implementation is smaller and more efficient than the common one.
 
 Same for compat_sys_sendfile64, although I don't think there is ever
 a case where loff_t is defined differently from compat_loff_t, so
 you can probably just use the native sys_sendfile64 for the compat
 case.

That's what we do on AArch64, though powerpc and sparc define their own.
The count argument would be different between compat and non-compat
versions and I'm not sure what assumptions are made on the syscall entry
path on these architectures (on AArch64 we ensure that the top 32-bit
part of an X register is always 0 for 32-bit syscalls).

Another difference is that the count argument for
compat_sys_sendfile64 is s32 on powerpc and u32 on sparc. I can't tell
whether it would make a difference in practice but if we use
compat_size_t for the generic version the powerpc wouldn't get the sign
extension.

Powerpc has some comment about a need to treat in_fd/out_fd arguments as
signed ints but I don't fully understand it (well, maybe powerpc needs
the sign to be fully extended to 64-bit even for int).

--8---

From 7c6747fc9f69d20f445e4af69c644acb04a74f45 Mon Sep 17 00:00:00 2001
From: Catalin Marinas catalin.mari...@arm.com
Date: Thu, 13 Sep 2012 09:51:10 +0100
Subject: [PATCH 1/3] Add generic compat_sys_sendfile implementation

This function is used by other architectures requiring compat support,
so just make it generic.

Signed-off-by: Catalin Marinas catalin.mari...@arm.com
Cc: Arnd Bergmann a...@arndb.de
---
 fs/read_write.c|   22 ++
 include/linux/compat.h |3 +++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 1adfb69..91b91c4 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1007,3 +1007,25 @@ SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, 
loff_t __user *, offset, si
 
return do_sendfile(out_fd, in_fd, NULL, count, 0);
 }
+
+#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, compat_size_t 
count)
+{
+   loff_t pos;
+   off_t off;
+   ssize_t ret;
+
+   if (offset) {
+   if (unlikely(get_user(off, offset)))
+   return -EFAULT;
+   pos = off;
+   ret = do_sendfile(out_fd, in_fd, pos, count, MAX_NON_LFS);
+   if (unlikely(put_user(pos, offset)))
+   return -EFAULT;
+   return ret;
+   }
+
+   return do_sendfile(out_fd, in_fd, NULL, count, 0);
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
diff --git a/include/linux/compat.h b/include/linux/compat.h
index c4be3f5..f386e82 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -594,6 +594,9 @@ asmlinkage ssize_t 
compat_sys_process_vm_writev(compat_pid_t pid,
unsigned long liovcnt, const struct compat_iovec __user *rvec,
unsigned long riovcnt, unsigned long flags);
 
+asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
+  compat_off_t __user *offset, s32 count);
+
 #else
 
 #define is_compat_task() (0)
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-07 Thread Arnd Bergmann
On Friday 07 September 2012, Catalin Marinas wrote:
> 
> From: Will Deacon 
> 
> This patch adds support for 32-bit applications. The vectors page is a
> binary blob mapped into the application user space at 0x (the
> AArch64 toolchain does not support compilation of AArch32 code). Full
> compatibility with ARMv7 user space is supported. The use of deprecated
> ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on
> AArch64 kernels and unaligned LDM/STM is not supported.
> 
> Please note that only the ARM 32-bit EABI is supported, so no OABI
> compatibility.
> 
> Signed-off-by: Will Deacon 
> Signed-off-by: Catalin Marinas 
> Acked-by: Tony Lindgren 

I guess you haven't had time to turn any of these into architecture
independent functions as discussed last time?

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


Re: [PATCH v3 21/31] arm64: 32-bit (compat) applications support

2012-09-07 Thread Arnd Bergmann
On Friday 07 September 2012, Catalin Marinas wrote:
 
 From: Will Deacon will.dea...@arm.com
 
 This patch adds support for 32-bit applications. The vectors page is a
 binary blob mapped into the application user space at 0x (the
 AArch64 toolchain does not support compilation of AArch32 code). Full
 compatibility with ARMv7 user space is supported. The use of deprecated
 ARMv7 functionality (SWP, CP15 barriers) has been disabled by default on
 AArch64 kernels and unaligned LDM/STM is not supported.
 
 Please note that only the ARM 32-bit EABI is supported, so no OABI
 compatibility.
 
 Signed-off-by: Will Deacon will.dea...@arm.com
 Signed-off-by: Catalin Marinas catalin.mari...@arm.com
 Acked-by: Tony Lindgren t...@atomide.com

I guess you haven't had time to turn any of these into architecture
independent functions as discussed last time?

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