From patchwork Fri Jun 17 23:54:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9185223 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 C29A5601C0 for ; Fri, 17 Jun 2016 23:59:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF047208C2 for ; Fri, 17 Jun 2016 23:59:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2AEC28327; Fri, 17 Jun 2016 23:59:54 +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 3233E208C2 for ; Fri, 17 Jun 2016 23:59:54 +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 1bE3eS-00057N-Pd; Fri, 17 Jun 2016 23:58:16 +0000 Received: from mail-bn1on0090.outbound.protection.outlook.com ([157.56.110.90] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bE3c0-0001Zu-An for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2016 23:55:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=q1HNlWfxg8p1c6PN/nqAKjtZj0ocSMHsuegpMLcYahA=; b=zHzYOJYDyhstmpSNf56dlg7aINn2NKSBEn56sa6BNcM+rv50OZ1qLbT2R+5B9sLMI1S6izD+ajwLWzaxL4jgfaiRzkcPzwntQStr4bp7YmkfwGGTw2Zq870of9b0BGhTaSPFuvjNuA35dwHcNLy1NXkLNXmcqPLsQQYgimYGXKc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (50.233.148.158) by CY1PR07MB2245.namprd07.prod.outlook.com (10.164.112.147) with Microsoft SMTP Server (TLS) id 15.1.517.8; Fri, 17 Jun 2016 23:55:22 +0000 From: Yury Norov To: , , , , , , Subject: [PATCH 11/19] arm64: ilp32: introduce binfmt_ilp32.c Date: Sat, 18 Jun 2016 02:54:20 +0300 Message-ID: <1466207668-10549-12-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466207668-10549-1-git-send-email-ynorov@caviumnetworks.com> References: <1466207668-10549-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [50.233.148.158] X-ClientProxiedBy: CY1PR04CA0019.namprd04.prod.outlook.com (10.166.187.29) To CY1PR07MB2245.namprd07.prod.outlook.com (10.164.112.147) X-MS-Office365-Filtering-Correlation-Id: ab966348-e368-4e33-e6ce-08d3970ad832 X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2245; 2:8VNHOQE0wuWxuDp75SPIL5oOsS/kIcXloQRbkW1RoRJWeGuPWPYtYo9XoM9V44N0yPzyQa0UcGsA30ypeY5zagT8XkI8qnuBdFFB7PbiwXQ7KRazvSxOjg8XQcVzS+HEz7n+HbQ5Ry3c6COt0ZFIqWYVryDYPdmR+1+QoKj+v9FIRwEI+KE0S77mR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gpNCwDGLWXlMjMmJodPH0J7ZNr5bVztaTn5zRsNP2LESigWzwzW1u1xmiGAdI2Qde2+5Fxkoe6G7SFKuxR1gNiWkatupDgazW6HrAupXssBmbkiqIsmp/LWQjeFzomQnqb5EbpgvKO/VAVKYWPF39qPA6vrKVq+NVoH9GHf4oS44TZ71O2GKRKTjsRPkXmFcqgHeD+pckgM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:CY1PR07MB2245; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2245; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2245; 4:kNZn5P5fCuH1zl4xg+em1L2K7UNxWY6yxvJK/yyCvbnnqO1/CZfOahbOSs0wu1XGFLkK6R8f8MNLyqngCrGWpUDm6qzmv322DPDoX/NvreUnJHwrwpgTwWpQhYlSn/dcJDTVmguph2UpeJcvKFURzBgHurwcdF8+7sgCp++uCM5QWZWgBrOQizCMEUnff7sUzBirR0f11H3o8fFL83VmQj0d4uFCTeRqw+4po63e4MZaHYkKX+NIen4j9LzlXWw7vnvEc+RI94JB2OTmAV/5xjo3GFSttXgBBuZVWcCSqJc4ohUbaY/dT1MQiNBrDW0wVOSFz7yj5US8m8rdPyHHhQgR9tA1OqPH4YgAuBQdfVwsplVQxJTuiD3NpJL00D56 X-Forefront-PRVS: 09760A0505 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(97736004)(105586002)(5001770100001)(106356001)(47776003)(36756003)(33646002)(19580405001)(19580395003)(2906002)(7846002)(42186005)(189998001)(81156014)(8676002)(81166006)(101416001)(77096005)(4326007)(2950100001)(6116002)(3846002)(586003)(68736007)(2201001)(76176999)(50986999)(66066001)(5004730100002)(229853001)(92566002)(48376002)(76506005)(5003940100001)(50226002)(50466002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR07MB2245; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; CAT:NONE; LANG:en; CAT:NONE; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2245; 23:sgh9u0ht5nQyjqIy2B9uTGHahqanBZDJ5m5lJOG2o?= =?us-ascii?Q?tZ7SsujYKnYeWWTajCpUSSSY/mMPgW/smaz5mCeaA7oDSMmuoUDW3l8e4a+a?= =?us-ascii?Q?iUd/flP8V2nYYbIuD34KNeaOzBL2Pjzoel85UR9LORhrtrK9zlItXBYoBLhI?= =?us-ascii?Q?+bNUXCOVuk8ZF/dDFsAprsbixnKVYaNG07o4hoIpF0yE6MJ58sRB/QJcAff+?= =?us-ascii?Q?45YP9iPnoHg7nYImksjW1mbfjq1zNXys94QDcXoqSABqHaWqJrTtSJFksW+c?= =?us-ascii?Q?MPOPoZU3bZ1ErkiLb5ybHQQO8d1f+NY93TiPJZG+jIY8/tbDru+1rZX4PBqa?= =?us-ascii?Q?jggzgXCsAN0lCMESe/567H9OjnfDZym/QH4lh7kHh/g/iw7h/L/V4MByBzK9?= =?us-ascii?Q?Pl1X9puIEOl1fTdUJqKOkzw6lXJ80YQQzXxOOOIHFfClIRyxsRvshfIqebpI?= =?us-ascii?Q?7I3sbsbsQfwe642TuelCT4gMQZeqE3z+LTbAg5SdQCLxe+A2DozPMHmcDmWR?= =?us-ascii?Q?6EJNh7hud2BpDA7A3Ajs4c4A9UIdCGgUCf/ZIN7Q2t4IIew+96QZL2cqsSmF?= =?us-ascii?Q?G7Qe2d9qOxDTkT3GwbhSI5pDXLTet84rvVWxFT+OJ/baPsS2XZtY2u276QjK?= =?us-ascii?Q?0eMG465ONco4BkOyT0PjUh0bSJI2dqazot5ygRZ933qvDI3GcpiZn5NIE6fN?= =?us-ascii?Q?iCZsfgeZjnlHOj2Q8iwP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vGnMWAkQX94=; 7:DXaagQFlyIKLxiHhrxnJr9IG2G7Ym7w0LDu+Yh6srq/aoiI7KMVi9VXscIhjSaVI9Z44rqCeYB7ufvuP29Chz7LWOtQtva1OGgWX3aygIc05/vYMgeItYOk9lOPluZli1A/3y5Gc0wSA7jcN0UYdro0VYLPAoyTn4DZ+r1jo9yeT7am7VP5bONXbWwYyq2LzyUg4kTjBEZzOoHCSmoIZjA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2016 23:55:22.0562 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2245 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160617_165545_006210_2B995D94 X-CRM114-Status: GOOD ( 10.87 ) 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, manuel.montezelo@gmail.com, 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, broonie@kernel.org, ynorov@caviumnetworks.com, maxim.kuvyrkov@linaro.org, schwidefsky@de.ibm.com, bamvor.zhangjian@huawei.com, philipp.tomsich@theobroma-systems.com, linyongting@huawei.com, davem@davemloft.net, 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 to handle ILP32 binaries Signed-off-by: Yury Norov --- arch/arm64/include/asm/elf.h | 6 +++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/binfmt_ilp32.c | 96 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 arch/arm64/kernel/binfmt_ilp32.c diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index a967726..4dcbcec 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -174,10 +174,16 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3) +#ifndef USE_AARCH64_GREG /* 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]; +#else /* AArch64 registers for AARCH64/ILP32 */ +#define COMPAT_ELF_NGREG ELF_NGREG +#define compat_elf_greg_t elf_greg_t +#define compat_elf_gregset_t elf_gregset_t +#endif /* AArch32 EABI. */ #define EF_ARM_EABI_MASK 0xff000000 diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 60d59cb..bcdd4b2 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -28,6 +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_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/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c new file mode 100644 index 0000000..416b3f5 --- /dev/null +++ b/arch/arm64/kernel/binfmt_ilp32.c @@ -0,0 +1,96 @@ +/* + * Support for ILP32 Linux/aarch64 ELF binaries. + */ +#define USE_AARCH64_GREG + +#include +#include + +#undef ELF_CLASS +#define ELF_CLASS ELFCLASS32 + +#undef elfhdr +#undef elf_phdr +#undef elf_shdr +#undef elf_note +#undef elf_addr_t +#define elfhdr elf32_hdr +#define elf_phdr elf32_phdr +#define elf_shdr elf32_shdr +#define elf_note elf32_note +#define elf_addr_t Elf32_Addr + +/* + * Some data types as stored in coredump. + */ +#define user_long_t compat_long_t +#define user_siginfo_t compat_siginfo_t +#define copy_siginfo_to_user copy_siginfo_to_user32 + +/* + * The machine-dependent core note format types are defined in elfcore-compat.h, + * which requires asm/elf.h to define compat_elf_gregset_t et al. + */ +#define elf_prstatus compat_elf_prstatus +#define elf_prpsinfo compat_elf_prpsinfo + +/* + * Compat version of cputime_to_compat_timeval, perhaps this + * should be an inline in . + */ +static void cputime_to_compat_timeval(const cputime_t cputime, + struct compat_timeval *value) +{ + struct timeval tv; + cputime_to_timeval(cputime, &tv); + value->tv_sec = tv.tv_sec; + value->tv_usec = tv.tv_usec; +} + +#undef cputime_to_timeval +#define cputime_to_timeval cputime_to_compat_timeval + +/* AARCH64 ILP32 EABI. */ +#undef elf_check_arch +#define elf_check_arch(x) (((x)->e_machine == EM_AARCH64) \ + && (x)->e_ident[EI_CLASS] == ELFCLASS32) + +#undef SET_PERSONALITY +#define SET_PERSONALITY(ex) \ +do { \ + set_thread_flag(TIF_32BIT_AARCH64); \ + clear_thread_flag(TIF_32BIT); \ +} while (0) + +#undef ARCH_DLINFO +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)(long)current->mm->context.vdso); \ +} while (0) + +#undef ELF_PLATFORM +#ifdef __AARCH64EB__ +#define ELF_PLATFORM ("aarch64_be:ilp32") +#else +#define ELF_PLATFORM ("aarch64:ilp32") +#endif + +#undef ELF_ET_DYN_BASE +#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE + +#undef ELF_HWCAP +#undef ELF_HWCAP2 +#define ELF_HWCAP ((u32) elf_hwcap) +#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32)) + +/* + * Rename a few of the symbols that binfmt_elf.c will define. + * These are all local so the names don't really matter, but it + * might make some debugging less confusing not to duplicate them. + */ +#define elf_format compat_elf_format +#define init_elf_binfmt init_compat_elf_binfmt +#define exit_elf_binfmt exit_compat_elf_binfmt + +#include "../../../fs/binfmt_elf.c"