Skip to content

Commit 7eb6369

Browse files
RISC-V: Add support for rv32 userspace via COMPAT
The RISC-V port supports the rv32i and rv64i base ISAs, but provides no mechanism to run 32-bit userspace on 64-bit systems. This adds that support, via the COMPAT framework. As the RISC-V ISAs (and uABIs) were developed concurrently, the resulting compat support is mostly generic. This includes a handful of cleanups to the generic compat infrastructure to more cleanly support RISC-V, followed by the RISC-V implementation. * palmer/riscv-compat: riscv: compat: Add COMPAT Kbuild skeletal support riscv: compat: ptrace: Add compat_arch_ptrace implement riscv: compat: signal: Add rt_frame implementation riscv: compat: vdso: Add setup additional pages implementation riscv: compat: vdso: Add COMPAT_VDSO base code implementation riscv: compat: Add hw capability check for elf riscv: compat: Add elf.h implementation riscv: compat: process: Add UXL_32 support in start_thread riscv: compat: syscall: Add entry.S implementation riscv: compat: syscall: Add compat_sys_call_table implementation riscv: compat: Support TASK_SIZE for compat mode riscv: compat: Add basic compat data type implementation riscv: Fixup difference with defconfig syscalls: compat: Fix the missing part for __SYSCALL_COMPAT asm-generic: compat: Cleanup duplicate definitions fs: stat: compat: Add __ARCH_WANT_COMPAT_STAT arch: Add SYSVIPC_COMPAT for all architectures compat: consolidate the compat_flock{,64} definition uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h uapi: simplify __ARCH_FLOCK{,64}_PAD a little
2 parents 93c0651 + 9be8459 commit 7eb6369

68 files changed

Lines changed: 1219 additions & 563 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/arm64/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,10 +2122,6 @@ config DMI
21222122

21232123
endmenu
21242124

2125-
config SYSVIPC_COMPAT
2126-
def_bool y
2127-
depends on COMPAT && SYSVIPC
2128-
21292125
menu "Power management options"
21302126

21312127
source "kernel/power/Kconfig"

arch/arm64/include/asm/compat.h

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
#define compat_mode_t compat_mode_t
99
typedef u16 compat_mode_t;
1010

11+
#define __compat_uid_t __compat_uid_t
12+
typedef u16 __compat_uid_t;
13+
typedef u16 __compat_gid_t;
14+
15+
#define compat_ipc_pid_t compat_ipc_pid_t
16+
typedef u16 compat_ipc_pid_t;
17+
18+
#define compat_statfs compat_statfs
19+
1120
#include <asm-generic/compat.h>
1221

1322
#ifdef CONFIG_COMPAT
@@ -19,21 +28,15 @@ typedef u16 compat_mode_t;
1928
#include <linux/sched.h>
2029
#include <linux/sched/task_stack.h>
2130

22-
#define COMPAT_USER_HZ 100
2331
#ifdef __AARCH64EB__
2432
#define COMPAT_UTS_MACHINE "armv8b\0\0"
2533
#else
2634
#define COMPAT_UTS_MACHINE "armv8l\0\0"
2735
#endif
2836

29-
typedef u16 __compat_uid_t;
30-
typedef u16 __compat_gid_t;
3137
typedef u16 __compat_uid16_t;
3238
typedef u16 __compat_gid16_t;
33-
typedef u32 compat_dev_t;
3439
typedef s32 compat_nlink_t;
35-
typedef u16 compat_ipc_pid_t;
36-
typedef __kernel_fsid_t compat_fsid_t;
3740

3841
struct compat_stat {
3942
#ifdef __AARCH64EB__
@@ -65,26 +68,6 @@ struct compat_stat {
6568
compat_ulong_t __unused4[2];
6669
};
6770

68-
struct compat_flock {
69-
short l_type;
70-
short l_whence;
71-
compat_off_t l_start;
72-
compat_off_t l_len;
73-
compat_pid_t l_pid;
74-
};
75-
76-
#define F_GETLK64 12 /* using 'struct flock64' */
77-
#define F_SETLK64 13
78-
#define F_SETLKW64 14
79-
80-
struct compat_flock64 {
81-
short l_type;
82-
short l_whence;
83-
compat_loff_t l_start;
84-
compat_loff_t l_len;
85-
compat_pid_t l_pid;
86-
};
87-
8871
struct compat_statfs {
8972
int f_type;
9073
int f_bsize;
@@ -107,64 +90,6 @@ struct compat_statfs {
10790
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
10891
#define COMPAT_MINSIGSTKSZ 2048
10992

110-
struct compat_ipc64_perm {
111-
compat_key_t key;
112-
__compat_uid32_t uid;
113-
__compat_gid32_t gid;
114-
__compat_uid32_t cuid;
115-
__compat_gid32_t cgid;
116-
unsigned short mode;
117-
unsigned short __pad1;
118-
unsigned short seq;
119-
unsigned short __pad2;
120-
compat_ulong_t unused1;
121-
compat_ulong_t unused2;
122-
};
123-
124-
struct compat_semid64_ds {
125-
struct compat_ipc64_perm sem_perm;
126-
compat_ulong_t sem_otime;
127-
compat_ulong_t sem_otime_high;
128-
compat_ulong_t sem_ctime;
129-
compat_ulong_t sem_ctime_high;
130-
compat_ulong_t sem_nsems;
131-
compat_ulong_t __unused3;
132-
compat_ulong_t __unused4;
133-
};
134-
135-
struct compat_msqid64_ds {
136-
struct compat_ipc64_perm msg_perm;
137-
compat_ulong_t msg_stime;
138-
compat_ulong_t msg_stime_high;
139-
compat_ulong_t msg_rtime;
140-
compat_ulong_t msg_rtime_high;
141-
compat_ulong_t msg_ctime;
142-
compat_ulong_t msg_ctime_high;
143-
compat_ulong_t msg_cbytes;
144-
compat_ulong_t msg_qnum;
145-
compat_ulong_t msg_qbytes;
146-
compat_pid_t msg_lspid;
147-
compat_pid_t msg_lrpid;
148-
compat_ulong_t __unused4;
149-
compat_ulong_t __unused5;
150-
};
151-
152-
struct compat_shmid64_ds {
153-
struct compat_ipc64_perm shm_perm;
154-
compat_size_t shm_segsz;
155-
compat_ulong_t shm_atime;
156-
compat_ulong_t shm_atime_high;
157-
compat_ulong_t shm_dtime;
158-
compat_ulong_t shm_dtime_high;
159-
compat_ulong_t shm_ctime;
160-
compat_ulong_t shm_ctime_high;
161-
compat_pid_t shm_cpid;
162-
compat_pid_t shm_lpid;
163-
compat_ulong_t shm_nattch;
164-
compat_ulong_t __unused4;
165-
compat_ulong_t __unused5;
166-
};
167-
16893
static inline int is_compat_task(void)
16994
{
17095
return test_thread_flag(TIF_32BIT);

arch/arm64/include/asm/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2012 ARM Ltd.
44
*/
55
#ifdef CONFIG_COMPAT
6+
#define __ARCH_WANT_COMPAT_STAT
67
#define __ARCH_WANT_COMPAT_STAT64
78
#define __ARCH_WANT_SYS_GETHOSTNAME
89
#define __ARCH_WANT_SYS_PAUSE

arch/mips/Kconfig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,16 +3198,12 @@ config MIPS32_COMPAT
31983198
config COMPAT
31993199
bool
32003200

3201-
config SYSVIPC_COMPAT
3202-
bool
3203-
32043201
config MIPS32_O32
32053202
bool "Kernel support for o32 binaries"
32063203
depends on 64BIT
32073204
select ARCH_WANT_OLD_COMPAT_IPC
32083205
select COMPAT
32093206
select MIPS32_COMPAT
3210-
select SYSVIPC_COMPAT if SYSVIPC
32113207
help
32123208
Select this option if you want to run o32 binaries. These are pure
32133209
32-bit binaries as used by the 32-bit Linux/MIPS port. Most of
@@ -3221,7 +3217,6 @@ config MIPS32_N32
32213217
select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
32223218
select COMPAT
32233219
select MIPS32_COMPAT
3224-
select SYSVIPC_COMPAT if SYSVIPC
32253220
help
32263221
Select this option if you want to run n32 binaries. These are
32273222
64-bit binaries using 32-bit quantities for addressing and certain

arch/mips/include/asm/compat.h

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
#include <asm/page.h>
1010
#include <asm/ptrace.h>
1111

12+
#define __compat_uid_t __compat_uid_t
1213
typedef s32 __compat_uid_t;
1314
typedef s32 __compat_gid_t;
15+
1416
typedef __compat_uid_t __compat_uid32_t;
1517
typedef __compat_gid_t __compat_gid32_t;
1618
#define __compat_uid32_t __compat_uid32_t
17-
#define __compat_gid32_t __compat_gid32_t
19+
20+
#define compat_statfs compat_statfs
21+
#define compat_ipc64_perm compat_ipc64_perm
1822

1923
#define _COMPAT_NSIG 128 /* Don't ask !$@#% ... */
2024
#define _COMPAT_NSIG_BPW 32
2125
typedef u32 compat_sigset_word;
2226

27+
#define COMPAT_RLIM_INFINITY 0x7fffffffUL
28+
2329
#include <asm-generic/compat.h>
2430

25-
#define COMPAT_USER_HZ 100
2631
#define COMPAT_UTS_MACHINE "mips\0\0\0"
2732

28-
typedef u32 compat_dev_t;
2933
typedef u32 compat_nlink_t;
30-
typedef s32 compat_ipc_pid_t;
31-
typedef struct {
32-
s32 val[2];
33-
} compat_fsid_t;
3434

3535
struct compat_stat {
3636
compat_dev_t st_dev;
@@ -55,27 +55,8 @@ struct compat_stat {
5555
s32 st_pad4[14];
5656
};
5757

58-
struct compat_flock {
59-
short l_type;
60-
short l_whence;
61-
compat_off_t l_start;
62-
compat_off_t l_len;
63-
s32 l_sysid;
64-
compat_pid_t l_pid;
65-
s32 pad[4];
66-
};
67-
68-
#define F_GETLK64 33
69-
#define F_SETLK64 34
70-
#define F_SETLKW64 35
71-
72-
struct compat_flock64 {
73-
short l_type;
74-
short l_whence;
75-
compat_loff_t l_start;
76-
compat_loff_t l_len;
77-
compat_pid_t l_pid;
78-
};
58+
#define __ARCH_COMPAT_FLOCK_EXTRA_SYSID s32 l_sysid;
59+
#define __ARCH_COMPAT_FLOCK_PAD s32 pad[4];
7960

8061
struct compat_statfs {
8162
int f_type;
@@ -92,10 +73,6 @@ struct compat_statfs {
9273
int f_spare[5];
9374
};
9475

95-
#define COMPAT_RLIM_INFINITY 0x7fffffffUL
96-
97-
#define COMPAT_OFF_T_MAX 0x7fffffff
98-
9976
struct compat_ipc64_perm {
10077
compat_key_t key;
10178
__compat_uid32_t uid;

arch/mips/include/asm/unistd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
# ifdef CONFIG_32BIT
5151
# define __ARCH_WANT_STAT64
5252
# define __ARCH_WANT_SYS_TIME32
53+
# else
54+
# define __ARCH_WANT_COMPAT_STAT
5355
# endif
5456
# ifdef CONFIG_MIPS32_O32
5557
# define __ARCH_WANT_SYS_TIME32

arch/mips/include/uapi/asm/fcntl.h

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,16 @@
4444
#define F_SETOWN 24 /* for sockets. */
4545
#define F_GETOWN 23 /* for sockets. */
4646

47-
#ifndef __mips64
47+
#if __BITS_PER_LONG == 32 || defined(__KERNEL__)
4848
#define F_GETLK64 33 /* using 'struct flock64' */
4949
#define F_SETLK64 34
5050
#define F_SETLKW64 35
51-
#endif
52-
53-
/*
54-
* The flavours of struct flock. "struct flock" is the ABI compliant
55-
* variant. Finally struct flock64 is the LFS variant of struct flock. As
56-
* a historic accident and inconsistence with the ABI definition it doesn't
57-
* contain all the same fields as struct flock.
58-
*/
51+
#endif /* __BITS_PER_LONG == 32 || defined(__KERNEL__) */
5952

6053
#if _MIPS_SIM != _MIPS_SIM_ABI64
61-
62-
#include <linux/types.h>
63-
64-
struct flock {
65-
short l_type;
66-
short l_whence;
67-
__kernel_off_t l_start;
68-
__kernel_off_t l_len;
69-
long l_sysid;
70-
__kernel_pid_t l_pid;
71-
long pad[4];
72-
};
73-
74-
#define HAVE_ARCH_STRUCT_FLOCK
75-
76-
#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
54+
#define __ARCH_FLOCK_EXTRA_SYSID long l_sysid;
55+
#define __ARCH_FLOCK_PAD long pad[4];
56+
#endif
7757

7858
#include <asm-generic/fcntl.h>
7959

arch/parisc/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,6 @@ config COMPAT
331331
def_bool y
332332
depends on 64BIT
333333

334-
config SYSVIPC_COMPAT
335-
def_bool y
336-
depends on COMPAT && SYSVIPC
337-
338334
config AUDIT_ARCH
339335
def_bool y
340336

arch/parisc/include/asm/compat.h

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
#define compat_mode_t compat_mode_t
1212
typedef u16 compat_mode_t;
1313

14+
#define compat_ipc_pid_t compat_ipc_pid_t
15+
typedef u16 compat_ipc_pid_t;
16+
17+
#define compat_ipc64_perm compat_ipc64_perm
18+
1419
#include <asm-generic/compat.h>
1520

16-
#define COMPAT_USER_HZ 100
1721
#define COMPAT_UTS_MACHINE "parisc\0\0"
1822

19-
typedef u32 __compat_uid_t;
20-
typedef u32 __compat_gid_t;
21-
typedef u32 compat_dev_t;
2223
typedef u16 compat_nlink_t;
23-
typedef u16 compat_ipc_pid_t;
2424

2525
struct compat_stat {
2626
compat_dev_t st_dev; /* dev_t is 32 bits on parisc */
@@ -53,37 +53,6 @@ struct compat_stat {
5353
u32 st_spare4[3];
5454
};
5555

56-
struct compat_flock {
57-
short l_type;
58-
short l_whence;
59-
compat_off_t l_start;
60-
compat_off_t l_len;
61-
compat_pid_t l_pid;
62-
};
63-
64-
struct compat_flock64 {
65-
short l_type;
66-
short l_whence;
67-
compat_loff_t l_start;
68-
compat_loff_t l_len;
69-
compat_pid_t l_pid;
70-
};
71-
72-
struct compat_statfs {
73-
s32 f_type;
74-
s32 f_bsize;
75-
s32 f_blocks;
76-
s32 f_bfree;
77-
s32 f_bavail;
78-
s32 f_files;
79-
s32 f_ffree;
80-
__kernel_fsid_t f_fsid;
81-
s32 f_namelen;
82-
s32 f_frsize;
83-
s32 f_flags;
84-
s32 f_spare[4];
85-
};
86-
8756
struct compat_sigcontext {
8857
compat_int_t sc_flags;
8958
compat_int_t sc_gr[32]; /* PSW in sc_gr[0] */
@@ -93,10 +62,6 @@ struct compat_sigcontext {
9362
compat_int_t sc_sar; /* cr11 */
9463
};
9564

96-
#define COMPAT_RLIM_INFINITY 0xffffffff
97-
98-
#define COMPAT_OFF_T_MAX 0x7fffffff
99-
10065
struct compat_ipc64_perm {
10166
compat_key_t key;
10267
__compat_uid_t uid;

arch/parisc/include/asm/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
164164
#define __ARCH_WANT_SYS_CLONE
165165
#define __ARCH_WANT_SYS_CLONE3
166166
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
167+
#define __ARCH_WANT_COMPAT_STAT
167168

168169
#ifdef CONFIG_64BIT
169170
#define __ARCH_WANT_SYS_TIME

0 commit comments

Comments
 (0)