From a59b013c11e9cb8a43f881aa4651271c8455b21f Mon Sep 17 00:00:00 2001
From: Dirk Mueller <dmueller@suse.com>
Date: Mon, 16 Mar 2015 15:04:51 +0100
Subject: [PATCH 2/2] ARM64: Enable CONFIG_COMPAT

---
 config/arm64/default                               |  9 ++++
 ...able-CONFIG_COMPAT-also-for-64k-page-size.patch | 54 ++++++++++++++++++++++
 series.conf                                        |  1 +
 3 files changed, 64 insertions(+)
 create mode 100644 patches.arch/arm64-Enable-CONFIG_COMPAT-also-for-64k-page-size.patch

diff --git a/config/arm64/default b/config/arm64/default
index fef3f67..6d8057e 100644
--- a/config/arm64/default
+++ b/config/arm64/default
@@ -145,8 +145,10 @@ CONFIG_RD_LZ4=y
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
+CONFIG_HAVE_UID16=y
 CONFIG_SYSCTL_EXCEPTION_TRACE=y
 CONFIG_EXPERT=y
+CONFIG_UID16=y
 CONFIG_SGETMASK_SYSCALL=y
 CONFIG_SYSFS_SYSCALL=y
 # CONFIG_SYSCTL_SYSCALL is not set
@@ -201,6 +203,8 @@ CONFIG_HAVE_VIRT_CPU_ACCOUNTING_GEN=y
 CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE=y
 CONFIG_MODULES_USE_ELF_RELA=y
 CONFIG_CLONE_BACKWARDS=y
+CONFIG_OLD_SIGSUSPEND3=y
+CONFIG_COMPAT_OLD_SIGACTION=y
 
 #
 # GCOV-based kernel profiling
@@ -249,6 +253,7 @@ CONFIG_KARMA_PARTITION=y
 CONFIG_EFI_PARTITION=y
 CONFIG_SYSV68_PARTITION=y
 # CONFIG_CMDLINE_PARTITION is not set
+CONFIG_BLOCK_COMPAT=y
 
 #
 # IO Schedulers
@@ -387,11 +392,14 @@ CONFIG_EFI=y
 # Userspace binary formats
 #
 CONFIG_BINFMT_ELF=y
+CONFIG_COMPAT_BINFMT_ELF=y
 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
 CONFIG_BINFMT_SCRIPT=y
 # CONFIG_HAVE_AOUT is not set
 CONFIG_BINFMT_MISC=m
 CONFIG_COREDUMP=y
+CONFIG_COMPAT=y
+CONFIG_SYSVIPC_COMPAT=y
 
 #
 # Power management options
@@ -446,6 +454,7 @@ CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m
 #
 # CONFIG_ARM_KIRKWOOD_CPUFREQ is not set
 CONFIG_NET=y
+CONFIG_COMPAT_NETLINK_MESSAGES=y
 
 #
 # Networking options
diff --git a/patches.arch/arm64-Enable-CONFIG_COMPAT-also-for-64k-page-size.patch b/patches.arch/arm64-Enable-CONFIG_COMPAT-also-for-64k-page-size.patch
new file mode 100644
index 0000000..18b015f
--- /dev/null
+++ b/patches.arch/arm64-Enable-CONFIG_COMPAT-also-for-64k-page-size.patch
@@ -0,0 +1,54 @@
+From a3ebb7c0471ed11000f024203ff2695fb2346797 Mon Sep 17 00:00:00 2001
+From: Alexander Graf <agraf@suse.de>
+Date: Thu, 4 Dec 2014 16:44:05 +0100
+Subject: [PATCH v2] arm64: Enable CONFIG_COMPAT also for 64k page size
+Patch-mainline: No
+References: bnc#908468
+
+With binutils 2.25 the default alignment for 32bit arm sections changed to
+have everything 64k aligned. Armv7 binaries built with this binutils version
+run successfully on an arm64 system.
+
+Since effectively there is now the chance to run armv7 code on arm64 even
+with 64k page size, it doesn't make sense to block people from enabling
+CONFIG_COMPAT on those configurations.
+
+Signed-off-by: Alexander Graf <agraf@suse.de>
+
+---
+
+v1 -> v2:
+
+  - add comment in KConfig explaining that segments need to be 64k aligned
+  - conditionalize the option on EXPERT
+---
+ arch/arm64/Kconfig | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
+index 9532f8d..7fc0ad6 100644
+--- a/arch/arm64/Kconfig
++++ b/arch/arm64/Kconfig
+@@ -409,7 +409,7 @@ source "fs/Kconfig.binfmt"
+ 
+ config COMPAT
+ 	bool "Kernel support for 32-bit EL0"
+-	depends on !ARM64_64K_PAGES
++	depends on !ARM64_64K_PAGES || EXPERT
+ 	select COMPAT_BINFMT_ELF
+ 	select HAVE_UID16
+ 	select OLD_SIGSUSPEND3
+@@ -420,6 +420,10 @@ config COMPAT
+ 	  the user helper functions, VFP support and the ptrace interface are
+ 	  handled appropriately by the kernel.
+ 
++	  If you also enabled CONFIG_ARM64_64K_PAGES, please be aware that you
++	  will only be able to execute AArch32 binaries that were compiled with
++	  64k aligned segments.
++
+ 	  If you want to execute 32-bit userspace applications, say Y.
+ 
+ config SYSVIPC_COMPAT
+-- 
+1.7.12.4
+
diff --git a/series.conf b/series.conf
index b582922..df79604 100644
--- a/series.conf
+++ b/series.conf
@@ -230,6 +230,7 @@
 	patches.arch/arm64-0037-drivers-net-fddi-skfp-h-skfbi.h-Remove-useless-PCI_B.patch
 	patches.arch/arm64-0038-arm64-mustang-Disable-sgenet-and-xgenet.patch
 	patches.arch/arm64-0039-generic-pci.patch
+	patches.arch/arm64-Enable-CONFIG_COMPAT-also-for-64k-page-size.patch
 	patches.arch/arm64-Implement-the-compat_sys_call_table-in-C.patch
 	patches.arch/arm64-fix-mmap2-compat-syscall.patch
 
-- 
2.0.4

