Skip to content

Commit fdfd428

Browse files
ardbiesheuvelPeter Zijlstra
authored andcommitted
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
1 parent 0c3b61e commit fdfd428

File tree

7 files changed

+24
-41
lines changed

7 files changed

+24
-41
lines changed

arch/mips/kernel/jump_label.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,22 @@ void arch_jump_label_transform(struct jump_entry *e,
8888

8989
mutex_unlock(&text_mutex);
9090
}
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

arch/mips/kernel/module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/spinlock.h>
2222
#include <linux/jump_label.h>
2323

24+
extern void jump_label_apply_nops(struct module *mod);
2425

2526
struct mips_hi16 {
2627
struct mips_hi16 *next;
@@ -428,8 +429,8 @@ int module_finalize(const Elf_Ehdr *hdr,
428429
const Elf_Shdr *s;
429430
char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
430431

431-
/* Make jump label nops. */
432-
jump_label_apply_nops(me);
432+
if (IS_ENABLED(CONFIG_JUMP_LABEL))
433+
jump_label_apply_nops(me);
433434

434435
INIT_LIST_HEAD(&me->arch.dbe_list);
435436
for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {

arch/s390/kernel/module.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,5 @@ int module_finalize(const Elf_Ehdr *hdr,
548548
#endif /* CONFIG_FUNCTION_TRACER */
549549
}
550550

551-
jump_label_apply_nops(me);
552551
return 0;
553552
}

arch/sparc/kernel/module.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ int module_finalize(const Elf_Ehdr *hdr,
208208
const Elf_Shdr *sechdrs,
209209
struct module *me)
210210
{
211-
/* make jump label nops */
212-
jump_label_apply_nops(me);
213-
214211
do_patch_sections(hdr, sechdrs);
215212

216213
/* Cheetah's I-cache is fully coherent. */

arch/x86/kernel/module.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,6 @@ int module_finalize(const Elf_Ehdr *hdr,
304304
tseg, tseg + text->sh_size);
305305
}
306306

307-
/* make jump label nops */
308-
jump_label_apply_nops(me);
309-
310307
if (orc && orc_ip)
311308
unwind_module_init(me, (void *)orc_ip->sh_addr, orc_ip->sh_size,
312309
(void *)orc->sh_addr, orc->sh_size);

include/linux/jump_label.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ extern void static_key_slow_inc(struct static_key *key);
230230
extern void static_key_slow_dec(struct static_key *key);
231231
extern void static_key_slow_inc_cpuslocked(struct static_key *key);
232232
extern void static_key_slow_dec_cpuslocked(struct static_key *key);
233-
extern void jump_label_apply_nops(struct module *mod);
234233
extern int static_key_count(struct static_key *key);
235234
extern void static_key_enable(struct static_key *key);
236235
extern void static_key_disable(struct static_key *key);
237236
extern void static_key_enable_cpuslocked(struct static_key *key);
238237
extern void static_key_disable_cpuslocked(struct static_key *key);
238+
extern enum jump_label_type jump_label_init_type(struct jump_entry *entry);
239239

240240
/*
241241
* We should be using ATOMIC_INIT() for initializing .enabled, but
@@ -303,11 +303,6 @@ static inline int jump_label_text_reserved(void *start, void *end)
303303
static inline void jump_label_lock(void) {}
304304
static inline void jump_label_unlock(void) {}
305305

306-
static inline int jump_label_apply_nops(struct module *mod)
307-
{
308-
return 0;
309-
}
310-
311306
static inline void static_key_enable(struct static_key *key)
312307
{
313308
STATIC_KEY_CHECK_USE(key);

kernel/jump_label.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void __init jump_label_init(void)
508508

509509
#ifdef CONFIG_MODULES
510510

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)
512512
{
513513
struct static_key *key = jump_entry_key(entry);
514514
bool type = static_key_type(key);
@@ -596,31 +596,6 @@ static void __jump_label_mod_update(struct static_key *key)
596596
}
597597
}
598598

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-
}
622-
}
623-
624599
static int jump_label_add_module(struct module *mod)
625600
{
626601
struct jump_entry *iter_start = mod->jump_entries;

0 commit comments

Comments
 (0)