]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blame - arch/s390/kernel/jump_label.c
Merge tag 'for-linus-20190118' of git://git.kernel.dk/linux-block
[mirror_ubuntu-disco-kernel.git] / arch / s390 / kernel / jump_label.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
5373db88
JG
2/*
3 * Jump label s390 support
4 *
5 * Copyright IBM Corp. 2011
6 * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
7 */
5373db88
JG
8#include <linux/uaccess.h>
9#include <linux/stop_machine.h>
10#include <linux/jump_label.h>
11#include <asm/ipl.h>
12
5373db88
JG
13struct insn {
14 u16 opcode;
15 s32 offset;
16} __packed;
17
18struct insn_args {
61f42183
JF
19 struct jump_entry *entry;
20 enum jump_label_type type;
5373db88
JG
21};
22
5c6497c5
HC
23static void jump_label_make_nop(struct jump_entry *entry, struct insn *insn)
24{
25 /* brcl 0,0 */
26 insn->opcode = 0xc004;
27 insn->offset = 0;
28}
29
30static void jump_label_make_branch(struct jump_entry *entry, struct insn *insn)
31{
32 /* brcl 15,offset */
33 insn->opcode = 0xc0f4;
13ddb52c 34 insn->offset = (jump_entry_target(entry) - jump_entry_code(entry)) >> 1;
5c6497c5
HC
35}
36
72dace96
HC
37static void jump_label_bug(struct jump_entry *entry, struct insn *expected,
38 struct insn *new)
5c6497c5 39{
13ddb52c 40 unsigned char *ipc = (unsigned char *)jump_entry_code(entry);
72dace96
HC
41 unsigned char *ipe = (unsigned char *)expected;
42 unsigned char *ipn = (unsigned char *)new;
5c6497c5
HC
43
44 pr_emerg("Jump label code mismatch at %pS [%p]\n", ipc, ipc);
e4ec7351
AK
45 pr_emerg("Found: %6ph\n", ipc);
46 pr_emerg("Expected: %6ph\n", ipe);
47 pr_emerg("New: %6ph\n", ipn);
5c6497c5
HC
48 panic("Corrupted kernel text");
49}
50
d5caa4db
HC
51static struct insn orignop = {
52 .opcode = 0xc004,
53 .offset = JUMP_LABEL_NOP_OFFSET >> 1,
54};
55
61f42183 56static void __jump_label_transform(struct jump_entry *entry,
5c6497c5
HC
57 enum jump_label_type type,
58 int init)
5373db88 59{
13ddb52c 60 void *code = (void *)jump_entry_code(entry);
5c6497c5 61 struct insn old, new;
5373db88 62
76b235c6 63 if (type == JUMP_LABEL_JMP) {
5c6497c5
HC
64 jump_label_make_nop(entry, &old);
65 jump_label_make_branch(entry, &new);
5373db88 66 } else {
d5caa4db 67 jump_label_make_branch(entry, &old);
5c6497c5 68 jump_label_make_nop(entry, &new);
5373db88 69 }
d5caa4db 70 if (init) {
13ddb52c 71 if (memcmp(code, &orignop, sizeof(orignop)))
72dace96 72 jump_label_bug(entry, &orignop, &new);
d5caa4db 73 } else {
13ddb52c 74 if (memcmp(code, &old, sizeof(old)))
72dace96 75 jump_label_bug(entry, &old, &new);
d5caa4db 76 }
13ddb52c 77 s390_kernel_write(code, &new, sizeof(new));
61f42183 78}
5373db88 79
61f42183
JF
80static int __sm_arch_jump_label_transform(void *data)
81{
82 struct insn_args *args = data;
83
5c6497c5 84 __jump_label_transform(args->entry, args->type, 0);
61f42183
JF
85 return 0;
86}
87
88void arch_jump_label_transform(struct jump_entry *entry,
89 enum jump_label_type type)
90{
91 struct insn_args args;
92
93 args.entry = entry;
94 args.type = type;
95
5d5dbc4e 96 stop_machine_cpuslocked(__sm_arch_jump_label_transform, &args, NULL);
61f42183
JF
97}
98
99void arch_jump_label_transform_static(struct jump_entry *entry,
100 enum jump_label_type type)
101{
5c6497c5 102 __jump_label_transform(entry, type, 1);
5373db88 103}