arm64: Allow AArch32 on arm64 with 64k PAGE_SIZE
cover arm64: Allow AArch32 on arm64 with 64k PAGE_SIZE
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 with this patch set applied.
This provides the best of both worlds for some users. You get less page faults, but can still run legacy broken code that might not be 64bit safe yet.
If you want to give this a try, you obviously need user space that was compiled with 64k constraints fulfilled. For a working rootfs, just grab the latest openSUSE Factory tree:
Alex
Alexander Graf (1):
arm64: Enable CONFIG_COMPAT also for 64k page size
Andreas Schwab (1):
arm64: fix implementation of mmap2 compat syscall
arch/arm64/Kconfig | 6 +++++- arch/arm64/include/asm/unistd32.h | 2 +- arch/arm64/kernel/entry32.S | 18 ++++++++++++++++++ arch/arm64/kernel/sys32.c | 6 ++++++ 4 files changed, 30 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/2 arm64: fix implementation of mmap2 compat syscall
From: Andreas Schwab <[email protected]>
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.
--- 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(-)
arch/arm64/include/asm/unistd32.h +1 -1
@@ -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
arch/arm64/kernel/entry32.S +18 -0
@@ -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.
arch/arm64/kernel/sys32.c +6 -0
@@ -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_wrapper(void);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,
Signature · 1 line
2.1.4
PATCH 2/2 arm64: Enable CONFIG_COMPAT also for 64k page size
In reply to Alexander GrafWith 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.
--- arch/arm64/Kconfig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +5 -1
@@ -670,7 +670,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
@@ -681,6 +681,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
Signature · 1 line
2.1.4