1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2012
4 * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
7 #include <linux/kernel.h>
8 #include <linux/syscalls.h>
9 #include <linux/signal.h>
11 #include <linux/slab.h>
12 #include <linux/init.h>
13 #include <linux/errno.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/sched/task_stack.h>
17 #include <asm/runtime_instr.h>
18 #include <asm/cpu_mf.h>
23 /* empty control block to disable RI by loading it */
24 struct runtime_instr_cb runtime_instr_empty_cb
;
26 void runtime_instr_release(struct task_struct
*tsk
)
28 kfree(tsk
->thread
.ri_cb
);
31 static void disable_runtime_instr(void)
33 struct task_struct
*task
= current
;
36 if (!task
->thread
.ri_cb
)
38 regs
= task_pt_regs(task
);
40 load_runtime_instr_cb(&runtime_instr_empty_cb
);
41 kfree(task
->thread
.ri_cb
);
42 task
->thread
.ri_cb
= NULL
;
46 * Make sure the RI bit is deleted from the PSW. If the user did not
47 * switch off RI before the system call the process will get a
48 * specification exception otherwise.
50 regs
->psw
.mask
&= ~PSW_MASK_RI
;
53 static void init_runtime_instr_cb(struct runtime_instr_cb
*cb
)
60 cb
->key
= PAGE_DEFAULT_KEY
>> 4;
65 * The signum argument is unused. In older kernels it was used to
66 * specify a real-time signal. For backwards compatibility user space
67 * should pass a valid real-time signal number (the signum argument
68 * was checked in older kernels).
70 SYSCALL_DEFINE2(s390_runtime_instr
, int, command
, int, signum
)
72 struct runtime_instr_cb
*cb
;
74 if (!test_facility(64))
77 if (command
== S390_RUNTIME_INSTR_STOP
) {
78 disable_runtime_instr();
82 if (command
!= S390_RUNTIME_INSTR_START
)
85 if (!current
->thread
.ri_cb
) {
86 cb
= kzalloc(sizeof(*cb
), GFP_KERNEL
);
90 cb
= current
->thread
.ri_cb
;
91 memset(cb
, 0, sizeof(*cb
));
94 init_runtime_instr_cb(cb
);
96 /* now load the control block to make it available */
98 current
->thread
.ri_cb
= cb
;
99 load_runtime_instr_cb(cb
);