From patchwork Wed Dec 27 08:50:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 122762 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1920073qgn; Wed, 27 Dec 2017 00:51:27 -0800 (PST) X-Google-Smtp-Source: ACJfBoursDmquIESOi3dL/9tKNUzTv03GhbnxpYpi67wMLiwuHZshy7DkRjNyaUyfBCUsQguuToG X-Received: by 10.159.252.76 with SMTP id t12mr28212132plz.323.1514364687669; Wed, 27 Dec 2017 00:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514364687; cv=none; d=google.com; s=arc-20160816; b=o5lgoeq3x4cdQgIB+gwL49ZoXSp3BbGhEPLVAXJdj4JF2X6TuKoSZ417rzqm7mkebu u/lBmSXQZv8nyK5wfZ83m6Pjjen/ULp0dTvFLqB3E3BJ81sW/DFvvHdKCcQqrdvlE4QP mQB/KNdNFA53pzigX68cWEtEgLkG0YBWHshE81MMpiBXtTngZr2ZE4y1VLRr/EXvh6CJ pM7kKpdnoEyfRZHExBswKWsIql7x/337PBO+9lEaQ+GpFuziBEnEf/gUHfbt5osvtQu1 Fx5r9+b+cVGe+yYrRAflbYsU40i/KZLKwaPjeS5Xow0mFhB+Hv90W8QlZH8TGg/5bks0 rf8Q== 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=FeRUkMrB+h9OzAG6tsXZHgHhFJKOYm9CVFNsKuS7D+M=; b=ZpznLs7k8/BzabqeMpphuM5CBXqPszo7bH5AOEJeIa8V24R4JHUFzIuC0K/sRdStRQ Ky0VG7GnpjxGn7MvajsASmebmeOjGAwueGodWoa2LgI0Yu+SGeZjM5kPY1+TAXp7NuNE A8BfaMywQzK3D6/N916cXT4R8wameNAMiXlSz76TnYUBWe6/Sgt6qr5TkvRZLw6ubcv1 D0UtDJ+EwSHD0mzWSKAb6faJdGCZgAjhxAWYgxG3kU8ZBZd+GwzaVbo/PoZCFyJODYpP DeHbRJjJYtGWX1ul/L5jO7UTac6qNTkOfjkB2xZISFXF7JkZRCtRpP6Stp4VczF2uhNU ZRPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C0bXnKbk; 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 a17si16507541pgf.378.2017.12.27.00.51.27; Wed, 27 Dec 2017 00:51:27 -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=C0bXnKbk; 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 S1751911AbdL0IvW (ORCPT + 28 others); Wed, 27 Dec 2017 03:51:22 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46375 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751891AbdL0IvS (ORCPT ); Wed, 27 Dec 2017 03:51:18 -0500 Received: by mail-wr0-f193.google.com with SMTP id g17so26988237wrd.13 for ; Wed, 27 Dec 2017 00:51:17 -0800 (PST) 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=FeRUkMrB+h9OzAG6tsXZHgHhFJKOYm9CVFNsKuS7D+M=; b=C0bXnKbkb3eJ2wpcGYBYzKmS7OKKVzqXvhGL+TE/Uy7dsuLNclfxKdtFgpHGQgKloY Zs4iWMSBuMsqiYFGCw7m1R4DbRiqKG1NW7f82TFyG7d1QwH3ewhZOSt0KdSM89TLjK2S iuQ8d9gZaTRU5K3xKVmzRGBFzahnqD72bpvu0= 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=FeRUkMrB+h9OzAG6tsXZHgHhFJKOYm9CVFNsKuS7D+M=; b=T4M/W0OfA6o1sG8TYXRom9DC9xnb16VjbGeA7Ia/86bicZ9p8z0feIYYK0gIBLOR6A 9CbXgLAKkvCvJKTi6LOvo0qx/vLlPx2bdZibhCdeZxy1XGdHFRBif7RcdJmTErqbN763 XHnZsCiYhzTEQjoXRcPjKRl9AyC0MC0br+wDuf3o6L+sqJMplMTDSzFYbe90qd6nk4+j OCNbwFn3ftfsfLrS5GTpNHZoI51huEza7pUgYEWaN4nXurteVHfifhLaWljHKqdNCKg5 +yarxF6zIEGvC0eT2emMNdRp6r27xyGdXOxJ0szepHjZ0HGEKBYStTLSfKd3kHLtpucJ NeMw== X-Gm-Message-State: AKGB3mLFLvMcrzBBdR9AmTK6QRmACau2PdZOPOwB5sGW/0jvT6hKipOZ W+q+GwQQebmMjB0TB5zhmVUAH2i2sYg= X-Received: by 10.223.136.118 with SMTP id e51mr28244488wre.21.1514364676546; Wed, 27 Dec 2017 00:51:16 -0800 (PST) Received: from localhost.localdomain ([105.137.110.132]) by smtp.gmail.com with ESMTPSA id q74sm32677226wmg.22.2017.12.27.00.51.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2017 00:51:15 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Ralf Baechle , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , "David S. Miller" , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v6 5/8] kernel: tracepoints: add support for relative references Date: Wed, 27 Dec 2017 08:50:30 +0000 Message-Id: <20171227085033.22389-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171227085033.22389-1-ard.biesheuvel@linaro.org> References: <20171227085033.22389-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: Steven Rostedt Cc: Ingo Molnar Signed-off-by: Ard Biesheuvel --- include/linux/tracepoint.h | 19 ++++++-- kernel/tracepoint.c | 50 +++++++++++--------- 2 files changed, 42 insertions(+), 27 deletions(-) -- 2.11.0 Acked-by: Steven Rostedt (VMware) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index a26ffbe09e71..d02bf1a695e8 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -228,6 +228,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 @@ -237,11 +250,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 685c50ae6300..05649fef106c 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -327,6 +327,28 @@ 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((struct tracepoint *)((unsigned long)iter + *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) { @@ -391,15 +413,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) @@ -450,8 +466,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; } } @@ -503,19 +520,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