diff options
author | Peter Zijlstra <peterz@infradead.org> | 2019-10-03 15:50:42 +0300 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2019-11-27 09:44:24 +0300 |
commit | 63f62addb88ec4b358cf4574789bc3180c689e9a (patch) | |
tree | 251af1ec2b3fc9ebfaee7fe2a89cb9201dd18750 /arch/x86/kernel/jump_label.c | |
parent | 18cbc8bed0c70795d2064217c89894e28eafdf04 (diff) | |
download | linux-63f62addb88ec4b358cf4574789bc3180c689e9a.tar.xz |
x86/alternatives: Add and use text_gen_insn() helper
Provide a simple helper function to create common instruction
encodings.
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: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20191111132457.703538332@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/kernel/jump_label.c')
-rw-r--r-- | arch/x86/kernel/jump_label.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index cf8c847c7b5d..9c4498ea0b3c 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -16,15 +16,7 @@ #include <asm/alternative.h> #include <asm/text-patching.h> -union jump_code_union { - char code[JUMP_LABEL_NOP_SIZE]; - struct { - char jump; - int offset; - } __attribute__((packed)); -}; - -static void bug_at(unsigned char *ip, int line) +static void bug_at(const void *ip, int line) { /* * The location is not an op that we were expecting. @@ -38,33 +30,32 @@ static void bug_at(unsigned char *ip, int line) static const void * __jump_label_set_jump_code(struct jump_entry *entry, enum jump_label_type type, int init) { - static union jump_code_union code; /* relies on text_mutex */ const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; - const void *expect; + const void *expect, *code; + const void *addr, *dest; int line; - lockdep_assert_held(&text_mutex); + addr = (void *)jump_entry_code(entry); + dest = (void *)jump_entry_target(entry); - code.jump = JMP32_INSN_OPCODE; - code.offset = jump_entry_target(entry) - - (jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE); + code = text_gen_insn(JMP32_INSN_OPCODE, addr, dest); if (init) { expect = default_nop; line = __LINE__; } else if (type == JUMP_LABEL_JMP) { expect = ideal_nop; line = __LINE__; } else { - expect = code.code; line = __LINE__; + expect = code; line = __LINE__; } - if (memcmp((void *)jump_entry_code(entry), expect, JUMP_LABEL_NOP_SIZE)) - bug_at((void *)jump_entry_code(entry), line); + if (memcmp(addr, expect, JUMP_LABEL_NOP_SIZE)) + bug_at(addr, line); if (type == JUMP_LABEL_NOP) - memcpy(&code, ideal_nop, JUMP_LABEL_NOP_SIZE); + code = ideal_nop; - return &code; + return code; } static void inline __jump_label_transform(struct jump_entry *entry, |