From patchwork Tue Jan 2 20:05:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 123218 Delivered-To: patch@linaro.org Received: by 10.80.135.92 with SMTP id 28csp4761342edv; Tue, 2 Jan 2018 12:06:55 -0800 (PST) X-Google-Smtp-Source: ACJfBosZdD2I9W1RHOFbz2QB3qL1tuN7J6BQgXMkovQUnm3pzsjBHEYAoCVBDZLgjEdh1Oye4pav X-Received: by 10.98.152.147 with SMTP id d19mr45668237pfk.95.1514923615194; Tue, 02 Jan 2018 12:06:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514923615; cv=none; d=google.com; s=arc-20160816; b=Gw0zbwLbo/GhOxn4/3P4JdVT4RRQRnlWyRfBkDhOV/e6BNYGV9ruh6sr5QblqcqKl8 2bG4zKJ6j+t4ArzYQ0pMo7DXg+AOC5AImM0M27KMmqlD2uVJogyh9G782VZnkhtwx8V4 yTQ2TQVsTY1Qw2mZzpkI7S+qW+lRXe/Ftj77EWLKEfdsfuHD+V1BQARwIvj/aHXX1gUt MK0+mmwlRlq2GR8/OOAJovMttJwxx8jiEFI+JfxjEhiUJ8ZglrOi20gp3f98zmxPR0vh CW6wfyrpj7KvFkyH5RXC29SWHLJsPYy1sHRJnUZQsLHlcJyNZvK8rZZrMra24e4MbqpR nUgA== 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=wKZwhkbHcAnKwdhVFtFBF5H65qthlsMyQbywDqRcj68=; b=fc/Tv34DxQ/NQpUiLYkG7NrTqkBi1aPMLADxMOsGgJEN05663nOj+KBIGO3M3yvma6 cAPnweB/7HdVqbTmgj1+WVXy5Fgs5vJfc1GxisoW2Vr6//FYNolX6VYEpAAX7RbCYva7 YS/+7TYu3C6s9znGXskw/vkFoK/f+uWZAgchb/PXY2Y9UHSSODzTY8XQZAkg7IcADg66 af4N1T/h+XapfGSGP/ITxs0s7oWphENfMHhx4Gb0ySOA7q2qN1ydcorBWsIQ6+VEVxSR n1HMDjQsKpNzH24Xwhn/jSXduB0JhqNF6dvgbfypMommi1aoDmnNLLPHNT/3/13U7g5k KaMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OTP3P2Q0; 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 e61si7515995plb.524.2018.01.02.12.06.54; Tue, 02 Jan 2018 12:06:55 -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=OTP3P2Q0; 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 S1751190AbeABUGx (ORCPT + 28 others); Tue, 2 Jan 2018 15:06:53 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37942 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751008AbeABUGt (ORCPT ); Tue, 2 Jan 2018 15:06:49 -0500 Received: by mail-wr0-f196.google.com with SMTP id y9so7456929wrb.5 for ; Tue, 02 Jan 2018 12:06:48 -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=wKZwhkbHcAnKwdhVFtFBF5H65qthlsMyQbywDqRcj68=; b=OTP3P2Q0+30/oFxHDyVu3M4GplpoAAATn7kHNcGIe9IokkX7drMcUm7be/KmZtGjZD WsazG+awbUfxpOYDUSYbOhoZlElVtzJpO670EGPlB/IE9QlNm18N9TnV/I2WtyXjIXNO mkB3y33bzP1G9PF+9/zy9mGfxkST/iRm29Obo= 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=wKZwhkbHcAnKwdhVFtFBF5H65qthlsMyQbywDqRcj68=; b=RH/6LY/6serXwC3OGEnur3oyLLZtzmu/7J/4k+VKn/FL+i2Wa3wSZIgV7NfnWgN3BB +VApvmklVIJAqAaYJTY64chyY3pOBifZX98ImZ+11+CDE554rm4zEsCBUqG+0hI/WbZt VStHKcZY0p5MwDm+7RdCP33QsQabEP8UcjxdvMqq4673UQve0rARv2VpXIcq/gbKqdnZ JDvLkunGUgFiPAvfvaotRbyvQL3J7UFLEybsJygrRbjP/hVXtQq0X5yAfvEcBD6Er8OH vjwIbH/9EM4fl+AFj6Y0iSzJ9APCiQrLaLbw1eGIrH+2PPiONT1l7qU3jjkB3RQmGv5d GqxQ== X-Gm-Message-State: AKGB3mIMy6+8BXEvXcdF5ZrZqEUaE4/O6654prxiGnQ2eQD2BxRA45mT +Nlgq4oznaaE+C66owVvIHQLfgJN4AQ= X-Received: by 10.223.138.195 with SMTP id z3mr46075191wrz.152.1514923607843; Tue, 02 Jan 2018 12:06:47 -0800 (PST) Received: from localhost.localdomain ([160.89.138.198]) by smtp.gmail.com with ESMTPSA id m70sm19128526wma.36.2018.01.02.12.06.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 12:06:47 -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 v7 06/10] kernel: tracepoints: add support for relative references Date: Tue, 2 Jan 2018 20:05:45 +0000 Message-Id: <20180102200549.22984-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180102200549.22984-1-ard.biesheuvel@linaro.org> References: <20180102200549.22984-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 | 50 +++++++++++--------- 2 files changed, 42 insertions(+), 27 deletions(-) -- 2.11.0 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