Received: by 10.213.65.68 with SMTP id h4csp490483imn; Tue, 13 Mar 2018 10:41:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELtR9HllIBecCu6a76HCqFJovdNR8AmE63QDdATyEx/9bymLcs/j1MT34/2aZ45jT97eVBOm X-Received: by 10.101.66.196 with SMTP id l4mr1159768pgp.66.1520962901593; Tue, 13 Mar 2018 10:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520962901; cv=none; d=google.com; s=arc-20160816; b=a3odWls7c/x8CJUeWyhxpixhk3vlzJtvudKNJs5IHyoNwpP4u5n+8rffaSknfsUwj3 QT+zrHGYkM6zqY+QHUbDeSqOKLwfjp7wmwy7G3qRnARTpNAmQbqyXOOKPipm39Xw3ksY SCT3rLlm+5HaY2ou2IgAFOY+qIOHxZT3K4U20hZVqwgCGzl3RH3DpI1CmfcjaZYJRdHL xmRKM7b4/oZUmKIM0JUxeO296ArmLyjCG7pLuG7jI45TVwFM82dx/3VQUD4uoh+IBic0 agISD6ewcK5in6Cex9s26TSBgYkY5bLKWhiOcXS6FDhvsU8Lxn4W39kTzd3YyqNFEkuz n2KQ== 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=usfL4KsMr842/uFkwngXmmjiDOJLY0m7NJe3x+etdbE=; b=oplQBsviuYa53cFSZyQHgTbbGatr7U0Sd31o8/QlJ4GqPu/p+S5es5kdqeaWrl5ZAS AIyyJ4KWLvey+T1oSu6cOdy9Jj8rDXLo55Mwt3ex52exfyPhuKg/yCV6/AYH5s3009H/ rrJGMwEADWxinPxF1cgEV+7rvdUKWW2LApa+dU+nn1X/WIL5yYAdi+9Vshu8jb3dz3E7 cQjDp7d0JE4MJ4lSFuz4v300JGtc5I/zNw0fhcausFliM8XxQWFxW66rp2okl/DsDi8a cr1tpKIqXF2Eh3MRnlXLIqaW13AKqRSrVf9gjFoNqD4M5YdJo06TZ+jCrOSiuNX4J2A/ p4/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ft1mT1qn; 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 68si480492pfl.312.2018.03.13.10.41.26; Tue, 13 Mar 2018 10:41:41 -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=@linaro.org header.s=google header.b=Ft1mT1qn; 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 S932409AbeCMRkC (ORCPT + 99 others); Tue, 13 Mar 2018 13:40:02 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:43892 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932326AbeCMRkA (ORCPT ); Tue, 13 Mar 2018 13:40:00 -0400 Received: by mail-io0-f194.google.com with SMTP id l12so1056191ioc.10 for ; Tue, 13 Mar 2018 10:40:00 -0700 (PDT) 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=usfL4KsMr842/uFkwngXmmjiDOJLY0m7NJe3x+etdbE=; b=Ft1mT1qnUXIru2vgwvd+bcE37KB1ewEalrUdnv32EpZaj2DQDQVE0SvN9imKfRmuid /B2N3fpn/7eI/gjZR5W0UGoDBEXZTjnNak868EZG4gJScocoD1SlfUFYbrrEOJJMSHGb w5QEzOvWdG4UUmulAUukr+l+hMtm24iKqKbI8= 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=usfL4KsMr842/uFkwngXmmjiDOJLY0m7NJe3x+etdbE=; b=Nnd9kCdsZZLCfoSJ/yjUZCPvkXdS7GxiVICrnSAPPrmL3e/563hTV1xbazBIqbmjl4 MYLvXYQFc+tzPUiX31s8M7qoDoF7Y/33ny1SvJ5AzadI9u05kzhFsFXO20gPMilNv1C6 mp6Ul7DCA9KzcJdE8l0rEEbWAmcLWw4n0/ilXGnoC+rssbo7+GMZw++lzP3lp69+A8UJ fAhR2mgbZhRjgWB8MMPgC6hggsa86RwyQz3KG90Kztfx8dCW43yiDq9frj2iRB8UB8aM suPMq8sOgGo5wjpm3elBpflv3z6WVN4oo6zxcR+aAw2HZOHdRk/tBw1t2uPkJzspXpNI V0rw== X-Gm-Message-State: AElRT7FG7P7I/TLvxZcQtN8Ox81qzuPODk/3zb2scjXVBiEEZNVCsXWP 3oLZJmsuN4WcPrgIldJx18wsS7scdjrKtmnYIeFx1HiP X-Received: by 10.107.151.74 with SMTP id z71mr1554313iod.277.1520962800076; Tue, 13 Mar 2018 10:40:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.138.209 with HTTP; Tue, 13 Mar 2018 10:39:59 -0700 (PDT) In-Reply-To: <60156300-b74a-628c-d296-7fb71a0eeb4f@nokia.com> References: <20180313135314.18780-1-alexander.sverdlin@nokia.com> <20180313135314.18780-3-alexander.sverdlin@nokia.com> <5d3ae760-45bd-3588-500f-1b352e1722de@nokia.com> <60156300-b74a-628c-d296-7fb71a0eeb4f@nokia.com> From: Ard Biesheuvel Date: Tue, 13 Mar 2018 17:39:59 +0000 Message-ID: Subject: Re: [PATCH v4 2/2] ARM: ftrace: Add MODULE_PLTS support To: Alexander Sverdlin Cc: linux-arm-kernel , Linux Kernel Mailing List , Russell King , Steven Rostedt , Ingo Molnar 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 13 March 2018 at 17:32, Alexander Sverdlin wrote: > Hi Ard! > > On 13/03/18 18:18, Ard Biesheuvel wrote: >>>>> 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; >>>>> + >>>> Where is plt_ent ever used? >>> Above is exactly the place it's used. >>> I need to cache it because after the module load is finished the ELF header is freed, >>> pltsec->plt pointer (*) is not valid any more. >>> With the above modification it's possible to call the function during the whole life >>> time of the module. >>> >> Right, ok. That's a problem. >> >> This means that you are relying on get_module_plt() being called at >> least once at module load time, which is not guaranteed. > > This is indeed guaranteed. For FTRACE use case. If it's being called from FTRACE in > run time, this would mean there were long calls in this module section, which in > turn means, get_module_plt() was called at least once for this module and this > section. > > This doesn't hold in general, though. > > In any case, if you insist, I can try to rework the whole stuff implementing module_finalize(). > I think it would be much better to use the module_finalize() hook for this, given that it is only called once already, and all the data you need is still available. Note that ARM already has such a function, so you'll need to add a call there, i.e., if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS)) module_plt_alloc_fixed(); or something like that. The CONFIG_FTRACE dependency can be kept local to module-plts.c