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>
21 /* empty control block to disable RI by loading it */
22 struct runtime_instr_cb runtime_instr_empty_cb
;
24 void runtime_instr_release(struct task_struct
*tsk
)
26 kfree(tsk
->thread
.ri_cb
);
29 static void disable_runtime_instr(void)
31 struct task_struct
*task
= current
;
34 if (!task
->thread
.ri_cb
)
36 regs
= task_pt_regs(task
);
38 load_runtime_instr_cb(&runtime_instr_empty_cb
);
39 kfree(task
->thread
.ri_cb
);
40 task
->thread
.ri_cb
= NULL
;
44 * Make sure the RI bit is deleted from the PSW. If the user did not
45 * switch off RI before the system call the process will get a
46 * specification exception otherwise.
48 regs
->psw
.mask
&= ~PSW_MASK_RI
;
51 static void init_runtime_instr_cb(struct runtime_instr_cb
*cb
)
53 cb
->buf_limit
= 0xfff;
55 cb
->pstate_set_buf
= 1;
56 cb
->pstate_sample
= 1;
57 cb
->pstate_collect
= 1;
58 cb
->key
= PAGE_DEFAULT_KEY
;
62 SYSCALL_DEFINE1(s390_runtime_instr
, int, command
)
64 struct runtime_instr_cb
*cb
;
66 if (!test_facility(64))
69 if (command
== S390_RUNTIME_INSTR_STOP
) {
70 disable_runtime_instr();
74 if (command
!= S390_RUNTIME_INSTR_START
)
77 if (!current
->thread
.ri_cb
) {
78 cb
= kzalloc(sizeof(*cb
), GFP_KERNEL
);
82 cb
= current
->thread
.ri_cb
;
83 memset(cb
, 0, sizeof(*cb
));
86 init_runtime_instr_cb(cb
);
88 /* now load the control block to make it available */
90 current
->thread
.ri_cb
= cb
;
91 load_runtime_instr_cb(cb
);