Skip to content

Commit 3fc24ef

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: compat: Implement misalignment fixups for multiword loads
The 32-bit ARM kernel implements fixups on behalf of user space when using LDM/STM or LDRD/STRD instructions on addresses that are not 32-bit aligned. This is not something that is supported by the architecture, but was done anyway to increase compatibility with user space software, which mostly targeted x86 at the time and did not care about aligned accesses. This feature is one of the remaining impediments to being able to switch to 64-bit kernels on 64-bit capable hardware running 32-bit user space, so let's implement it for the arm64 compat layer as well. Note that the intent is to implement the exact same handling of misaligned multi-word loads and stores as the 32-bit kernel does, including what appears to be missing support for user space programs that rely on SETEND to switch to a different byte order and back. Also, like the 32-bit ARM version, we rely on the faulting address reported by the CPU to infer the memory address, instead of decoding the instruction fully to obtain this information. This implementation is taken from the 32-bit ARM tree, with all pieces removed that deal with instructions other than LDRD/STRD and LDM/STM, or that deal with alignment exceptions taken in kernel mode. Cc: [email protected] Cc: Vagrant Cascadian <[email protected]> Cc: Riku Voipio <[email protected]> Cc: Steve McIntyre <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: change the option to 'default n'] Signed-off-by: Catalin Marinas <[email protected]>
1 parent b90cb10 commit 3fc24ef

File tree

5 files changed

+395
-0
lines changed

5 files changed

+395
-0
lines changed

arch/arm64/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,9 @@ config THUMB2_COMPAT_VDSO
15621562
Compile the compat vDSO with '-mthumb -fomit-frame-pointer' if y,
15631563
otherwise with '-marm'.
15641564

1565+
config COMPAT_ALIGNMENT_FIXUPS
1566+
bool "Fix up misaligned multi-word loads and stores in user space"
1567+
15651568
menuconfig ARMV8_DEPRECATED
15661569
bool "Emulate deprecated/obsolete ARMv8 instructions"
15671570
depends on SYSCTL

arch/arm64/include/asm/exception.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void do_sysinstr(unsigned long esr, struct pt_regs *regs);
7070
void do_sp_pc_abort(unsigned long addr, unsigned long esr, struct pt_regs *regs);
7171
void bad_el0_sync(struct pt_regs *regs, int reason, unsigned long esr);
7272
void do_cp15instr(unsigned long esr, struct pt_regs *regs);
73+
int do_compat_alignment_fixup(unsigned long addr, struct pt_regs *regs);
7374
void do_el0_svc(struct pt_regs *regs);
7475
void do_el0_svc_compat(struct pt_regs *regs);
7576
void do_ptrauth_fault(struct pt_regs *regs, unsigned long esr);

arch/arm64/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
4545
obj-$(CONFIG_COMPAT) += sys32.o signal32.o \
4646
sys_compat.o
4747
obj-$(CONFIG_COMPAT) += sigreturn32.o
48+
obj-$(CONFIG_COMPAT_ALIGNMENT_FIXUPS) += compat_alignment.o
4849
obj-$(CONFIG_KUSER_HELPERS) += kuser32.o
4950
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o
5051
obj-$(CONFIG_MODULES) += module.o

0 commit comments

Comments
 (0)