xref: /openbmc/linux/arch/s390/include/asm/compat.h (revision b8d312aa)
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 #include <asm-generic/compat.h>
13 
14 #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \
15 				typeof(0?(__force t)0:0ULL), u64))
16 
17 #define __SC_DELOUSE(t,v) ({ \
18 	BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \
19 	(__force t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \
20 })
21 
22 #define PSW32_MASK_PER		0x40000000UL
23 #define PSW32_MASK_DAT		0x04000000UL
24 #define PSW32_MASK_IO		0x02000000UL
25 #define PSW32_MASK_EXT		0x01000000UL
26 #define PSW32_MASK_KEY		0x00F00000UL
27 #define PSW32_MASK_BASE		0x00080000UL	/* Always one */
28 #define PSW32_MASK_MCHECK	0x00040000UL
29 #define PSW32_MASK_WAIT		0x00020000UL
30 #define PSW32_MASK_PSTATE	0x00010000UL
31 #define PSW32_MASK_ASC		0x0000C000UL
32 #define PSW32_MASK_CC		0x00003000UL
33 #define PSW32_MASK_PM		0x00000f00UL
34 #define PSW32_MASK_RI		0x00000080UL
35 
36 #define PSW32_MASK_USER		0x0000FF00UL
37 
38 #define PSW32_ADDR_AMODE	0x80000000UL
39 #define PSW32_ADDR_INSN		0x7FFFFFFFUL
40 
41 #define PSW32_DEFAULT_KEY	(((u32) PAGE_DEFAULT_ACC) << 20)
42 
43 #define PSW32_ASC_PRIMARY	0x00000000UL
44 #define PSW32_ASC_ACCREG	0x00004000UL
45 #define PSW32_ASC_SECONDARY	0x00008000UL
46 #define PSW32_ASC_HOME		0x0000C000UL
47 
48 #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \
49 			 PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \
50 			 PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \
51 			 PSW32_ASC_PRIMARY)
52 
53 #define COMPAT_USER_HZ		100
54 #define COMPAT_UTS_MACHINE	"s390\0\0\0\0"
55 
56 typedef u16		__compat_uid_t;
57 typedef u16		__compat_gid_t;
58 typedef u32		__compat_uid32_t;
59 typedef u32		__compat_gid32_t;
60 typedef u16		compat_mode_t;
61 typedef u16		compat_dev_t;
62 typedef u16		compat_nlink_t;
63 typedef u16		compat_ipc_pid_t;
64 typedef u32		compat_caddr_t;
65 typedef __kernel_fsid_t	compat_fsid_t;
66 typedef s64		compat_s64;
67 typedef u64		compat_u64;
68 
69 typedef struct {
70 	u32 mask;
71 	u32 addr;
72 } __aligned(8) psw_compat_t;
73 
74 typedef struct {
75 	psw_compat_t psw;
76 	u32 gprs[NUM_GPRS];
77 	u32 acrs[NUM_ACRS];
78 	u32 orig_gpr2;
79 } s390_compat_regs;
80 
81 typedef struct {
82 	u32 gprs_high[NUM_GPRS];
83 } s390_compat_regs_high;
84 
85 struct compat_stat {
86 	compat_dev_t	st_dev;
87 	u16		__pad1;
88 	compat_ino_t	st_ino;
89 	compat_mode_t	st_mode;
90 	compat_nlink_t	st_nlink;
91 	__compat_uid_t	st_uid;
92 	__compat_gid_t	st_gid;
93 	compat_dev_t	st_rdev;
94 	u16		__pad2;
95 	u32		st_size;
96 	u32		st_blksize;
97 	u32		st_blocks;
98 	u32		st_atime;
99 	u32		st_atime_nsec;
100 	u32		st_mtime;
101 	u32		st_mtime_nsec;
102 	u32		st_ctime;
103 	u32		st_ctime_nsec;
104 	u32		__unused4;
105 	u32		__unused5;
106 };
107 
108 struct compat_flock {
109 	short		l_type;
110 	short		l_whence;
111 	compat_off_t	l_start;
112 	compat_off_t	l_len;
113 	compat_pid_t	l_pid;
114 };
115 
116 #define F_GETLK64       12
117 #define F_SETLK64       13
118 #define F_SETLKW64      14
119 
120 struct compat_flock64 {
121 	short		l_type;
122 	short		l_whence;
123 	compat_loff_t	l_start;
124 	compat_loff_t	l_len;
125 	compat_pid_t	l_pid;
126 };
127 
128 struct compat_statfs {
129 	u32		f_type;
130 	u32		f_bsize;
131 	u32		f_blocks;
132 	u32		f_bfree;
133 	u32		f_bavail;
134 	u32		f_files;
135 	u32		f_ffree;
136 	compat_fsid_t	f_fsid;
137 	u32		f_namelen;
138 	u32		f_frsize;
139 	u32		f_flags;
140 	u32		f_spare[4];
141 };
142 
143 struct compat_statfs64 {
144 	u32		f_type;
145 	u32		f_bsize;
146 	u64		f_blocks;
147 	u64		f_bfree;
148 	u64		f_bavail;
149 	u64		f_files;
150 	u64		f_ffree;
151 	compat_fsid_t	f_fsid;
152 	u32		f_namelen;
153 	u32		f_frsize;
154 	u32		f_flags;
155 	u32		f_spare[4];
156 };
157 
158 #define COMPAT_RLIM_INFINITY		0xffffffff
159 
160 typedef u32		compat_old_sigset_t;	/* at least 32 bits */
161 
162 #define _COMPAT_NSIG		64
163 #define _COMPAT_NSIG_BPW	32
164 
165 typedef u32		compat_sigset_word;
166 
167 #define COMPAT_OFF_T_MAX	0x7fffffff
168 
169 /*
170  * A pointer passed in from user mode. This should not
171  * be used for syscall parameters, just declare them
172  * as pointers because the syscall entry code will have
173  * appropriately converted them already.
174  */
175 
176 static inline void __user *compat_ptr(compat_uptr_t uptr)
177 {
178 	return (void __user *)(unsigned long)(uptr & 0x7fffffffUL);
179 }
180 
181 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
182 {
183 	return (u32)(unsigned long)uptr;
184 }
185 
186 #ifdef CONFIG_COMPAT
187 
188 static inline int is_compat_task(void)
189 {
190 	return test_thread_flag(TIF_31BIT);
191 }
192 
193 static inline void __user *arch_compat_alloc_user_space(long len)
194 {
195 	unsigned long stack;
196 
197 	stack = KSTK_ESP(current);
198 	if (is_compat_task())
199 		stack &= 0x7fffffffUL;
200 	return (void __user *) (stack - len);
201 }
202 
203 #endif
204 
205 struct compat_ipc64_perm {
206 	compat_key_t key;
207 	__compat_uid32_t uid;
208 	__compat_gid32_t gid;
209 	__compat_uid32_t cuid;
210 	__compat_gid32_t cgid;
211 	compat_mode_t mode;
212 	unsigned short __pad1;
213 	unsigned short seq;
214 	unsigned short __pad2;
215 	unsigned int __unused1;
216 	unsigned int __unused2;
217 };
218 
219 struct compat_semid64_ds {
220 	struct compat_ipc64_perm sem_perm;
221 	compat_ulong_t sem_otime;
222 	compat_ulong_t sem_otime_high;
223 	compat_ulong_t sem_ctime;
224 	compat_ulong_t sem_ctime_high;
225 	compat_ulong_t sem_nsems;
226 	compat_ulong_t __unused1;
227 	compat_ulong_t __unused2;
228 };
229 
230 struct compat_msqid64_ds {
231 	struct compat_ipc64_perm msg_perm;
232 	compat_ulong_t msg_stime;
233 	compat_ulong_t msg_stime_high;
234 	compat_ulong_t msg_rtime;
235 	compat_ulong_t msg_rtime_high;
236 	compat_ulong_t msg_ctime;
237 	compat_ulong_t msg_ctime_high;
238 	compat_ulong_t msg_cbytes;
239 	compat_ulong_t msg_qnum;
240 	compat_ulong_t msg_qbytes;
241 	compat_pid_t   msg_lspid;
242 	compat_pid_t   msg_lrpid;
243 	compat_ulong_t __unused1;
244 	compat_ulong_t __unused2;
245 };
246 
247 struct compat_shmid64_ds {
248 	struct compat_ipc64_perm shm_perm;
249 	compat_size_t  shm_segsz;
250 	compat_ulong_t shm_atime;
251 	compat_ulong_t shm_atime_high;
252 	compat_ulong_t shm_dtime;
253 	compat_ulong_t shm_dtime_high;
254 	compat_ulong_t shm_ctime;
255 	compat_ulong_t shm_ctime_high;
256 	compat_pid_t   shm_cpid;
257 	compat_pid_t   shm_lpid;
258 	compat_ulong_t shm_nattch;
259 	compat_ulong_t __unused1;
260 	compat_ulong_t __unused2;
261 };
262 #endif /* _ASM_S390X_COMPAT_H */
263