From patchwork Tue May 24 00:04:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9132571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8EF9B607D3 for ; Tue, 24 May 2016 00:14:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 805C728237 for ; Tue, 24 May 2016 00:14:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7220F28252; Tue, 24 May 2016 00:14:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C34BB28237 for ; Tue, 24 May 2016 00:14:17 +0000 (UTC) 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 1b4zy6-0006A1-4w; Tue, 24 May 2016 00:13:06 +0000 Received: from mail-bl2on0095.outbound.protection.outlook.com ([65.55.169.95] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b4zrq-0005hC-Uq for linux-arm-kernel@lists.infradead.org; Tue, 24 May 2016 00:06:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rnLOqzIiRzF6flfnqSDOD8zYxsLs2fuCuV0lq8xiO/Q=; b=dPA2F0q+av+oKN7nxfBHcqucHkPUGjbIegjWcJy+Ij+86jYRsVucSoIzATOmJuWtnTAQjGuztx7LYBV7DE6vOwHo6zD5OnMZgzj5BTcxJaTeYHOklxJoZKldaKOyn2vDWJvz0ZrktS7eeeaqkaPegITHQnBc5by+wMTHxJsoDEQ= Authentication-Results: arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost (50.233.148.158) by CY1PR07MB2230.namprd07.prod.outlook.com (10.164.112.144) with Microsoft SMTP Server (TLS) id 15.1.497.12; Tue, 24 May 2016 00:06:12 +0000 From: Yury Norov To: , , , , , , , Subject: [PATCH 18/23] arm64: ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it Date: Tue, 24 May 2016 03:04:47 +0300 Message-ID: <1464048292-30136-19-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1464048292-30136-1-git-send-email-ynorov@caviumnetworks.com> References: <1464048292-30136-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.158] X-ClientProxiedBy: CY1PR1201CA0040.namprd12.prod.outlook.com (10.169.17.178) To CY1PR07MB2230.namprd07.prod.outlook.com (10.164.112.144) X-MS-Office365-Filtering-Correlation-Id: 6f5fc97b-9791-41af-a676-08d3836737ca X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2230; 2:ZgAuIQLVyBVcwYrc/V9aKtHJq7Dk6GyXeC4+a0kIy7J2CeVxXR7yqi+2RRtjEkhc6AdhFB3EcFVxWW2miAPqyPbvgYPVGiN1ElPnNj0jug0vn54MU5QpUbm2hNQE72WBDAFRGCvdiQXwLddlRbRBYFcTowVjz6h56IVH479Nn0ZeYi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xijhmWTES3+GBP6JJhk5+OeB3xgj6YMru3MDg== X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2230; 20:U6jZM0XUpC3QKCjBSGzd7Vz8oJ0rS5FrFObwOssem5WdLDGxp/8c0wNdp8Xj8kVchwWi0XtWYGDwO/+kvwZAM4mdSkHe69vtvlVW7NiJUqB6JuaGSk/0Xdt6HivaPDn1HAYiRsk19nm880/FcECqiV/uoiKlyouuZ3u1UEMGA9P4EAc55qtguYYbea0x57hWDFkkzvUG4JOt2dHZsR0MPIWtYA+Vdf2/657i3V850WnE3tTGT+y08fOuWFS1mvvZ5GKIgzbVn9O2tf6bdgl7gKFcSEySCsXRUXZcaJ7Lr3VAoprk9jpK40Dl0EsFENgGT6eRUFx6nZmUSY74h+9VK0BZ20xP46SFsxdvXr1YX+Vr2kxzCnFQSF7dG2V2sVrc7MNnlWUS+r5Usa3qOqBP+MyAit7PzxWdQEZ0uUBZbI6VjyG2k+NtIx7HYtJf8gYgElQPTN+eKesLokOtBno+8I9vRX+BrHTrvbqYwAGXMd3wVoJJ12qq1NalepjKT6xkYg3D7aOQvfZwRQTjrtgmGFvSyJB/MSfR3EjCeQoShRB4MqG+m9MnrUrn2QM5fEn3sfZH8QNvSfl0RnVuBpcKs/kxaFTGXkT9cNRQWF5rq7E= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:CY1PR07MB2230; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2230; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2230; 4:Bnj8Oe2fq8DZOcbLhg4e0kXnjDCjjKayDVxvg2T231Pra8KJ+2BotAC0C5DvSFAn76VznGCMYpoQ7Z+q98BqUnxxYkAkNJSVN1djGSAFdKWtI3Rnt5ix0E2kp8TWTLm9j9G0Gc1Lq6YTO0euHYktnVLZeEakhdThv859DK+DGNKrYNSi1P3/4FQGWcvHTQdJXis+uVJjIpV+8X7yDBk/W75jtNgXRfHLNf9p/webKcGdl4DrYyCz/aDaBhZ+gt/LbS354MS9qNLIhYRibkjeQO+gM/MtgfAiIlCT6jucSAd2Q3jRW/cjHQHlaZL29f4Rna+vdcN7X7xO1+/oIKTO+fIgOc2tfKi7TQ+4Ecg/Zabw/XW8+3IMNyttjdVkQPmI X-Forefront-PRVS: 09525C61DB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(19580395003)(36756003)(5004730100002)(19580405001)(5008740100001)(2906002)(229853001)(2201001)(4001430100002)(586003)(47776003)(33646002)(4326007)(66066001)(6116002)(76506005)(42186005)(92566002)(15975445007)(77096005)(2950100001)(189998001)(107886002)(5001770100001)(81166006)(5003940100001)(76176999)(50986999)(50226002)(50466002)(48376002)(8676002)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR07MB2230; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2230; 23:PJT52wUP5dwVRht3/38GWHZaNE8VDwMJNYk7oTqJW?= =?us-ascii?Q?o2MV/97m/rHon691dq/0rhF9/lv7MegDC3tcdkVF+rNEQ8ixFR/PtghCdFF+?= =?us-ascii?Q?IkJP5Tb010T3f/FLyizPRK9s52vRB1gAGYebIPxGEhqR/+d0Z6KNAwxim3DG?= =?us-ascii?Q?V/l4UcBMuWDxdSQUEJxAov1RRc1b1NI8fNXniMoa1mxQYfUGCilzMuDLS2EM?= =?us-ascii?Q?A/QxB1UhoyiFUceMrYK02N4ooXw7Itn4nv8nSykw1Z4vSpJfQoAj7D96MCXg?= =?us-ascii?Q?mS+aZtucGrpgs+wAXZ/av/XRCD6aD/dkA3QcIoqOAqoD0sFJhWCLWXsTjrrf?= =?us-ascii?Q?WCw7Ys1YVcQNxTtD57hoRVYlyJ6JXlAh4cG50t0tKTQuXrj0qF9DjOoiDELF?= =?us-ascii?Q?JYgnUpvi8Zg52bAENQ4djsBxxeMGrT6UqbPkmx4OdUp7tcbziq3nLCkH+sZn?= =?us-ascii?Q?i5eAhmen5ypjctiRWuOKr/mwoTig+RnE3ayEfeCrxydGwqypvuMqMlseUwUw?= =?us-ascii?Q?h6uteZgikoQxv8iH+zCnkBA1CGfI0D2HJKejzhh8GPtVc+4tIolHjkBt71lF?= =?us-ascii?Q?J8ZsHKJ/u2ckEpg5568L78Xj8ONuccu6EHoBVjphliAG5PqscEHDCnY1T/N6?= =?us-ascii?Q?egmYulXFpmqLIle50ldOn9DTrZOXwv8d1mNz/x1FFIY6b0CHudv7qlDPn8ln?= =?us-ascii?Q?p1xs6W/MMpFUBBJhGjJGB9hAGXl0wSko448Snzt/dE5XAxnCUv+C7RiusYoD?= =?us-ascii?Q?mJz3aBgQOHHwKH85jb6cbtLYTZjpuEbmnJyGI9b2BMe1kcQcQMVoe9jqejf+?= =?us-ascii?Q?+TTbEYBR6uL+jdAHDutDOgo4jSRlFwyiAcAPswgmzJMl7bl0/gZeSNVkcVNb?= =?us-ascii?Q?EG7+PkGQ/IslmZunv86KKjTA17hCoa363ZjY/2izfMsbPetx2aNZ1VmYJkBR?= =?us-ascii?Q?yM3vWnEUHBj6IwBjPj5NRGn6kexcIIfBaCIwhTiiUgkk1RF/fdk4WdRlVmnJ?= =?us-ascii?Q?dc=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2230; 5:7l3sAugYDBDklRA724ITshooNLPutV5HAuyV1s8ybGGZHhbor5iQJBEWDjaL/JwMkNRpI2LyyM9gQ/z0b39ynKgkHAw/cyli8L39J3oTpMnXequtNBwevRZHtXHsd4Zsy29F7NtersG36R3slqFfow==; 24:qCUfy4Z0NwkhFuM1YxYIwL0WixJCvXzSUw/cVk4XuwKM4oFLyUBgzznaii5VVo6KbvOkpzJYzFW+jcy1ExqU5jlHcwy0VHs3CAg5rhKLdqo=; 7:eUpJb+TRSVxVcJomjX98sT4yPMR9+XZ3nSo39xQTNuosKLh+Svt078vZlJBIlVrkIC3SLLn/bEG4qL4MAos+KcfUo5R9eFca/0SQBis6p1TOc52bp8+b4HMvs2FvJBMAwi04r8XM5/fh1mR1O7eDbo1irSGUIwS0Fg9r8a6kYM+rmw6EafC+o+roB7+1rtB5 SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2016 00:06:12.8707 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2230 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160523_170639_752907_A4DD5D21 X-CRM114-Status: GOOD ( 14.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kilobyte@angband.pl, pinskia@gmail.com, szabolcs.nagy@arm.com, Nathan_Lynch@mentor.com, heiko.carstens@de.ibm.com, agraf@suse.de, geert@linux-m68k.org, Prasun.Kapoor@caviumnetworks.com, klimov.linux@gmail.com, Andrew Pinski , broonie@kernel.org, ynorov@caviumnetworks.com, Andrew Pinski , schwidefsky@de.ibm.com, bamvor.zhangjian@huawei.com, philipp.tomsich@theobroma-systems.com, joseph@codesourcery.com, christoph.muellner@theobroma-systems.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Pinski Add a separate syscall-table for ILP32, which dispatches either to native LP64 system call implementation or to compat-syscalls, as appropriate. Signed-off-by: Andrew Pinski Signed-off-by: Yury Norov --- arch/arm64/include/asm/unistd.h | 11 +++++- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/entry.S | 10 ++++- arch/arm64/kernel/sys_ilp32.c | 83 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 arch/arm64/kernel/sys_ilp32.c diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h index 2971dea..5ea18ef 100644 --- a/arch/arm64/include/asm/unistd.h +++ b/arch/arm64/include/asm/unistd.h @@ -13,9 +13,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#ifdef CONFIG_COMPAT +#define __ARCH_WANT_COMPAT_STAT64 +#endif + +#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 #define __ARCH_WANT_SYS_GETHOSTNAME #define __ARCH_WANT_SYS_PAUSE #define __ARCH_WANT_SYS_GETPGRP diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 9dfdf86..7aa65ea 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE arm64-obj-$(CONFIG_AARCH32_EL0) += sys32.o kuser32.o signal32.o \ sys_compat.o entry32.o \ ../../arm/kernel/opcodes.o binfmt_elf32.o -arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o +arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o sys_ilp32.o arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 21a0624..acea2cb 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -501,6 +501,7 @@ el0_svc_compat: * AArch32 syscall handling */ adrp stbl, compat_sys_call_table // load compat syscall table pointer + ldr x16, [tsk, #TI_FLAGS] uxtw scno, w7 // syscall number in w7 (r7) mov sc_nr, #__NR_compat_syscalls b el0_svc_naked @@ -717,15 +718,20 @@ ENDPROC(ret_from_fork) .align 6 el0_svc: adrp stbl, sys_call_table // load syscall table pointer + ldr x16, [tsk, #TI_FLAGS] uxtw scno, w8 // syscall number in w8 mov sc_nr, #__NR_syscalls +#ifdef CONFIG_ARM64_ILP32 + adrp x17, sys_call_ilp32_table // load ilp32 syscall table pointer + tst x16, #_TIF_32BIT_AARCH64 + csel stbl, stbl, x17, eq // We are using ILP32 +#endif el0_svc_naked: // compat entry point stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number enable_dbg_and_irq ct_user_exit 1 - ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks - tst x16, #_TIF_SYSCALL_WORK + tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks b.ne __sys_trace cmp scno, sc_nr // check upper syscall limit b.hs ni_sys diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c new file mode 100644 index 0000000..d4cd2a9 --- /dev/null +++ b/arch/arm64/kernel/sys_ilp32.c @@ -0,0 +1,83 @@ +/* + * AArch64- ILP32 specific system calls implementation + * + * Copyright (C) 2016 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 . + */ + +#define __SYSCALL_COMPAT + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Using non-compat syscalls where necessary */ +#define compat_sys_fadvise64_64 sys_fadvise64_64 +#define compat_sys_fallocate sys_fallocate +#define compat_sys_ftruncate64 sys_ftruncate +#define compat_sys_lookup_dcookie sys_lookup_dcookie +#define compat_sys_readahead sys_readahead +#define compat_sys_shmat sys_shmat +#define compat_sys_sync_file_range sys_sync_file_range +#define compat_sys_truncate64 sys_truncate +#define sys_llseek sys_lseek +#define sys_mmap2 compat_sys_mmap2 + +static unsigned long compat_sys_mmap2(compat_uptr_t addr, compat_size_t len, + int prot, int flags, int fd, off_t pgoff) +{ + if (pgoff & (~PAGE_MASK >> 12)) + return -EINVAL; + + return sys_mmap_pgoff(addr, len, prot, flags, fd, + pgoff >> (PAGE_SHIFT - 12)); +} + +static unsigned long compat_sys_pread64(unsigned int fd, + compat_uptr_t __user *ubuf, compat_size_t count, off_t offset) +{ + return sys_pread64(fd, (char *) ubuf, count, offset); +} + +static unsigned long compat_sys_pwrite64(unsigned int fd, + compat_uptr_t __user *ubuf, compat_size_t count, off_t offset) +{ + return sys_pwrite64(fd, (char *) ubuf, count, offset); +} + +#include + +#undef __SYSCALL +#undef __SC_WRAP + +#define __SYSCALL(nr, sym) [nr] = sym, +#define __SC_WRAP(nr, sym) [nr] = compat_##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 +};