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

jump_label: s390: avoid pointless initial NOP patching

Patching NOPs into other NOPs at boot time serves no purpose, so let's
use the same NOP encodings at compile time and runtime.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220615154142.1574619-2-ardb@kernel.org

authored by

Ard Biesheuvel and committed by
Peter Zijlstra
0c3b61e0 a111daf0

+7 -21
+2 -3
arch/s390/include/asm/jump_label.h
··· 10 10 #include <linux/stringify.h> 11 11 12 12 #define JUMP_LABEL_NOP_SIZE 6 13 - #define JUMP_LABEL_NOP_OFFSET 2 14 13 15 14 #ifdef CONFIG_CC_IS_CLANG 16 15 #define JUMP_LABEL_STATIC_KEY_CONSTRAINT "i" ··· 20 21 #endif 21 22 22 23 /* 23 - * We use a brcl 0,2 instruction for jump labels at compile time so it 24 + * We use a brcl 0,<offset> instruction for jump labels so it 24 25 * can be easily distinguished from a hotpatch generated instruction. 25 26 */ 26 27 static __always_inline bool arch_static_branch(struct static_key *key, bool branch) 27 28 { 28 - asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n" 29 + asm_volatile_goto("0: brcl 0,%l[label]\n" 29 30 ".pushsection __jump_table,\"aw\"\n" 30 31 ".balign 8\n" 31 32 ".long 0b-.,%l[label]-.\n"
+5 -18
arch/s390/kernel/jump_label.c
··· 44 44 panic("Corrupted kernel text"); 45 45 } 46 46 47 - static struct insn orignop = { 48 - .opcode = 0xc004, 49 - .offset = JUMP_LABEL_NOP_OFFSET >> 1, 50 - }; 51 - 52 47 static void jump_label_transform(struct jump_entry *entry, 53 - enum jump_label_type type, 54 - int init) 48 + enum jump_label_type type) 55 49 { 56 50 void *code = (void *)jump_entry_code(entry); 57 51 struct insn old, new; ··· 57 63 jump_label_make_branch(entry, &old); 58 64 jump_label_make_nop(entry, &new); 59 65 } 60 - if (init) { 61 - if (memcmp(code, &orignop, sizeof(orignop))) 62 - jump_label_bug(entry, &orignop, &new); 63 - } else { 64 - if (memcmp(code, &old, sizeof(old))) 65 - jump_label_bug(entry, &old, &new); 66 - } 66 + if (memcmp(code, &old, sizeof(old))) 67 + jump_label_bug(entry, &old, &new); 67 68 s390_kernel_write(code, &new, sizeof(new)); 68 69 } 69 70 70 71 void arch_jump_label_transform(struct jump_entry *entry, 71 72 enum jump_label_type type) 72 73 { 73 - jump_label_transform(entry, type, 0); 74 + jump_label_transform(entry, type); 74 75 text_poke_sync(); 75 76 } 76 77 77 78 bool arch_jump_label_transform_queue(struct jump_entry *entry, 78 79 enum jump_label_type type) 79 80 { 80 - jump_label_transform(entry, type, 0); 81 + jump_label_transform(entry, type); 81 82 return true; 82 83 } 83 84 ··· 84 95 void __init_or_module arch_jump_label_transform_static(struct jump_entry *entry, 85 96 enum jump_label_type type) 86 97 { 87 - jump_label_transform(entry, type, 1); 88 - text_poke_sync(); 89 98 }