Received: by 10.223.185.111 with SMTP id b44csp99799wrg; Fri, 9 Mar 2018 01:43:05 -0800 (PST) X-Google-Smtp-Source: AG47ELtkTtaWiTeej3muB7tH4oIMcrl9qFohwWvckZ9tmSLWoLbwPbkp+gwlxcd0CW4WQdHt64ZV X-Received: by 2002:a17:902:bd41:: with SMTP id b1-v6mr26861451plx.147.1520588585801; Fri, 09 Mar 2018 01:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520588585; cv=none; d=google.com; s=arc-20160816; b=yDz/pM+nbrvo4hbw/kRTgvD7Nok4njx6AuVUIud+CPc5frZl0bfW3FO8D+jWc5nxEn g4Fmzy56NNwxniiuqLYRaTZDSDiR0idFK7L4at5QS9uuVAjfm94/JSdXeLW24KsTKVyn 9NQTmDlPkMdo7IMuBsVcCOH78LEEJtZScYpwg8DKD2n27Hnj7rcRqd1EdcaMaw3pgQC3 OFPN0Dat56ytH1R5jnJPAgv624av5fJbF6hoGfHu17YjWHlC2ipK1FO8OpsV17pkO7DF +UTbCXcZVWXggTzvwyE8aAzrXme98ORnTvklvV3qu94/PjdT8PBMXKvbLKQ2OhzfCaSg wIRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=hzmI06qIP/68q7tOp6PAMSwGJs4X4vUGt66d2UwqMHA=; b=TF8TP4iUnysl5Ybnbco6qdn1/6wOuIT9UpEHFrU/krDclyIr7y1mTtQIp1wEmhofIE WjM9sJJS5yJT4UBZC9Fp96YuEgSX1a2m2r9FXh4dzTud3Yip44PqrCmh9TFMlykPZ+nG c830/Czn8x/eD32l0kxZw2nd+xMhC2uCtgjlP3UM3HzFqekf2QWWRo07hqjlakjiwcOh ygd1if+/hcNdSZ/eCmrn8wDKXw7ti9azqN/dICSEVKbfUTcVT5ekrIqvV4dZyHzcgo5z Iu59FKYDggwMEdZsuKgKX54l97IrFa/78YGKJjLRu66xTAWMbg7Mr/iVTJ7g+QdyGNtd Tcyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZsBIMSEi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si493888pgn.157.2018.03.09.01.42.51; Fri, 09 Mar 2018 01:43:05 -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=@linaro.org header.s=google header.b=ZsBIMSEi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751086AbeCIJl6 (ORCPT + 99 others); Fri, 9 Mar 2018 04:41:58 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:32889 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750909AbeCIJlx (ORCPT ); Fri, 9 Mar 2018 04:41:53 -0500 Received: by mail-it0-f67.google.com with SMTP id w19-v6so2180540ite.0 for ; Fri, 09 Mar 2018 01:41:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hzmI06qIP/68q7tOp6PAMSwGJs4X4vUGt66d2UwqMHA=; b=ZsBIMSEijyqIQNFrqcRiDc1RO0SMDNdJcDwAa/JlpXXX5jVuqsBP0nAEZora/7OAso DrGZoVu1hN6gddHPfOfwZiPRUAry20q++5tHgoaOQmiK99Ql/1Dq2TBJYRwRnKl5CCK4 vPJ2zR5WjImquAtcDJZv9wAlZXS5gi6mbNiwg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hzmI06qIP/68q7tOp6PAMSwGJs4X4vUGt66d2UwqMHA=; b=JSULsIxyX/42M7Y0LmjjYAY04vulBOaTpPNGbUyogzNTAb3l0JuJS1z2a1trovJgN3 dIdWvkCx3fFw2/Rj/0kuEEeiOkYHb4CiIkC48SImQSYe4ks1Ts0gdOoYrP9uUIbe0ZE/ HIP0U8/oYTGS6Bc29tvtk8nvJ0zjyPtV5+O2rvwnyTbTR8V0FXSFUXaqAAmgXiIqPZZO /Deppxy0fYAqhsve5h6k8udoGhOFGvl2Q2+8c+NBu6xJxhPNDzyuO31CnvJnGy1MWZNp y9DBRT3j/DnI9BlPMFmQlkTRg8KCBWElEfpNd7kxv53ClwXdAY1fyooZrtKxeGSn/DjU QR5A== X-Gm-Message-State: AElRT7G8GaVcLdzgH5Gqpw3y2MJIRSIJQgwOPyNgkU/nY+IZn0mETGCd gL5+eUlbr9rB7HjVaeFKeZh+GnMukZ98tNTo2doYXg== X-Received: by 2002:a24:d916:: with SMTP id p22-v6mr2613978itg.106.1520588513246; Fri, 09 Mar 2018 01:41:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.138.209 with HTTP; Fri, 9 Mar 2018 01:41:52 -0800 (PST) In-Reply-To: <93864477-75bb-3f73-1d06-03d128b04f94@nokia.com> References: <20180309084151.2379-1-alexander.sverdlin@nokia.com> <20180309084151.2379-3-alexander.sverdlin@nokia.com> <93864477-75bb-3f73-1d06-03d128b04f94@nokia.com> From: Ard Biesheuvel Date: Fri, 9 Mar 2018 09:41:52 +0000 Message-ID: Subject: Re: [PATCH v3 2/2] ARM: ftrace: Add MODULE_PLTS support To: Alexander Sverdlin Cc: linux-arm-kernel , Ingo Molnar , Linux Kernel Mailing List , Steven Rostedt , Russell King Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9 March 2018 at 08:54, Alexander Sverdlin wrote: > Hello Ard! > > On 09/03/18 09:50, Ard Biesheuvel wrote: >>> +static u32 fixed_plts[] = { >>> + FTRACE_ADDR, >>> + MCOUNT_ADDR, >>> +#ifdef CONFIG_OLD_MCOUNT >>> + (unsigned long)ftrace_caller_old, >>> + (unsigned long)mcount, >>> +#endif >>> +}; >>> + >> Do we need this stuff in the PLT loader if ftrace is disabled? > > You are right, it probably would not even build w/o FTRACE. > I'll fix it, thanks for looking into this! > Also, perhaps you can make the array const (after you put #ifdef's around all entries) >>> 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]; >>> ... and put all this handling in a helper function that only gets called if ARRAY_SIZE() > 0 AFAICT, that should allow you to leave the rest unchanged.