xref: /openbmc/linux/arch/s390/include/asm/compat.h (revision bbecb07f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390X_COMPAT_H
3 #define _ASM_S390X_COMPAT_H
4 /*
5  * Architecture specific compatibility types
6  */
7 #include <linux/types.h>
8 #include <linux/sched.h>
9 #include <linux/sched/task_stack.h>
10 #include <linux/thread_info.h>
11 
12 #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \
13 				typeof(0?(__force t)0:0ULL), u64))
14 
15 #define __SC_DELOUSE(t,v) ({ \
16 	BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
17 	(__force t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
18 })
19 
20 #define PSW32_MASK_PER		0x40000000UL
21 #define PSW32_MASK_DAT		0x04000000UL
22 #define PSW32_MASK_IO		0x02000000UL
23 #define PSW32_MASK_EXT		0x01000000UL
24 #define PSW32_MASK_KEY		0x00F00000UL
25 #define PSW32_MASK_BASE		0x00080000UL	/* Always one */
26 #define PSW32_MASK_MCHECK	0x00040000UL
27 #define PSW32_MASK_WAIT		0x00020000UL
28 #define PSW32_MASK_PSTATE	0x00010000UL
29 #define PSW32_MASK_ASC		0x0000C000UL
30 #define PSW32_MASK_CC		0x00003000UL
31 #define PSW32_MASK_PM		0x00000f00UL
32 #define PSW32_MASK_RI		0x00000080UL
33 
34 #define PSW32_MASK_USER		0x0000FF00UL
35 
36 #define PSW32_ADDR_AMODE	0x80000000UL
37 #define PSW32_ADDR_INSN		0x7FFFFFFFUL
38 
39 #define PSW32_DEFAULT_KEY	(((u32) PAGE_DEFAULT_ACC) << 20)
40 
41 #define PSW32_ASC_PRIMARY	0x00000000UL
42 #define PSW32_ASC_ACCREG	0x00004000UL
43 #define PSW32_ASC_SECONDARY	0x00008000UL
44 #define PSW32_ASC_HOME		0x0000C000UL
45 
46 #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \
47 			 PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \
48 			 PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \
49 			 PSW32_ASC_PRIMARY)
50 
51 #define COMPAT_USER_HZ		100
52 #define COMPAT_UTS_MACHINE	"s390\0\0\0\0"
53 
54 typedef u32		compat_size_t;
55 typedef s32		compat_ssize_t;
56 typedef s32		compat_time_t;
57 typedef s32		compat_clock_t;
58 typedef s32		compat_pid_t;
59 typedef u16		__compat_uid_t;
60 typedef u16		__compat_gid_t;
61 typedef u32		__compat_uid32_t;
62 typedef u32		__compat_gid32_t;
63 typedef u16		compat_mode_t;
64 typedef u32		compat_ino_t;
65 typedef u16		compat_dev_t;
66 typedef s32		compat_off_t;
67 typedef s64		compat_loff_t;
68 typedef u16		compat_nlink_t;
69 typedef u16		compat_ipc_pid_t;
70 typedef s32		compat_daddr_t;
71 typedef u32		compat_caddr_t;
72 typedef __kernel_fsid_t	compat_fsid_t;
73 typedef s32		compat_key_t;
74 typedef s32		compat_timer_t;
75 
76 typedef s32		compat_int_t;
77 typedef s32		compat_long_t;
78 typedef s64		compat_s64;
79 typedef u32		compat_uint_t;
80 typedef u32		compat_ulong_t;
81 typedef u64		compat_u64;
82 typedef u32		compat_uptr_t;
83 
84 typedef struct {
85 	u32 mask;
86 	u32 addr;
87 } __aligned(8) psw_compat_t;
88 
89 typedef struct {
90 	psw_compat_t psw;
91 	u32 gprs[NUM_GPRS];
92 	u32 acrs[NUM_ACRS];
93 	u32 orig_gpr2;
94 } s390_compat_regs;
95 
96 typedef struct {
97 	u32 gprs_high[NUM_GPRS];
98 } s390_compat_regs_high;
99 
100 struct compat_timespec {
101 	compat_time_t	tv_sec;
102 	s32		tv_nsec;
103 };
104 
105 struct compat_timeval {
106 	compat_time_t	tv_sec;
107 	s32		tv_usec;
108 };
109 
110 struct compat_stat {
111 	compat_dev_t	st_dev;
112 	u16		__pad1;
113 	compat_ino_t	st_ino;
114 	compat_mode_t	st_mode;
115 	compat_nlink_t	st_nlink;
116 	__compat_uid_t	st_uid;
117 	__compat_gid_t	st_gid;
118 	compat_dev_t	st_rdev;
119 	u16		__pad2;
120 	u32		st_size;
121 	u32		st_blksize;
122 	u32		st_blocks;
123 	u32		st_atime;
124 	u32		st_atime_nsec;
125 	u32		st_mtime;
126 	u32		st_mtime_nsec;
127 	u32		st_ctime;
128 	u32		st_ctime_nsec;
129 	u32		__unused4;
130 	u32		__unused5;
131 };
132 
133 struct compat_flock {
134 	short		l_type;
135 	short		l_whence;
136 	compat_off_t	l_start;
137 	compat_off_t	l_len;
138 	compat_pid_t	l_pid;
139 };
140 
141 #define F_GETLK64       12
142 #define F_SETLK64       13
143 #define F_SETLKW64      14
144 
145 struct compat_flock64 {
146 	short		l_type;
147 	short		l_whence;
148 	compat_loff_t	l_start;
149 	compat_loff_t	l_len;
150 	compat_pid_t	l_pid;
151 };
152 
153 struct compat_statfs {
154 	u32		f_type;
155 	u32		f_bsize;
156 	u32		f_blocks;
157 	u32		f_bfree;
158 	u32		f_bavail;
159 	u32		f_files;
160 	u32		f_ffree;
161 	compat_fsid_t	f_fsid;
162 	u32		f_namelen;
163 	u32		f_frsize;
164 	u32		f_flags;
165 	u32		f_spare[4];
166 };
167 
168 struct compat_statfs64 {
169 	u32		f_type;
170 	u32		f_bsize;
171 	u64		f_blocks;
172 	u64		f_bfree;
173 	u64		f_bavail;
174 	u64		f_files;
175 	u64		f_ffree;
176 	compat_fsid_t	f_fsid;
177 	u32		f_namelen;
178 	u32		f_frsize;
179 	u32		f_flags;
180 	u32		f_spare[4];
181 };
182 
183 #define COMPAT_RLIM_INFINITY		0xffffffff
184 
185 typedef u32		compat_old_sigset_t;	/* at least 32 bits */
186 
187 #define _COMPAT_NSIG		64
188 #define _COMPAT_NSIG_BPW	32
189 
190 typedef u32		compat_sigset_word;
191 
192 typedef union compat_sigval {
193 	compat_int_t	sival_int;
194 	compat_uptr_t	sival_ptr;
195 } compat_sigval_t;
196 
197 typedef struct compat_siginfo {
198 	int	si_signo;
199 	int	si_errno;
200 	int	si_code;
201 
202 	union {
203 		int _pad[128/sizeof(int) - 3];
204 
205 		/* kill() */
206 		struct {
207 			pid_t	_pid;	/* sender's pid */
208 			uid_t	_uid;	/* sender's uid */
209 		} _kill;
210 
211 		/* POSIX.1b timers */
212 		struct {
213 			compat_timer_t _tid;		/* timer id */
214 			int _overrun;			/* overrun count */
215 			compat_sigval_t _sigval;	/* same as below */
216 			int _sys_private;	/* not to be passed to user */
217 		} _timer;
218 
219 		/* POSIX.1b signals */
220 		struct {
221 			pid_t			_pid;	/* sender's pid */
222 			uid_t			_uid;	/* sender's uid */
223 			compat_sigval_t		_sigval;
224 		} _rt;
225 
226 		/* SIGCHLD */
227 		struct {
228 			pid_t			_pid;	/* which child */
229 			uid_t			_uid;	/* sender's uid */
230 			int			_status;/* exit code */
231 			compat_clock_t		_utime;
232 			compat_clock_t		_stime;
233 		} _sigchld;
234 
235 		/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
236 		struct {
237 			__u32	_addr;	/* faulting insn/memory ref. - pointer */
238 		} _sigfault;
239 
240 		/* SIGPOLL */
241 		struct {
242 			int	_band;	/* POLL_IN, POLL_OUT, POLL_MSG */
243 			int	_fd;
244 		} _sigpoll;
245 	} _sifields;
246 } compat_siginfo_t;
247 
248 /*
249  * How these fields are to be accessed.
250  */
251 #define si_pid		_sifields._kill._pid
252 #define si_uid		_sifields._kill._uid
253 #define si_status	_sifields._sigchld._status
254 #define si_utime	_sifields._sigchld._utime
255 #define si_stime	_sifields._sigchld._stime
256 #define si_value	_sifields._rt._sigval
257 #define si_int		_sifields._rt._sigval.sival_int
258 #define si_ptr		_sifields._rt._sigval.sival_ptr
259 #define si_addr		_sifields._sigfault._addr
260 #define si_band		_sifields._sigpoll._band
261 #define si_fd		_sifields._sigpoll._fd
262 #define si_tid		_sifields._timer._tid
263 #define si_overrun	_sifields._timer._overrun
264 
265 #define COMPAT_OFF_T_MAX	0x7fffffff
266 
267 /*
268  * A pointer passed in from user mode. This should not
269  * be used for syscall parameters, just declare them
270  * as pointers because the syscall entry code will have
271  * appropriately converted them already.
272  */
273 
274 static inline void __user *compat_ptr(compat_uptr_t uptr)
275 {
276 	return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
277 }
278 
279 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
280 {
281 	return (u32)(unsigned long)uptr;
282 }
283 
284 #ifdef CONFIG_COMPAT
285 
286 static inline int is_compat_task(void)
287 {
288 	return test_thread_flag(TIF_31BIT);
289 }
290 
291 static inline void __user *arch_compat_alloc_user_space(long len)
292 {
293 	unsigned long stack;
294 
295 	stack = KSTK_ESP(current);
296 	if (is_compat_task())
297 		stack &= 0x7fffffffUL;
298 	return (void __user *) (stack - len);
299 }
300 
301 #endif
302 
303 struct compat_ipc64_perm {
304 	compat_key_t key;
305 	__compat_uid32_t uid;
306 	__compat_gid32_t gid;
307 	__compat_uid32_t cuid;
308 	__compat_gid32_t cgid;
309 	compat_mode_t mode;
310 	unsigned short __pad1;
311 	unsigned short seq;
312 	unsigned short __pad2;
313 	unsigned int __unused1;
314 	unsigned int __unused2;
315 };
316 
317 struct compat_semid64_ds {
318 	struct compat_ipc64_perm sem_perm;
319 	compat_time_t  sem_otime;
320 	compat_ulong_t __pad1;
321 	compat_time_t  sem_ctime;
322 	compat_ulong_t __pad2;
323 	compat_ulong_t sem_nsems;
324 	compat_ulong_t __unused1;
325 	compat_ulong_t __unused2;
326 };
327 
328 struct compat_msqid64_ds {
329 	struct compat_ipc64_perm msg_perm;
330 	compat_time_t   msg_stime;
331 	compat_ulong_t __pad1;
332 	compat_time_t   msg_rtime;
333 	compat_ulong_t __pad2;
334 	compat_time_t   msg_ctime;
335 	compat_ulong_t __pad3;
336 	compat_ulong_t msg_cbytes;
337 	compat_ulong_t msg_qnum;
338 	compat_ulong_t msg_qbytes;
339 	compat_pid_t   msg_lspid;
340 	compat_pid_t   msg_lrpid;
341 	compat_ulong_t __unused1;
342 	compat_ulong_t __unused2;
343 };
344 
345 struct compat_shmid64_ds {
346 	struct compat_ipc64_perm shm_perm;
347 	compat_size_t  shm_segsz;
348 	compat_time_t  shm_atime;
349 	compat_ulong_t __pad1;
350 	compat_time_t  shm_dtime;
351 	compat_ulong_t __pad2;
352 	compat_time_t  shm_ctime;
353 	compat_ulong_t __pad3;
354 	compat_pid_t   shm_cpid;
355 	compat_pid_t   shm_lpid;
356 	compat_ulong_t shm_nattch;
357 	compat_ulong_t __unused1;
358 	compat_ulong_t __unused2;
359 };
360 #endif /* _ASM_S390X_COMPAT_H */
361