Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/jump-label: Remove support for custom text poker

There are only two types of text poking: early and breakpoint based. The use
of a function pointer to perform text poking complicates the code and is
probably inefficient due to the use of indirect branches.

Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <akpm@linux-foundation.org>
Cc: <ard.biesheuvel@linaro.org>
Cc: <deneen.t.dock@intel.com>
Cc: <kernel-hardening@lists.openwall.com>
Cc: <kristen@linux.intel.com>
Cc: <linux_dti@icloud.com>
Cc: <will.deacon@arm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190426001143.4983-13-namit@vmware.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Nadav Amit and committed by
Ingo Molnar
bb0a008d f2c65fb3

+10 -16
+10 -16
arch/x86/kernel/jump_label.c
··· 37 37 38 38 static void __ref __jump_label_transform(struct jump_entry *entry, 39 39 enum jump_label_type type, 40 - void *(*poker)(void *, const void *, size_t), 41 40 int init) 42 41 { 43 42 union jump_code_union jmp; ··· 48 49 jmp.jump = 0xe9; 49 50 jmp.offset = jump_entry_target(entry) - 50 51 (jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE); 51 - 52 - /* 53 - * As long as only a single processor is running and the code is still 54 - * not marked as RO, text_poke_early() can be used; Checking that 55 - * system_state is SYSTEM_BOOTING guarantees it. 56 - */ 57 - if (system_state == SYSTEM_BOOTING) 58 - poker = text_poke_early; 59 52 60 53 if (type == JUMP_LABEL_JMP) { 61 54 if (init) { ··· 71 80 bug_at((void *)jump_entry_code(entry), line); 72 81 73 82 /* 74 - * Make text_poke_bp() a default fallback poker. 83 + * As long as only a single processor is running and the code is still 84 + * not marked as RO, text_poke_early() can be used; Checking that 85 + * system_state is SYSTEM_BOOTING guarantees it. It will be set to 86 + * SYSTEM_SCHEDULING before other cores are awaken and before the 87 + * code is write-protected. 75 88 * 76 89 * At the time the change is being done, just ignore whether we 77 90 * are doing nop -> jump or jump -> nop transition, and assume 78 91 * always nop being the 'currently valid' instruction 79 - * 80 92 */ 81 - if (poker) { 82 - (*poker)((void *)jump_entry_code(entry), code, 83 - JUMP_LABEL_NOP_SIZE); 93 + if (init || system_state == SYSTEM_BOOTING) { 94 + text_poke_early((void *)jump_entry_code(entry), code, 95 + JUMP_LABEL_NOP_SIZE); 84 96 return; 85 97 } 86 98 ··· 95 101 enum jump_label_type type) 96 102 { 97 103 mutex_lock(&text_mutex); 98 - __jump_label_transform(entry, type, NULL, 0); 104 + __jump_label_transform(entry, type, 0); 99 105 mutex_unlock(&text_mutex); 100 106 } 101 107 ··· 125 131 jlstate = JL_STATE_NO_UPDATE; 126 132 } 127 133 if (jlstate == JL_STATE_UPDATE) 128 - __jump_label_transform(entry, type, text_poke_early, 1); 134 + __jump_label_transform(entry, type, 1); 129 135 }