Received: by 10.223.185.111 with SMTP id b44csp53870wrg; Fri, 9 Mar 2018 00:43:32 -0800 (PST) X-Google-Smtp-Source: AG47ELsCwo4YY6TJQPcKtjnyCPX0IWamtBcfcO7gjjvQbp2erNV+kjJJOd5fFtdTCKWbDQIcOeLO X-Received: by 2002:a17:902:47:: with SMTP id 65-v6mr26381769pla.194.1520585012774; Fri, 09 Mar 2018 00:43:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520585012; cv=none; d=google.com; s=arc-20160816; b=iYUdWRO8oL/B2PIQwpnYMxTLGQoJCIx15WnwFBkSTPcVOVbvQrOlc2DHqTImLz6xnx dcSZb0+i3oa5B4OCAfhAfwKzRjz9zUP2v4WYVNfh4BWv1U1WRS0Idm+lD75PUudRLwwt cOQUR7lo1bE3dOEVCFP5s2mqsVzfu7ogf6cQd5/ilT8nsl1cAFbUd6ucepwr97ppOM0O wgsjwg6H+SA1ztgioFhxsW66v51ziCG+4nmLozeXEg4xR3FQyhB6oh007n5esK3WMCJN JKR7zMp62E3wy/QieAlz65Bh4u9EHG2fuYsvhEVhE1nkbBU4r+2+KJWyfzpe4iETqgmM QKPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:arc-authentication-results; bh=h7WWalSDuqZykxYYNUP4HQiz59fPUcgou8HT2S11hpE=; b=BdHAmPtluRKJGCY1r2yZacz7by4g7VcCYiUkydxGK69mfSktqlusCeWllKThlMfcL5 v9yfL+7QvoAWrHPp1+Tz87dEwoLv0ggD9On78HKenc0wspRsMktFeO6Ag5EIeX8KBH4i twtFqKiWtpYHHSRDHsmW+aFDZm/775/GuPyZ0xOu0gpZjxKw3nQ7ZX5CfB0ak9N1mP5c TCJHffKbWDQa48cPqrrS16Y+DIXeV0VOqCHqGU6KVRD7jJY1li9/TG+l88ZCuoVARoC/ LGzCAXQg6qLAO1Yf3qmOnCQFKWYx0ZL9vTTSjyBB+uhoc7ZOLeqQyF8pMqCXo7Si3Fh8 97FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nokia.onmicrosoft.com header.s=selector1-nokia-com header.b=gM76WHRg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nokia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si410137pgr.797.2018.03.09.00.43.18; Fri, 09 Mar 2018 00:43:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nokia.onmicrosoft.com header.s=selector1-nokia-com header.b=gM76WHRg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nokia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752084AbeCIIm1 (ORCPT + 99 others); Fri, 9 Mar 2018 03:42:27 -0500 Received: from mail-eopbgr10123.outbound.protection.outlook.com ([40.107.1.123]:19872 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750926AbeCIImS (ORCPT ); Fri, 9 Mar 2018 03:42:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=h7WWalSDuqZykxYYNUP4HQiz59fPUcgou8HT2S11hpE=; b=gM76WHRgrbFO7BmswUAathzOj6R5g4LeGBnj0623nF+j2rdf5QmblyGRKR9DfY1V4w/JxLIBUBQUrmhv7RkdpcffOqNIzhgYW6jvmlzWbK8T/Pllfs3s4IaRn8gkYjPmyc6VnOfTOjCAakSM7Ys6H+hemXtE0hqWzqjuYdwLZKE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=alexander.sverdlin@nokia.com; Received: from ulegcpsvdell.emea.nsn-net.net (131.228.2.20) by VI1PR07MB1328.eurprd07.prod.outlook.com (2a01:111:e400:5a03::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.6; Fri, 9 Mar 2018 08:42:11 +0000 From: Alexander Sverdlin To: linux-arm-kernel@lists.infradead.org Cc: Alexander Sverdlin , linux-kernel@vger.kernel.org, Russell King , Steven Rostedt , Ingo Molnar Subject: [PATCH v3 2/2] ARM: ftrace: Add MODULE_PLTS support Date: Fri, 9 Mar 2018 09:41:51 +0100 Message-Id: <20180309084151.2379-3-alexander.sverdlin@nokia.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180309084151.2379-1-alexander.sverdlin@nokia.com> References: <20180309084151.2379-1-alexander.sverdlin@nokia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [131.228.2.20] X-ClientProxiedBy: HE1P192CA0018.EURP192.PROD.OUTLOOK.COM (2603:10a6:3:fe::28) To VI1PR07MB1328.eurprd07.prod.outlook.com (2a01:111:e400:5a03::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1a679d04-f651-4ae8-bce5-08d58599a6c0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:VI1PR07MB1328; X-Microsoft-Exchange-Diagnostics: 1;VI1PR07MB1328;3:HI36nfah/OJy8JJ1tmKODb684R3liYObc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Re65Hr6NR9Z3waPhBTvfyJOzDdbfPg/0WNkD2gtInWkmxsFW0Vyykf6nP+KHNVhHlpqyl/2Sd8U6XAatJcuYrDMVEulr14OhGP/EHvR9sJ9xGrbxx4K1o15A9UGyB71hCSHqzicySGGVE0eGjN7NCtxcr8bHmWEW6pbWViIc1VoWPjUkFwvttacHZ4uwmEDKiuGBBGR4thqYjZg50nKSPhBrFJEQhhJYg5Mhy6PeGsGqdLBS9rlYdbEs9UHJVIhilban6ye2DTjmJ1K5MMh0TKQcArLEZzS9Tuzy6LF833KBeX4/2WR8wL32JxX9bHxr6GO3oKaxAgsY/7Lphlha62AnxOlA1/TtJ2YQqYCPOI/8axS3Nyl/Z4UCRBsXSka5ufMkfHyNNuJwOk2Bx7+H+wBgbeCtKraAC9nQnSSEns7Xt8R9Yw=;4:TVRM7LhAvGZCRq6jww9Hor5bP7i73IC5nOOZpfG94e1Z9pGoBca7Cpt9WWYbcMmSnlYJLjMmypHZHqOFru2xqbHEYyIQnScmq/eLe75fnQod6ZWryU9k0fJaPjVDz6NmdA4kVcSgMKcfHGqw8VUV3IkRkOR7mPKa5PRRCJxbCTQqFbbqe/1BojjAnvv6UgB7nHZah3ggejWuyTiAfmSkhdYDCiVcb769S7n9A9wbitNoh4+CqRtVZeDh/Hnf6fCIUGLiJtDpCX0HXhcXZF6lg305Sla89OSMhEy8dKo5jHQzhIxtbaY6+bb7vXA8PcVs X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(82608151540597); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231220)(11241501184)(806099)(944501244)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041310)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011);SRVR:VI1PR07MB1328;BCL:0;PCL:0;RULEID:;SRVR:VI1PR07MB1328; X-Forefront-PRVS: 0606BBEB39 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(39860400002)(396003)(376002)(346002)(39380400002)(199004)(189003)(48376002)(4326008)(36756003)(86362001)(106356001)(6486002)(25786009)(97736004)(105586002)(51416003)(16526019)(50466002)(59450400001)(50226002)(52116002)(386003)(26005)(76176011)(7736002)(305945005)(186003)(6506007)(8936002)(54906003)(3846002)(6116002)(6666003)(8676002)(16586007)(68736007)(316002)(66066001)(1076002)(2361001)(5660300001)(81166006)(6512007)(2351001)(478600001)(47776003)(2950100002)(81156014)(6916009)(2906002)(53936002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR07MB1328;H:ulegcpsvdell.emea.nsn-net.net;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;VI1PR07MB1328;23:ii2rWmjN4XWAp9S0fy5dMA14MbqNJ3dYzKxViBJ+v?= =?us-ascii?Q?VLeH1ND1QONF/aMTC2DAVSHvUP/05Ocupnr3InW1RHWZp/zsgu5ZOL+eM3Fp?= =?us-ascii?Q?atBw4LE/yG4D5BV3ik8ULl1BUt+1KJ+3mByqywhHFkPogv7Tiv/PS8STuQb/?= =?us-ascii?Q?b7C01mT2qhC6rjAk1VMSO+PSIlNr9S5DZGc/jYxshDAgjdNi7SG8qyzcnWOn?= =?us-ascii?Q?+CbCy6hK+kmopBB88SaBdZ6PqngOGZESUDvXrWTw7HgjihyEwNF+1R7HGQAL?= =?us-ascii?Q?H8KMAIi2UtyUkMJOi6j56lURGilzlM8M6anh6F6gnZ8w7ME5/VZ7g5QpI3Nl?= =?us-ascii?Q?3HMdD2RUQCwz287fWT8pDhujHFIJ2f/4D4escs7QOhmMSK1APmx0ZMHPMr64?= =?us-ascii?Q?sPth3zaDhCJS9Aod4KFRJNpinZSuBsLCJTOjQHFKkfrO1oLRHYvESFdptBbq?= =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SPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2018 08:42:11.1038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a679d04-f651-4ae8-bce5-08d58599a6c0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB1328 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Teach ftrace_make_call() and ftrace_make_nop() about PLTs. Teach PLT code about FTRACE and all its callbacks. Otherwise the following might happen: ------------[ cut here ]------------ WARNING: CPU: 14 PID: 2265 at .../arch/arm/kernel/insn.c:14 __arm_gen_branch+0x83/0x8c() ... Hardware name: LSI Axxia AXM55XX [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x81/0xa8) [] (dump_stack) from [] (warn_slowpath_common+0x69/0x90) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [] (warn_slowpath_null) from [] (__arm_gen_branch+0x83/0x8c) [] (__arm_gen_branch) from [] (ftrace_make_nop+0xf/0x24) [] (ftrace_make_nop) from [] (ftrace_process_locs+0x27b/0x3e8) [] (ftrace_process_locs) from [] (load_module+0x11e9/0x1a44) [] (load_module) from [] (SyS_finit_module+0x59/0x84) [] (SyS_finit_module) from [] (ret_fast_syscall+0x1/0x18) ---[ end trace e1b64ced7a89adcc ]--- ------------[ cut here ]------------ WARNING: CPU: 14 PID: 2265 at .../kernel/trace/ftrace.c:1979 ftrace_bug+0x1b1/0x234() ... Hardware name: LSI Axxia AXM55XX [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x81/0xa8) [] (dump_stack) from [] (warn_slowpath_common+0x69/0x90) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [] (warn_slowpath_null) from [] (ftrace_bug+0x1b1/0x234) [] (ftrace_bug) from [] (ftrace_process_locs+0x285/0x3e8) [] (ftrace_process_locs) from [] (load_module+0x11e9/0x1a44) [] (load_module) from [] (SyS_finit_module+0x59/0x84) [] (SyS_finit_module) from [] (ret_fast_syscall+0x1/0x18) ---[ end trace e1b64ced7a89adcd ]--- ftrace failed to modify [] 0xe9ef7006 actual: 02:f0:3b:fa ftrace record flags: 0 (0) expected tramp: c0314265 Signed-off-by: Alexander Sverdlin --- arch/arm/include/asm/ftrace.h | 3 +++ arch/arm/include/asm/module.h | 1 + arch/arm/kernel/ftrace.c | 62 ++++++++++++++++++++++++++++++++++++------- arch/arm/kernel/module-plts.c | 53 +++++++++++++++++++++++++++--------- 4 files changed, 97 insertions(+), 22 deletions(-) diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 9e842ff..faeb6b1 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -19,6 +19,9 @@ struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; #endif +#ifdef CONFIG_ARM_MODULE_PLTS + struct module *mod; +#endif }; static inline unsigned long ftrace_call_adjust(unsigned long addr) diff --git a/arch/arm/include/asm/module.h b/arch/arm/include/asm/module.h index 6996405..e3d7a51 100644 --- a/arch/arm/include/asm/module.h +++ b/arch/arm/include/asm/module.h @@ -30,6 +30,7 @@ struct plt_entries { struct mod_plt_sec { struct elf32_shdr *plt; + struct plt_entries *plt_ent; int plt_count; }; diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index 5617932..b55355f 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -98,6 +98,19 @@ int ftrace_arch_code_modify_post_process(void) static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) { + s32 offset = addr - pc; + s32 blim = 0xfe000008; + s32 flim = 0x02000004; + + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) { + blim = 0xff000004; + flim = 0x01000002; + } + + if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS) && + (offset < blim || offset > flim)) + return 0; + return arm_gen_branch_link(pc, addr); } @@ -166,10 +179,22 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) { unsigned long new, old; unsigned long ip = rec->ip; + unsigned long aaddr = adjust_address(rec, addr); old = ftrace_nop_replace(rec); - new = ftrace_call_replace(ip, adjust_address(rec, addr)); + new = ftrace_call_replace(ip, aaddr); + +#ifdef CONFIG_ARM_MODULE_PLTS + if (!new) { + struct module *mod = rec->arch.mod; + + if (mod) { + aaddr = get_module_plt(mod, ip, aaddr); + new = ftrace_call_replace(ip, aaddr); + } + } +#endif return ftrace_modify_code(rec->ip, old, new, true); } @@ -199,20 +224,39 @@ int ftrace_make_nop(struct module *mod, unsigned long new; int ret; - old = ftrace_call_replace(ip, adjust_address(rec, addr)); - new = ftrace_nop_replace(rec); - ret = ftrace_modify_code(ip, old, new, true); +#ifdef CONFIG_ARM_MODULE_PLTS + /* mod is only supplied during module loading */ + if (!mod) + mod = rec->arch.mod; + else + rec->arch.mod = mod; +#endif -#ifdef CONFIG_OLD_MCOUNT - if (ret == -EINVAL && addr == MCOUNT_ADDR) { - rec->arch.old_mcount = true; + for (;;) { + unsigned long aaddr = adjust_address(rec, addr); + + old = ftrace_call_replace(ip, aaddr); + +#ifdef CONFIG_ARM_MODULE_PLTS + if (!old && mod) { + aaddr = get_module_plt(mod, ip, aaddr); + old = ftrace_call_replace(ip, aaddr); + } +#endif - old = ftrace_call_replace(ip, adjust_address(rec, addr)); new = ftrace_nop_replace(rec); ret = ftrace_modify_code(ip, old, new, true); - } + +#ifdef CONFIG_OLD_MCOUNT + if (ret == -EINVAL && !rec->arch.old_mcount) { + rec->arch.old_mcount = true; + continue; + } #endif + break; + } + return ret; } diff --git a/arch/arm/kernel/module-plts.c b/arch/arm/kernel/module-plts.c index f272711..a216256 100644 --- a/arch/arm/kernel/module-plts.c +++ b/arch/arm/kernel/module-plts.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -22,6 +23,15 @@ (PLT_ENT_STRIDE - 8)) #endif +static u32 fixed_plts[] = { + FTRACE_ADDR, + MCOUNT_ADDR, +#ifdef CONFIG_OLD_MCOUNT + (unsigned long)ftrace_caller_old, + (unsigned long)mcount, +#endif +}; + static bool in_init(const struct module *mod, unsigned long loc) { return loc - (u32)mod->init_layout.base < mod->init_layout.size; @@ -31,26 +41,43 @@ u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) { struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core : &mod->arch.init; + int idx; + struct plt_entries *plt; + + /* Pre-allocate entries in the first plt */ + if (!pltsec->plt_count) { + plt = (struct plt_entries *)pltsec->plt->sh_addr; + for (idx = 0; idx < ARRAY_SIZE(plt->ldr); ++idx) + plt->ldr[idx] = PLT_ENT_LDR; + memcpy(plt->lit, fixed_plts, sizeof(fixed_plts)); + pltsec->plt_count = ARRAY_SIZE(fixed_plts); + /* + * cache the address, + * ELF header is available only during module load + */ + pltsec->plt_ent = plt; + } + plt = pltsec->plt_ent; - struct plt_entries *plt = (struct plt_entries *)pltsec->plt->sh_addr; - int idx = 0; + idx = ARRAY_SIZE(fixed_plts); + while (idx) + if (plt->lit[--idx] == val) + return (u32)&plt->ldr[idx]; /* * Look for an existing entry pointing to 'val'. Given that the * relocations are sorted, this will be the last entry we allocated. * (if one exists). */ - if (pltsec->plt_count > 0) { - plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; - idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; + plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; + idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; - if (plt->lit[idx] == val) - return (u32)&plt->ldr[idx]; + if (plt->lit[idx] == val) + return (u32)&plt->ldr[idx]; - idx = (idx + 1) % PLT_ENT_COUNT; - if (!idx) - plt++; - } + idx = (idx + 1) % PLT_ENT_COUNT; + if (!idx) + plt++; pltsec->plt_count++; BUG_ON(pltsec->plt_count * PLT_ENT_SIZE > pltsec->plt->sh_size); @@ -182,8 +209,8 @@ static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base, int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings, struct module *mod) { - unsigned long core_plts = 0; - unsigned long init_plts = 0; + unsigned long core_plts = ARRAY_SIZE(fixed_plts); + unsigned long init_plts = ARRAY_SIZE(fixed_plts); Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; Elf32_Sym *syms = NULL; -- 2.4.6