Skip to content

Commit 578ae44

Browse files
jpoimboeIngo Molnar
authored andcommitted
jump_label: Disable jump labels in __exit code
With the following commit: 3335224 ("jump_label: Explicitly disable jump labels in __init code") ... we explicitly disabled jump labels in __init code, so they could be detected and not warned about in the following commit: dc1dd18 ("jump_label: Warn on failed jump_label patching attempt") In-kernel __exit code has the same issue. It's never used, so it's freed along with the rest of initmem. But jump label entries in __exit code aren't explicitly disabled, so we get the following warning when enabling pr_debug() in __exit code: can't patch jump_label at dmi_sysfs_exit+0x0/0x2d WARNING: CPU: 0 PID: 22572 at kernel/jump_label.c:376 __jump_label_update+0x9d/0xb0 Fix the warning by disabling all jump labels in initmem (which includes both __init and __exit code). Reported-and-tested-by: Li Wang <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Jason Baron <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Fixes: dc1dd18 ("jump_label: Warn on failed jump_label patching attempt") Link: http://lkml.kernel.org/r/7121e6e595374f06616c505b6e690e275c0054d1.1521483452.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent 45dbac0 commit 578ae44

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

include/linux/jump_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extern struct jump_entry __start___jump_table[];
151151
extern struct jump_entry __stop___jump_table[];
152152

153153
extern void jump_label_init(void);
154-
extern void jump_label_invalidate_init(void);
154+
extern void jump_label_invalidate_initmem(void);
155155
extern void jump_label_lock(void);
156156
extern void jump_label_unlock(void);
157157
extern void arch_jump_label_transform(struct jump_entry *entry,
@@ -199,7 +199,7 @@ static __always_inline void jump_label_init(void)
199199
static_key_initialized = true;
200200
}
201201

202-
static inline void jump_label_invalidate_init(void) {}
202+
static inline void jump_label_invalidate_initmem(void) {}
203203

204204
static __always_inline bool static_key_false(struct static_key *key)
205205
{

init/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ static int __ref kernel_init(void *unused)
10011001
/* need to finish all async __init code before freeing the memory */
10021002
async_synchronize_full();
10031003
ftrace_free_init_mem();
1004-
jump_label_invalidate_init();
1004+
jump_label_invalidate_initmem();
10051005
free_initmem();
10061006
mark_readonly();
10071007
system_state = SYSTEM_RUNNING;

kernel/jump_label.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/jump_label_ratelimit.h>
1717
#include <linux/bug.h>
1818
#include <linux/cpu.h>
19+
#include <asm/sections.h>
1920

2021
#ifdef HAVE_JUMP_LABEL
2122

@@ -421,15 +422,15 @@ void __init jump_label_init(void)
421422
cpus_read_unlock();
422423
}
423424

424-
/* Disable any jump label entries in __init code */
425-
void __init jump_label_invalidate_init(void)
425+
/* Disable any jump label entries in __init/__exit code */
426+
void __init jump_label_invalidate_initmem(void)
426427
{
427428
struct jump_entry *iter_start = __start___jump_table;
428429
struct jump_entry *iter_stop = __stop___jump_table;
429430
struct jump_entry *iter;
430431

431432
for (iter = iter_start; iter < iter_stop; iter++) {
432-
if (init_kernel_text(iter->code))
433+
if (init_section_contains((void *)(unsigned long)iter->code, 1))
433434
iter->code = 0;
434435
}
435436
}

0 commit comments

Comments
 (0)