Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5725746imm; Tue, 26 Jun 2018 17:07:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJQcnZm/FuQn/xWhItEync+eRUD2WF1RONrpBV5Ab7xh+ZD598sd0i3RdYAMpGfqlYlp/WH X-Received: by 2002:a65:61aa:: with SMTP id i10-v6mr3121500pgv.139.1530058078235; Tue, 26 Jun 2018 17:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530058078; cv=none; d=google.com; s=arc-20160816; b=F5FeIAxNNaIXca+11McBxwEO7TMsWZf5d3kwdqvdOQ0772xLKuIzyWxt+nUHhrzbbL uFoOmxnMpRir4J9DohbjifNYIvrCkJ397VfQ25Lf+68FU86XD0GH/CU/z/8aBWvgqCW6 Wy8PHRAo8cf4r9rUbUNCr5275pa1I6nTj4YE5yj57GurL5fLxz1jgBX3CxlPdvp3g1RN LYBEPrlui6PeW58oIKp6wDQW+DHar/0dUPjxAdLqE2KBCMO10t3OqBLVw0/UkFGe0bah yq4/9ap397b9+WycKp/cFgKpHKa9mYKwBHBP6+xcFnHc+/b1CN8GK2mNWIlJilTJ3PMJ ujcw== 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=6EXfacxtBs2hWqAKIliQJWWXNn3sfRJsVjsG6USvlLk=; b=TnU6lnORGLAgXXDHlXNJ3Wm5pWWoU5AqT+nZoJ5zyVbpFEXtdMi3sATHSb/vF1CQ/L KzWOGPb4bgOc+wdvcZDmooX8qWtnjF71Gi1Y4NiQErd7EzLig+u+p6/99/1OlP/OCssG Ka14Kuwx2Y4OPK0BgQxHyJi0hN1cjyErxBlxSxiDJkEL9EI+b8SyNCTuiE7UJ5txeNWD RGg3Y4MZiLokis4PkipuRAIV87afLBmCKDmRderGCvU4lNvzWKuuuAdbEtBgvA66jezw VVcYwEVZTTo+Dk5QoIoxTQtvSQCg61smUwXKeVyjKtMruSYE8FFAASODT8HMxIOJ590N +zlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bQrVGqib; 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 a5-v6si2293539pgq.669.2018.06.26.17.07.42; Tue, 26 Jun 2018 17:07:58 -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=bQrVGqib; 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 S1754314AbeFZS26 (ORCPT + 99 others); Tue, 26 Jun 2018 14:28:58 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:41103 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753931AbeFZS2w (ORCPT ); Tue, 26 Jun 2018 14:28:52 -0400 Received: by mail-wr0-f195.google.com with SMTP id h10-v6so18200320wrq.8 for ; Tue, 26 Jun 2018 11:28:52 -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=6EXfacxtBs2hWqAKIliQJWWXNn3sfRJsVjsG6USvlLk=; b=bQrVGqibSpzm0lqYZfOm5M3p2Ku6H+gTjwAeyMNzYNZM2wBegZD3H2nSkXaYFw3GzF RALNyXp+ukRiRhRzRiQ7UULLBWgsF352CMLsqolMnKbhtIO8zu0YOG250DacHndwhwof Wk4yk38W3fkpJN+GqJixfAxrbDiIKD8xFX9w8= 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=6EXfacxtBs2hWqAKIliQJWWXNn3sfRJsVjsG6USvlLk=; b=bcyyvdiyJ0S91lCrI6JO2Ta17/UhgChvyLto5On6ZFa/z4fEx2jZ7f0vhqXokXTaQB gOmuCbZxDf17hdKzPmloguvHBsZ2AxX/0QfuwstffxtEbfCJM0pdoR3+J+3JJX0bcwvX rmfnWXmNBgmCy5xggNDFp+iDuAupsqwFH+JXFjZncvwjgkwe5a5vgopCqG78V9+84x47 kVOQEVwuuQP7FZ57pdsciEpX2neh4Q5LZRSZXK8dbMG5LRlgEDw2CySG/mHDX/TNfFnm faZXJl8oPraJQauai9VwSFwIgi6RMPxAw0R7TBbokOqjRFCY12hIZtkAqxkzedJNJysp VxAQ== X-Gm-Message-State: APt69E3tBACKl/Q3e2SRmL9pDMT6EZ3E03+/qi8NXnLAmt6I4/O89jSJ 7yVCAtJk0q6Ro2V9f4QyC4AHlXh48eE= X-Received: by 2002:adf:fb43:: with SMTP id c3-v6mr2534500wrs.32.1530037731293; Tue, 26 Jun 2018 11:28:51 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:d037:e907:f0a2:a5ea]) by smtp.gmail.com with ESMTPSA id s17-v6sm1707664wmc.34.2018.06.26.11.28.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 11:28:50 -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 v9 6/6] kernel: tracepoints: add support for relative references Date: Tue, 26 Jun 2018 20:28:01 +0200 Message-Id: <20180626182802.19932-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180626182802.19932-1-ard.biesheuvel@linaro.org> References: <20180626182802.19932-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. 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 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 -- 2.11.0