From patchwork Fri Oct 21 20:33:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9390087 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 A236060231 for ; Fri, 21 Oct 2016 20:39:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E64329F03 for ; Fri, 21 Oct 2016 20:39:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E83E29F28; Fri, 21 Oct 2016 20:39:21 +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 DCA8029F03 for ; Fri, 21 Oct 2016 20:39:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bxgZY-00061D-50; Fri, 21 Oct 2016 20:37:48 +0000 Received: from mail-cys01nam02on0063.outbound.protection.outlook.com ([104.47.37.63] helo=NAM02-CY1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bxgXW-0003Oh-TS for linux-arm-kernel@lists.infradead.org; Fri, 21 Oct 2016 20:35:57 +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=m7Xc7oofaxyui1h4T0eat7jLhxNlA49hXwic2T68cb8=; b=LbLqFD+eP/fTIt6gQACUuVMqainqQksn54WBiOep1b50MO3tR0fBtO0ZysPzFviLXq5tWND2i5DUwz52teTGbDUwUjombDcPfJklVmvwOtvVmXYpZOwZi32OXlqvkmpjEgJ9BNGr+L90FapcckowwuCjDLTSFKAQUpmBC+m/jEs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (95.143.213.121) by CY1PR07MB2247.namprd07.prod.outlook.com (10.164.112.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.659.11; Fri, 21 Oct 2016 20:35:16 +0000 From: Yury Norov To: , , , , , Subject: [PATCH 10/18] arm64: ilp32: introduce binfmt_ilp32.c Date: Fri, 21 Oct 2016 23:33:09 +0300 Message-ID: <1477081997-4770-11-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477081997-4770-1-git-send-email-ynorov@caviumnetworks.com> References: <1477081997-4770-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: HE1PR02CA0067.eurprd02.prod.outlook.com (10.163.170.35) To CY1PR07MB2247.namprd07.prod.outlook.com (10.164.112.149) X-MS-Office365-Filtering-Correlation-Id: 76e6f6c6-88a5-480d-196f-08d3f9f1c46e X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2247; 2:6i1TB+EN5izZIJaqeLV7L3+7eK8KLKfgf29GgE4+k7zCZhTthtiwCQ1fH98LdpnjQuoi1zJXO457KT9Ya3q41tF9981cwT6lP9aBDNi+joSpwBSqc/kFTDkbHOhX+mVwrerYxBAQpGppQXMU7z1fi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mKdFGHTzY0uftdmUkqrA7ot+HbzZKEZWo1AEJRKt4HbMgLaqQ+lHFvDepxRYZbk9CB+5oWknh+LpQbzEYVIk01aLDtA0hHrQKv3CRMaG8jzCuaxbxABHc//wTFYAKnliwil4xTJqtciFPKmmYEOxCD1sR9/S1Ntxnw+jSIHmYuUi9BIrDDdqSG0Eqz+67Bsh/S1Ofyv3VWYYp3jt1N22B5eYdpquZzJwG61s8KM4DxWd3O8B5292o3wQ1FudVop5TpiR2W4likQ3QWtGBdGtSuM0jEi02KJOXokcV6hjl/+uPvL/57D63mhCy7bxp/nc+aY6Vdm0gg7pwCMIzX0I9GXl9vZYurXu8Ti61lepua71/z6laZ4oz7sIhdllHp7HEZeoYRgEXFRV4fp++4na5rXvdXnaxYmW1DYIKQlY+WkAOCA75IO8RaQ3608aJXE83Yv/H5V02pOn32Vlz04sDy0azVUFdr4Lgxz+o12U2k4G5cVFaUD/QksHt5z7Wf/f1cv4y+R2eRAj6U6Rv3m8ntk1z/fTk2CM8TAp3GBqiwf7mpt3U69eR8FXTJJ1FL3N3cFlfCGfxv4BCE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:CY1PR07MB2247; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2247; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2247; 4:aP8RIqF/YwFuVsiqzlRmA8QSXB0WT5XeVg0IozlnYB9Cm5ovHpfaOpCdC71TG5ObR5IRFFJUkJVL2KIT+94smSoJcv3gu7boIJfjWRexVrR8HWw7ySJl0Hs5bBED82+nynkcuFNWPurkVbd+QRr5iZjMc0AJy5xAaB6OFlc+ns+8XztZCV5yO97zJzjyHLkjLLGP49qSWDKH0HFjYZ6S29LzqZWIL6jAIMTjDcxCoaMeMl/+pTDdh/vRhrQcffiHiqLio/CdF05a4No3mOXMZqWrhNmrbeSN9b+uh2S90QXTEwUrzMd0r82pzclijD17eMlKw9R2I7rn1QwPVDYIdKCcf9WQraByhqyWz0n0UfLv8QjFE6leJyyLErtIdwyiS0OjSsTLq5PewhsnXkvqFA== X-Forefront-PRVS: 01026E1310 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(189002)(199003)(189998001)(76176999)(50986999)(47776003)(97736004)(5001770100001)(77096005)(33646002)(92566002)(36756003)(5660300001)(101416001)(42186005)(7416002)(66066001)(76506005)(106356001)(105586002)(229853001)(19580395003)(3846002)(48376002)(2950100002)(6666003)(5003940100001)(19580405001)(7846002)(50466002)(305945005)(4326007)(50226002)(8676002)(2201001)(2906002)(81166006)(68736007)(7736002)(6116002)(586003)(81156014)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR07MB2247; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2247; 23:wJgzlYBF1kXrGU4uQUoXD0jEKOHX6mKSykEGtxE8g?= =?us-ascii?Q?wMT8bdnab8FXrCNiVzBTvjVcz9Pf9OTwd/X2+rpFDAL3UE/y9Ac2vEspJrn2?= =?us-ascii?Q?0sqyymFb2EV9zgj7j2VJK2JKv00/O4Bua6IjDOGiKTNMmxOpkE8dFMTJcsaV?= =?us-ascii?Q?m04es+V6zrvmqtQtzOKOmBIklXs98PLzeUELCE906kX4/XRHOlTbBKsUEdmv?= =?us-ascii?Q?V4SQaIDnWDaGhGmx9fMrroqYwUsSG7NNJZWjeDH8PpORd98C5w50Xe9rjeX4?= =?us-ascii?Q?FiePL+xN6lGgDQQuZb10Ssd+6izTcQmyR5gKJFSNrty0uv9ulbv03KvZEqFV?= =?us-ascii?Q?6j3LUaOl1LTFKOjN9ILFK9NGyZiwSefLIEC3gN8Oc3uhPzFzueV7m6vZPZFK?= =?us-ascii?Q?9Ont1gbEhZ03pRU7DLqGidax59EXG+WV3KIVMIw01LnW8DOVuOV6B78I1CLj?= =?us-ascii?Q?vQ4GWlkTSTVvLH/e22j/9GK5r7AS3FGq0ObFpIToaUsRs/otcgENmKKTatMc?= =?us-ascii?Q?mrH+aT83G3nsG/jyTL9reWW/UrfLw2KdZPfGn7HrDOhk35godxp1+J9NvDkM?= =?us-ascii?Q?sTnzgu45XxYbfZPcKmwueHW6JZD+YlhcunGSK2s8FkihKqaiN1Gm48qlMxpc?= =?us-ascii?Q?tu7LkpmJDF9Pvd0GRM0HD47oPhGPy/V08h/aZipc4lgw/lC8I73wRz0itr/j?= =?us-ascii?Q?XumaHJWJoZJrsPNaoMmpUGO3jG71HWedAebEbSkRxUTUO7mDmRYIATQN25jm?= =?us-ascii?Q?ewRgE9Lik53KDOnb//4fZOYs8NqKiy/J+V0qeCQW3dCze/8YKLZiE5ME+spP?= =?us-ascii?Q?qXxnqDkVbvzoCMQSRDEaOS1e2wpfpXUwBNft+cdwHtegfEgA/7h3y/DHfeac?= =?us-ascii?Q?vXAsITbqcGnQK28EwEpi5vkFPcWabXb2FsKmgnTbiWgDBJzTOSrsWcC5yAWt?= =?us-ascii?Q?jU+voCyy8Y+TKX8GPXhGO0tNHInMIA13diP7r1yGkQBJEmPVgFaE2ejIBZEm?= =?us-ascii?Q?tiKa4mtN1hB3ZUmRNdtyn2QIw7ckz4bNW6kzkC/wrRFJPSWjSxz3lGxUyYEn?= =?us-ascii?Q?3jdROxNlfHt0RjVAosq7iCQ5ElnkeXXKwheFzwJ1G10a2FUkPF696lP2h3hx?= =?us-ascii?Q?+SawAYAngm9O6ZIWrtrgQU3P2fBbf6doL5HHeBhKqozvQ3kUH1esaGc4sLL+?= =?us-ascii?Q?M3ECZdsgrq2Oww=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2247; 6:cLS6MmJS8XZ6J9bTDT0WziQVq3tkh91lN91A7P3SGsKLdoCchf1YMRWmFW1jg/pKyExZuYAYs/I+pnHTGyFvco5sHWfDMQsP1g08SwiKSEQ8vF2neuvF+TJrQowb2DvbqE7lFNffvO9od5hMSowjeA9q3fmJX8RR7UiJGgyb0hO57mc/s7XAjL0RShTv3gR3ol/in2ItyWxmlIWfe2VCEiHq9tr7znhno7l+lJ02+g2+tDNTlzJODSpe6v9KCNBoKeHrB/PG4eosBt1ruWZ1ZTwy15hJ67PddxqkQeLoHcPlmGBvGoEmA1DdG1/mU4j/; 5:v364aVPd48BR96cX40rKT1YarOeP74PsSZ8NhA5NSp9ZIoc8Y5E3sKcCTDhV7ediBy7JbLPVxUea9xHxYguRTwXrPOueO42xdkqzlMGA4y2xbFR3krgF+mzWP8l5ldB95QoAIogjmKEv9XQ3lgnAnGe7IWjHKi4Adgn2eWv3+1Q=; 24:EFGNUMStwS/7EkhPlkuH0CN1QDRychWaFXIm8XxL0ORLuIcDLcZ2kCaCTLppwMMPN2Rf3XbYsjXFWjboSdPKKXNJS1BW+5/scqPUWPApipE=; 7:cJ9e9jfmLXcls2RAy1cuicNK90CQLxbRw3q63D3eeEaa7ZasuhFgn9udmzDOUrd1MKfSm5wLUL6Wtterdn208rNMgckp7IWQziOLc81rRKXsmGK+qnlIKkCA5Hu2VLckcFMQqMer/bzm6XyeCkC2e0VoCeujR/feIcXcmnjfJcOH+PZxLvYekrMcRerqt9Lw4JRdgp03+sgIgg6p44VbIrI6Hj440H5joV078TGfa35UXn2aze6qT1AFaCoNJGsFyay/CwemJznPYxZ2KFtx4WQ0gHLS5lXij6rfb3dTKHQeDSjGDEMAp2yciITtz3p4yvvgBVHKaycYovIN20D575Cg5AYEuhxxRTa88POWaQw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2016 20:35:16.2202 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2247 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161021_133548_935484_C15A5176 X-CRM114-Status: GOOD ( 11.56 ) 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: szabolcs.nagy@arm.com, heiko.carstens@de.ibm.com, cmetcalf@ezchip.com, ynorov@caviumnetworks.com, philipp.tomsich@theobroma-systems.com, joseph@codesourcery.com, zhouchengming1@huawei.com, Prasun.Kapoor@caviumnetworks.com, agraf@suse.de, geert@linux-m68k.org, kilobyte@angband.pl, manuel.montezelo@gmail.com, pinskia@gmail.com, linyongting@huawei.com, klimov.linux@gmail.com, broonie@kernel.org, bamvor.zhangjian@huawei.com, Bamvor Zhang Jian , maxim.kuvyrkov@linaro.org, Nathan_Lynch@mentor.com, schwidefsky@de.ibm.com, davem@davemloft.net, 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 binfmt_ilp32.c is needed to handle ILP32 binaries Signed-off-by: Yury Norov Signed-off-by: Bamvor Zhang Jian --- arch/arm64/include/asm/elf.h | 6 +++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/binfmt_ilp32.c | 97 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 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 f259fe8..be29dde 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -175,10 +175,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 abe5040..f661888 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -29,6 +29,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE arm64-obj-$(CONFIG_AARCH32_EL0) += sys32.o kuser32.o signal32.o \ sys_compat.o entry32.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..759066e --- /dev/null +++ b/arch/arm64/kernel/binfmt_ilp32.c @@ -0,0 +1,97 @@ +/* + * 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"