Received: by 10.213.65.68 with SMTP id h4csp712747imn; Fri, 6 Apr 2018 07:41:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/H5u9UNsiHn3JrHiM6YQifw4RBauKX8rAfE5mVfA0MJQ0TX4J/RGehDGW65Amgv9csxVa9 X-Received: by 10.101.100.132 with SMTP id e4mr18044579pgv.240.1523025714457; Fri, 06 Apr 2018 07:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523025714; cv=none; d=google.com; s=arc-20160816; b=n+AHceGMp2hbcDf0V5ApOzrfw+JJJDTu4Rig/QYOGIUvtPKnkkCtsz7ZrUL74z8Rv4 97j3XwV9bU+ZQBuOvt40HtfWAETLvwjbAbwR/Y3uYAouazzefTD9rzTmEGxCd1mx8SFu WWdY+W3c/IgejpcQdnKXzek82l/Piv4IeqVFW61iwRPf5BsfxzC9uDKwsG6+nZ2hJqFp pDocqLwlAZ2xVs4Nk1hwR3j89A0yGRdrOIwB0/51wN0BluSh2vPpthtbjGhs8R/wKS12 hN5lK9OoRxmiLnAd5U/VE2YcqjmggmxYG+1fxv+wOGMOuIJlCzratW8cXovaR1wsv7r9 40Xw== 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=yAVDz18ftekCij2QXs2aytFla0k+Xa1F0TLFLSgDhKk=; b=FLIeBM3ISqmfzrnnAirHd9sUrkzMNgueNLt511zhLdjlP3GGDQpmO6TEGgj1k9+rEv WKwDl1vrTQusZ6COAc1KKi2R+thfEwCzHRefrOiaq8BBoOhUsyG2WD8m4sEd27KWgAz8 NkH0u8STr5nrr1M6vGOCzkAAkMvoqSjbmK/m6nf5atakNeSK1KVRxmtUF61LnyNcNcJR mBC9n03af5GNEM6mdWg9yfSfGWdIa8+dvqDP6lgNg+svkKbpveV2WB1ceHry/jPn4t88 0Z+eLBBCblSUvsmi47s+bBbdtRb1Td9mk0kmckfbX/rh9770WQU5C46GEcNtsVjBvexZ tjpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nokia.onmicrosoft.com header.s=selector1-nokia-com header.b=HJbMORX9; 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 p4si7018964pgv.545.2018.04.06.07.41.40; Fri, 06 Apr 2018 07:41:54 -0700 (PDT) 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=HJbMORX9; 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 S1756017AbeDFOki (ORCPT + 99 others); Fri, 6 Apr 2018 10:40:38 -0400 Received: from mail-he1eur01on0092.outbound.protection.outlook.com ([104.47.0.92]:14464 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756049AbeDFOk2 (ORCPT ); Fri, 6 Apr 2018 10:40:28 -0400 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=yAVDz18ftekCij2QXs2aytFla0k+Xa1F0TLFLSgDhKk=; b=HJbMORX91zjtqegOh9nFV3aptbfL1VfMwjjoYCtiGHfQO2+FuopeMrFe/og2K9gH17MTfykrfnqPrWSUXb2Q3536txc2gAJyu0AevY4T/EoAUjUQEU7E7Icw9w62LCLuEnMhYg4Sf8gWDIVk8I0KHOQZRhw+3jsOgmUcOeGaSvo= 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 HE1PR0701MB2473.eurprd07.prod.outlook.com (2603:10a6:3:71::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.675.4; Fri, 6 Apr 2018 14:40:22 +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 , Ard Biesheuvel Subject: [PATCH v5 3/3] ARM: ftrace: Add MODULE_PLTS support Date: Fri, 6 Apr 2018 16:39:39 +0200 Message-Id: <20180406143939.14642-4-alexander.sverdlin@nokia.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180406143939.14642-1-alexander.sverdlin@nokia.com> References: <20180406143939.14642-1-alexander.sverdlin@nokia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [131.228.2.20] X-ClientProxiedBy: MAXPR0101CA0018.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:c::28) To HE1PR0701MB2473.eurprd07.prod.outlook.com (2603:10a6:3:71::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 140f14cd-f769-4849-c054-08d59bcc55b9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:HE1PR0701MB2473; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0701MB2473;3:F01eP2pEa4LmZSf8YQHdloS/6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p1mFKlHrPeiHHLQuBnSk8XC+IKDDD0d4UhllRRxlU3YHzTQ8B5+phnWj5qaoASjHsjdJvUVUj0ItRItCyw4WADRz7ObUD4Foue1IVhwMHZSy/BPRfmTsPrCLkK9g2QdQKQYX9Jk1b2lOlflFNRbIx/Zt/Mkkm1eACCpjjqjjVHRmNhKJ+0KetlBgKKQy8ehkuPRHRV+CmMuqlGNgl2w/mp4bYg+nUg9IlGVqUFwN+Onh7L92sDjqjyGeOElo/P+SudRM/0XX57B3KBplnH3i2cT2pp49njcBKjQ4T+kbHes9lChwROsiDCBU21SxunRk8StKrauUTZEn6OnagxBmyShBf99KpyIliZLzWJ0IBESkpnrheXwsxrLquwwpwJRfNjazjwLFllmwjuO1BLeIweSSS+R6QQwwO0ZWoB25HYbk2CF3Hcg=;4:ruR0DnE7KUJ6fOhDB4Hf8TnwU3aZ/HJSvxp1CVR9U5SJSbYTJRwe+a0mYXtqyMsNzAALmmrSe3WQ1fIl2vW5oTjjEbT4KzDNucWLY7MG9+aN5XlhB/L2+9g/I9EGnu2yhxVGJCM1tvAH1/HiXET5yL8M2v5EeUUjbeKblySpaPhdo+FL02IjVVzVRbJ5K4mtQMp0l+ESoNnZ7NaA3FsR+ehSOHpR04SL/8ySoWWG7SXQbKxm6xF+7pMOIHAxWaD5PCZgLBb55SERHNeCuGtdApwXuNKhXHCSJTcFRUQk8UxrFJSFtbbXIuedfLNOdL/B 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)(3002001)(10201501046)(3231221)(11241501184)(806099)(944501327)(52105095)(93006095)(93001095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(6072148)(201708071742011);SRVR:HE1PR0701MB2473;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0701MB2473; X-Forefront-PRVS: 0634F37BFF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(346002)(376002)(39380400002)(189003)(199004)(25786009)(446003)(4326008)(11346002)(956004)(97736004)(2616005)(476003)(26005)(186003)(16526019)(6666003)(47776003)(6916009)(2361001)(66066001)(7736002)(305945005)(5660300001)(486006)(8936002)(50226002)(81166006)(53936002)(3846002)(6116002)(8676002)(81156014)(106356001)(6512007)(105586002)(16586007)(316002)(6486002)(52116002)(51416003)(76176011)(2906002)(36756003)(68736007)(1076002)(86362001)(54906003)(2351001)(48376002)(6506007)(50466002)(386003)(478600001)(59450400001);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0701MB2473;H:ulegcpsvdell.emea.nsn-net.net;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR0701MB2473;23:k39GbYA133xUlalCE/GcmN08vgzU5krV2XnqkZe?= =?us-ascii?Q?7/8LlDcYTFi3Au3Uvkl7UHBm8il+QWTG4KHdMrDADHZYShqPx5zHDqN4muRy?= =?us-ascii?Q?dcFWHZL11Uu5k1/KJXtM+enJaDO1matCkjySIXy346o5Cnx4srvh+fP4Fa4n?= =?us-ascii?Q?wF+EjY1aMiiRoshR89H1lcd5fcEJ7ZuDqe5mtdhv7pEDj1MYXOTZmTsOIUYn?= =?us-ascii?Q?25y2IWfoQ2vM1hkP3FrX6y0y4Y2J+CsS0XO3dGTZfy4d9rHN9KMA5cYWlJbk?= =?us-ascii?Q?ybsOxwp13pylTW3t6llGOMZkb+doAIaTfXaj0nEjp1jc9IGaQMXAyj57UmNG?= =?us-ascii?Q?dys+XOU86Scd7Rfz3cU3ALV5ODbZyMQ9DqkCcyoMZ4GqbL/X72Ay04ZD/4Li?= =?us-ascii?Q?g6PiXFnJKiA0f5wO4owPVdPjWWzEcMKTzT+7kbOeP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ticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0701MB2473;7:WYzdYqMaQ8TXcftRrykYJsXGLSZ1GeJxxEduBb3OSaQfzQrsPlBpVL0NaaB/S8PajnX5PLE9k3SwySspX/jRCFcJu8jdZ84Qm5sWOfPYXbpJUhxXTDbtUQLZmzaQw3n8sJWQc/vd2bs8CluC7gxVA7dyyEIRXQsGl/97qMVzu2HKcvbWJmURRnwZDZ9KKcgCbAkzmu+WeWd0Sfpa18Oq+x5dWdbbWL2cAqpl62LRVO+ocbCJ10jJcfZh3GTcHo2t X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2018 14:40:22.4567 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 140f14cd-f769-4849-c054-08d59bcc55b9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0701MB2473 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 | 48 ++++++++++++++++++++++++++++++--- 4 files changed, 101 insertions(+), 13 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..da9a8a3 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,19 +23,56 @@ (PLT_ENT_STRIDE - 8)) #endif +static const u32 fixed_plts[] = { +#ifdef CONFIG_FUNCTION_TRACER + FTRACE_ADDR, + MCOUNT_ADDR, +#endif +#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; } +static void prealloc_fixed(struct mod_plt_sec *pltsec, struct plt_entries *plt) +{ + int i; + + if (!ARRAY_SIZE(fixed_plts) || pltsec->plt_count) + return; + pltsec->plt_count = ARRAY_SIZE(fixed_plts); + + for (i = 0; i < ARRAY_SIZE(plt->ldr); ++i) + plt->ldr[i] = PLT_ENT_LDR; + + BUILD_BUG_ON(sizeof(fixed_plts) > sizeof(plt->lit)); + memcpy(plt->lit, fixed_plts, sizeof(fixed_plts)); +} + 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; + struct plt_entries *plt; + int idx; + + /* cache the address, ELF header is available only during module load */ + if (!pltsec->plt_ent) + pltsec->plt_ent = (struct plt_entries *)pltsec->plt->sh_addr; + plt = pltsec->plt_ent; - struct plt_entries *plt = (struct plt_entries *)pltsec->plt->sh_addr; - int idx = 0; + prealloc_fixed(pltsec, plt); + + for (idx = 0; idx < ARRAY_SIZE(fixed_plts); ++idx) + if (plt->lit[idx] == val) + return (u32)&plt->ldr[idx]; + idx = 0; /* * Look for an existing entry pointing to 'val'. Given that the * relocations are sorted, this will be the last entry we allocated. @@ -182,8 +220,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; @@ -238,6 +276,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, mod->arch.core.plt->sh_size = round_up(core_plts * PLT_ENT_SIZE, sizeof(struct plt_entries)); mod->arch.core.plt_count = 0; + mod->arch.core.plt_ent = NULL; mod->arch.init.plt->sh_type = SHT_NOBITS; mod->arch.init.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; @@ -245,6 +284,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, mod->arch.init.plt->sh_size = round_up(init_plts * PLT_ENT_SIZE, sizeof(struct plt_entries)); mod->arch.init.plt_count = 0; + mod->arch.init.plt_ent = NULL; pr_debug("%s: plt=%x, init.plt=%x\n", __func__, mod->arch.core.plt->sh_size, mod->arch.init.plt->sh_size); -- 2.4.6