From patchwork Wed Sep 3 21:19:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 36655 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f199.google.com (mail-pd0-f199.google.com [209.85.192.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 28912202E4 for ; Wed, 3 Sep 2014 21:23:23 +0000 (UTC) Received: by mail-pd0-f199.google.com with SMTP id ft15sf9620578pdb.6 for ; Wed, 03 Sep 2014 14:23:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=Ip8C2yarFJzrhvKEBZUhGApicN865qOLJV6ecIN1ZrY=; b=MdfC8sA/kwPh0E0++MCc+8q93g2jXnu+wY6DIsa31HbIO1iNnN8/40MftHQmooGtPS mFjq8hklMrHs+/vqB7RS8+70u+WlOcguro6djmEaxQ2MH7hbcuwiQPjZXL6K6lBuDacF dGWwgAKPgM2MngmBZLm4RfBkvDYzSmDq5llAO7FvtgA0cblwA0ibRhhx2QzBzrzyXjlU Z1j5/xhVvzw5EoJQoSeXXPyNXYqBNBQDe5IY3GHryP9h1YmnsBH+U8HG1m4QyBNMjVrU X65Cx62UGohzoEEricdoqBa5IzEKJDhlf4ilPZYYX/Vs2Cwpf4rQ4oZ7UEPKt3QkfTNb xUjw== X-Gm-Message-State: ALoCoQngbzoBM71yjh0f9wG1MTovtY/PcfonmZk139I1iuyRoBlRgsyxI1SPSquT+J7JDtFjDou8 X-Received: by 10.66.65.75 with SMTP id v11mr54549pas.30.1409779401695; Wed, 03 Sep 2014 14:23:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.211 with SMTP id z77ls10748qgz.54.gmail; Wed, 03 Sep 2014 14:23:21 -0700 (PDT) X-Received: by 10.52.32.66 with SMTP id g2mr120296vdi.49.1409779401585; Wed, 03 Sep 2014 14:23:21 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id sl18si1712689vdb.42.2014.09.03.14.23.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 14:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id ij19so9596961vcb.31 for ; Wed, 03 Sep 2014 14:23:21 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr83505vdz.24.1409779401357; Wed, 03 Sep 2014 14:23:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp740408vcb; Wed, 3 Sep 2014 14:23:20 -0700 (PDT) X-Received: by 10.66.174.72 with SMTP id bq8mr212796pac.88.1409779400336; Wed, 03 Sep 2014 14:23:20 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id oh8si13275113pbc.156.2014.09.03.14.23.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Sep 2014 14:23:20 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPHzi-00057C-4Y; Wed, 03 Sep 2014 21:21:34 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPHy8-0002gb-0O for linux-arm-kernel@bombadil.infradead.org; Wed, 03 Sep 2014 21:19:56 +0000 Received: from mail-ig0-f178.google.com ([209.85.213.178]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XPHy5-0004kk-3h for linux-arm-kernel@lists.infradead.org; Wed, 03 Sep 2014 21:19:55 +0000 Received: by mail-ig0-f178.google.com with SMTP id hn18so9887693igb.17 for ; Wed, 03 Sep 2014 14:19:29 -0700 (PDT) X-Received: by 10.50.234.193 with SMTP id ug1mr200876igc.20.1409779169754; Wed, 03 Sep 2014 14:19:29 -0700 (PDT) Received: from localhost.localdomain (64.2.3.195.ptr.us.xo.net. [64.2.3.195]) by mx.google.com with ESMTPSA id e1sm6493390igx.18.2014.09.03.14.19.26 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 14:19:28 -0700 (PDT) Received: from localhost.localdomain (apinskidesktop [127.0.0.1]) by localhost.localdomain (8.14.3/8.14.3/Debian-9.4) with ESMTP id s83LJPSh031095 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Wed, 3 Sep 2014 14:19:26 -0700 Received: (from apinski@localhost) by localhost.localdomain (8.14.3/8.14.3/Submit) id s83LJPlQ031094; Wed, 3 Sep 2014 14:19:25 -0700 From: Andrew Pinski To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, pinskia@gmail.com Subject: [PATCH 21/24] ARM64:ILP32: Use a seperate syscall table as a few syscalls need to be using the compat syscalls Date: Wed, 3 Sep 2014 14:19:15 -0700 Message-Id: <1409779158-30963-22-git-send-email-apinski@cavium.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1409779158-30963-1-git-send-email-apinski@cavium.com> References: <1409779158-30963-1-git-send-email-apinski@cavium.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140903_171953_295106_1260C350 X-CRM114-Status: GOOD ( 27.84 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.213.178 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Andrew Pinski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: apinski@cavium.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Some syscalls are still need to use the compat versions. So we need to have a seperate syscall table for ILP32. This patch adds them including documentation on why we need to use each one. This list is based on the list from https://lkml.org/lkml/2013/9/11/478. Signed-off-by: Andrew Pinski --- arch/arm64/include/asm/syscalls.h | 4 + arch/arm64/include/asm/unistd.h | 4 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/entry.S | 13 +++- arch/arm64/kernel/sys_ilp32.c | 195 +++++++++++++++++++++++++++++++++++++ 5 files changed, 216 insertions(+), 1 deletions(-) create mode 100644 arch/arm64/kernel/sys_ilp32.c diff --git a/arch/arm64/include/asm/syscalls.h b/arch/arm64/include/asm/syscalls.h index 48fe7c6..b58dad7 100644 --- a/arch/arm64/include/asm/syscalls.h +++ b/arch/arm64/include/asm/syscalls.h @@ -25,6 +25,10 @@ */ asmlinkage long sys_rt_sigreturn_wrapper(void); +#ifdef CONFIG_ARM64_ILP32 +long ilp32_sys_sigaltstack(const stack_t __user *, stack_t __user *); +#endif + #include #endif /* __ASM_SYSCALLS_H */ diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index 70e5559..c99815a 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -13,6 +13,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#ifdef CONFIG_ARM64_ILP32 +#define __ARCH_WANT_COMPAT_SYS_PREADV64 +#define __ARCH_WANT_COMPAT_SYS_PWRITEV64 +#endif #ifdef CONFIG_AARCH32_EL0 #define __ARCH_WANT_COMPAT_SYS_GETDENTS64 #define __ARCH_WANT_COMPAT_STAT64 diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index dcb9033..8a531fb 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -19,6 +19,7 @@ arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \ arm64-obj-$(CONFIG_AARCH32_EL0) += sys32.o kuser32.o signal32.o \ sys_compat.o +arm64-obj-$(CONFIG_ARM64_ILP32) += sys_ilp32.o arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o topology.o diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 9314352..dbedecf 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -643,9 +643,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, 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 enable_dbg_and_irq @@ -664,6 +669,12 @@ ni_sys: b do_ni_syscall ENDPROC(el0_svc) +#ifdef CONFIG_ARM64_ILP32 +el0_ilp32_svc: + adrp stbl, sys_call_ilp32_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. diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c new file mode 100644 index 0000000..8c68d28 --- /dev/null +++ b/arch/arm64/kernel/sys_ilp32.c @@ -0,0 +1,195 @@ +/* + * AArch64- ILP32 specific system calls implementation + * + * Copyright (C) 2013 Cavium Inc. + * Author: Andrew Pinski + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Wrappers to pass the pt_regs argument. + */ +#define sys_rt_sigreturn sys_rt_sigreturn_wrapper + +/* + * Note places where mention unsigned long bitmaps, could + * use the non compat version for little-endian but big-endian + * has issues to do layout of the bits in the bitmaps. + */ + +/* Using Compat syscalls where necessary */ +#define sys_ioctl compat_sys_ioctl +/* iovec */ +#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 +/* robust_list_head */ +#define sys_set_robust_list compat_sys_set_robust_list +#define sys_get_robust_list compat_sys_get_robust_list + +/* kexec_segment */ +#define sys_kexec_load compat_sys_kexec_load + +/* Ptrace has some structures which are different between ILP32 and LP64 */ +#define sys_ptrace compat_sys_ptrace + +/* struct msghdr */ +#define sys_recvfrom compat_sys_recvfrom +#define sys_recvmmsg compat_sys_recvmmsg +#define sys_sendmmsg compat_sys_sendmmsg +#define sys_sendmsg compat_sys_sendmsg +#define sys_recvmsg compat_sys_recvmsg + +/* + * Note the timeval is taken care by COMPAT_USE_64BIT_TIME + * being true. + */ +#define sys_setsockopt compat_sys_setsockopt +#define sys_getsockopt compat_sys_getsockopt + +/* Array of pointers */ +#define sys_execve compat_sys_execve +#define sys_move_pages compat_sys_move_pages + +/* iovec */ +#define sys_process_vm_readv compat_sys_process_vm_readv +#define sys_process_vm_writev compat_sys_process_vm_writev + +/* + * The NFSv4 and ncpfs structures are depend on the long and + * pointer sizes. + */ +#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 */ +/* Array of pointers (iocb's) */ +#define sys_io_submit compat_sys_io_submit + +/* We need to make sure the pointer gets copied correctly. */ +asmlinkage long ilp32_sys_mq_notify(mqd_t mqdes, + const struct sigevent __user *u_notification) +{ + struct sigevent __user *p = NULL; + + if (u_notification) { + struct sigevent n; + + p = compat_alloc_user_space(sizeof(*p)); + if (copy_from_user(&n, u_notification, sizeof(*p))) + return -EFAULT; + if (n.sigev_notify == SIGEV_THREAD) + n.sigev_value.sival_ptr = compat_ptr((uintptr_t)n.sigev_value.sival_ptr); + if (copy_to_user(p, &n, sizeof(*p))) + return -EFAULT; + } + return sys_mq_notify(mqdes, p); +} + +/* + * sigevent contains sigval_t which is now 64bit always + * but need special handling due to padding for SIGEV_THREAD. + */ +#define sys_mq_notify ilp32_sys_mq_notify + + +/* + * sigaltstack needs some special handling as the + * padding for stack_t might not be non-zero. + */ +long ilp32_sys_sigaltstack(const stack_t __user *uss_ptr, + stack_t __user *uoss_ptr) +{ + stack_t uss, uoss; + int ret; + mm_segment_t seg; + + if (uss_ptr) { + if (!access_ok(VERIFY_READ, uss_ptr, sizeof(*uss_ptr))) + return -EFAULT; + if (__get_user(uss.ss_sp, &uss_ptr->ss_sp) | + __get_user(uss.ss_flags, &uss_ptr->ss_flags) | + __get_user(uss.ss_size, &uss_ptr->ss_size)) + return -EFAULT; + /* Zero extend the sp address and the size. */ + uss.ss_sp = (void *)(uintptr_t)(unsigned int)(uintptr_t)uss.ss_sp; + uss.ss_size = (size_t)(unsigned int)uss.ss_size; + } + seg = get_fs(); + set_fs(KERNEL_DS); + /* + * Note we need to use uoss as we have changed the segment to the + * kernel one so passing an user one around is wrong. + */ + ret = sys_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL), + (stack_t __force __user *) &uoss); + set_fs(seg); + if (ret >= 0 && uoss_ptr) { + if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_t)) || + __put_user(uoss.ss_sp, &uoss_ptr->ss_sp) || + __put_user(uoss.ss_flags, &uoss_ptr->ss_flags) || + __put_user(uoss.ss_size, &uoss_ptr->ss_size)) + ret = -EFAULT; + } + return ret; +} + +/* + * sigaltstack needs some special handling as the padding + * for stack_t might not be non-zero. + */ +#define sys_sigaltstack ilp32_sys_sigaltstack + +#include + +#undef __SYSCALL +#define __SYSCALL(nr, sym) [nr] = sym, + +/* + * The sys_call_ilp32_table array must be 4K aligned to be accessible from + * kernel/entry.S. + */ +void *sys_call_ilp32_table[__NR_syscalls] __aligned(4096) = { + [0 ... __NR_syscalls - 1] = sys_ni_syscall, +#include +};