From patchwork Sat Aug 19 18:10:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110459 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2383880qge; Sat, 19 Aug 2017 11:11:26 -0700 (PDT) X-Received: by 10.99.182.67 with SMTP id v3mr12124885pgt.228.1503166286571; Sat, 19 Aug 2017 11:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503166286; cv=none; d=google.com; s=arc-20160816; b=fSlMS++5fH5WYOYiwnrhcJLf/Qo20FvFibYYOeba5UV69sFa07amqnaMZURTAyEQyu bLfHHaQ/rRt/Y6UOm+v/q2v40ngHttK1iiwsoRktvGJ0+FXDorAApmGtatqsmn0YrjLu 39MON2oiNQxfIbfhmFsxNk/2Ws6UkjqA4i3WZXSUpLC2RjD7Bk/GQ/IYQYtMUXdGvj5u ObhlamLVnVfzbq1iFbPOgo0LWGUK0MqgXm+iM+yLmF4zLJ2hhLlZidKE5Xrbsu3UxxoQ VjRu1BgjOHg/aDQQKQnYcvVmXy8EUru8k0Z/60uo3QcKT67lba1OEkcQOtD6IjTwfako ezLQ== 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=T0eIFkvXTGn2bVADgTPYmcybECRT8dELGRo+5YN0FJ4=; b=kaXx5/hy8CTi5DhtW8biwB43iSup8LdA+AtwYFkxrlwdILcywcKrEKHtXboTKhs5Uj hQfziuINs1JqV72s2qQiCBbbisra/DIPtm3JyAtLKxTeFpjWHVovTGeVf0g6J9aV5Qj4 jyuInwhJqCWxe5cSrooRJDskXr8epK1vHHiPvg0z1SJRVZCzCAgs6IMr8wHwSGVG8TZR Vb0+KyK3IRE7kv+NcVoa3Uwxi1bZq30rqrtK8B+TxmX9wBc5Dr6HqlFUcXdM9JRQrcgi SAm4c9ylCjMLnqClROvANmrK57CsxUg9U46DZ1ahvojGUloB458LR/tERT15FnYcmuOJ 1SOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sp2cp7EW; 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 v13si5161206pgf.643.2017.08.19.11.11.26; Sat, 19 Aug 2017 11:11:26 -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=Sp2cp7EW; 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 S1752394AbdHSSLY (ORCPT + 26 others); Sat, 19 Aug 2017 14:11:24 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:37099 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752349AbdHSSLU (ORCPT ); Sat, 19 Aug 2017 14:11:20 -0400 Received: by mail-wm0-f44.google.com with SMTP id i66so20962949wmg.0 for ; Sat, 19 Aug 2017 11:11:19 -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=T0eIFkvXTGn2bVADgTPYmcybECRT8dELGRo+5YN0FJ4=; b=Sp2cp7EWzZVVnXBAEnX/MPNZC36CajsgsXPGF9Ehn9gQy4WWMGbCorFF2WIsxFEsQa 6Byg8aoUstNuEySFiwmrniUodeRF3RR0kHLoNgH31YPekhb6coWH0rDvKXng+Bny4FWT lDsWjBXBQwducCOeUvKgw3gSHvZLIiAFziIEM= 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=T0eIFkvXTGn2bVADgTPYmcybECRT8dELGRo+5YN0FJ4=; b=dk/l7jM7OO/au6BOkATWZLAFB1l/Wrr1rlzNDpDyCEvd71iIoIYRxLYBSolf+mcop3 4Dc3NqO/qlgy2cFgVPCsCMMDKIDJdtv7NnyoO98OQqyUygL3A7YRvmdTHRe14aAvjNmM gGmx1uS+2mipUVDhZ5iqDKu0U0IZQaWRwLNkPnNjVTIdSizljVYuz8yHRHvJh2iHO0nQ X4YNdwB92JVmKawtoimTIzlU5itsICZwk+EPRcBxpz14ecwi8zfcPR4e37LXNAYcdfgj NHtYxPGAayJD11aVnfw0nix7B+4IY7TosPjr1cmMS+kzQKjgF2eRYbJTo5WmH6SowrEv OBiQ== X-Gm-Message-State: AHYfb5iC3l4EZbD2sENvMY5Z/GCV1xMeyB2EA+VrE4ORn07SwOTfyb7h 523waev0QaLcMTgsroD8NQ== X-Received: by 10.28.224.138 with SMTP id x132mr3003940wmg.90.1503166278921; Sat, 19 Aug 2017 11:11:18 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id m127sm4056261wmm.46.2017.08.19.11.11.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Aug 2017 11:11:18 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu Subject: [PATCH v3 5/5] kernel: tracepoints: add support for relative references Date: Sat, 19 Aug 2017 19:10:35 +0100 Message-Id: <20170819181035.969-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170819181035.969-1-ard.biesheuvel@linaro.org> References: <20170819181035.969-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 | 17 +++++++++++++---- 2 files changed, 28 insertions(+), 8 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..68b0218ef66b 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -508,12 +508,21 @@ static void for_each_tracepoint_range(struct tracepoint * const *begin, 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); + + 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); + } } /**