From patchwork Wed Jul 4 08:36:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141022 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp543236ljj; Wed, 4 Jul 2018 01:41:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcmgZgbibcgjMvMsaTR9aPHq2GbmT1a679mveZtyLF6xMPtEfwBN0ukIIlGY1Bfh+JHXixY X-Received: by 2002:a65:58c8:: with SMTP id e8-v6mr1069585pgu.96.1530693674151; Wed, 04 Jul 2018 01:41:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530693674; cv=none; d=google.com; s=arc-20160816; b=TlpsT8d1As8pVz8qMwBkE4mNtKAru0u/A9RA4x9688W/kAD6z6BzsjknRwv6SfK7IA z6K4uQqYZvWyLxXNNGu0cLIPs33gIP7H533kF4ysRJc5uG6edvWoAp2bsztUiBRFQGPu NdnFTHbbmDV25QGczc1I2V4/HAjC0yWad8QBLfoTqNm6/hYOq5KX2P6EP62Pp+bZrMlV p2FxvLtV6Arozj+B6DyNb7bdh02PhGg2kEjaEbJY3xZMPsHku5iXTs+/xg57RiCuVw5D HFXLwCJMiCr/++mPkEwCI/cAH4gPlP6SW9ss3CZ4o7ZeyElJyuxRP7YU/kOmYdYdnYSY 6GEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=sNQ200Dbn8i5rABOHA2COrJbJeN/1Dd7TOxo9J6iksY=; b=VzUG0QW55aFRHR2anl413w4VB+8qIJgQm2a8i6ezQv3OmxEQYgFnWCBBdQHya0WNNV JEpTQjLJlw63yR4j4qhwk9g98xnz18MKnwqKYyJm6dtqHcmz80ID0gLw9ZdnH0SxCM/T QQ/XOR7tSLxDYkqMmxqxz9/bGY0c7gCcTy2xt1r6Xl4DWR/hu7gbu9O6MRcimbfMv4ua o7ypRxp7KMecNzDIfnOTftV+BYHY1WsKXXxDLmVGC2rTnSApK/Pxs0FlQqef9fZi9lwR /aB9iGvRR9EFMBCcbOTSXNj45AKn3p3YfwHImHo6CTx5GovGE5mUxXROJ/Lvi7j8i5Ug WL9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=egozONIv; 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 g92-v6si3135469plg.0.2018.07.04.01.41.13; Wed, 04 Jul 2018 01:41:14 -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=egozONIv; 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 S934066AbeGDIlK (ORCPT + 31 others); Wed, 4 Jul 2018 04:41:10 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:36457 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933741AbeGDIi5 (ORCPT ); Wed, 4 Jul 2018 04:38:57 -0400 Received: by mail-ed1-f65.google.com with SMTP id t3-v6so3468270eds.3 for ; Wed, 04 Jul 2018 01:38:56 -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=sNQ200Dbn8i5rABOHA2COrJbJeN/1Dd7TOxo9J6iksY=; b=egozONIvLTNRF14bkHiz1LxWn3ZE/RmJ9/KQP6mYSoT+Ck+jy5MGj1XCYoSQL34Yuz rD+btanjtPcwVK+bbMJRJvZpW1gFOruSWbwSuvLqcF8PnQ5dpsyYhO5mGNA7NSxuVjk6 iZXERhQaBbe3acJH1sm1UlXrI4aOg9dEpF7DM= 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=sNQ200Dbn8i5rABOHA2COrJbJeN/1Dd7TOxo9J6iksY=; b=kCME4ClF5x+IdUylL6BhOnQCmKWiDOqp90ruwWIfEozEpDw5eGwt0/W9FHFyCyqym2 3jepYPZsbb5k8qLJp7S8nXhyO7TqZmnwNUtRCNbMX2g+Ak3mK0qbd+W5fe+s3q3wHXlH ZckZpe8y75iL4jSj97SqpSQ9ewzCX3nCWDo76sLGk+gFhrRmM5MPMxbGqNAtyhUh0+Jn sBOV76jS05CAsKutCu/HILSSmewVM4MmJXUYoF7yZdpEq8ym1D3gYW521PLPh2qt2c8t zDFbg/ylE7+WFOWdGcW6tG8myoEKXK7yyh9U+pUHCqGkD/zT1lPPuvuhZIB09ceOOmmp 7Kxg== X-Gm-Message-State: APt69E0u9xP2qPg0P6Ts0zgkZOoQ2fykLem2ZevYoICKkyOqxXwan9Wk 9QtQMbYJADMTL7Dm/35dks8+19tHD8U= X-Received: by 2002:a50:da01:: with SMTP id z1-v6mr1734704edj.62.1530693535996; Wed, 04 Jul 2018 01:38:55 -0700 (PDT) Received: from ards-mac-mini.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id k13-v6sm1821740edj.55.2018.07.04.01.38.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 01:38:55 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v10 6/6] kernel: tracepoints: add support for relative references Date: Wed, 4 Jul 2018 10:36:51 +0200 Message-Id: <20180704083651.24360-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704083651.24360-1-ard.biesheuvel@linaro.org> References: <20180704083651.24360-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Acked-by: Michael Ellerman Acked-by: 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(-) -- 2.17.1 diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 19a690b559ca..b130e40d82cb 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 __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 6dc6356c3327..451c8f5e8345 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -325,6 +325,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) { @@ -389,15 +410,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) @@ -448,8 +463,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; } } @@ -501,19 +517,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