]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/s390/kernel/guarded_storage.c
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2016
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7 #include <linux/kernel.h>
8 #include <linux/syscalls.h>
9 #include <linux/signal.h>
11 #include <linux/slab.h>
12 #include <asm/guarded_storage.h>
15 void exit_thread_gs(void)
17 kfree(current
->thread
.gs_cb
);
18 kfree(current
->thread
.gs_bc_cb
);
19 current
->thread
.gs_cb
= current
->thread
.gs_bc_cb
= NULL
;
22 static int gs_enable(void)
26 if (!current
->thread
.gs_cb
) {
27 gs_cb
= kzalloc(sizeof(*gs_cb
), GFP_KERNEL
);
34 current
->thread
.gs_cb
= gs_cb
;
40 static int gs_disable(void)
42 if (current
->thread
.gs_cb
) {
44 kfree(current
->thread
.gs_cb
);
45 current
->thread
.gs_cb
= NULL
;
46 __ctl_clear_bit(2, 4);
52 static int gs_set_bc_cb(struct gs_cb __user
*u_gs_cb
)
56 gs_cb
= current
->thread
.gs_bc_cb
;
58 gs_cb
= kzalloc(sizeof(*gs_cb
), GFP_KERNEL
);
61 current
->thread
.gs_bc_cb
= gs_cb
;
63 if (copy_from_user(gs_cb
, u_gs_cb
, sizeof(*gs_cb
)))
68 static int gs_clear_bc_cb(void)
72 gs_cb
= current
->thread
.gs_bc_cb
;
73 current
->thread
.gs_bc_cb
= NULL
;
78 void gs_load_bc_cb(struct pt_regs
*regs
)
83 clear_thread_flag(TIF_GUARDED_STORAGE
);
84 gs_cb
= current
->thread
.gs_bc_cb
;
86 kfree(current
->thread
.gs_cb
);
87 current
->thread
.gs_bc_cb
= NULL
;
90 current
->thread
.gs_cb
= gs_cb
;
95 static int gs_broadcast(void)
97 struct task_struct
*sibling
;
99 read_lock(&tasklist_lock
);
100 for_each_thread(current
, sibling
) {
101 if (!sibling
->thread
.gs_bc_cb
)
103 if (test_and_set_tsk_thread_flag(sibling
, TIF_GUARDED_STORAGE
))
104 kick_process(sibling
);
106 read_unlock(&tasklist_lock
);
110 SYSCALL_DEFINE2(s390_guarded_storage
, int, command
,
111 struct gs_cb __user
*, gs_cb
)
121 return gs_set_bc_cb(gs_cb
);
123 return gs_clear_bc_cb();
125 return gs_broadcast();