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

jump_label: mips: move module NOP patching into arch code

MIPS is the only remaining architecture that needs to patch jump label
NOP encodings to initialize them at load time. So let's move the module
patching part of that from generic code into arch/mips, and drop it from
the others.

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-3-ardb@kernel.org

authored by

Ard Biesheuvel and committed by
Peter Zijlstra
fdfd4289 0c3b61e0

+24 -41
+19
arch/mips/kernel/jump_label.c
··· 88 88 89 89 mutex_unlock(&text_mutex); 90 90 } 91 + 92 + #ifdef CONFIG_MODULES 93 + void jump_label_apply_nops(struct module *mod) 94 + { 95 + struct jump_entry *iter_start = mod->jump_entries; 96 + struct jump_entry *iter_stop = iter_start + mod->num_jump_entries; 97 + struct jump_entry *iter; 98 + 99 + /* if the module doesn't have jump label entries, just return */ 100 + if (iter_start == iter_stop) 101 + return; 102 + 103 + for (iter = iter_start; iter < iter_stop; iter++) { 104 + /* Only write NOPs for arch_branch_static(). */ 105 + if (jump_label_init_type(iter) == JUMP_LABEL_NOP) 106 + arch_jump_label_transform(iter, JUMP_LABEL_NOP); 107 + } 108 + } 109 + #endif
+3 -2
arch/mips/kernel/module.c
··· 21 21 #include <linux/spinlock.h> 22 22 #include <linux/jump_label.h> 23 23 24 + extern void jump_label_apply_nops(struct module *mod); 24 25 25 26 struct mips_hi16 { 26 27 struct mips_hi16 *next; ··· 429 428 const Elf_Shdr *s; 430 429 char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; 431 430 432 - /* Make jump label nops. */ 433 - jump_label_apply_nops(me); 431 + if (IS_ENABLED(CONFIG_JUMP_LABEL)) 432 + jump_label_apply_nops(me); 434 433 435 434 INIT_LIST_HEAD(&me->arch.dbe_list); 436 435 for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
-1
arch/s390/kernel/module.c
··· 548 548 #endif /* CONFIG_FUNCTION_TRACER */ 549 549 } 550 550 551 - jump_label_apply_nops(me); 552 551 return 0; 553 552 }
-3
arch/sparc/kernel/module.c
··· 208 208 const Elf_Shdr *sechdrs, 209 209 struct module *me) 210 210 { 211 - /* make jump label nops */ 212 - jump_label_apply_nops(me); 213 - 214 211 do_patch_sections(hdr, sechdrs); 215 212 216 213 /* Cheetah's I-cache is fully coherent. */
-3
arch/x86/kernel/module.c
··· 304 304 tseg, tseg + text->sh_size); 305 305 } 306 306 307 - /* make jump label nops */ 308 - jump_label_apply_nops(me); 309 - 310 307 if (orc && orc_ip) 311 308 unwind_module_init(me, (void *)orc_ip->sh_addr, orc_ip->sh_size, 312 309 (void *)orc->sh_addr, orc->sh_size);
+1 -6
include/linux/jump_label.h
··· 230 230 extern void static_key_slow_dec(struct static_key *key); 231 231 extern void static_key_slow_inc_cpuslocked(struct static_key *key); 232 232 extern void static_key_slow_dec_cpuslocked(struct static_key *key); 233 - extern void jump_label_apply_nops(struct module *mod); 234 233 extern int static_key_count(struct static_key *key); 235 234 extern void static_key_enable(struct static_key *key); 236 235 extern void static_key_disable(struct static_key *key); 237 236 extern void static_key_enable_cpuslocked(struct static_key *key); 238 237 extern void static_key_disable_cpuslocked(struct static_key *key); 238 + extern enum jump_label_type jump_label_init_type(struct jump_entry *entry); 239 239 240 240 /* 241 241 * We should be using ATOMIC_INIT() for initializing .enabled, but ··· 302 302 303 303 static inline void jump_label_lock(void) {} 304 304 static inline void jump_label_unlock(void) {} 305 - 306 - static inline int jump_label_apply_nops(struct module *mod) 307 - { 308 - return 0; 309 - } 310 305 311 306 static inline void static_key_enable(struct static_key *key) 312 307 {
+1 -26
kernel/jump_label.c
··· 508 508 509 509 #ifdef CONFIG_MODULES 510 510 511 - static enum jump_label_type jump_label_init_type(struct jump_entry *entry) 511 + enum jump_label_type jump_label_init_type(struct jump_entry *entry) 512 512 { 513 513 struct static_key *key = jump_entry_key(entry); 514 514 bool type = static_key_type(key); ··· 593 593 stop = m->jump_entries + m->num_jump_entries; 594 594 __jump_label_update(key, mod->entries, stop, 595 595 m && m->state == MODULE_STATE_COMING); 596 - } 597 - } 598 - 599 - /*** 600 - * apply_jump_label_nops - patch module jump labels with arch_get_jump_label_nop() 601 - * @mod: module to patch 602 - * 603 - * Allow for run-time selection of the optimal nops. Before the module 604 - * loads patch these with arch_get_jump_label_nop(), which is specified by 605 - * the arch specific jump label code. 606 - */ 607 - void jump_label_apply_nops(struct module *mod) 608 - { 609 - struct jump_entry *iter_start = mod->jump_entries; 610 - struct jump_entry *iter_stop = iter_start + mod->num_jump_entries; 611 - struct jump_entry *iter; 612 - 613 - /* if the module doesn't have jump label entries, just return */ 614 - if (iter_start == iter_stop) 615 - return; 616 - 617 - for (iter = iter_start; iter < iter_stop; iter++) { 618 - /* Only write NOPs for arch_branch_static(). */ 619 - if (jump_label_init_type(iter) == JUMP_LABEL_NOP) 620 - arch_jump_label_transform_static(iter, JUMP_LABEL_NOP); 621 596 } 622 597 } 623 598