Received: by 10.213.65.68 with SMTP id h4csp365236imn; Tue, 13 Mar 2018 06:55:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELtm146twkgAhFN8p1asgnjNqnct2t0H33v8V4N3vze7eQTbNyN/eLF2XA5uCp1oXUg0zv4/ X-Received: by 10.98.174.16 with SMTP id q16mr717194pff.92.1520949305242; Tue, 13 Mar 2018 06:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520949305; cv=none; d=google.com; s=arc-20160816; b=vL/Bn9mro4naf8X5WiIZmfneS4U7e2YE+ZmN6QIXPjeHDZuqdWMBO75KOFAhucpOsG 69ZQQR0RPhoT1DPf+2GdD9mCn6Y6DLXktH7roRFJukQHdMRckfNApAxuZmcoO9dva4zy LOyMd26WoDuqKnYGiJx+hZIH38xrlwzBEk/l9Ry7/BS9+7F7loEJz7HdrFHVoPAVAgt4 qAUIopAf5rkjQ/PSKwywsEJ0uoV2OGuV3TeaCbNo6inMdnyDmSxv8hewxsO4/QEDYk03 z52FIb/qdPnYxg3ubErDnNEGEssghA5t7M+a+fC3M+VHXliYoCZ4UC4s8BDhoN4kWxEr EtmQ== 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=x7MWuQ/r+qAfvoOA+lt3T4Hko6W1EVAOYp/rsPMjOe4=; b=rcwKmKrnhEwh6gwQvURbb8lmpOEsPSL/f3qLMLN1V7WYHG8cn0E9FBw4D8HgURLYf0 bPdLUxWkliDDQRrCaagZ1V5DPs8cRqGriVNlhyNVpJggm62wrmLnWfmYdrO/tOCgi9h4 TeP8Z/E+mC/v7WHptQWf3gpD7xSgwTx5zBrTkqLEAStdeD4IQcmrgj5mc4Xa+0zpoz2I Btc9ESP2+odhf6/ZFnVbSaJySRn39bUF8dxlZvCRKgetBG+80N4IBM52P0NvmjlZMqyy XKiwEQ0QkfXZEyPuf5wucbIRouF5j3Z2/bL+D6RBB797XSZ93nxtXkt09kafFskfPdfn LBwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nokia.onmicrosoft.com header.s=selector1-nokia-com header.b=YirD42lh; 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 e1-v6si137460ple.654.2018.03.13.06.54.50; Tue, 13 Mar 2018 06:55:05 -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=YirD42lh; 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 S932910AbeCMNxq (ORCPT + 99 others); Tue, 13 Mar 2018 09:53:46 -0400 Received: from mail-eopbgr20095.outbound.protection.outlook.com ([40.107.2.95]:3417 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932822AbeCMNxl (ORCPT ); Tue, 13 Mar 2018 09:53:41 -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=x7MWuQ/r+qAfvoOA+lt3T4Hko6W1EVAOYp/rsPMjOe4=; b=YirD42lh0iJrx4yTojhSiWMNuOTJDn8sT31iKZVJb/NFxTUOFOZ22BIuOitNwnajszPsGEKcdcaCROiPc8nn/HJCYxRRDUTo7gbinFhExUFd2mmsE9vL1KE8DroVwTIPhfA24esXxcLhlJ4Ak7CGjG09MieENksJyIan2pT9Upo= 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 DB5PR07MB1319.eurprd07.prod.outlook.com (2a01:111:e400:599b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.7; Tue, 13 Mar 2018 13:53:34 +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 v4 2/2] ARM: ftrace: Add MODULE_PLTS support Date: Tue, 13 Mar 2018 14:53:14 +0100 Message-Id: <20180313135314.18780-3-alexander.sverdlin@nokia.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180313135314.18780-1-alexander.sverdlin@nokia.com> References: <20180313135314.18780-1-alexander.sverdlin@nokia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [131.228.2.20] X-ClientProxiedBy: HE1PR0202CA0002.eurprd02.prod.outlook.com (2603:10a6:3:8c::12) To DB5PR07MB1319.eurprd07.prod.outlook.com (2a01:111:e400:599b::13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e2da8f2f-5efa-4ba3-2b43-08d588e9d0f9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DB5PR07MB1319; X-Microsoft-Exchange-Diagnostics: 1;DB5PR07MB1319;3:r0gaA2GucxALZvQnYBcavplGiEKDD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K+vSUCxrJpk2i5x1MZ1j8eDHkKT3mha/HSIvrn/7lRx7xzl78daYW9WNT8Y0DljZGdB06DtvvBMwOzPQUvwIvufq62lIK6ID4nhBtpYvodayTxP8KZZ4YMM2G1aUS2Ato9WUicZTwRBuuGxFFyQEghL4kDrUF7L6b36pjTu4XgU80uMCR0v9JKKug3YSv2wlLXBwyMI/Dcq/TNa/iHLwWbQX/kBZUeb4LWEBIx7zAPyM1iGy0z4j6QSZw575xGcKNAHg/7eu3+3msamo98IbVRbnvSvCl9qXcBI9iZXb/TkJBzzcX3S14TD7jXUKZgeKMo4Pzo6+yMB2MoYJggJAsPc1oHo3W0ks/aPw4gLr2Nbg3U15G4emsFvy9/gwvIVYs6LCSCTYzPSSZan6EuOtnE+sD/e98bZ1CH34vRxGinScPXKBg/FeLbNUmG9yrU=;4:hX3ftU/qJJLDmbVwfe2A5NdWXu9v23cTy8bHAtz13LquTGrwaId7pNIUz/Ab8Vc8IEBzHgf7jzd3oCaqLB3aobY8n7RkeiDEEh5wmAPSSc9Xsbu9uozQA4oK5qh78BQasaE9eE8BKoIKuh9naNZp/xC9IR1fjPrUzYSJ2oAlkdGWUVOHxk482uok3hD4QiMI5YmTlL2FVOG4/IuEV7NW9envLr0BwU+0qY2g5DNZFu9nrw9F61uTkDoH44Q1t2MWkI+uD0ksi6PNHkeTnrkVcpW945A0nwRXjdBKylt71ZClxYU5SH25ppQw3KYjRV4w 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)(10201501046)(3002001)(3231221)(11241501184)(806099)(944501244)(52105095)(93006095)(93001095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DB5PR07MB1319;BCL:0;PCL:0;RULEID:;SRVR:DB5PR07MB1319; X-Forefront-PRVS: 0610D16BBE X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(39380400002)(366004)(39860400002)(396003)(346002)(376002)(189003)(199004)(16526019)(53936002)(2950100002)(52116002)(186003)(76176011)(2361001)(2351001)(47776003)(36756003)(86362001)(54906003)(81156014)(81166006)(8676002)(6916009)(7736002)(6666003)(6486002)(6512007)(97736004)(50226002)(2906002)(105586002)(16586007)(305945005)(48376002)(8936002)(4326008)(5660300001)(25786009)(26005)(59450400001)(106356001)(51416003)(386003)(6506007)(50466002)(478600001)(316002)(1076002)(66066001)(3846002)(68736007)(6116002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5PR07MB1319;H:ulegcpsvdell.emea.nsn-net.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A: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;DB5PR07MB1319;23:sCyIQacEGHJBvRKnj1HN4KFeMa48VQcBZJAh6FM0J?= =?us-ascii?Q?+O1NnJmxnJGO0hofO0mvLQ037QVB+RHeoilwi8YvEpP60SEBdYogFu73JELT?= =?us-ascii?Q?2eZlA8bITAblKODUU21LCAxR7Prmu7wae/u3mPqc/LDKrImMDOO6+Zq4GLIJ?= =?us-ascii?Q?yHy6703n/TyXmMlniG8YN2jGcRZlGpK5Xe0ZBlKZI9DkscYWYoepWOclOnmE?= =?us-ascii?Q?hFiRHijgO8SXYkzqdNkhsmx6zXeCuLb7uj3MICnbCOKyuU6UsqClm/naEhLh?= =?us-ascii?Q?yRXhftdxfVLP0QiudhCvSUo6SvRbX8n6u1uDwoOVFFI57iyT6gSa2RCHfQ6l?= =?us-ascii?Q?TrH1dFG0jL8FWFKlwGZxwPOPPQPyphwkZsFHHn6Is4lMIOJAnLUdIWYQgykP?= =?us-ascii?Q?fO507NJQgkEAs26qdGElPyplpjdPPpiKnxUXK/MYnxuchvh53w2ohZQ9USmA?= =?us-ascii?Q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DiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2018 13:53:34.9944 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2da8f2f-5efa-4ba3-2b43-08d588e9d0f9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR07MB1319 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 | 47 +++++++++++++++++++++++++++++--- 4 files changed, 100 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..0951270 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,18 +23,54 @@ (PLT_ENT_STRIDE - 8)) #endif +static const u32 fixed_plts[] = { +#ifdef CONFIG_FUNCTION_TRACER + FTRACE_ADDR, + MCOUNT_ADDR, +#ifdef CONFIG_OLD_MCOUNT + (unsigned long)ftrace_caller_old, + (unsigned long)mcount, +#endif +#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)) + return; + + for (i = 0; i < ARRAY_SIZE(plt->ldr); ++i) + plt->ldr[i] = PLT_ENT_LDR; + memcpy(plt->lit, fixed_plts, sizeof(fixed_plts)); + pltsec->plt_count = ARRAY_SIZE(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; - struct plt_entries *plt = (struct plt_entries *)pltsec->plt->sh_addr; - int idx = 0; + /* 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; + + if (!pltsec->plt_count) + prealloc_fixed(pltsec, plt); + + 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 @@ -182,8 +219,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 +275,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 +283,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