From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
"H. Peter Anvin" <hpa@zytor.com>, Arnd Bergmann <arnd@arndb.de>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Kees Cook <keescook@chromium.org>,
Will Deacon <will.deacon@arm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Thomas Garnier <thgarnie@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
"Serge E. Hallyn" <serge@hallyn.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Petr Mladek <pmladek@suse.com>, Ingo Molnar <mingo@redhat.com>,
James Morris <james.l.morris@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
Joe Perches <joe@perches.com>, Nicolas Pitre <nico@linaro.org>,
Steve
Subject: [PATCH v2 6/6] kernel: tracepoints: add support for relative references
Date: Fri, 18 Aug 2017 12:26:24 +0100 [thread overview]
Message-ID: <20170818112624.24991-7-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.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 <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
include/linux/tracepoint.h | 42 ++++++++++++++++++--
kernel/tracepoint.c | 7 +---
2 files changed, 40 insertions(+), 9 deletions(-)
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 <linux/sched/task.h>
#include <linux/static_key.h>
-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);
}
/**
--
2.11.0
WARNING: multiple messages have this Message-ID (diff)
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
"H. Peter Anvin" <hpa@zytor.com>, Arnd Bergmann <arnd@arndb.de>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Kees Cook <keescook@chromium.org>,
Will Deacon <will.deacon@arm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Thomas Garnier <thgarnie@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
"Serge E. Hallyn" <serge@hallyn.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Petr Mladek <pmladek@suse.com>, Ingo Molnar <mingo@redhat.com>,
James Morris <james.l.morris@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>,
Joe Perches <joe@perches.com>, Nicolas Pitre <nico@linaro.org>,
Steven Rostedt <rostedt@goodmis.org>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andy Whitcroft <apw@canonical.com>, Jessica Yu <jeyu@kernel.org>
Subject: [PATCH v2 6/6] kernel: tracepoints: add support for relative references
Date: Fri, 18 Aug 2017 12:26:24 +0100 [thread overview]
Message-ID: <20170818112624.24991-7-ard.biesheuvel@linaro.org> (raw)
Message-ID: <20170818112624.AVWksoECi1uCPB4CuQPRQcxZQrHA7SOOuJLOeyS6DU4@z> (raw)
In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.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 <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
include/linux/tracepoint.h | 42 ++++++++++++++++++--
kernel/tracepoint.c | 7 +---
2 files changed, 40 insertions(+), 9 deletions(-)
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 <linux/sched/task.h>
#include <linux/static_key.h>
-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);
}
/**
--
2.11.0
next prev parent reply other threads:[~2017-08-18 11:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-18 11:26 [PATCH v2 0/6] add support for relative references in special sections Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel
2017-08-18 11:26 ` [PATCH v2 1/6] arch: enable relative relocations for arm64, power, x86, s390 and x86 Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel
2017-08-18 11:26 ` [PATCH v2 2/6] module: use relative references for __ksymtab entries Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel
2017-08-18 11:26 ` [PATCH v2 3/6] treewide: add missing trailing semicolons to initcall() invocations Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel
2017-08-18 11:26 ` [PATCH v2 4/6] init: allow initcall tables to be emitted using relative references Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel
2017-08-18 11:26 ` [PATCH v2 5/6] drivers: pci: add support for relative addressing in quirk tables Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel
2017-08-18 11:26 ` Ard Biesheuvel [this message]
2017-08-18 11:26 ` [PATCH v2 6/6] kernel: tracepoints: add support for relative references Ard Biesheuvel
2017-08-18 11:44 ` Ard Biesheuvel
2017-08-18 11:44 ` Ard Biesheuvel
2017-08-18 13:43 ` Steven Rostedt
2017-08-18 13:43 ` Steven Rostedt
2017-08-18 13:44 ` Ard Biesheuvel
2017-08-18 13:44 ` Ard Biesheuvel
2017-08-18 13:52 ` Steven Rostedt
2017-08-18 13:52 ` Steven Rostedt
2017-08-18 13:54 ` Ard Biesheuvel
2017-08-18 13:54 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170818112624.24991-7-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=catalin.marinas@arm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=hpa@zytor.com \
--cc=james.l.morris@oracle.com \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=nico@linaro.org \
--cc=paulus@samba.org \
--cc=pmladek@suse.com \
--cc=serge@hallyn.com \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).