ARM64: Split out CONFIG_ARM64_AARCH32 from CONFIG_COMPAT. Signed-off-by: Andrew Pinski <[email protected]>
Subsystems (6)
PATCH 1/5 ARM64: Split out CONFIG_ARM64_AARCH32 from CONFIG_COMPAT. Signed-off-by: Andrew Pinski <[email protected]>
Right now CONFIG_COMPAT means enabling AARCH32 support in the ARM64 traget, which we want to split out so we can it to mean any 32bit ABI support instead.
--- arch/arm64/Kconfig | 6 +++++- arch/arm64/include/asm/compat.h | 32 ++++++++++++++++++++++++++++---- arch/arm64/include/asm/elf.h | 19 ++++++++++++++----- arch/arm64/include/asm/fpsimd.h | 2 +- arch/arm64/include/asm/hwcap.h | 3 ++- arch/arm64/include/asm/memory.h | 6 +++--- arch/arm64/include/asm/processor.h | 2 +- arch/arm64/include/asm/ptrace.h | 2 +- arch/arm64/include/asm/stat.h | 2 +- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/entry.S | 6 +++--- arch/arm64/kernel/head.S | 2 +- arch/arm64/kernel/hw_breakpoint.c | 6 +++--- arch/arm64/kernel/process.c | 6 +++--- arch/arm64/kernel/ptrace.c | 28 ++++++++++++++-------------- arch/arm64/kernel/signal.c | 4 ++-- arch/arm64/kernel/traps.c | 4 ++-- arch/arm64/kernel/vdso.c | 6 +++--- arch/arm64/mm/fault.c | 1 + arch/arm64/mm/mmap.c | 1 + 20 files changed, 90 insertions(+), 50 deletions(-)
arch/arm64/Kconfig +5 -1
@@ -247,9 +247,13 @@ menu "Userspace binary formats" source "fs/Kconfig.binfmt" config COMPAT + def_bool y + depends on ARM64_AARCH32 + select COMPAT_BINFMT_ELF + +config ARM64_AARCH32 bool "Kernel support for 32-bit EL0" depends on !ARM64_64K_PAGES - select COMPAT_BINFMT_ELF select HAVE_UID16 select OLD_SIGSUSPEND3 select COMPAT_OLD_SIGACTION
arch/arm64/include/asm/compat.h +28 -4
@@ -279,28 +279,52 @@ struct compat_shmid64_ds {compat_ulong_t __unused5; }; -static inline int is_compat_task (void ) +#if defined(CONFIG_ARM64_AARCH32 ) +static inline int is_aarch32_task (void ) {return test_thread_flag (TIF_32BIT ); } -static inline int is_compat_thread (struct thread_info *thread) +static inline int is_aarch32_thread (struct thread_info *thread) {return test_ti_thread_flag (thread,TIF_32BIT ); } +#else +static inline int is_aarch32_task (void ) +{ +return 0 ; +} + +static inline int is_aarch32_thread (struct thread_info *thread) +{ +return 0 ; +} +#endif +#else /* !CONFIG_COMPAT */ -static inline int is_compat_task (void ) +static inline int is_aarch32_task (void ) {return 0 ; } -static inline int is_compat_thread (struct thread_info *thread) +static inline int is_aarch32_thread (struct thread_info *thread) {return 0 ; }#endif /* CONFIG_COMPAT */ + +static inline int is_compat_task (void ) +{ +return is_aarch32_task (); +} + +static inline int is_compat_thread (struct thread_info *thread) +{ +return is_aarch32_thread (thread); +} +#endif /* __KERNEL__ */ #endif /* __ASM_COMPAT_H */
arch/arm64/include/asm/elf.h +14 -5
@@ -153,24 +153,33 @@ extern unsigned long arch_randomize_brk(struct mm_struct *mm);#define COMPAT_ELF_ET_DYN_BASE (randomize_et_dyn(2 * TASK_SIZE_32 / 3)) +#ifdef CONFIG_ARM64_AARCH32 /* 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 ]; +typedef unsigned int compat_a32_elf_greg_t ; +typedef compat_a32_elf_greg_t compat_a32_elf_gregset_t [COMPAT_ELF_NGREG ];/* AArch32 EABI. */ #define EF_ARM_EABI_MASK 0xff000000 -#define compat_elf_check_arch (x) (((x)->e_machine == EM_ARM) && \ +#define compat_elf_a32_check_arch (x) (((x)->e_machine == EM_ARM) && \ ((x)->e_flags & EF_ARM_EABI_MASK)) -#define compat_start_thread compat_start_thread -#define COMPAT_SET_PERSONALITY (ex) set_thread_flag(TIF_32BIT); +#define COMPAT_SET_A32_PERSONALITY (ex) set_thread_flag(TIF_32BIT);#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 +typedef compat_a32_elf_greg_t compat_elf_greg_t ; +typedef compat_a32_elf_gregset_t compat_elf_gregset_t ; +#endif + +#define compat_elf_check_arch (x) compat_elf_a32_check_arch(x) +#define COMPAT_SET_PERSONALITY (ex) COMPAT_SET_A32_PERSONALITY(x) +#define compat_start_thread compat_start_thread +#endif /* CONFIG_COMPAT */ #endif
arch/arm64/include/asm/fpsimd.h +1 -1
@@ -39,7 +39,7 @@ struct fpsimd_state { }; }; -#if defined(__KERNEL__) && defined(CONFIG_COMPAT ) +#if defined(__KERNEL__) && defined(CONFIG_ARM64_AARCH32 )/* Masks for extracting the FPSR and FPCR from the FPSCR */ #define VFP_FPSCR_STAT_MASK 0xf800009f#define VFP_FPSCR_CTRL_MASK 0x07f79f00
arch/arm64/include/asm/hwcap.h +2 -1
@@ -37,12 +37,13 @@* instruction set this cpu supports. */ #define ELF_HWCAP (elf_hwcap) -#define COMPAT_ELF_HWCAP (COMPAT_HWCAP_HALF|COMPAT_HWCAP_THUMB|\ +#define COMPAT_ELF_A32_HWCAP (COMPAT_HWCAP_HALF|COMPAT_HWCAP_THUMB|\ COMPAT_HWCAP_FAST_MULT|COMPAT_HWCAP_EDSP|\ COMPAT_HWCAP_TLS|COMPAT_HWCAP_VFP|\ COMPAT_HWCAP_VFPv3|COMPAT_HWCAP_VFPv4|\ COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV)extern unsigned int elf_hwcap; +#define COMPAT_ELF_HWCAP COMPAT_ELF_A32_HWCAP#endif #endif
arch/arm64/include/asm/memory.h +3 -3
@@ -49,11 +49,11 @@#ifdef CONFIG_COMPAT #define TASK_SIZE_32 UL(0x100000000) -#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ +#define TASK_SIZE (is_compat_task() ? \ TASK_SIZE_32 : TASK_SIZE_64)#else -#define TASK_SIZE TASK_SIZE_64 -#endif /* CONFIG_COMPAT */ +#define TASK_SIZE TASK_SIZE_64 +#endif #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4))
arch/arm64/include/asm/processor.h +1 -1
@@ -38,7 +38,7 @@#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000 -#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ +#define STACK_TOP (is_compat_task() ? \ AARCH32_VECTORS_BASE : STACK_TOP_MAX)#else #define STACK_TOP STACK_TOP_MAX
arch/arm64/include/asm/ptrace.h +1 -1
@@ -107,7 +107,7 @@ struct pt_regs {#define arch_has_single_step () (1) -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 #define compat_thumb_mode (regs) \ (((regs)->pstate & COMPAT_PSR_T_BIT))#else
arch/arm64/include/asm/stat.h +1 -1
@@ -18,7 +18,7 @@#include <uapi/asm/stat.h> -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 #include <asm/compat.h>
arch/arm64/kernel/Makefile +1 -1
@@ -11,7 +11,7 @@ arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ sys.o stacktrace.o time.o traps.o io.o vdso.o \ hyp-stub.o psci.o -arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ +arm64-obj-$(CONFIG_ARM64_AARCH32) += sys32.o kuser32.o signal32.o \ sys_compat.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o smp_psci.o
arch/arm64/kernel/entry.S +3 -3
@@ -167,7 +167,7 @@ ENTRY(vectors) ventry el0_fiq_invalid // FIQ 64-bit EL0 ventry el0_error_invalid // Error 64-bit EL0 -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 ventry el0_sync_compat // Synchronous 32-bit EL0 ventry el0_irq_compat // IRQ 32-bit EL0 ventry el0_fiq_invalid_compat // FIQ 32-bit EL0
@@ -207,7 +207,7 @@ el0_error_invalid: inv_entry 0, BAD_ERROR ENDPROC(el0_error_invalid) -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 el0_fiq_invalid_compat: inv_entry 0, BAD_FIQ, 32 ENDPROC(el0_fiq_invalid_compat)
@@ -371,7 +371,7 @@ el0_sync: b.ge el0_dbg b el0_inv -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 .align 6 el0_sync_compat: kernel_entry 0, 32
arch/arm64/kernel/head.S +1 -1
@@ -188,7 +188,7 @@ ENTRY(el2_setup) mov x0, #0x33ff msr cptr_el2, x0 // Disable copro. traps to EL2 -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 msr hstr_el2, xzr // Disable CP15 traps to EL2 #endif
arch/arm64/kernel/hw_breakpoint.c +3 -3
@@ -392,7 +392,7 @@ static int arch_build_bp_info(struct perf_event *bp)* Watchpoints can be of length 1, 2, 4 or 8 bytes. */ if (info->ctrl.type ==ARM_BREAKPOINT_EXECUTE ) { -if (is_compat_task ()) { +if (is_aarch32_task ()) {if (info->ctrl.len !=ARM_BREAKPOINT_LEN_2 && info->ctrl.len !=ARM_BREAKPOINT_LEN_4 )return -EINVAL ;
@@ -449,7 +449,7 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp)* AArch32 tasks expect some simple alignment fixups, so emulate * that here. */ -if (is_compat_task ()) { +if (is_aarch32_task ()) {if (info->ctrl.len ==ARM_BREAKPOINT_LEN_8 ) alignment_mask =0x7 ;else
@@ -636,7 +636,7 @@ static int watchpoint_handler(unsigned long addr, unsigned int esr, info =counter_arch_bp (wp);/* AArch32 watchpoints are either 4 or 8 bytes aligned. */ -if (is_compat_task ()) { +if (is_aarch32_task ()) {if (info->ctrl.len ==ARM_BREAKPOINT_LEN_8 ) alignment_mask =0x7 ;else
arch/arm64/kernel/process.c +3 -3
@@ -202,7 +202,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,if (likely (!(p->flags &PF_KTHREAD ))) { *childregs = *current_pt_regs (); childregs->regs[0 ] =0 ; -if (is_compat_thread (task_thread_info (p))) { +if (is_aarch32_thread (task_thread_info (p))) {if (stack_start) childregs->compat_sp = stack_start; }else {
@@ -243,12 +243,12 @@ static void tls_thread_switch(struct task_struct *next) {unsigned long tpidr, tpidrro; -if (!is_compat_task ()) { +if (!is_aarch32_task ()) { asm("mrs %0, tpidr_el0" :"=r" (tpidr)); current->thread.tp_value = tpidr; } -if (is_compat_thread (task_thread_info (next))) { +if (is_aarch32_thread (task_thread_info (next))) { tpidr =0 ; tpidrro = next->thread.tp_value; }else {
arch/arm64/kernel/ptrace.c +14 -14
@@ -69,10 +69,10 @@ static void ptrace_hbptriggered(struct perf_event *bp, .si_addr = (void __user *)(bkpt->trigger), }; -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 int i; -if (!is_compat_task ()) +if (!is_aarch32_task ()) goto send_sig;for (i =0 ; i <ARM_MAX_BRP ; ++i) {
@@ -609,7 +609,7 @@ static const struct user_regset_view user_aarch64_view = { .regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets) }; -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 #include <linux/compat.h> enum compat_regset {
@@ -775,8 +775,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 },
@@ -809,7 +809,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, &user_aarch32_view,REGSET_COMPAT_GPR , off,sizeof (compat_ulong_t), ret);
@@ -829,7 +829,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 ; ret = copy_regset_from_user(tsk, &user_aarch32_view,
@@ -989,7 +989,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, ret =copy_regset_to_user (child, &user_aarch32_view,REGSET_COMPAT_GPR , -0 ,sizeof (compat_elf_gregset_t), +0 ,sizeof (compat_a32_elf_gregset_t), datap);break ;
@@ -997,7 +997,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, ret =copy_regset_from_user (child, &user_aarch32_view,REGSET_COMPAT_GPR , -0 ,sizeof (compat_elf_gregset_t), +0 ,sizeof (compat_a32_elf_gregset_t), datap);break ;
@@ -1045,12 +1045,12 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, return ret; } -#endif /* CONFIG_COMPAT */ +#endif /* CONFIG_ARM64_AARCH32 */ const struct user_regset_view *task_user_regset_view (struct task_struct *task) { -#ifdef CONFIG_COMPAT -if (is_compat_thread (task_thread_info (task))) +#ifdef CONFIG_ARM64_AARCH32 +if (is_aarch32_thread (task_thread_info (task)))return &user_aarch32_view;#endif return &user_aarch64_view;
@@ -1069,7 +1069,7 @@ asmlinkage int syscall_trace(int dir, struct pt_regs *regs)if (!test_thread_flag (TIF_SYSCALL_TRACE ))return regs->syscallno; -if (is_compat_task ()) { +if (is_aarch32_task ()) {/* AArch32 uses ip (r12) for scratch */ saved_reg = regs->regs[12 ]; regs->regs[12 ] = dir;
@@ -1087,7 +1087,7 @@ asmlinkage int syscall_trace(int dir, struct pt_regs *regs)else if (tracehook_report_syscall_entry (regs)) regs->syscallno = ~0UL ; -if (is_compat_task ()) +if (is_aarch32_task ()) regs->regs[12 ] = saved_reg;else regs->regs[7 ] = saved_reg;
arch/arm64/kernel/signal.c +2 -2
@@ -268,7 +268,7 @@ static int setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,static void setup_restart_syscall (struct pt_regs *regs) { -if (is_compat_task ()) +if (is_aarch32_task ())compat_setup_restart_syscall (regs);else regs->regs[8 ] = __NR_restart_syscall;
@@ -295,7 +295,7 @@ static void handle_signal(unsigned long sig, struct k_sigaction *ka,/* * Set up the stack frame */ -if (is_compat_task ()) { +if (is_aarch32_task ()) {if (ka->sa.sa_flags &SA_SIGINFO ) ret =compat_setup_rt_frame (usig, ka, info, oldset, regs);
arch/arm64/kernel/traps.c +2 -2
@@ -285,9 +285,9 @@ long compat_arm_syscall(struct pt_regs *regs);asmlinkage long do_ni_syscall (struct pt_regs *regs) { -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 long ret; -if (is_compat_task ()) { +if (is_aarch32_task ()) { ret =compat_arm_syscall (regs);if (ret != -ENOSYS )return ret;
arch/arm64/kernel/vdso.c +3 -3
@@ -49,7 +49,7 @@ static union { }vdso_data_store __page_aligned_data;struct vdso_data *vdso_data = &vdso_data_store.data; -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 /* * Create and map the vectors page for AArch32 tasks. */
@@ -99,7 +99,7 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) return ret; } -#endif /* CONFIG_COMPAT */ +#endif /* CONFIG_ARM64_AARCH32 */ static int __init vdso_init (void ) {
@@ -191,7 +191,7 @@ const char *arch_vma_name(struct vm_area_struct *vma)* it conflicting with the vectors base. */ if (vma->vm_mm && vma->vm_start == (long )vma->vm_mm->context.vdso) { -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 if (vma->vm_start ==AARCH32_VECTORS_BASE )return "[vectors]" ;#endif
arch/arm64/mm/fault.c +1 -0
@@ -35,6 +35,7 @@#include <asm/system_misc.h> #include <asm/pgtable.h> #include <asm/tlbflush.h> +#include <asm/compat.h> static const char *fault_name (unsigned int esr);
arch/arm64/mm/mmap.c +1 -0
@@ -28,6 +28,7 @@#include <linux/random.h> #include <asm/cputype.h> +#include <asm/compat.h> /* * Leave enough space between the mmap area and the stack to honour ulimit in
Signature · 1 line
1.7.2.5
PATCH 2/5 ARM64: Move some signal code to a seperate file to be reused by ILP32.
Since the ILP32 ABI uses similar signal code as the LP64 ABI, it makes sense to reuse rather than copy the same code.
--- arch/arm64/kernel/signal.c | 170 +------------------------------------------- 1 files changed, 1 insertions(+), 169 deletions(-)
arch/arm64/kernel/signal.c +1 -169
@@ -95,176 +95,8 @@ static int restore_fpsimd_context(struct fpsimd_context __user *ctx)return err ? -EFAULT :0 ; } -static int restore_sigframe (struct pt_regs *regs, -struct rt_sigframe __user *sf) -{ -sigset_t set; -int i, err; -struct aux_context __user *aux = - (struct aux_context __user *)sf->uc.uc_mcontext.__reserved; - - err =__copy_from_user (&set, &sf->uc.uc_sigmask,sizeof (set)); -if (err ==0 ) -set_current_blocked (&set); - -for (i =0 ; i <31 ; i++) -__get_user_error (regs->regs[i], &sf->uc.uc_mcontext.regs[i], - err); -__get_user_error (regs->sp, &sf->uc.uc_mcontext.sp, err); -__get_user_error (regs->pc, &sf->uc.uc_mcontext.pc, err); -__get_user_error (regs->pstate, &sf->uc.uc_mcontext.pstate, err); - -/* -* Avoid sys_rt_sigreturn() restarting. -*/ - regs->syscallno = ~0UL ; - - err |= !valid_user_regs (®s->user_regs); - -if (err ==0 ) - err |=restore_fpsimd_context (&aux->fpsimd); - -return err; -} - -asmlinkage long sys_rt_sigreturn (struct pt_regs *regs) -{ -struct rt_sigframe __user *frame; - -/* Always make any pending restarted system calls return -EINTR */ -current_thread_info ()->restart_block.fn = do_no_restart_syscall; - -/* -* Since we stacked the signal on a 128-bit boundary, then 'sp' should -* be word aligned here. -*/ -if (regs->sp &15 ) - goto badframe; - - frame = (struct rt_sigframe __user *)regs->sp; - -if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) - goto badframe; - -if (restore_sigframe (regs, frame)) - goto badframe; - -if (restore_altstack (&frame->uc.uc_stack)) - goto badframe; - -return regs->regs[0 ]; - -badframe: -if (show_unhandled_signals) -pr_info_ratelimited ("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n" , - current->comm,task_pid_nr (current), __func__, - regs->pc, regs->sp); -force_sig (SIGSEGV , current); -return 0 ; -} - -static int setup_sigframe (struct rt_sigframe __user *sf, -struct pt_regs *regs,sigset_t *set) -{ -int i, err =0 ; -struct aux_context __user *aux = - (struct aux_context __user *)sf->uc.uc_mcontext.__reserved; - -/* set up the stack frame for unwinding */ -__put_user_error (regs->regs[29 ], &sf->fp, err); -__put_user_error (regs->regs[30 ], &sf->lr, err); - -for (i =0 ; i <31 ; i++) -__put_user_error (regs->regs[i], &sf->uc.uc_mcontext.regs[i], - err); -__put_user_error (regs->sp, &sf->uc.uc_mcontext.sp, err); -__put_user_error (regs->pc, &sf->uc.uc_mcontext.pc, err); -__put_user_error (regs->pstate, &sf->uc.uc_mcontext.pstate, err); - -__put_user_error (current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err); - - err |=__copy_to_user (&sf->uc.uc_sigmask, set,sizeof (*set)); - -if (err ==0 ) - err |=preserve_fpsimd_context (&aux->fpsimd); - -/* set the "end" magic */ -__put_user_error (0 , &aux->end.magic, err); -__put_user_error (0 , &aux->end.size, err); +#include "signal_template.c" -return err; -} - -static struct rt_sigframe __user *get_sigframe (struct k_sigaction *ka, -struct pt_regs *regs) -{ -unsigned long sp, sp_top; -struct rt_sigframe __user *frame; - - sp = sp_top = regs->sp; - -/* -* This is the X/Open sanctioned signal stack switching. -*/ -if ((ka->sa.sa_flags &SA_ONSTACK ) && !sas_ss_flags (sp)) - sp = sp_top = current->sas_ss_sp + current->sas_ss_size; - - sp = (sp -sizeof (struct rt_sigframe )) & ~15 ; - frame = (struct rt_sigframe __user *)sp; - -/* -* Check that we can actually write to the signal frame. -*/ -if (!access_ok (VERIFY_WRITE , frame, sp_top - sp)) - frame =NULL ; - -return frame; -} - -static void setup_return (struct pt_regs *regs,struct k_sigaction *ka, -void __user *frame,int usig) -{ -__sigrestore_t sigtramp; - - regs->regs[0 ] = usig; - regs->sp = (unsigned long )frame; - regs->regs[29 ] = regs->sp + offsetof(struct rt_sigframe , fp); - regs->pc = (unsigned long )ka->sa.sa_handler; - -if (ka->sa.sa_flags &SA_RESTORER ) - sigtramp = ka->sa.sa_restorer; -else - sigtramp =VDSO_SYMBOL (current->mm->context.vdso, sigtramp); - - regs->regs[30 ] = (unsigned long )sigtramp; -} - -static int setup_rt_frame (int usig,struct k_sigaction *ka,siginfo_t *info, -sigset_t *set,struct pt_regs *regs) -{ -struct rt_sigframe __user *frame; -int err =0 ; - - frame =get_sigframe (ka, regs); -if (!frame) -return 1 ; - -__put_user_error (0 , &frame->uc.uc_flags, err); -__put_user_error (NULL , &frame->uc.uc_link, err); - - err |=__save_altstack (&frame->uc.uc_stack, regs->sp); - err |=setup_sigframe (frame, regs, set); -if (err ==0 ) { -setup_return (regs, ka, frame, usig); -if (ka->sa.sa_flags &SA_SIGINFO ) { - err |=copy_siginfo_to_user (&frame->info, info); - regs->regs[1 ] = (unsigned long )&frame->info; - regs->regs[2 ] = (unsigned long )&frame->uc; - } - } - -return err; -}static void setup_restart_syscall (struct pt_regs *regs) {
Signature · 1 line
1.7.2.5
Re: [PATCH 2/5] ARM64: Move some signal code to a seperate file to be reused by ILP32.
Quoted 2 lines · Andrew Pinski
Since the ILP32 ABI uses similar signal code as the LP64 ABI, it makes sense to reuse rather than copy the same code.
I just noticed that signal_template.c was not part of this patch but it is included with patch number 5.
Thanks,
Andrew Pinski
Quoted 192 lines
Signed-off-by Andrew Pinski <[email protected]>--- arch/arm64/kernel/signal.c | 170 +------------------------------------------- 1 files changed, 1 insertions(+), 169 deletions(-)arch/arm64/kernel/signal.c +1
-170@@ -95,176 +95,8 @@ static int restore_fpsimd_context(struct fpsimd_context __user *ctx)return err ? -EFAULT :0 ; } -static int restore_sigframe (struct pt_regs *regs, -struct rt_sigframe __user *sf) -{ -sigset_t set; -int i, err; -struct aux_context __user *aux = - (struct aux_context __user *)sf->uc.uc_mcontext.__reserved; - - err =__copy_from_user (&set, &sf->uc.uc_sigmask,sizeof (set)); -if (err ==0 ) -set_current_blocked (&set); - -for (i =0 ; i <31 ; i++) -__get_user_error (regs->regs[i], &sf->uc.uc_mcontext.regs[i], - err); -__get_user_error (regs->sp, &sf->uc.uc_mcontext.sp, err); -__get_user_error (regs->pc, &sf->uc.uc_mcontext.pc, err); -__get_user_error (regs->pstate, &sf->uc.uc_mcontext.pstate, err); - -/* -* Avoid sys_rt_sigreturn() restarting. -*/ - regs->syscallno = ~0UL ; - - err |= !valid_user_regs (®s->user_regs); - -if (err ==0 ) - err |=restore_fpsimd_context (&aux->fpsimd); - -return err; -} - -asmlinkage long sys_rt_sigreturn (struct pt_regs *regs) -{ -struct rt_sigframe __user *frame; - -/* Always make any pending restarted system calls return -EINTR */ -current_thread_info ()->restart_block.fn = do_no_restart_syscall; - -/* -* Since we stacked the signal on a 128-bit boundary, then 'sp' should -* be word aligned here. -*/ -if (regs->sp &15 ) - goto badframe; - - frame = (struct rt_sigframe __user *)regs->sp; - -if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) - goto badframe; - -if (restore_sigframe (regs, frame)) - goto badframe; - -if (restore_altstack (&frame->uc.uc_stack)) - goto badframe; - -return regs->regs[0 ]; - -badframe: -if (show_unhandled_signals) -pr_info_ratelimited ("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n" , - current->comm,task_pid_nr (current), __func__, - regs->pc, regs->sp); -force_sig (SIGSEGV , current); -return 0 ; -} - -static int setup_sigframe (struct rt_sigframe __user *sf, -struct pt_regs *regs,sigset_t *set) -{ -int i, err =0 ; -struct aux_context __user *aux = - (struct aux_context __user *)sf->uc.uc_mcontext.__reserved; - -/* set up the stack frame for unwinding */ -__put_user_error (regs->regs[29 ], &sf->fp, err); -__put_user_error (regs->regs[30 ], &sf->lr, err); - -for (i =0 ; i <31 ; i++) -__put_user_error (regs->regs[i], &sf->uc.uc_mcontext.regs[i], - err); -__put_user_error (regs->sp, &sf->uc.uc_mcontext.sp, err); -__put_user_error (regs->pc, &sf->uc.uc_mcontext.pc, err); -__put_user_error (regs->pstate, &sf->uc.uc_mcontext.pstate, err); - -__put_user_error (current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err); - - err |=__copy_to_user (&sf->uc.uc_sigmask, set,sizeof (*set)); - -if (err ==0 ) - err |=preserve_fpsimd_context (&aux->fpsimd); - -/* set the "end" magic */ -__put_user_error (0 , &aux->end.magic, err); -__put_user_error (0 , &aux->end.size, err); +#include "signal_template.c" -return err; -} - -static struct rt_sigframe __user *get_sigframe (struct k_sigaction *ka, -struct pt_regs *regs) -{ -unsigned long sp, sp_top; -struct rt_sigframe __user *frame; - - sp = sp_top = regs->sp; - -/* -* This is the X/Open sanctioned signal stack switching. -*/ -if ((ka->sa.sa_flags &SA_ONSTACK ) && !sas_ss_flags (sp)) - sp = sp_top = current->sas_ss_sp + current->sas_ss_size; - - sp = (sp -sizeof (struct rt_sigframe )) & ~15 ; - frame = (struct rt_sigframe __user *)sp; - -/* -* Check that we can actually write to the signal frame. -*/ -if (!access_ok (VERIFY_WRITE , frame, sp_top - sp)) - frame =NULL ; - -return frame; -} - -static void setup_return (struct pt_regs *regs,struct k_sigaction *ka, -void __user *frame,int usig) -{ -__sigrestore_t sigtramp; - - regs->regs[0 ] = usig; - regs->sp = (unsigned long )frame; - regs->regs[29 ] = regs->sp + offsetof(struct rt_sigframe , fp); - regs->pc = (unsigned long )ka->sa.sa_handler; - -if (ka->sa.sa_flags &SA_RESTORER ) - sigtramp = ka->sa.sa_restorer; -else - sigtramp =VDSO_SYMBOL (current->mm->context.vdso, sigtramp); - - regs->regs[30 ] = (unsigned long )sigtramp; -} - -static int setup_rt_frame (int usig,struct k_sigaction *ka,siginfo_t *info, -sigset_t *set,struct pt_regs *regs) -{ -struct rt_sigframe __user *frame; -int err =0 ; - - frame =get_sigframe (ka, regs); -if (!frame) -return 1 ; - -__put_user_error (0 , &frame->uc.uc_flags, err); -__put_user_error (NULL , &frame->uc.uc_link, err); - - err |=__save_altstack (&frame->uc.uc_stack, regs->sp); - err |=setup_sigframe (frame, regs, set); -if (err ==0 ) { -setup_return (regs, ka, frame, usig); -if (ka->sa.sa_flags &SA_SIGINFO ) { - err |=copy_siginfo_to_user (&frame->info, info); - regs->regs[1 ] = (unsigned long )&frame->info; - regs->regs[2 ] = (unsigned long )&frame->uc; - } - } - -return err; -}static void setup_restart_syscall (struct pt_regs *regs) { --1.7.2.5
Re: [PATCH 2/5] ARM64: Move some signal code to a seperate file to be reused by ILP32.
Quoted 7 lines · Andrew Pinski
Quoted 2 lines · Andrew Pinski
Since the ILP32 ABI uses similar signal code as the LP64 ABI, it makes sense to reuse rather than copy the same code.
I just noticed that
signal_template.cwas not part of this patch but it is included with patch number 5.
At a minimum, the patch set should be respun so that it builds, runs and has no unusable Kconfig options at all intermediate points in the set.
You could also consider splitting out cosmetic changes unrelated to the meat of a change to a separate patches.
David Daney
Catalin Marinas
maintainerRe: [PATCH 2/5] ARM64: Move some signal code to a seperate file to be reused by ILP32.
In reply to Andrew PinskiQuoted 2 lines · Andrew Pinski
Since the ILP32 ABI uses similar signal code as the LP64 ABI, it makes sense to reuse rather than copy the same code.
At a first look, I don't really like this part. I'll comment more on the last patch.
Signature · 1 line
Catalin
PATCH 3/5 FS: Export poll_select_copy_remaining and rename poll_select_copy_remaining in compat.c so it does not pick the wrong copy.
In reply to Andrew PinskiHi,
The ILP32 ABI in ARM64 uses a slightly different pselect from either the compat or even the native LP64 ABI. We would want to reuse some of the code path that are used as the size of the timespec is the same, so this patch exports poll_select_copy_remaining from fs/select.c and renames the copy in fs/compat.c to make sure that it is not being used.
--- fs/compat.c | 8 ++++---- fs/select.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/compat.c +4 -4
@@ -1088,7 +1088,7 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla#define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t)) -static int poll_select_copy_remaining (struct timespec *end_time,void __user *p, +static int compat_poll_select_copy_remaining (struct timespec *end_time,void __user *p,int timeval,int ret) {struct timespec ts;
@@ -1307,7 +1307,7 @@ asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp, } ret =compat_core_sys_select (n, inp, outp, exp, to); - ret =poll_select_copy_remaining (&end_time, tvp,1 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tvp,1 , ret);return ret; }
@@ -1362,7 +1362,7 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp, } ret =compat_core_sys_select (n, inp, outp, exp, to); - ret =poll_select_copy_remaining (&end_time, tsp,0 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tsp,0 , ret);if (ret == -ERESTARTNOHAND ) {/*
@@ -1448,7 +1448,7 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, }else if (sigmask)sigprocmask (SIG_SETMASK , &sigsaved,NULL ); - ret =poll_select_copy_remaining (&end_time, tsp,0 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tsp,0 , ret);return ret; }
fs/select.c +2 -2
@@ -287,8 +287,8 @@ int poll_select_set_timeout(struct timespec *to, long sec, long nsec)return 0 ; } -static int poll_select_copy_remaining (struct timespec *end_time,void __user *p, -int timeval,int ret) +int poll_select_copy_remaining (struct timespec *end_time,void __user *p, +int timeval,int ret) {struct timespec rts;struct timeval rtv;
Signature · 1 line
1.7.2.5
Catalin Marinas
maintainerRe: [PATCH 3/5] FS: Export poll_select_copy_remaining and rename poll_select_copy_remaining in compat.c so it does not pick the wrong copy.
Quoted 8 lines · Andrew Pinski
The ILP32 ABI in ARM64 uses a slightly different pselect from either the compat or even the native LP64 ABI. We would want to reuse some of the code path that are used as the size of the timespec is the same, so this patch exports
poll_select_copy_remainingfromfs/select.cand renames the copy infs/compat.cto make sure that it is not being used.Signed-off-by Andrew Pinski <[email protected]>
I think this patch has to wait until we review the ILP32 ABI for arm64. When I looked at this some time ago I thought we can just use the native arm64 pselect6 and ppoll. Once we agree that's not possible we can push this patch. On its own it doesn't have much value.
Signature · 1 line
Catalin
Re: [PATCH 3/5] FS: Export poll_select_copy_remaining and rename poll_select_copy_remaining in compat.c so it does not pick the wrong copy.
Quoted 8 lines · Catalin Marinas
Quoted 7 lines · Andrew Pinski
The ILP32 ABI in ARM64 uses a slightly different pselect from either the compat or even the native LP64 ABI. We would want to reuse some of the code path that are used as the size of the timespec is the same, so this patch exports
poll_select_copy_remainingfromfs/select.cand renames the copy infs/compat.cto make sure that it is not being used.
Quoted 6 lines
Quoted 1 line
Signed-off-by Andrew Pinski <[email protected]>I think this patch has to wait until we review the ILP32 ABI for arm64. When I looked at this some time ago I thought we can just use the native arm64 pselect6 and ppoll. Once we agree that's not possible we can push this patch. On its own it doesn't have much value.
Since fd_set is defined by XPG4.2 to be a struct of an array of "long"'s, we cannot change the definition in user space.
I tried using the native ppoll/pselect for the ABI first. It worked for little-endian just fine but failed hard when big-endian. If we only care about little-endian arm64 at this point, I can remove this part of the patch and keep it for when we (Cavium) submits the big-endian patches.
Thanks,
Andrew Pinski
Quoted 3 lines
--
Catalin
Catalin Marinas
maintainerRe: [PATCH 3/5] FS: Export poll_select_copy_remaining and rename poll_select_copy_remaining in compat.c so it does not pick the wrong copy.
Quoted 17 lines · Andrew Pinski
Quoted 8 lines · Catalin Marinas
Quoted 7 lines · Andrew Pinski
The ILP32 ABI in ARM64 uses a slightly different pselect from either the compat or even the native LP64 ABI. We would want to reuse some of the code path that are used as the size of the timespec is the same, so this patch exports
poll_select_copy_remainingfromfs/select.cand renames the copy infs/compat.cto make sure that it is not being used.Quoted 6 lines
Quoted 1 line
Signed-off-by Andrew Pinski <[email protected]>I think this patch has to wait until we review the ILP32 ABI for arm64. When I looked at this some time ago I thought we can just use the native arm64 pselect6 and ppoll. Once we agree that's not possible we can push this patch. On its own it doesn't have much value.
Quoted 8 lines
Since
fd_setis defined by XPG4.2 to be a struct of an array of "long"'s, we cannot change the definition in user space.I tried using the native ppoll/pselect for the ABI first. It worked for little-endian just fine but failed hard when big-endian. If we only care about little-endian arm64 at this point, I can remove this part of the patch and keep it for when we (Cavium) submits the big-endian patches.
I see the issue now. I think for the initial set of patches we can assume little endian. We need a lot more testing, at least for AArch32 mode (we can kick off some tests here once these patches get closer to merging).
Signature · 1 line
Catalin
PATCH 3/5 FS: Export poll_select_copy_remaining and rename poll_select_copy_remaining in compat.c so it does not pick the wrong copy.
In reply to Andrew PinskiHi,
The ILP32 ABI in ARM64 uses a slightly different pselect from either the compat or even the native LP64 ABI. We would want to reuse some of the code path that are used as the size of the timespec is the same, so this patch exports poll_select_copy_remaining from fs/select.c and renames the copy in fs/compat.c to make sure that it is not being used.
--- fs/compat.c | 8 ++++---- fs/select.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/compat.c +4 -4
@@ -1088,7 +1088,7 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla#define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t)) -static int poll_select_copy_remaining (struct timespec *end_time,void __user *p, +static int compat_poll_select_copy_remaining (struct timespec *end_time,void __user *p,int timeval,int ret) {struct timespec ts;
@@ -1307,7 +1307,7 @@ asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp, } ret =compat_core_sys_select (n, inp, outp, exp, to); - ret =poll_select_copy_remaining (&end_time, tvp,1 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tvp,1 , ret);return ret; }
@@ -1362,7 +1362,7 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp, } ret =compat_core_sys_select (n, inp, outp, exp, to); - ret =poll_select_copy_remaining (&end_time, tsp,0 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tsp,0 , ret);if (ret == -ERESTARTNOHAND ) {/*
@@ -1448,7 +1448,7 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, }else if (sigmask)sigprocmask (SIG_SETMASK , &sigsaved,NULL ); - ret =poll_select_copy_remaining (&end_time, tsp,0 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tsp,0 , ret);return ret; }
fs/select.c +2 -2
@@ -287,8 +287,8 @@ int poll_select_set_timeout(struct timespec *to, long sec, long nsec)return 0 ; } -static int poll_select_copy_remaining (struct timespec *end_time,void __user *p, -int timeval,int ret) +int poll_select_copy_remaining (struct timespec *end_time,void __user *p, +int timeval,int ret) {struct timespec rts;struct timeval rtv;
Signature · 1 line
1.7.2.5
PATCH 3/5 FS: Export poll_select_copy_remaining and rename poll_select_copy_remaining in compat.c so it does not pick the wrong copy.
In reply to Andrew PinskiHi,
The ILP32 ABI in ARM64 uses a slightly different pselect from either the compat or even the native LP64 ABI. We would want to reuse some of the code path that are used as the size of the timespec is the same, so this patch exports poll_select_copy_remaining from fs/select.c and renames the copy in fs/compat.c to make sure that it is not being used.
--- fs/compat.c | 8 ++++---- fs/select.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/compat.c +4 -4
@@ -1088,7 +1088,7 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla#define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t)) -static int poll_select_copy_remaining (struct timespec *end_time,void __user *p, +static int compat_poll_select_copy_remaining (struct timespec *end_time,void __user *p,int timeval,int ret) {struct timespec ts;
@@ -1307,7 +1307,7 @@ asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp, } ret =compat_core_sys_select (n, inp, outp, exp, to); - ret =poll_select_copy_remaining (&end_time, tvp,1 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tvp,1 , ret);return ret; }
@@ -1362,7 +1362,7 @@ static long do_compat_pselect(int n, compat_ulong_t __user *inp, } ret =compat_core_sys_select (n, inp, outp, exp, to); - ret =poll_select_copy_remaining (&end_time, tsp,0 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tsp,0 , ret);if (ret == -ERESTARTNOHAND ) {/*
@@ -1448,7 +1448,7 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, }else if (sigmask)sigprocmask (SIG_SETMASK , &sigsaved,NULL ); - ret =poll_select_copy_remaining (&end_time, tsp,0 , ret); + ret =compat_poll_select_copy_remaining (&end_time, tsp,0 , ret);return ret; }
fs/select.c +2 -2
@@ -287,8 +287,8 @@ int poll_select_set_timeout(struct timespec *to, long sec, long nsec)return 0 ; } -static int poll_select_copy_remaining (struct timespec *end_time,void __user *p, -int timeval,int ret) +int poll_select_copy_remaining (struct timespec *end_time,void __user *p, +int timeval,int ret) {struct timespec rts;struct timeval rtv;
Signature · 1 line
1.7.2.5
PATCH 4/5 ARM64: Move copy_siginfo_to_user32 and copy_siginfo_from_user32 to signal.c to be able to use from non AARCH32 code.
In reply to Andrew PinskiThe signal code for ILP32 uses one extra function from signal32.c; it does not make sense to enable the whole signal32.c code so we move the function which was being used to signal.c.
--- arch/arm64/kernel/signal.c | 85 ++++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/signal32.c | 81 ---------------------------------------- 2 files changed, 85 insertions(+), 81 deletions(-)
arch/arm64/kernel/signal.c +85 -0
@@ -249,3 +249,88 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,tracehook_notify_resume (regs); } } + + +#ifdef CONFIG_COMPAT +int copy_siginfo_to_user32 (compat_siginfo_t __user *to,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, &to->si_signo); + err |=__put_user (from->si_errno, &to->si_errno); + err |=__put_user ((short )from->si_code, &to->si_code); +if (from->si_code <0 ) + err |=__copy_to_user (&to->_sifields._pad, &from->_sifields._pad, +SI_PAD_SIZE ); +else switch (from->si_code & __SI_MASK) { +case __SI_KILL: + err |=__put_user (from->si_pid, &to->si_pid); + err |=__put_user (from->si_uid, &to->si_uid); +break ; +case __SI_TIMER: + err |=__put_user (from->si_tid, &to->si_tid); + err |=__put_user (from->si_overrun, &to->si_overrun); + err |=__put_user ((compat_uptr_t )(unsigned long )from->si_ptr, + &to->si_ptr); +break ; +case __SI_POLL: + err |=__put_user (from->si_band, &to->si_band); + err |=__put_user (from->si_fd, &to->si_fd); +break ; +case __SI_FAULT: + err |=__put_user ((compat_uptr_t )(unsigned long )from->si_addr, + &to->si_addr); +#ifdef BUS_MCEERR_AO +/* +* Other callers might not initialize the si_lsb field, +* so check explicitely for the right codes here. +*/ +if (from->si_code ==BUS_MCEERR_AR || from->si_code ==BUS_MCEERR_AO ) + err |=__put_user (from->si_addr_lsb, &to->si_addr_lsb); +#endif +break ; +case __SI_CHLD: + err |=__put_user (from->si_pid, &to->si_pid); + err |=__put_user (from->si_uid, &to->si_uid); + err |=__put_user (from->si_status, &to->si_status); + err |=__put_user (from->si_utime, &to->si_utime); + err |=__put_user (from->si_stime, &to->si_stime); +break ; +case __SI_RT:/* This is not generated by the kernel as of now. */ +case __SI_MESGQ:/* But this is */ + err |=__put_user (from->si_pid, &to->si_pid); + err |=__put_user (from->si_uid, &to->si_uid); + err |=__put_user ((compat_uptr_t )(unsigned long )from->si_ptr, &to->si_ptr); +break ; +default :/* this is just in case for now ... */ + err |=__put_user (from->si_pid, &to->si_pid); + err |=__put_user (from->si_uid, &to->si_uid); +break ; + } +return err; +} + +int copy_siginfo_from_user32 (siginfo_t *to,compat_siginfo_t __user *from) +{ +memset (to,0 ,sizeof *to); + +if (copy_from_user (to, from, __ARCH_SI_PREAMBLE_SIZE) || +copy_from_user (to->_sifields._pad, + from->_sifields._pad,SI_PAD_SIZE )) +return -EFAULT ; + +return 0 ; +} +#endif +
arch/arm64/kernel/signal32.c +0 -81
87 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH 5/5 ARM64: Add support for ILP32 ABI.
In reply to Andrew PinskiThis patch adds full support of the ABI to the ARM64 target.
--- arch/arm64/Kconfig | 11 +- arch/arm64/include/asm/Kbuild | 1 - arch/arm64/include/asm/compat.h | 72 ++++++- arch/arm64/include/asm/elf.h | 71 ++++++-- arch/arm64/include/asm/hwcap.h | 2 +- arch/arm64/include/asm/memory.h | 4 +- arch/arm64/include/asm/processor.h | 12 -- arch/arm64/include/asm/stat.h | 6 +- arch/arm64/include/asm/syscalls.h | 3 + arch/arm64/include/asm/thread_info.h | 1 + arch/arm64/include/asm/unistd.h | 10 +- arch/arm64/include/asm/vdso.h | 4 + arch/arm64/include/uapi/asm/bitsperlong.h | 7 +- arch/arm64/include/uapi/asm/posix_types.h | 12 ++ arch/arm64/include/uapi/asm/siginfo.h | 6 + arch/arm64/kernel/Makefile | 7 + arch/arm64/kernel/entry.S | 20 ++- arch/arm64/kernel/process.c | 18 ++ arch/arm64/kernel/ptrace.c | 38 ++++- arch/arm64/kernel/signal.c | 43 ++++- arch/arm64/kernel/signal_template.c | 193 ++++++++++++++++++ arch/arm64/kernel/signalilp32.c | 30 +++ arch/arm64/kernel/sys_ilp32.c | 274 ++++++++++++++++++++++++++ arch/arm64/kernel/vdso.c | 81 ++++++++- arch/arm64/kernel/vdsoilp32/.gitignore | 2 + arch/arm64/kernel/vdsoilp32/Makefile | 72 +++++++ arch/arm64/kernel/vdsoilp32/vdso_ilp32.lds.S | 100 ++++++++++ arch/arm64/kernel/vdsoilp32/vdsoilp32.S | 33 +++ arch/arm64/mm/init.c | 1 + 29 files changed, 1076 insertions(+), 58 deletions(-) create mode 100644 arch/arm64/include/uapi/asm/posix_types.h create mode 100644 arch/arm64/kernel/signal_template.c create mode 100644 arch/arm64/kernel/signalilp32.c create mode 100644 arch/arm64/kernel/sys_ilp32.c create mode 100644 arch/arm64/kernel/vdsoilp32/.gitignore create mode 100644 arch/arm64/kernel/vdsoilp32/Makefile create mode 100644 arch/arm64/kernel/vdsoilp32/vdso_ilp32.lds.S create mode 100644 arch/arm64/kernel/vdsoilp32/vdsoilp32.S
arch/arm64/Kconfig +9 -2
@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt" config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF config ARM64_AARCH32
@@ -263,7 +263,14 @@ config ARM64_AARCH32 the user helper functions, VFP support and the ptrace interface are handled appropriately by the kernel. - If you want to execute 32-bit userspace applications, say Y. + If you want to execute Aarch32 userspace applications, say Y. + +config ARM64_ILP32 + bool "Kernel support for ILP32" + help + This option enables support for AArch64 ILP32 user space. These are + 64-bit binaries using 32-bit quantities for addressing and certain + data that would normally be 64-bit. config SYSVIPC_COMPAT def_bool y
arch/arm64/include/asm/Kbuild +0 -1
@@ -28,7 +28,6 @@ generic-y += mutex.h generic-y += pci.h generic-y += percpu.h generic-y += poll.h -generic-y += posix_types.h generic-y += resource.h generic-y += scatterlist.h generic-y += sections.h
arch/arm64/include/asm/compat.h +61 -11
129 lines not on this page · raw message
arch/arm64/include/asm/elf.h +59 -12
92 lines not on this page · raw message
arch/arm64/include/asm/hwcap.h +1 -1
@@ -44,6 +44,6 @@ COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV)extern unsigned int elf_hwcap; -#define COMPAT_ELF_HWCAP COMPAT_ELF_A32_HWCAP +#define COMPAT_ELF_HWCAP (is_aarch32_task() ? COMPAT_ELF_A32_HWCAP : elf_hwcap)#endif #endif
arch/arm64/include/asm/memory.h +2 -2
@@ -52,8 +52,8 @@#define TASK_SIZE (is_compat_task() ? \ TASK_SIZE_32 : TASK_SIZE_64)#else -#define TASK_SIZE TASK_SIZE_64 -#endif +#define TASK_SIZE TASK_SIZE_64 +#endif /* CONFIG_COMPAT */ #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4))
arch/arm64/include/asm/processor.h +0 -12
@@ -99,18 +99,6 @@ static inline void start_thread(struct pt_regs *regs, unsigned long pc, regs->sp = sp; } -#ifdef CONFIG_COMPAT -static inline void compat_start_thread (struct pt_regs *regs,unsigned long pc, -unsigned long sp) -{ -start_thread_common (regs, pc); - regs->pstate =COMPAT_PSR_MODE_USR ; -if (pc &1 ) - regs->pstate |=COMPAT_PSR_T_BIT ; - regs->compat_sp = sp; -} -#endif -/* Forward declaration, a strange C thing */ struct task_struct ;
arch/arm64/include/asm/stat.h +4 -2
@@ -18,9 +18,11 @@#include <uapi/asm/stat.h> -#ifdef CONFIG_ARM64_AARCH32 - +#ifdef CONFIG_COMPAT #include <asm/compat.h> +#endif + +#ifdef CONFIG_ARM64_AARCH32 /* * struct stat64 is needed for compat tasks only. Its definition is different
arch/arm64/include/asm/syscalls.h +3 -0
@@ -24,6 +24,9 @@* System call wrappers implemented in kernel/entry.S. */ asmlinkage long sys_rt_sigreturn_wrapper (void ); +#ifdef CONFIG_ARM64_ILP32 +asmlinkage long sys_ilp32_rt_sigreturn_wrapper (void ); +#endif #include <asm-generic/syscalls.h>
arch/arm64/include/asm/thread_info.h +1 -0
@@ -114,6 +114,7 @@ static inline struct thread_info *current_thread_info(void)#define TIF_SINGLESTEP 21#define TIF_32BIT 22/* 32bit process */ #define TIF_SWITCH_MM 23/* deferred switch_mm */ +#define TIF_32BIT_AARCH64 24/* 32 bit process on AArch64(ILP32) */ #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
arch/arm64/include/asm/unistd.h +7 -3
@@ -13,18 +13,22 @@* 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 +#ifdef CONFIG_ARM64_AARCH32 #define __ARCH_WANT_COMPAT_STAT64#define __ARCH_WANT_SYS_GETHOSTNAME#define __ARCH_WANT_SYS_PAUSE#define __ARCH_WANT_SYS_GETPGRP -#define __ARCH_WANT_SYS_LLSEEK#define __ARCH_WANT_SYS_NICE#define __ARCH_WANT_SYS_SIGPENDING#define __ARCH_WANT_SYS_SIGPROCMASK -#define __ARCH_WANT_COMPAT_SYS_SENDFILE#define __ARCH_WANT_SYS_FORK#define __ARCH_WANT_SYS_VFORK#endif + +#ifdef CONFIG_COMPAT +#define __ARCH_WANT_SYS_LLSEEK +#define __ARCH_WANT_COMPAT_SYS_SENDFILE +#endif +#define __ARCH_WANT_SYS_CLONE#include <uapi/asm/unistd.h>
arch/arm64/include/asm/vdso.h +4 -0
@@ -29,6 +29,10 @@#include <generated/vdso-offsets.h> +#ifdef CONFIG_ARM64_ILP32 +#include <generated/vdso-ilp32-offsets.h> +#endif +#define VDSO_SYMBOL (base, name) \ ({ \ (void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \
arch/arm64/include/uapi/asm/bitsperlong.h +6 -1
@@ -16,7 +16,12 @@#ifndef __ASM_BITSPERLONG_H#define __ASM_BITSPERLONG_H -#define __BITS_PER_LONG 64 + +#ifdef __LP64__ +# define __BITS_PER_LONG 64 +#else +# define __BITS_PER_LONG 32 +#endif #include <asm-generic/bitsperlong.h>
arch/arm64/include/uapi/asm/posix_types.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef __ASM_POSIX_TYPES_H +#define __ASM_POSIX_TYPES_H + +#ifndef __LP64__/* ILP32 */ +typedef long long __kernel_long_t ; +typedef unsigned long long __kernel_ulong_t ; +#define __kernel_long_t __kernel_long_t +#endif + +#include <asm-generic/posix_types.h> + +#endif /* __ASM_POSIX_TYPES_H */
arch/arm64/include/uapi/asm/siginfo.h +6 -0
@@ -16,7 +16,13 @@#ifndef __ASM_SIGINFO_H#define __ASM_SIGINFO_H +#ifdef __LP64__#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#else /* ILP32 */ +typedef long long __kernel_si_clock_t __attribute__((aligned (4 ))); +#define __ARCH_SI_CLOCK_T __kernel_si_clock_t +#define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8))) +#endif #include <asm-generic/siginfo.h>
arch/arm64/kernel/Makefile +7 -0
@@ -13,6 +13,7 @@ arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ arm64-obj-$(CONFIG_ARM64_AARCH32) += sys32.o kuser32.o signal32.o \ sys_compat.o +arm64-obj-$(CONFIG_ARM64_ILP32) += sys_ilp32.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o smp_psci.o arm64-obj-$(CONFIG_HW_PERF_EVENTS) += perf_event.o
@@ -20,6 +21,7 @@ arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += $(arm64-obj-y) vdso/ +obj-$(CONFIG_ARM64_ILP32) += vdsoilp32/ obj-m += $(arm64-obj-m) head-y := head.o extra-y := $(head-y) vmlinux.lds
@@ -27,3 +29,8 @@ 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) +$(call objectify,$(arm64-obj-y)): $(obj)/vdsoilp32/vdso-ilp32-offsets.h +$(obj)/vdsoilp32/vdso-ilp32-offsets.h: $(obj)/vdsoilp32 +endif
arch/arm64/kernel/entry.S +19 -1
@@ -633,9 +633,14 @@ ENDPROC(ret_from_fork) */ .align 6 el0_svc: - adrp stbl, sys_call_table // load syscall table pointer uxtw scno, w8 // syscall number in w8 mov sc_nr, #__NR_syscalls +#ifdef CONFIG_ARM64_ILP32 + get_thread_info tsk + ldr x16, [tsk, #TI_FLAGS] + tbnz x16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32 +#endif + adrp stbl, 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 disable_step x16
@@ -656,6 +661,12 @@ ni_sys: b do_ni_syscall ENDPROC(el0_svc) +#ifdef CONFIG_ARM64_ILP32 +el0_ilp32_svc: + adrp stbl, sys_ilp32_call_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.
@@ -691,5 +702,12 @@ ENTRY(sys_rt_sigreturn_wrapper) b sys_rt_sigreturn ENDPROC(sys_rt_sigreturn_wrapper) +#ifdef CONFIG_ARM64_ILP32 +ENTRY(sys_ilp32_rt_sigreturn_wrapper) + mov x0, sp + b sys_ilp32_rt_sigreturn +ENDPROC(sys_ilp32_rt_sigreturn_wrapper) +#endif + ENTRY(handle_arch_irq) .quad 0
arch/arm64/kernel/process.c +18 -0
@@ -329,3 +329,21 @@ unsigned long randomize_et_dyn(unsigned long base) {return randomize_base (base); } + +#ifdef CONFIG_ARM64_AARCH32 +void compat_start_thread (struct pt_regs *regs,unsigned long pc, +unsigned long sp) +{ +if (is_ilp32_task ()) { +start_thread (regs, pc, sp); +return ; + } + +start_thread_common (regs, pc); + regs->pstate =COMPAT_PSR_MODE_USR ; +if (pc &1 ) + regs->pstate |=COMPAT_PSR_T_BIT ; + regs->compat_sp = sp; +} +#endif +
arch/arm64/kernel/ptrace.c +35 -3
@@ -609,8 +609,11 @@ static const struct user_regset_view user_aarch64_view = { .regsets = aarch64_regsets, .n = ARRAY_SIZE(aarch64_regsets) }; -#ifdef CONFIG_ARM64_AARCH32 +#ifdef CONFIG_COMPAT #include <linux/compat.h> +#endif + +#ifdef CONFIG_ARM64_AARCH32 enum compat_regset { REGSET_COMPAT_GPR,
@@ -968,8 +971,9 @@ 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, -compat_ulong_t caddr,compat_ulong_t cdata) + +static long compat_arch_aarch32_ptrace (struct task_struct *child,compat_long_t request, +compat_ulong_t caddr,compat_ulong_t cdata) {unsigned long addr = caddr;unsigned long data = cdata;
@@ -1047,6 +1051,34 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, }#endif /* CONFIG_ARM64_AARCH32 */ +#ifdef CONFIG_ARM64_ILP32 +static long compat_arch_ilp32_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_ARM64_ILP32 */ + +#ifdef CONFIG_COMPAT +long compat_arch_ptrace (struct task_struct *child,compat_long_t request, +compat_ulong_t caddr,compat_ulong_t cdata) +{ + +#ifdef CONFIG_ARM64_ILP32 +if (is_ilp32_task ()) +return compat_arch_ilp32_ptrace (child, request, caddr, cdata); +#endif + +#ifdef CONFIG_ARM64_AARCH32 +if (is_aarch32_task ()) +return compat_arch_aarch32_ptrace (child, request, caddr, cdata); +#endif + +panic ("Calling compat_arch_ptrace without being ilp32 or aarch32 task." ); +} + +#endif +const struct user_regset_view *task_user_regset_view (struct task_struct *task) {#ifdef CONFIG_ARM64_AARCH32
arch/arm64/kernel/signal.c +38 -5
74 lines not on this page · raw message
arch/arm64/kernel/signal_template.c new file +193 -0
193 lines not on this page · raw message
arch/arm64/kernel/signalilp32.c new file +30 -0
@@ -0,0 +1,30 @@ + +#ifdef CONFIG_ARM64_ILP32 + +#define rt_sigframe rt_sigframe_ilp32 +#define restore_sigframe restore_sigframe_ilp32 +#define sys_rt_sigreturn sys_ilp32_rt_sigreturn +#define restore_altstack compat_restore_altstack +#define setup_sigframe setup_sigframe_ilp32 +#define get_sigframe get_sigframe_ilp32 +#define setup_return setup_return_ilp32 +#define setup_rt_frame setup_rt_frame_ilp32 +#define __save_altstack __compat_save_altstack +#define copy_siginfo_to_user copy_siginfo_to_user32 +#define ilp32 + +#include "signal_template.c" + +#undef rt_sigframe +#undef restore_sigframe +#undef sys_rt_sigreturn +#undef restore_altstack +#undef setup_sigframe +#undef get_sigframe +#undef setup_return +#undef setup_rt_frame +#undef __save_altstack +#undef copy_siginfo_to_user +#undef ilp32 + +#endif
arch/arm64/kernel/sys_ilp32.c new file +274 -0
274 lines not on this page · raw message
arch/arm64/kernel/vdso.c +79 -2
116 lines not on this page · raw message
arch/arm64/kernel/vdsoilp32/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +vdso_ilp32.lds +vdso-ilp32-offsets.h
arch/arm64/kernel/vdsoilp32/Makefile new file +72 -0
72 lines not on this page · raw message
arch/arm64/kernel/vdsoilp32/vdso_ilp32.lds.S new file +100 -0
100 lines not on this page · raw message
arch/arm64/kernel/vdsoilp32/vdsoilp32.S new file +33 -0
@@ -0,0 +1,33 @@ +/* + * Copyright (C) 2012 ARM Limited + * + * 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/>. + * + * Author: Will Deacon <[email protected]> + */ + +#include <linux/init.h> +#include <linux/linkage.h> +#include <linux/const.h> +#include <asm/page.h> + + __PAGE_ALIGNED_DATA + + .globl vdsoilp32_start, vdsoilp32_end + .balign PAGE_SIZE +vdsoilp32_start: + .incbin "arch/arm64/kernel/vdsoilp32/vdso_ilp32.so" + .balign PAGE_SIZE +vdsoilp32_end: + + .previous
arch/arm64/mm/init.c +1 -0
@@ -35,6 +35,7 @@#include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> +#include <asm/compat.h> #include <asm/tlb.h> #include "mm.h"
Signature · 1 line
1.7.2.5
Catalin Marinas
maintainerRe: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 1 line · Andrew Pinski
This patch adds full support of the ABI to the ARM64 target.
This description is too short. Please describe what the ABI is, what are the commonalities with AArch64 and AArch32, what other non-obvious things had to be done (like __kernel_long_t being long long). Split this patch into multiple patches like base syscall handling, signal handling, pselect6/ppoll, vdso etc. It's too much to review at once.
On top of these, I would really like to seeDocumentation/arm64/ilp32.txt describing the ABI.
I would also like to know (you can state this in the cover letter) the level of testing for all 3 types of ABI. I'm worried that at least this patch breaks the current compat ABI (has LTP reported anything?).
Quoted 16 lines
arch/arm64/Kconfig +1
-1@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt" config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF config ARM64_AARCH32@@ -263,7 +263,14 @@ config ARM64_AARCH32 the user helper functions, VFP support and the ptrace interface are handled appropriately by the kernel.
arch/arm64/Kconfig config ARM64_AARCH32 · line 273
Quoted 10 lines
arch/arm64/Kconfig +8
-1- If you want to execute 32-bit userspace applications, say Y. + If you want to execute Aarch32 userspace applications, say Y. + +config ARM64_ILP32 + bool "Kernel support for ILP32" + help + This option enables support for AArch64 ILP32 user space. These are + 64-bit binaries using 32-bit quantities for addressing and certain + data that would normally be 64-bit.
You could be even more precise by mentioning that longs and pointers are 32-bit, together with the derived types.
Quoted 15 lines
arch/arm64/include/asm/compat.h +2
-0@@ -62,6 +62,8 @@ typedef u32 compat_ulong_t;typedef u64 compat_u64 ;typedef u32 compat_uptr_t ; +typedef s64 ilp32_clock_t ; +struct compat_timespec {compat_time_t tv_sec;s32 tv_nsec;@@ -180,6 +182,15 @@ typedef struct compat_siginfo {compat_clock_t _stime;
arch/arm64/include/asm/compat.h typedef struct compat_siginfo { · line 192
Quoted 10 lines
arch/arm64/include/asm/compat.h +8
-0} _sigchld; +/* SIGCHLD (ILP32 version) */ +struct { +compat_pid_t _pid;/* which child */ +__compat_uid32_t _uid;/* sender's uid */ +int _status;/* exit code */ +ilp32_clock_t _utime; +ilp32_clock_t _stime; + } _sigchld_ilp32;
This *breaks* the compat_siginfo alignment. ilp32_clock_t is 64-bit which forces the _sigchld_ilp32 to be 64-bit which makes the preamble 16 instead of 12 bytes. This ilp32_clock_t needs __attribute__((aligned(4))).
The other approach I've been looking at is just using the native siginfo instead of the compat one for ILP32. But this requires wider debate (cc'ed Arnd if he has time).
Basically if you use the current siginfo in the ILP32 context with __kernel_clock_t being 64-bit you end up with a structure that doesn't match any of the native or compat siginfo. This is because we have some pointers which will turn into 32-bit values in ILP32:
void __user *sival_ptr; /* accessed via si_ptr */
void __user *_addr; /* accessed via si_addr */
void __user *_call_addr; /* accessed via si_call_addr */We also have __ARCH_SI_BAND_T defined as long.
AFAICT, Linux only does a put_user() on these and never reads them from user space. This means that we can add the right padding on either side of these pointers (for endianness reasons) and Linux would write 0 as the top part of a 64-bit pointer (since the user address is restricted to 32-bit anyway). User ILP32 would only access the corresponding pointer as a 32-bit value and ignore the padding.
It's easier to explain with some code (untested):
arch/arm64/include/uapi/asm/siginfo.h +7 -0
@@ -18,6 +18,13 @@#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#ifndef __LP64__/* ILP32 */ +#define __ARCH_SI_BAND_T long long +#define VOID_USER_PTR (x) \ + void __user *x __attribute__((aligned(8))); \ + char _pad[4] +#endif +#include <asm-generic/siginfo.h> #endif
include/uapi/asm-generic/siginfo.h +7 -3
@@ -4,9 +4,13 @@#include <linux/compiler.h> #include <linux/types.h> +#ifndef VOID_USER_PTR +#define VOID_USER_PTR (x) void __user *x +#endif +typedef union sigval {int sival_int; -void __user *sival_ptr; +VOID_USER_PTR (sival_ptr); }sigval_t ;/*
@@ -86,7 +90,7 @@ typedef struct siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ struct { -void __user *_addr;/* faulting insn/memory ref. */ +VOID_USER_PTR (_addr);/* faulting insn/memory ref. */ #ifdef __ARCH_SI_TRAPNOint _trapno;/* TRAP # which caused the signal */ #endif
@@ -101,7 +105,7 @@ typedef struct siginfo {/* SIGSYS */ struct { -void __user *_call_addr;/* calling user insn */ +VOID_USER_PTR (_call_addr);/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys;
__LP64__ is always defined for AArch64 (kernel and native applications). ILP32 user would not get this symbol and compat use a separate compat_siginfo anyway.
I'm not entirely sure about defining __ARCH_SI_BAND_T to long long but as it also seems to be just written by the kernel, we can use some padding as for the void __user *.
So, I'm looking for feedback on this proposal.
arch/arm64/include/asm/stat.h line 23
Quoted 13 lines
arch/arm64/include/asm/stat.h +2
-2@@ -18,9 +18,11 @@#include <uapi/asm/stat.h> -#ifdef CONFIG_ARM64_AARCH32 - +#ifdef CONFIG_COMPAT #include <asm/compat.h> +#endif
Doesn't asm/compat.h have guards already? Do you get a conflict with is_compat_task()?
Quoted 5 lines
arch/arm64/include/uapi/asm/siginfo.h +0
-0
arch/arm64/include/uapi/asm/siginfo.h line 25
Quoted 10 lines
arch/arm64/include/uapi/asm/siginfo.h +6
-0@@ -16,7 +16,13 @@#ifndef __ASM_SIGINFO_H#define __ASM_SIGINFO_H +#ifdef __LP64__#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#else /* ILP32 */ +typedef long long __kernel_si_clock_t __attribute__((aligned (4 ))); +#define __ARCH_SI_CLOCK_T __kernel_si_clock_t +#define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8))) +#endif
This could go away if we manage to use the native siginfo.
arch/arm64/kernel/signalilp32.c line 4
Quoted 7 lines
arch/arm64/kernel/signalilp32.c new file +4
-0@@ -0,0 +1,30 @@ + +#ifdef CONFIG_ARM64_ILP32 + +#define rt_sigframe rt_sigframe_ilp32
Can we have the same native rt_sigframe (if we go for the native siginfo)? ucontext is an arm64 structure, so we can add padding for pointers and long.
Quoted 14 lines
arch/arm64/kernel/sys_ilp32.c new file +11
-0@@ -0,0 +1,274 @@ +/* +* AArch64- ILP32 specific system calls implementation +* +* Copyright (C) 2013 Cavium Inc. +* Author: Andrew Pinski <[email protected]> +* +* 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,
arch/arm64/kernel/sys_ilp32.c line 21
Quoted 10 lines
arch/arm64/kernel/sys_ilp32.c new file +10
-0+* 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/>. +*/ + +/* Adjust unistd.h to provide 32-bit numbers and functions. */ +#define __SYSCALL_COMPAT
No. We need to use as many native syscalls as possible and only define those absolutely necessary. In my investigation, I only ended up needing these:
#define sys_ioctl compat_sys_ioctl
#define sys_readv compat_sys_readv
#define sys_writev compat_sys_writev
#define sys_preadv compat_sys_preadv64
#define sys_pwritev compat_sys_pwritev64
#define sys_vmsplice compat_sys_vmsplice
#define sys_waitid compat_sys_waitid
#define sys_set_robust_list compat_sys_set_robust_list
#define sys_get_robust_list compat_sys_get_robust_list
#define sys_kexec_load compat_sys_kexec_load
#define sys_timer_create compat_sys_timer_create
#define sys_ptrace compat_sys_ptrace
#define sys_sigaltstack compat_sys_sigaltstack
#define sys_rt_sigaction compat_sys_rt_sigaction
#define sys_rt_sigpending compat_sys_rt_sigpending
#define sys_rt_sigtimedwait compat_sys_rt_sigtimedwait
#define sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo
#define sys_rt_sigreturn compat_sys_rt_sigreturn_wrapper
#define sys_mq_notify compat_sys_mq_notify
#define sys_recvfrom compat_sys_recvfrom
#define sys_setsockopt compat_sys_setsockopt
#define sys_getsockopt compat_sys_getsockopt
#define sys_sendmsg compat_sys_sendmsg
#define sys_recvmsg compat_sys_recvmsg
#define sys_execve compat_sys_execve
#define sys_move_pages compat_sys_move_pages
#define sys_rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo
#define sys_recvmmsg compat_sys_recvmmsg
#define sys_sendmmsg compat_sys_sendmmsg
#define sys_process_vm_readv compat_sys_process_vm_readv
#define sys_process_vm_writev compat_sys_process_vm_writev
arch/arm64/kernel/vdsoilp32/Makefile
Quoted 5 lines
arch/arm64/kernel/vdsoilp32/Makefile new file +0
-0
Could we not keep vdso in the same directory?
arch/arm64/mm/init.c line 39
Quoted 10 lines
arch/arm64/mm/init.c +1
-0@@ -35,6 +35,7 @@#include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> +#include <asm/compat.h> #include <asm/tlb.h>
Same issue, other header files doesn't include what is necessary.
--
Catalin
Re: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 8 lines · Catalin Marinas
Quoted 1 line · Andrew Pinski
This patch adds full support of the ABI to the ARM64 target.
This description is too short. Please describe what the ABI is, what are the commonalities with AArch64 and AArch32, what other non-obvious things had to be done (like
__kernel_long_tbeing long long). Split this patch into multiple patches like base syscall handling, signal handling, pselect6/ppoll, vdso etc. It's too much to review at once.
Ok. I will do so after my vacation next week.
Quoted 3 lines
On top of these, I would really like to see
Documentation/arm64/ilp32.txtdescribing the ABI.
No other target does not, not even x86_64 for x32.
Quoted 4 lines
I would also like to know (you can state this in the cover letter) the level of testing for all 3 types of ABI. I'm worried that at least this patch breaks the current compat ABI (has LTP reported anything?).
We did test LTP on an earlier version of this patch for all three ABIs, I will make sure that the next version I send out is tested on all three ABIs also. We also tested ILP32/LP64 on big-endian at the same time which we will continue to do (I should push for our team here to push out the big-endian patches).
Quoted 18 lines
Quoted 18 lines
arch/arm64/Kconfig +1
-1@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt" config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF config ARM64_AARCH32@@ -263,7 +263,14 @@ config ARM64_AARCH32 the user helper functions, VFP support and the ptrace interface are handled appropriately by the kernel.
Quoted 12 lines
arch/arm64/Kconfig config ARM64_AARCH32 · line 273
Quoted 9 lines
arch/arm64/Kconfig +8
-1- If you want to execute 32-bit userspace applications, say Y. + If you want to execute Aarch32 userspace applications, say Y. + +config ARM64_ILP32 + bool "Kernel support for ILP32" + help + This option enables support for AArch64 ILP32 user space. These are + 64-bit binaries using 32-bit quantities for addressing and certain + data that would normally be 64-bit.You could be even more precise by mentioning that longs and pointers are 32-bit, together with the derived types.
I copied this from the MIPS64 n32 description in Kconfig. But I will make it more explicit.
Quoted 18 lines
Quoted 18 lines
arch/arm64/include/asm/compat.h +2
-0@@ -62,6 +62,8 @@ typedef u32 compat_ulong_t;typedef u64 compat_u64 ;typedef u32 compat_uptr_t ; +typedef s64 ilp32_clock_t ; +struct compat_timespec {compat_time_t tv_sec;s32 tv_nsec;@@ -180,6 +182,15 @@ typedef struct compat_siginfo {compat_clock_t _stime; } _sigchld;
Quoted 13 lines
arch/arm64/include/asm/compat.h typedef struct compat_siginfo { · line 192
Quoted 8 lines
arch/arm64/include/asm/compat.h +8
-0+/* SIGCHLD (ILP32 version) */ +struct { +compat_pid_t _pid;/* which child */ +__compat_uid32_t _uid;/* sender's uid */ +int _status;/* exit code */ +ilp32_clock_t _utime; +ilp32_clock_t _stime; + } _sigchld_ilp32;This *breaks* the
compat_siginfoalignment.ilp32_clock_tis 64-bit which forces the_sigchld_ilp32to be 64-bit which makes the preamble 16 instead of 12 bytes. Thisilp32_clock_tneeds __attribute__((aligned(4))).
I will check on this.
Quoted 4 lines
The other approach I've been looking at is just using the native siginfo instead of the compat one for ILP32. But this requires wider debate (cc'ed Arnd if he has time).
This is not useful and as you shown can be very messy and even worse when it comes taking into account big and little-endian. Even x32 does not do that.
Quoted 11 lines
Basically if you use the current siginfo in the ILP32 context with
__kernel_clock_tbeing 64-bit you end up with a structure that doesn't match any of the native or compat siginfo. This is because we have some pointers which will turn into 32-bit values in ILP32:void __user *sival_ptr; /* accessed via si_ptr */ void __user *_addr; /* accessed via si_addr */ void __user *_call_addr; /* accessed via si_call_addr */We also have
__ARCH_SI_BAND_Tdefined as long.
I had first thought about this and even started to implement it but I found the glibc and the kernel messier than it was already.
Quoted 7 lines
AFAICT, Linux only does a
put_user()on these and never reads them from user space. This means that we can add the right padding on either side of these pointers (for endianness reasons) and Linux would write 0 as the top part of a 64-bit pointer (since the user address is restricted to 32-bit anyway). User ILP32 would only access the corresponding pointer as a 32-bit value and ignore the padding.
And I am not a fan of changing the generic UAPI files just so it is no longer generic like you are doing.
Quoted 64 lines
It's easier to explain with some code (untested):
arch/arm64/include/uapi/asm/siginfo.h +7
-0@@ -18,6 +18,13 @@#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#ifndef __LP64__/* ILP32 */ +#define __ARCH_SI_BAND_T long long +#define VOID_USER_PTR (x) \ + void __user *x __attribute__((aligned(8))); \ + char _pad[4] +#endif +#include <asm-generic/siginfo.h> #endif include/uapi/asm-generic/siginfo.h +7
-3@@ -4,9 +4,13 @@#include <linux/compiler.h> #include <linux/types.h> +#ifndef VOID_USER_PTR +#define VOID_USER_PTR (x) void __user *x +#endif +typedef union sigval {int sival_int; -void __user *sival_ptr; +VOID_USER_PTR (sival_ptr); }sigval_t ;/* @@ -86,7 +90,7 @@ typedef struct siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ struct { -void __user *_addr;/* faulting insn/memory ref. */ +VOID_USER_PTR (_addr);/* faulting insn/memory ref. */ #ifdef __ARCH_SI_TRAPNOint _trapno;/* TRAP # which caused the signal */ #endif @@ -101,7 +105,7 @@ typedef struct siginfo {/* SIGSYS */ struct { -void __user *_call_addr;/* calling user insn */ +VOID_USER_PTR (_call_addr);/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys;
__LP64__is always defined for AArch64 (kernel and native applications). ILP32 user would not get this symbol and compat use a separatecompat_siginfoanyway.
Quoted 6 lines
I'm not entirely sure about defining
__ARCH_SI_BAND_Tto long long but as it also seems to be just written by the kernel, we can use some padding as for the void__user*.So, I'm looking for feedback on this proposal.
As I mentioned before even x32 does not do that and it is very messy to make sure things get zero'd on the glibc and kernel sides.
Quoted 9 lines
Quoted 9 lines
arch/arm64/include/asm/stat.h +0
-0@@ -18,9 +18,11 @@#include <uapi/asm/stat.h>
Quoted 8 lines
arch/arm64/include/asm/stat.h line 23
Quoted 5 lines
arch/arm64/include/asm/stat.h +2
-2-#ifdef CONFIG_ARM64_AARCH32 - +#ifdef CONFIG_COMPAT #include <asm/compat.h> +#endif Doesn't
asm/compat.hhave guards already? Do you get a conflict withis_compat_task()?
The guard was there already, I am just changing it back to be under CONFIG_COMPAT from when I added CONFIG_ARM64_AARCH32. When I submit the next version of the set of patches, this change will be done correctly in the patch which adds CONFIG_ARM64_AARCH32.
Quoted 9 lines
Quoted 9 lines
arch/arm64/include/uapi/asm/siginfo.h +0
-0@@ -16,7 +16,13 @@#ifndef __ASM_SIGINFO_H#define __ASM_SIGINFO_H
Quoted 9 lines
arch/arm64/include/uapi/asm/siginfo.h line 25
Quoted 7 lines
arch/arm64/include/uapi/asm/siginfo.h +6
-0+#ifdef __LP64__#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#else /* ILP32 */ +typedef long long __kernel_si_clock_t __attribute__((aligned (4 ))); +#define __ARCH_SI_CLOCK_T __kernel_si_clock_t +#define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8))) +#endif This could go away if we manage to use the native siginfo.
See above why I think this is a bad thing and even worse since even x32 did not do that already; it was the last added ABI like ILP32 to the kernel.
Quoted 12 lines
arch/arm64/kernel/signalilp32.c line 4
Quoted 8 lines
arch/arm64/kernel/signalilp32.c new file +4
-0@@ -0,0 +1,30 @@ + +#ifdef CONFIG_ARM64_ILP32 + +#define rt_sigframe rt_sigframe_ilp32Can we have the same native
rt_sigframe(if we go for the native siginfo)? ucontext is an arm64 structure, so we can add padding for pointers and long.
No again this is messy due to the zeroing of the values. As I mentioned, I started to implement that but it got messy and there was no right way of having the headers be sane.
Quoted 21 lines
Quoted 21 lines
arch/arm64/kernel/sys_ilp32.c new file +17
-0@@ -0,0 +1,274 @@ +/* +* AArch64- ILP32 specific system calls implementation +* +* Copyright (C) 2013 Cavium Inc. +* Author: Andrew Pinski <[email protected]> +* +* 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/>.
Quoted 8 lines
arch/arm64/kernel/sys_ilp32.c line 21
Quoted 4 lines
arch/arm64/kernel/sys_ilp32.c new file +4
-0+*/ + +/* Adjust unistd.h to provide 32-bit numbers and functions. */ +#define __SYSCALL_COMPATNo. We need to use as many native syscalls as possible and only define those absolutely necessary. In my investigation, I only ended up needing these:
No using __SYSCALL_COMPAT is the correct thing to do and then only reverting back what is needed.
The main reason is due to using the generic support inside glibc already.
Quoted 24 lines
#define sys_ioctl compat_sys_ioctl #define sys_readv compat_sys_readv #define sys_writev compat_sys_writev #define sys_preadv compat_sys_preadv64 #define sys_pwritev compat_sys_pwritev64 #define sys_vmsplice compat_sys_vmsplice #define sys_waitid compat_sys_waitid #define sys_set_robust_list compat_sys_set_robust_list #define sys_get_robust_list compat_sys_get_robust_list #define sys_kexec_load compat_sys_kexec_load #define sys_timer_create compat_sys_timer_create #define sys_ptrace compat_sys_ptrace #define sys_sigaltstack compat_sys_sigaltstack #define sys_rt_sigaction compat_sys_rt_sigaction #define sys_rt_sigpending compat_sys_rt_sigpending #define sys_rt_sigtimedwait compat_sys_rt_sigtimedwait #define sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo #define sys_rt_sigreturn compat_sys_rt_sigreturn_wrapper #define sys_mq_notify compat_sys_mq_notify #define sys_recvfrom compat_sys_recvfrom #define sys_setsockopt compat_sys_setsockopt #define sys_getsockopt compat_sys_getsockopt #define sys_sendmsg compat_sys_sendmsg
Quoted 8 lines
#define sys_recvmsg compat_sys_recvmsg #define sys_execve compat_sys_execve #define sys_move_pages compat_sys_move_pages #define sys_rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo #define sys_recvmmsg compat_sys_recvmmsg #define sys_sendmmsg compat_sys_sendmmsg #define sys_process_vm_readv compat_sys_process_vm_readv #define sys_process_vm_writev compat_sys_process_vm_writev
You even forgot compat_sys_openat (where O_LARGEFILE differences does make a difference).
Quoted 8 lines
arch/arm64/kernel/vdsoilp32/Makefile
Quoted 6 lines
arch/arm64/kernel/vdsoilp32/Makefile new file +0
-0Could we not keep vdso in the same directory?
I started out that way but "make clean ARCH=arm64" did not clean the vdso files all the time.
Quoted 13 lines
arch/arm64/mm/init.c line 39
Quoted 11 lines
arch/arm64/mm/init.c +1
-0@@ -35,6 +35,7 @@#include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> +#include <asm/compat.h> #include <asm/tlb.h> Same issue, other header files doesn't include what is necessary.
I will double check these but I think it was a fall out due to my change that I had originally did for asm/stat.h .
Thanks,
Andrew Pinski
Re: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 11 lines · Andrew Pinski
Quoted 8 lines · Catalin Marinas
Quoted 1 line · Andrew Pinski
This patch adds full support of the ABI to the ARM64 target.
This description is too short. Please describe what the ABI is, what are the commonalities with AArch64 and AArch32, what other non-obvious things had to be done (like
__kernel_long_tbeing long long). Split this patch into multiple patches like base syscall handling, signal handling, pselect6/ppoll, vdso etc. It's too much to review at once.
Quoted 7 lines
Ok. I will do so after my vacation next week.
Quoted 3 lines
On top of these, I would really like to see
Documentation/arm64/ilp32.txtdescribing the ABI.No other target does not, not even
x86_64for x32.
Well, I'm sure they wouldn't mind if you submitted documentation for them too.
Quoted 9 lines
Quoted 3 lines
I would also like to know (you can state this in the cover letter) the level of testing for all 3 types of ABI. I'm worried that at least this patch breaks the current compat ABI (has LTP reported anything?).
We did test LTP on an earlier version of this patch for all three ABIs, I will make sure that the next version I send out is tested on all three ABIs also. We also tested ILP32/LP64 on big-endian at the same time which we will continue to do (I should push for our team here to push out the big-endian patches).
We also have some BE patches internally, but obviously they just target LP64 and AArch32 compat. I'd hope to get these out shortly (the current issue is extensive testing, since we don't have much of a BE userspace).
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/arm64/Kconfig +0
-0@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt"
Quoted 7 lines
Quoted 7 lines
arch/arm64/Kconfig source "fs/Kconfig.binfmt" · line 254
Quoted 7 lines
arch/arm64/Kconfig +1
-1config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF config ARM64_AARCH32
(nitpick) We used to have an option like this, called CONFIG_AARCH32_EMULATION, which I think is clearer than CONFIG_ARM64_AARCH32.
Quoted 10 lines
Quoted 7 lines
arch/arm64/kernel/vdsoilp32/Makefile
Quoted 5 lines
arch/arm64/kernel/vdsoilp32/Makefile new file +0
-0Could we not keep vdso in the same directory?
I started out that way but "make clean ARCH=arm64" did not clean the vdso files all the time.
Can you elaborate please? I'd much rather we fix broken make rules instead of botching around the issue by creating new directories.
Will
Catalin Marinas
maintainerRe: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 16 lines · Will Deacon
Quoted 15 lines · Andrew Pinski
Quoted 13 lines · Catalin Marinas
Quoted 12 lines · Andrew Pinski
arch/arm64/Kconfig +1
-1@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt" config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF
Quoted 4 lines
Quoted 1 line
Quoted 1 line
arch/arm64/Kconfig source "fs/Kconfig.binfmt" · line 254
Quoted 1 line
arch/arm64/Kconfig +0
-0config ARM64_AARCH32(nitpick) We used to have an option like this, called
CONFIG_AARCH32_EMULATION, which I think is clearer thanCONFIG_ARM64_AARCH32.
I think avoiding "EMULATION" is better, we don't actually emulate the instruction set ;).
Signature · 1 line
Catalin
Re: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 17 lines · Catalin Marinas
Quoted 16 lines · Will Deacon
Quoted 15 lines · Andrew Pinski
Quoted 13 lines · Catalin Marinas
Quoted 12 lines · Andrew Pinski
arch/arm64/Kconfig +1
-1@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt" config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
arch/arm64/Kconfig source "fs/Kconfig.binfmt" · line 254
Quoted 1 line
arch/arm64/Kconfig +0
-0config ARM64_AARCH32(nitpick) We used to have an option like this, called
CONFIG_AARCH32_EMULATION, which I think is clearer thanCONFIG_ARM64_AARCH32.I think avoiding "EMULATION" is better, we don't actually emulate the instruction set ;).
Bah, you suggest something better then!
Will
Catalin Marinas
maintainerRe: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 23 lines · Will Deacon
Quoted 22 lines · Catalin Marinas
Quoted 20 lines · Will Deacon
Quoted 9 lines · Andrew Pinski
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Andrew Pinski
arch/arm64/Kconfig +0
-0@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt"Quoted 7 lines
Quoted 7 lines
arch/arm64/Kconfig source "fs/Kconfig.binfmt" · line 254
Quoted 7 lines
arch/arm64/Kconfig +1
-1config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF config ARM64_AARCH32(nitpick) We used to have an option like this, called
CONFIG_AARCH32_EMULATION, which I think is clearer thanCONFIG_ARM64_AARCH32.
Quoted 4 lines
Quoted 2 lines
I think avoiding "EMULATION" is better, we don't actually emulate the instruction set ;).
Bah, you suggest something better then!
CONFIG_AARCH32_EL0.
Signature · 1 line
Catalin
Catalin Marinas
maintainerRe: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
In reply to Andrew PinskiQuoted 8 lines · Andrew Pinski
Quoted 4 lines · Catalin Marinas
On Mon, Sep 09, 2013 at 10:32:59PM +0100, Andrew Pinski wrote:
On top of these, I would really like to see
Documentation/arm64/ilp32.txtdescribing the ABI.No other target does not, not even
x86_64for x32.
That's not really a good argument.
Quoted 7 lines
Quoted 3 lines
The other approach I've been looking at is just using the native siginfo instead of the compat one for ILP32. But this requires wider debate (cc'ed Arnd if he has time).
This is not useful and as you shown can be very messy and even worse when it comes taking into account big and little-endian. Even x32 does not do that.
Well, please don't bring the "x32 does not do that" argument. It doesn't mean we shouldn't investigate better ways. Initially x32 got the siginfo members alignment wrong and they ended up __ARCH_SI_CLOCK_T and __ARCH_SI_ATTRIBUTES, changing the generic uapi files.
Quoted 5 lines
Quoted 5 lines
Basically if you use the current siginfo in the ILP32 context with
__kernel_clock_tbeing 64-bit you end up with a structure that doesn't match any of the native or compat siginfo. This is because we have some pointers which will turn into 32-bit values in ILP32:
Quoted 8 lines
Quoted 5 lines
void __user *sival_ptr; /* accessed via si_ptr */ void __user *_addr; /* accessed via si_addr */ void __user *_call_addr; /* accessed via si_call_addr */We also have
__ARCH_SI_BAND_Tdefined as long.I had first thought about this and even started to implement it but I found the glibc and the kernel messier than it was already.
The kernel part wasn't bad IMO (of course, needs ack from generic headers maintainer). I can't talk about glibc but wouldn't it just access these members explicitly?
Quoted 9 lines
Quoted 6 lines
AFAICT, Linux only does a
put_user()on these and never reads them from user space. This means that we can add the right padding on either side of these pointers (for endianness reasons) and Linux would write 0 as the top part of a 64-bit pointer (since the user address is restricted to 32-bit anyway). User ILP32 would only access the corresponding pointer as a 32-bit value and ignore the padding.And I am not a fan of changing the generic UAPI files just so it is no longer generic like you are doing.
As I said above, x32 did that already and your are doing similar things for __ARCH_SI_CLOCK_T.
Quoted 4 lines
Quoted 1 line
So, I'm looking for feedback on this proposal.
As I mentioned before even x32 does not do that and it is very messy to make sure things get zero'd on the glibc and kernel sides.
(not the x32 argument again)
On the kernel side, they get zeroed automatically because the kernel assumes it is a 64-bit address for user space, which is restricted to 32-bit only. Are these members ever read back by the kernel? That's where glibc zeroing would be needed (and I wouldn't like it either).
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
arch/arm64/include/uapi/asm/siginfo.h +0
-0@@ -16,7 +16,13 @@#ifndef __ASM_SIGINFO_H#define __ASM_SIGINFO_HQuoted 9 lines
arch/arm64/include/uapi/asm/siginfo.h line 25
Quoted 7 lines
arch/arm64/include/uapi/asm/siginfo.h +6
-0+#ifdef __LP64__#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#else /* ILP32 */ +typedef long long __kernel_si_clock_t __attribute__((aligned (4 ))); +#define __ARCH_SI_CLOCK_T __kernel_si_clock_t +#define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8))) +#endif This could go away if we manage to use the native siginfo.
Quoted 3 lines
See above why I think this is a bad thing and even worse since even x32 did not do that already; it was the last added ABI like ILP32 to the kernel.
The x32 thing is becoming the central theme.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
arch/arm64/kernel/sys_ilp32.c new file +17
-0@@ -0,0 +1,274 @@ +/* +* AArch64- ILP32 specific system calls implementation +* +* Copyright (C) 2013 Cavium Inc. +* Author: Andrew Pinski <[email protected]> +* +* 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/>. Quoted 8 lines
arch/arm64/kernel/sys_ilp32.c line 21
Quoted 4 lines
arch/arm64/kernel/sys_ilp32.c new file +4
-0+*/ + +/* Adjust unistd.h to provide 32-bit numbers and functions. */ +#define __SYSCALL_COMPATNo. We need to use as many native syscalls as possible and only define those absolutely necessary. In my investigation, I only ended up needing these:
Quoted 2 lines
No using
__SYSCALL_COMPATis the correct thing to do and then only reverting back what is needed.
I _disagree_. "Even x32 does not to that". Some past discussions:
http://thread.gmane.org/gmane.linux.kernel/1184913
Quoted 32 lines
Quoted 23 lines
#define sys_ioctl compat_sys_ioctl #define sys_readv compat_sys_readv #define sys_writev compat_sys_writev #define sys_preadv compat_sys_preadv64 #define sys_pwritev compat_sys_pwritev64 #define sys_vmsplice compat_sys_vmsplice #define sys_waitid compat_sys_waitid #define sys_set_robust_list compat_sys_set_robust_list #define sys_get_robust_list compat_sys_get_robust_list #define sys_kexec_load compat_sys_kexec_load #define sys_timer_create compat_sys_timer_create #define sys_ptrace compat_sys_ptrace #define sys_sigaltstack compat_sys_sigaltstack #define sys_rt_sigaction compat_sys_rt_sigaction #define sys_rt_sigpending compat_sys_rt_sigpending #define sys_rt_sigtimedwait compat_sys_rt_sigtimedwait #define sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo #define sys_rt_sigreturn compat_sys_rt_sigreturn_wrapper #define sys_mq_notify compat_sys_mq_notify #define sys_recvfrom compat_sys_recvfrom #define sys_setsockopt compat_sys_setsockopt #define sys_getsockopt compat_sys_getsockopt #define sys_sendmsg compat_sys_sendmsgQuoted 8 lines
#define sys_recvmsg compat_sys_recvmsg #define sys_execve compat_sys_execve #define sys_move_pages compat_sys_move_pages #define sys_rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo #define sys_recvmmsg compat_sys_recvmmsg #define sys_sendmmsg compat_sys_sendmmsg #define sys_process_vm_readv compat_sys_process_vm_readv #define sys_process_vm_writev compat_sys_process_vm_writev
Quoted 2 lines
You even forgot
compat_sys_openat(whereO_LARGEFILEdifferences does make a difference).
Just read the above thread. "Even x32 does not do that".
Quoted 10 lines
Quoted 7 lines
arch/arm64/kernel/vdsoilp32/Makefile
Quoted 5 lines
arch/arm64/kernel/vdsoilp32/Makefile new file +0
-0Could we not keep vdso in the same directory?
I started out that way but "make clean ARCH=arm64" did not clean the vdso files all the time.
I'll leave vdso comments to Will.
Signature · 1 line
Catalin
Re: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
Quoted 34 lines · Catalin Marinas
Quoted 8 lines · Andrew Pinski
Quoted 4 lines · Catalin Marinas
On Mon, Sep 09, 2013 at 10:32:59PM +0100, Andrew Pinski wrote:
On top of these, I would really like to see
Documentation/arm64/ilp32.txtdescribing the ABI.No other target does not, not even
x86_64for x32.That's not really a good argument.
Quoted 7 lines
Quoted 3 lines
The other approach I've been looking at is just using the native siginfo instead of the compat one for ILP32. But this requires wider debate (cc'ed Arnd if he has time).
This is not useful and as you shown can be very messy and even worse when it comes taking into account big and little-endian. Even x32 does not do that.
Well, please don't bring the "x32 does not do that" argument. It doesn't mean we shouldn't investigate better ways. Initially x32 got the siginfo members alignment wrong and they ended up
__ARCH_SI_CLOCK_Tand__ARCH_SI_ATTRIBUTES, changing the generic uapi files.Quoted 9 lines
Quoted 9 lines
Basically if you use the current siginfo in the ILP32 context with
__kernel_clock_tbeing 64-bit you end up with a structure that doesn't match any of the native or compat siginfo. This is because we have some pointers which will turn into 32-bit values in ILP32:void __user *sival_ptr; /* accessed via si_ptr */ void __user *_addr; /* accessed via si_addr */ void __user *_call_addr; /* accessed via si_call_addr */
Quoted 17 lines
Quoted 4 lines
Quoted 1 line
We also have
__ARCH_SI_BAND_Tdefined as long.I had first thought about this and even started to implement it but I found the glibc and the kernel messier than it was already.
The kernel part wasn't bad IMO (of course, needs ack from generic headers maintainer). I can't talk about glibc but wouldn't it just access these members explicitly?
Quoted 6 lines
Quoted 6 lines
AFAICT, Linux only does a
put_user()on these and never reads them from user space. This means that we can add the right padding on either side of these pointers (for endianness reasons) and Linux would write 0 as the top part of a 64-bit pointer (since the user address is restricted to 32-bit anyway). User ILP32 would only access the corresponding pointer as a 32-bit value and ignore the padding.
This is not true for sigevent which is defined to include "union sigval" by the POSIX standard. sigval is also included in siginfo so it needs to be using 64bit pointers here. The padding issue does come into play for some syscalls (mq_notify and timer_create). They both would need a special wrapper syscall to correctly zero fill the upper bits of that union. Would it be ok for those two system calls to have a wapper?
The rest is correct we only write to those fields and never read from them.
Thanks,
Andrew Pinski
Quoted 131 lines
Quoted 3 lines
And I am not a fan of changing the generic UAPI files just so it is no longer generic like you are doing.
As I said above, x32 did that already and your are doing similar things for
__ARCH_SI_CLOCK_T.Quoted 4 lines
Quoted 1 line
So, I'm looking for feedback on this proposal.
As I mentioned before even x32 does not do that and it is very messy to make sure things get zero'd on the glibc and kernel sides.
(not the x32 argument again)
On the kernel side, they get zeroed automatically because the kernel assumes it is a 64-bit address for user space, which is restricted to 32-bit only. Are these members ever read back by the kernel? That's where glibc zeroing would be needed (and I wouldn't like it either).
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
arch/arm64/include/uapi/asm/siginfo.h +0
-0@@ -16,7 +16,13 @@#ifndef __ASM_SIGINFO_H#define __ASM_SIGINFO_HQuoted 9 lines
arch/arm64/include/uapi/asm/siginfo.h line 25
Quoted 7 lines
arch/arm64/include/uapi/asm/siginfo.h +6
-0+#ifdef __LP64__#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#else /* ILP32 */ +typedef long long __kernel_si_clock_t __attribute__((aligned (4 ))); +#define __ARCH_SI_CLOCK_T __kernel_si_clock_t +#define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8))) +#endif This could go away if we manage to use the native siginfo.
Quoted 3 lines
See above why I think this is a bad thing and even worse since even x32 did not do that already; it was the last added ABI like ILP32 to the kernel.
The x32 thing is becoming the central theme.
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
arch/arm64/kernel/sys_ilp32.c new file +17
-0@@ -0,0 +1,274 @@ +/* +* AArch64- ILP32 specific system calls implementation +* +* Copyright (C) 2013 Cavium Inc. +* Author: Andrew Pinski <[email protected]> +* +* 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/>. Quoted 8 lines
arch/arm64/kernel/sys_ilp32.c line 21
Quoted 4 lines
arch/arm64/kernel/sys_ilp32.c new file +4
-0+*/ + +/* Adjust unistd.h to provide 32-bit numbers and functions. */ +#define __SYSCALL_COMPATNo. We need to use as many native syscalls as possible and only define those absolutely necessary. In my investigation, I only ended up needing these:
Quoted 2 lines
No using
__SYSCALL_COMPATis the correct thing to do and then only reverting back what is needed.I _disagree_. "Even x32 does not to that". Some past discussions:
http://thread.gmane.org/gmane.linux.kernel/1184913
Quoted 32 lines
Quoted 23 lines
#define sys_ioctl compat_sys_ioctl #define sys_readv compat_sys_readv #define sys_writev compat_sys_writev #define sys_preadv compat_sys_preadv64 #define sys_pwritev compat_sys_pwritev64 #define sys_vmsplice compat_sys_vmsplice #define sys_waitid compat_sys_waitid #define sys_set_robust_list compat_sys_set_robust_list #define sys_get_robust_list compat_sys_get_robust_list #define sys_kexec_load compat_sys_kexec_load #define sys_timer_create compat_sys_timer_create #define sys_ptrace compat_sys_ptrace #define sys_sigaltstack compat_sys_sigaltstack #define sys_rt_sigaction compat_sys_rt_sigaction #define sys_rt_sigpending compat_sys_rt_sigpending #define sys_rt_sigtimedwait compat_sys_rt_sigtimedwait #define sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo #define sys_rt_sigreturn compat_sys_rt_sigreturn_wrapper #define sys_mq_notify compat_sys_mq_notify #define sys_recvfrom compat_sys_recvfrom #define sys_setsockopt compat_sys_setsockopt #define sys_getsockopt compat_sys_getsockopt #define sys_sendmsg compat_sys_sendmsgQuoted 8 lines
#define sys_recvmsg compat_sys_recvmsg #define sys_execve compat_sys_execve #define sys_move_pages compat_sys_move_pages #define sys_rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo #define sys_recvmmsg compat_sys_recvmmsg #define sys_sendmmsg compat_sys_sendmmsg #define sys_process_vm_readv compat_sys_process_vm_readv #define sys_process_vm_writev compat_sys_process_vm_writevQuoted 2 lines
You even forgot
compat_sys_openat(whereO_LARGEFILEdifferences does make a difference).Just read the above thread. "Even x32 does not do that".
Quoted 10 lines
Quoted 7 lines
arch/arm64/kernel/vdsoilp32/Makefile
Quoted 5 lines
arch/arm64/kernel/vdsoilp32/Makefile new file +0
-0Could we not keep vdso in the same directory?
I started out that way but "make clean ARCH=arm64" did not clean the vdso files all the time.
I'll leave vdso comments to Will.
--
Catalin
Re: [PATCH 5/5] ARM64: Add support for ILP32 ABI.
In reply to Catalin MarinasQuoted 8 lines · Catalin Marinas
Quoted 1 line · Andrew Pinski
This patch adds full support of the ABI to the ARM64 target.
This description is too short. Please describe what the ABI is, what are the commonalities with AArch64 and AArch32, what other non-obvious things had to be done (like
__kernel_long_tbeing long long). Split this patch into multiple patches like base syscall handling, signal handling, pselect6/ppoll, vdso etc. It's too much to review at once.
I will try to do this.
Quoted 3 lines
On top of these, I would really like to see
Documentation/arm64/ilp32.txtdescribing the ABI.
Ok, I will add some documentation.
Quoted 4 lines
I would also like to know (you can state this in the cover letter) the level of testing for all 3 types of ABI. I'm worried that at least this patch breaks the current compat ABI (has LTP reported anything?).
When I submit the next version, I will cover this in my cover letter.
Quoted 18 lines
Quoted 18 lines
arch/arm64/Kconfig +1
-1@@ -248,7 +248,7 @@ source "fs/Kconfig.binfmt" config COMPAT def_bool y - depends on ARM64_AARCH32 + depends on ARM64_AARCH32 || ARM64_ILP32 select COMPAT_BINFMT_ELF config ARM64_AARCH32@@ -263,7 +263,14 @@ config ARM64_AARCH32 the user helper functions, VFP support and the ptrace interface are handled appropriately by the kernel.
Quoted 12 lines
arch/arm64/Kconfig config ARM64_AARCH32 · line 273
Quoted 9 lines
arch/arm64/Kconfig +8
-1- If you want to execute 32-bit userspace applications, say Y. + If you want to execute Aarch32 userspace applications, say Y. + +config ARM64_ILP32 + bool "Kernel support for ILP32" + help + This option enables support for AArch64 ILP32 user space. These are + 64-bit binaries using 32-bit quantities for addressing and certain + data that would normally be 64-bit.You could be even more precise by mentioning that longs and pointers are 32-bit, together with the derived types.
Will fix this as mentioned before.
Quoted 18 lines
Quoted 18 lines
arch/arm64/include/asm/compat.h +2
-0@@ -62,6 +62,8 @@ typedef u32 compat_ulong_t;typedef u64 compat_u64 ;typedef u32 compat_uptr_t ; +typedef s64 ilp32_clock_t ; +struct compat_timespec {compat_time_t tv_sec;s32 tv_nsec;@@ -180,6 +182,15 @@ typedef struct compat_siginfo {compat_clock_t _stime; } _sigchld;
Quoted 13 lines
arch/arm64/include/asm/compat.h typedef struct compat_siginfo { · line 192
Quoted 8 lines
arch/arm64/include/asm/compat.h +8
-0+/* SIGCHLD (ILP32 version) */ +struct { +compat_pid_t _pid;/* which child */ +__compat_uid32_t _uid;/* sender's uid */ +int _status;/* exit code */ +ilp32_clock_t _utime; +ilp32_clock_t _stime; + } _sigchld_ilp32;This *breaks* the
compat_siginfoalignment.ilp32_clock_tis 64-bit which forces the_sigchld_ilp32to be 64-bit which makes the preamble 16 instead of 12 bytes. Thisilp32_clock_tneeds __attribute__((aligned(4))).
Will fix this.
Quoted 4 lines
The other approach I've been looking at is just using the native siginfo instead of the compat one for ILP32. But this requires wider debate (cc'ed Arnd if he has time).
I will try to do this though it will take a week to get how much I can do with siginfo as the glibc side can be a pain to work with. The kernel is cleaner here since it is always 64bit.
Quoted 11 lines
Basically if you use the current siginfo in the ILP32 context with
__kernel_clock_tbeing 64-bit you end up with a structure that doesn't match any of the native or compat siginfo. This is because we have some pointers which will turn into 32-bit values in ILP32:void __user *sival_ptr; /* accessed via si_ptr */ void __user *_addr; /* accessed via si_addr */ void __user *_call_addr; /* accessed via si_call_addr */We also have
__ARCH_SI_BAND_Tdefined as long.
This has to stay long as POSIX defines it as a long type as mentioned in the header file. I will use an anonymous union/struct to get the correct definition for ilp32. I have to also fix the ptrace interface after I do this.
Quoted 67 lines
AFAICT, Linux only does a
put_user()on these and never reads them from user space. This means that we can add the right padding on either side of these pointers (for endianness reasons) and Linux would write 0 as the top part of a 64-bit pointer (since the user address is restricted to 32-bit anyway). User ILP32 would only access the corresponding pointer as a 32-bit value and ignore the padding.It's easier to explain with some code (untested):
arch/arm64/include/uapi/asm/siginfo.h +7
-0@@ -18,6 +18,13 @@#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#ifndef __LP64__/* ILP32 */ +#define __ARCH_SI_BAND_T long long +#define VOID_USER_PTR (x) \ + void __user *x __attribute__((aligned(8))); \ + char _pad[4] +#endif +#include <asm-generic/siginfo.h> #endif include/uapi/asm-generic/siginfo.h +7
-3@@ -4,9 +4,13 @@#include <linux/compiler.h> #include <linux/types.h> +#ifndef VOID_USER_PTR +#define VOID_USER_PTR (x) void __user *x +#endif +typedef union sigval {int sival_int; -void __user *sival_ptr; +VOID_USER_PTR (sival_ptr); }sigval_t ;/* @@ -86,7 +90,7 @@ typedef struct siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ struct { -void __user *_addr;/* faulting insn/memory ref. */ +VOID_USER_PTR (_addr);/* faulting insn/memory ref. */ #ifdef __ARCH_SI_TRAPNOint _trapno;/* TRAP # which caused the signal */ #endif @@ -101,7 +105,7 @@ typedef struct siginfo {/* SIGSYS */ struct { -void __user *_call_addr;/* calling user insn */ +VOID_USER_PTR (_call_addr);/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys;
Quoted 7 lines
__LP64__is always defined for AArch64 (kernel and native applications). ILP32 user would not get this symbol and compat use a separatecompat_siginfoanyway.I'm not entirely sure about defining
__ARCH_SI_BAND_Tto long long but as it also seems to be just written by the kernel, we can use some padding as for the void__user*.
POSIX defines it as long as mentioned above. I don't think we want ILP32 to violate POSIX here if we can not help it.
Quoted 12 lines
So, I'm looking for feedback on this proposal.
Quoted 8 lines
arch/arm64/include/asm/stat.h +0
-0@@ -18,9 +18,11 @@#include <uapi/asm/stat.h>
Quoted 8 lines
arch/arm64/include/asm/stat.h line 23
Quoted 5 lines
arch/arm64/include/asm/stat.h +2
-2-#ifdef CONFIG_ARM64_AARCH32 - +#ifdef CONFIG_COMPAT #include <asm/compat.h> +#endif Doesn't
asm/compat.hhave guards already? Do you get a conflict withis_compat_task()?
This was due to the order of the patches were applied and I did not notice the breakage until after I finished the last one. I will fix this so it is correctly done before I submit the next version of the patches.
Quoted 9 lines
Quoted 9 lines
arch/arm64/include/uapi/asm/siginfo.h +0
-0@@ -16,7 +16,13 @@#ifndef __ASM_SIGINFO_H#define __ASM_SIGINFO_H
Quoted 9 lines
arch/arm64/include/uapi/asm/siginfo.h line 25
Quoted 7 lines
arch/arm64/include/uapi/asm/siginfo.h +6
-0+#ifdef __LP64__#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int)) +#else /* ILP32 */ +typedef long long __kernel_si_clock_t __attribute__((aligned (4 ))); +#define __ARCH_SI_CLOCK_T __kernel_si_clock_t +#define __ARCH_SI_ATTRIBUTES __attribute__((aligned(8))) +#endif This could go away if we manage to use the native siginfo.
Yes I agree.
Quoted 12 lines
arch/arm64/kernel/signalilp32.c line 4
Quoted 8 lines
arch/arm64/kernel/signalilp32.c new file +4
-0@@ -0,0 +1,30 @@ + +#ifdef CONFIG_ARM64_ILP32 + +#define rt_sigframe rt_sigframe_ilp32Can we have the same native
rt_sigframe(if we go for the native siginfo)? ucontext is an arm64 structure, so we can add padding for pointers and long.
This one is a little harder at least in glibc itself. I tried a few times but I always failed due to not having that much experience with the code there but I will try one more time.
Quoted 53 lines
Quoted 15 lines
arch/arm64/kernel/sys_ilp32.c new file +11
-0@@ -0,0 +1,274 @@ +/* +* AArch64- ILP32 specific system calls implementation +* +* Copyright (C) 2013 Cavium Inc. +* Author: Andrew Pinski <[email protected]> +* +* 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, arch/arm64/kernel/sys_ilp32.c line 21
Quoted 10 lines
arch/arm64/kernel/sys_ilp32.c new file +10
-0+* 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/>. +*/ + +/* Adjust unistd.h to provide 32-bit numbers and functions. */ +#define __SYSCALL_COMPATNo. We need to use as many native syscalls as possible and only define those absolutely necessary. In my investigation, I only ended up needing these:
#define sys_ioctl compat_sys_ioctl #define sys_readv compat_sys_readv #define sys_writev compat_sys_writev #define sys_preadv compat_sys_preadv64 #define sys_pwritev compat_sys_pwritev64 #define sys_vmsplice compat_sys_vmsplice #define sys_waitid compat_sys_waitid #define sys_set_robust_list compat_sys_set_robust_list #define sys_get_robust_list compat_sys_get_robust_list #define sys_kexec_load compat_sys_kexec_load #define sys_timer_create compat_sys_timer_create #define sys_ptrace compat_sys_ptrace #define sys_sigaltstack compat_sys_sigaltstack #define sys_rt_sigaction compat_sys_rt_sigaction #define sys_rt_sigpending compat_sys_rt_sigpending #define sys_rt_sigtimedwait compat_sys_rt_sigtimedwait #define sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo #define sys_rt_sigreturn compat_sys_rt_sigreturn_wrapper #define sys_mq_notify compat_sys_mq_notify #define sys_recvfrom compat_sys_recvfrom #define sys_setsockopt compat_sys_setsockopt #define sys_getsockopt compat_sys_getsockopt #define sys_sendmsg compat_sys_sendmsg
Quoted 8 lines
#define sys_recvmsg compat_sys_recvmsg #define sys_execve compat_sys_execve #define sys_move_pages compat_sys_move_pages #define sys_rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo #define sys_recvmmsg compat_sys_recvmmsg #define sys_sendmmsg compat_sys_sendmmsg #define sys_process_vm_readv compat_sys_process_vm_readv #define sys_process_vm_writev compat_sys_process_vm_writev
Here is some additional ones I can up with after understanding this code better:\
/* Pointer in struct */
#define sys_mount compat_sys_mount
/* NUMA */
/* unsigned long bitmaps */
#define sys_get_mempolicy compat_sys_get_mempolicy #define sys_set_mempolicy compat_sys_set_mempolicy #define sys_mbind compat_sys_mbind
/* array of pointers */
/* unsigned long bitmaps */
#define sys_migrate_pages compat_sys_migrate_pages
/* Scheduler */
/* unsigned long bitmaps */
#define sys_sched_setaffinity compat_sys_sched_setaffinity
#define sys_sched_getaffinity compat_sys_sched_getaffinity
/* iov usage */
#define sys_keyctl compat_sys_keyctl
/* aio */
/* Pointer to Pointer */
#define sys_io_setup compat_sys_io_setup
/* Array of pointers */
#define sys_io_submit compat_sys_io_submit
--- CUT ----
I added a couple of comments on why the ones listed above are needed. Also I don't think ilp32 needs its own sys_ptrace rather than using the compat one.
Quoted 24 lines
arch/arm64/kernel/vdsoilp32/Makefile
Quoted 6 lines
arch/arm64/kernel/vdsoilp32/Makefile new file +0
-0Could we not keep vdso in the same directory?
arch/arm64/mm/init.c line 39
Quoted 10 lines
arch/arm64/mm/init.c +1
-0@@ -35,6 +35,7 @@#include <asm/sections.h> #include <asm/setup.h> #include <asm/sizes.h> +#include <asm/compat.h> #include <asm/tlb.h> Same issue, other header files doesn't include what is necessary.
--
Catalin
Catalin Marinas
maintainerHi Andrew,
Quoted 1 line · Andrew Pinski
Right now
CONFIG_COMPATmeans enabling AARCH32 support in the ARM64 traget, which we want to split out so we can it to mean any 32bit ABI support instead.
First, there are some coding style and patch format issues. Please pass the patches through checkpatch.pl.
Also, I would like to see a cover letter giving an overview of the ABI changes needed for arm64 ILP32 and better, longer patch description. At a first look, you would think that this simply changes CONFIG_COMPAT to CONFIG_ARM64_AARCH32 but you have other changes like compat_elf_greg_t types.
More comments below.
Quoted 22 lines
arch/arm64/include/asm/compat.h +7
-2@@ -279,28 +279,52 @@ struct compat_shmid64_ds {compat_ulong_t __unused5; }; -static inline int is_compat_task (void ) +#if defined(CONFIG_ARM64_AARCH32 ) +static inline int is_aarch32_task (void ) {return test_thread_flag (TIF_32BIT ); } -static inline int is_compat_thread (struct thread_info *thread) +static inline int is_aarch32_thread (struct thread_info *thread) {return test_ti_thread_flag (thread,TIF_32BIT ); } +#else +static inline int is_aarch32_task (void ) +{ +return 0 ;
arch/arm64/include/asm/compat.h struct compat_shmid64_ds { · line 305
Quoted 10 lines
arch/arm64/include/asm/compat.h +8
-0+} + +static inline int is_aarch32_thread (struct thread_info *thread) +{ +return 0 ; +} +#endif +#else /* !CONFIG_COMPAT */
Is the comment still correct here?
arch/arm64/include/asm/compat.h struct compat_shmid64_ds { · line 317
Quoted 13 lines
arch/arm64/include/asm/compat.h +2
-2-static inline int is_compat_task (void ) +static inline int is_aarch32_task (void ) {return 0 ; } -static inline int is_compat_thread (struct thread_info *thread) +static inline int is_aarch32_thread (struct thread_info *thread) {return 0 ; }#endif /* CONFIG_COMPAT */
Same here.
Quoted 5 lines
arch/arm64/include/asm/elf.h +0
-0
arch/arm64/include/asm/elf.h extern unsigned long arch_randomize_brk(struct mm_struct *mm); · line 160
Quoted 10 lines
arch/arm64/include/asm/elf.h +3
-2@@ -153,24 +153,33 @@ extern unsigned long arch_randomize_brk(struct mm_struct *mm);#define COMPAT_ELF_ET_DYN_BASE (randomize_et_dyn(2 * TASK_SIZE_32 / 3)) +#ifdef CONFIG_ARM64_AARCH32 /* 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 ]; +typedef unsigned int compat_a32_elf_greg_t ; +typedef compat_a32_elf_greg_t compat_a32_elf_gregset_t [COMPAT_ELF_NGREG ];
I'm not sure we need to bother placing typedefs under #ifdef. I'll have to see how this file is modified in later patches.
Quoted 16 lines
arch/arm64/include/asm/elf.h +3
-3/* AArch32 EABI. */ #define EF_ARM_EABI_MASK 0xff000000 -#define compat_elf_check_arch (x) (((x)->e_machine == EM_ARM) && \ +#define compat_elf_a32_check_arch (x) (((x)->e_machine == EM_ARM) && \ ((x)->e_flags & EF_ARM_EABI_MASK)) -#define compat_start_thread compat_start_thread -#define COMPAT_SET_PERSONALITY (ex) set_thread_flag(TIF_32BIT); +#define COMPAT_SET_A32_PERSONALITY (ex) set_thread_flag(TIF_32BIT);#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
arch/arm64/include/asm/elf.h extern unsigned long arch_randomize_brk(struct mm_struct *mm); · line 183
Quoted 10 lines
arch/arm64/include/asm/elf.h +8
-0+typedef compat_a32_elf_greg_t compat_elf_greg_t ; +typedef compat_a32_elf_gregset_t compat_elf_gregset_t ; +#endif + +#define compat_elf_check_arch (x) compat_elf_a32_check_arch(x) +#define COMPAT_SET_PERSONALITY (ex) COMPAT_SET_A32_PERSONALITY(x) +#define compat_start_thread compat_start_thread +#endif /* CONFIG_COMPAT */
Mismatched comment?
arch/arm64/include/asm/memory.h line 53
Quoted 11 lines
arch/arm64/include/asm/memory.h +1
-1@@ -49,11 +49,11 @@#ifdef CONFIG_COMPAT #define TASK_SIZE_32 UL(0x100000000) -#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ +#define TASK_SIZE (is_compat_task() ? \ TASK_SIZE_32 : TASK_SIZE_64)
Does this file also need to include compat.h?
arch/arm64/include/asm/processor.h line 42
Quoted 9 lines
arch/arm64/include/asm/processor.h +1
-1@@ -38,7 +38,7 @@#define STACK_TOP_MAX TASK_SIZE_64#ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000 -#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ +#define STACK_TOP (is_compat_task() ? \ AARCH32_VECTORS_BASE : STACK_TOP_MAX)
Same here.
arch/arm64/include/asm/ptrace.h struct pt_regs { · line 112
Quoted 10 lines
arch/arm64/include/asm/ptrace.h +1
-1@@ -107,7 +107,7 @@ struct pt_regs {#define arch_has_single_step () (1) -#ifdef CONFIG_COMPAT +#ifdef CONFIG_ARM64_AARCH32 #define compat_thumb_mode (regs) \ (((regs)->pstate & COMPAT_PSR_T_BIT))
Maybe for consistency it could be worth changing to compat_a32_thumb_mode(), if the aim is to use compat_ prefix for ILP32 as well (I'll see in the rest of the patches).
Quoted 15 lines
arch/arm64/mm/fault.c +1
-0@@ -35,6 +35,7 @@#include <asm/system_misc.h> #include <asm/pgtable.h> #include <asm/tlbflush.h> +#include <asm/compat.h> static const char *fault_name (unsigned int esr);arch/arm64/mm/mmap.c +0
-0
arch/arm64/mm/mmap.c line 31
Quoted 4 lines
arch/arm64/mm/mmap.c +1
-0@@ -28,6 +28,7 @@#include <linux/random.h> #include <asm/cputype.h> +#include <asm/compat.h>
So you added these includes because one was missing in memory.h?
Signature · 1 line
Catalin