From patchwork Tue Dec 15 21:42:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 7857631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C8B1BBEEE1 for ; Tue, 15 Dec 2015 21:52:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AC1DD203C2 for ; Tue, 15 Dec 2015 21:52:04 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 872552037F for ; Tue, 15 Dec 2015 21:52:03 +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 1a8xUB-0008UW-0F; Tue, 15 Dec 2015 21:50:19 +0000 Received: from mail-bn1bon0084.outbound.protection.outlook.com ([157.56.111.84] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a8xSs-0006Y0-Ir for linux-arm-kernel@lists.infradead.org; Tue, 15 Dec 2015 21:49:04 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (95.143.213.121) by DM2PR07MB623.namprd07.prod.outlook.com (10.141.177.148) with Microsoft SMTP Server (TLS) id 15.1.337.19; Tue, 15 Dec 2015 21:48:35 +0000 From: Yury Norov To: , , , Subject: [PATCH v6 11/20] arm64:ilp32: support core dump generation for ILP32 Date: Wed, 16 Dec 2015 00:42:37 +0300 Message-ID: <1450215766-14765-12-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1450215766-14765-1-git-send-email-ynorov@caviumnetworks.com> References: <1450215766-14765-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM3PR01CA050.eurprd01.prod.exchangelabs.com (10.141.191.40) To DM2PR07MB623.namprd07.prod.outlook.com (10.141.177.148) X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB623; 2:R87u4UH/XDnI/sNh188itKeaxYx7tOoAurSEBt8Sbg9ldjG3+lE6ITjEtehwPRs5uPcSAvbP/vF4OjIFAbrnNoHTz62XQtPRdp1GOrsliHLuto5H4s011G2geY+B98IXn+45GgogEP2P7EGJl/6I/Q==; 3:Gfk5KHaYVDIOT/39q2cdjRkHJEEzXXqDDZ78eNpj0D6dDQ5XBuYIwcRUat0SIF83ifwZa72TUFK1sauZ67R12q8Ym+7S7UZqAMtRMMeAvVZTkhoGe7t7HYhpnZelSyF0; 25:hfUs44lDZZ+1esQbDCrGwZ3EVkXQ3Pb9qhZDlFmUSbrr/hGsXFdBPmY2EcAVQRBmTvKkqwEm6Kce5NJRAIQZeftvSiWhWtUf9+8QYv2cpicygaD7mvnff1KcIyJ+RNAo6Qwk8PJBaM3zLRPgI8q/RWZkLMryuN7YOllmXhaCf5om2aX+kKD5cMIFaYLaUtmBzf47Wv89DVrAKn8AK2MgEUvSAjy/8MA2yoWUgYJU6mq14ldjrJ2zxRdue2eBaWgJuEf29EvLAMs9ciSgmyBpHA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR07MB623; X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB623; 20:HogLAGVA3efTwQI1RHXGaU7C3/Gh4wZ5Lfx+4rx4fDAb4lYCTg8z2ManxdM9KbBg/ueLtxfZq+TYxR2wt9sQd6KDk/oN8EPiYblG74cH40e6f3SCI/3B1rTsZGHO3h9SBMQ0EC4n48EKa1DsACRA56Usz0mOz/4+jKFuviraKNhHIGd73AkVzBqgm+MgPYxW5caMUJ4v3kZzst8diqUcHyBXS38v7zH0IsuwnFCZToHvZAYJ9hg0f0kUCzLeyqT1eFERbj0FIoCa9Q+E6Lyz2/CYwOJFptfCqGcP76t8I5TTXS/pROIxsV1+N0gFB8hHtBIZPB9BGaYMqWLQnRQsI7KqoilhUpu7bFsF04Yzl0i6MTK9/2RSzlxbcB3pQf1q9mVM5XCOa+hlvY1JpTZAN+qwVGLdJ3gE0XuggJWA6TZSpdKkhylbbJOYmtYtlvjd4JuTlLOqzw0HozhN2Dt4yk1tZKr58034n6GoOSrXc9KZHs0RJuVYhVhGYr0wMmEL6okT4CKcePJcZYHZqsZWFL6Ak3O5FHgNXRQLIJ/o+9W5HxjDGXnbvQXXEpPSiK/vYaRfsR8ucO5rmZ4DPCGZii5zUSHZ3JUlJjNUR4KptYI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(236414709691187); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(3002001)(10201501046); SRVR:DM2PR07MB623; BCL:0; PCL:0; RULEID:; SRVR:DM2PR07MB623; X-Microsoft-Exchange-Diagnostics: 1; DM2PR07MB623; 4:B6AQrOMyET4xbghTZw8ItqVpJNAJ8qnBsdQdE2oWnuFa8l9IqjXDjavFbqz/HfulVvU9LvmTQo2Xbrx3/fGr5X8UEEqLwLN3DVcQNzrXMT7Hifpe0JM3azl1AbGK19oWwtQlyBLufjBNhXfzmE5M1WE5/YZ6evYSc3FPv4w+2PN6dVAp9AtkYAqMAmphoKGWu+bOvZj5D5tSqyiQdyrq279S32j9Agv5ZIILPkQNaLq8caDKpVI1SbHRVXSgKlCuInJPSaxGZrc7m81KvfQGAZ5ErEraofISq0D5GXFnOx5eyjfhp+oDoHb9rse5IszS6RUcZ/alalvJfbenDblK5TOMFw12FJAWw/kq4FtUpH0wAvqhpNHZ+e7PagO5aIykgWvBudRchdaT9JFxWanWkSxbasOk5Fh3WW5yLcpFSDeDmESwVbxUVfbSmfjBi2qG X-Forefront-PRVS: 07915F544A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(6009001)(189002)(199003)(50986999)(50226001)(97736004)(229853001)(87976001)(2201001)(42186005)(101416001)(1096002)(106356001)(19580395003)(5008740100001)(5003940100001)(40100003)(76176999)(5001960100002)(122386002)(4001430100002)(77096005)(2950100001)(189998001)(19580405001)(33646002)(47776003)(5004730100002)(66066001)(50466002)(76506005)(92566002)(48376002)(107886002)(105586002)(5001770100001)(81156007)(3846002)(6116002)(36756003)(586003)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR07MB623; 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; DM2PR07MB623; 23:nnEnVQrFVoNcN0TiPbXeaMcg0JdpLZh5NLBukdj7Gg?= =?us-ascii?Q?2+ZxTGhsfku+1+eXgMlTyyzih4eQU6/uuDjj2Sfjfo8d8SWwgut43wX97bWW?= =?us-ascii?Q?kJpn4ofjJxMEU2wMDA7iehrFuxZZm7bvvzYhIebqq0/NjEsXcDVTvDAg12dr?= =?us-ascii?Q?C9DCsnirwq6klUAb+yphfDnHTi0wbwiU9prvuxo02o2Ql7YgwefdeSqkemFC?= =?us-ascii?Q?DsEw9cyFV2mJKbNVDstCK1neMk97odFvKQPjGz9eIPs+s7srAPqZ+L5Urb2B?= =?us-ascii?Q?yk7q/NFsqQxp/AfadUAso3ORC+Cx9BFNcZT0TaxuEDgaec9chPVXLiEMhsin?= =?us-ascii?Q?PfW0wUxCZq/oIzHHNmXomGvc5rpwsDH5oG5SNzvawxIYfoZBfivGaPs0WgVA?= =?us-ascii?Q?iBv/wZu5Tsm8MrMpbaUXeCJuEMvlU1UkB6p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cXjmQhqyOxPBLKEqWODMR3ZX/OuYFuk26B+gEem6m54XDasGyyNzFBDe1glgF5Pz7cHxevL83b/d/akyRi9//mI2VwT8xcyAvYTpnTVng= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2015 21:48:35.4231 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR07MB623 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151215_134859_247586_88155E1A X-CRM114-Status: GOOD ( 11.45 ) X-Spam-Score: -1.9 (-) 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: pinskia@gmail.com, Prasun.Kapoor@caviumnetworks.com, schwab@suse.de, broonie@kernel.org, Nathan_Lynch@mentor.com, agraf@suse.de, klimov.linux@gmail.com, Andrew Pinski , ynorov@caviumnetworks.com, jan.dakinevich@gmail.com, ddaney.cavm@gmail.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-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Pinski This patch supports core dumping on ILP32. We need a few extra macros (COMPAT_PR_REG_SIZE and COMPAT_PRSTATUS_SIZE) due to size differences of the register sets. Reviewed-by: David Daney Signed-off-by: Philipp Tomsich Signed-off-by: Christoph Muellner Signed-off-by: Yury Norov Signed-off-by: Andrew Pinski --- arch/arm64/include/asm/elf.h | 104 ++++++++++++++++++++++++++++++++++++++----- arch/arm64/kernel/ptrace.c | 12 ++--- 2 files changed, 100 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 8786ca5..4e2e3c0 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -135,7 +135,11 @@ typedef struct user_fpsimd_state elf_fpregset_t; */ #define ELF_PLAT_INIT(_r, load_addr) (_r)->regs[0] = 0 -#define SET_PERSONALITY(ex) clear_thread_flag(TIF_32BIT); +#define SET_PERSONALITY(ex) \ +do { \ + clear_thread_flag(TIF_32BIT_AARCH64); \ + clear_thread_flag(TIF_32BIT); \ +} while (0) #define ARCH_DLINFO \ do { \ @@ -167,12 +171,15 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3) +extern int aarch32_setup_vectors_page(struct linux_binprm *bprm, + int uses_interp); + #ifdef CONFIG_AARCH32_EL0 /* AArch32 registers. */ #define COMPAT_A32_ELF_NGREG 18 -typedef unsigned int compat_elf_greg_t; -typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_A32_ELF_NGREG]; +typedef unsigned int compat_a32_elf_greg_t; +typedef compat_a32_elf_greg_t compat_a32_elf_gregset_t[COMPAT_A32_ELF_NGREG]; /* AArch32 EABI. */ #define EF_ARM_EABI_MASK 0xff000000 @@ -180,15 +187,92 @@ typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_A32_ELF_NGREG]; ((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_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 +#define COMPAT_A32_SET_PERSONALITY(ex) \ +do { \ + clear_thread_flag(TIF_32BIT_AARCH64); \ + set_thread_flag(TIF_32BIT); \ +} while (0) +#define COMPAT_A32_ARCH_DLINFO do {} while (0) + +#else + +typedef elf_greg_t compat_elf_greg_t; +typedef elf_gregset_t compat_elf_gregset_t; +#define compat_a32_elf_check_arch(x) 0 +#define COMPAT_A32_SET_PERSONALITY(ex) do {} while (0) +#define COMPAT_A32_ARCH_DLINFO do {} while (0) +#endif + +/* + * If ILP32 is turned on, we want to define the compat_elf_greg_t to the non compat + * one and define PR_REG_SIZE/PRSTATUS_SIZE/SET_PR_FPVALID so we pick up the correct + * ones for AARCH32. Note also the definition of the macros have to be correct for + * LP64 as this file is included in the standard binfmt_elf.c. + */ +#ifdef CONFIG_ARM64_ILP32 +typedef elf_greg_t compat_elf_greg_t; +typedef elf_gregset_t compat_elf_gregset_t; +#ifdef CONFIG_AARCH32_EL0 +#define PR_REG_SIZE(S) (is_a32_compat_task() \ + ? sizeof(compat_a32_elf_gregset_t) \ + : sizeof(elf_gregset_t)) +#endif + +/* + * struct elf_prstatus is defined in include/uapi/linux/elfcore.h, + * and has different sise for supported ABIs + */ +#define PRSTATUS_SIZE(S) (is_a32_compat_task() ? 124 : (is_ilp32_compat_task() ? 352 : 392)) + +#define SET_PR_FPVALID(S, V) \ +do { \ + *(int *) (((void *) &((S)->pr_reg)) + PR_REG_SIZE((S)->pr_reg)) = (V); \ +} while (0) +#else +typedef compat_a32_elf_greg_t compat_elf_greg_t; +typedef compat_a32_elf_gregset_t compat_elf_gregset_t; +#endif + +#ifdef CONFIG_ARM64_ILP32 +#define compat_ilp32_elf_check_arch(x) ((x)->e_machine == EM_AARCH64) +#define COMPAT_ILP32_SET_PERSONALITY(ex) \ +do { \ + set_thread_flag(TIF_32BIT_AARCH64); \ + clear_thread_flag(TIF_32BIT); \ +} while (0) +#define COMPAT_ILP32_ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)(long)current->mm->context.vdso); \ +} while (0) +#else +#define compat_ilp32_elf_check_arch(x) 0 +#define COMPAT_ILP32_SET_PERSONALITY(ex) do {} while (0) +#define COMPAT_ILP32_ARCH_DLINFO do {} while (0) #endif -#define compat_elf_check_arch(x) compat_a32_elf_check_arch(x) +#define compat_elf_check_arch(x) (compat_a32_elf_check_arch(x) || compat_ilp32_elf_check_arch(x)) +#define COMPAT_SET_PERSONALITY(ex) \ +do { \ + if (compat_a32_elf_check_arch(&ex)) \ + COMPAT_A32_SET_PERSONALITY(ex); \ + else \ + COMPAT_ILP32_SET_PERSONALITY(ex); \ +} while (0) + +/* ILP32 uses the "LP64-like" vdso pages */ +#define compat_arch_setup_additional_pages \ + (is_a32_compat_task() \ + ? &aarch32_setup_vectors_page \ + : &(arch_setup_additional_pages)) + +#define COMPAT_ARCH_DLINFO \ +do { \ + if (is_a32_compat_task()) \ + COMPAT_A32_ARCH_DLINFO; \ + else \ + COMPAT_ILP32_ARCH_DLINFO; \ +} while (0) #endif /* CONFIG_COMPAT */ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 816b432..a9d07a9 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -853,8 +853,8 @@ static const struct user_regset aarch32_regsets[] = { [REGSET_COMPAT_GPR] = { .core_note_type = NT_PRSTATUS, .n = COMPAT_A32_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 }, @@ -945,7 +945,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); @@ -966,7 +966,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; set_fs(KERNEL_DS); @@ -1129,7 +1129,7 @@ long compat_a32_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; @@ -1137,7 +1137,7 @@ long compat_a32_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;