Skip to content

Commit 916cda1

Browse files
author
Martin Schwidefsky
committed
s390: add a system call for guarded storage
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>
1 parent 093b995 commit 916cda1

27 files changed

Lines changed: 436 additions & 46 deletions

‎arch/s390/include/asm/elf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
#define HWCAP_S390_VXRS 2048
106106
#define HWCAP_S390_VXRS_BCD 4096
107107
#define HWCAP_S390_VXRS_EXT 8192
108+
#define HWCAP_S390_GS 16384
108109

109110
/* Internal bits, not exposed via elf */
110111
#define HWCAP_INT_SIE 1UL

‎arch/s390/include/asm/lowcore.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ struct lowcore {
157157
__u64 stfle_fac_list[32]; /* 0x0f00 */
158158
__u8 pad_0x1000[0x11b0-0x1000]; /* 0x1000 */
159159

160-
/* Pointer to vector register save area */
161-
__u64 vector_save_area_addr; /* 0x11b0 */
160+
/* Pointer to the machine check extended save area */
161+
__u64 mcesad; /* 0x11b0 */
162162

163163
/* 64 bit extparam used for pfault/diag 250: defined by architecture */
164164
__u64 ext_params2; /* 0x11B8 */
@@ -182,10 +182,7 @@ struct lowcore {
182182

183183
/* Transaction abort diagnostic block */
184184
__u8 pgm_tdb[256]; /* 0x1800 */
185-
__u8 pad_0x1900[0x1c00-0x1900]; /* 0x1900 */
186-
187-
/* Software defined save area for vector registers */
188-
__u8 vector_save_area[1024]; /* 0x1c00 */
185+
__u8 pad_0x1900[0x2000-0x1900]; /* 0x1900 */
189186
} __packed;
190187

191188
#define S390_lowcore (*((struct lowcore *) 0))

‎arch/s390/include/asm/nmi.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ union mci {
5858
u64 ie : 1; /* 32 indirect storage error */
5959
u64 ar : 1; /* 33 access register validity */
6060
u64 da : 1; /* 34 delayed access exception */
61-
u64 : 7; /* 35-41 */
61+
u64 : 1; /* 35 */
62+
u64 gs : 1; /* 36 guarded storage registers */
63+
u64 : 5; /* 37-41 */
6264
u64 pr : 1; /* 42 tod programmable register validity */
6365
u64 fc : 1; /* 43 fp control register validity */
6466
u64 ap : 1; /* 44 ancillary report */
@@ -69,6 +71,14 @@ union mci {
6971
};
7072
};
7173

74+
#define MCESA_ORIGIN_MASK (~0x3ffUL)
75+
#define MCESA_LC_MASK (0xfUL)
76+
77+
struct mcesa {
78+
u8 vector_save_area[1024];
79+
u8 guarded_storage_save_area[32];
80+
};
81+
7282
struct pt_regs;
7383

7484
extern void s390_handle_mcck(void);

‎arch/s390/include/asm/processor.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ struct thread_struct {
135135
struct list_head list;
136136
/* cpu runtime instrumentation */
137137
struct runtime_instr_cb *ri_cb;
138+
struct gs_cb *gs_cb; /* Current guarded storage cb */
139+
struct gs_cb *gs_bc_cb; /* Broadcast guarded storage cb */
138140
unsigned char trap_tdb[256]; /* Transaction abort diagnose block */
139141
/*
140142
* Warning: 'fpu' is dynamically-sized. It *MUST* be at
@@ -215,6 +217,9 @@ void show_cacheinfo(struct seq_file *m);
215217
/* Free all resources held by a thread. */
216218
extern void release_thread(struct task_struct *);
217219

220+
/* Free guarded storage control block for current */
221+
void exit_thread_gs(void);
222+
218223
/*
219224
* Return saved PC of a blocked thread.
220225
*/

‎arch/s390/include/asm/setup.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define MACHINE_FLAG_VX _BITUL(13)
3232
#define MACHINE_FLAG_CAD _BITUL(14)
3333
#define MACHINE_FLAG_NX _BITUL(15)
34+
#define MACHINE_FLAG_GS _BITUL(16)
3435

3536
#define LPP_MAGIC _BITUL(31)
3637
#define LPP_PFAULT_PID_MASK _AC(0xffffffff, UL)
@@ -70,6 +71,7 @@ extern void detect_memory_memblock(void);
7071
#define MACHINE_HAS_VX (S390_lowcore.machine_flags & MACHINE_FLAG_VX)
7172
#define MACHINE_HAS_CAD (S390_lowcore.machine_flags & MACHINE_FLAG_CAD)
7273
#define MACHINE_HAS_NX (S390_lowcore.machine_flags & MACHINE_FLAG_NX)
74+
#define MACHINE_HAS_GS (S390_lowcore.machine_flags & MACHINE_FLAG_GS)
7375

7476
/*
7577
* Console mode. Override with conmode=

‎arch/s390/include/asm/switch_to.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/thread_info.h>
1111
#include <asm/fpu/api.h>
1212
#include <asm/ptrace.h>
13+
#include <asm/guarded_storage.h>
1314

1415
extern struct task_struct *__switch_to(void *, void *);
1516
extern void update_cr_regs(struct task_struct *task);
@@ -33,12 +34,14 @@ static inline void restore_access_regs(unsigned int *acrs)
3334
save_fpu_regs(); \
3435
save_access_regs(&prev->thread.acrs[0]); \
3536
save_ri_cb(prev->thread.ri_cb); \
37+
save_gs_cb(prev->thread.gs_cb); \
3638
} \
3739
if (next->mm) { \
3840
update_cr_regs(next); \
3941
set_cpu_flag(CIF_FPU); \
4042
restore_access_regs(&next->thread.acrs[0]); \
4143
restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
44+
restore_gs_cb(next->thread.gs_cb); \
4245
} \
4346
prev = __switch_to(prev,next); \
4447
} while (0)

‎arch/s390/include/asm/thread_info.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
5454
#define TIF_NOTIFY_RESUME 0 /* callback before returning to user */
5555
#define TIF_SIGPENDING 1 /* signal pending */
5656
#define TIF_NEED_RESCHED 2 /* rescheduling necessary */
57-
#define TIF_SYSCALL_TRACE 3 /* syscall trace active */
58-
#define TIF_SYSCALL_AUDIT 4 /* syscall auditing active */
59-
#define TIF_SECCOMP 5 /* secure computing */
60-
#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
61-
#define TIF_UPROBE 7 /* breakpointed or single-stepping */
57+
#define TIF_UPROBE 3 /* breakpointed or single-stepping */
58+
#define TIF_GUARDED_STORAGE 4 /* load guarded storage control block */
59+
#define TIF_SYSCALL_TRACE 8 /* syscall trace active */
60+
#define TIF_SYSCALL_AUDIT 9 /* syscall auditing active */
61+
#define TIF_SECCOMP 10 /* secure computing */
62+
#define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6263
#define TIF_31BIT 16 /* 32bit process */
6364
#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6465
#define TIF_RESTORE_SIGMASK 18 /* restore signal mask in do_signal() */
@@ -76,5 +77,6 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
7677
#define _TIF_UPROBE _BITUL(TIF_UPROBE)
7778
#define _TIF_31BIT _BITUL(TIF_31BIT)
7879
#define _TIF_SINGLE_STEP _BITUL(TIF_SINGLE_STEP)
80+
#define _TIF_GUARDED_STORAGE _BITUL(TIF_GUARDED_STORAGE)
7981

8082
#endif /* _ASM_THREAD_INFO_H */

‎arch/s390/include/uapi/asm/Kbuild‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ header-y += dasd.h
1212
header-y += debug.h
1313
header-y += errno.h
1414
header-y += fcntl.h
15+
header-y += guarded_storage.h
1516
header-y += hypfs.h
1617
header-y += ioctl.h
1718
header-y += ioctls.h
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#ifndef _GUARDED_STORAGE_H
2+
#define _GUARDED_STORAGE_H
3+
4+
#include <linux/types.h>
5+
6+
struct gs_cb {
7+
__u64 reserved;
8+
__u64 gsd;
9+
__u64 gssm;
10+
__u64 gs_epl_a;
11+
};
12+
13+
struct gs_epl {
14+
__u8 pad1;
15+
union {
16+
__u8 gs_eam;
17+
struct {
18+
__u8 : 6;
19+
__u8 e : 1;
20+
__u8 b : 1;
21+
};
22+
};
23+
union {
24+
__u8 gs_eci;
25+
struct {
26+
__u8 tx : 1;
27+
__u8 cx : 1;
28+
__u8 : 5;
29+
__u8 in : 1;
30+
};
31+
};
32+
union {
33+
__u8 gs_eai;
34+
struct {
35+
__u8 : 1;
36+
__u8 t : 1;
37+
__u8 as : 2;
38+
__u8 ar : 4;
39+
};
40+
};
41+
__u32 pad2;
42+
__u64 gs_eha;
43+
__u64 gs_eia;
44+
__u64 gs_eoa;
45+
__u64 gs_eir;
46+
__u64 gs_era;
47+
};
48+
49+
#define GS_ENABLE 0
50+
#define GS_DISABLE 1
51+
#define GS_SET_BC_CB 2
52+
#define GS_CLEAR_BC_CB 3
53+
#define GS_BROADCAST 4
54+
55+
static inline void load_gs_cb(struct gs_cb *gs_cb)
56+
{
57+
asm volatile(".insn rxy,0xe3000000004d,0,%0" : : "Q" (*gs_cb));
58+
}
59+
60+
static inline void store_gs_cb(struct gs_cb *gs_cb)
61+
{
62+
asm volatile(".insn rxy,0xe30000000049,0,%0" : : "Q" (*gs_cb));
63+
}
64+
65+
static inline void save_gs_cb(struct gs_cb *gs_cb)
66+
{
67+
if (gs_cb)
68+
store_gs_cb(gs_cb);
69+
}
70+
71+
static inline void restore_gs_cb(struct gs_cb *gs_cb)
72+
{
73+
if (gs_cb)
74+
load_gs_cb(gs_cb);
75+
}
76+
77+
#endif /* _GUARDED_STORAGE_H */

‎arch/s390/include/uapi/asm/unistd.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
#define __NR_copy_file_range 375
314314
#define __NR_preadv2 376
315315
#define __NR_pwritev2 377
316-
/* Number 378 is reserved for guarded storage */
316+
#define __NR_s390_guarded_storage 378
317317
#define __NR_statx 379
318318
#define NR_syscalls 380
319319

0 commit comments

Comments
 (0)