From 86b157b3f17c779bed4b717b7fab1449e08efc42 Mon Sep 17 00:00:00 2001
From: Dirk Mueller <dmueller@suse.com>
Date: Sun, 15 Mar 2015 12:44:37 +0100
Subject: [PATCH 1/2] ARM64: Fix support for ARMv7 userspace

---
 ...rm64-0004-net-xgbe-Add-A0-silicon-support.patch |  2 +-
 .../arm64-0013-fix-mmap2-compat-syscall.patch      | 94 ++++++++++++++++++++++
 series.conf                                        |  1 +
 3 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 patches.arch/arm64-0013-fix-mmap2-compat-syscall.patch

diff --git a/patches.arch/arm64-0004-net-xgbe-Add-A0-silicon-support.patch b/patches.arch/arm64-0004-net-xgbe-Add-A0-silicon-support.patch
index 5c06a82..39221b6 100644
--- a/patches.arch/arm64-0004-net-xgbe-Add-A0-silicon-support.patch
+++ b/patches.arch/arm64-0004-net-xgbe-Add-A0-silicon-support.patch
@@ -10,7 +10,7 @@ already have A0 silicon. This patch adds a driver from AMD for
 early A0 silicon in parallel to the B0 one.
 
 Signed-off-by: Alexander Graf <agraf@suse.de>
-Signed-off-by: Dirk Mueller <@dmueller@suse.com>
+Signed-off-by: Dirk Mueller <dmueller@suse.com>
 
 ---
  drivers/net/ethernet/amd/Makefile               |    2 +-
diff --git a/patches.arch/arm64-0013-fix-mmap2-compat-syscall.patch b/patches.arch/arm64-0013-fix-mmap2-compat-syscall.patch
new file mode 100644
index 0000000..5f5c0a8
--- /dev/null
+++ b/patches.arch/arm64-0013-fix-mmap2-compat-syscall.patch
@@ -0,0 +1,94 @@
+From: Andreas Schwab <schwab@suse.de>
+Date: Mon, 9 Mar 2015 17:27:36 +0100
+Subject: [PATCH] arm64: fix implementation of mmap2 compat syscall
+Patch-mainline: Submitted, http://lists.infradead.org/pipermail/linux-arm-kernel/2015-March/330081.html
+
+The arm mmap2 syscall takes the offset in units of 4K, thus with 64K pages
+the offset needs to be scaled to units of pages.
+
+Tested-by: Alexander Graf <agraf@suse.de>
+Signed-off-by: Andreas Schwab <schwab@suse.de>
+Signed-off-by: Dirk Mueller <dmueller@suse.com>
+
+---
+ arch/arm64/include/asm/unistd32.h |  2 +-
+ arch/arm64/kernel/entry32.S       | 18 ++++++++++++++++++
+ arch/arm64/kernel/sys32.c         |  6 ++++++
+ 3 files changed, 25 insertions(+), 1 deletion(-)
+
+Index: linux-4.0-rc3-master/arch/arm64/include/asm/unistd32.h
+===================================================================
+--- linux-4.0-rc3-master.orig/arch/arm64/include/asm/unistd32.h
++++ linux-4.0-rc3-master/arch/arm64/include/asm/unistd32.h
+@@ -406,7 +406,7 @@ __SYSCALL(__NR_vfork, sys_vfork)
+ #define __NR_ugetrlimit 191	/* SuS compliant getrlimit */
+ __SYSCALL(__NR_ugetrlimit, compat_sys_getrlimit)		/* SuS compliant getrlimit */
+ #define __NR_mmap2 192
+-__SYSCALL(__NR_mmap2, sys_mmap_pgoff)
++__SYSCALL(__NR_mmap2, compat_sys_mmap2_wrapper)
+ #define __NR_truncate64 193
+ __SYSCALL(__NR_truncate64, compat_sys_truncate64_wrapper)
+ #define __NR_ftruncate64 194
+Index: linux-4.0-rc3-master/arch/arm64/kernel/entry32.S
+===================================================================
+--- linux-4.0-rc3-master.orig/arch/arm64/kernel/entry32.S
++++ linux-4.0-rc3-master/arch/arm64/kernel/entry32.S
+@@ -19,9 +19,12 @@
+  */
+ 
+ #include <linux/linkage.h>
++#include <linux/const.h>
+ 
+ #include <asm/assembler.h>
+ #include <asm/asm-offsets.h>
++#include <asm/errno.h>
++#include <asm/page.h>
+ 
+ /*
+  * System call wrappers for the AArch32 compatibility layer.
+@@ -54,6 +57,21 @@ ENTRY(compat_sys_fstatfs64_wrapper)
+ ENDPROC(compat_sys_fstatfs64_wrapper)
+ 
+ /*
++ * Note: off_4k (w5) is always units of 4K.  If we can't do the requested
++ * offset, we return EINVAL.
++ */
++#if PAGE_SHIFT > 12
++ENTRY(compat_sys_mmap2_wrapper)
++       tst     w5, #~PAGE_MASK >> 12
++       b.ne    1f
++       lsr     w5, w5, #PAGE_SHIFT - 12
++       b       sys_mmap_pgoff
++1:     mov     x0, #-EINVAL
++       ret     lr
++ENDPROC(compat_sys_mmap2_wrapper)
++#endif
++
++/*
+  * Wrappers for AArch32 syscalls that either take 64-bit parameters
+  * in registers or that take 32-bit parameters which require sign
+  * extension.
+Index: linux-4.0-rc3-master/arch/arm64/kernel/sys32.c
+===================================================================
+--- linux-4.0-rc3-master.orig/arch/arm64/kernel/sys32.c
++++ linux-4.0-rc3-master/arch/arm64/kernel/sys32.c
+@@ -24,6 +24,7 @@
+ 
+ #include <linux/compiler.h>
+ #include <linux/syscalls.h>
++#include <asm/page.h>
+ 
+ asmlinkage long compat_sys_sigreturn_wrapper(void);
+ asmlinkage long compat_sys_rt_sigreturn_wrapper(void);
+@@ -37,6 +38,11 @@ asmlinkage long compat_sys_readahead_wra
+ asmlinkage long compat_sys_fadvise64_64_wrapper(void);
+ asmlinkage long compat_sys_sync_file_range2_wrapper(void);
+ asmlinkage long compat_sys_fallocate_wrapper(void);
++#if PAGE_SHIFT > 12
++asmlinkage long compat_sys_mmap2_wrapper(void);
++#else
++#define compat_sys_mmap2_wrapper sys_mmap_pgoff
++#endif
+ 
+ #undef __SYSCALL
+ #define __SYSCALL(nr, sym)	[nr] = sym,
diff --git a/series.conf b/series.conf
index 36be064..992892a 100644
--- a/series.conf
+++ b/series.conf
@@ -171,6 +171,7 @@
 +agraf	patches.arch/arm64-0010-KVM-ARM-Hack-to-enable-VGIC-mapping-on-64k-PAGE_SIZE.patch
 	patches.arch/arm64-0011-Enable-CONFIG_COMPAT-also-for-64k-page-size.patch
 +agraf	patches.arch/arm64-0012-generic-pci.patch
+	patches.arch/arm64-0013-fix-mmap2-compat-syscall.patch
 
 	########################################################
 	# S/390
-- 
2.0.4

