From patchwork Fri Aug 18 11:26:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110376 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780796qge; Fri, 18 Aug 2017 04:27:22 -0700 (PDT) X-Received: by 10.98.245.6 with SMTP id n6mr8398031pfh.113.1503055642182; Fri, 18 Aug 2017 04:27:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055642; cv=none; d=google.com; s=arc-20160816; b=C4WDSYjLNFT2b2Tbbor3ox2zU7UZ0BTSaXE4JOzb5Mp/kNPPA7Xu3o4RoXCs9xyyzG 96IzfV1drguESo5whVTSYlUgalPWcqBQh50PlCr5Oo0GYd0taneivA/WhfyOt4pXZDCZ yvfO/NWr4BaBtw3knQEayyx1r86T2C4UbjG2xwgzCS1DZz8aveKkdqB4qtmeY+B+uGyS t9DlZBkyy7G6sD3uGbfWciYJbcYeUfiSkWO8isiLlsyXD1aOpcM3ebnLj+7+pnMciRDW w2Fe5LX/rk+j/Yi1wflMeU9ejgS+LxSCraViPOZsGpRzd2G19yM65ahk/0t7mFuUiZFZ 7/fA== 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=x7SeoIU5D9NbCpDRoojAmu77Dw7Y+/0EtgpjZyyQq8k=; b=gEB40pEDQTEko2K2n5KYtb1pCaDavb0pYmx2iNlTWRsvrU5bBcs0Kmdh+A9kT0ZkHq bPOwlYlxTV/hK3iWBXr9C5JRPeZEHZp8tp7KFoXezX+nLYD6t99sBrnWqTcNIlqgcBgq kxbYjJanWoY+x/brQTotR2qZJ5LKVWqi8KN0EDlpES1ntUiDs83vR7Uig6jyIfQBFSlv +nx+K/QC1yLHfzv8i6FAFZ8EbX1nG/3sdjlO7m0YewCiXlvOFz3kVIvBWXsoQeIS1ny+ k59K8JMt3Cc9N83kKgKAXKt1JdozkVcKtOeWQvHYexURUfSXCetFvY2SWjLB8Lh472x2 ko/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZNWP6V8; 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 a6si3367492pgc.316.2017.08.18.04.27.21; Fri, 18 Aug 2017 04:27:22 -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=gZNWP6V8; 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 S1752115AbdHRL1S (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:18 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:37227 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751969AbdHRL1O (ORCPT ); Fri, 18 Aug 2017 07:27:14 -0400 Received: by mail-wr0-f173.google.com with SMTP id z91so59503198wrc.4 for ; Fri, 18 Aug 2017 04:27:14 -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=x7SeoIU5D9NbCpDRoojAmu77Dw7Y+/0EtgpjZyyQq8k=; b=gZNWP6V8BxN9lo07RMzktpO8GaHrGskbjZII8bl6wwL/Qtf7hR0yVEdVx9e5jCDdqL JG1nf3nr7XJDRFC+6Z5cIzHLgDT16l4LmtZhXIdq6vZEPCfmfnN+eg4AnpzAv3FsemJM 1qyJtd2JYam1aTM0pqJxTUa14rRZtk0PSma5o= 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=x7SeoIU5D9NbCpDRoojAmu77Dw7Y+/0EtgpjZyyQq8k=; b=qXukE0GdFkALnFc4FYB8NiwWCmnH9IRLhwrBzBoDl8CG7vv00NaIICucfYRpAaSAKP Y8zfS0ScAEJpwFG8xvgR4jB2QMeVGmJ1o+Zc37yFpk2Hx8LCOaFtmJTagFY3GdBcjxY5 9Haoyg88RN0t/BIGd5h6+FoiG67ftWwg/MmntCQa3EO4uYVUv1bo6ZnaaqS1Fpat5vV1 z6yb1/5to13VPT42fjaSnFdJwtrnvaMNzgLXKbmgj00ToI+d8XT4ZPxIvCkkd1LfWr/y 0RE7cAenUfP2x/J867oXhZ1hhngZClhAZ0BW+1SR9VFuPedOUEa1TYC3uFXtMkzjPF9N /jGw== X-Gm-Message-State: AHYfb5jqo92WSxuaElznhUrnV6jOtV80i3VIew/FzbdoiUjmXeteTCXG cINDciQFCYmOVBA4NdvZwg== X-Received: by 10.28.196.12 with SMTP id u12mr1130658wmf.165.1503055633317; Fri, 18 Aug 2017 04:27:13 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.27.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:27:12 -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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu Subject: [PATCH v2 6/6] kernel: tracepoints: add support for relative references Date: Fri, 18 Aug 2017 12:26:24 +0100 Message-Id: <20170818112624.24991-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-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 | 42 ++++++++++++++++++-- kernel/tracepoint.c | 7 +--- 2 files changed, 40 insertions(+), 9 deletions(-) -- 2.11.0 diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index a26ffbe09e71..68701821933a 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -228,6 +228,42 @@ 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") + +struct tracepoint_entry_t { + int tp_offset; +}; + +static inline +struct tracepoint *tracepoint_from_entry(const struct tracepoint_entry_t *ent) +{ + return (struct tracepoint *)((unsigned long)ent + ent->tp_offset); +} +#else +#define __TRACEPOINT_ENTRY(name) \ + static struct tracepoint * const __tracepoint_ptr_##name __used \ + __attribute__((section("__tracepoints_ptrs"))) = \ + &__tracepoint_##name + +struct tracepoint_entry_t { + struct tracepoint *tp; +}; + +static inline +struct tracepoint *tracepoint_from_entry(const struct tracepoint_entry_t *ent) +{ + return ent->tp; +} +#endif + +extern struct tracepoint_entry_t const __start___tracepoints_ptrs[]; +extern struct tracepoint_entry_t const __stop___tracepoints_ptrs[]; + /* * 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 +273,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..21bc41454fd6 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -28,9 +28,6 @@ #include #include -extern struct tracepoint * const __start___tracepoints_ptrs[]; -extern struct tracepoint * const __stop___tracepoints_ptrs[]; - /* Set to 1 to enable tracepoint debug output */ static const int tracepoint_debug; @@ -508,12 +505,12 @@ static void for_each_tracepoint_range(struct tracepoint * const *begin, void (*fct)(struct tracepoint *tp, void *priv), void *priv) { - struct tracepoint * const *iter; + struct tracepoint_entry_t const *iter; if (!begin) return; for (iter = begin; iter < end; iter++) - fct(*iter, priv); + fct(tracepoint_from_entry(iter), priv); } /**