Skip to content

Commit 4cc6620

Browse files
Daniel Bristot de OliveiraIngo Molnar
authored andcommitted
x86/jump_label: Add a __jump_label_set_jump_code() helper
Move the definition of the code to be written from __jump_label_transform() to a specialized function. No functional change. Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Chris von Recklinghausen <crecklin@redhat.com> Cc: Clark Williams <williams@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jason Baron <jbaron@akamai.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Scott Wood <swood@redhat.com> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/d2f52a0010ecd399cf9b02a65bcf5836571b9e52.1560325897.git.bristot@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent e1aacb3 commit 4cc6620

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

arch/x86/kernel/jump_label.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,43 @@ static void bug_at(unsigned char *ip, int line)
3535
BUG();
3636
}
3737

38-
static void __ref __jump_label_transform(struct jump_entry *entry,
39-
enum jump_label_type type,
40-
int init)
38+
static void __jump_label_set_jump_code(struct jump_entry *entry,
39+
enum jump_label_type type,
40+
union jump_code_union *code,
41+
int init)
4142
{
42-
union jump_code_union jmp;
4343
const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
4444
const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5];
45-
const void *expect, *code;
45+
const void *expect;
4646
int line;
4747

48-
jmp.jump = 0xe9;
49-
jmp.offset = jump_entry_target(entry) -
50-
(jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE);
51-
52-
if (type == JUMP_LABEL_JMP) {
53-
if (init) {
54-
expect = default_nop; line = __LINE__;
55-
} else {
56-
expect = ideal_nop; line = __LINE__;
57-
}
48+
code->jump = 0xe9;
49+
code->offset = jump_entry_target(entry) -
50+
(jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE);
5851

59-
code = &jmp.code;
52+
if (init) {
53+
expect = default_nop; line = __LINE__;
54+
} else if (type == JUMP_LABEL_JMP) {
55+
expect = ideal_nop; line = __LINE__;
6056
} else {
61-
if (init) {
62-
expect = default_nop; line = __LINE__;
63-
} else {
64-
expect = &jmp.code; line = __LINE__;
65-
}
66-
67-
code = ideal_nop;
57+
expect = code->code; line = __LINE__;
6858
}
6959

7060
if (memcmp((void *)jump_entry_code(entry), expect, JUMP_LABEL_NOP_SIZE))
7161
bug_at((void *)jump_entry_code(entry), line);
7262

63+
if (type == JUMP_LABEL_NOP)
64+
memcpy(code, ideal_nop, JUMP_LABEL_NOP_SIZE);
65+
}
66+
67+
static void __ref __jump_label_transform(struct jump_entry *entry,
68+
enum jump_label_type type,
69+
int init)
70+
{
71+
union jump_code_union code;
72+
73+
__jump_label_set_jump_code(entry, type, &code, init);
74+
7375
/*
7476
* As long as only a single processor is running and the code is still
7577
* not marked as RO, text_poke_early() can be used; Checking that
@@ -82,12 +84,12 @@ static void __ref __jump_label_transform(struct jump_entry *entry,
8284
* always nop being the 'currently valid' instruction
8385
*/
8486
if (init || system_state == SYSTEM_BOOTING) {
85-
text_poke_early((void *)jump_entry_code(entry), code,
87+
text_poke_early((void *)jump_entry_code(entry), &code,
8688
JUMP_LABEL_NOP_SIZE);
8789
return;
8890
}
8991

90-
text_poke_bp((void *)jump_entry_code(entry), code, JUMP_LABEL_NOP_SIZE,
92+
text_poke_bp((void *)jump_entry_code(entry), &code, JUMP_LABEL_NOP_SIZE,
9193
(void *)jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE);
9294
}
9395

0 commit comments

Comments
 (0)