summaryrefslogtreecommitdiff
path: root/arch/x86/include/asm/text-patching.h
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2019-10-09 13:44:14 +0300
committerIngo Molnar <mingo@kernel.org>2019-11-27 09:44:24 +0300
commit67c1d4a28064f9ec63df03f7798e4a334176a9cd (patch)
tree6194a25303109c696bfd23f85b8d3e27c263a353 /arch/x86/include/asm/text-patching.h
parent254d2c04515ea4532a503cc5d8649e1513042e56 (diff)
downloadlinux-67c1d4a28064f9ec63df03f7798e4a334176a9cd.tar.xz
x86/ftrace: Use text_gen_insn()
Replace the ftrace_code_union with the generic text_gen_insn() helper, which does exactly this. Tested-by: Alexei Starovoitov <ast@kernel.org> Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Alexei Starovoitov <ast@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20191111132457.932808000@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/include/asm/text-patching.h')
-rw-r--r--arch/x86/include/asm/text-patching.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/text-patching.h
index 93e4266cd5a3..ad8f9f433a1b 100644
--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -80,7 +80,35 @@ static inline int text_opcode_size(u8 opcode)
return size;
}
-extern void *text_gen_insn(u8 opcode, const void *addr, const void *dest);
+union text_poke_insn {
+ u8 text[POKE_MAX_OPCODE_SIZE];
+ struct {
+ u8 opcode;
+ s32 disp;
+ } __attribute__((packed));
+};
+
+static __always_inline
+void *text_gen_insn(u8 opcode, const void *addr, const void *dest)
+{
+ static union text_poke_insn insn; /* per instance */
+ int size = text_opcode_size(opcode);
+
+ insn.opcode = opcode;
+
+ if (size > 1) {
+ insn.disp = (long)dest - (long)(addr + size);
+ if (size == 2) {
+ /*
+ * Ensure that for JMP9 the displacement
+ * actually fits the signed byte.
+ */
+ BUG_ON((insn.disp >> 31) != (insn.disp >> 7));
+ }
+ }
+
+ return &insn.text;
+}
extern int after_bootmem;
extern __ro_after_init struct mm_struct *poking_mm;