[PATCH 10/19] arm64: introduce binfmt_elf32.c

2016-06-17 Thread Yury Norov
As we support more than one compat formats, it looks more reasonable
to not use fs/compat_binfmt.c. Custom binfmt_elf32.c allows to move aarch32
specific definitions there and make code more maintainable and readable.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/Kconfig   |  1 -
 arch/arm64/include/asm/hwcap.h   |  2 --
 arch/arm64/kernel/Makefile   |  2 +-
 arch/arm64/kernel/binfmt_elf32.c | 31 +++
 4 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm64/kernel/binfmt_elf32.c

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index aea8e61..f5735ec 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -979,7 +979,6 @@ config AARCH32_EL0
def_bool y
depends on ARM64_4K_PAGES || EXPERT
select COMPAT
-   select COMPAT_BINFMT_ELF
select HAVE_UID16
select OLD_SIGSUSPEND3
select COMPAT_OLD_SIGACTION
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 2c7fc5d..99dfd92 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -47,8 +47,6 @@
 #define ELF_HWCAP  (elf_hwcap)
 
 #ifdef CONFIG_AARCH32_EL0
-#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
-#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
 extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
 #endif
 
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 631a118..60d59cb 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -27,7 +27,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
-  ../../arm/kernel/opcodes.o
+  ../../arm/kernel/opcodes.o 
binfmt_elf32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
new file mode 100644
index 000..aec1c8a
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -0,0 +1,31 @@
+/*
+ * Support for AArch32 Linux ELF binaries.
+ */
+
+/* AArch32 EABI. */
+#define EF_ARM_EABI_MASK   0xff00
+
+#define compat_start_threadcompat_start_thread
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
+#define COMPAT_ARCH_DLINFO
+#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
+#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("v8b")
+#else
+#define COMPAT_ELF_PLATFORM("v8l")
+#endif
+
+#define compat_arch_setup_additional_pages \
+   aarch32_setup_vectors_page
+struct linux_binprm;
+extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
+ int uses_interp);
+
+#include "../../../fs/compat_binfmt_elf.c"
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/19] arm64: ilp32: introduce binfmt_ilp32.c

2016-06-17 Thread Yury Norov
to handle ILP32 binaries

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/elf.h |  6 +++
 arch/arm64/kernel/Makefile   |  1 +
 arch/arm64/kernel/binfmt_ilp32.c | 96 
 3 files changed, 103 insertions(+)
 create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index a967726..4dcbcec 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -174,10 +174,16 @@ extern int arch_setup_additional_pages(struct 
linux_binprm *bprm,
 
 #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)
 
+#ifndef USE_AARCH64_GREG
 /* AArch32 registers. */
 #define COMPAT_ELF_NGREG   18
 typedef unsigned int   compat_elf_greg_t;
 typedef compat_elf_greg_t  compat_elf_gregset_t[COMPAT_ELF_NGREG];
+#else /* AArch64 registers for AARCH64/ILP32 */
+#define COMPAT_ELF_NGREG   ELF_NGREG
+#define compat_elf_greg_t  elf_greg_t
+#define compat_elf_gregset_t   elf_gregset_t
+#endif
 
 /* AArch32 EABI. */
 #define EF_ARM_EABI_MASK   0xff00
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 60d59cb..bcdd4b2 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..416b3f5
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,96 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+#define USE_AARCH64_GREG
+
+#include 
+#include 
+
+#undef ELF_CLASS
+#define ELF_CLASS  ELFCLASS32
+
+#undef elfhdr
+#undef elf_phdr
+#undef elf_shdr
+#undef elf_note
+#undef elf_addr_t
+#define elfhdr elf32_hdr
+#define elf_phdr   elf32_phdr
+#define elf_shdr   elf32_shdr
+#define elf_note   elf32_note
+#define elf_addr_t Elf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_t compat_siginfo_t
+#define copy_siginfo_to_user   copy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatus   compat_elf_prstatus
+#define elf_prpsinfo   compat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+ struct compat_timeval *value)
+{
+   struct timeval tv;
+   cputime_to_timeval(cputime, );
+   value->tv_sec = tv.tv_sec;
+   value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)  (((x)->e_machine == EM_AARCH64) \
+   && (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {   \
+   set_thread_flag(TIF_32BIT_AARCH64); \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)(long)current->mm->context.vdso);   \
+} while (0)
+
+#undef ELF_PLATFORM
+#ifdef __AARCH64EB__
+#define ELF_PLATFORM   ("aarch64_be:ilp32")
+#else
+#define ELF_PLATFORM   ("aarch64:ilp32")
+#endif
+
+#undef ELF_ET_DYN_BASE
+#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE
+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP  ((u32) elf_hwcap)
+#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_for

[PATCH 15/19] arm64: signal: share lp64 signal routines to ilp32

2016-06-17 Thread Yury Norov
After that, it will be possible to reuse it in ilp32.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal_common.h | 33 
 arch/arm64/kernel/signal.c | 93 +-
 2 files changed, 92 insertions(+), 34 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal_common.h

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
new file mode 100644
index 000..756ed2c
--- /dev/null
+++ b/arch/arm64/include/asm/signal_common.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 1995-2009 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 Cavium Networks.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_SIGNAL_COMMON_H
+#define __ASM_SIGNAL_COMMON_H
+
+#include 
+#include 
+#include 
+
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx);
+int restore_fpsimd_context(struct fpsimd_context __user *ctx);
+int setup_sigcontext(struct sigcontext __user *uc_mcontext, struct pt_regs 
*regs);
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
+void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
+   void __user *frame, off_t sigframe_off, int usig);
+
+#endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index be02f65..5c73864 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -34,18 +34,26 @@
 #include 
 #include 
 #include 
+#include 
+
+#define RT_SIGFRAME_FP_POS (offsetof(struct rt_sigframe, sig)  \
+   + offsetof(struct sigframe, fp))
+
+struct sigframe {
+   struct ucontext uc;
+   u64 fp;
+   u64 lr;
+};
 
 /*
  * Do a signal return; undo the signal stack. These are aligned to 128-bit.
  */
 struct rt_sigframe {
struct siginfo info;
-   struct ucontext uc;
-   u64 fp;
-   u64 lr;
+   struct sigframe sig;
 };
 
-static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state *fpsimd = >thread.fpsimd_state;
int err;
@@ -65,7 +73,7 @@ static int preserve_fpsimd_context(struct fpsimd_context 
__user *ctx)
return err ? -EFAULT : 0;
 }
 
-static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
+int restore_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state fpsimd;
__u32 magic, size;
@@ -93,22 +101,30 @@ static int restore_fpsimd_context(struct fpsimd_context 
__user *ctx)
 }
 
 static int restore_sigframe(struct pt_regs *regs,
-   struct rt_sigframe __user *sf)
+   struct sigframe __user *sf)
 {
sigset_t set;
-   int i, err;
-   void *aux = sf->uc.uc_mcontext.__reserved;
-
+   int err;
err = __copy_from_user(, >uc.uc_sigmask, sizeof(set));
if (err == 0)
set_current_blocked();
 
+   err |= restore_sigcontext(regs, >uc.uc_mcontext);
+   return err;
+}
+
+
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user 
*uc_mcontext)
+{
+   int i, err = 0;
+   void *aux = uc_mcontext->__reserved;
+
for (i = 0; i < 31; i++)
-   __get_user_error(regs->regs[i], >uc.uc_mcontext.regs[i],
+   __get_user_error(regs->regs[i], _mcontext->regs[i],
 err);
-   __get_user_error(regs->sp, >uc.uc_mcontext.sp, err);
-   __get_user_error(regs->pc, >uc.uc_mcontext.pc, err);
-   __get_user_error(regs->pstate, >uc.uc_mcontext.pstate, err);
+   __get_user_error(regs->sp, _mcontext->sp, err);
+   __get_user_error(regs->pc, _mcontext->pc, err);
+   __get_user_error(regs->pstate, _mcontext->pstate, err);
 
/*
 * Avoid sys_rt_sigreturn() restarting.
@@ -145,10 +161,10 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
goto badframe;
 
-   if (restore_sigframe(regs, frame))
+   if (restore_sigframe(regs, >sig))
goto badframe;
 
-   if (restore_altstack(>uc.uc_stack))
+   if (restore_altstack(>sig.uc.uc_stack))
goto badframe;
 
return regs->

[PATCH 17/19] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-17 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

ILP32 uses AARCH32 compat structures and syscall handlers for signals.
But ILP32 struct rt_sigframe  and ucontext differs from both LP64 and
AARCH32. So some specific mechanism is needed to take care of it.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal_ilp32.h |  34 ++
 arch/arm64/kernel/Makefile|   3 +-
 arch/arm64/kernel/entry_ilp32.S   |  23 
 arch/arm64/kernel/signal.c|   3 +
 arch/arm64/kernel/signal_ilp32.c  | 194 ++
 5 files changed, 256 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/signal_ilp32.h
 create mode 100644 arch/arm64/kernel/entry_ilp32.S
 create mode 100644 arch/arm64/kernel/signal_ilp32.c

diff --git a/arch/arm64/include/asm/signal_ilp32.h 
b/arch/arm64/include/asm/signal_ilp32.h
new file mode 100644
index 000..30eff23
--- /dev/null
+++ b/arch/arm64/include/asm/signal_ilp32.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGNAL_ILP32_H
+#define __ASM_SIGNAL_ILP32_H
+
+#ifdef CONFIG_ARM64_ILP32
+
+#include 
+
+int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs);
+
+#else
+
+static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
+ struct pt_regs *regs)
+{
+   return -ENOSYS;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
+#endif /* __ASM_SIGNAL_ILP32_H */
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index d69bd40..ae8aacb 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,8 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o   
\
+  signal_ilp32.o entry_ilp32.o
 arm64-obj-$(CONFIG_COMPAT) += entry32_common.o signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
diff --git a/arch/arm64/kernel/entry_ilp32.S b/arch/arm64/kernel/entry_ilp32.S
new file mode 100644
index 000..5063172
--- /dev/null
+++ b/arch/arm64/kernel/entry_ilp32.S
@@ -0,0 +1,23 @@
+/*
+ * ILP32 system call wrappers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+
+ENTRY(ilp32_sys_rt_sigreturn_wrapper)
+   mov x0, sp
+   b   ilp32_sys_rt_sigreturn
+ENDPROC(ilp32_sys_rt_sigreturn_wrapper)
+
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 5c73864..241bfeb 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RT_SIGFRAME_FP_POS (offsetof(struct rt_sigframe, sig)  \
+ offsetof(struct sigframe, fp))
@@ -325,6 +326,8 @@ static void handle_signal(struct ksignal *ksig, struct 
pt_regs *regs)
ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
else
ret = compat_setup_frame(usig, ksig, oldset, regs);
+   } else if (is_ilp32_compat_task()) {
+   ret = ilp32_setup_rt_frame(usig, ksig, oldset, regs);
} else {
ret = setup_rt_frame(usig, ksig, oldset, regs);
}
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp3

[PATCH 03/19] arm64: ilp32: add documentation on the ILP32 ABI for ARM64

2016-06-17 Thread Yury Norov
Based on Andrew Pinski's patch-series.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 Documentation/arm64/ilp32.txt | 54 +++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/arm64/ilp32.txt

diff --git a/Documentation/arm64/ilp32.txt b/Documentation/arm64/ilp32.txt
new file mode 100644
index 000..d5faa31
--- /dev/null
+++ b/Documentation/arm64/ilp32.txt
@@ -0,0 +1,54 @@
+ILP32 AARCH64 SYSCALL ABI
+=
+
+This document describes the ILP32 syscall ABI and where it differs
+from the generic compat linux syscall interface.
+
+AARCH64/ILP32 userspace can potentially access top halves of registers that
+are passed as syscall arguments, so such registers (w0-w7) are deloused.
+
+AARCH64/ILP32 provides next types turned to 64-bit (comparing to AARCH32):
+ino_t   is u64 type.
+off_t   is s64 type.
+blkcnt_tis s64 type.
+fsblkcnt_t  is u64 type.
+fsfilcnt_t  is u64 type.
+
+AARCH64/ILP32 ABI uses standard syscall table which can be found at
+include/uapi/asm-generic/unistd.h, with the exceptions listed below.
+
+Syscalls which pass 64bit values are handled by the code shared from
+AARCH32 and pass that value as a pair. Next syscalls are affected:
+fadvise64_64()
+fallocate()
+ftruncate64()  
+pread64()
+pwrite64()
+readahead()
+sync_file_range()
+truncate64()
+sys_mmap()
+
+ptrace() syscall is handled by compat version.
+
+fcntl64() syscall is handled by non-compat handler as struct flock for ilp32
+is the same as for lp64
+
+shmat() syscall is handled by non-compat handler as aarch64/ilp32 has no
+limitation on 4-pages alignement for shared memory.
+
+Syscalls which take a pointer to stat, stat64, statfs, statfs64
+structures are now routed to native handlers directly, as aarch64/ilp32
+defines userspace ino_t, off_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t types
+as 64-bit and it makes that structures have same layout as lp64.
+Next syscalls are affected:
+fstatat64()
+fstat64()
+statfs64()
+fstatfs64()
+
+struct rt_sigframe is redefined and contains struct compat_siginfo,
+as compat syscalls expects, and struct ilp32_sigframe, to handle
+AARCH64 register set and 32-bit userspace register representation.h
+
+elf_gregset_t is taken from lp64 to handle registers properly.
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/19] compat ABI: use non-compat openat and open_by_handle_at variants

2016-06-17 Thread Yury Norov
The only difference is that non-compat version forces O_LARGEFILE,
and it should be the default behaviour for all architectures, as
we don't support 32-bit off_t. The only exception is tile32, that
continues with compat version of syscalls.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Chris Metcalf <cmetc...@ezchip.com> [for tile]
---
 arch/tile/kernel/compat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c
index 4912084..489ae19 100644
--- a/arch/tile/kernel/compat.c
+++ b/arch/tile/kernel/compat.c
@@ -94,6 +94,9 @@ COMPAT_SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned 
int, offset_high,
 #define compat_sys_readahead sys32_readahead
 #define sys_llseek compat_sys_llseek
 
+#define sys_openat compat_sys_openat
+#define sys_open_by_handle_at  compat_sys_open_by_handle_at
+
 /* Call the assembly trampolines where necessary. */
 #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn
 #define sys_clone _sys_clone
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-06-14 Thread Yury Norov
On Thu, May 26, 2016 at 09:49:42PM +0800, Zhangjian (Bamvor) wrote:
> Hi, yury
> 
> The coredump is usable in our platform. It miss the following definition:
> +#define compat_elf_greg_telf_greg_t
> +#define compat_elf_gregset_t elf_gregset_t
> 
> And it leads to the wrong register save in core dump. After apply this patch,
> gdb could debug core dump files.
> 
> Here is the full patch:
> From 102624840aa5dacdd1bbfe3b390290f52f530ea2 Mon Sep 17 00:00:00 2001
> From: Bamvor Jian Zhang 
> Date: Thu, 26 May 2016 21:00:16 +0800
> Subject: [PATCH hulk-4.1-next] arm64: ilp32: fix coredump issue
> 
> ILP32 use aarch64 register and 32bit signal struct which means it
> could not make use of the existing compat_elf_prstatus/elf_prstatus
> and compat_elf_prpsinfo/elf_prpsinfo.
> 
> This patch fix this issue by introducing the different
> compat_elf_greg_t, compat_elf_gregset_t for aarch64 ilp32 and aarch32
> el0.
> 
> Tested pass on huawei's hardware in bigendian.
> 
> Signed-off-by: Bamvor Jian Zhang 
> ---
>  arch/arm64/include/asm/elf.h | 14 +++---
>  arch/arm64/kernel/binfmt_elf32.c |  3 +++
>  arch/arm64/kernel/binfmt_ilp32.c |  8 +++-
>  arch/arm64/kernel/ptrace.c   | 20 ++--
>  4 files changed, 27 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
> index 0106d18..9019441 100644
> --- a/arch/arm64/include/asm/elf.h
> +++ b/arch/arm64/include/asm/elf.h
> @@ -154,18 +154,18 @@ extern int arch_setup_additional_pages(struct 
> linux_binprm *bprm,
>  int uses_interp);
> 
>  /* 1GB of VA */
> -#define STACK_RND_MASK   (is_compat_task() ? \
> - 0x7ff >> (PAGE_SHIFT - 12) : \
> - 0x3 >> (PAGE_SHIFT - 12))
> +#define STACK_RND_MASK   (is_compat_task() ? \
> + 0x7ff >> (PAGE_SHIFT - 12) : \
> + 0x3 >> (PAGE_SHIFT - 12))
> 
>  #ifdef CONFIG_COMPAT
> 
> -#define COMPAT_ELF_ET_DYN_BASE   (2 * TASK_SIZE_32 / 3)
> +#define COMPAT_ELF_ET_DYN_BASE   (2 * TASK_SIZE_32 / 3)
> 
>  /* AArch32 registers. */
> -#define COMPAT_ELF_NGREG 18
> -typedef unsigned int compat_elf_greg_t;
> -typedef compat_elf_greg_tcompat_elf_gregset_t[COMPAT_ELF_NGREG];
> +#define COMPAT_ELF_NGREG 18
> +typedef unsigned int compat_a32_elf_greg_t;
> +typedef compat_a32_elf_greg_t
> compat_a32_elf_gregset_t[COMPAT_ELF_NGREG];
> 
>  #endif /* CONFIG_COMPAT */
> 
> diff --git a/arch/arm64/kernel/binfmt_elf32.c 
> b/arch/arm64/kernel/binfmt_elf32.c
> index 7b9b445..f75253c 100644
> --- a/arch/arm64/kernel/binfmt_elf32.c
> +++ b/arch/arm64/kernel/binfmt_elf32.c
> @@ -31,4 +31,7 @@ struct linux_binprm;
>  extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
> int uses_interp);
> 
> +#define compat_elf_greg_tcompat_a32_elf_greg_t
> +#define compat_elf_gregset_t compat_a32_elf_gregset_t
> +
>  #include "../../../fs/compat_binfmt_elf.c"
> diff --git a/arch/arm64/kernel/binfmt_ilp32.c 
> b/arch/arm64/kernel/binfmt_ilp32.c
> index b827a9a..01baf83 100644
> --- a/arch/arm64/kernel/binfmt_ilp32.c
> +++ b/arch/arm64/kernel/binfmt_ilp32.c
> @@ -2,7 +2,9 @@
>   * Support for ILP32 Linux/aarch64 ELF binaries.
>   */
> 
> -#include 
> +#include 
> +#include 
> +#include 
>  #include 
> 
>  #undef   ELF_CLASS
> @@ -30,9 +32,13 @@
>   * The machine-dependent core note format types are defined in 
> elfcore-compat.h,
>   * which requires asm/elf.h to define compat_elf_gregset_t et al.
>   */
> +#define compat_elf_greg_telf_greg_t
> +#define compat_elf_gregset_t elf_gregset_t
>  #define elf_prstatus compat_elf_prstatus
>  #define elf_prpsinfo compat_elf_prpsinfo
> 
> +#include 
> +
>  /*
>   * Compat version of cputime_to_compat_timeval, perhaps this
>   * should be an inline in .
> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
> index 5c86135..9784c77 100644
> --- a/arch/arm64/kernel/ptrace.c
> +++ b/arch/arm64/kernel/ptrace.c
> @@ -913,8 +913,8 @@ static const struct user_regset aarch32_regsets[] = {
>   [REGSET_COMPAT_GPR] = {
>   .core_note_type = NT_PRSTATUS,
>   .n = COMPAT_ELF_NGREG,
> - .size = sizeof(compat_elf_greg_t),
> - .align = sizeof(compat_elf_greg_t),
> + .size = sizeof(compat_a32_elf_greg_t),
> + .align = sizeof(compat_a32_elf_greg_t),
>   .get = compat_gpr_get,
>   .set = compat_gpr_set
>   },
> @@ -947,7 +947,7 @@ static int compat_ptrace_read_user(struct task_struct 
> *tsk, compat_ulong_t off,
>   tmp = tsk->mm->start_data;
>   else if (off == COMPAT_PT_TEXT_END_ADDR)
>   tmp = 

Re: [PATCH 01/23] all: syscall wrappers: add documentation

2016-06-14 Thread Yury Norov
Hi Catalin, David, all

> COMPAT_SYSCALL_WRAP2(creat, ...):
>   mov w0, w0
>   b   
> 
> > > Cost wise, this seems like it all cancels out in the end, but what
> > > do I know?
> > 
> > I think you know something, and I also think Heiko and other s390 guys
> > know something as well. So I'd like to listen their arguments here.
> > 
> > For me spark64 way is looking reasonable only because it's really simple
> > and takes less coding. I'll try it on some branch and share here what 
> > happened.
> 
> The kernel code will definitely look simpler ;). It would be good to see
> if there actually is any performance impact. Even with 16 more cycles on
> syscall entry, would they be lost in the noise? You don't need a full
> implementation, just some dummy mov x0, x0 on the entry path.
> 
> -- 
> Catalin

I wrote a simple test:

struct timeval start, end;
unsigned long long ut;

int main()
{
gettimeofday(, NULL);

for (int i = 100; i; i--)
syscall(__NR_getrusage, 100 /* EINVAL */, NULL);

gettimeofday(, NULL);

ut = (end.tv_sec - start.tv_sec) * 100ULL
+ end.tv_usec - start.tv_usec;

printf("%lld\n", ut);

exit(EXIT_SUCCESS);
}

In kernel there's minimal overhead:
diff --git a/kernel/sys.c b/kernel/sys.c
index 89d5be4..003d5ad 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1634,6 +1634,17 @@ COMPAT_SYSCALL_DEFINE2(getrusage, int, who,
struct compat_rusage __user *, ru)
{
struct rusage r;
 
+   asm volatile (
+   "   mov w0, w0  \n"
+   "   mov w1, w1  \n"
+   "   mov w2, w2  \n"
+   "   mov w3, w3  \n"
+   "   mov w4, w4  \n"
+   "   mov w5, w5  \n"
+   "   mov w6, w6  \n"
+   "   mov w7, w7  \n"
+   );
+
if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN &&
who != RUSAGE_THREAD)
return -EINVAL;

On QEMU:
With MOVs:  W/O MOVs:
832015  814564
840639  803165
830482  813116
832895  802928
832083  832658
834461  802993
829405  812465
846677  822651
828409  803393
836845  821470
828716  801044
831620  821301
825423  800278
829946  821476

We have 83 mS vs 81 mS, ~2.6% of performance degradation.
And I can show bigger numbers if I'll use asm svc instead of
syscall() wrapper which increases time as well. 

It's definitely more than 0, but not so big anyway. For syscalls
with heavy payload it will be non-measurable. So the choice
is still there. Should we use wrappers and save 2.5% of syscall
performance. Or clear top-halves unconditionally and win in simplicity?

If QEMU is looking non-representative, I can run test on real
hardware, but it takes a time, and I think will end up with similar
results.

Latest kernel with wrappers and library are here:
https://github.com/norov/linux/commits/ilp32
https://github.com/norov/glibc/commits/ilp32-dev

BTW, notice the change in ABI: syscalls that take stat and statfs
structures now routed to (wrapped) native handlers, after switching
userspace to use 64-bit off_t, ino_t, blkcnt_t, fsblkcnt_t and
fsfilcnt_t types.

Yury.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Yury Norov
Hi Bamvor,

Sorry, I missed this patch.

On Sat, Jun 04, 2016 at 07:34:32PM +0800, Zhangjian (Bamvor) wrote:
> Hi,
> 
> I found an issue of unwind with the following code. The correct backtrace
> should be:
> (gdb) where
> #0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
> #1 
> #2 func2 (num=0) at test_force3.c:22
> #3 0x00400540 in func1 (num=1) at test_force3.c:28
> #4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33
> 
> Without my patch, the backtrace is:
> (gdb) where
> #0 0x00400490 in my_sig (sig=11) at test_force3.c:16
> #1 
> #2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33
> 
> With my patch which fix the wrong frame pointer(setup_return calculate the 
> offset
> of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
> (gdb) where
> #0 0x00400490 in my_sig (sig=11) at test_force3.c:16
> #1 
> #2 func1 () at test_force3.c:28
> #3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33
> 
> I am not sure there is still some issue in kernel. But it seem that the gdb 
> of ilp32
> does not work correctly when unwind without framepointer.
> 
> The test code is:
> 
> From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
> From: Bamvor Jian Zhang 
> Date: Sat, 4 Jun 2016 14:30:05 +0800
> Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
>  new fp
> 
> ILP32 define its own sigframe(ilp32_sigframe) because of the
> difference uc_context. setup_return do not use ilp32 specific
> sigframe to calculate the new offset of fp which lead to wrong
> fp in signal handler. At this circumstance, gdb backtrace will miss
> one item:
> (gdb) where
> 
> It should be:
> (gdb) where
> 
> The test code is as follows:
> 
> void my_sig(int sig)
> {
> printf("sig=%d\n", sig);
> *(int *)0 = 0x0;
> }
> 
> void func2(int num)
> {
> printf("%s: %d\n", __FUNCTION__, num);
> *(int *)0 = 0x0;
> func2(num-1);
> }
> 
> void func1(int num)
> {
> printf("%s\n", __FUNCTION__);
> func2(num - 1);
> }
> 
> int main(int argc, char **argv)
> {
> signal(11, my_sig);
> func1(argc);
> return 0;
> }
> 
> This patch fix this by passing the correct offset of fp to
> setup_return.
> Test pass on both ILP32 and LP64 in aarch64 EE.
> 
> Signed-off-by: Bamvor Jian Zhang 
> ---
>  arch/arm64/include/asm/signal_common.h | 3 ++-
>  arch/arm64/kernel/signal.c | 9 +
>  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
>  3 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/signal_common.h 
> b/arch/arm64/include/asm/signal_common.h
> index de93c71..a5d7b63 100644
> --- a/arch/arm64/include/asm/signal_common.h
> +++ b/arch/arm64/include/asm/signal_common.h
> @@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
>   struct pt_regs *regs);
>  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
>  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
> - void __user *frame, off_t sigframe_off, int usig);
> + void __user *frame, off_t sigframe_off, off_t fp_off,
> + int usig); 
> 
>  #endif /* __ASM_SIGNAL_COMMON_H */
> diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
> index 038bebe..e66a6e9 100644
> --- a/arch/arm64/kernel/signal.c
> +++ b/arch/arm64/kernel/signal.c
> @@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
> ksignal *ksig,
>  }
> 
>  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
> -  void __user *frame, off_t sigframe_off, int usig)
> +  void __user *frame, off_t sigframe_off, off_t fp_off,
> +  int usig)
>  {
>   __sigrestore_t sigtramp;
> 
>   regs->regs[0] = usig;
>   regs->sp = (unsigned long)frame;
> - regs->regs[29] = regs->sp + sigframe_off +
> - offsetof(struct sigframe, fp);
> + regs->regs[29] = regs->sp + sigframe_off + fp_off;

I think you are right here. The only nitpick is what for we send 2
offsets just to add one to another inside setup_return()?
We can do like this:

void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
 void __user *frame, off_t fp_off, int usig)
{
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
regs->regs[29] = regs->sp + fp_off;
[...]
}

Where fp_off calculation is done by caller. 

setup_return(regs, >ka, frame,
offsetof(struct rt_sigframe, sig) + offsetof(struct sigframe, 
fp),
usig);

For me it's more clear to understand what happens with this approach.
I don't think struct rt_sigframe will grow, but we can 

Re: [PATCH 17/23] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32

2016-06-08 Thread Yury Norov
On Wed, Jun 08, 2016 at 09:34:09AM +0800, zhouchengming wrote:
> On 2016/5/24 8:04, Yury Norov wrote:
> >Here new aarch32 ptrace syscall handler is introsuced to avoid run-time
> >detection of the task type.
> >
> >Signed-off-by: Yury Norov<yno...@caviumnetworks.com>

[...]

> Hello, I found ilp32 will use sys_ptrace, not compat_sys_ptrace. So I write
> a little patch to see if can solve the problem correctly.
> 
> Thanks.
> 
> From f6156236df578bb05c4a17e7f9776ceaf8f7afe6 Mon Sep 17 00:00:00 2001
> From: Zhou Chengming <zhouchengmi...@huawei.com>
> Date: Wed, 8 Jun 2016 09:46:23 +0800
> Subject: [PATCH] ilp32: use compat_sys_ptrace instead of sys_ptrace
> 
> When we analyze a testcase of ptrace that failed on ilp32, we found
> the syscall that the ilp32 uses is sys_ptrace, not compat_sys_ptrace.
> Because in include/uapi/asm-generic/unistd.h it's defined like:
> __SYSCALL(__NR_ptrace, sys_ptrace)
> So we change it to __SC_COMP(__NR_ptrace, sys_ptrace, compat_sys_ptrace),
> let compat tasks use the compat_sys_ptrace.
> 
> Signed-off-by: Zhou Chengming <zhouchengmi...@huawei.com>
> ---
>  include/uapi/asm-generic/unistd.h |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/include/uapi/asm-generic/unistd.h
> b/include/uapi/asm-generic/unistd.h
> index 2862d2e..50ee770 100644
> --- a/include/uapi/asm-generic/unistd.h
> +++ b/include/uapi/asm-generic/unistd.h
> @@ -364,7 +364,7 @@ __SC_WRAP(__NR_syslog, sys_syslog)
> 
>  /* kernel/ptrace.c */
>  #define __NR_ptrace 117
> -__SYSCALL(__NR_ptrace, sys_ptrace)
> +__SC_COMP(__NR_ptrace, sys_ptrace, compat_sys_ptrace)
> 
>  /* kernel/sched/core.c */
>  #define __NR_sched_setparam 118
> -- 
> 1.7.7
> 

Hi Zhou,

Thank you for the catch.

Could you also show the test that is failed for you. It should
probably be sent to LTP maillist.

I'm not sure your fix correct as it affects other architectures that
use standard unistd.h. I think it's better to redirect the syscall in
arch/arm64/kernel/sys_ilp32.c with corresponding definition.

Yury
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/23] all: syscall wrappers: add documentation

2016-05-27 Thread Yury Norov
On Fri, May 27, 2016 at 02:04:47PM +0100, Catalin Marinas wrote:
> On Fri, May 27, 2016 at 12:49:11PM +0200, Arnd Bergmann wrote:
> > On Friday, May 27, 2016 10:30:52 AM CEST Catalin Marinas wrote:
> > > On Fri, May 27, 2016 at 10:42:59AM +0200, Arnd Bergmann wrote:
> > > > On Friday, May 27, 2016 8:03:57 AM CEST Heiko Carstens wrote:
> > > > > > > > > Cost wise, this seems like it all cancels out in the end, but 
> > > > > > > > > what
> > > > > > > > > do I know?
> > > > > > > > 
> > > > > > > > I think you know something, and I also think Heiko and other 
> > > > > > > > s390 guys
> > > > > > > > know something as well. So I'd like to listen their arguments 
> > > > > > > > here.
> > > > > 
> > > > > If it comes to 64 bit arguments for compat system calls: s390 also 
> > > > > has an
> > > > > x32-like ABI extension which allows user space to use full 64 bit
> > > > > registers. As far as I know hardly anybody ever made use of that.
> > > > > 
> > > > > However even if that would be widely used, to me it wouldn't make 
> > > > > sense to
> > > > > add new compat system calls which allow 64 bit arguments, simply 
> > > > > because
> > > > > something like
> > > > > 
> > > > > c = (u32)a | (u64)b << 32;
> > > > > 
> > > > > can be done with a single 1-cycle instruction. It's just not worth the
> > > > > extra effort to maintain additional system call variants.
> > > > 
> > > > For reference, both tile and mips also have separate 32-bit ABIs that 
> > > > are
> > > > only used on 64-bit kernels (aside from the normal 32-bit ABI). Tile
> > > > does it like s390 and passes 64-bit arguments as pairs, while MIPS
> > > > and x86 and pass them as single registers.
> > > 
> > > AFAIK, x32 also requires that the upper half of a 64-bit reg is zeroed
> > > by the user when a 32-bit value is passed. We could require the same on
> > > AArch64/ILP32 but I'm a bit uneasy on trusting a multitude of C
> > > libraries on this.
> > 
> > It's not about trusting a C library, it's about ensuring malicious code
> > cannot pass argumentst that the kernel code assumes will never happen.
> 
> At least for pointers and sizes, we have additional checks in place
> already, like __access_ok(). Most of the syscalls should be safe since
> they either go through some compat functions taking 32-bit arguments or
> are routed to native functions which already need to cope with a full
> random 64-bit value.

It's not a good idea to rely on current implementation. Implementation
may be changed and it's impossible to check each and every patch
against register top-halves correctness.

> 
> On arm64, I think the only risk comes from syscall handlers expecting
> 32-bit arguments but using 64-bit types. Apart from pointer types, I
> don't expect this to happen but we could enforce it via a
> BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)) in __SC_DELOUSE as per
> the s390 implementation. With ILP32 if we go for 64-bit off_t, those
> syscalls would be routed directly to the native layer.
> 

64-bit off_t doesn't imply we'd rout it directly. At first glance it's
looking reasonable but there are other considerations like simplicity and
unification with aarch32 that may become more important. That's what
David pointed out.

So, we have 3 options for now:
1. Clear top halves in entry.S which means we pass off_t as a pair.
   The cost is performance (didn't measure it yet and doubt about it
   makes serious impact). The advantage is simplicity and unification with
   aarch32, as I mentioned above. And David likes it. And it mininizes
   the amount of changes on glibc side.
2. Clear top halves in in separated file hosted wrappers.
3. Clear top halves in I-cache and tail optimization friendly in-site wrappers.

2 and 3 are the same from ABI point of view.

2 is the worst for me as it is the most complex in implementation and 
I-cache and tail optimization non-friendly. But Heiko likes it.
 
3 is what Catalin is talking about, and it was my initial approach.
Though I didn't made compiler to do tail optimization, I think we can
do it.

But 2 is what we have now. And I'd choose it. We'll never get ilp32 done
if will roll back previously agreed decisions again and again.

Yury.

> -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-05-26 Thread Yury Norov
ze = sizeof(compat_a32_elf_greg_t),
> + .align = sizeof(compat_a32_elf_greg_t),
>   .get = compat_gpr_get,
>   .set = compat_gpr_set
>   },
> @@ -947,7 +947,7 @@ static int compat_ptrace_read_user(struct task_struct 
> *tsk, compat_ulong_t off,
>   tmp = tsk->mm->start_data;
>   else if (off == COMPAT_PT_TEXT_END_ADDR)
>   tmp = tsk->mm->end_code;
> - else if (off < sizeof(compat_elf_gregset_t))
> + else if (off < sizeof(compat_a32_elf_gregset_t))
>   return copy_regset_to_user(tsk, _aarch32_view,
>  REGSET_COMPAT_GPR, off,
>  sizeof(compat_ulong_t), ret);
> @@ -968,7 +968,7 @@ static int compat_ptrace_write_user(struct task_struct 
> *tsk, compat_ulong_t off,
>   if (off & 3 || off >= COMPAT_USER_SZ)
>   return -EIO;
> 
> - if (off >= sizeof(compat_elf_gregset_t))
> + if (off >= sizeof(compat_a32_elf_gregset_t))
>   return 0;
> 
>   set_fs(KERNEL_DS);
> @@ -1116,9 +1116,11 @@ static long compat_a32_ptrace(struct task_struct 
> *child, compat_long_t request,
>   unsigned long addr = caddr;
>   unsigned long data = cdata;
>   void __user *datap = compat_ptr(data);
> + unsigned int pr_reg_size = sizeof(compat_a32_elf_gregset_t);
>   int ret;
> 
>   switch (request) {
> +
>   case PTRACE_PEEKUSR:
>   ret = compat_ptrace_read_user(child, addr, datap);
>   break;
> @@ -1130,17 +1132,15 @@ static long compat_a32_ptrace(struct task_struct 
> *child, compat_long_t request,
>   case COMPAT_PTRACE_GETREGS:
>   ret = copy_regset_to_user(child,
> _aarch32_view,
> -   REGSET_COMPAT_GPR,
> -   0, 
> sizeof(compat_elf_gregset_t),
> -   datap);
> +   REGSET_COMPAT_GPR, 0,
> +   pr_reg_size, datap);
>   break;
> 
>   case COMPAT_PTRACE_SETREGS:
>   ret = copy_regset_from_user(child,
>   _aarch32_view,
> - REGSET_COMPAT_GPR,
> - 0, 
> sizeof(compat_elf_gregset_t),
> - datap);
> + REGSET_COMPAT_GPR, 0,
> + pr_reg_size, datap);
>   break;
> 
>   case COMPAT_PTRACE_GET_THREAD_AREA:
> -- 
> 1.8.4.5
> 
> 
> On 2016/5/24 8:04, Yury Norov wrote:
> >to handle ILP32 binaries
> >
> >Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
> >---
> >  arch/arm64/kernel/Makefile   |  1 +
> >  arch/arm64/kernel/binfmt_ilp32.c | 91 
> > 
> >  2 files changed, 92 insertions(+)
> >  create mode 100644 arch/arm64/kernel/binfmt_ilp32.c
> >
> >diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> >index 6bc9738..9dfdf86 100644
> >--- a/arch/arm64/kernel/Makefile
> >+++ b/arch/arm64/kernel/Makefile
> >@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
> >  arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
> > \
> >sys_compat.o entry32.o   
> > \
> >../../arm/kernel/opcodes.o 
> > binfmt_elf32.o
> >+arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o
> >  arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
> >  arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
> >  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
> >diff --git a/arch/arm64/kernel/binfmt_ilp32.c 
> >b/arch/arm64/kernel/binfmt_ilp32.c
> >new file mode 100644
> >index 000..a934fd4
> >--- /dev/null
> >+++ b/arch/arm64/kernel/binfmt_ilp32.c
> >@@ -0,0 +1,91 @@
> >+/*
> >+ * Support for ILP32 Linux/aarch64 ELF binaries.
> >+ */
> >+
> >+#include 
> >+#include 
> >+
> >+#undef  ELF_CLASS
> >+#define ELF_CLASS   ELFCLASS32
> >+
> >+#undef  elfhdr
> >+#undef  elf_phdr
> >+#undef  elf_shdr

Re: [PATCH 01/23] all: syscall wrappers: add documentation

2016-05-26 Thread Yury Norov
On Wed, May 25, 2016 at 02:28:21PM -0700, David Miller wrote:
> From: Arnd Bergmann 
> Date: Wed, 25 May 2016 23:01:06 +0200
> 
> > On Wednesday, May 25, 2016 1:50:39 PM CEST David Miller wrote:
> >> From: Arnd Bergmann 
> >> Date: Wed, 25 May 2016 22:47:33 +0200
> >> 
> >> > If we use the normal calling conventions, we could remove these overrides
> >> > along with the respective special-case handling in glibc. None of them
> >> > look particularly performance-sensitive, but I could be wrong there.
> >> 
> >> You could set the lowest bit in the system call entry pointer to indicate
> >> the upper-half clears should be elided.
> > 
> > Right, but that would introduce an extra conditional branch in the syscall
> > hotpath, and likely eliminate the gains from passing the loff_t arguments
> > in a single register instead of a pair.
> 
> Ok, then, how much are you really gaining from avoiding a 'shift' and
> an 'or' to build the full 64-bit value?  3 cycles?  Maybe 4?

4 cycles in kernel and ~same cost in glibc to create a pair. And 8
'mov's that exist for every syscall, even yield().

> And the executing the wrappers, those have a non-trivial cost too.

The cost is pretty trivial though. See kernel/compat_wrapper.o:
COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
0:   a9bf7bfdstp x29, x30, [sp,#-16]!
4:   910003fdmov x29, sp
8:   2a0003e0mov w0, w0
c:   9400bl  0 
10:  a8c17bfdldp x29, x30, [sp],#16
14:  d65f03c0ret

> Cost wise, this seems like it all cancels out in the end, but what
> do I know?

I think you know something, and I also think Heiko and other s390 guys
know something as well. So I'd like to listen their arguments here.

For me spark64 way is looking reasonable only because it's really simple
and takes less coding. I'll try it on some branch and share here what happened.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/23] all: syscall wrappers: add documentation

2016-05-25 Thread Yury Norov
On Wed, May 25, 2016 at 12:30:17PM -0700, David Miller wrote:
> From: Yury Norov <yno...@caviumnetworks.com>
> Date: Tue, 24 May 2016 03:04:30 +0300
> 
> > +To clear that top halves, automatic wrappers are introduced. They clear all
> > +required registers before passing control to regular syscall handler.
> 
> Why have one of these for every single compat system call, rather than
> simply clearing the top half of all of these registers unconditionally
> in the 32-bit system call trap before the system call is invoked?
> 
> That's what we do on sparc64.
> 
> And with that, you only need wrappers for the case where there needs
> to be proper sign extention of a 32-bit signed argument.

It was discussed as one of possible solutions. The downside of it is
that we cannot pass 64-bit types (like off_t) in single register.
The other downside is that we clear top halves for every single
syscall, and it looks excessive. So, from spark64 and s390 approaches
we choosed second.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/23] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-05-23 Thread Yury Norov
Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/include/asm/compat.h  | 19 ++--
 arch/arm64/include/asm/elf.h | 10 +++
 arch/arm64/include/asm/ftrace.h  |  2 +-
 arch/arm64/include/asm/is_compat.h   | 58 
 arch/arm64/include/asm/memory.h  |  3 +-
 arch/arm64/include/asm/processor.h   |  5 ++--
 arch/arm64/include/asm/syscall.h |  2 +-
 arch/arm64/include/asm/thread_info.h |  2 +-
 arch/arm64/kernel/hw_breakpoint.c| 10 +++
 arch/arm64/kernel/perf_regs.c|  2 +-
 arch/arm64/kernel/process.c  |  7 ++---
 arch/arm64/kernel/ptrace.c   | 11 ---
 arch/arm64/kernel/signal.c   |  4 +--
 arch/arm64/kernel/traps.c|  3 +-
 14 files changed, 91 insertions(+), 47 deletions(-)
 create mode 100644 arch/arm64/include/asm/is_compat.h

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index eb8432b..df2f72d 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -24,6 +24,8 @@
 #include 
 #include 
 
+#include 
+
 #define COMPAT_USER_HZ 100
 #ifdef __AARCH64EB__
 #define COMPAT_UTS_MACHINE "armv8b\0\0"
@@ -298,23 +300,6 @@ struct compat_shmid64_ds {
compat_ulong_t __unused5;
 };
 
-static inline int is_compat_task(void)
-{
-   return test_thread_flag(TIF_32BIT);
-}
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return test_ti_thread_flag(thread, TIF_32BIT);
-}
-
-#else /* !CONFIG_COMPAT */
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return 0;
-}
-
 #endif /* CONFIG_COMPAT */
 #endif /* __KERNEL__ */
 #endif /* __ASM_COMPAT_H */
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 24ed037..b5437c5 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -16,6 +16,10 @@
 #ifndef __ASM_ELF_H
 #define __ASM_ELF_H
 
+#ifndef __ASSEMBLY__
+#include 
+#endif
+
 #include 
 
 /*
@@ -152,13 +156,9 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
   int uses_interp);
 
 /* 1GB of VA */
-#ifdef CONFIG_COMPAT
-#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+#define STACK_RND_MASK (is_compat_task() ? \
0x7ff >> (PAGE_SHIFT - 12) : \
0x3 >> (PAGE_SHIFT - 12))
-#else
-#define STACK_RND_MASK (0x3 >> (PAGE_SHIFT - 12))
-#endif
 
 #ifdef CONFIG_COMPAT
 
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index caa955f..0feb28a 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -54,7 +54,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long 
addr)
 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
 {
-   return is_compat_task();
+   return is_a32_compat_task();
 }
 #endif /* ifndef __ASSEMBLY__ */
 
diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
new file mode 100644
index 000..6139b5a
--- /dev/null
+++ b/arch/arm64/include/asm/is_compat.h
@@ -0,0 +1,58 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_IS_COMPAT_H
+#define __ASM_IS_COMPAT_H
+#ifndef __ASSEMBLY__
+
+#include 
+
+#ifdef CONFIG_AARCH32_EL0
+
+static inline int is_a32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT);
+}
+
+static inline int is_a32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT);
+}
+
+#else
+
+static inline int is_a32_compat_task(void)
+
+

[PATCH 10/23] arm64: rename COMPAT to AARCH32_EL0 in Kconfig

2016-05-23 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

In this patchset  ILP32 ABI support is added. Additionally to AARCH32,
which is binary-compatible with ARM, ILP32 is (mostly) ABI-compatible.

>From now, AARCH32_EL0 (former COMPAT) config option means the support of
AARCH32 userspace, ARM64_ILP32 - support of ILP32 ABI (see next patches),
and COMPAT indicates that one of them, or both, is enabled.

Where needed, CONFIG_COMPAT is changed over to use CONFIG_AARCH32_EL0 instead

Reviewed-by: David Daney <dda...@caviumnetworks.com>
Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@linaro.org>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/Kconfig   | 9 +++--
 arch/arm64/include/asm/fpsimd.h  | 2 +-
 arch/arm64/include/asm/hwcap.h   | 4 ++--
 arch/arm64/include/asm/processor.h   | 6 +++---
 arch/arm64/include/asm/ptrace.h  | 2 +-
 arch/arm64/include/asm/signal32.h| 6 --
 arch/arm64/include/asm/unistd.h  | 2 +-
 arch/arm64/kernel/Makefile   | 2 +-
 arch/arm64/kernel/asm-offsets.c  | 2 +-
 arch/arm64/kernel/cpufeature.c   | 8 
 arch/arm64/kernel/cpuinfo.c  | 4 ++--
 arch/arm64/kernel/entry.S| 6 +++---
 arch/arm64/kernel/head.S | 2 +-
 arch/arm64/kernel/ptrace.c   | 8 
 arch/arm64/kernel/traps.c| 2 +-
 arch/arm64/kernel/vdso.c | 4 ++--
 drivers/clocksource/arm_arch_timer.c | 2 +-
 17 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 4f43622..ede9b2e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -370,7 +370,7 @@ config ARM64_ERRATUM_834220
 
 config ARM64_ERRATUM_845719
bool "Cortex-A53: 845719: a load might read incorrect data"
-   depends on COMPAT
+   depends on AARCH32_EL0
default y
help
  This option adds an alternative code sequence to work around ARM
@@ -655,7 +655,7 @@ config FORCE_MAX_ZONEORDER
 
 menuconfig ARMV8_DEPRECATED
bool "Emulate deprecated/obsolete ARMv8 instructions"
-   depends on COMPAT
+   depends on AARCH32_EL0
help
  Legacy software support may require certain instructions
  that have been deprecated or obsoleted in the architecture.
@@ -925,7 +925,12 @@ menu "Userspace binary formats"
 source "fs/Kconfig.binfmt"
 
 config COMPAT
+   bool
+   depends on AARCH32_EL0
+
+config AARCH32_EL0
bool "Kernel support for 32-bit EL0"
+   def_bool y
depends on ARM64_4K_PAGES || EXPERT
select COMPAT_BINFMT_ELF
select HAVE_UID16
diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h
index 50f559f..63b19f1 100644
--- a/arch/arm64/include/asm/fpsimd.h
+++ b/arch/arm64/include/asm/fpsimd.h
@@ -52,7 +52,7 @@ struct fpsimd_partial_state {
 };
 
 
-#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
+#if defined(__KERNEL__) && defined(CONFIG_AARCH32_EL0)
 /* Masks for extracting the FPSR and FPCR from the FPSCR */
 #define VFP_FPSCR_STAT_MASK0xf89f
 #define VFP_FPSCR_CTRL_MASK0x07f79f00
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 400b80b..2c7fc5d 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -46,7 +46,7 @@
  */
 #define ELF_HWCAP  (elf_hwcap)
 
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
 #define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
 #define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
 extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
@@ -54,7 +54,7 @@ extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
 
 enum {
CAP_HWCAP = 1,
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
CAP_COMPAT_HWCAP,
CAP_COMPAT_HWCAP2,
 #endif
diff --git a/arch/arm64/include/asm/processor.h 
b/arch/arm64/include/asm/processor.h
index cef1cf3..5bbdbb4 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -81,7 +81,7 @@ struct cpu_context {
 struct thread_struct {
struct cpu_context  cpu_context;/* cpu context */
unsigned long   tp_value;   /* TLS register */
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
unsigned long   tp2_value;
 #endif
struct fpsimd_state fpsimd_state;
@@ -90,7 +90,7 @@ struct thread_struct {
struct debug_info   debug;  /* debugging */
 };
 
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
 #define task_user_tls(t)   \
 ({ \
unsigned long *__tls;

[PATCH 05/23] all: wrap needed syscalls in generic unistd

2016-05-23 Thread Yury Norov
As generic unistd syscall table is written in C, syscall
prototypes declaration is needed. It's added to compat header.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 include/linux/compat.h| 225 +
 include/uapi/asm-generic/unistd.h | 227 +++---
 2 files changed, 338 insertions(+), 114 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index 4eba16e..248e015 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -789,6 +789,231 @@ asmlinkage long notrace 
compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))
 }
 #endif
 
+/* Compat wrappers */
+#include 
+asmlinkage long compat_sys_creat(const char __user *pathname, umode_t mode);
+asmlinkage long compat_sys_link(const char __user *oldname,
+   const char __user *newname);
+asmlinkage long compat_sys_chdir(const char __user *filename);
+asmlinkage long compat_sys_mknod(const char __user *filename, umode_t mode,
+   unsigned dev);
+asmlinkage long compat_sys_chmod(const char __user *filename, umode_t mode);
+asmlinkage long compat_sys_oldumount(char __user *name);
+asmlinkage long compat_sys_access(const char __user *filename, int mode);
+asmlinkage long compat_sys_rename(const char __user *oldname,
+   const char __user *newname);
+asmlinkage long compat_sys_mkdir(const char __user *pathname, umode_t mode);
+asmlinkage long compat_sys_rmdir(const char __user *pathname);
+asmlinkage long compat_sys_pipe(int __user *fildes);
+asmlinkage long compat_sys_brk(unsigned long brk);
+asmlinkage long compat_sys_signal(int sig, __sighandler_t handler);
+asmlinkage long compat_sys_acct(const char __user *name);
+asmlinkage long compat_sys_umount(char __user *name, int flags);
+asmlinkage long compat_sys_chroot(const char __user *filename);
+
+#ifdef CONFIG_OLD_SIGSUSPEND
+asmlinkage long compat_sys_sigsuspend(old_sigset_t mask);
+#endif
+
+#ifdef CONFIG_OLD_SIGSUSPEND3
+asmlinkage long compat_sys_sigsuspend(int unused1, int unused2, old_sigset_t 
mask);
+#endif
+
+asmlinkage long compat_sys_sethostname(char __user *name, int len);
+asmlinkage long compat_sys_symlink(const char __user *old, const char __user 
*new);
+asmlinkage long compat_sys_readlink(const char __user *path,
+   char __user *buf, int bufsiz);
+asmlinkage long compat_sys_uselib(const char __user *library);
+asmlinkage long compat_sys_swapon(const char __user *specialfile, int 
swap_flags);
+asmlinkage long compat_sys_reboot(int magic1, int magic2, unsigned int cmd,
+   void __user *arg);
+asmlinkage long compat_sys_munmap(unsigned long addr, size_t len);
+asmlinkage long compat_sys_munmap(unsigned long addr, size_t len);
+asmlinkage long compat_sys_syslog(int type, char __user *buf, int len);
+asmlinkage long compat_sys_swapoff(const char __user *specialfile);
+asmlinkage long compat_sys_setdomainname(char __user *name, int len);
+asmlinkage long compat_sys_newuname(struct new_utsname __user *name);
+asmlinkage long compat_sys_mprotect(unsigned long start, size_t len,
+   unsigned long prot);
+asmlinkage long compat_sys_init_module(void __user *umod, unsigned long len,
+   const char __user *uargs);
+asmlinkage long compat_sys_delete_module(const char __user *name_user,
+   unsigned int flags);
+asmlinkage long compat_sys_quotactl(unsigned int cmd, const char __user 
*special,
+   qid_t id, void __user *addr);
+asmlinkage long compat_sys_bdflush(int func, long data);
+asmlinkage long compat_sys_sysfs(int option,
+   unsigned long arg1, unsigned long arg2);
+asmlinkage long compat_sys_llseek(unsigned int fd, unsigned long offset_high,
+   unsigned long offset_low, loff_t __user *result,
+   unsigned int whence);
+asmlinkage long compat_sys_msync(unsigned long start, size_t len, int flags);
+asmlinkage long compat_sys_mlock(unsigned long start, size_t len);
+asmlinkage long compat_sys_munlock(unsigned long start, size_t len);
+asmlinkage long compat_sys_sched_setparam(pid_t pid,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_sched_getparam(pid_t pid,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_sched_setscheduler(pid_t pid, int policy,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_mremap(unsigned long addr,
+  unsigned long old_len, unsigned long new_len,
+  unsigned long flags, unsigned long new_addr);
+asmlinkage long compat_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
+   int timeout);
+asmlinkag

[PATCH 04/23] all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/

2016-05-23 Thread Yury Norov
Some syscalls are declared conditionally, so corresponding wrappers
are conditional accordingly.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/s390/kernel/Makefile |   2 +-
 arch/s390/kernel/compat_linux.c   |   4 +
 arch/s390/kernel/compat_wrapper.c | 129 
 kernel/Makefile   |   1 +
 kernel/compat_wrapper.c   | 175 ++
 5 files changed, 181 insertions(+), 130 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
 create mode 100644 kernel/compat_wrapper.c

diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 2f5586a..145d3d8 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -57,7 +57,7 @@ obj-$(CONFIG_HIBERNATION) += suspend.o swsusp.o
 obj-$(CONFIG_AUDIT)+= audit.o
 compat-obj-$(CONFIG_AUDIT) += compat_audit.o
 obj-$(CONFIG_COMPAT)   += compat_linux.o compat_signal.o
-obj-$(CONFIG_COMPAT)   += compat_wrapper.o $(compat-obj-y)
+obj-$(CONFIG_COMPAT)   += $(compat-obj-y)
 
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_KPROBES)  += kprobes.o
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index 437e611..783c208 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -86,6 +86,10 @@
 #define SET_STAT_UID(stat, uid)(stat).st_uid = high2lowuid(uid)
 #define SET_STAT_GID(stat, gid)(stat).st_gid = high2lowgid(gid)
 
+COMPAT_SYSCALL_WRAP3(s390_pci_mmio_write, const unsigned long, mmio_addr, 
const void __user *, user_buffer, const size_t, length);
+
+COMPAT_SYSCALL_WRAP3(s390_pci_mmio_read, const unsigned long, mmio_addr, void 
__user *, user_buffer, const size_t, length);
+
 COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
   u16, user, u16, group)
 {
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
deleted file mode 100644
index 1614e15..000
--- a/arch/s390/kernel/compat_wrapper.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *  Compat system call wrappers.
- *
- *Copyright IBM Corp. 2014
- */
-
-#include 
-#include 
-#include "entry.h"
-
-COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, 
newname);
-COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(chdir, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(mknod, const char __user *, filename, umode_t, mode, 
unsigned, dev);
-COMPAT_SYSCALL_WRAP2(chmod, const char __user *, filename, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(oldumount, char __user *, name);
-COMPAT_SYSCALL_WRAP2(access, const char __user *, filename, int, mode);
-COMPAT_SYSCALL_WRAP2(rename, const char __user *, oldname, const char __user 
*, newname);
-COMPAT_SYSCALL_WRAP2(mkdir, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(rmdir, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(pipe, int __user *, fildes);
-COMPAT_SYSCALL_WRAP1(brk, unsigned long, brk);
-COMPAT_SYSCALL_WRAP2(signal, int, sig, __sighandler_t, handler);
-COMPAT_SYSCALL_WRAP1(acct, const char __user *, name);
-COMPAT_SYSCALL_WRAP2(umount, char __user *, name, int, flags);
-COMPAT_SYSCALL_WRAP1(chroot, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(sigsuspend, int, unused1, int, unused2, old_sigset_t, 
mask);
-COMPAT_SYSCALL_WRAP2(sethostname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP2(symlink, const char __user *, old, const char __user *, 
new);
-COMPAT_SYSCALL_WRAP3(readlink, const char __user *, path, char __user *, buf, 
int, bufsiz);
-COMPAT_SYSCALL_WRAP1(uselib, const char __user *, library);
-COMPAT_SYSCALL_WRAP2(swapon, const char __user *, specialfile, int, 
swap_flags);
-COMPAT_SYSCALL_WRAP4(reboot, int, magic1, int, magic2, unsigned int, cmd, void 
__user *, arg);
-COMPAT_SYSCALL_WRAP2(munmap, unsigned long, addr, size_t, len);
-COMPAT_SYSCALL_WRAP3(syslog, int, type, char __user *, buf, int, len);
-COMPAT_SYSCALL_WRAP1(swapoff, const char __user *, specialfile);
-COMPAT_SYSCALL_WRAP2(setdomainname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP1(newuname, struct new_utsname __user *, name);
-COMPAT_SYSCALL_WRAP3(mprotect, unsigned long, start, size_t, len, unsigned 
long, prot);
-COMPAT_SYSCALL_WRAP3(init_module, void __user *, umod, unsigned long, len, 
const char __user *, uargs);
-COMPAT_SYSCALL_WRAP2(delete_module, const char __user *, name_user, unsigned 
int, flags);
-COMPAT_SYSCALL_WRAP4(quotactl, unsigned int, cmd, const char __user *, 
special, qid_t, id, void __user *, addr);
-COMPAT_SYSCALL_WRAP2(bdflush, int, func, long, data);
-COMPAT_SYSCALL_WRAP3(sysfs, int, option, unsigned long, arg1, unsigned long, 
arg2);
-COMPAT_SYSCALL_WRAP5(llseek, unsigned int, fd, unsigned long, high, unsigned 
long, lo

[PATCH 01/23] all: syscall wrappers: add documentation

2016-05-23 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 Documentation/adding-syscalls.txt | 32 
 1 file changed, 32 insertions(+)

diff --git a/Documentation/adding-syscalls.txt 
b/Documentation/adding-syscalls.txt
index cc2d4ac..d02a6bd 100644
--- a/Documentation/adding-syscalls.txt
+++ b/Documentation/adding-syscalls.txt
@@ -341,6 +341,38 @@ To summarize, you need:
  - instance of __SC_COMP not __SYSCALL in include/uapi/asm-generic/unistd.h
 
 
+Compatibility System Calls Wrappers
+
+
+Some architectures prevent 32-bit userspace from access to top halves of 64-bit
+registers, but some not. It's not a problem if specific argument is the same
+size in kernel and userspace. It also is not a problem if system call is 
already
+handled by compatible routine. Otherwise we'd take care of it. Usually, glibc
+and compiler handles register's top halve, but from kernel side, we cannot rely
+on it, as malicious code may cause incorrect behaviour and/or security
+vulnerabilities.
+
+For now, only s390 and arm64/ilp32 are affected.
+
+To clear that top halves, automatic wrappers are introduced. They clear all
+required registers before passing control to regular syscall handler.
+
+If your architecture allows userspace code to access top halves of register,
+you need to:
+ - enable COMPAT_WRAPPER in configuration file;
+ - declare: "#define __SC_WRAP(nr, sym) [nr] = compat_##sym,", just before
+   compatible syscall table declaration, if you use generic unistd; or
+ - declare compat wrappers manually, if you use non-generic syscall table.
+   The list of unsafe syscalls is in kernel/compat_wrapper.
+
+If you write new syscall, make sure, its arguments are the same size in both
+64- and 32-bits modes. If no, and if there's no explicit compat version for
+syscall handler, you need to:
+ - declare compat version prototype in 'include/linux/compat.h';
+ - in 'include/uapi/asm-generic/unistd.h' declare syscall with macro 
'__SC_WRAP'
+   instead of '__SYSCALL';
+ - add corresponding line to 'kernel/compat_wrapper.c' to let it generate 
wrapper.
+
 Compatibility System Calls (x86)
 
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/23] all: introduce COMPAT_WRAPPER option and enable it for s390

2016-05-23 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/Kconfig  | 4 
 arch/s390/Kconfig | 1 +
 2 files changed, 5 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index 81869a5..92fcbd4 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -589,6 +589,10 @@ config HAVE_STACK_VALIDATION
  Architecture supports the 'objtool check' host tool command, which
  performs compile-time stack metadata validation.
 
+config COMPAT_WRAPPER
+   bool
+   depends on COMPAT
+
 #
 # ABI hall of shame
 #
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index bf24ab1..6d643b3 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -340,6 +340,7 @@ config COMPAT
select COMPAT_BINFMT_ELF if BINFMT_ELF
select ARCH_WANT_OLD_COMPAT_IPC
select COMPAT_OLD_SIGACTION
+   select COMPAT_WRAPPER
depends on MULTIUSER
help
  Select this option if you want to enable your system kernel to
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 00/21] ILP32 for ARM64

2016-05-23 Thread Yury Norov
This series enables aarch64 with ilp32 mode, and as supporting work,
introduces compat wrappers based on s390 solution, and also introduces
ARCH_32BIT_OFF_T configuration option that is enabled for existing
32-bit architectures but disabled for new arches (so 64-bit off_t is 
is used by new userspace).

This version is based on kernel v4.6.
It works with glibc-2.23, and tested with LTP.

It was tested on QEMU and ThunderX machines. No major differences found.

This is not RFC anymore, because ILP32 is now tested in big-endian mode;
signals, vDSO and other subsystems are tested, and look working

 v3: https://lkml.org/lkml/2014/9/3/704
 v4: https://lkml.org/lkml/2015/4/13/691
 v5: https://lkml.org/lkml/2015/9/29/911
 v6: ABI reworked significantly;
- syscall input arguments are deloused with compat wrappers;
- vDSO is now working for both BE and LE;
- signal subsystem is reworked to handle signal context properly;
- binfmt_elf is reworked, and now most of places where execution mode
  should be detected, are handled statically;
- many other less-important fixes.

ILP32 glibc branch is available here:
https://github.com/norov/glibc/tree/ilp32-2.23

It is tested with this series with no major downsides. I will send it to 
glibc-alpha soon, after final revise. Please review and comment it as well.

Andrew Pinski (6):
  arm64: ensure the kernel is compiled for LP64
  arm64: rename COMPAT to AARCH32_EL0 in Kconfig
  arm64:uapi: set __BITS_PER_LONG correctly for ILP32 and LP64
  arm64: ilp32: add sys_ilp32.c and a separate table (in entry.S) to use
it
  arm64: ilp32: introduce ilp32-specific handlers for sigframe and
ucontext
  arm64:ilp32: add ARM64_ILP32 to Kconfig

Philipp Tomsich (1):
  arm64:ilp32: add vdso-ilp32 and use for signal return

Yury Norov (15):
  all: introduce COMPAT_WRAPPER option and enable it for s390
  all: s390: move wrapper infrastructure to generic headers
  all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/
  all: wrap needed syscalls in generic unistd
  compat ABI: use non-compat openat and open_by_handle_at variants
  32-bit ABI: introduce ARCH_32BIT_OFF_T config option
  arm64: ilp32: add documentation on the ILP32 ABI for ARM64
  thread: move thread bits accessors to separated file
  arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)
  arm64: ilp32: add is_ilp32_compat_{task,thread} and TIF_32BIT_AARCH64
  arm64: introduce binfmt_elf32.c
  arm64: ilp32: introduce binfmt_ilp32.c
  arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32
  arm64: signal: share lp64 signal routines to ilp32
  arm64: signal32: move ilp32 and aarch32 common code to separated file

 Documentation/arm64/ilp32.txt |  25 +++
 arch/Kconfig  |   8 +
 arch/arc/Kconfig  |   1 +
 arch/arm/Kconfig  |   1 +
 arch/arm64/Kconfig|  20 +-
 arch/arm64/Makefile   |   5 +
 arch/arm64/include/asm/compat.h   |  19 +-
 arch/arm64/include/asm/elf.h  |  35 +---
 arch/arm64/include/asm/fpsimd.h   |   2 +-
 arch/arm64/include/asm/ftrace.h   |   2 +-
 arch/arm64/include/asm/hwcap.h|   6 +-
 arch/arm64/include/asm/is_compat.h|  84 
 arch/arm64/include/asm/memory.h   |   3 +-
 arch/arm64/include/asm/processor.h|  11 +-
 arch/arm64/include/asm/ptrace.h   |   2 +-
 arch/arm64/include/asm/signal32.h |   6 +-
 arch/arm64/include/asm/signal32_common.h  |  25 +++
 arch/arm64/include/asm/signal_common.h|  33 +++
 arch/arm64/include/asm/signal_ilp32.h |  34 
 arch/arm64/include/asm/syscall.h  |   2 +-
 arch/arm64/include/asm/thread_info.h  |   4 +-
 arch/arm64/include/asm/unistd.h   |  11 +-
 arch/arm64/include/asm/unistd32.h |   2 +-
 arch/arm64/include/asm/vdso.h |   6 +
 arch/arm64/include/uapi/asm/bitsperlong.h |   9 +-
 arch/arm64/kernel/Makefile|  14 +-
 arch/arm64/kernel/asm-offsets.c   |   9 +-
 arch/arm64/kernel/binfmt_elf32.c  |  33 +++
 arch/arm64/kernel/binfmt_ilp32.c  |  91 +
 arch/arm64/kernel/cpufeature.c|   8 +-
 arch/arm64/kernel/cpuinfo.c   |   4 +-
 arch/arm64/kernel/entry.S |  16 +-
 arch/arm64/kernel/entry_ilp32.S   |  23 +++
 arch/arm64/kernel/head.S  |   2 +-
 arch/arm64/kernel/hw_breakpoint.c |  10 +-
 arch/arm64/kernel/perf_regs.c |   2 +-
 arch/arm64/kernel/process.c   |   7 +-
 arch/arm64/kernel/ptrace.c|  67 ++-
 arch/arm64/kernel/signal.c| 100 ++
 arch/arm64/kernel/signal32.c  |  85 
 arch/arm64

[PATCH 07/23] 32-bit ABI: introduce ARCH_32BIT_OFF_T config option

2016-05-23 Thread Yury Norov
All new 32-bit architectures should have 64-bit off_t type, but existing
architectures has 32-bit ones.

To handle it, new config option is added to arch/Kconfig that defaults
ARCH_32BIT_OFF_T to be disabled for non-64 bit architectures. All existing
32-bit architectures enable it explicitly here.

New option affects force_o_largefile() behaviour. Namely, if off_t is
64-bits long, we have no reason to reject user to open big files.

Note that even if architectures has only 64-bit off_t in the kernel
(arc, c6x, h8300, hexagon, metag, nios2, openrisc, tile32 and unicore32),
a libc may use 32-bit off_t, and therefore want to limit the file size
to 4GB unless specified differently in the open flags.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/Kconfig| 4 
 arch/arc/Kconfig| 1 +
 arch/arm/Kconfig| 1 +
 arch/blackfin/Kconfig   | 1 +
 arch/cris/Kconfig   | 1 +
 arch/frv/Kconfig| 1 +
 arch/h8300/Kconfig  | 1 +
 arch/hexagon/Kconfig| 1 +
 arch/m32r/Kconfig   | 1 +
 arch/m68k/Kconfig   | 1 +
 arch/metag/Kconfig  | 1 +
 arch/microblaze/Kconfig | 1 +
 arch/mips/Kconfig   | 1 +
 arch/mn10300/Kconfig| 1 +
 arch/nios2/Kconfig  | 1 +
 arch/openrisc/Kconfig   | 1 +
 arch/parisc/Kconfig | 1 +
 arch/powerpc/Kconfig| 1 +
 arch/score/Kconfig  | 1 +
 arch/sh/Kconfig | 1 +
 arch/sparc/Kconfig  | 1 +
 arch/tile/Kconfig   | 1 +
 arch/unicore32/Kconfig  | 1 +
 arch/x86/Kconfig| 1 +
 arch/x86/um/Kconfig | 1 +
 arch/xtensa/Kconfig | 1 +
 include/linux/fcntl.h   | 2 +-
 27 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 92fcbd4..a2b7cf3 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -230,6 +230,10 @@ config ARCH_THREAD_INFO_ALLOCATOR
 config ARCH_WANTS_DYNAMIC_TASK_STRUCT
bool
 
+config ARCH_32BIT_OFF_T
+   bool
+   depends on !64BIT
+
 config HAVE_REGS_AND_STACK_ACCESS_API
bool
help
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index a876743..13f66cc 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -9,6 +9,7 @@
 config ARC
def_bool y
select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC
+   select ARCH_32BIT_OFF_T
select BUILDTIME_EXTABLE_SORT
select COMMON_CLK
select CLONE_BACKWARDS
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index cdfa6c2..efe3ca2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1,6 +1,7 @@
 config ARM
bool
default y
+   select ARCH_32BIT_OFF_T
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_ELF_RANDOMIZE
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index a63c122..ef4368e 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -12,6 +12,7 @@ config RWSEM_XCHGADD_ALGORITHM
 
 config BLACKFIN
def_bool y
+   select ARCH_32BIT_OFF_T
select HAVE_ARCH_KGDB
select HAVE_ARCH_TRACEHOOK
select HAVE_DYNAMIC_FTRACE
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index e086f9e..5bc9203 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -50,6 +50,7 @@ config LOCKDEP_SUPPORT
 config CRIS
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select GENERIC_ATOMIC64
select HAVE_UID16
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index eefd9a4..2f14904 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -1,6 +1,7 @@
 config FRV
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select HAVE_ARCH_TRACEHOOK
select HAVE_PERF_EVENTS
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig
index 986ea84..8c221f1 100644
--- a/arch/h8300/Kconfig
+++ b/arch/h8300/Kconfig
@@ -1,5 +1,6 @@
 config H8300
 def_bool y
+   select ARCH_32BIT_OFF_T
select GENERIC_ATOMIC64
select HAVE_UID16
select VIRT_TO_BUS
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 57298e7..df84602 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -3,6 +3,7 @@ comment "Linux Kernel Configuration for Hexagon"
 
 config HEXAGON
def_bool y
+   select ARCH_32BIT_OFF_T
select HAVE_OPROFILE
# Other pending projects/to-do items.
# select HAVE_REGS_AND_STACK_ACCESS_API
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index c82b292..7866bca 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -1,6 +1,7 @@
 config M32R
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select HAVE_OPROFILE
select INIT_ALL_POSSIBLE
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 498b567..e9897e4 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -1,6 +1,7 @@
 config M68K
bool
default y
+   select ARCH_32BIT_OFF_T
select ARCH_MIGHT_HAVE_PC_PARPORT if IS

[PATCH 03/23] all: s390: move wrapper infrastructure to generic headers

2016-05-23 Thread Yury Norov
This patch moves required calls to generic files to let other arches use
it if needed. Here also, additional code is introduced, as s390 uses asm
syscall tables, while in general case, wrappers may be used in C code.

__SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
unsigned long and pointer types are all 32-bit length.

linux/syscalls_structs.h header is introduced, because from now (see next patch)
structure types listed there are needed for both normal and compat mode.

cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
compat wrappers are enabled.

Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
asm-generated syscall table. But architectures that generate that tables with
C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) 
compat_##name'.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/s390/include/asm/compat.h| 17 +--
 arch/s390/kernel/compat_wrapper.c | 51 -
 include/linux/compat.h| 52 +
 include/linux/syscalls.h  | 57 +
 include/linux/syscalls_structs.h  | 60 +++
 include/uapi/asm-generic/unistd.h |  4 +++
 6 files changed, 132 insertions(+), 109 deletions(-)
 create mode 100644 include/linux/syscalls_structs.h

diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 352f7bd..f412723 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -7,13 +7,26 @@
 #include 
 #include 
 
-#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), 
u64))
-
 #define __SC_DELOUSE(t,v) ({ \
BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
(t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fff) : (v)); \
 })
 
+#define __SC_COMPAT_CAST(t, a) \
+({ \
+   long __ReS = a; \
+   \
+   BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+   if (__TYPE_IS_L(t)) \
+   __ReS = (s32)a; \
+   if (__TYPE_IS_UL(t))\
+   __ReS = (u32)a; \
+   if (__TYPE_IS_PTR(t))   \
+   __ReS = a & 0x7fff; \
+   (t)__ReS;   \
+})
+
 #define PSW32_MASK_PER 0x4000UL
 #define PSW32_MASK_DAT 0x0400UL
 #define PSW32_MASK_IO  0x0200UL
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
index ae2cda5..1614e15 100644
--- a/arch/s390/kernel/compat_wrapper.c
+++ b/arch/s390/kernel/compat_wrapper.c
@@ -8,57 +8,6 @@
 #include 
 #include "entry.h"
 
-#define COMPAT_SYSCALL_WRAP1(name, ...) \
-   COMPAT_SYSCALL_WRAPx(1, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP2(name, ...) \
-   COMPAT_SYSCALL_WRAPx(2, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP3(name, ...) \
-   COMPAT_SYSCALL_WRAPx(3, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP4(name, ...) \
-   COMPAT_SYSCALL_WRAPx(4, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP5(name, ...) \
-   COMPAT_SYSCALL_WRAPx(5, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP6(name, ...) \
-   COMPAT_SYSCALL_WRAPx(6, _##name, __VA_ARGS__)
-
-#define __SC_COMPAT_TYPE(t, a) \
-   __typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
-
-#define __SC_COMPAT_CAST(t, a) \
-({ \
-   long __ReS = a; \
-   \
-   BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
-   if (__TYPE_IS_L(t)) \
-   __ReS = (s32)a; \
-   if (__TYPE_IS_UL(t))\
-   __ReS = (u32)a; \
-   if (__TYPE_IS_PTR(t))   

[PATCH 14/23] arm64: ilp32: add is_ilp32_compat_{task,thread} and TIF_32BIT_AARCH64

2016-05-23 Thread Yury Norov
ILP32 tasks are needed to be distinguished from lp64 and aarch32.
This patch adds helper functions is_ilp32_compat_{task,thread} and
thread flag TIF_32BIT_AARCH64 to address it. This is a preparation
for following patches in ilp32 patchset.

For consistency, SET_PERSONALITY is changed here accordingly.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/include/asm/elf.h | 13 +++--
 arch/arm64/include/asm/is_compat.h   | 28 +++-
 arch/arm64/include/asm/thread_info.h |  2 ++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index b5437c5..e18bb8a 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -142,7 +142,11 @@ typedef struct user_fpsimd_state elf_fpregset_t;
  */
 #define ELF_PLAT_INIT(_r, load_addr)   (_r)->regs[0] = 0
 
-#define SET_PERSONALITY(ex)clear_thread_flag(TIF_32BIT);
+#define SET_PERSONALITY(ex)\
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
 
 #define ARCH_DLINFO\
 do {   \
@@ -181,7 +185,12 @@ typedef compat_elf_greg_t  
compat_elf_gregset_t[COMPAT_ELF_NGREG];
 ((x)->e_flags & EF_ARM_EABI_MASK))
 
 #define compat_start_threadcompat_start_thread
-#define COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
 #define COMPAT_ARCH_DLINFO
 extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
  int uses_interp);
diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
index 6139b5a..55134cf 100644
--- a/arch/arm64/include/asm/is_compat.h
+++ b/arch/arm64/include/asm/is_compat.h
@@ -45,11 +45,37 @@ static inline int is_a32_compat_thread(struct thread_info 
*thread)
 
 #endif /* CONFIG_AARCH32_EL0 */
 
+#ifdef CONFIG_ARM64_ILP32
+
+static inline int is_ilp32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT_AARCH64);
+}
+
+static inline int is_ilp32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT_AARCH64);
+}
+
+#else
+
+static inline int is_ilp32_compat_task(void)
+{
+   return 0;
+}
+
+static inline int is_ilp32_compat_thread(struct thread_info *thread)
+{
+   return 0;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
 #ifdef CONFIG_COMPAT
 
 static inline int is_compat_task(void)
 {
-   return is_a32_compat_task();
+   return is_a32_compat_task() || is_ilp32_compat_task();
 }
 
 #endif /* CONFIG_COMPAT */
diff --git a/arch/arm64/include/asm/thread_info.h 
b/arch/arm64/include/asm/thread_info.h
index 4daa559..8802645 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -119,6 +119,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_RESTORE_SIGMASK20
 #define TIF_SINGLESTEP 21
 #define TIF_32BIT  22  /* AARCH32 process */
+#define TIF_32BIT_AARCH64  23  /* 32 bit process on AArch64(ILP32) */
 
 #define _TIF_SIGPENDING(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED  (1 << TIF_NEED_RESCHED)
@@ -130,6 +131,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_SYSCALL_TRACEPOINT(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SECCOMP   (1 << TIF_SECCOMP)
 #define _TIF_32BIT (1 << TIF_32BIT)
+#define _TIF_32BIT_AARCH64 (1 << TIF_32BIT_AARCH64)
 
 #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
 _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE)
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/23] arm64: introduce binfmt_elf32.c

2016-05-23 Thread Yury Norov
As we support more than one compat formats, it looks more reasonable
to not use fs/compat_binfmt.c. Custom binfmt_elf32.c allows to move aarch32
specific definitions there and make code more maintainable and readable.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/Kconfig   |  1 -
 arch/arm64/include/asm/elf.h | 24 
 arch/arm64/include/asm/hwcap.h   |  2 --
 arch/arm64/kernel/Makefile   |  2 +-
 arch/arm64/kernel/binfmt_elf32.c | 33 +
 5 files changed, 34 insertions(+), 28 deletions(-)
 create mode 100644 arch/arm64/kernel/binfmt_elf32.c

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index ede9b2e..0bb7adc 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -932,7 +932,6 @@ config AARCH32_EL0
bool "Kernel support for 32-bit EL0"
def_bool y
depends on ARM64_4K_PAGES || EXPERT
-   select COMPAT_BINFMT_ELF
select HAVE_UID16
select OLD_SIGSUSPEND3
select COMPAT_OLD_SIGACTION
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index e18bb8a..7a39683 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -166,12 +166,6 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
 
 #ifdef CONFIG_COMPAT
 
-#ifdef __AARCH64EB__
-#define COMPAT_ELF_PLATFORM("v8b")
-#else
-#define COMPAT_ELF_PLATFORM("v8l")
-#endif
-
 #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)
 
 /* AArch32 registers. */
@@ -179,24 +173,6 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
 typedef unsigned int   compat_elf_greg_t;
 typedef compat_elf_greg_t  compat_elf_gregset_t[COMPAT_ELF_NGREG];
 
-/* AArch32 EABI. */
-#define EF_ARM_EABI_MASK   0xff00
-#define compat_elf_check_arch(x)   (((x)->e_machine == EM_ARM) && \
-((x)->e_flags & EF_ARM_EABI_MASK))
-
-#define compat_start_threadcompat_start_thread
-#define COMPAT_SET_PERSONALITY(ex) \
-do {   \
-   clear_thread_flag(TIF_32BIT_AARCH64);   \
-   set_thread_flag(TIF_32BIT); \
-} while (0)
-
-#define COMPAT_ARCH_DLINFO
-extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
- int uses_interp);
-#define compat_arch_setup_additional_pages \
-   aarch32_setup_vectors_page
-
 #endif /* CONFIG_COMPAT */
 
 #endif /* !__ASSEMBLY__ */
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 2c7fc5d..99dfd92 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -47,8 +47,6 @@
 #define ELF_HWCAP  (elf_hwcap)
 
 #ifdef CONFIG_AARCH32_EL0
-#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
-#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
 extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
 #endif
 
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 75dd250..6bc9738 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -27,7 +27,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
-  ../../arm/kernel/opcodes.o
+  ../../arm/kernel/opcodes.o 
binfmt_elf32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
new file mode 100644
index 000..5487872
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -0,0 +1,33 @@
+/*
+ * Support for AArch32 Linux ELF binaries.
+ */
+
+/* AArch32 EABI. */
+#define EF_ARM_EABI_MASK   0xff00
+#define compat_elf_check_arch(x)   (((x)->e_machine == EM_ARM) && \
+((x)->e_flags & EF_ARM_EABI_MASK))
+
+#define compat_start_threadcompat_start_thread
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
+#define COMPAT_ARCH_DLINFO
+#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
+#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("v8b")
+#else
+#define COMPAT_ELF_PLATFORM("v8l")
+#endif
+
+#define compat_arch_setup_additional_pages \
+   

[PATCH 09/23] arm64: ensure the kernel is compiled for LP64

2016-05-23 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

The kernel needs to be compiled as a LP64 binary for ARM64, even when
using a compiler that defaults to code-generation for the ILP32 ABI.
Consequently, we need to explicitly pass '-mabi=lp64' (supported on
gcc-4.9 and newer).

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/Makefile | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 354d754..29ebf23 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -35,14 +35,19 @@ KBUILD_CFLAGS   += -fno-asynchronous-unwind-tables
 KBUILD_CFLAGS  += $(call cc-option, -mpc-relative-literal-loads)
 KBUILD_AFLAGS  += $(lseinstr)
 
+KBUILD_CFLAGS  += $(call cc-option,-mabi=lp64)
+KBUILD_AFLAGS  += $(call cc-option,-mabi=lp64)
+
 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
 KBUILD_CPPFLAGS+= -mbig-endian
 AS += -EB
 LD += -EB
+LDFLAGS+= -maarch64linuxb
 else
 KBUILD_CPPFLAGS+= -mlittle-endian
 AS += -EL
 LD += -EL
+LDFLAGS+= -maarch64linux
 endif
 
 CHECKFLAGS += -D__aarch64__
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/23] arm64: ilp32: add documentation on the ILP32 ABI for ARM64

2016-05-23 Thread Yury Norov
Based on Andrew Pinski's patch-series.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 Documentation/arm64/ilp32.txt | 25 +
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/arm64/ilp32.txt

diff --git a/Documentation/arm64/ilp32.txt b/Documentation/arm64/ilp32.txt
new file mode 100644
index 000..8e74d67
--- /dev/null
+++ b/Documentation/arm64/ilp32.txt
@@ -0,0 +1,25 @@
+ILP32 AARCH64 SYSCALL ABI
+=
+
+This document describes the ILP32 syscall ABI and where it differs
+from the generic compat linux syscall interface.
+
+Syscalls which normally would pass 64bit values as two arguments;
+now pass the 64bit value as one argument. Next syscalls are affected:
+fadvise64_64,
+fallocate,
+ftruncate,
+lookup_dcookie,
+pread64,
+pwrite64,
+readahead,
+shmat,
+sync_file_range,
+truncate,
+lseek,
+mmap
+
+struct rt_sigframe is redefined and contains struct compat_siginfo,
+as compat syscalls expects, and struct ilp32_sigframe, to handle
+AARCH64 register set and 32-bit userspace register representation.
+
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/23] arm64: ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-23 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/unistd.h | 11 +-
 arch/arm64/kernel/Makefile  |  2 +-
 arch/arm64/kernel/entry.S   | 10 -
 arch/arm64/kernel/sys_ilp32.c   | 83 +
 4 files changed, 102 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
 #ifdef CONFIG_AARCH32_EL0
 #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
 #define __ARCH_WANT_SYS_GETHOSTNAME
 #define __ARCH_WANT_SYS_PAUSE
 #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 21a0624..acea2cb 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -501,6 +501,7 @@ el0_svc_compat:
 * AArch32 syscall handling
 */
adrpstbl, compat_sys_call_table // load compat syscall table 
pointer
+   ldr x16, [tsk, #TI_FLAGS]
uxtwscno, w7// syscall number in w7 (r7)
mov sc_nr, #__NR_compat_syscalls
b   el0_svc_naked
@@ -717,15 +718,20 @@ ENDPROC(ret_from_fork)
.align  6
 el0_svc:
adrpstbl, sys_call_table// load syscall table pointer
+   ldr x16, [tsk, #TI_FLAGS]
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   adrpx17, sys_call_ilp32_table   // load ilp32 syscall table 
pointer
+   tst x16, #_TIF_32BIT_AARCH64
+   cselstbl, stbl, x17, eq // We are using ILP32
+#endif
 el0_svc_naked: // compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
ct_user_exit 1
 
-   ldr x16, [tsk, #TI_FLAGS]   // check for syscall hooks
-   tst x16, #_TIF_SYSCALL_WORK
+   tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks
b.ne__sys_trace
cmp scno, sc_nr // check upper syscall limit
b.hsni_sys
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..d4cd2a9
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,83 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski <apin...@cavium.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define __SYSCALL_COMPAT
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Using non-compat syscalls where necessary */
+#define compat_sys_fadvise64_64sys_fadvis

[PATCH 12/23] thread: move thread bits accessors to separated file

2016-05-23 Thread Yury Norov
They may be accessed from low-level code, so isolating is a measure to
avoid circular dependencies in header files.

The exact reason for circular dependency is WARN_ON() macro added by Al
Viro in patch [edd63a27] "set_restore_sigmask() is never called without
SIGPENDING (and never should be)"

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 include/linux/thread_bits.h | 55 +
 include/linux/thread_info.h | 44 +---
 2 files changed, 56 insertions(+), 43 deletions(-)
 create mode 100644 include/linux/thread_bits.h

diff --git a/include/linux/thread_bits.h b/include/linux/thread_bits.h
new file mode 100644
index 000..0d05d16
--- /dev/null
+++ b/include/linux/thread_bits.h
@@ -0,0 +1,55 @@
+
+/* thread_bits.h: common low-level thread bits accessors */
+
+#ifndef _LINUX_THREAD_BITS_H
+#define _LINUX_THREAD_BITS_H
+
+#ifndef __ASSEMBLY__
+
+#include 
+#include 
+
+/*
+ * flag set/clear/test wrappers
+ * - pass TIF_ constants to these functions
+ */
+
+static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   set_bit(flag, (unsigned long *)>flags);
+}
+
+static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   clear_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   return test_and_set_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int 
flag)
+{
+   return test_and_clear_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   return test_bit(flag, (unsigned long *)>flags);
+}
+
+#define set_thread_flag(flag) \
+   set_ti_thread_flag(current_thread_info(), flag)
+#define clear_thread_flag(flag) \
+   clear_ti_thread_flag(current_thread_info(), flag)
+#define test_and_set_thread_flag(flag) \
+   test_and_set_ti_thread_flag(current_thread_info(), flag)
+#define test_and_clear_thread_flag(flag) \
+   test_and_clear_ti_thread_flag(current_thread_info(), flag)
+#define test_thread_flag(flag) \
+   test_ti_thread_flag(current_thread_info(), flag)
+
+#endif /* !__ASSEMBLY__ */
+#endif /* _LINUX_THREAD_BITS_H */
+
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index b4c2a48..b094aed 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -50,8 +50,7 @@ struct restart_block {
 
 extern long do_no_restart_syscall(struct restart_block *parm);
 
-#include 
-#include 
+#include 
 
 #ifdef __KERNEL__
 
@@ -62,47 +61,6 @@ extern long do_no_restart_syscall(struct restart_block 
*parm);
 # define THREADINFO_GFP(GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
 #endif
 
-/*
- * flag set/clear/test wrappers
- * - pass TIF_ constants to these functions
- */
-
-static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   set_bit(flag, (unsigned long *)>flags);
-}
-
-static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   clear_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   return test_and_set_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int 
flag)
-{
-   return test_and_clear_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   return test_bit(flag, (unsigned long *)>flags);
-}
-
-#define set_thread_flag(flag) \
-   set_ti_thread_flag(current_thread_info(), flag)
-#define clear_thread_flag(flag) \
-   clear_ti_thread_flag(current_thread_info(), flag)
-#define test_and_set_thread_flag(flag) \
-   test_and_set_ti_thread_flag(current_thread_info(), flag)
-#define test_and_clear_thread_flag(flag) \
-   test_and_clear_ti_thread_flag(current_thread_info(), flag)
-#define test_thread_flag(flag) \
-   test_ti_thread_flag(current_thread_info(), flag)
-
 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
 
 #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/23] compat ABI: use non-compat openat and open_by_handle_at variants

2016-05-23 Thread Yury Norov
The only difference is that non-compat version forces O_LARGEFILE,
and it should be the default behaviour for all architectures, as
we don't support 32-bit off_t. The only exception is tile32, that
continues with compat version of syscalls.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Chris Metcalf <cmetc...@ezchip.com> [for tile]
---
 arch/tile/kernel/compat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c
index 4912084..489ae19 100644
--- a/arch/tile/kernel/compat.c
+++ b/arch/tile/kernel/compat.c
@@ -94,6 +94,9 @@ COMPAT_SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned 
int, offset_high,
 #define compat_sys_readahead sys32_readahead
 #define sys_llseek compat_sys_llseek
 
+#define sys_openat compat_sys_openat
+#define sys_open_by_handle_at  compat_sys_open_by_handle_at
+
 /* Call the assembly trampolines where necessary. */
 #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn
 #define sys_clone _sys_clone
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-05-23 Thread Yury Norov
to handle ILP32 binaries

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/kernel/Makefile   |  1 +
 arch/arm64/kernel/binfmt_ilp32.c | 91 
 2 files changed, 92 insertions(+)
 create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 6bc9738..9dfdf86 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..a934fd4
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,91 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+
+#include 
+#include 
+
+#undef ELF_CLASS
+#define ELF_CLASS  ELFCLASS32
+
+#undef elfhdr
+#undef elf_phdr
+#undef elf_shdr
+#undef elf_note
+#undef elf_addr_t
+#define elfhdr elf32_hdr
+#define elf_phdr   elf32_phdr
+#define elf_shdr   elf32_shdr
+#define elf_note   elf32_note
+#define elf_addr_t Elf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_t compat_siginfo_t
+#define copy_siginfo_to_user   copy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatus   compat_elf_prstatus
+#define elf_prpsinfo   compat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+ struct compat_timeval *value)
+{
+   struct timeval tv;
+   cputime_to_timeval(cputime, );
+   value->tv_sec = tv.tv_sec;
+   value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)  (((x)->e_machine == EM_AARCH64) \
+   && (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {   \
+   set_thread_flag(TIF_32BIT_AARCH64); \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)(long)current->mm->context.vdso);   \
+} while (0)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("aarch64_be:ilp32")
+#else
+#define COMPAT_ELF_PLATFORM("aarch64:ilp32")
+#endif
+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP  ((u32) elf_hwcap)
+#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_format compat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmtexit_compat_elf_binfmt
+
+#include "../../../fs/binfmt_elf.c"
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 19/23] arm64: signal: share lp64 signal routines to ilp32

2016-05-23 Thread Yury Norov
After that, it will be possible to reuse it in ilp32.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal_common.h | 33 
 arch/arm64/kernel/signal.c | 91 +-
 2 files changed, 90 insertions(+), 34 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal_common.h

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
new file mode 100644
index 000..756ed2c
--- /dev/null
+++ b/arch/arm64/include/asm/signal_common.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 1995-2009 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 Cavium Networks.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_SIGNAL_COMMON_H
+#define __ASM_SIGNAL_COMMON_H
+
+#include 
+#include 
+#include 
+
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx);
+int restore_fpsimd_context(struct fpsimd_context __user *ctx);
+int setup_sigcontext(struct sigcontext __user *uc_mcontext, struct pt_regs 
*regs);
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
+void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
+   void __user *frame, off_t sigframe_off, int usig);
+
+#endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index be02f65..f9fbf8a 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -34,18 +34,23 @@
 #include 
 #include 
 #include 
+#include 
+
+struct sigframe {
+   struct ucontext uc;
+   u64 fp;
+   u64 lr;
+};
 
 /*
  * Do a signal return; undo the signal stack. These are aligned to 128-bit.
  */
 struct rt_sigframe {
struct siginfo info;
-   struct ucontext uc;
-   u64 fp;
-   u64 lr;
+   struct sigframe sig;
 };
 
-static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state *fpsimd = >thread.fpsimd_state;
int err;
@@ -65,7 +70,7 @@ static int preserve_fpsimd_context(struct fpsimd_context 
__user *ctx)
return err ? -EFAULT : 0;
 }
 
-static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
+int restore_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state fpsimd;
__u32 magic, size;
@@ -93,22 +98,30 @@ static int restore_fpsimd_context(struct fpsimd_context 
__user *ctx)
 }
 
 static int restore_sigframe(struct pt_regs *regs,
-   struct rt_sigframe __user *sf)
+   struct sigframe __user *sf)
 {
sigset_t set;
-   int i, err;
-   void *aux = sf->uc.uc_mcontext.__reserved;
-
+   int err;
err = __copy_from_user(, >uc.uc_sigmask, sizeof(set));
if (err == 0)
set_current_blocked();
 
+   err |= restore_sigcontext(regs, >uc.uc_mcontext);
+   return err;
+}
+
+
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user 
*uc_mcontext)
+{
+   int i, err = 0;
+   void *aux = uc_mcontext->__reserved;
+
for (i = 0; i < 31; i++)
-   __get_user_error(regs->regs[i], >uc.uc_mcontext.regs[i],
+   __get_user_error(regs->regs[i], _mcontext->regs[i],
 err);
-   __get_user_error(regs->sp, >uc.uc_mcontext.sp, err);
-   __get_user_error(regs->pc, >uc.uc_mcontext.pc, err);
-   __get_user_error(regs->pstate, >uc.uc_mcontext.pstate, err);
+   __get_user_error(regs->sp, _mcontext->sp, err);
+   __get_user_error(regs->pc, _mcontext->pc, err);
+   __get_user_error(regs->pstate, _mcontext->pstate, err);
 
/*
 * Avoid sys_rt_sigreturn() restarting.
@@ -145,10 +158,10 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
goto badframe;
 
-   if (restore_sigframe(regs, frame))
+   if (restore_sigframe(regs, >sig))
goto badframe;
 
-   if (restore_altstack(>uc.uc_stack))
+   if (restore_altstack(>sig.uc.uc_stack))
goto badframe;
 
return regs->regs[0];
@@ -162,27 +175,36 @@ badframe:
return 0;
 }
 
-static int setup_sigframe(struct rt_sigframe __user *sf,
+stat

[PATCH 20/23] arm64: signal32: move ilp32 and aarch32 common code to separated file

2016-05-23 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal32_common.h |  25 +++
 arch/arm64/kernel/Makefile   |   1 +
 arch/arm64/kernel/signal32.c |  85 ---
 arch/arm64/kernel/signal32_common.c  | 115 +++
 4 files changed, 141 insertions(+), 85 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal32_common.h
 create mode 100644 arch/arm64/kernel/signal32_common.c

diff --git a/arch/arm64/include/asm/signal32_common.h 
b/arch/arm64/include/asm/signal32_common.h
new file mode 100644
index 000..b4f2099
--- /dev/null
+++ b/arch/arm64/include/asm/signal32_common.h
@@ -0,0 +1,25 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGNAL32_COMMON_H
+#define __ASM_SIGNAL32_COMMON_H
+
+#ifdef CONFIG_COMPAT
+
+int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from);
+int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from);
+
+#endif /* CONFIG_COMPAT*/
+
+#endif /* __ASM_SIGNAL32_COMMON_H */
+
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 7aa65ea..3ed55eb 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -29,6 +29,7 @@ arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o 
kuser32.o signal32.o \
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
 arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
+arm64-obj-$(CONFIG_COMPAT) += signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c
index b7063de..b103af3 100644
--- a/arch/arm64/kernel/signal32.c
+++ b/arch/arm64/kernel/signal32.c
@@ -125,91 +125,6 @@ static inline int get_sigset_t(sigset_t *set,
return 0;
 }
 
-int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
-{
-   int err;
-
-   if (!access_ok(VERIFY_WRITE, to, sizeof(*to)))
-   return -EFAULT;
-
-   /* If you change siginfo_t structure, please be sure
-* this code is fixed accordingly.
-* It should never copy any pad contained in the structure
-* to avoid security leaks, but must copy the generic
-* 3 ints plus the relevant union member.
-* This routine must convert siginfo from 64bit to 32bit as well
-* at the same time.
-*/
-   err = __put_user(from->si_signo, >si_signo);
-   err |= __put_user(from->si_errno, >si_errno);
-   err |= __put_user((short)from->si_code, >si_code);
-   if (from->si_code < 0)
-   err |= __copy_to_user(>_sifields._pad, 
>_sifields._pad,
- SI_PAD_SIZE);
-   else switch (from->si_code & __SI_MASK) {
-   case __SI_KILL:
-   err |= __put_user(from->si_pid, >si_pid);
-   err |= __put_user(from->si_uid, >si_uid);
-   break;
-   case __SI_TIMER:
-err |= __put_user(from->si_tid, >si_tid);
-err |= __put_user(from->si_overrun, >si_overrun);
-err |= __put_user(from->si_int, >si_int);
-   break;
-   case __SI_POLL:
-   err |= __put_user(from->si_band, >si_band);
-   err |= __put_user(from->si_fd, >si_fd);
-   break;
-   case __SI_FAULT:
-   err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
- >si_addr);
-#ifdef BUS_MCEERR_AO
-   /*
-* Other callers might not initialize the si_lsb field,
-* so check explicitly for the right codes here.
-*/
-   if (from->si_signo == SIGBUS &&
-   (from->si_code == BUS_MCEERR_AR || from->si_code == 
BUS_MCEERR_AO))
-   err |= __put_user(from->si_addr_lsb, >si_addr_lsb);
-#endif
-   break;
-   case __SI_CHLD:
-   err |= __put_user(from->si_pid, >si_pid);
-  

[PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-05-23 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

ILP32 uses AARCH32 compat structures and syscall handlers for signals.
But ILP32 struct rt_sigframe  and ucontext differs from both LP64 and
AARCH32. So some specific mechanism is needed to take care of it.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal_ilp32.h |  34 ++
 arch/arm64/kernel/Makefile|   3 +-
 arch/arm64/kernel/entry_ilp32.S   |  23 
 arch/arm64/kernel/signal.c|   3 +
 arch/arm64/kernel/signal_ilp32.c  | 192 ++
 arch/arm64/kernel/sys_ilp32.c |   3 +
 6 files changed, 257 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/signal_ilp32.h
 create mode 100644 arch/arm64/kernel/entry_ilp32.S
 create mode 100644 arch/arm64/kernel/signal_ilp32.c

diff --git a/arch/arm64/include/asm/signal_ilp32.h 
b/arch/arm64/include/asm/signal_ilp32.h
new file mode 100644
index 000..30eff23
--- /dev/null
+++ b/arch/arm64/include/asm/signal_ilp32.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGNAL_ILP32_H
+#define __ASM_SIGNAL_ILP32_H
+
+#ifdef CONFIG_ARM64_ILP32
+
+#include 
+
+int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs);
+
+#else
+
+static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
+ struct pt_regs *regs)
+{
+   return -ENOSYS;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
+#endif /* __ASM_SIGNAL_ILP32_H */
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 3ed55eb..09e4373 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,8 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o   
\
+  signal_ilp32.o entry_ilp32.o
 arm64-obj-$(CONFIG_COMPAT) += signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
diff --git a/arch/arm64/kernel/entry_ilp32.S b/arch/arm64/kernel/entry_ilp32.S
new file mode 100644
index 000..5063172
--- /dev/null
+++ b/arch/arm64/kernel/entry_ilp32.S
@@ -0,0 +1,23 @@
+/*
+ * ILP32 system call wrappers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+
+ENTRY(ilp32_sys_rt_sigreturn_wrapper)
+   mov x0, sp
+   b   ilp32_sys_rt_sigreturn
+ENDPROC(ilp32_sys_rt_sigreturn_wrapper)
+
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index f9fbf8a..45bcd96 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct sigframe {
struct ucontext uc;
@@ -323,6 +324,8 @@ static void handle_signal(struct ksignal *ksig, struct 
pt_regs *regs)
ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
else
ret = compat_setup_frame(usig, ksig, oldset, regs);
+   } else if (is_ilp32_compat_task()) {
+   ret = ilp32_setup_rt_frame(usig, ksig, oldset, regs);
} else {
ret = setup_rt_frame(usig, ksig, oldset, regs);
}
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
new file mode 100644
index 000..84

[PATCH 22/23] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-23 Thread Yury Norov
From: Philipp Tomsich <philipp.toms...@theobroma-systems.com>

ILP32 VDSO exports next symbols:
 __kernel_rt_sigreturn;
 __kernel_gettimeofday;
 __kernel_clock_gettime;
 __kernel_clock_getres;

What shared object to use, kernel selects depending on result of
is_ilp32_compat_task() in arch/arm64/kernel/vdso.c, so it substitutes
correct pages and spec.

Adjusted to move the move data page before code pages in sync with
commit 601255ae3c98fd3a8bb4696425e4f868b4f1

Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/vdso.h |  6 ++
 arch/arm64/kernel/Makefile|  7 ++
 arch/arm64/kernel/asm-offsets.c   |  7 ++
 arch/arm64/kernel/signal.c|  2 +
 arch/arm64/kernel/vdso-ilp32/.gitignore   |  2 +
 arch/arm64/kernel/vdso-ilp32/Makefile | 74 +
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S | 33 ++
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S | 95 +++
 arch/arm64/kernel/vdso.c  | 61 ++---
 arch/arm64/kernel/vdso/gettimeofday.S | 20 +-
 10 files changed, 294 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm64/kernel/vdso-ilp32/.gitignore
 create mode 100644 arch/arm64/kernel/vdso-ilp32/Makefile
 create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S
 create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S

diff --git a/arch/arm64/include/asm/vdso.h b/arch/arm64/include/asm/vdso.h
index 839ce00..649a9a4 100644
--- a/arch/arm64/include/asm/vdso.h
+++ b/arch/arm64/include/asm/vdso.h
@@ -29,6 +29,12 @@
 
 #include 
 
+#ifdef CONFIG_ARM64_ILP32
+#include 
+#else
+#define vdso_offset_sigtramp_ilp32
+#endif
+
 #define VDSO_SYMBOL(base, name)
   \
 ({\
(void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 09e4373..e98add5 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -50,6 +50,7 @@ arm64-obj-$(CONFIG_PARAVIRT)  += paravirt.o
 arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
 
 obj-y  += $(arm64-obj-y) vdso/
+obj-$(CONFIG_ARM64_ILP32)  += vdso-ilp32/
 obj-m  += $(arm64-obj-m)
 head-y := head.o
 extra-y+= $(head-y) vmlinux.lds
@@ -57,3 +58,9 @@ extra-y   += $(head-y) 
vmlinux.lds
 # vDSO - this must be built first to generate the symbol offsets
 $(call objectify,$(arm64-obj-y)): $(obj)/vdso/vdso-offsets.h
 $(obj)/vdso/vdso-offsets.h: $(obj)/vdso
+
+ifeq ($(CONFIG_ARM64_ILP32),y)
+# vDSO - this must be built first to generate the symbol offsets
+$(call objectify,$(arm64-obj-y)): $(obj)/vdso-ilp32/vdso-ilp32-offsets.h
+$(obj)/vdso-ilp32/vdso-ilp32-offsets.h: $(obj)/vdso-ilp32
+endif
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index e229525..af69b81 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -101,6 +101,13 @@ int main(void)
   DEFINE(TSPEC_TV_SEC, offsetof(struct timespec, tv_sec));
   DEFINE(TSPEC_TV_NSEC,offsetof(struct timespec, tv_nsec));
   BLANK();
+#ifdef CONFIG_COMPAT
+  DEFINE(COMPAT_TVAL_TV_SEC,   offsetof(struct compat_timeval, tv_sec));
+  DEFINE(COMPAT_TVAL_TV_USEC,  offsetof(struct compat_timeval, tv_usec));
+  DEFINE(COMPAT_TSPEC_TV_SEC,  offsetof(struct compat_timespec, tv_sec));
+  DEFINE(COMPAT_TSPEC_TV_NSEC, offsetof(struct compat_timespec, tv_nsec));
+  BLANK();
+#endif
   DEFINE(TZ_MINWEST,   offsetof(struct timezone, tz_minuteswest));
   DEFINE(TZ_DSTTIME,   offsetof(struct timezone, tz_dsttime));
   BLANK();
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 45bcd96..933cdcf 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -264,6 +264,8 @@ void setup_return(struct pt_regs *regs, struct k_sigaction 
*ka,
 
if (ka->sa.sa_flags & SA_RESTORER)
sigtramp = ka->sa.sa_restorer;
+   else if (is_ilp32_compat_task())
+   sigtramp = VDSO_SYMBOL(current->mm->context.vdso, 
sigtramp_ilp32);
else
sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
 
diff --git a/arch/arm64/kernel/vdso-ilp32/.gitignore 
b/arch/arm64/kernel/vdso-ilp32/.gitignore
new file mode 100644
index 000..61806c3
--- /dev/null
+++ b/arch/arm64/kernel/vdso-ilp32/.gitignore
@@ -0,0 +1,2 @@
+vdso-ilp32.lds
+vdso-ilp32-offsets.h
diff --git a/arch/arm64/kernel

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-18 Thread Yury Norov
On Wed, May 18, 2016 at 12:21:46PM +0100, Catalin Marinas wrote:
> On Tue, May 17, 2016 at 10:05:26PM +0300, Yury Norov wrote:
> > On Mon, May 16, 2016 at 06:06:05PM +0100, Catalin Marinas wrote:
> > > On Sat, May 14, 2016 at 06:03:52PM +0300, Yury Norov wrote:
> > > > +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
> > > > +   unsigned long, prot, unsigned long, flags, unsigned long, fd,
> > > > +   unsigned long, pgoff)
> > > 
> > > To avoid the types confusion we could add __SC_WRAP to mmap2 in unistd.h
> > > and use COMPAT_SYSCALL_DEFINE6 here (together with compat_ptr_t etc.).
> > > 
> > > > +{
> > > > +   if (pgoff & (~PAGE_MASK >> 12))
> > > > +   return -EINVAL;
> > > > +
> > > > +   return sys_mmap_pgoff((compat_uptr_t) addr, (compat_size_t) len,
> > > > +  (int) prot, (int) flags, (int) fd,
> > > > +  pgoff >> (PAGE_SHIFT-12));
> > > 
> > > Then we wouldn't need the explicit casting here.
> > 
> > See below
> > 
> > > > +}
> > > > +
> > > > +COMPAT_SYSCALL_DEFINE4(pread64, unsigned int, fd, compat_uptr_t __user 
> > > > *, ubuf,
> > > > +  compat_size_t, count, off_t, offset)
> > > > +{
> > > > +   return sys_pread64(fd, (char *) ubuf, count, offset);
> > > > +}
> > > > +
> > > > +COMPAT_SYSCALL_DEFINE4(pwrite64, unsigned int, fd, compat_uptr_t 
> > > > __user *, ubuf,
> > > > +  compat_size_t, count, off_t, offset)
> > > > +{
> > > > +   return sys_pwrite64(fd, (char *) ubuf, count, offset);
> > > 
> > > Nitpick: no space between cast type and variable name: (char *)ubuf, ...
> > 
> > I think it's really a matter of taste. I prefer to have a space, and
> > there's no solid rule in coding style.
> > 
> > And there are 13032 insertions of my version vs 35030 of yours:
> > ~/work/linux$ git grep ' \*)[a-zA-Z]'|wc -l
> > 35030
> > ~/work/linux$ git grep ' \*) [a-zA-Z]'|wc -l
> > 13032
> > 
> > Of course, I will change it if you insist.
> 
> Not really, I thought it's covered by CodingStyle but it doesn't seem
> to.
> 
> > > We can also make these functions static as they are not used outside
> > > this file.
> > 
> > If it's OK, we can use just compat_sys_xxx() instead of
> > COMPAT_SYSCALL_DEFINEx(xxx),
> 
> I got lost in macros, what difference would COMPAT_SYSCALL_DEFINE vs
> compat_sys_*() make? Is this the delouse stuff?
> 

Hmm... I looked again. It seems that COMPAT delouses all arguments,
including off_t, and that's what we try to avoid. So we *should* use
naked functions. 

include/linux/compat.h:
53 #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
54 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
55  __attribute__((alias(__stringify(compat_SyS##name;  \
56 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
57 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
58 asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
59 { \
60 return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
61 } \
62 static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))


> > and for mmap2 we'll not need to change _SYSCALL to _SC_WRAP in
> > unistd.h that way.
> 
> Looking at the generic unistd.h, adding _SC_WRAP for sys_mmap2 is
> indeed not easy:
> 
> #define __NR3264_mmap 222
> __SC_3264(__NR3264_mmap, sys_mmap2, sys_mmap)
> 
> So defining a compat_sys_mmap2() would work but I think you'd also need:
> 

> #define sys_mmap2 compat_sys_mmap2()

OK.

> 
> -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-17 Thread Yury Norov
On Mon, May 16, 2016 at 06:06:05PM +0100, Catalin Marinas wrote:
> On Sat, May 14, 2016 at 06:03:52PM +0300, Yury Norov wrote:
> > +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
> > +   unsigned long, prot, unsigned long, flags, unsigned long, fd,
> > +   unsigned long, pgoff)
> 
> To avoid the types confusion we could add __SC_WRAP to mmap2 in unistd.h
> and use COMPAT_SYSCALL_DEFINE6 here (together with compat_ptr_t etc.).
> 
> > +{
> > +   if (pgoff & (~PAGE_MASK >> 12))
> > +   return -EINVAL;
> > +
> > +   return sys_mmap_pgoff((compat_uptr_t) addr, (compat_size_t) len,
> > +  (int) prot, (int) flags, (int) fd,
> > +  pgoff >> (PAGE_SHIFT-12));
> 
> Then we wouldn't need the explicit casting here.

See below

> 
> > +}
> > +
> > +COMPAT_SYSCALL_DEFINE4(pread64, unsigned int, fd, compat_uptr_t __user *, 
> > ubuf,
> > +  compat_size_t, count, off_t, offset)
> > +{
> > +   return sys_pread64(fd, (char *) ubuf, count, offset);
> > +}
> > +
> > +COMPAT_SYSCALL_DEFINE4(pwrite64, unsigned int, fd, compat_uptr_t __user *, 
> > ubuf,
> > +  compat_size_t, count, off_t, offset)
> > +{
> > +   return sys_pwrite64(fd, (char *) ubuf, count, offset);
> 
> Nitpick: no space between cast type and variable name: (char *)ubuf, ...

I think it's really a matter of taste. I prefer to have a space, and
there's no solid rule in coding style.

And there are 13032 insertions of my version vs 35030 of yours:
~/work/linux$ git grep ' \*)[a-zA-Z]'|wc -l
35030
~/work/linux$ git grep ' \*) [a-zA-Z]'|wc -l
13032

Of course, I will change it if you insist.

> We can also make these functions static as they are not used outside
> this file.

If it's OK, we can use just compat_sys_xxx() instead of
COMPAT_SYSCALL_DEFINEx(xxx), and for mmap2 we'll not need to change 
_SYSCALL to _SC_WRAP in unistd.h that way.

> > -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-14 Thread Yury Norov
So, after all discussions, this patch is looking like this.

Changes:
 - assembler part reworked to be more clear, as Catalin recommended;
 - mmap now points to mmap2, as in 1st versions (suggested by Bamvor),
   and ilp32 wrapper delouses required arguments;
 - pread64 and pwrite64 wrappers introduced to delouse args as well;
 - removed unneeded #undefs;

Did I miss something?

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see .
  */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
 #ifdef CONFIG_AARCH32_EL0
 #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
 #define __ARCH_WANT_SYS_GETHOSTNAME
 #define __ARCH_WANT_SYS_PAUSE
 #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..0f651bc 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -500,6 +500,7 @@ el0_svc_compat:
 * AArch32 syscall handling
 */
adrpstbl, compat_sys_call_table // load compat syscall table 
pointer
+   ldr x16, [tsk, #TI_FLAGS]
uxtwscno, w7// syscall number in w7 (r7)
mov sc_nr, #__NR_compat_syscalls
b   el0_svc_naked
@@ -716,15 +717,20 @@ ENDPROC(ret_from_fork)
.align  6
 el0_svc:
adrpstbl, sys_call_table// load syscall table pointer
+   ldr x16, [tsk, #TI_FLAGS]
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   adrpx17, sys_call_ilp32_table   // load ilp32 syscall table 
pointer
+   tst x16, #_TIF_32BIT_AARCH64
+   cselstbl, stbl, x17, eq // We are using ILP32
+#endif
 el0_svc_naked: // compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
ct_user_exit 1
 
-   ldr x16, [tsk, #TI_FLAGS]   // check for syscall hooks
-   tst x16, #_TIF_SYSCALL_WORK
+   tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks
b.ne__sys_trace
cmp scno, sc_nr // check upper syscall limit
b.hsni_sys
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..64db612
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,84 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#define __SYSCALL_COMPAT
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Using non-compat syscalls where necessary */
+#define compat_sys_fadvise64_64sys_fadvise64_64
+#define compat_sys_fallocate   sys_fallocate
+#define compat_sys_ftruncate64 sys_ftruncate
+#define compat_sys_lookup_dcookie  sys_lookup_dcookie
+#define compat_sys_readahead   sys_readahead
+#define compat_sys_shmat   sys_shmat
+#define 

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-14 Thread Yury Norov
On Thu, May 12, 2016 at 04:19:48PM +0300, Yury Norov wrote:

[...]

> > I think that's a good idea. The function used to be slightly different
> > for each architecture, but now it seems we have a significant number
> > of identical implementations that we could just merge them together
> > into one.
> > 
> > sys_mmap_pgoff was originally introduced as the common implementation
> > and it reduced the amount of duplication a lot, but as its units
> > are based on PAGE_SIZE rather than hardwired 4096 bytes, it's
> > not as useful.
> > 
> 
> microblaze and mips (twice) are doing like this. And aarh32 as well,
> in arch/arm64/kernel/entry32.S
> 
> In previous submissions it was a patch that shares aarch32 code to
> ilp32. If we decided turn around again, I think, we'd pick up that patch.
> 
> The other option is to make this hack generic, as so many arches use it.

Hi again,

I picked up that old patch from Jan, and found that it doesn't delouse
addr and length, which is wrong for ilp32. So now I think we'd pick
Bamvor version.

Jan's patch (rebased) is attached for reference.

Yury.


>From 02ad258662c40d457ac041634e67e1cbdbb800f3 Mon Sep 17 00:00:00 2001
From: Jan Dakinevich <jan.dakinev...@gmail.com>
Date: Tue, 3 Nov 2015 02:30:41 +0300
Subject: ilp32: common 32-bit wrappers

Signed-off-by: Jan Dakinevich <jan.dakinev...@gmail.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..2319042 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -30,6 +30,7 @@ arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o 
kuser32.o signal32.o \
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
 arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
+arm64-obj-$(CONFIG_COMPAT) += entry32-common.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
 arm64-obj-$(CONFIG_PERF_EVENTS)+= perf_regs.o perf_callchain.o
diff --git a/arch/arm64/kernel/entry32-common.S 
b/arch/arm64/kernel/entry32-common.S
new file mode 100644
index 000..1a0abe3
--- /dev/null
+++ b/arch/arm64/kernel/entry32-common.S
@@ -0,0 +1,23 @@
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Note: off_4k (w5) is always in units of 4K. If we can't do the
+ * requested offset because it is not page-aligned, we return -EINVAL.
+ */
+ENTRY(compat_sys_mmap2_wrapper)
+#if PAGE_SHIFT > 12
+   tst w5, #~PAGE_MASK >> 12
+   b.ne1f
+   lsr w5, w5, #PAGE_SHIFT - 12
+#endif
+   b   sys_mmap_pgoff
+1: mov x0, #-EINVAL
+   ret
+ENDPROC(compat_sys_mmap2_wrapper)
+
diff --git a/arch/arm64/kernel/entry32.S b/arch/arm64/kernel/entry32.S
index f332d5d..58cb5b0 100644
--- a/arch/arm64/kernel/entry32.S
+++ b/arch/arm64/kernel/entry32.S
@@ -55,21 +55,6 @@ ENTRY(compat_sys_fstatfs64_wrapper)
 ENDPROC(compat_sys_fstatfs64_wrapper)
 
 /*
- * Note: off_4k (w5) is always in units of 4K. If we can't do the
- * requested offset because it is not page-aligned, we return -EINVAL.
- */
-ENTRY(compat_sys_mmap2_wrapper)
-#if PAGE_SHIFT > 12
-   tst w5, #~PAGE_MASK >> 12
-   b.ne1f
-   lsr w5, w5, #PAGE_SHIFT - 12
-#endif
-   b   sys_mmap_pgoff
-1: mov x0, #-EINVAL
-   ret
-ENDPROC(compat_sys_mmap2_wrapper)
-
-/*
  * Wrappers for AArch32 syscalls that either take 64-bit parameters
  * in registers or that take 32-bit parameters which require sign
  * extension.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-13 Thread Yury Norov
On Fri, May 13, 2016 at 09:28:03AM +, Catalin Marinas wrote:
> 
> The discussion is mainly around whether USER_DS for 32-bit compat apps
> should be the same as USER_DS for native 32-bit apps. Even for native
> 32-bit kernels, we don't use STACK_TOP as addr_limit. A read/write from
> 0x would fail in both cases anyway. I think the LTP test doesn't
> even try to access such memory but only to probe the range validity (I
> haven't managed to build the latest LTP yet).

This fix lets me build it (on top of 7b3ef3b0b)
Of course, it's not 'official'. :)

---
 testcases/kernel/syscalls/fstatat/fstatat01.c  | 1 +
 testcases/kernel/syscalls/preadv/preadv.h  | 1 +
 testcases/kernel/syscalls/pwritev/pwritev.h| 1 +
 testcases/kernel/syscalls/request_key/Makefile | 2 +-
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/fstatat/fstatat01.c 
b/testcases/kernel/syscalls/fstatat/fstatat01.c
index 128f6dd..6e23c9e 100644
--- a/testcases/kernel/syscalls/fstatat/fstatat01.c
+++ b/testcases/kernel/syscalls/fstatat/fstatat01.c
@@ -59,6 +59,7 @@ static const char *filenames[TEST_CASES];
 static const int expected_errno[] = { 0, 0, ENOTDIR, EBADF, EINVAL, 0 };
 static const int flags[] = { 0, 0, 0, 0, , 0 };
 
+#define HAVE_FSTATAT
 #if !defined(HAVE_FSTATAT)
 #if (__NR_fstatat64 > 0)
 int fstatat(int dirfd, const char *filename, struct stat64 *statbuf, int flags)
diff --git a/testcases/kernel/syscalls/preadv/preadv.h 
b/testcases/kernel/syscalls/preadv/preadv.h
index f3ac30d..b001389 100644
--- a/testcases/kernel/syscalls/preadv/preadv.h
+++ b/testcases/kernel/syscalls/preadv/preadv.h
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "linux_syscall_numbers.h"
 
+#define HAVE_PREADV
 #if !defined(HAVE_PREADV)
 int preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
 {
diff --git a/testcases/kernel/syscalls/pwritev/pwritev.h 
b/testcases/kernel/syscalls/pwritev/pwritev.h
index ae9d999..2a4d188 100644
--- a/testcases/kernel/syscalls/pwritev/pwritev.h
+++ b/testcases/kernel/syscalls/pwritev/pwritev.h
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "linux_syscall_numbers.h"
 
+#define HAVE_PWRITEV
 #if !defined(HAVE_PWRITEV)
 int pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
 {
diff --git a/testcases/kernel/syscalls/request_key/Makefile 
b/testcases/kernel/syscalls/request_key/Makefile
index 9add429..2e8a37c 100644
--- a/testcases/kernel/syscalls/request_key/Makefile
+++ b/testcases/kernel/syscalls/request_key/Makefile
@@ -19,6 +19,6 @@ top_srcdir?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-LDLIBS += $(KEYUTILS_LIBS)
+LDLIBS += $(lkeyutils)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
-- 
2.5.0


> 
> -- 
> Catalin
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-12 Thread Yury Norov
On Thu, May 12, 2016 at 03:07:35PM +0100, Catalin Marinas wrote:
> On Thu, May 12, 2016 at 04:44:31PM +0300, Yury Norov wrote:
> > On Thu, May 12, 2016 at 02:35:34PM +0100, Catalin Marinas wrote:
> > > On Thu, May 12, 2016 at 03:20:00AM +0300, Yury Norov wrote:
> > > > I debugged preadv02 and pwritev02 failures and found very weird bug.
> > > > Test passes {iovec_base = 0x, iovec_len = 64} as one element
> > > > of vector, and kernel reports successful read/write.
> > > > 
> > > > There are 2 problems:
> > > > 1. How kernel allows such address to be passed to fs subsystem;
> > > > 2. How fs successes to read/write at non-mapped, and in fact non-user
> > > > address.
> > > > 
> > > > I don't know the answer on 2'nd question, and it might be something
> > > > generic. But I investigated first problem.
> > > > 
> > > > The problem is that compat_rw_copy_check_uvector() uses access_ok() to
> > > > validate user address, and on arm64 it ends up with checking buffer
> > > > end against current_thread_info()->addr_limit.
> > > > 
> > > > current_thread_info()->addr_limit for ilp32, and most probably for
> > > > aarch32 is equal to aarch64 one, and so adress_ok() doesn't fail.
> > > > It happens because on thread creation we call flush_old_exec() to set 
> > > > addr_limit, and completely ignore compat mode there.
> 
> [...]
> 
> > > > --- a/arch/arm64/kernel/binfmt_elf32.c
> > > > +++ b/arch/arm64/kernel/binfmt_elf32.c
> > > > @@ -12,6 +12,7 @@
> > > >  do {   \
> > > > clear_thread_flag(TIF_32BIT_AARCH64);   \
> > > > set_thread_flag(TIF_32BIT); \
> > > > +   set_fs(TASK_SIZE_32);   \
> > > >  } while (0)
> > > >  
> > > >  #define COMPAT_ARCH_DLINFO
> > > > diff --git a/arch/arm64/kernel/binfmt_ilp32.c 
> > > > b/arch/arm64/kernel/binfmt_ilp32.c
> > > > index a934fd4..a8599c6 100644
> > > > --- a/arch/arm64/kernel/binfmt_ilp32.c
> > > > +++ b/arch/arm64/kernel/binfmt_ilp32.c
> > > > @@ -59,6 +59,7 @@ static void cputime_to_compat_timeval(const cputime_t 
> > > > cputime,
> > > >  do {   
> > > > \
> > > > set_thread_flag(TIF_32BIT_AARCH64); 
> > > > \
> > > > clear_thread_flag(TIF_32BIT);   
> > > > \
> > > > +   set_fs(TASK_SIZE_32);   
> > > > \
> > > >  } while (0)
> > > 
> > > I don't think we need these two. AFAICT, flush_old_exec() takes care of
> > > setting the USER_DS for the new thread.
> > 
> > That's true, but USER_DS depends on personality which is not set yet
> > for new thread, as I wrote above. In fact, I tried correct USER_DS
> > only, and it doesn't work
> 
> Ah, it looks like load_elf_binary() sets the personality after
> flush_old_exec(). Looking at powerpc and x86, they set USER_DS to the
> maximum 64-bit task value, so they should have a similar issue with
> native 32-bit vs compat behaviour.

Hmmm. If so, it means we'd introduce generic fix. It would be removing 
set_fs() from flush_old_exec() and appending it to load_elf_binary()
after SET_PERSONALITY(). But I think it should be agreed with other
arches developers. I've sent standalone patch for aarch64 (you in CC)
so let's move discussion there.

> So what exactly is LTP complaining about? Is different error (like
> EFAULT vs EINVAL) or not getting an error at all.
 
It should be EINVAL, but it succeed. The other problem is that
following fs routines does not complain on wrong address.

> (I need to update my LTP, the preadv tests appeared in December last
> year)
> 

preadv02 was extended with this testcase in April.

> -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-12 Thread Yury Norov
On Thu, May 12, 2016 at 02:35:34PM +0100, Catalin Marinas wrote:
> On Thu, May 12, 2016 at 03:20:00AM +0300, Yury Norov wrote:
> > I debugged preadv02 and pwritev02 failures and found very weird bug.
> > Test passes {iovec_base = 0x, iovec_len = 64} as one element
> > of vector, and kernel reports successful read/write.
> > 
> > There are 2 problems:
> > 1. How kernel allows such address to be passed to fs subsystem;
> > 2. How fs successes to read/write at non-mapped, and in fact non-user
> > address.
> > 
> > I don't know the answer on 2'nd question, and it might be something
> > generic. But I investigated first problem.
> > 
> > The problem is that compat_rw_copy_check_uvector() uses access_ok() to
> > validate user address, and on arm64 it ends up with checking buffer
> > end against current_thread_info()->addr_limit.
> > 
> > current_thread_info()->addr_limit for ilp32, and most probably for
> > aarch32 is equal to aarch64 one, and so adress_ok() doesn't fail.
> > It happens because on thread creation we call flush_old_exec() to set 
> > addr_limit, and completely ignore compat mode there.
> 
> I assume accesses beyond this address would fault anyway but I haven't
> checked the code paths.
> 
> > diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
> > index 7a39683..6ba4952 100644
> > --- a/arch/arm64/include/asm/elf.h
> > +++ b/arch/arm64/include/asm/elf.h
> > @@ -146,6 +146,7 @@ typedef struct user_fpsimd_state elf_fpregset_t;
> >  do {   \
> > clear_thread_flag(TIF_32BIT_AARCH64);   \
> > clear_thread_flag(TIF_32BIT);   \
> > +   set_fs(TASK_SIZE_64);   \
> >  } while (0)
> 
> See below.
> 
> > diff --git a/arch/arm64/include/asm/uaccess.h 
> > b/arch/arm64/include/asm/uaccess.h
> > index 19cfdc5..3b0dd8d 100644
> > --- a/arch/arm64/include/asm/uaccess.h
> > +++ b/arch/arm64/include/asm/uaccess.h
> > @@ -51,7 +51,7 @@
> >  #define KERNEL_DS  (-1UL)
> >  #define get_ds()   (KERNEL_DS)
> >  
> > -#define USER_DSTASK_SIZE_64
> > +#define USER_DSTASK_SIZE
> 
> I agree with this.
> 
> >  #define get_fs()   (current_thread_info()->addr_limit)
> >  
> >  static inline void set_fs(mm_segment_t fs)
> > diff --git a/arch/arm64/kernel/binfmt_elf32.c 
> > b/arch/arm64/kernel/binfmt_elf32.c
> > index 5487872..2e8d9f3 100644
> > --- a/arch/arm64/kernel/binfmt_elf32.c
> > +++ b/arch/arm64/kernel/binfmt_elf32.c
> > @@ -12,6 +12,7 @@
> >  do {   \
> > clear_thread_flag(TIF_32BIT_AARCH64);   \
> > set_thread_flag(TIF_32BIT); \
> > +   set_fs(TASK_SIZE_32);   \
> >  } while (0)
> >  
> >  #define COMPAT_ARCH_DLINFO
> > diff --git a/arch/arm64/kernel/binfmt_ilp32.c 
> > b/arch/arm64/kernel/binfmt_ilp32.c
> > index a934fd4..a8599c6 100644
> > --- a/arch/arm64/kernel/binfmt_ilp32.c
> > +++ b/arch/arm64/kernel/binfmt_ilp32.c
> > @@ -59,6 +59,7 @@ static void cputime_to_compat_timeval(const cputime_t 
> > cputime,
> >  do {   
> > \
> > set_thread_flag(TIF_32BIT_AARCH64); \
> > clear_thread_flag(TIF_32BIT);   \
> > +   set_fs(TASK_SIZE_32);   \
> >  } while (0)
> 
> I don't think we need these two. AFAICT, flush_old_exec() takes care of
> setting the USER_DS for the new thread.

That's true, but USER_DS depends on personality which is not set yet
for new thread, as I wrote above. In fact, I tried correct USER_DS
only, and it doesn't work

> 
> -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-12 Thread Yury Norov
On Thu, May 12, 2016 at 03:06:39PM +0200, Arnd Bergmann wrote:
> On Thursday 12 May 2016 20:49:24 Zhangjian wrote:
> > Hi,
> > 
> > On 2016/5/12 17:21, Arnd Bergmann wrote:
> > > On Thursday 12 May 2016 10:17:58 Catalin Marinas wrote:
> > >> On Wed, May 11, 2016 at 09:30:07PM +0200, Arnd Bergmann wrote:
> > >>> On Wednesday 11 May 2016 17:59:01 Catalin Marinas wrote:
> > >>>
> > >>> I don't think the shifts are a problem, the main downside would be
> > >>> the limit to 44 bits of file offsets (16TB files), but it's also
> > >>> unclear if that is a practical problem at all. If it is, we run
> > >>> into the same problem on all other 32-bit architectures too.
> > >>
> > >> I hope people are seriously thinking of moving to an LP64 ABI if they
> > >> have such large file offset needs.
> > >
> > > Good point. 44 bits of file size is certainly enough for mmap()
> > > on a 32-bit task: you would only be able to map a very small fraction
> > > of the file anyway, and if you want to map larger files, and should
> > > move to 64-bit tasks long before this becomes a limitation.
> > Hi,
> > 
> > I apply the following patch in order to make use of the REAL mmmap2. LTP
> > test pass in litle endian. mmap16 successful with segfault in big endian.
> > 
> > BTW, I saw the similar code in tile, mips, microblaze and s390 compat. 
> > Should
> > we merge these code into a common syscall wrapper?
> 
> I think that's a good idea. The function used to be slightly different
> for each architecture, but now it seems we have a significant number
> of identical implementations that we could just merge them together
> into one.
> 
> sys_mmap_pgoff was originally introduced as the common implementation
> and it reduced the amount of duplication a lot, but as its units
> are based on PAGE_SIZE rather than hardwired 4096 bytes, it's
> not as useful.
> 

microblaze and mips (twice) are doing like this. And aarh32 as well,
in arch/arm64/kernel/entry32.S

In previous submissions it was a patch that shares aarch32 code to
ilp32. If we decided turn around again, I think, we'd pick up that patch.

The other option is to make this hack generic, as so many arches use it.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-12 Thread Yury Norov
On Thu, May 12, 2016 at 11:19:21AM +0200, Arnd Bergmann wrote:
> On Thursday 12 May 2016 03:20:00 Yury Norov wrote:
> > 
> > I debugged preadv02 and pwritev02 failures and found very weird bug.
> > Test passes {iovec_base = 0x, iovec_len = 64} as one element
> > of vector, and kernel reports successful read/write.
> > 
> > There are 2 problems:
> > 1. How kernel allows such address to be passed to fs subsystem;
> > 2. How fs successes to read/write at non-mapped, and in fact non-user
> > address.
> > 
> > I don't know the answer on 2'nd question, and it might be something
> > generic. But I investigated first problem.
> > 
> > The problem is that compat_rw_copy_check_uvector() uses access_ok() to
> > validate user address, and on arm64 it ends up with checking buffer
> > end against current_thread_info()->addr_limit.
> > 
> > current_thread_info()->addr_limit for ilp32, and most probably for
> > aarch32 is equal to aarch64 one, and so adress_ok() doesn't fail.
> > It happens because on thread creation we call flush_old_exec() to set 
> > addr_limit, and completely ignore compat mode there.
> > 
> > This patch fixes it. It also fixes USER_DS macro to return different
> > values depending on compat.
> > 
> > This patch is enough to handle preadv02 and pwritev02, but problem #2
> > is still there.
> > 
> > Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
> > 
> 
> Good catch!
> 
> Can you do a version of this patch that works on the current
> mainline kernel and can be backported to fix aarch32 emulation?
> 
> For ilp32 mode, I think we can better fix arch/arm64/kernel/binfmt_ilp32.c
> as it is introduced.
> 
>   Arnd
> 

OK, will do

> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-12 Thread Yury Norov
On Thu, May 12, 2016 at 11:45:53AM +0800, Zhangjian (Bamvor) wrote:

[...]

> >Hmm, that is indeed tricky. I think COMPAT_SYSCALL_WRAP4 rightfully
> >refuses the loff_t argument here, as the common case is that this is
> >not possible.
> It works if I apply the following patch, I defined the wrong `__TYPE_IS_xxx`
> yesterday. Should we merge this into ILP32 series or send the compat.h
> and syscalls.h individually? The current series of ILP32 is a little bit
> long and hard to review.
> diff --git a/include/linux/compat.h b/include/linux/compat.h
> index ba6ebe0..22a9565 100644
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -747,7 +747,8 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned 
> int, __u32, __u32,
>  #ifndef __SC_COMPAT_CAST
>  #define __SC_COMPAT_CAST(t, a) ({  \
> BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
> -!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
> +!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t) &&   \
> +!__TYPE_IS_LOFFT(t));  \

I think it's wrong, as loff_t is 64-bit in 32-bit userspace, and this
will clear meaningful data in top halve.

> ((t) ((t)(-1) < 0 ? (s64)(s32)(a) : (u64)(u32)(a)));\
>  })
>  #endif
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index 6e57d9c..66eb85d 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -47,6 +47,7 @@
>  #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
>  #define __TYPE_IS_UL(t)(__same_type((t)0, 0UL))
>  #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
> +#define __TYPE_IS_LOFFT(t) (__same_type((t)0, (loff_t)0))
>  #define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 
> 0L)) a
>  #define __SC_CAST(t, a)(t) a
>  #define __SC_ARGS(t, a)a
> diff --git a/kernel/compat_wrapper.c b/kernel/compat_wrapper.c
> index 98b68b8..28f02d0 100644
> --- a/kernel/compat_wrapper.c
> +++ b/kernel/compat_wrapper.c
> @@ -304,3 +304,7 @@ COMPAT_SYSCALL_WRAP3(getpeername, int, fd, struct 
> sockaddr __user *, usockaddr,
>  COMPAT_SYSCALL_WRAP6(sendto, int, fd, void __user *, buff, size_t, len,
>  unsigned int, flags, struct sockaddr __user *, addr,
>  int, addr_len);
> +COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
> +   size_t, count, loff_t, pos);
> +COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
> +size_t, count, loff_t, pos);

For cases like this I think we should write wrappers by hands. In
unistd.h we can use __SC_WRAP, so they will work like wrappers
generated by COMPAT_SYSCALL_WRAPx() 
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-11 Thread Yury Norov
Hi,

I debugged preadv02 and pwritev02 failures and found very weird bug.
Test passes {iovec_base = 0x, iovec_len = 64} as one element
of vector, and kernel reports successful read/write.

There are 2 problems:
1. How kernel allows such address to be passed to fs subsystem;
2. How fs successes to read/write at non-mapped, and in fact non-user
address.

I don't know the answer on 2'nd question, and it might be something
generic. But I investigated first problem.

The problem is that compat_rw_copy_check_uvector() uses access_ok() to
validate user address, and on arm64 it ends up with checking buffer
end against current_thread_info()->addr_limit.

current_thread_info()->addr_limit for ilp32, and most probably for
aarch32 is equal to aarch64 one, and so adress_ok() doesn't fail.
It happens because on thread creation we call flush_old_exec() to set 
addr_limit, and completely ignore compat mode there.

This patch fixes it. It also fixes USER_DS macro to return different
values depending on compat.

This patch is enough to handle preadv02 and pwritev02, but problem #2
is still there.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/elf.h | 1 +
 arch/arm64/include/asm/uaccess.h | 2 +-
 arch/arm64/kernel/binfmt_elf32.c | 1 +
 arch/arm64/kernel/binfmt_ilp32.c | 1 +
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 7a39683..6ba4952 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -146,6 +146,7 @@ typedef struct user_fpsimd_state elf_fpregset_t;
 do {   \
clear_thread_flag(TIF_32BIT_AARCH64);   \
clear_thread_flag(TIF_32BIT);   \
+   set_fs(TASK_SIZE_64);   \
 } while (0)
 
 #define ARCH_DLINFO\
diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
index 19cfdc5..3b0dd8d 100644
--- a/arch/arm64/include/asm/uaccess.h
+++ b/arch/arm64/include/asm/uaccess.h
@@ -51,7 +51,7 @@
 #define KERNEL_DS  (-1UL)
 #define get_ds()   (KERNEL_DS)
 
-#define USER_DSTASK_SIZE_64
+#define USER_DSTASK_SIZE
 #define get_fs()   (current_thread_info()->addr_limit)
 
 static inline void set_fs(mm_segment_t fs)
diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
index 5487872..2e8d9f3 100644
--- a/arch/arm64/kernel/binfmt_elf32.c
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -12,6 +12,7 @@
 do {   \
clear_thread_flag(TIF_32BIT_AARCH64);   \
set_thread_flag(TIF_32BIT); \
+   set_fs(TASK_SIZE_32);   \
 } while (0)
 
 #define COMPAT_ARCH_DLINFO
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
index a934fd4..a8599c6 100644
--- a/arch/arm64/kernel/binfmt_ilp32.c
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -59,6 +59,7 @@ static void cputime_to_compat_timeval(const cputime_t cputime,
 do {   \
set_thread_flag(TIF_32BIT_AARCH64); \
clear_thread_flag(TIF_32BIT);   \
+   set_fs(TASK_SIZE_32);   \
 } while (0)
 
 #undef ARCH_DLINFO
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Yury Norov
On Wed, May 11, 2016 at 10:04:16AM +0800, Zhangjian (Bamvor) wrote:
[...]

> >>Ok, I will test the ltp syscall test.
> >>With this changes, the issue I mentioned should be fixed. But we still
> >>use mmap2 syscall for ILP32 application when we pass the offset instead
> >>of page offset. Is it correct?
> >
> >I don't remember. It's probably not important whether we have the shift
> >in there, as long as it's independent of the actual kernel page size and
> >user space and kernel agree on the calling conventions.
> Well. I am ok with where to shift the pages size because we get the same
> result. I was just thinking if we should get rid of the name of mmap2 in our
> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may confused
> if they do not know the implementations.
> 

This is what generic unistd.h does. If you want to change it, you'd
change each arch that uses generic unistd.h.

> Regards
> 
> Bamvor
> 
> >
> > Arnd
> >
> 
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-06 Thread Yury Norov
Hello colleagues,

After all comments, VDSO fix looks like this for me.

Note I renamed Andrew's ZERO macro to DELOUSE, as
there already is __SC_DELOUSE which does the same,
but in C, not asm.

Like Bamvor, I'm not sure how we'd apply this patch - 
standalone or meld to VDSO. I think, VDSO patch is too
big and bad-structurized, and if I find how to refactor
it, I'll incorporate this fix.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/kernel/asm-offsets.c   |  7 +++
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S |  2 +-
 arch/arm64/kernel/vdso/gettimeofday.S | 20 +---
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index e229525..fcfd087 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -101,6 +101,13 @@ int main(void)
   DEFINE(TSPEC_TV_SEC, offsetof(struct timespec, tv_sec));
   DEFINE(TSPEC_TV_NSEC,offsetof(struct timespec, tv_nsec));
   BLANK();
+#ifdef CONFIG_ARM64_ILP32
+  DEFINE(COMPAT_TVAL_TV_SEC,   offsetof(struct compat_timeval, tv_sec));
+  DEFINE(COMPAT_TVAL_TV_USEC,  offsetof(struct compat_timeval, tv_usec));
+  DEFINE(COMPAT_TSPEC_TV_SEC,  offsetof(struct compat_timespec, tv_sec));
+  DEFINE(COMPAT_TSPEC_TV_NSEC, offsetof(struct compat_timespec, tv_nsec));
+  BLANK();
+#endif
   DEFINE(TZ_MINWEST,   offsetof(struct timezone, tz_minuteswest));
   DEFINE(TZ_DSTTIME,   offsetof(struct timezone, tz_dsttime));
   BLANK();
diff --git a/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S 
b/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
index ddc63fd..d182a8d 100644
--- a/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
+++ b/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
@@ -79,7 +79,7 @@ PHDRS
  */
 VERSION
 {
-   LINUX_2.6 {
+   LINUX_2.6.39 {
global:
__kernel_rt_sigreturn;
__kernel_gettimeofday;
diff --git a/arch/arm64/kernel/vdso/gettimeofday.S 
b/arch/arm64/kernel/vdso/gettimeofday.S
index efa79e8..a2d8a70 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/arch/arm64/kernel/vdso/gettimeofday.S
@@ -25,6 +25,16 @@
 #define NSEC_PER_SEC_LO16  0xca00
 #define NSEC_PER_SEC_HI16  0x3b9a
 
+#ifdef __LP64__
+#define PTR_REG(n) x##n
+#define OFFSET(n)  n
+#define DELOUSE(n)
+#else
+#define PTR_REG(n) w##n
+#define OFFSET(n)  COMPAT_##n
+#define DELOUSE(n) mov w##n, w##n
+#endif
+
 vdso_data  .reqx6
 use_syscall.reqw7
 seqcnt .reqw8
@@ -51,6 +61,8 @@ seqcnt.reqw8
 /* int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz); */
 ENTRY(__kernel_gettimeofday)
.cfi_startproc
+   DELOUSE(0)
+   DELOUSE(1)
mov x2, x30
.cfi_register x30, x2
 
@@ -68,7 +80,7 @@ ENTRY(__kernel_gettimeofday)
mov x13, #1000
lsl x13, x13, x12
udivx11, x11, x13
-   stp x10, x11, [x0, #TVAL_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x0, #OFFSET(TVAL_TV_SEC)]
 2:
/* If tz is NULL, return 0. */
cbz x1, 3f
@@ -88,6 +100,7 @@ ENDPROC(__kernel_gettimeofday)
 /* int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp); */
 ENTRY(__kernel_clock_gettime)
.cfi_startproc
+   DELOUSE(1)
cmp w0, #CLOCK_REALTIME
ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
b.ne2f
@@ -159,7 +172,7 @@ ENTRY(__kernel_clock_gettime)
 
 6: /* Store to the user timespec. */
lsr x11, x11, x12
-   stp x10, x11, [x1, #TSPEC_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x1, #OFFSET(TSPEC_TV_SEC)]
mov x0, xzr
ret
 7:
@@ -174,6 +187,7 @@ ENDPROC(__kernel_clock_gettime)
 /* int __kernel_clock_getres(clockid_t clock_id, struct timespec *res); */
 ENTRY(__kernel_clock_getres)
.cfi_startproc
+   DELOUSE(1)
cmp w0, #CLOCK_REALTIME
ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
b.ne1f
@@ -187,7 +201,7 @@ ENTRY(__kernel_clock_getres)
ldr x2, 6f
 2:
cbz w1, 3f
-   stp xzr, x2, [x1]
+   stp PTR_REG(zr), PTR_REG(2), [x1]
 
 3: /* res == NULL. */
mov w0, wzr
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-04 Thread Yury Norov
On Tue, May 03, 2016 at 08:41:25PM +0800, Zhangjian (Bamvor) wrote:
> Hi, all
> 
> After apply this patch with my small testcase, the vsyscall of gettimeofday in
> ilp32 works in both big endian and small endian. In this patch, I use the
> different register and offset for ilp32 and lp64. Actually, the
> COMPAT_TVAL_TV_SEC is same as TVAL_TV_SEC(so as to COMPAT_TSPEC_TV_SEC and
> TSPEC_TV_SEC). I add it to keep the logic clear. I also change the version
> of vdso to 4.6. It should change to 2.6.39 if glibc is not update.
> 

[...]

Hi Bamvor,

It works for me as well. Thank you.
I'll incorporate it in next submission.

Yury.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-04-29 Thread Yury Norov
On Fri, Apr 29, 2016 at 12:43:41AM +0200, Arnd Bergmann wrote:
> On Friday 29 April 2016 01:21:37 Yury Norov wrote:
> > index 1458ad7..410d817 100644
> > --- a/arch/arm64/kernel/sys_ilp32.c
> > +++ b/arch/arm64/kernel/sys_ilp32.c
> > @@ -17,6 +17,8 @@
> >  * along with this program.  If not, see
> >  * <http://www.gnu.org/licenses/>.
> >  */
> > 
> > +#define __SYSCALL_COMPAT
> > +
> >  #include 
> >  #include 
> >  #include 
> > @@ -48,13 +50,12 @@ asmlinkage long
> >  ilp32_sys_rt_sigreturn_wrapper(void);
> >
> >  #include 
> >  
> > -#undef __SYSCALL
> > -#undef __SC_COMP
> > -#undef __SC_WRAP
> > -#undef __SC_3264
> > -#undef __SC_COMP_3264
> >  
> > -#define __SYSCALL_COMPAT
> >  #define __SYSCALL(nr, sym) [nr] = sym,
> >  #define __SC_WRAP(nr, sym) [nr] = compat_##sym,
> >  
> > This patch makes gcc warn about redefinition.
> > 
> > arch/arm64/kernel/sys_ilp32.c:59:0: warning: "__SYSCALL" redefined
> >  #define __SYSCALL(nr, sym) [nr] = sym,
> >  ^
> > In file included from include/asm-generic/unistd.h:1:0,
> > 
> 
> Ok, I think I see it now. Can you #undef the two symbols at the
> end of arch/arm64/include/uapi/asm/unistd.h

I think it doesn't look better than what we have now, but not worse
as well. If you like it, I'll change.

> or possibly
> include/uapi/asm-generic/unistd.h?
> 
>   Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-04-28 Thread Yury Norov
On Thu, Apr 28, 2016 at 10:43:59PM +0200, Arnd Bergmann wrote:
> On Thursday 28 April 2016 22:19:14 Yury Norov wrote:
> > 
> > Yes, we need. Otherwise we have circular dependency like this:
> > arch/arm64/kernel/sys_ilp32.c:60:0: warning: "__SC_WRAP" redefined
> >  #define __SC_WRAP(nr, sym) [nr] = compat_##sym,
> >   ^
> >   In file included from include/asm-generic/unistd.h:1:0,
> >from ./arch/arm64/include/uapi/asm/unistd.h:16,
> >from ./arch/arm64/include/asm/unistd.h:62,
> >from ./include/uapi/linux/unistd.h:7,
> >from include/linux/syscalls.h:23,
> >from arch/arm64/kernel/sys_ilp32.c:30:
> > include/uapi/asm-generic/unistd.h:33:0: note: this is the location of the 
> > previous definition
> >  #define __SC_WRAP __SYSCALL
> > 
> > Defining __SYSCALL_COMPAT at the top of the file does not help much.
> 
> Hmm, this sounds like something that we should fix in the asm-generic/unistd.h
> file. Is it just for __SC_WRAP, or also the other macros?
> 
>   Arnd

For __SYSCALL and __SC_WRAP:

diff --git a/arch/arm64/kernel/sys_ilp32.c
b/arch/arm64/kernel/sys_ilp32.c
index 1458ad7..410d817 100644
--- a/arch/arm64/kernel/sys_ilp32.c
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -17,6 +17,8 @@
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

+#define __SYSCALL_COMPAT
+
 #include 
 #include 
 #include 
@@ -48,13 +50,12 @@ asmlinkage long
 ilp32_sys_rt_sigreturn_wrapper(void);
   
 #include 
 
-#undef __SYSCALL
-#undef __SC_COMP
-#undef __SC_WRAP
-#undef __SC_3264
-#undef __SC_COMP_3264
 
-#define __SYSCALL_COMPAT
 #define __SYSCALL(nr, sym) [nr] = sym,
 #define __SC_WRAP(nr, sym) [nr] = compat_##sym,
 
This patch makes gcc warn about redefinition.

arch/arm64/kernel/sys_ilp32.c:59:0: warning: "__SYSCALL" redefined
 #define __SYSCALL(nr, sym) [nr] = sym,
 ^
In file included from include/asm-generic/unistd.h:1:0,
 from ./arch/arm64/include/uapi/asm/unistd.h:16,
 from ./arch/arm64/include/asm/unistd.h:62,
 from ./include/uapi/linux/unistd.h:7,
 from include/linux/syscalls.h:23,
 from arch/arm64/kernel/sys_ilp32.c:30:
include/uapi/asm-generic/unistd.h:15:0: note: this is the location of the 
previous definition
 #define __SYSCALL(x, y)
 ^
arch/arm64/kernel/sys_ilp32.c:60:0: warning: "__SC_WRAP" redefined
 #define __SC_WRAP(nr, sym) [nr] = compat_##sym,
 ^
In file included from include/asm-generic/unistd.h:1:0,
 from ./arch/arm64/include/uapi/asm/unistd.h:16,
 from ./arch/arm64/include/asm/unistd.h:62,
 from ./include/uapi/linux/unistd.h:7,
 from include/linux/syscalls.h:23,
 from arch/arm64/kernel/sys_ilp32.c:30:
include/uapi/asm-generic/unistd.h:33:0: note: this is the location of the 
previous definition
 #define __SC_WRAP __SYSCALL
 ^
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-04-28 Thread Yury Norov
On Tue, Apr 26, 2016 at 05:57:01PM +0100, Catalin Marinas wrote:
> On Wed, Apr 06, 2016 at 01:08:42AM +0300, Yury Norov wrote:
> > +/* Using non-compat syscalls where necessary */
> > +#define compat_sys_fadvise64_64sys_fadvise64_64
> > +#define compat_sys_fallocate   sys_fallocate
> > +#define compat_sys_ftruncate64 sys_ftruncate
> > +#define compat_sys_lookup_dcookie  sys_lookup_dcookie
> > +#define compat_sys_pread64 sys_pread64
> > +#define compat_sys_pwrite64sys_pwrite64
> > +#define compat_sys_readahead   sys_readahead
> > +#define compat_sys_shmat   sys_shmat
> 
> Why don't we use compat_sys_shmat? Is it because of COMPAT_SHMLBA?

Yes. COMPAT_SHMLBA is 4 pages, and it's aarch32-only limitation.

> 
> > +#define compat_sys_sync_file_range sys_sync_file_range
> > +#define compat_sys_truncate64  sys_truncate
> > +#define sys_llseek sys_lseek
> > +#define sys_mmap2 sys_mmap
> 
> Nitpick: there are some whitespace inconsistencies above (just convert
> all spaces to tabs).
> 
> I think you should also update Documentation/arm64/ilp32.txt to include
> the list above.

OK

> 
> > +
> > +#include 
> > +
> > +#undef __SYSCALL
> > +#undef __SC_COMP
> > +#undef __SC_WRAP
> > +#undef __SC_3264
> > +#undef __SC_COMP_3264
> 
> Minor detail: do we actually need to undef all these? Maybe we can get
> away with just defining __SYSCALL_COMPAT at the top of the file.
> 

Yes, we need. Otherwise we have circular dependency like this:
arch/arm64/kernel/sys_ilp32.c:60:0: warning: "__SC_WRAP" redefined
 #define __SC_WRAP(nr, sym) [nr] = compat_##sym,
  ^
  In file included from include/asm-generic/unistd.h:1:0,
   from ./arch/arm64/include/uapi/asm/unistd.h:16,
   from ./arch/arm64/include/asm/unistd.h:62,
   from ./include/uapi/linux/unistd.h:7,
   from include/linux/syscalls.h:23,
   from arch/arm64/kernel/sys_ilp32.c:30:
include/uapi/asm-generic/unistd.h:33:0: note: this is the location of the 
previous definition
 #define __SC_WRAP __SYSCALL

Defining __SYSCALL_COMPAT at the top of the file does not help much.

> > +
> > +#define __SYSCALL_COMPAT
> > +#define __SYSCALL(nr, sym) [nr] = sym,
> > +#define __SC_WRAP(nr, sym) [nr] = compat_##sym,
> > +
> > +/*
> > + * The sys_call_ilp32_table array must be 4K aligned to be accessible from
> > + * kernel/entry.S.
> > + */
> > +void *sys_call_ilp32_table[__NR_syscalls] __aligned(4096) = {
> > +   [0 ... __NR_syscalls - 1] = sys_ni_syscall,
> > +#include 
> > +};
> 
> -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-04-25 Thread Yury Norov
On Mon, Apr 25, 2016 at 09:19:13PM +0300, Yury Norov wrote:
> On Mon, Apr 25, 2016 at 06:26:56PM +0100, Catalin Marinas wrote:
> > On Wed, Apr 06, 2016 at 01:08:42AM +0300, Yury Norov wrote:
> > > --- a/arch/arm64/kernel/entry.S
> > > +++ b/arch/arm64/kernel/entry.S
> > > @@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
> > >   */
> > >   .align  6
> > >  el0_svc:
> > > - adrpstbl, sys_call_table// load syscall table pointer
> > >   uxtwscno, w8// syscall number in w8
> > >   mov sc_nr, #__NR_syscalls
> > > +#ifdef CONFIG_ARM64_ILP32
> > > + ldr x16, [tsk, #TI_FLAGS]
> > > + tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
> > > +#endif
> > 
> > There is another ldr x16, [tsk, #TI_FLAGS] load further down in the
> > el0_svc_naked block. We should rework these a bit to avoid loading the
> > same location twice unnecessarily. E.g. move the ldr x16 just before
> > el0_svc_naked and branch one line after in case of the ILP32 syscall.
> > 
> 
> Yes, I thiks we can refactor it. Thanks for a catch.

Now it's better, I think


diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..21312bb 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,16 +715,22 @@ ENDPROC(ret_from_fork)
  */
.align  6
 el0_svc:
-   adrpstbl, sys_call_table// load syscall table pointer
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+   ldr x16, [tsk, #TI_FLAGS]
+#ifdef CONFIG_ARM64_ILP32
+   tbz x16, #TIF_32BIT_AARCH64, el0_lp64_svc // We are using ILP32
+   adrpstbl, sys_call_ilp32_table  // load ilp32 syscall table 
pointer
+   b el0_svc_naked
+el0_lp64_svc:
+#endif
+   adrpstbl, sys_call_table// load syscall table pointer
 el0_svc_naked: // compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
ct_user_exit 1
 
-   ldr x16, [tsk, #TI_FLAGS]   // check for syscall hooks
-   tst x16, #_TIF_SYSCALL_WORK
+   tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks
b.ne__sys_trace
cmp scno, sc_nr // check upper syscall limit
b.hsni_sys
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-04-25 Thread Yury Norov
On Mon, Apr 25, 2016 at 06:26:56PM +0100, Catalin Marinas wrote:
> On Wed, Apr 06, 2016 at 01:08:42AM +0300, Yury Norov wrote:
> > --- a/arch/arm64/kernel/entry.S
> > +++ b/arch/arm64/kernel/entry.S
> > @@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
> >   */
> > .align  6
> >  el0_svc:
> > -   adrpstbl, sys_call_table// load syscall table pointer
> > uxtwscno, w8// syscall number in w8
> > mov sc_nr, #__NR_syscalls
> > +#ifdef CONFIG_ARM64_ILP32
> > +   ldr x16, [tsk, #TI_FLAGS]
> > +   tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
> > +#endif
> 
> There is another ldr x16, [tsk, #TI_FLAGS] load further down in the
> el0_svc_naked block. We should rework these a bit to avoid loading the
> same location twice unnecessarily. E.g. move the ldr x16 just before
> el0_svc_naked and branch one line after in case of the ILP32 syscall.
> 

Yes, I thiks we can refactor it. Thanks for a catch.

> > +   adrpstbl, sys_call_table// load syscall table pointer
> >  el0_svc_naked: // compat entry point
> > stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
> > syscall number
> > enable_dbg_and_irq
> > @@ -737,6 +741,12 @@ ni_sys:
> > b   ret_fast_syscall
> >  ENDPROC(el0_svc)
> >  
> > +#ifdef CONFIG_ARM64_ILP32
> > +el0_ilp32_svc:
> > +   adrpstbl, sys_call_ilp32_table // load syscall table pointer
> > +   b el0_svc_naked
> > +#endif
> > +
> > /*
> >  * This is the really slow path.  We're going to be doing context
> >  * switches, and waiting for our parent to respond.
> 
> -- 
> Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-04-13 Thread Yury Norov
Hi Bamvor,

On Wed, Apr 13, 2016 at 05:19:28PM +0800, Zhangjian (Bamvor) wrote:
> Hi, Yury and Philipp
> 
> There is a small fix for this patch. Othervise our tools of living
> patch could not work.
> 
> Regards
> 
> Bamvor
> 
> From e05770efca9f040e0039a4a9c4e0d7d3b2bd13e8 Mon Sep 17 00:00:00 2001
> From: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
> Date: Wed, 13 Apr 2016 15:46:28 +0800
> Subject: [PATCH] arm64: ilp32: do not check vdso-ilp32-offsets.h when ILP32
>  disabled
> 
> vdso-ilp32-offsets.h is the dependency of all the arm64-obj-y. And
> it does not exist when CONFIG_ARM64_ILP32 is disable which lead to
> all the arm64-obj-y are re-built unnecessarily.
> 
> Such rebuild may confuse the sofware(e.g. tools of living patch)
> which need to know exactly which file(s) is(are) updated.
> 
> This patch fix this issue by adding the config checker.

It looks reasonable and correct.

I'll apply your patch in next submission (if it will be needed),
otherwise I think, Arnd may apply it. 

Though, I don't understand much, what 'tools of living patch' means.
Could you explain in details what you do, and what goes wrong?

Nevertheless, thank you for your attention to this patchset.

Yury.

> 
> Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
> ---
>  arch/arm64/kernel/Makefile | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> index b43ff12..0f27a10 100644
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -60,5 +60,7 @@ $(call objectify,$(arm64-obj-y)): $(obj)/vdso/vdso-offsets.h
>  $(obj)/vdso/vdso-offsets.h: $(obj)/vdso
> 
>  # vDSO - this must be built first to generate the symbol offsets
> +ifeq ($(CONFIG_ARM64_ILP32),y)
>  $(call objectify,$(arm64-obj-y)): $(obj)/vdso-ilp32/vdso-ilp32-offsets.h
>  $(obj)/vdso-ilp32/vdso-ilp32-offsets.h: $(obj)/vdso-ilp32
> +endif
> --
> 1.8.4.5
> 
> On 2016/4/6 6:08, Yury Norov wrote:
> >From: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
> >
> >ILP32 VDSO exports next symbols:
> >  __kernel_rt_sigreturn;
> >  __kernel_gettimeofday;
> >  __kernel_clock_gettime;
> >  __kernel_clock_getres;
> >
> >What shared object to use, kernel selects depending on result of
> >is_ilp32_compat_task() in arch/arm64/kernel/vdso.c, so it substitutes
> >correct pages and spec.
> >
> >Adjusted to move the move data page before code pages in sync with
> >commit 601255ae3c98fd3a8bb4696425e4f868b4f1
> >
> >Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
> >Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
> >Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
> >---
> >  arch/arm64/include/asm/vdso.h |  6 ++
> >  arch/arm64/kernel/Makefile|  5 ++
> >  arch/arm64/kernel/signal.c|  2 +
> >  arch/arm64/kernel/vdso-ilp32/.gitignore   |  2 +
> >  arch/arm64/kernel/vdso-ilp32/Makefile | 72 
> >  arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S | 33 ++
> >  arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S | 95 
> > +++
> >  arch/arm64/kernel/vdso.c  | 61 ++---
> >  8 files changed, 266 insertions(+), 10 deletions(-)
> >  create mode 100644 arch/arm64/kernel/vdso-ilp32/.gitignore
> >  create mode 100644 arch/arm64/kernel/vdso-ilp32/Makefile
> >  create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S
> >  create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
> >
> >diff --git a/arch/arm64/include/asm/vdso.h b/arch/arm64/include/asm/vdso.h
> >index 839ce00..649a9a4 100644
> >--- a/arch/arm64/include/asm/vdso.h
> >+++ b/arch/arm64/include/asm/vdso.h
> >@@ -29,6 +29,12 @@
> >
> >  #include 
> >
> >+#ifdef CONFIG_ARM64_ILP32
> >+#include 
> >+#else
> >+#define vdso_offset_sigtramp_ilp32
> >+#endif
> >+
> >  #define VDSO_SYMBOL(base, name)
> >\
> >  ({\
> > (void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \
> >diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> >index 09e4373..b43ff12 100644
> >--- a/arch/arm64/kernel/Makefile
> >+++ b/arch/arm64/kernel/Makefile
> >@@ -50,6 +50,7 @@ arm64-obj-$(CONFIG_PARAVIRT)   += paravirt.o
> >  arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
> >
> >  o

Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-04-06 Thread Yury Norov
Hi Geert,

On Wed, Apr 06, 2016 at 08:51:50AM +0200, Geert Uytterhoeven wrote:
> Hi Yuri,
> 
> On Wed, Apr 6, 2016 at 12:08 AM, Yury Norov <yno...@caviumnetworks.com> wrote:
> > This version is rebased on kernel v4.6-rc2, and has fixes in signal 
> > subsystem.
> > It works with updated glibc [1] (though very draft), and tested with LTP.
> >
> > It was tested on QEMU and ThunderX machines. No major difference found.
> > This is RFC because ILP32 is not tested in big-endian mode.
> >
> >  v3: https://lkml.org/lkml/2014/9/3/704
> >  v4: https://lkml.org/lkml/2015/4/13/691
> >  v5: https://lkml.org/lkml/2015/9/29/911
> >
> >  v6:
> >  - time_t, __kenel_off_t and other types turned to be 32-bit
> >for compatibility reasons (after v5 discussion);
> 
> Reading this sparked my interest, so I went to the links above...

Great! I'll add you to CC than.

> 
> What makes you think these "applications that can’t readily be migrated to 
> LP64
> because they were written assuming an ILP32 data model, and that will never
> become suitable for a LP64 data model and will remain locked into ILP32
> operating environments" are more likely to be fixed for y2038 later, than for
> LP64 now?
> 

It was written by Philipp, not me:
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-April/337350.html

I'm not the author of this, and I don't think so. Maybe just because I
didn't see all that legacy nightmare, as Philipp does...

Chris Tyler shares relatively common point of view in his video from
Linaro Connect:
https://www.youtube.com/watch?v=QsVLsw_LrJ0

Briefly, we need it (mostly) for compatibility and (then) for performance.
Maybe Prasun can share more details and examples.

> We're already closer to the (future) y2038 than to the (past) introduction of
> LP64...
> 

This is not about Y2038 at all. In fact, current version doesn't fix
Y2038 problem, as we decided finally.

After v4 and v5, it was spread discussion about what ilp32 should do,
and what not. Finally we decided to be not like aarch32, and not like
lp64, and don't fix any issues specifically, but be standard compat
format, as much as possible. So, any improvements and fixes applied
to generic compat will be applied to ilp32 with minimal efforts.

> These unfixable legacy applications have been spreading through x32 to
> the shiny new arm64 server architecture (does ppc64el also have an ILP32 mode,
> or is it planned)?

I don't think this is the question you really don't know the answer.
Almost everywhere shiny arm64 comes with old and ugly aarch32 IP core.
If no, like ThunderX, people really worry about that. And for me,
configurable option in kernel sources is better tradeoff than billions
transistors in every chip on market. So Cavium here is more
future-oriented than many others...

The other example is ACPI. We have nice and cute device tree, don't we?
Does it make sense to vendors?

> Lots of resources are spent on maintaining the status quo,
> instead of on fixing the real problems.
> 

I think, compatibility is one of real problems. Aarch32 is hardware
solution, and ilp32 is software one.

Yury.

> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64 - LTP results

2016-04-05 Thread Yury Norov
There are about 20 failing tests of 782 in lite scenario.
float_bessel 
float_exp_log
float_iperb
float_power
float_trigo
pipeio_1 
pipeio_3 
pipeio_5 
pipeio_8 
abort01  
clone02  
kill11   
mmap16   
open12   
pause01
rename11 
rmdir02  
umount2_01   
umount2_02   
umount2_03   
utime06  
mtest06  

The list is rough because some tests fail not every time.

Tests abort01 and kill11 fail for lp64 too, so maybe there's
a reason unrelated to ilp32 itself.

float_xxx tests fail because they call unwind() from signal context,
and GCC for ilp32 has problem with it, as Andrew told.

pipeio_x tests are very unstable and may fail randomly. I strongly
suspect race conditions, as they all work like a charm if pinned to
single CPU with taskset. Probably, race is the reason of clone02 too.
Though I'm not sure, is the race in kernel, glibc or test itself.

But I know for sure that pause01 fails due to test design:
if (setitimer(ITIMER_REAL, , NULL)) // For 1000us
tst_brkm(TBROK | TERRNO, NULL, "setitimer() failed");

TEST(pause());

As setitimer() and pause() calls are not atomic, alarm may come before pause()
is called, and be silently dropped by the handler. Next pause() call hangs
test forever. I already reported to LTP list.

open12, rename11, rmdir02, mmap16, mtest06 - all call mkfs tool, and it returns
error code. I didn't investigate it much yet.

umount02_x, utime06 - cannot reproduce out of scenario, even run it in infinite
loop - they work fine.

Full test log is attached.

Yury


ltplite.tar.gz
Description: application/gzip


[PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-04-05 Thread Yury Norov
From: Philipp Tomsich <philipp.toms...@theobroma-systems.com>

ILP32 VDSO exports next symbols:
 __kernel_rt_sigreturn;
 __kernel_gettimeofday;
 __kernel_clock_gettime;
 __kernel_clock_getres;

What shared object to use, kernel selects depending on result of
is_ilp32_compat_task() in arch/arm64/kernel/vdso.c, so it substitutes
correct pages and spec.

Adjusted to move the move data page before code pages in sync with
commit 601255ae3c98fd3a8bb4696425e4f868b4f1

Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/vdso.h |  6 ++
 arch/arm64/kernel/Makefile|  5 ++
 arch/arm64/kernel/signal.c|  2 +
 arch/arm64/kernel/vdso-ilp32/.gitignore   |  2 +
 arch/arm64/kernel/vdso-ilp32/Makefile | 72 
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S | 33 ++
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S | 95 +++
 arch/arm64/kernel/vdso.c  | 61 ++---
 8 files changed, 266 insertions(+), 10 deletions(-)
 create mode 100644 arch/arm64/kernel/vdso-ilp32/.gitignore
 create mode 100644 arch/arm64/kernel/vdso-ilp32/Makefile
 create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S
 create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S

diff --git a/arch/arm64/include/asm/vdso.h b/arch/arm64/include/asm/vdso.h
index 839ce00..649a9a4 100644
--- a/arch/arm64/include/asm/vdso.h
+++ b/arch/arm64/include/asm/vdso.h
@@ -29,6 +29,12 @@
 
 #include 
 
+#ifdef CONFIG_ARM64_ILP32
+#include 
+#else
+#define vdso_offset_sigtramp_ilp32
+#endif
+
 #define VDSO_SYMBOL(base, name)
   \
 ({\
(void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 09e4373..b43ff12 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -50,6 +50,7 @@ arm64-obj-$(CONFIG_PARAVIRT)  += paravirt.o
 arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
 
 obj-y  += $(arm64-obj-y) vdso/
+obj-$(CONFIG_ARM64_ILP32)  += vdso-ilp32/
 obj-m  += $(arm64-obj-m)
 head-y := head.o
 extra-y+= $(head-y) vmlinux.lds
@@ -57,3 +58,7 @@ extra-y   += $(head-y) 
vmlinux.lds
 # vDSO - this must be built first to generate the symbol offsets
 $(call objectify,$(arm64-obj-y)): $(obj)/vdso/vdso-offsets.h
 $(obj)/vdso/vdso-offsets.h: $(obj)/vdso
+
+# vDSO - this must be built first to generate the symbol offsets
+$(call objectify,$(arm64-obj-y)): $(obj)/vdso-ilp32/vdso-ilp32-offsets.h
+$(obj)/vdso-ilp32/vdso-ilp32-offsets.h: $(obj)/vdso-ilp32
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 45bcd96..933cdcf 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -264,6 +264,8 @@ void setup_return(struct pt_regs *regs, struct k_sigaction 
*ka,
 
if (ka->sa.sa_flags & SA_RESTORER)
sigtramp = ka->sa.sa_restorer;
+   else if (is_ilp32_compat_task())
+   sigtramp = VDSO_SYMBOL(current->mm->context.vdso, 
sigtramp_ilp32);
else
sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
 
diff --git a/arch/arm64/kernel/vdso-ilp32/.gitignore 
b/arch/arm64/kernel/vdso-ilp32/.gitignore
new file mode 100644
index 000..61806c3
--- /dev/null
+++ b/arch/arm64/kernel/vdso-ilp32/.gitignore
@@ -0,0 +1,2 @@
+vdso-ilp32.lds
+vdso-ilp32-offsets.h
diff --git a/arch/arm64/kernel/vdso-ilp32/Makefile 
b/arch/arm64/kernel/vdso-ilp32/Makefile
new file mode 100644
index 000..c8f5472
--- /dev/null
+++ b/arch/arm64/kernel/vdso-ilp32/Makefile
@@ -0,0 +1,72 @@
+#
+# Building a vDSO image for AArch64.
+#
+# Author: Will Deacon <will.dea...@arm.com>
+# Heavily based on the vDSO Makefiles for other archs.
+#
+
+obj-ilp32-vdso := gettimeofday-ilp32.o note-ilp32.o sigreturn-ilp32.o
+
+# Build rules
+targets := $(obj-ilp32-vdso) vdso-ilp32.so vdso-ilp32.so.dbg
+obj-ilp32-vdso := $(addprefix $(obj)/, $(obj-ilp32-vdso))
+
+ccflags-y := -shared -fno-common -fno-builtin
+ccflags-y += -nostdlib -Wl,-soname=linux-ilp32-vdso.so.1 \
+   $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
+
+obj-y += vdso-ilp32.o
+extra-y += vdso-ilp32.lds vdso-ilp32-offsets.h
+CPPFLAGS_vdso-ilp32.lds += -P -C -U$(ARCH) -mabi=ilp32
+
+# Force dependency (incbin is bad)
+$(obj)/vdso-ilp32.o : $(obj)/vdso-ilp32.so
+
+# Link rule for the .so file, .lds has to be first
+$(obj)/vdso-ilp32.so.dbg: $(src)/vdso-ilp32.lds $(ob

[PATCH 21/25] arm64: signal: share lp64 signal routines to ilp32

2016-04-05 Thread Yury Norov
After that, it will be possible to reuse it in ilp32.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal_common.h | 33 
 arch/arm64/kernel/signal.c | 91 +-
 2 files changed, 90 insertions(+), 34 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal_common.h

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
new file mode 100644
index 000..756ed2c
--- /dev/null
+++ b/arch/arm64/include/asm/signal_common.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 1995-2009 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 Cavium Networks.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_SIGNAL_COMMON_H
+#define __ASM_SIGNAL_COMMON_H
+
+#include 
+#include 
+#include 
+
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx);
+int restore_fpsimd_context(struct fpsimd_context __user *ctx);
+int setup_sigcontext(struct sigcontext __user *uc_mcontext, struct pt_regs 
*regs);
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
+void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
+   void __user *frame, off_t sigframe_off, int usig);
+
+#endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index be02f65..f9fbf8a 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -34,18 +34,23 @@
 #include 
 #include 
 #include 
+#include 
+
+struct sigframe {
+   struct ucontext uc;
+   u64 fp;
+   u64 lr;
+};
 
 /*
  * Do a signal return; undo the signal stack. These are aligned to 128-bit.
  */
 struct rt_sigframe {
struct siginfo info;
-   struct ucontext uc;
-   u64 fp;
-   u64 lr;
+   struct sigframe sig;
 };
 
-static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state *fpsimd = >thread.fpsimd_state;
int err;
@@ -65,7 +70,7 @@ static int preserve_fpsimd_context(struct fpsimd_context 
__user *ctx)
return err ? -EFAULT : 0;
 }
 
-static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
+int restore_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state fpsimd;
__u32 magic, size;
@@ -93,22 +98,30 @@ static int restore_fpsimd_context(struct fpsimd_context 
__user *ctx)
 }
 
 static int restore_sigframe(struct pt_regs *regs,
-   struct rt_sigframe __user *sf)
+   struct sigframe __user *sf)
 {
sigset_t set;
-   int i, err;
-   void *aux = sf->uc.uc_mcontext.__reserved;
-
+   int err;
err = __copy_from_user(, >uc.uc_sigmask, sizeof(set));
if (err == 0)
set_current_blocked();
 
+   err |= restore_sigcontext(regs, >uc.uc_mcontext);
+   return err;
+}
+
+
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user 
*uc_mcontext)
+{
+   int i, err = 0;
+   void *aux = uc_mcontext->__reserved;
+
for (i = 0; i < 31; i++)
-   __get_user_error(regs->regs[i], >uc.uc_mcontext.regs[i],
+   __get_user_error(regs->regs[i], _mcontext->regs[i],
 err);
-   __get_user_error(regs->sp, >uc.uc_mcontext.sp, err);
-   __get_user_error(regs->pc, >uc.uc_mcontext.pc, err);
-   __get_user_error(regs->pstate, >uc.uc_mcontext.pstate, err);
+   __get_user_error(regs->sp, _mcontext->sp, err);
+   __get_user_error(regs->pc, _mcontext->pc, err);
+   __get_user_error(regs->pstate, _mcontext->pstate, err);
 
/*
 * Avoid sys_rt_sigreturn() restarting.
@@ -145,10 +158,10 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
goto badframe;
 
-   if (restore_sigframe(regs, frame))
+   if (restore_sigframe(regs, >sig))
goto badframe;
 
-   if (restore_altstack(>uc.uc_stack))
+   if (restore_altstack(>sig.uc.uc_stack))
goto badframe;
 
return regs->regs[0];
@@ -162,27 +175,36 @@ badframe:
return 0;
 }
 
-static int setup_sigframe(struct rt_sigframe __user *sf,
+stat

[PATCH 19/25] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32

2016-04-05 Thread Yury Norov
Here new aarch32 ptrace syscall handler is introsuced to avoid run-time
detection of the task type.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/unistd32.h |  2 +-
 arch/arm64/kernel/ptrace.c| 50 ++-
 arch/arm64/kernel/sys32.c |  1 +
 include/linux/ptrace.h|  6 +
 kernel/ptrace.c   | 10 
 5 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index 5b925b7..f57bbe3 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -74,7 +74,7 @@ __SYSCALL(__NR_getuid, sys_getuid16)
/* 25 was sys_stime */
 __SYSCALL(25, sys_ni_syscall)
 #define __NR_ptrace 26
-__SYSCALL(__NR_ptrace, compat_sys_ptrace)
+__SYSCALL(__NR_ptrace, compat_sys_aarch32_ptrace)
/* 27 was sys_alarm */
 __SYSCALL(27, sys_ni_syscall)
/* 28 was sys_fstat */
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 38a09338..a861105 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1114,7 +1115,7 @@ static int compat_ptrace_sethbpregs(struct task_struct 
*tsk, compat_long_t num,
 }
 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
 
-long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+static long compat_a32_ptrace(struct task_struct *child, compat_long_t request,
compat_ulong_t caddr, compat_ulong_t cdata)
 {
unsigned long addr = caddr;
@@ -1191,8 +1192,55 @@ long compat_arch_ptrace(struct task_struct *child, 
compat_long_t request,
 
return ret;
 }
+
+COMPAT_SYSCALL_DEFINE4(aarch32_ptrace, compat_long_t, request, compat_long_t, 
pid,
+  compat_long_t, addr, compat_long_t, data)
+{
+   struct task_struct *child;
+   long ret;
+
+   if (request == PTRACE_TRACEME) {
+   ret = ptrace_traceme();
+   goto out;
+   }
+
+   child = ptrace_get_task_struct(pid);
+   if (IS_ERR(child)) {
+   ret = PTR_ERR(child);
+   goto out;
+   }
+
+   if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
+   ret = ptrace_attach(child, request, addr, data);
+   goto out_put_task_struct;
+   }
+
+   ret = ptrace_check_attach(child, request == PTRACE_KILL ||
+ request == PTRACE_INTERRUPT);
+   if (!ret) {
+   ret = compat_a32_ptrace(child, request, addr, data);
+   if (ret || request != PTRACE_DETACH)
+   ptrace_unfreeze_traced(child);
+   }
+
+ out_put_task_struct:
+   put_task_struct(child);
+ out:
+   return ret;
+}
+
 #endif /* CONFIG_AARCH32_EL0 */
 
+#ifdef CONFIG_COMPAT
+
+long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+   compat_ulong_t caddr, compat_ulong_t cdata)
+{
+   return compat_ptrace_request(child, request, caddr, cdata);
+}
+
+#endif /* CONFIG_COMPAT */
+
 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 {
 #ifdef CONFIG_AARCH32_EL0
diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c
index a40b134..3752443 100644
--- a/arch/arm64/kernel/sys32.c
+++ b/arch/arm64/kernel/sys32.c
@@ -38,6 +38,7 @@ asmlinkage long compat_sys_fadvise64_64_wrapper(void);
 asmlinkage long compat_sys_sync_file_range2_wrapper(void);
 asmlinkage long compat_sys_fallocate_wrapper(void);
 asmlinkage long compat_sys_mmap2_wrapper(void);
+asmlinkage long compat_sys_aarch32_ptrace(void);
 
 #undef __SYSCALL
 #define __SYSCALL(nr, sym) [nr] = sym,
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 504c98a..75887a0 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -97,6 +97,12 @@ int generic_ptrace_peekdata(struct task_struct *tsk, 
unsigned long addr,
unsigned long data);
 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
unsigned long data);
+int ptrace_traceme(void);
+struct task_struct *ptrace_get_task_struct(pid_t pid);
+int ptrace_attach(struct task_struct *task, long request,
+unsigned long addr, unsigned long flags);
+int ptrace_check_attach(struct task_struct *child, bool ignore_state);
+void ptrace_unfreeze_traced(struct task_struct *task);
 
 /**
  * ptrace_parent - return the task that is tracing the given task
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index d49bfa1..cadf24c 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -136,7 +136,7 @@ static bool ptrace_freeze_traced(struct task_struct *task)
return ret;
 }
 
-static void ptrace_unfreeze_traced(struct task_struct *task)
+void ptrace_unfreeze_

[PATCH 14/25] thread: move thread bits accessors to separated file

2016-04-05 Thread Yury Norov
They may be accessed from low-level code, so isolating is a measure to
avoid circular dependencies in header files.

The exact reason for circular dependency is WARN_ON() macro added by Al
Viro in patch "set_restore_sigmask() is never called without SIGPENDING
(and never should be)" [edd63a27]

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 include/linux/thread_bits.h | 55 +
 include/linux/thread_info.h | 44 +---
 2 files changed, 56 insertions(+), 43 deletions(-)
 create mode 100644 include/linux/thread_bits.h

diff --git a/include/linux/thread_bits.h b/include/linux/thread_bits.h
new file mode 100644
index 000..0d05d16
--- /dev/null
+++ b/include/linux/thread_bits.h
@@ -0,0 +1,55 @@
+
+/* thread_bits.h: common low-level thread bits accessors */
+
+#ifndef _LINUX_THREAD_BITS_H
+#define _LINUX_THREAD_BITS_H
+
+#ifndef __ASSEMBLY__
+
+#include 
+#include 
+
+/*
+ * flag set/clear/test wrappers
+ * - pass TIF_ constants to these functions
+ */
+
+static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   set_bit(flag, (unsigned long *)>flags);
+}
+
+static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   clear_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   return test_and_set_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int 
flag)
+{
+   return test_and_clear_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   return test_bit(flag, (unsigned long *)>flags);
+}
+
+#define set_thread_flag(flag) \
+   set_ti_thread_flag(current_thread_info(), flag)
+#define clear_thread_flag(flag) \
+   clear_ti_thread_flag(current_thread_info(), flag)
+#define test_and_set_thread_flag(flag) \
+   test_and_set_ti_thread_flag(current_thread_info(), flag)
+#define test_and_clear_thread_flag(flag) \
+   test_and_clear_ti_thread_flag(current_thread_info(), flag)
+#define test_thread_flag(flag) \
+   test_ti_thread_flag(current_thread_info(), flag)
+
+#endif /* !__ASSEMBLY__ */
+#endif /* _LINUX_THREAD_BITS_H */
+
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index b4c2a48..b094aed 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -50,8 +50,7 @@ struct restart_block {
 
 extern long do_no_restart_syscall(struct restart_block *parm);
 
-#include 
-#include 
+#include 
 
 #ifdef __KERNEL__
 
@@ -62,47 +61,6 @@ extern long do_no_restart_syscall(struct restart_block 
*parm);
 # define THREADINFO_GFP(GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
 #endif
 
-/*
- * flag set/clear/test wrappers
- * - pass TIF_ constants to these functions
- */
-
-static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   set_bit(flag, (unsigned long *)>flags);
-}
-
-static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   clear_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   return test_and_set_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int 
flag)
-{
-   return test_and_clear_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   return test_bit(flag, (unsigned long *)>flags);
-}
-
-#define set_thread_flag(flag) \
-   set_ti_thread_flag(current_thread_info(), flag)
-#define clear_thread_flag(flag) \
-   clear_ti_thread_flag(current_thread_info(), flag)
-#define test_and_set_thread_flag(flag) \
-   test_and_set_ti_thread_flag(current_thread_info(), flag)
-#define test_and_clear_thread_flag(flag) \
-   test_and_clear_ti_thread_flag(current_thread_info(), flag)
-#define test_thread_flag(flag) \
-   test_ti_thread_flag(current_thread_info(), flag)
-
 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
 
 #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/25] arm64: ilp32: introduce binfmt_ilp32.c

2016-04-05 Thread Yury Norov
to handle ILP32 binaries

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/kernel/Makefile   |  1 +
 arch/arm64/kernel/binfmt_ilp32.c | 91 
 2 files changed, 92 insertions(+)
 create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 6bc9738..9dfdf86 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..a934fd4
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,91 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+
+#include 
+#include 
+
+#undef ELF_CLASS
+#define ELF_CLASS  ELFCLASS32
+
+#undef elfhdr
+#undef elf_phdr
+#undef elf_shdr
+#undef elf_note
+#undef elf_addr_t
+#define elfhdr elf32_hdr
+#define elf_phdr   elf32_phdr
+#define elf_shdr   elf32_shdr
+#define elf_note   elf32_note
+#define elf_addr_t Elf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_t compat_siginfo_t
+#define copy_siginfo_to_user   copy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatus   compat_elf_prstatus
+#define elf_prpsinfo   compat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+ struct compat_timeval *value)
+{
+   struct timeval tv;
+   cputime_to_timeval(cputime, );
+   value->tv_sec = tv.tv_sec;
+   value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)  (((x)->e_machine == EM_AARCH64) \
+   && (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {   \
+   set_thread_flag(TIF_32BIT_AARCH64); \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)(long)current->mm->context.vdso);   \
+} while (0)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("aarch64_be:ilp32")
+#else
+#define COMPAT_ELF_PLATFORM("aarch64:ilp32")
+#endif
+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP  ((u32) elf_hwcap)
+#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_format compat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmtexit_compat_elf_binfmt
+
+#include "../../../fs/binfmt_elf.c"
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/25] arm64:uapi: set __BITS_PER_LONG correctly for ILP32 and LP64

2016-04-05 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

Define __BITS_PER_LONG depending on the ABI used (i.e. check whether
__ILP32__ or __LP64__ is defined).  This is necessary for glibc to
determine the appropriate type definitions for the system call interface.

Signed-off-by: Andrew Pinski <apin...@cavium.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/include/uapi/asm/bitsperlong.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/uapi/asm/bitsperlong.h 
b/arch/arm64/include/uapi/asm/bitsperlong.h
index fce9c29..4265243 100644
--- a/arch/arm64/include/uapi/asm/bitsperlong.h
+++ b/arch/arm64/include/uapi/asm/bitsperlong.h
@@ -16,7 +16,14 @@
 #ifndef __ASM_BITSPERLONG_H
 #define __ASM_BITSPERLONG_H
 
-#define __BITS_PER_LONG 64
+#if defined(__LP64__)
+/* Assuming __LP64__ will be defined for native ELF64's and not for ILP32. */
+#  define __BITS_PER_LONG 64
+#elif defined(__ILP32__)
+#  define __BITS_PER_LONG 32
+#else
+#  error "Neither LP64 nor ILP32: unsupported ABI in asm/bitsperlong.h"
+#endif
 
 #include 
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/25] arm64: signal32: move ilp32 and aarch32 common code to separated file

2016-04-05 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal32_common.h |  25 +++
 arch/arm64/kernel/Makefile   |   1 +
 arch/arm64/kernel/signal32.c |  85 ---
 arch/arm64/kernel/signal32_common.c  | 115 +++
 4 files changed, 141 insertions(+), 85 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal32_common.h
 create mode 100644 arch/arm64/kernel/signal32_common.c

diff --git a/arch/arm64/include/asm/signal32_common.h 
b/arch/arm64/include/asm/signal32_common.h
new file mode 100644
index 000..b4f2099
--- /dev/null
+++ b/arch/arm64/include/asm/signal32_common.h
@@ -0,0 +1,25 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGNAL32_COMMON_H
+#define __ASM_SIGNAL32_COMMON_H
+
+#ifdef CONFIG_COMPAT
+
+int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from);
+int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from);
+
+#endif /* CONFIG_COMPAT*/
+
+#endif /* __ASM_SIGNAL32_COMMON_H */
+
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 7aa65ea..3ed55eb 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -29,6 +29,7 @@ arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o 
kuser32.o signal32.o \
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
 arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
+arm64-obj-$(CONFIG_COMPAT) += signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c
index b7063de..b103af3 100644
--- a/arch/arm64/kernel/signal32.c
+++ b/arch/arm64/kernel/signal32.c
@@ -125,91 +125,6 @@ static inline int get_sigset_t(sigset_t *set,
return 0;
 }
 
-int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
-{
-   int err;
-
-   if (!access_ok(VERIFY_WRITE, to, sizeof(*to)))
-   return -EFAULT;
-
-   /* If you change siginfo_t structure, please be sure
-* this code is fixed accordingly.
-* It should never copy any pad contained in the structure
-* to avoid security leaks, but must copy the generic
-* 3 ints plus the relevant union member.
-* This routine must convert siginfo from 64bit to 32bit as well
-* at the same time.
-*/
-   err = __put_user(from->si_signo, >si_signo);
-   err |= __put_user(from->si_errno, >si_errno);
-   err |= __put_user((short)from->si_code, >si_code);
-   if (from->si_code < 0)
-   err |= __copy_to_user(>_sifields._pad, 
>_sifields._pad,
- SI_PAD_SIZE);
-   else switch (from->si_code & __SI_MASK) {
-   case __SI_KILL:
-   err |= __put_user(from->si_pid, >si_pid);
-   err |= __put_user(from->si_uid, >si_uid);
-   break;
-   case __SI_TIMER:
-err |= __put_user(from->si_tid, >si_tid);
-err |= __put_user(from->si_overrun, >si_overrun);
-err |= __put_user(from->si_int, >si_int);
-   break;
-   case __SI_POLL:
-   err |= __put_user(from->si_band, >si_band);
-   err |= __put_user(from->si_fd, >si_fd);
-   break;
-   case __SI_FAULT:
-   err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
- >si_addr);
-#ifdef BUS_MCEERR_AO
-   /*
-* Other callers might not initialize the si_lsb field,
-* so check explicitly for the right codes here.
-*/
-   if (from->si_signo == SIGBUS &&
-   (from->si_code == BUS_MCEERR_AR || from->si_code == 
BUS_MCEERR_AO))
-   err |= __put_user(from->si_addr_lsb, >si_addr_lsb);
-#endif
-   break;
-   case __SI_CHLD:
-   err |= __put_user(from->si_pid, >si_pid);
-  

[PATCH 17/25] arm64: introduce binfmt_elf32.c

2016-04-05 Thread Yury Norov
As we support more than one compat formats, it looks more reasonable
to not use fs/compat_binfmt.c. Custom binfmt_elf32.c allows to move aarch32
specific definitions there and make code more maintainable and readable.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/Kconfig   |  1 -
 arch/arm64/include/asm/elf.h | 24 
 arch/arm64/include/asm/hwcap.h   |  2 --
 arch/arm64/kernel/Makefile   |  2 +-
 arch/arm64/kernel/binfmt_elf32.c | 33 +
 5 files changed, 34 insertions(+), 28 deletions(-)
 create mode 100644 arch/arm64/kernel/binfmt_elf32.c

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index ebaf38a..46fc295 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -931,7 +931,6 @@ config COMPAT
 config AARCH32_EL0
bool "Kernel support for 32-bit EL0"
depends on ARM64_4K_PAGES || EXPERT
-   select COMPAT_BINFMT_ELF
select HAVE_UID16
select OLD_SIGSUSPEND3
select COMPAT_OLD_SIGACTION
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index e18bb8a..7a39683 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -166,12 +166,6 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
 
 #ifdef CONFIG_COMPAT
 
-#ifdef __AARCH64EB__
-#define COMPAT_ELF_PLATFORM("v8b")
-#else
-#define COMPAT_ELF_PLATFORM("v8l")
-#endif
-
 #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)
 
 /* AArch32 registers. */
@@ -179,24 +173,6 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
 typedef unsigned int   compat_elf_greg_t;
 typedef compat_elf_greg_t  compat_elf_gregset_t[COMPAT_ELF_NGREG];
 
-/* AArch32 EABI. */
-#define EF_ARM_EABI_MASK   0xff00
-#define compat_elf_check_arch(x)   (((x)->e_machine == EM_ARM) && \
-((x)->e_flags & EF_ARM_EABI_MASK))
-
-#define compat_start_threadcompat_start_thread
-#define COMPAT_SET_PERSONALITY(ex) \
-do {   \
-   clear_thread_flag(TIF_32BIT_AARCH64);   \
-   set_thread_flag(TIF_32BIT); \
-} while (0)
-
-#define COMPAT_ARCH_DLINFO
-extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
- int uses_interp);
-#define compat_arch_setup_additional_pages \
-   aarch32_setup_vectors_page
-
 #endif /* CONFIG_COMPAT */
 
 #endif /* !__ASSEMBLY__ */
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 2c7fc5d..99dfd92 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -47,8 +47,6 @@
 #define ELF_HWCAP  (elf_hwcap)
 
 #ifdef CONFIG_AARCH32_EL0
-#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
-#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
 extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
 #endif
 
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 75dd250..6bc9738 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -27,7 +27,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
-  ../../arm/kernel/opcodes.o
+  ../../arm/kernel/opcodes.o 
binfmt_elf32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
new file mode 100644
index 000..5487872
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -0,0 +1,33 @@
+/*
+ * Support for AArch32 Linux ELF binaries.
+ */
+
+/* AArch32 EABI. */
+#define EF_ARM_EABI_MASK   0xff00
+#define compat_elf_check_arch(x)   (((x)->e_machine == EM_ARM) && \
+((x)->e_flags & EF_ARM_EABI_MASK))
+
+#define compat_start_threadcompat_start_thread
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
+#define COMPAT_ARCH_DLINFO
+#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
+#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("v8b")
+#else
+#define COMPAT_ELF_PLATFORM("v8l")
+#endif
+
+#define compat_arch_setup_additional_pages \
+  

[PATCH 15/25] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-04-05 Thread Yury Norov
Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/include/asm/compat.h  | 19 ++--
 arch/arm64/include/asm/elf.h | 10 +++
 arch/arm64/include/asm/ftrace.h  |  2 +-
 arch/arm64/include/asm/is_compat.h   | 58 
 arch/arm64/include/asm/memory.h  |  3 +-
 arch/arm64/include/asm/processor.h   |  5 ++--
 arch/arm64/include/asm/syscall.h |  2 +-
 arch/arm64/include/asm/thread_info.h |  2 +-
 arch/arm64/kernel/hw_breakpoint.c| 10 +++
 arch/arm64/kernel/perf_regs.c|  2 +-
 arch/arm64/kernel/process.c  |  7 ++---
 arch/arm64/kernel/ptrace.c   | 11 ---
 arch/arm64/kernel/signal.c   |  4 +--
 arch/arm64/kernel/traps.c|  3 +-
 14 files changed, 91 insertions(+), 47 deletions(-)
 create mode 100644 arch/arm64/include/asm/is_compat.h

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index eb8432b..df2f72d 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -24,6 +24,8 @@
 #include 
 #include 
 
+#include 
+
 #define COMPAT_USER_HZ 100
 #ifdef __AARCH64EB__
 #define COMPAT_UTS_MACHINE "armv8b\0\0"
@@ -298,23 +300,6 @@ struct compat_shmid64_ds {
compat_ulong_t __unused5;
 };
 
-static inline int is_compat_task(void)
-{
-   return test_thread_flag(TIF_32BIT);
-}
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return test_ti_thread_flag(thread, TIF_32BIT);
-}
-
-#else /* !CONFIG_COMPAT */
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return 0;
-}
-
 #endif /* CONFIG_COMPAT */
 #endif /* __KERNEL__ */
 #endif /* __ASM_COMPAT_H */
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 24ed037..b5437c5 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -16,6 +16,10 @@
 #ifndef __ASM_ELF_H
 #define __ASM_ELF_H
 
+#ifndef __ASSEMBLY__
+#include 
+#endif
+
 #include 
 
 /*
@@ -152,13 +156,9 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
   int uses_interp);
 
 /* 1GB of VA */
-#ifdef CONFIG_COMPAT
-#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+#define STACK_RND_MASK (is_compat_task() ? \
0x7ff >> (PAGE_SHIFT - 12) : \
0x3 >> (PAGE_SHIFT - 12))
-#else
-#define STACK_RND_MASK (0x3 >> (PAGE_SHIFT - 12))
-#endif
 
 #ifdef CONFIG_COMPAT
 
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index caa955f..0feb28a 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -54,7 +54,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long 
addr)
 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
 {
-   return is_compat_task();
+   return is_a32_compat_task();
 }
 #endif /* ifndef __ASSEMBLY__ */
 
diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
new file mode 100644
index 000..6139b5a
--- /dev/null
+++ b/arch/arm64/include/asm/is_compat.h
@@ -0,0 +1,58 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_IS_COMPAT_H
+#define __ASM_IS_COMPAT_H
+#ifndef __ASSEMBLY__
+
+#include 
+
+#ifdef CONFIG_AARCH32_EL0
+
+static inline int is_a32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT);
+}
+
+static inline int is_a32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT);
+}
+
+#else
+
+static inline int is_a32_compat_task(void)
+
+

[PATCH 09/25] arm64: ensure the kernel is compiled for LP64

2016-04-05 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

The kernel needs to be compiled as a LP64 binary for ARM64, even when
using a compiler that defaults to code-generation for the ILP32 ABI.
Consequently, we need to explicitly pass '-mabi=lp64' (supported on
gcc-4.9 and newer).

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/Makefile | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 354d754..29ebf23 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -35,14 +35,19 @@ KBUILD_CFLAGS   += -fno-asynchronous-unwind-tables
 KBUILD_CFLAGS  += $(call cc-option, -mpc-relative-literal-loads)
 KBUILD_AFLAGS  += $(lseinstr)
 
+KBUILD_CFLAGS  += $(call cc-option,-mabi=lp64)
+KBUILD_AFLAGS  += $(call cc-option,-mabi=lp64)
+
 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
 KBUILD_CPPFLAGS+= -mbig-endian
 AS += -EB
 LD += -EB
+LDFLAGS+= -maarch64linuxb
 else
 KBUILD_CPPFLAGS+= -mlittle-endian
 AS += -EL
 LD += -EL
+LDFLAGS+= -maarch64linux
 endif
 
 CHECKFLAGS += -D__aarch64__
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/25] arm64: ilp32: add is_ilp32_compat_{task,thread} and TIF_32BIT_AARCH64

2016-04-05 Thread Yury Norov
ILP32 tasks are needed to be distinguished from lp64 and aarch32.
This patch adds helper functions is_ilp32_compat_{task,thread} and
thread flag TIF_32BIT_AARCH64 to address it. This is a preparation
for following patches in ilp32 patchset.

For consistency, SET_PERSONALITY are changed here accordingly.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/include/asm/elf.h | 13 +++--
 arch/arm64/include/asm/is_compat.h   | 28 +++-
 arch/arm64/include/asm/thread_info.h |  1 +
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index b5437c5..e18bb8a 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -142,7 +142,11 @@ typedef struct user_fpsimd_state elf_fpregset_t;
  */
 #define ELF_PLAT_INIT(_r, load_addr)   (_r)->regs[0] = 0
 
-#define SET_PERSONALITY(ex)clear_thread_flag(TIF_32BIT);
+#define SET_PERSONALITY(ex)\
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
 
 #define ARCH_DLINFO\
 do {   \
@@ -181,7 +185,12 @@ typedef compat_elf_greg_t  
compat_elf_gregset_t[COMPAT_ELF_NGREG];
 ((x)->e_flags & EF_ARM_EABI_MASK))
 
 #define compat_start_threadcompat_start_thread
-#define COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
 #define COMPAT_ARCH_DLINFO
 extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
  int uses_interp);
diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
index 6139b5a..55134cf 100644
--- a/arch/arm64/include/asm/is_compat.h
+++ b/arch/arm64/include/asm/is_compat.h
@@ -45,11 +45,37 @@ static inline int is_a32_compat_thread(struct thread_info 
*thread)
 
 #endif /* CONFIG_AARCH32_EL0 */
 
+#ifdef CONFIG_ARM64_ILP32
+
+static inline int is_ilp32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT_AARCH64);
+}
+
+static inline int is_ilp32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT_AARCH64);
+}
+
+#else
+
+static inline int is_ilp32_compat_task(void)
+{
+   return 0;
+}
+
+static inline int is_ilp32_compat_thread(struct thread_info *thread)
+{
+   return 0;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
 #ifdef CONFIG_COMPAT
 
 static inline int is_compat_task(void)
 {
-   return is_a32_compat_task();
+   return is_a32_compat_task() || is_ilp32_compat_task();
 }
 
 #endif /* CONFIG_COMPAT */
diff --git a/arch/arm64/include/asm/thread_info.h 
b/arch/arm64/include/asm/thread_info.h
index 4daa559..8bcfa38 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -119,6 +119,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_RESTORE_SIGMASK20
 #define TIF_SINGLESTEP 21
 #define TIF_32BIT  22  /* AARCH32 process */
+#define TIF_32BIT_AARCH64  23  /* 32 bit process on AArch64(ILP32) */
 
 #define _TIF_SIGPENDING(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED  (1 << TIF_NEED_RESCHED)
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/25] arm64: rename COMPAT to AARCH32_EL0 in Kconfig

2016-04-05 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

In this patchset  ILP32 ABI support is added. Additionally to AARCH32,
which is binary-compatible with ARM, ILP32 is (mostly) ABI-compatible.

>From now, AARCH32_EL0 (former COMPAT) config option means the support of
AARCH32 userspace, ARM64_ILP32 - support of ILP32 ABI (see next patches),
and COMPAT indicates that one of them, or both, is enabled.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
 arch/arm64/Kconfig | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 4f43622..f923687 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -925,6 +925,10 @@ menu "Userspace binary formats"
 source "fs/Kconfig.binfmt"
 
 config COMPAT
+   def_bool y
+   depends on AARCH32_EL0
+
+config AARCH32_EL0
bool "Kernel support for 32-bit EL0"
depends on ARM64_4K_PAGES || EXPERT
select COMPAT_BINFMT_ELF
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/25] compat ABI: use non-compat openat and open_by_handle_at variants

2016-04-05 Thread Yury Norov
The only difference is that non-compat version forces O_LARGEFILE,
and it should be the default behaviour for all architectures, as
we don't support 32-bit off_t. The only exception is tile32, that
continues with compat version of syscalls.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Chris Metcalf <cmetc...@ezchip.com> [for tile]
---
 arch/tile/kernel/compat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c
index 4912084..489ae19 100644
--- a/arch/tile/kernel/compat.c
+++ b/arch/tile/kernel/compat.c
@@ -94,6 +94,9 @@ COMPAT_SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned 
int, offset_high,
 #define compat_sys_readahead sys32_readahead
 #define sys_llseek compat_sys_llseek
 
+#define sys_openat compat_sys_openat
+#define sys_open_by_handle_at  compat_sys_open_by_handle_at
+
 /* Call the assembly trampolines where necessary. */
 #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn
 #define sys_clone _sys_clone
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/25] all: introduce COMPAT_WRAPPER option and enable it for s390

2016-04-05 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Heiko Carstens <heiko.carst...@de.ibm.com>
---
 arch/Kconfig  | 4 
 arch/s390/Kconfig | 1 +
 2 files changed, 5 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index 81869a5..92fcbd4 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -589,6 +589,10 @@ config HAVE_STACK_VALIDATION
  Architecture supports the 'objtool check' host tool command, which
  performs compile-time stack metadata validation.
 
+config COMPAT_WRAPPER
+   bool
+   depends on COMPAT
+
 #
 # ABI hall of shame
 #
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index aad23e3..cdc02e0 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -337,6 +337,7 @@ config COMPAT
select COMPAT_BINFMT_ELF if BINFMT_ELF
select ARCH_WANT_OLD_COMPAT_IPC
select COMPAT_OLD_SIGACTION
+   select COMPAT_WRAPPER
depends on MULTIUSER
help
  Select this option if you want to enable your system kernel to
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/25] all: s390: move wrapper infrastructure to generic headers

2016-04-05 Thread Yury Norov
This patch moves required calls to generic files to let other arches use
it if needed. Here also, additional code is introduced, as s390 uses asm
syscall tables, while in general case, wrappers may be used in C code.

__SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
unsigned long and pointer types are all 32-bit length.

linux/syscalls_structs.h header is introduced, because from now (see next patch)
structure types listed there are needed for both normal and compat mode.

cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
compat wrappers are enabled.

Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
asm-generated syscall table. But architectures that generate that tables with
C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) 
compat_##name'.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Heiko Carstens <heiko.carst...@de.ibm.com>
---
 arch/s390/include/asm/compat.h| 17 +--
 arch/s390/kernel/compat_wrapper.c | 51 -
 include/linux/compat.h| 52 +
 include/linux/syscalls.h  | 57 +
 include/linux/syscalls_structs.h  | 60 +++
 include/uapi/asm-generic/unistd.h |  4 +++
 6 files changed, 132 insertions(+), 109 deletions(-)
 create mode 100644 include/linux/syscalls_structs.h

diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 352f7bd..f412723 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -7,13 +7,26 @@
 #include 
 #include 
 
-#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), 
u64))
-
 #define __SC_DELOUSE(t,v) ({ \
BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
(t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fff) : (v)); \
 })
 
+#define __SC_COMPAT_CAST(t, a) \
+({ \
+   long __ReS = a; \
+   \
+   BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+   if (__TYPE_IS_L(t)) \
+   __ReS = (s32)a; \
+   if (__TYPE_IS_UL(t))\
+   __ReS = (u32)a; \
+   if (__TYPE_IS_PTR(t))   \
+   __ReS = a & 0x7fff; \
+   (t)__ReS;   \
+})
+
 #define PSW32_MASK_PER 0x4000UL
 #define PSW32_MASK_DAT 0x0400UL
 #define PSW32_MASK_IO  0x0200UL
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
index ae2cda5..1614e15 100644
--- a/arch/s390/kernel/compat_wrapper.c
+++ b/arch/s390/kernel/compat_wrapper.c
@@ -8,57 +8,6 @@
 #include 
 #include "entry.h"
 
-#define COMPAT_SYSCALL_WRAP1(name, ...) \
-   COMPAT_SYSCALL_WRAPx(1, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP2(name, ...) \
-   COMPAT_SYSCALL_WRAPx(2, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP3(name, ...) \
-   COMPAT_SYSCALL_WRAPx(3, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP4(name, ...) \
-   COMPAT_SYSCALL_WRAPx(4, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP5(name, ...) \
-   COMPAT_SYSCALL_WRAPx(5, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP6(name, ...) \
-   COMPAT_SYSCALL_WRAPx(6, _##name, __VA_ARGS__)
-
-#define __SC_COMPAT_TYPE(t, a) \
-   __typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
-
-#define __SC_COMPAT_CAST(t, a) \
-({ \
-   long __ReS = a; \
-   \
-   BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
-   if (__TYPE_IS_L(t)) \
-   __ReS = (s32)a; \
-   if (__TYPE_IS_UL(t))\
-   __ReS = (u32)a; \
-   if (__TYPE_IS_PTR(t)) 

[PATCH 05/25] all: wrap needed syscalls in generic unistd

2016-04-05 Thread Yury Norov
As generic unistd syscall table is written in C, syscall
prototypes declaration is needed. It's added to compat header.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Heiko Carstens <heiko.carst...@de.ibm.com>
---
 include/linux/compat.h| 225 +
 include/uapi/asm-generic/unistd.h | 227 +++---
 2 files changed, 338 insertions(+), 114 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index 4eba16e..248e015 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -789,6 +789,231 @@ asmlinkage long notrace 
compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))
 }
 #endif
 
+/* Compat wrappers */
+#include 
+asmlinkage long compat_sys_creat(const char __user *pathname, umode_t mode);
+asmlinkage long compat_sys_link(const char __user *oldname,
+   const char __user *newname);
+asmlinkage long compat_sys_chdir(const char __user *filename);
+asmlinkage long compat_sys_mknod(const char __user *filename, umode_t mode,
+   unsigned dev);
+asmlinkage long compat_sys_chmod(const char __user *filename, umode_t mode);
+asmlinkage long compat_sys_oldumount(char __user *name);
+asmlinkage long compat_sys_access(const char __user *filename, int mode);
+asmlinkage long compat_sys_rename(const char __user *oldname,
+   const char __user *newname);
+asmlinkage long compat_sys_mkdir(const char __user *pathname, umode_t mode);
+asmlinkage long compat_sys_rmdir(const char __user *pathname);
+asmlinkage long compat_sys_pipe(int __user *fildes);
+asmlinkage long compat_sys_brk(unsigned long brk);
+asmlinkage long compat_sys_signal(int sig, __sighandler_t handler);
+asmlinkage long compat_sys_acct(const char __user *name);
+asmlinkage long compat_sys_umount(char __user *name, int flags);
+asmlinkage long compat_sys_chroot(const char __user *filename);
+
+#ifdef CONFIG_OLD_SIGSUSPEND
+asmlinkage long compat_sys_sigsuspend(old_sigset_t mask);
+#endif
+
+#ifdef CONFIG_OLD_SIGSUSPEND3
+asmlinkage long compat_sys_sigsuspend(int unused1, int unused2, old_sigset_t 
mask);
+#endif
+
+asmlinkage long compat_sys_sethostname(char __user *name, int len);
+asmlinkage long compat_sys_symlink(const char __user *old, const char __user 
*new);
+asmlinkage long compat_sys_readlink(const char __user *path,
+   char __user *buf, int bufsiz);
+asmlinkage long compat_sys_uselib(const char __user *library);
+asmlinkage long compat_sys_swapon(const char __user *specialfile, int 
swap_flags);
+asmlinkage long compat_sys_reboot(int magic1, int magic2, unsigned int cmd,
+   void __user *arg);
+asmlinkage long compat_sys_munmap(unsigned long addr, size_t len);
+asmlinkage long compat_sys_munmap(unsigned long addr, size_t len);
+asmlinkage long compat_sys_syslog(int type, char __user *buf, int len);
+asmlinkage long compat_sys_swapoff(const char __user *specialfile);
+asmlinkage long compat_sys_setdomainname(char __user *name, int len);
+asmlinkage long compat_sys_newuname(struct new_utsname __user *name);
+asmlinkage long compat_sys_mprotect(unsigned long start, size_t len,
+   unsigned long prot);
+asmlinkage long compat_sys_init_module(void __user *umod, unsigned long len,
+   const char __user *uargs);
+asmlinkage long compat_sys_delete_module(const char __user *name_user,
+   unsigned int flags);
+asmlinkage long compat_sys_quotactl(unsigned int cmd, const char __user 
*special,
+   qid_t id, void __user *addr);
+asmlinkage long compat_sys_bdflush(int func, long data);
+asmlinkage long compat_sys_sysfs(int option,
+   unsigned long arg1, unsigned long arg2);
+asmlinkage long compat_sys_llseek(unsigned int fd, unsigned long offset_high,
+   unsigned long offset_low, loff_t __user *result,
+   unsigned int whence);
+asmlinkage long compat_sys_msync(unsigned long start, size_t len, int flags);
+asmlinkage long compat_sys_mlock(unsigned long start, size_t len);
+asmlinkage long compat_sys_munlock(unsigned long start, size_t len);
+asmlinkage long compat_sys_sched_setparam(pid_t pid,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_sched_getparam(pid_t pid,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_sched_setscheduler(pid_t pid, int policy,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_mremap(unsigned long addr,
+  unsigned long old_len, unsigned long new_len,
+  unsigned long flags, unsigned long new_addr);
+asmlinkage long compat_sys_poll(struct pollfd __user *ufds, unsig

[PATCH 07/25] 32-bit ABI: introduce ARCH_32BIT_OFF_T config option

2016-04-05 Thread Yury Norov
All new 32-bit architectures should have 64-bit off_t type, but existing
architectures has 32-bit ones.

To handle it, new config option is added to arch/Kconfig that defaults
ARCH_32BIT_OFF_T to be disabled for non-64 bit architectures. All existing
32-bit architectures enable it explicitly here.

New option affects force_o_largefile() behaviour. Namely, if off_t is
64-bits long, we have no reason to reject user to open big files.

Note that even if architectures has only 64-bit off_t in the kernel
(arc, c6x, h8300, hexagon, metag, nios2, openrisc, tile32 and unicore32),
a libc may use 32-bit off_t, and therefore want to limit the file size
to 4GB unless specified differently in the open flags.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Thomas Gleixner <t...@linutronix.de> (For the x86 part)
Acked-by: Arnd Bergmann <a...@arndb.de>
---
 arch/Kconfig| 4 
 arch/arc/Kconfig| 1 +
 arch/arm/Kconfig| 1 +
 arch/blackfin/Kconfig   | 1 +
 arch/cris/Kconfig   | 1 +
 arch/frv/Kconfig| 1 +
 arch/h8300/Kconfig  | 1 +
 arch/hexagon/Kconfig| 1 +
 arch/m32r/Kconfig   | 1 +
 arch/m68k/Kconfig   | 1 +
 arch/metag/Kconfig  | 1 +
 arch/microblaze/Kconfig | 1 +
 arch/mips/Kconfig   | 1 +
 arch/mn10300/Kconfig| 1 +
 arch/nios2/Kconfig  | 1 +
 arch/openrisc/Kconfig   | 1 +
 arch/parisc/Kconfig | 1 +
 arch/powerpc/Kconfig| 1 +
 arch/score/Kconfig  | 1 +
 arch/sh/Kconfig | 1 +
 arch/sparc/Kconfig  | 1 +
 arch/tile/Kconfig   | 1 +
 arch/unicore32/Kconfig  | 1 +
 arch/x86/Kconfig| 1 +
 arch/x86/um/Kconfig | 1 +
 arch/xtensa/Kconfig | 1 +
 include/linux/fcntl.h   | 2 +-
 27 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 92fcbd4..a2b7cf3 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -230,6 +230,10 @@ config ARCH_THREAD_INFO_ALLOCATOR
 config ARCH_WANTS_DYNAMIC_TASK_STRUCT
bool
 
+config ARCH_32BIT_OFF_T
+   bool
+   depends on !64BIT
+
 config HAVE_REGS_AND_STACK_ACCESS_API
bool
help
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 208aae0..52e3f9b 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -9,6 +9,7 @@
 config ARC
def_bool y
select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC
+   select ARCH_32BIT_OFF_T
select BUILDTIME_EXTABLE_SORT
select COMMON_CLK
select CLONE_BACKWARDS
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index cdfa6c2..efe3ca2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1,6 +1,7 @@
 config ARM
bool
default y
+   select ARCH_32BIT_OFF_T
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_ELF_RANDOMIZE
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index a63c122..ef4368e 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -12,6 +12,7 @@ config RWSEM_XCHGADD_ALGORITHM
 
 config BLACKFIN
def_bool y
+   select ARCH_32BIT_OFF_T
select HAVE_ARCH_KGDB
select HAVE_ARCH_TRACEHOOK
select HAVE_DYNAMIC_FTRACE
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index e086f9e..5bc9203 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -50,6 +50,7 @@ config LOCKDEP_SUPPORT
 config CRIS
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select GENERIC_ATOMIC64
select HAVE_UID16
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index eefd9a4..2f14904 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -1,6 +1,7 @@
 config FRV
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select HAVE_ARCH_TRACEHOOK
select HAVE_PERF_EVENTS
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig
index 986ea84..8c221f1 100644
--- a/arch/h8300/Kconfig
+++ b/arch/h8300/Kconfig
@@ -1,5 +1,6 @@
 config H8300
 def_bool y
+   select ARCH_32BIT_OFF_T
select GENERIC_ATOMIC64
select HAVE_UID16
select VIRT_TO_BUS
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 57298e7..df84602 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -3,6 +3,7 @@ comment "Linux Kernel Configuration for Hexagon"
 
 config HEXAGON
def_bool y
+   select ARCH_32BIT_OFF_T
select HAVE_OPROFILE
# Other pending projects/to-do items.
# select HAVE_REGS_AND_STACK_ACCESS_API
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index c82b292..7866bca 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -1,6 +1,7 @@
 config M32R
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select HAVE_OPROFILE
select INIT_ALL_POSSIBLE
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 498b567..e9897e4 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -1,6 +1,7 

[PATCH 04/25] all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/

2016-04-05 Thread Yury Norov
Some syscalls are declared conditionally, so corresponding wrappers
are conditional accordingly.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Acked-by: Heiko Carstens <heiko.carst...@de.ibm.com>
---
 arch/s390/kernel/Makefile |   2 +-
 arch/s390/kernel/compat_linux.c   |   4 +
 arch/s390/kernel/compat_wrapper.c | 129 
 kernel/Makefile   |   1 +
 kernel/compat_wrapper.c   | 175 ++
 5 files changed, 181 insertions(+), 130 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
 create mode 100644 kernel/compat_wrapper.c

diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 2f5586a..145d3d8 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -57,7 +57,7 @@ obj-$(CONFIG_HIBERNATION) += suspend.o swsusp.o
 obj-$(CONFIG_AUDIT)+= audit.o
 compat-obj-$(CONFIG_AUDIT) += compat_audit.o
 obj-$(CONFIG_COMPAT)   += compat_linux.o compat_signal.o
-obj-$(CONFIG_COMPAT)   += compat_wrapper.o $(compat-obj-y)
+obj-$(CONFIG_COMPAT)   += $(compat-obj-y)
 
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_KPROBES)  += kprobes.o
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index 437e611..783c208 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -86,6 +86,10 @@
 #define SET_STAT_UID(stat, uid)(stat).st_uid = high2lowuid(uid)
 #define SET_STAT_GID(stat, gid)(stat).st_gid = high2lowgid(gid)
 
+COMPAT_SYSCALL_WRAP3(s390_pci_mmio_write, const unsigned long, mmio_addr, 
const void __user *, user_buffer, const size_t, length);
+
+COMPAT_SYSCALL_WRAP3(s390_pci_mmio_read, const unsigned long, mmio_addr, void 
__user *, user_buffer, const size_t, length);
+
 COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
   u16, user, u16, group)
 {
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
deleted file mode 100644
index 1614e15..000
--- a/arch/s390/kernel/compat_wrapper.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *  Compat system call wrappers.
- *
- *Copyright IBM Corp. 2014
- */
-
-#include 
-#include 
-#include "entry.h"
-
-COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, 
newname);
-COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(chdir, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(mknod, const char __user *, filename, umode_t, mode, 
unsigned, dev);
-COMPAT_SYSCALL_WRAP2(chmod, const char __user *, filename, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(oldumount, char __user *, name);
-COMPAT_SYSCALL_WRAP2(access, const char __user *, filename, int, mode);
-COMPAT_SYSCALL_WRAP2(rename, const char __user *, oldname, const char __user 
*, newname);
-COMPAT_SYSCALL_WRAP2(mkdir, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(rmdir, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(pipe, int __user *, fildes);
-COMPAT_SYSCALL_WRAP1(brk, unsigned long, brk);
-COMPAT_SYSCALL_WRAP2(signal, int, sig, __sighandler_t, handler);
-COMPAT_SYSCALL_WRAP1(acct, const char __user *, name);
-COMPAT_SYSCALL_WRAP2(umount, char __user *, name, int, flags);
-COMPAT_SYSCALL_WRAP1(chroot, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(sigsuspend, int, unused1, int, unused2, old_sigset_t, 
mask);
-COMPAT_SYSCALL_WRAP2(sethostname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP2(symlink, const char __user *, old, const char __user *, 
new);
-COMPAT_SYSCALL_WRAP3(readlink, const char __user *, path, char __user *, buf, 
int, bufsiz);
-COMPAT_SYSCALL_WRAP1(uselib, const char __user *, library);
-COMPAT_SYSCALL_WRAP2(swapon, const char __user *, specialfile, int, 
swap_flags);
-COMPAT_SYSCALL_WRAP4(reboot, int, magic1, int, magic2, unsigned int, cmd, void 
__user *, arg);
-COMPAT_SYSCALL_WRAP2(munmap, unsigned long, addr, size_t, len);
-COMPAT_SYSCALL_WRAP3(syslog, int, type, char __user *, buf, int, len);
-COMPAT_SYSCALL_WRAP1(swapoff, const char __user *, specialfile);
-COMPAT_SYSCALL_WRAP2(setdomainname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP1(newuname, struct new_utsname __user *, name);
-COMPAT_SYSCALL_WRAP3(mprotect, unsigned long, start, size_t, len, unsigned 
long, prot);
-COMPAT_SYSCALL_WRAP3(init_module, void __user *, umod, unsigned long, len, 
const char __user *, uargs);
-COMPAT_SYSCALL_WRAP2(delete_module, const char __user *, name_user, unsigned 
int, flags);
-COMPAT_SYSCALL_WRAP4(quotactl, unsigned int, cmd, const char __user *, 
special, qid_t, id, void __user *, addr);
-COMPAT_SYSCALL_WRAP2(bdflush, int, func, long, data);
-COMPAT_SYSCALL_WRAP3(sysfs, int, option, unsigned long, arg1, unsigned long, 
arg2);
-COMPAT_SYSCALL_WRAP5(llseek, unsi

[PATCH 23/25] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-04-05 Thread Yury Norov
From: Andrew Pinski <apin...@cavium.com>

ILP32 uses AARCH32 compat structures and syscall handlers for signals.
But ILP32 struct rt_sigframe  and ucontext differs from both LP64 and
AARCH32. So some specific mechanism is needed to take care of it.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/arm64/include/asm/signal_ilp32.h |  34 ++
 arch/arm64/kernel/Makefile|   3 +-
 arch/arm64/kernel/entry_ilp32.S   |  23 
 arch/arm64/kernel/signal.c|   3 +
 arch/arm64/kernel/signal_ilp32.c  | 192 ++
 arch/arm64/kernel/sys_ilp32.c |   3 +
 6 files changed, 257 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/signal_ilp32.h
 create mode 100644 arch/arm64/kernel/entry_ilp32.S
 create mode 100644 arch/arm64/kernel/signal_ilp32.c

diff --git a/arch/arm64/include/asm/signal_ilp32.h 
b/arch/arm64/include/asm/signal_ilp32.h
new file mode 100644
index 000..30eff23
--- /dev/null
+++ b/arch/arm64/include/asm/signal_ilp32.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __ASM_SIGNAL_ILP32_H
+#define __ASM_SIGNAL_ILP32_H
+
+#ifdef CONFIG_ARM64_ILP32
+
+#include 
+
+int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs);
+
+#else
+
+static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
+ struct pt_regs *regs)
+{
+   return -ENOSYS;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
+#endif /* __ASM_SIGNAL_ILP32_H */
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 3ed55eb..09e4373 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,8 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o   
\
+  signal_ilp32.o entry_ilp32.o
 arm64-obj-$(CONFIG_COMPAT) += signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
diff --git a/arch/arm64/kernel/entry_ilp32.S b/arch/arm64/kernel/entry_ilp32.S
new file mode 100644
index 000..5063172
--- /dev/null
+++ b/arch/arm64/kernel/entry_ilp32.S
@@ -0,0 +1,23 @@
+/*
+ * ILP32 system call wrappers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+
+ENTRY(ilp32_sys_rt_sigreturn_wrapper)
+   mov x0, sp
+   b   ilp32_sys_rt_sigreturn
+ENDPROC(ilp32_sys_rt_sigreturn_wrapper)
+
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index f9fbf8a..45bcd96 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct sigframe {
struct ucontext uc;
@@ -323,6 +324,8 @@ static void handle_signal(struct ksignal *ksig, struct 
pt_regs *regs)
ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
else
ret = compat_setup_frame(usig, ksig, oldset, regs);
+   } else if (is_ilp32_compat_task()) {
+   ret = ilp32_setup_rt_frame(usig, ksig, oldset, regs);
} else {
ret = setup_rt_frame(usig, ksig, oldset, regs);
}
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
new file mode 100644
index 000..84

[RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-04-05 Thread Yury Norov
This version is rebased on kernel v4.6-rc2, and has fixes in signal subsystem.
It works with updated glibc [1] (though very draft), and tested with LTP.

It was tested on QEMU and ThunderX machines. No major difference found.
This is RFC because ILP32 is not tested in big-endian mode.

 v3: https://lkml.org/lkml/2014/9/3/704
 v4: https://lkml.org/lkml/2015/4/13/691
 v5: https://lkml.org/lkml/2015/9/29/911

 v6:
 - time_t, __kenel_off_t and other types turned to be 32-bit
   for compatibility reasons (after v5 discussion);
 - related changes applied to ILP32 syscall table and handlers;
 - ILP32 VDSO code excluded. It's not mandatory, and caused questions
   during review process. We definitely make sure we will follow up
   with a VDSO later on because it is needed for performance reasons;
 - fixed build issues with different combinations of AARCH32 / ILP32
   enabling in config;
 - ILP32 TLS bug fixed;
 - entry32-common.S introduced to hold wrappers needed for both ILP32
   and AARCH32_EL0;
 - documentation updated according to latest changes;
 - rebased to the current head;
 - coding style re-checked;
 - ILP32 syscall table turned around.

   rfc3:
 - all structures and system calls are just like AARCH32 ones now. with 2
   exceptions: syscalls that take 64-bit parameter in 2 32-bit regosters
   are replaced with LP64 version; struct rt_sigframe is constructed both
   from LP64 and AARCH32 fields to be consistent with AARCH64 register set;
 - documentation rewritten accordingly;
 - common code for all 3 ABIs is moved to separated files for easy use,
   new headers and objects are introduced, incl: is_compat.h, thread_bits.h,
   signal_common.h, signal32_common.h.
 - ILP32 VDSO code restored, Nathans comments are addressed;
 - patch "arm64: ilp32: force IPC_64 in msgctl, shmctl, semctl" removed, as
   Arnd suggested general solution for IPC_64 problem.

   rfc4:
 - sys_ilp32.c syscall list is fixed according to comments;
 - binfmt_elf32.c and binfmt_ilp32.c are introduced to host the code handling
   corresponding formats;
 - statfs64, fstsatfs64 and mmap wrappers are removed;
 - rebased on v4.4-rc8 + http://www.spinics.net/lists/kernel/msg2151759.html

 rfc5:
 - addressed rfc4 comments;
 - turned s390 compat wrappers to be generic and applied it to arm64/ilp32.
   Heiko Carsten and Martin Schwidefsky added to CC as s390 maintainers.

 rfc6:
 - glibc follows new ABI, [1];
 - significant rework for signal subsystem (patches 21, 23) - struct ucontext
   is now corresponds user representation;
 - compat wrappers and 32-bit off_t patchsets are joined with this patchset,
   as for now ilp32 is the only user for them;
 - moved to kernel v4.6-rc2;
 - few minor bugfixes.

[1] https://github.com/norov/glibc/tree/new-api

Andrew Pinski (7):
  arm64: ensure the kernel is compiled for LP64
  arm64: rename COMPAT to AARCH32_EL0 in Kconfig
  arm64: change some CONFIG_COMPAT over to use CONFIG_AARCH32_EL0
instead
  arm64:uapi: set __BITS_PER_LONG correctly for ILP32 and LP64
  arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use
it
  arm64: ilp32: introduce ilp32-specific handlers for sigframe and
ucontext
  arm64:ilp32: add ARM64_ILP32 to Kconfig

Bamvor Jian Zhang (1):
  arm64: compat: change config dependences to aarch32

Philipp Tomsich (1):
  arm64:ilp32: add vdso-ilp32 and use for signal return

Yury Norov (16):
  all: syscall wrappers: add documentation
  all: introduce COMPAT_WRAPPER option and enable it for s390
  all: s390: move wrapper infrastructure to generic headers
  all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/
  all: wrap needed syscalls in generic unistd
  compat ABI: use non-compat openat and open_by_handle_at variants
  32-bit ABI: introduce ARCH_32BIT_OFF_T config option
  arm64: ilp32: add documentation on the ILP32 ABI for ARM64
  thread: move thread bits accessors to separated file
  arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)
  arm64: ilp32: add is_ilp32_compat_{task,thread} and TIF_32BIT_AARCH64
  arm64: introduce binfmt_elf32.c
  arm64: ilp32: introduce binfmt_ilp32.c
  arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32
  arm64: signal: share lp64 signal routines to ilp32
  arm64: signal32: move ilp32 and aarch32 common code to separated file

 Documentation/adding-syscalls.txt |  32 +++
 Documentation/arm64/ilp32.txt |  13 ++
 arch/Kconfig  |   8 +
 arch/arc/Kconfig  |   1 +
 arch/arm/Kconfig  |   1 +
 arch/arm64/Kconfig|  17 +-
 arch/arm64/Makefile   |   5 +
 arch/arm64/include/asm/compat.h   |  19 +-
 arch/arm64/include/asm/elf.h  |  35 +---
 arch/arm64/include/asm/fpsimd.h   |   2 +-
 arch/arm64/include/asm/ftrace.h   |   2 +-
 arch/arm64/include/asm/hwcap.h   

[PATCH 4/5] all: s390: move compat_wrappers.c from arch/s390/kernel to kernel

2016-02-26 Thread Yury Norov
S390-specific wrappers are moved to arch/s390/kernel/compat_linux.c

Some syscalls are declared conditionally, so corresponding wrappers
are conditional accordingly.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/s390/kernel/Makefile |   2 +-
 arch/s390/kernel/compat_linux.c   |   4 +
 arch/s390/kernel/compat_wrapper.c | 129 -
 kernel/Makefile   |   1 +
 kernel/compat_wrapper.c   | 167 ++
 5 files changed, 173 insertions(+), 130 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
 create mode 100644 kernel/compat_wrapper.c

diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 2f5586a..145d3d8 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -57,7 +57,7 @@ obj-$(CONFIG_HIBERNATION) += suspend.o swsusp.o
 obj-$(CONFIG_AUDIT)+= audit.o
 compat-obj-$(CONFIG_AUDIT) += compat_audit.o
 obj-$(CONFIG_COMPAT)   += compat_linux.o compat_signal.o
-obj-$(CONFIG_COMPAT)   += compat_wrapper.o $(compat-obj-y)
+obj-$(CONFIG_COMPAT)   += $(compat-obj-y)
 
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_KPROBES)  += kprobes.o
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index 437e611..783c208 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -86,6 +86,10 @@
 #define SET_STAT_UID(stat, uid)(stat).st_uid = high2lowuid(uid)
 #define SET_STAT_GID(stat, gid)(stat).st_gid = high2lowgid(gid)
 
+COMPAT_SYSCALL_WRAP3(s390_pci_mmio_write, const unsigned long, mmio_addr, 
const void __user *, user_buffer, const size_t, length);
+
+COMPAT_SYSCALL_WRAP3(s390_pci_mmio_read, const unsigned long, mmio_addr, void 
__user *, user_buffer, const size_t, length);
+
 COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
   u16, user, u16, group)
 {
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
deleted file mode 100644
index 1614e15..000
--- a/arch/s390/kernel/compat_wrapper.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *  Compat system call wrappers.
- *
- *Copyright IBM Corp. 2014
- */
-
-#include 
-#include 
-#include "entry.h"
-
-COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, 
newname);
-COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(chdir, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(mknod, const char __user *, filename, umode_t, mode, 
unsigned, dev);
-COMPAT_SYSCALL_WRAP2(chmod, const char __user *, filename, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(oldumount, char __user *, name);
-COMPAT_SYSCALL_WRAP2(access, const char __user *, filename, int, mode);
-COMPAT_SYSCALL_WRAP2(rename, const char __user *, oldname, const char __user 
*, newname);
-COMPAT_SYSCALL_WRAP2(mkdir, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(rmdir, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(pipe, int __user *, fildes);
-COMPAT_SYSCALL_WRAP1(brk, unsigned long, brk);
-COMPAT_SYSCALL_WRAP2(signal, int, sig, __sighandler_t, handler);
-COMPAT_SYSCALL_WRAP1(acct, const char __user *, name);
-COMPAT_SYSCALL_WRAP2(umount, char __user *, name, int, flags);
-COMPAT_SYSCALL_WRAP1(chroot, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(sigsuspend, int, unused1, int, unused2, old_sigset_t, 
mask);
-COMPAT_SYSCALL_WRAP2(sethostname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP2(symlink, const char __user *, old, const char __user *, 
new);
-COMPAT_SYSCALL_WRAP3(readlink, const char __user *, path, char __user *, buf, 
int, bufsiz);
-COMPAT_SYSCALL_WRAP1(uselib, const char __user *, library);
-COMPAT_SYSCALL_WRAP2(swapon, const char __user *, specialfile, int, 
swap_flags);
-COMPAT_SYSCALL_WRAP4(reboot, int, magic1, int, magic2, unsigned int, cmd, void 
__user *, arg);
-COMPAT_SYSCALL_WRAP2(munmap, unsigned long, addr, size_t, len);
-COMPAT_SYSCALL_WRAP3(syslog, int, type, char __user *, buf, int, len);
-COMPAT_SYSCALL_WRAP1(swapoff, const char __user *, specialfile);
-COMPAT_SYSCALL_WRAP2(setdomainname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP1(newuname, struct new_utsname __user *, name);
-COMPAT_SYSCALL_WRAP3(mprotect, unsigned long, start, size_t, len, unsigned 
long, prot);
-COMPAT_SYSCALL_WRAP3(init_module, void __user *, umod, unsigned long, len, 
const char __user *, uargs);
-COMPAT_SYSCALL_WRAP2(delete_module, const char __user *, name_user, unsigned 
int, flags);
-COMPAT_SYSCALL_WRAP4(quotactl, unsigned int, cmd, const char __user *, 
special, qid_t, id, void __user *, addr);
-COMPAT_SYSCALL_WRAP2(bdflush, int, func, long, data);
-COMPAT_SYSCALL_WRAP3(sysfs, int, option, unsigned long, arg1, unsigned long, 
arg2);
-COMPAT_SYSCALL_WRAP5(

[PATCH v3 0/5] all: s390: make compat wrappers the generic solution

2016-02-26 Thread Yury Norov
The problem that makes us use wrappers is that some compat
architectures allows user code to access top halves of registers.
This is not a problem for syscalls that are already handled by compat
code, or for that who has types of the same size in kernel and
userspace. In case of s390 and lp64/ilp32 the problem is in pointer
types, long, unsigned long.

S390 folks already have the solution for it. In this patchset,
it is turned to be general, as arm64/ilp32 needs it too.

This patchset is created as the part of the work of enabling arm64
with ILP32 user mode. See details here:
http://thread.gmane.org/gmane.linux.kernel/2126946

Acked-by: Heiko Carstens <heiko.carst...@de.ibm.com>

v2:
 This is the implementation of one of two possible approaches. First
 one defines new syscall handler declaration macro, that creates both compat and
 non-compat handlers, see [1]. This one declares all wrappers in separated file
 kernel/compat_wrapper.c

v3: 
 - move 2 s390-related wrappers from kernel/compat_wrappers.h
   to arch/s390/kernel/compat_linux.c
 - comments extended
Build-tested on s390.

[1] http://www.spinics.net/lists/linux-s390/msg11593.html

Yury Norov (5):
  all: syscall wrappers: add documentation
  all: introduce COMPAT_WRAPPER option and enable it for s390
  all: s390: move wrapper infrastructure to generic headers
  all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/
  all: wrap needed syscalls in generic unistd

 Documentation/adding-syscalls.txt |  32 +
 arch/Kconfig  |   4 +
 arch/s390/Kconfig |   1 +
 arch/s390/include/asm/compat.h|  17 ++-
 arch/s390/kernel/Makefile |   2 +-
 arch/s390/kernel/compat_wrapper.c | 180 
 include/linux/compat.h| 278 ++
 include/linux/syscalls.h  |  57 +---
 include/linux/syscalls_structs.h  |  60 
 include/uapi/asm-generic/unistd.h | 231 +++
 kernel/Makefile   |   1 +
 kernel/compat_wrapper.c   | 170 +++
 12 files changed, 680 insertions(+), 353 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
 create mode 100644 include/linux/syscalls_structs.h
 create mode 100644 kernel/compat_wrapper.c

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] all: syscall wrappers: add documentation

2016-02-26 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 Documentation/adding-syscalls.txt | 32 
 1 file changed, 32 insertions(+)

diff --git a/Documentation/adding-syscalls.txt 
b/Documentation/adding-syscalls.txt
index cc2d4ac..d02a6bd 100644
--- a/Documentation/adding-syscalls.txt
+++ b/Documentation/adding-syscalls.txt
@@ -341,6 +341,38 @@ To summarize, you need:
  - instance of __SC_COMP not __SYSCALL in include/uapi/asm-generic/unistd.h
 
 
+Compatibility System Calls Wrappers
+
+
+Some architectures prevent 32-bit userspace from access to top halves of 64-bit
+registers, but some not. It's not a problem if specific argument is the same
+size in kernel and userspace. It also is not a problem if system call is 
already
+handled by compatible routine. Otherwise we'd take care of it. Usually, glibc
+and compiler handles register's top halve, but from kernel side, we cannot rely
+on it, as malicious code may cause incorrect behaviour and/or security
+vulnerabilities.
+
+For now, only s390 and arm64/ilp32 are affected.
+
+To clear that top halves, automatic wrappers are introduced. They clear all
+required registers before passing control to regular syscall handler.
+
+If your architecture allows userspace code to access top halves of register,
+you need to:
+ - enable COMPAT_WRAPPER in configuration file;
+ - declare: "#define __SC_WRAP(nr, sym) [nr] = compat_##sym,", just before
+   compatible syscall table declaration, if you use generic unistd; or
+ - declare compat wrappers manually, if you use non-generic syscall table.
+   The list of unsafe syscalls is in kernel/compat_wrapper.
+
+If you write new syscall, make sure, its arguments are the same size in both
+64- and 32-bits modes. If no, and if there's no explicit compat version for
+syscall handler, you need to:
+ - declare compat version prototype in 'include/linux/compat.h';
+ - in 'include/uapi/asm-generic/unistd.h' declare syscall with macro 
'__SC_WRAP'
+   instead of '__SYSCALL';
+ - add corresponding line to 'kernel/compat_wrapper.c' to let it generate 
wrapper.
+
 Compatibility System Calls (x86)
 
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/5] all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/

2016-02-25 Thread Yury Norov
On Wed, Feb 24, 2016 at 09:34:13PM +0300, Yury Norov wrote:

[...]

> +COMPAT_SYSCALL_WRAP3(bpf, int, cmd, union bpf_attr *, attr, unsigned int, 
> size);
> +COMPAT_SYSCALL_WRAP3(s390_pci_mmio_write, const unsigned long, mmio_addr, 
> const void __user *, user_buffer, const size_t, length);
> +COMPAT_SYSCALL_WRAP3(s390_pci_mmio_read, const unsigned long, mmio_addr, 
> void __user *, user_buffer, const size_t, length);

Oops... This one should stay in arch/s390, as it was in previous
version.

> 2.5.0
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/5] all: s390: move wrapper infrastructure to generic headers

2016-02-25 Thread Yury Norov
On Thu, Feb 25, 2016 at 09:51:40AM +0100, Heiko Carstens wrote:
> On Wed, Feb 24, 2016 at 09:34:12PM +0300, Yury Norov wrote:
> > diff --git a/include/linux/syscalls_structs.h 
> > b/include/linux/syscalls_structs.h
> > new file mode 100644
> > index 000..a920cbc
> > --- /dev/null
> > +++ b/include/linux/syscalls_structs.h
> > @@ -0,0 +1,60 @@
> > +#ifndef _LINUX_SYSCALL_STRUCTS_H
> > +#define _LINUX_SYSCALL_STRUCTS_H
> > +
> > +struct epoll_event;
> > +struct iattr;
> > +struct inode;
> > +struct iocb;
> > +struct io_event;
> > +struct iovec;
> > +struct itimerspec;
> > +struct itimerval;
> 
> This is not needed for s390, right? So might be worth a separate patch
> which moves the forward declarations?

This patch also introduces __SC_WRAP, not needed as well. The idea of
this patch is to introduce all the tricky machinery at once. If you
think we need split it, I'm OK, but maybe it's enough to add more
detailed description... What do you think?
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/5] all: introduce COMPAT_WRAPPER option and enable it for s390

2016-02-25 Thread Yury Norov
On Thu, Feb 25, 2016 at 09:49:43AM +0100, Heiko Carstens wrote:
> On Wed, Feb 24, 2016 at 09:34:11PM +0300, Yury Norov wrote:
> > Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
> > ---
> >  arch/Kconfig  | 4 
> >  arch/s390/Kconfig | 1 +
> >  2 files changed, 5 insertions(+)
> > 
> > diff --git a/arch/Kconfig b/arch/Kconfig
> > index f6b649d..6393093 100644
> > --- a/arch/Kconfig
> > +++ b/arch/Kconfig
> > @@ -583,6 +583,10 @@ config HAVE_COPY_THREAD_TLS
> >   normal C parameter passing, rather than extracting the syscall
> >   argument from pt_regs.
> > 
> > +config COMPAT_WRAPPER
> > +   bool
> > +   depends on COMPAT
> > +
> >  #
> >  # ABI hall of shame
> >  #
> > diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
> > index 3be9c83..082b861 100644
> > --- a/arch/s390/Kconfig
> > +++ b/arch/s390/Kconfig
> > @@ -333,6 +333,7 @@ config COMPAT
> > select COMPAT_BINFMT_ELF if BINFMT_ELF
> > select ARCH_WANT_OLD_COMPAT_IPC
> > select COMPAT_OLD_SIGACTION
> > +   select COMPAT_WRAPPER
> > depends on MULTIUSER
> > help
> >   Select this option if you want to enable your system kernel to
> 
> Maybe merge this into patch 4/5?

Then bisectability will suffer, as next patch needs COMPAT_WRAPPER
enabled.

> 
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/5] all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/

2016-02-24 Thread Yury Norov
Some syscalls are declared conditionally, so corresponding wrappers
are conditional accordingly.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/s390/kernel/Makefile |   2 +-
 arch/s390/kernel/compat_wrapper.c | 129 -
 kernel/Makefile   |   1 +
 kernel/compat_wrapper.c   | 170 ++
 4 files changed, 172 insertions(+), 130 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
 create mode 100644 kernel/compat_wrapper.c

diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 2f5586a..145d3d8 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -57,7 +57,7 @@ obj-$(CONFIG_HIBERNATION) += suspend.o swsusp.o
 obj-$(CONFIG_AUDIT)+= audit.o
 compat-obj-$(CONFIG_AUDIT) += compat_audit.o
 obj-$(CONFIG_COMPAT)   += compat_linux.o compat_signal.o
-obj-$(CONFIG_COMPAT)   += compat_wrapper.o $(compat-obj-y)
+obj-$(CONFIG_COMPAT)   += $(compat-obj-y)
 
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
 obj-$(CONFIG_KPROBES)  += kprobes.o
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
deleted file mode 100644
index 1614e15..000
--- a/arch/s390/kernel/compat_wrapper.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *  Compat system call wrappers.
- *
- *Copyright IBM Corp. 2014
- */
-
-#include 
-#include 
-#include "entry.h"
-
-COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP2(link, const char __user *, oldname, const char __user *, 
newname);
-COMPAT_SYSCALL_WRAP1(unlink, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(chdir, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(mknod, const char __user *, filename, umode_t, mode, 
unsigned, dev);
-COMPAT_SYSCALL_WRAP2(chmod, const char __user *, filename, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(oldumount, char __user *, name);
-COMPAT_SYSCALL_WRAP2(access, const char __user *, filename, int, mode);
-COMPAT_SYSCALL_WRAP2(rename, const char __user *, oldname, const char __user 
*, newname);
-COMPAT_SYSCALL_WRAP2(mkdir, const char __user *, pathname, umode_t, mode);
-COMPAT_SYSCALL_WRAP1(rmdir, const char __user *, pathname);
-COMPAT_SYSCALL_WRAP1(pipe, int __user *, fildes);
-COMPAT_SYSCALL_WRAP1(brk, unsigned long, brk);
-COMPAT_SYSCALL_WRAP2(signal, int, sig, __sighandler_t, handler);
-COMPAT_SYSCALL_WRAP1(acct, const char __user *, name);
-COMPAT_SYSCALL_WRAP2(umount, char __user *, name, int, flags);
-COMPAT_SYSCALL_WRAP1(chroot, const char __user *, filename);
-COMPAT_SYSCALL_WRAP3(sigsuspend, int, unused1, int, unused2, old_sigset_t, 
mask);
-COMPAT_SYSCALL_WRAP2(sethostname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP2(symlink, const char __user *, old, const char __user *, 
new);
-COMPAT_SYSCALL_WRAP3(readlink, const char __user *, path, char __user *, buf, 
int, bufsiz);
-COMPAT_SYSCALL_WRAP1(uselib, const char __user *, library);
-COMPAT_SYSCALL_WRAP2(swapon, const char __user *, specialfile, int, 
swap_flags);
-COMPAT_SYSCALL_WRAP4(reboot, int, magic1, int, magic2, unsigned int, cmd, void 
__user *, arg);
-COMPAT_SYSCALL_WRAP2(munmap, unsigned long, addr, size_t, len);
-COMPAT_SYSCALL_WRAP3(syslog, int, type, char __user *, buf, int, len);
-COMPAT_SYSCALL_WRAP1(swapoff, const char __user *, specialfile);
-COMPAT_SYSCALL_WRAP2(setdomainname, char __user *, name, int, len);
-COMPAT_SYSCALL_WRAP1(newuname, struct new_utsname __user *, name);
-COMPAT_SYSCALL_WRAP3(mprotect, unsigned long, start, size_t, len, unsigned 
long, prot);
-COMPAT_SYSCALL_WRAP3(init_module, void __user *, umod, unsigned long, len, 
const char __user *, uargs);
-COMPAT_SYSCALL_WRAP2(delete_module, const char __user *, name_user, unsigned 
int, flags);
-COMPAT_SYSCALL_WRAP4(quotactl, unsigned int, cmd, const char __user *, 
special, qid_t, id, void __user *, addr);
-COMPAT_SYSCALL_WRAP2(bdflush, int, func, long, data);
-COMPAT_SYSCALL_WRAP3(sysfs, int, option, unsigned long, arg1, unsigned long, 
arg2);
-COMPAT_SYSCALL_WRAP5(llseek, unsigned int, fd, unsigned long, high, unsigned 
long, low, loff_t __user *, result, unsigned int, whence);
-COMPAT_SYSCALL_WRAP3(msync, unsigned long, start, size_t, len, int, flags);
-COMPAT_SYSCALL_WRAP2(mlock, unsigned long, start, size_t, len);
-COMPAT_SYSCALL_WRAP2(munlock, unsigned long, start, size_t, len);
-COMPAT_SYSCALL_WRAP2(sched_setparam, pid_t, pid, struct sched_param __user *, 
param);
-COMPAT_SYSCALL_WRAP2(sched_getparam, pid_t, pid, struct sched_param __user *, 
param);
-COMPAT_SYSCALL_WRAP3(sched_setscheduler, pid_t, pid, int, policy, struct 
sched_param __user *, param);
-COMPAT_SYSCALL_WRAP5(mremap, unsigned long, addr, unsigned long, old_len, 
unsigned long, new_len, unsigned long, flags, unsigned long, new_addr);
-COMPAT_SYSCALL_WRAP3(poll, struct pollfd __user *, ufds, unsigned int, nfds, 
int, timeout);
-COMPAT_SYSCALL_

[PATCH 2/5] all: introduce COMPAT_WRAPPER option and enable it for s390

2016-02-24 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/Kconfig  | 4 
 arch/s390/Kconfig | 1 +
 2 files changed, 5 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index f6b649d..6393093 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -583,6 +583,10 @@ config HAVE_COPY_THREAD_TLS
  normal C parameter passing, rather than extracting the syscall
  argument from pt_regs.
 
+config COMPAT_WRAPPER
+   bool
+   depends on COMPAT
+
 #
 # ABI hall of shame
 #
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 3be9c83..082b861 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -333,6 +333,7 @@ config COMPAT
select COMPAT_BINFMT_ELF if BINFMT_ELF
select ARCH_WANT_OLD_COMPAT_IPC
select COMPAT_OLD_SIGACTION
+   select COMPAT_WRAPPER
depends on MULTIUSER
help
  Select this option if you want to enable your system kernel to
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/5] all: s390: make compat wrappers the generic solution

2016-02-24 Thread Yury Norov
The problem that makes us use wrappers is that some compat
architectures allows user code to access top halves of registers.
This is not a problem for syscalls that are already handled by compat
code, or for that who has types of the same size in kernel and
userspace. In case of s390 and lp64/ilp32 the problem is in pointer
types, long, unsigned long.

S390 folks already have the solution for it. In this patchset,
it is turned to be general, as arm64/ilp32 needs it too.

This patchset is created as the part of the work of enabling arm64
with ILP32 user mode. See details here:
http://thread.gmane.org/gmane.linux.kernel/2126946

This is the implementation of one of two possible approaches. First
one defines new syscall handler declaration macro, that creates both compat and
non-compat handlers, see [1]. This one declares all wrappers in separated file
kernel/compat_wrapper.c

Build-tested on s390.

[1] http://www.spinics.net/lists/linux-s390/msg11593.html

Yury Norov (5):
  all: syscall wrappers: add documentation
  all: introduce COMPAT_WRAPPER option and enable it for s390
  all: s390: move wrapper infrastructure to generic headers
  all: s390: move compat_wrappers.c from arch/s390/kernel to kernel/
  all: wrap needed syscalls in generic unistd

 Documentation/adding-syscalls.txt |  32 +
 arch/Kconfig  |   4 +
 arch/s390/Kconfig |   1 +
 arch/s390/include/asm/compat.h|  17 ++-
 arch/s390/kernel/Makefile |   2 +-
 arch/s390/kernel/compat_wrapper.c | 180 
 include/linux/compat.h| 278 ++
 include/linux/syscalls.h  |  57 +---
 include/linux/syscalls_structs.h  |  60 
 include/uapi/asm-generic/unistd.h | 231 +++
 kernel/Makefile   |   1 +
 kernel/compat_wrapper.c   | 170 +++
 12 files changed, 680 insertions(+), 353 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
 create mode 100644 include/linux/syscalls_structs.h
 create mode 100644 kernel/compat_wrapper.c

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] all: syscall wrappers: add documentation

2016-02-24 Thread Yury Norov
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 Documentation/adding-syscalls.txt | 32 
 1 file changed, 32 insertions(+)

diff --git a/Documentation/adding-syscalls.txt 
b/Documentation/adding-syscalls.txt
index cc2d4ac..1db880c 100644
--- a/Documentation/adding-syscalls.txt
+++ b/Documentation/adding-syscalls.txt
@@ -341,6 +341,38 @@ To summarize, you need:
  - instance of __SC_COMP not __SYSCALL in include/uapi/asm-generic/unistd.h
 
 
+Compatibility System Calls Wrappers
+
+
+Some architectures prevent 32-bit userspace from access to top halves of 64-bit
+registers, but some not. It's not a problem if specific argument is the same
+size in kernel and userspace. It also is not a problem if system call is 
already
+handled by compatible routine. Otherwise we'd take care of it. Usually, glibc
+and compiler handles register's top halve, but from kernel side, we cannot rely
+on it, as malicious code may cause incorrect behaviour and/or security
+vulnerabilities.
+
+For now, only s390 and arm64/ilp32 are affected.
+
+To clear that top halves, automatic wrappers are introduced. They clear all
+required registers before passing control to regular syscall handler.
+
+If your architecture allows userspace code to access top halves of register,
+you need to:
+ - enable COMPAT_WRAPPER in configuration file;
+ - declare: "#define __SC_WRAP(nr, sym) [nr] = compat_##sym,", just before
+   compatible syscall table declaration, if you use generic unistd; or
+ - declare compat wrappers manually, if you use non-generic syscall table.
+   The list of unsafe syscalls is in kernel/compat_wrapper.
+
+If you write new syscall, make sure, its arguments are the same size in both
+64- and 32-bits modes. If no, and if there's no explicit compat version for
+syscall handler, you need to:
+ - declare compat version prototype in 'include/linux/compat.h';
+ - in 'include/uapi/asm-generic/unistd.h' declare syscall with macro 
'__SC_WRAP'
+   instead of '__SYSCALL';
+ - add corresponding line to 'kernel/compat_wrapper.c' to let it generate 
wrapper.
+
 Compatibility System Calls (x86)
 
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/5] all: wrap needed syscalls in generic unistd

2016-02-24 Thread Yury Norov
As generic unistd syscall table is written in C, syscall
prototypes declaration is needed. It's added to compat header.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 include/linux/compat.h| 225 +
 include/uapi/asm-generic/unistd.h | 227 +++---
 2 files changed, 338 insertions(+), 114 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index 243b656..72c922f 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -769,6 +769,231 @@ asmlinkage long notrace 
compat_SyS##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))
 }
 #endif
 
+/* Compat wrappers */
+#include 
+asmlinkage long compat_sys_creat(const char __user *pathname, umode_t mode);
+asmlinkage long compat_sys_link(const char __user *oldname,
+   const char __user *newname);
+asmlinkage long compat_sys_chdir(const char __user *filename);
+asmlinkage long compat_sys_mknod(const char __user *filename, umode_t mode,
+   unsigned dev);
+asmlinkage long compat_sys_chmod(const char __user *filename, umode_t mode);
+asmlinkage long compat_sys_oldumount(char __user *name);
+asmlinkage long compat_sys_access(const char __user *filename, int mode);
+asmlinkage long compat_sys_rename(const char __user *oldname,
+   const char __user *newname);
+asmlinkage long compat_sys_mkdir(const char __user *pathname, umode_t mode);
+asmlinkage long compat_sys_rmdir(const char __user *pathname);
+asmlinkage long compat_sys_pipe(int __user *fildes);
+asmlinkage long compat_sys_brk(unsigned long brk);
+asmlinkage long compat_sys_signal(int sig, __sighandler_t handler);
+asmlinkage long compat_sys_acct(const char __user *name);
+asmlinkage long compat_sys_umount(char __user *name, int flags);
+asmlinkage long compat_sys_chroot(const char __user *filename);
+
+#ifdef CONFIG_OLD_SIGSUSPEND
+asmlinkage long compat_sys_sigsuspend(old_sigset_t mask);
+#endif
+
+#ifdef CONFIG_OLD_SIGSUSPEND3
+asmlinkage long compat_sys_sigsuspend(int unused1, int unused2, old_sigset_t 
mask);
+#endif
+
+asmlinkage long compat_sys_sethostname(char __user *name, int len);
+asmlinkage long compat_sys_symlink(const char __user *old, const char __user 
*new);
+asmlinkage long compat_sys_readlink(const char __user *path,
+   char __user *buf, int bufsiz);
+asmlinkage long compat_sys_uselib(const char __user *library);
+asmlinkage long compat_sys_swapon(const char __user *specialfile, int 
swap_flags);
+asmlinkage long compat_sys_reboot(int magic1, int magic2, unsigned int cmd,
+   void __user *arg);
+asmlinkage long compat_sys_munmap(unsigned long addr, size_t len);
+asmlinkage long compat_sys_munmap(unsigned long addr, size_t len);
+asmlinkage long compat_sys_syslog(int type, char __user *buf, int len);
+asmlinkage long compat_sys_swapoff(const char __user *specialfile);
+asmlinkage long compat_sys_setdomainname(char __user *name, int len);
+asmlinkage long compat_sys_newuname(struct new_utsname __user *name);
+asmlinkage long compat_sys_mprotect(unsigned long start, size_t len,
+   unsigned long prot);
+asmlinkage long compat_sys_init_module(void __user *umod, unsigned long len,
+   const char __user *uargs);
+asmlinkage long compat_sys_delete_module(const char __user *name_user,
+   unsigned int flags);
+asmlinkage long compat_sys_quotactl(unsigned int cmd, const char __user 
*special,
+   qid_t id, void __user *addr);
+asmlinkage long compat_sys_bdflush(int func, long data);
+asmlinkage long compat_sys_sysfs(int option,
+   unsigned long arg1, unsigned long arg2);
+asmlinkage long compat_sys_llseek(unsigned int fd, unsigned long offset_high,
+   unsigned long offset_low, loff_t __user *result,
+   unsigned int whence);
+asmlinkage long compat_sys_msync(unsigned long start, size_t len, int flags);
+asmlinkage long compat_sys_mlock(unsigned long start, size_t len);
+asmlinkage long compat_sys_munlock(unsigned long start, size_t len);
+asmlinkage long compat_sys_sched_setparam(pid_t pid,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_sched_getparam(pid_t pid,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_sched_setscheduler(pid_t pid, int policy,
+   struct sched_param __user *param);
+asmlinkage long compat_sys_mremap(unsigned long addr,
+  unsigned long old_len, unsigned long new_len,
+  unsigned long flags, unsigned long new_addr);
+asmlinkage long compat_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
+   int timeout);
+asmlinkag

[PATCH 3/5] all: s390: move wrapper infrastructure to generic headers

2016-02-24 Thread Yury Norov
__SC_COMPAT_CAST for s390 is too specific due to 31-bit pointer length, so it's
moved to arch/s390/include/asm/compat.h. Generic declaration assumes that long,
unsigned long and pointer types are all 32-bit length.

linux/syscalls_structs.h header is introduced, because from now (see next patch)
structure types listed there are needed for both normal and compat mode.

cond_syscall_wrapped now defined two symbols: sys_foo() and compat_sys_foo(), if
compat wrappers are enabled.

Here __SC_WRAP() macro is introduced as well. s390 doesn't need it as it uses
asm-generated syscall table. But architectures that generate that tables with
C code (ARM64/ILP32) should redefine it as '#define __SC_WRAP(name) 
compat_##name'.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
 arch/s390/include/asm/compat.h| 17 +--
 arch/s390/kernel/compat_wrapper.c | 51 -
 include/linux/compat.h| 53 ++
 include/linux/syscalls.h  | 57 +
 include/linux/syscalls_structs.h  | 60 +++
 include/uapi/asm-generic/unistd.h |  4 +++
 6 files changed, 133 insertions(+), 109 deletions(-)
 create mode 100644 include/linux/syscalls_structs.h

diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 352f7bd..f412723 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -7,13 +7,26 @@
 #include 
 #include 
 
-#define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p(typeof(0?(t)0:0ULL), 
u64))
-
 #define __SC_DELOUSE(t,v) ({ \
BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
(t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fff) : (v)); \
 })
 
+#define __SC_COMPAT_CAST(t, a) \
+({ \
+   long __ReS = a; \
+   \
+   BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+   if (__TYPE_IS_L(t)) \
+   __ReS = (s32)a; \
+   if (__TYPE_IS_UL(t))\
+   __ReS = (u32)a; \
+   if (__TYPE_IS_PTR(t))   \
+   __ReS = a & 0x7fff; \
+   (t)__ReS;   \
+})
+
 #define PSW32_MASK_PER 0x4000UL
 #define PSW32_MASK_DAT 0x0400UL
 #define PSW32_MASK_IO  0x0200UL
diff --git a/arch/s390/kernel/compat_wrapper.c 
b/arch/s390/kernel/compat_wrapper.c
index ae2cda5..1614e15 100644
--- a/arch/s390/kernel/compat_wrapper.c
+++ b/arch/s390/kernel/compat_wrapper.c
@@ -8,57 +8,6 @@
 #include 
 #include "entry.h"
 
-#define COMPAT_SYSCALL_WRAP1(name, ...) \
-   COMPAT_SYSCALL_WRAPx(1, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP2(name, ...) \
-   COMPAT_SYSCALL_WRAPx(2, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP3(name, ...) \
-   COMPAT_SYSCALL_WRAPx(3, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP4(name, ...) \
-   COMPAT_SYSCALL_WRAPx(4, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP5(name, ...) \
-   COMPAT_SYSCALL_WRAPx(5, _##name, __VA_ARGS__)
-#define COMPAT_SYSCALL_WRAP6(name, ...) \
-   COMPAT_SYSCALL_WRAPx(6, _##name, __VA_ARGS__)
-
-#define __SC_COMPAT_TYPE(t, a) \
-   __typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
-
-#define __SC_COMPAT_CAST(t, a) \
-({ \
-   long __ReS = a; \
-   \
-   BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
-   if (__TYPE_IS_L(t)) \
-   __ReS = (s32)a; \
-   if (__TYPE_IS_UL(t))\
-   __ReS = (u32)a; \
-   if (__TYPE_IS_PTR(t))   \
-   __ReS = a & 0x7fff; \
-   (t)__ReS;   \
-})
-
-/*
- * The COMPAT_SYSCALL_WRAP macro generates system call wrappers to be used by
- * compat tasks. These wrappers will only be used 

<    1   2   3