From patchwork Sun Mar 11 12:38:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10274731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 13B1460233 for ; Sun, 11 Mar 2018 12:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0157B28CFE for ; Sun, 11 Mar 2018 12:42:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E94AF28D18; Sun, 11 Mar 2018 12:42:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48D0028CFE for ; Sun, 11 Mar 2018 12:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hVdb9ENqZox6eb2LXjcN16mJkAQ8CzM2ZFnzliulCyw=; b=AIv1r9VvxwhmKBMrgFlCsKkLEJ mkql55gMTAXiLn6oJlkfwjf/bn4oVDc6BhX/tUWNkU7ZrqgJtDifUDScrShIGvUeLF7ukHHIvRdsL 6fqrawwNegjIDFu5Y+P3exxEVC+zodTKyjX6JEMROY5bLpoQPrOeyWV51mFlk+QnK1bxf38AS1KK/ lq1eBLADBS/9a0w/pDYBljiKWqZs99cOH0Q0ZlXWRo8JG5/uS7rBh/ZwfYz2DwmOAenHiUZEVDtBR xCNa5PUav5YaHvuhybEAh/taOVWq5I7vFcFnkYceWnzpwxSwotXr3XM1WZuyerq1RdV125kLGwOfV lMk4ZrFQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ev0JB-0005td-J6; Sun, 11 Mar 2018 12:42:37 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ev0GB-0002jy-6w for linux-arm-kernel@lists.infradead.org; Sun, 11 Mar 2018 12:39:42 +0000 Received: by mail-wm0-x241.google.com with SMTP id i3so11210639wmi.4 for ; Sun, 11 Mar 2018 05:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bbTSC6rTARnom9ckByI6VfHxqghKSu+vbbJy6E3JvOU=; b=P/fjsi0+pbLreU2S7U7w9l6MFak2naltGvAx9BZhwUVRh4mWBVqbAzyBYFDXd+b7nz E0QmVuMdTLMYDRG9M7X4+VCW0dm+dRx+fT+epfX+dc+kjyNqp3Ch3JXjkRCR/RgkHllU Ue20Y2byk0fEaT5T96/bqVq1344i14dMZo+wA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bbTSC6rTARnom9ckByI6VfHxqghKSu+vbbJy6E3JvOU=; b=Aj9jWQY/plxgUOjnVBzGYcHtxWbm7aY/extg+jtcJjTuQaYY5Cv6TsXJAQ8clfkMRi p5Ouf2s4Df4xAdS8QSQrjX4eaiDJll7B65aTl/vk+Q+sN6dxm9yqSWCxhNm13MSjsQHr rm135D8w+oYMBDQ7rB4pUojxj7xEqRni3t1DCSaOxOxBQEKYYnkr0ABLkpyMcEmRCKD+ se+OSyaMJJhT4dJ+osXH85WsEHfu98jLe1Yi430wA78Nibf1YtcQ4mr0zcIC/NB/k8+M NCFseicl6WdsO49N5b18Dkoq9jaNqnTExlxJjJXzqDtvaaMzqjUrihzP0XmvJKR53myB Ymng== X-Gm-Message-State: AElRT7HgX9Eu8K5jStN/HfwSQVlY+p58kHjHXnO9l/ewjJr8H5fzXvmP tcLYUfQ3uA8zayWYXAKLkJq9uS+ee3o= X-Google-Smtp-Source: AG47ELsJuAlc564Ycmr2Rz+4PpYa+2aQaCrrqmYHPkXeXXEQdXdHnhlLUCjMtC/BKtiRn/gpxo3urw== X-Received: by 10.28.158.205 with SMTP id h196mr2838678wme.25.1520771959268; Sun, 11 Mar 2018 05:39:19 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id h188sm2569103wmf.37.2018.03.11.05.39.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 05:39:18 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 6/6] kernel: tracepoints: add support for relative references Date: Sun, 11 Mar 2018 12:38:15 +0000 Message-Id: <20180311123815.17916-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180311123815.17916-1-ard.biesheuvel@linaro.org> References: <20180311123815.17916-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180311_053932_172605_BB8D1D00 X-CRM114-Status: GOOD ( 17.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Will Deacon , Paul Mackerras , Nicolas Pitre , Michael Ellerman , x86@kernel.org, Russell King , Ingo Molnar , Benjamin Herrenschmidt , "Serge E. Hallyn" , Petr Mladek , Kees Cook , Arnd Bergmann , Steven Rostedt , James Morris , Josh Poimboeuf , Bjorn Helgaas , Thomas Gleixner , Ard Biesheuvel , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , Linus Torvalds , Thomas Garnier MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP To avoid the need for relocating absolute references to tracepoint structures at boot time when running relocatable kernels (which may take a disproportionate amount of space), add the option to emit these tables as relative references instead. Cc: Ingo Molnar Acked-by: Steven Rostedt (VMware) Signed-off-by: Ard Biesheuvel --- include/linux/tracepoint.h | 19 ++++++-- kernel/tracepoint.c | 49 +++++++++++--------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index c94f466d57ef..cdb0a9461d71 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -225,6 +225,19 @@ extern void syscall_unregfunc(void); return static_key_false(&__tracepoint_##name.key); \ } +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS +#define __TRACEPOINT_ENTRY(name) \ + asm(" .section \"__tracepoints_ptrs\", \"a\" \n" \ + " .balign 4 \n" \ + " .long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \ + " .previous \n") +#else +#define __TRACEPOINT_ENTRY(name) \ + static struct tracepoint * const __tracepoint_ptr_##name __used \ + __attribute__((section("__tracepoints_ptrs"))) = \ + &__tracepoint_##name +#endif + /* * We have no guarantee that gcc and the linker won't up-align the tracepoint * structures, so we create an array of pointers that will be used for iteration @@ -234,11 +247,9 @@ extern void syscall_unregfunc(void); static const char __tpstrtab_##name[] \ __attribute__((section("__tracepoints_strings"))) = #name; \ struct tracepoint __tracepoint_##name \ - __attribute__((section("__tracepoints"))) = \ + __attribute__((section("__tracepoints"), used)) = \ { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\ - static struct tracepoint * const __tracepoint_ptr_##name __used \ - __attribute__((section("__tracepoints_ptrs"))) = \ - &__tracepoint_##name; + __TRACEPOINT_ENTRY(name); #define DEFINE_TRACE(name) \ DEFINE_TRACE_FN(name, NULL, NULL); diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 671b13457387..4ce8cc4bf2c3 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -326,6 +326,27 @@ int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data) } EXPORT_SYMBOL_GPL(tracepoint_probe_unregister); +static void for_each_tracepoint_range(struct tracepoint * const *begin, + struct tracepoint * const *end, + void (*fct)(struct tracepoint *tp, void *priv), + void *priv) +{ + if (!begin) + return; + + if (IS_ENABLED(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)) { + const int *iter; + + for (iter = (const int *)begin; iter < (const int *)end; iter++) + fct(offset_to_ptr(iter), priv); + } else { + struct tracepoint * const *iter; + + for (iter = begin; iter < end; iter++) + fct(*iter, priv); + } +} + #ifdef CONFIG_MODULES bool trace_module_has_bad_taint(struct module *mod) { @@ -390,15 +411,9 @@ EXPORT_SYMBOL_GPL(unregister_tracepoint_module_notifier); * Ensure the tracer unregistered the module's probes before the module * teardown is performed. Prevents leaks of probe and data pointers. */ -static void tp_module_going_check_quiescent(struct tracepoint * const *begin, - struct tracepoint * const *end) +static void tp_module_going_check_quiescent(struct tracepoint *tp, void *priv) { - struct tracepoint * const *iter; - - if (!begin) - return; - for (iter = begin; iter < end; iter++) - WARN_ON_ONCE((*iter)->funcs); + WARN_ON_ONCE(tp->funcs); } static int tracepoint_module_coming(struct module *mod) @@ -449,8 +464,9 @@ static void tracepoint_module_going(struct module *mod) * Called the going notifier before checking for * quiescence. */ - tp_module_going_check_quiescent(mod->tracepoints_ptrs, - mod->tracepoints_ptrs + mod->num_tracepoints); + for_each_tracepoint_range(mod->tracepoints_ptrs, + mod->tracepoints_ptrs + mod->num_tracepoints, + tp_module_going_check_quiescent, NULL); break; } } @@ -502,19 +518,6 @@ static __init int init_tracepoints(void) __initcall(init_tracepoints); #endif /* CONFIG_MODULES */ -static void for_each_tracepoint_range(struct tracepoint * const *begin, - struct tracepoint * const *end, - void (*fct)(struct tracepoint *tp, void *priv), - void *priv) -{ - struct tracepoint * const *iter; - - if (!begin) - return; - for (iter = begin; iter < end; iter++) - fct(*iter, priv); -} - /** * for_each_kernel_tracepoint - iteration on all kernel tracepoints * @fct: callback