Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933827AbbLOVsl (ORCPT ); Tue, 15 Dec 2015 16:48:41 -0500 Received: from mail-bn1bon0074.outbound.protection.outlook.com ([157.56.111.74]:9856 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932449AbbLOVsh (ORCPT ); Tue, 15 Dec 2015 16:48:37 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; From: Yury Norov To: , , , CC: , , , , , , , , , , , , , , Andrew Pinski 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 Content-Type: text/plain 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; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR07MB623;23:nnEnVQrFVoNcN0TiPbXeaMcg0JdpLZh5NLBukdj7Gg?= =?us-ascii?Q?2+ZxTGhsfku+1+eXgMlTyyzih4eQU6/uuDjj2Sfjfo8d8SWwgut43wX97bWW?= =?us-ascii?Q?kJpn4ofjJxMEU2wM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us-ascii?Q?+C4vMzgjqdbMR8SW9pme4h9fR8Z6p8gbiEol5m5U0xFM2d8j1qp+0zUI5qpQ?= =?us-ascii?Q?SNZppQm7z0WJmQAA3dXdYvdLku0UtOo/BITluIMvFhz38sAc7fcYdMKxxGBQ?= =?us-ascii?Q?YhZxeuwiuWsay3jY09yPH18ZNYEvL3?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR07MB623;5:ucf+1WhTJeFxJ/GqWHsX0xomQXwPf/p4s902LwbKcVlWaUkH9hm4XMFaYiW2707tTw7quMpAujzJWAtpPsHzxMvPzqUj+0kbtYC0TGv8KTEpCthHKm7oByv+sVX95hCHtIrx3sHWYJt/sxh9sbA4cw==;24:yRcXjmQhqyOxPBLKEqWODMR3ZX/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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7370 Lines: 210 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; -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/