![Martin Schwidefsky](/assets/img/avatar_default.png)
This adds a new system call to enable the use of guarded storage for user space processes. The system call takes two arguments, a command and pointer to a guarded storage control block: s390_guarded_storage(int command, struct gs_cb *gs_cb); The second argument is relevant only for the GS_SET_BC_CB command. The commands in detail: 0 - GS_ENABLE Enable the guarded storage facility for the current task. The initial content of the guarded storage control block will be all zeros. After the enablement the user space code can use load-guarded-storage-controls instruction (LGSC) to load an arbitrary control block. While a task is enabled the kernel will save and restore the current content of the guarded storage registers on context switch. 1 - GS_DISABLE Disables the use of the guarded storage facility for the current task. The kernel will cease to save and restore the content of the guarded storage registers, the task specific content of these registers is lost. 2 - GS_SET_BC_CB Set a broadcast guarded storage control block. This is called per thread and stores a specific guarded storage control block in the task struct of the current task. This control block will be used for the broadcast event GS_BROADCAST. 3 - GS_CLEAR_BC_CB Clears the broadcast guarded storage control block. The guarded- storage control block is removed from the task struct that was established by GS_SET_BC_CB. 4 - GS_BROADCAST Sends a broadcast to all thread siblings of the current task. Every sibling that has established a broadcast guarded storage control block will load this control block and will be enabled for guarded storage. The broadcast guarded storage control block is used up, a second broadcast without a refresh of the stored control block with GS_SET_BC_CB will not have any effect. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
129 lines
2.4 KiB
C
129 lines
2.4 KiB
C
/*
|
|
* Copyright IBM Corp. 2016
|
|
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/signal.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/slab.h>
|
|
#include <asm/guarded_storage.h>
|
|
#include "entry.h"
|
|
|
|
void exit_thread_gs(void)
|
|
{
|
|
kfree(current->thread.gs_cb);
|
|
kfree(current->thread.gs_bc_cb);
|
|
current->thread.gs_cb = current->thread.gs_bc_cb = NULL;
|
|
}
|
|
|
|
static int gs_enable(void)
|
|
{
|
|
struct gs_cb *gs_cb;
|
|
|
|
if (!current->thread.gs_cb) {
|
|
gs_cb = kzalloc(sizeof(*gs_cb), GFP_KERNEL);
|
|
if (!gs_cb)
|
|
return -ENOMEM;
|
|
gs_cb->gsd = 25;
|
|
preempt_disable();
|
|
__ctl_set_bit(2, 4);
|
|
load_gs_cb(gs_cb);
|
|
current->thread.gs_cb = gs_cb;
|
|
preempt_enable();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int gs_disable(void)
|
|
{
|
|
if (current->thread.gs_cb) {
|
|
preempt_disable();
|
|
kfree(current->thread.gs_cb);
|
|
current->thread.gs_cb = NULL;
|
|
__ctl_clear_bit(2, 4);
|
|
preempt_enable();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int gs_set_bc_cb(struct gs_cb __user *u_gs_cb)
|
|
{
|
|
struct gs_cb *gs_cb;
|
|
|
|
gs_cb = current->thread.gs_bc_cb;
|
|
if (!gs_cb) {
|
|
gs_cb = kzalloc(sizeof(*gs_cb), GFP_KERNEL);
|
|
if (!gs_cb)
|
|
return -ENOMEM;
|
|
current->thread.gs_bc_cb = gs_cb;
|
|
}
|
|
if (copy_from_user(gs_cb, u_gs_cb, sizeof(*gs_cb)))
|
|
return -EFAULT;
|
|
return 0;
|
|
}
|
|
|
|
static int gs_clear_bc_cb(void)
|
|
{
|
|
struct gs_cb *gs_cb;
|
|
|
|
gs_cb = current->thread.gs_bc_cb;
|
|
current->thread.gs_bc_cb = NULL;
|
|
kfree(gs_cb);
|
|
return 0;
|
|
}
|
|
|
|
void gs_load_bc_cb(struct pt_regs *regs)
|
|
{
|
|
struct gs_cb *gs_cb;
|
|
|
|
preempt_disable();
|
|
clear_thread_flag(TIF_GUARDED_STORAGE);
|
|
gs_cb = current->thread.gs_bc_cb;
|
|
if (gs_cb) {
|
|
kfree(current->thread.gs_cb);
|
|
current->thread.gs_bc_cb = NULL;
|
|
__ctl_set_bit(2, 4);
|
|
load_gs_cb(gs_cb);
|
|
current->thread.gs_cb = gs_cb;
|
|
}
|
|
preempt_enable();
|
|
}
|
|
|
|
static int gs_broadcast(void)
|
|
{
|
|
struct task_struct *sibling;
|
|
|
|
read_lock(&tasklist_lock);
|
|
for_each_thread(current, sibling) {
|
|
if (!sibling->thread.gs_bc_cb)
|
|
continue;
|
|
if (test_and_set_tsk_thread_flag(sibling, TIF_GUARDED_STORAGE))
|
|
kick_process(sibling);
|
|
}
|
|
read_unlock(&tasklist_lock);
|
|
return 0;
|
|
}
|
|
|
|
SYSCALL_DEFINE2(s390_guarded_storage, int, command,
|
|
struct gs_cb __user *, gs_cb)
|
|
{
|
|
if (!MACHINE_HAS_GS)
|
|
return -EOPNOTSUPP;
|
|
switch (command) {
|
|
case GS_ENABLE:
|
|
return gs_enable();
|
|
case GS_DISABLE:
|
|
return gs_disable();
|
|
case GS_SET_BC_CB:
|
|
return gs_set_bc_cb(gs_cb);
|
|
case GS_CLEAR_BC_CB:
|
|
return gs_clear_bc_cb();
|
|
case GS_BROADCAST:
|
|
return gs_broadcast();
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|