Skip to content

Commit 0c3b61e

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

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

arch/s390/include/asm/jump_label.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/stringify.h>
1111

1212
#define JUMP_LABEL_NOP_SIZE 6
13-
#define JUMP_LABEL_NOP_OFFSET 2
1413

1514
#ifdef CONFIG_CC_IS_CLANG
1615
#define JUMP_LABEL_STATIC_KEY_CONSTRAINT "i"
@@ -21,12 +20,12 @@
2120
#endif
2221

2322
/*
24-
* We use a brcl 0,2 instruction for jump labels at compile time so it
23+
* We use a brcl 0,<offset> instruction for jump labels so it
2524
* can be easily distinguished from a hotpatch generated instruction.
2625
*/
2726
static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
2827
{
29-
asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n"
28+
asm_volatile_goto("0: brcl 0,%l[label]\n"
3029
".pushsection __jump_table,\"aw\"\n"
3130
".balign 8\n"
3231
".long 0b-.,%l[label]-.\n"

arch/s390/kernel/jump_label.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ static void jump_label_bug(struct jump_entry *entry, struct insn *expected,
4444
panic("Corrupted kernel text");
4545
}
4646

47-
static struct insn orignop = {
48-
.opcode = 0xc004,
49-
.offset = JUMP_LABEL_NOP_OFFSET >> 1,
50-
};
51-
5247
static void jump_label_transform(struct jump_entry *entry,
53-
enum jump_label_type type,
54-
int init)
48+
enum jump_label_type type)
5549
{
5650
void *code = (void *)jump_entry_code(entry);
5751
struct insn old, new;
@@ -63,27 +57,22 @@ static void jump_label_transform(struct jump_entry *entry,
6357
jump_label_make_branch(entry, &old);
6458
jump_label_make_nop(entry, &new);
6559
}
66-
if (init) {
67-
if (memcmp(code, &orignop, sizeof(orignop)))
68-
jump_label_bug(entry, &orignop, &new);
69-
} else {
70-
if (memcmp(code, &old, sizeof(old)))
71-
jump_label_bug(entry, &old, &new);
72-
}
60+
if (memcmp(code, &old, sizeof(old)))
61+
jump_label_bug(entry, &old, &new);
7362
s390_kernel_write(code, &new, sizeof(new));
7463
}
7564

7665
void arch_jump_label_transform(struct jump_entry *entry,
7766
enum jump_label_type type)
7867
{
79-
jump_label_transform(entry, type, 0);
68+
jump_label_transform(entry, type);
8069
text_poke_sync();
8170
}
8271

8372
bool arch_jump_label_transform_queue(struct jump_entry *entry,
8473
enum jump_label_type type)
8574
{
86-
jump_label_transform(entry, type, 0);
75+
jump_label_transform(entry, type);
8776
return true;
8877
}
8978

@@ -95,6 +84,4 @@ void arch_jump_label_transform_apply(void)
9584
void __init_or_module arch_jump_label_transform_static(struct jump_entry *entry,
9685
enum jump_label_type type)
9786
{
98-
jump_label_transform(entry, type, 1);
99-
text_poke_sync();
10087
}

0 commit comments

Comments
 (0)