From: Anton Blanchard <anton@samba.org>
To: benh@kernel.crashing.org, paulus@samba.org,
rusty@rustcorp.com.au, ulrich.weigand@de.ibm.com,
amodra@gmail.com, mikey@neuling.org, mjw@linux.vnet.ibm.com,
rostedt@goodmis.org, philippe.bergheaud@fr.ibm.com
Cc: linuxppc-dev@lists.ozlabs.org
Subject: [PATCH 4/7] powerpc/modules: Create is_module_trampoline()
Date: Fri, 4 Apr 2014 17:09:07 +1100 [thread overview]
Message-ID: <1396591750-8203-5-git-send-email-anton@samba.org> (raw)
In-Reply-To: <1396591750-8203-1-git-send-email-anton@samba.org>
ftrace has way too much knowledge of our kernel module trampoline
layout hidden inside it. Create is_module_trampoline() that can
abstract this away inside the module loader code.
Signed-off-by: Anton Blanchard <anton@samba.org>
---
arch/powerpc/include/asm/module.h | 1 +
arch/powerpc/kernel/module_64.c | 51 +++++++++++++++++++++++++++++++++++----
2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/include/asm/module.h b/arch/powerpc/include/asm/module.h
index c9c7aaa..f2711f0 100644
--- a/arch/powerpc/include/asm/module.h
+++ b/arch/powerpc/include/asm/module.h
@@ -78,6 +78,7 @@ struct mod_arch_specific {
# endif /* MODULE */
#endif
+bool is_module_trampoline(u32 *insns);
struct exception_table_entry;
void sort_ex_table(struct exception_table_entry *start,
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 0423601..4db5ecd 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -22,6 +22,7 @@
#include <linux/vmalloc.h>
#include <linux/ftrace.h>
#include <linux/bug.h>
+#include <linux/uaccess.h>
#include <asm/module.h>
#include <asm/firmware.h>
#include <asm/code-patching.h>
@@ -102,7 +103,9 @@ static unsigned int local_entry_offset(const Elf64_Sym *sym)
jump, actually, to reset r2 (TOC+0x8000). */
struct ppc64_stub_entry
{
- /* 28 byte jump instruction sequence (7 instructions) */
+ /* 28 byte jump instruction sequence (7 instructions). We only
+ * need 6 instructions on ABIv2 but we always allocate 7 so
+ * so we don't have to modify the trampoline load instruction. */
u32 jump[7];
u32 unused;
/* Data for the above code */
@@ -122,8 +125,8 @@ struct ppc64_stub_entry
* end of the stub code, and patch the stub address (32-bits relative
* to the TOC ptr, r2) into the stub.
*/
-static struct ppc64_stub_entry ppc64_stub =
-{ .jump = {
+
+static u32 ppc64_stub_insns[] = {
0x3d620000, /* addis r11,r2, <high> */
0x396b0000, /* addi r11,r11, <low> */
/* Save current r2 value in magic place on the stack. */
@@ -135,7 +138,45 @@ static struct ppc64_stub_entry ppc64_stub =
#endif
0x7d8903a6, /* mtctr r12 */
0x4e800420 /* bctr */
-} };
+};
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+
+static u32 ppc64_stub_mask[] = {
+ 0xffff0000,
+ 0xffff0000,
+ 0xffffffff,
+ 0xffffffff,
+#if !defined(_CALL_ELF) || _CALL_ELF != 2
+ 0xffffffff,
+#endif
+ 0xffffffff,
+ 0xffffffff
+};
+
+bool is_module_trampoline(u32 *p)
+{
+ unsigned int i;
+ u32 insns[ARRAY_SIZE(ppc64_stub_insns)];
+
+ BUILD_BUG_ON(sizeof(ppc64_stub_insns) != sizeof(ppc64_stub_mask));
+
+ if (probe_kernel_read(insns, p, sizeof(insns)))
+ return -EFAULT;
+
+ for (i = 0; i < ARRAY_SIZE(ppc64_stub_insns); i++) {
+ u32 insna = insns[i];
+ u32 insnb = ppc64_stub_insns[i];
+ u32 mask = ppc64_stub_mask[i];
+
+ if ((insna & mask) != (insnb & mask))
+ return false;
+ }
+
+ return true;
+}
+
+#endif
/* Count how many different 24-bit relocations (different symbol,
different addend) */
@@ -350,7 +391,7 @@ static inline int create_stub(Elf64_Shdr *sechdrs,
{
long reladdr;
- *entry = ppc64_stub;
+ memcpy(entry->jump, ppc64_stub_insns, sizeof(ppc64_stub_insns));
/* Stub uses address relative to r2. */
reladdr = (unsigned long)entry - my_r2(sechdrs, me);
--
1.8.3.2
next prev parent reply other threads:[~2014-04-04 6:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-04 6:09 [PATCH 0/7] Build ppc64le kernel using ABIv2, supplemental patches Anton Blanchard
2014-04-04 6:09 ` [PATCH 1/7] powerpc: Add _GLOBAL_TOC for ABIv2 assembly functions exported to modules Anton Blanchard
2014-04-04 6:09 ` [PATCH 2/7] powerpc: ftrace_caller, _mcount is exported to modules so needs _GLOBAL_TOC() Anton Blanchard
2014-04-04 6:09 ` [PATCH 3/7] powerpc/kprobes: Fix ABIv2 issues with kprobe_lookup_name Anton Blanchard
2014-04-04 6:09 ` Anton Blanchard [this message]
2014-04-04 6:09 ` [PATCH 5/7] powerpc/modules: Create module_trampoline_target() Anton Blanchard
2014-04-04 6:09 ` [PATCH 6/7] powerpc/ftrace: Use module loader helpers to parse trampolines Anton Blanchard
2014-04-22 6:58 ` Rusty Russell
2014-04-04 6:09 ` [PATCH 7/7] powerpc/ftrace: Fix ABIv2 issues with __ftrace_make_call Anton Blanchard
2014-04-04 6:19 ` [PATCH 0/7] Build ppc64le kernel using ABIv2, supplemental patches Michael Neuling
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=1396591750-8203-5-git-send-email-anton@samba.org \
--to=anton@samba.org \
--cc=amodra@gmail.com \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mikey@neuling.org \
--cc=mjw@linux.vnet.ibm.com \
--cc=paulus@samba.org \
--cc=philippe.bergheaud@fr.ibm.com \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
--cc=ulrich.weigand@de.ibm.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).