Skip to contentSkip to conversation

asm-generic: compat: Cleanup duplicate definitions

PATCH Superseded [email protected] 3 participants 4 messages Jan 20, 2022 – Jan 28, 2022

Subsystems (10)
x86 PowerPC MIPS RISC-V +6 more subsystems

v3 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v3 3/17 asm-generic: compat: Cleanup duplicate definitions

From: Guo Ren <[email protected]>

There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate:
- COMPAT_USER_HZ
- COMPAT_RLIM_INFINITY
- COMPAT_OFF_T_MAX
- __compat_uid_t, __compat_uid_t
- compat_dev_t
- compat_ipc_pid_t
- struct compat_flock
- struct compat_flock64
- struct compat_statfs
- struct compat_ipc64_perm, compat_semid64_ds, compat_msqid64_ds, compat_shmid64_ds

Cleanup duplicate definitions and merge them into asm-generic.

---
 arch/arm64/include/asm/compat.h   | 108 +++-----------------------
 arch/mips/include/asm/compat.h    |  24 ++----
 arch/parisc/include/asm/compat.h  |  47 ++----------
 arch/powerpc/include/asm/compat.h |  47 ++----------
 arch/s390/include/asm/compat.h    | 109 +++-----------------------
 arch/sparc/include/asm/compat.h   |  39 ++++------
 arch/x86/include/asm/compat.h     | 114 +++-------------------------
 include/asm-generic/compat.h      | 122 ++++++++++++++++++++++++++++++
 8 files changed, 191 insertions(+), 419 deletions(-)
arch/arm64/include/asm/compat.h +9 -99
index eaa6ca062d89..f54f295efae3 100644
@@ -5,9 +5,18 @@
 #ifndef __ASM_COMPAT_H
 #define __ASM_COMPAT_H
 
+#define COMPAT_RLIM_INFINITY		0xffffffff
+
 #define compat_mode_t compat_mode_t
 typedef u16		compat_mode_t;
 
+#define __compat_uid_t	__compat_uid_t
+typedef u16		__compat_uid_t;
+typedef u16		__compat_gid_t;
+
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16		 compat_ipc_pid_t;
+
 #include <asm-generic/compat.h>
 
 #ifdef CONFIG_COMPAT
@@ -19,21 +28,15 @@ typedef u16		compat_mode_t;
 #include <linux/sched.h>
 #include <linux/sched/task_stack.h>
 
-#define COMPAT_USER_HZ		100
 #ifdef __AARCH64EB__
 #define COMPAT_UTS_MACHINE	"armv8b\0\0"
 #else
 #define COMPAT_UTS_MACHINE	"armv8l\0\0"
 #endif
 
-typedef u16		__compat_uid_t;
-typedef u16		__compat_gid_t;
 typedef u16		__compat_uid16_t;
 typedef u16		__compat_gid16_t;
-typedef u32		compat_dev_t;
 typedef s32		compat_nlink_t;
-typedef u16		compat_ipc_pid_t;
-typedef __kernel_fsid_t	compat_fsid_t;
 
 struct compat_stat {
 #ifdef __AARCH64EB__
@@ -65,106 +68,13 @@ struct compat_stat {
 	compat_ulong_t	__unused4[2];
 };
 
-struct compat_flock {
-	short		l_type;
-	short		l_whence;
-	compat_off_t	l_start;
-	compat_off_t	l_len;
-	compat_pid_t	l_pid;
-};
-
 #define F_GETLK64	12	/*  using 'struct flock64' */
 #define F_SETLK64	13
 #define F_SETLKW64	14
 
-struct compat_flock64 {
-	short		l_type;
-	short		l_whence;
-	compat_loff_t	l_start;
-	compat_loff_t	l_len;
-	compat_pid_t	l_pid;
-};
-
-struct compat_statfs {
-	int		f_type;
-	int		f_bsize;
-	int		f_blocks;
-	int		f_bfree;
-	int		f_bavail;
-	int		f_files;
-	int		f_ffree;
-	compat_fsid_t	f_fsid;
-	int		f_namelen;	/* SunOS ignores this field. */
-	int		f_frsize;
-	int		f_flags;
-	int		f_spare[4];
-};
-
-#define COMPAT_RLIM_INFINITY		0xffffffff
-
-#define COMPAT_OFF_T_MAX	0x7fffffff
-
 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
 #define COMPAT_MINSIGSTKSZ	2048
 
-struct compat_ipc64_perm {
-	compat_key_t key;
-	__compat_uid32_t uid;
-	__compat_gid32_t gid;
-	__compat_uid32_t cuid;
-	__compat_gid32_t cgid;
-	unsigned short mode;
-	unsigned short __pad1;
-	unsigned short seq;
-	unsigned short __pad2;
-	compat_ulong_t unused1;
-	compat_ulong_t unused2;
-};
-
-struct compat_semid64_ds {
-	struct compat_ipc64_perm sem_perm;
-	compat_ulong_t sem_otime;
-	compat_ulong_t sem_otime_high;
-	compat_ulong_t sem_ctime;
-	compat_ulong_t sem_ctime_high;
-	compat_ulong_t sem_nsems;
-	compat_ulong_t __unused3;
-	compat_ulong_t __unused4;
-};
-
-struct compat_msqid64_ds {
-	struct compat_ipc64_perm msg_perm;
-	compat_ulong_t msg_stime;
-	compat_ulong_t msg_stime_high;
-	compat_ulong_t msg_rtime;
-	compat_ulong_t msg_rtime_high;
-	compat_ulong_t msg_ctime;
-	compat_ulong_t msg_ctime_high;
-	compat_ulong_t msg_cbytes;
-	compat_ulong_t msg_qnum;
-	compat_ulong_t msg_qbytes;
-	compat_pid_t   msg_lspid;
-	compat_pid_t   msg_lrpid;
-	compat_ulong_t __unused4;
-	compat_ulong_t __unused5;
-};
-
-struct compat_shmid64_ds {
-	struct compat_ipc64_perm shm_perm;
-	compat_size_t  shm_segsz;
-	compat_ulong_t shm_atime;
-	compat_ulong_t shm_atime_high;
-	compat_ulong_t shm_dtime;
-	compat_ulong_t shm_dtime_high;
-	compat_ulong_t shm_ctime;
-	compat_ulong_t shm_ctime_high;
-	compat_pid_t   shm_cpid;
-	compat_pid_t   shm_lpid;
-	compat_ulong_t shm_nattch;
-	compat_ulong_t __unused4;
-	compat_ulong_t __unused5;
-};
-
 static inline int is_compat_task(void)
 {
 	return test_thread_flag(TIF_32BIT);
arch/mips/include/asm/compat.h +7 -17
index bbb3bc5a42fd..cc2d76953792 100644
@@ -9,12 +9,17 @@
 #include <asm/page.h>
 #include <asm/ptrace.h>
 
+#define __compat_uid_t	__compat_uid_t
 typedef s32		__compat_uid_t;
 typedef s32		__compat_gid_t;
+
+#define __compat_uid32_t __compat_uid32_t
 typedef __compat_uid_t	__compat_uid32_t;
 typedef __compat_gid_t	__compat_gid32_t;
-#define __compat_uid32_t __compat_uid32_t
-#define __compat_gid32_t __compat_gid32_t
+
+#define compat_flock		compat_flock
+#define compat_statfs		compat_statfs
+#define compat_ipc64_perm	compat_ipc64_perm
 
 #define _COMPAT_NSIG		128		/* Don't ask !$@#% ...	*/
 #define _COMPAT_NSIG_BPW	32
@@ -22,12 +27,9 @@ typedef u32		compat_sigset_word;
 
 #include <asm-generic/compat.h>
 
-#define COMPAT_USER_HZ		100
 #define COMPAT_UTS_MACHINE	"mips\0\0\0"
 
-typedef u32		compat_dev_t;
 typedef u32		compat_nlink_t;
-typedef s32		compat_ipc_pid_t;
 typedef struct {
 	s32	val[2];
 } compat_fsid_t;
@@ -69,14 +71,6 @@ struct compat_flock {
 #define F_SETLK64	34
 #define F_SETLKW64	35
 
-struct compat_flock64 {
-	short		l_type;
-	short		l_whence;
-	compat_loff_t	l_start;
-	compat_loff_t	l_len;
-	compat_pid_t	l_pid;
-};
-
 struct compat_statfs {
 	int		f_type;
 	int		f_bsize;
@@ -92,10 +86,6 @@ struct compat_statfs {
 	int		f_spare[5];
 };
 
-#define COMPAT_RLIM_INFINITY	0x7fffffffUL
-
-#define COMPAT_OFF_T_MAX	0x7fffffff
-
 struct compat_ipc64_perm {
 	compat_key_t key;
 	__compat_uid32_t uid;
arch/parisc/include/asm/compat.h +7 -40

73 lines not on this page · raw message

arch/powerpc/include/asm/compat.h +7 -40

72 lines not on this page · raw message

arch/s390/include/asm/compat.h +12 -97

147 lines not on this page · raw message

arch/sparc/include/asm/compat.h +15 -24
index bd949fcf9d63..44c7d1db3c80 100644
@@ -9,16 +9,26 @@
 #define compat_mode_t	compat_mode_t
 typedef u16		compat_mode_t;
 
+#define __compat_uid_t	__compat_uid_t
+typedef u16		__compat_uid_t;
+typedef u16		__compat_gid_t;
+
+#define compat_dev_t	compat_dev_t
+typedef u16		compat_dev_t;
+
+#define compat_ipc_pid_t compat_ipc_pid_t
+typedef u16		 compat_ipc_pid_t;
+
+#define compat_flock	compat_flock
+#define compat_flock64	compat_flock64
+
+#define compat_ipc64_perm compat_ipc64_perm
+
 #include <asm-generic/compat.h>
 
-#define COMPAT_USER_HZ		100
 #define COMPAT_UTS_MACHINE	"sparc\0\0"
 
-typedef u16		__compat_uid_t;
-typedef u16		__compat_gid_t;
-typedef u16		compat_dev_t;
 typedef s16		compat_nlink_t;
-typedef u16		compat_ipc_pid_t;
 typedef __kernel_fsid_t	compat_fsid_t;
 
 struct compat_stat {
@@ -97,25 +107,6 @@ struct compat_flock64 {
 	short		__unused;
 };
 
-struct compat_statfs {
-	int		f_type;
-	int		f_bsize;
-	int		f_blocks;
-	int		f_bfree;
-	int		f_bavail;
-	int		f_files;
-	int		f_ffree;
-	compat_fsid_t	f_fsid;
-	int		f_namelen;	/* SunOS ignores this field. */
-	int		f_frsize;
-	int		f_flags;
-	int		f_spare[4];
-};
-
-#define COMPAT_RLIM_INFINITY 0x7fffffff
-
-#define COMPAT_OFF_T_MAX	0x7fffffff
-
 struct compat_ipc64_perm {
 	compat_key_t key;
 	__compat_uid32_t uid;
arch/x86/include/asm/compat.h +12 -102

138 lines not on this page · raw message

include/asm-generic/compat.h +122 -0

138 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 43 lines · On Thu, Jan 20, 2022 at 8:38 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate:
- COMPAT_USER_HZ
- COMPAT_RLIM_INFINITY
- COMPAT_OFF_T_MAX
- __compat_uid_t, __compat_uid_t
- compat_dev_t
- compat_ipc_pid_t
- struct compat_flock
- struct compat_flock64
- struct compat_statfs
- struct compat_ipc64_perm, compat_semid64_ds, compat_msqid64_ds, compat_shmid64_ds

Cleanup duplicate definitions and merge them into asm-generic.

---
 arch/arm64/include/asm/compat.h   | 108 +++-----------------------
 arch/mips/include/asm/compat.h    |  24 ++----
 arch/parisc/include/asm/compat.h  |  47 ++----------
 arch/powerpc/include/asm/compat.h |  47 ++----------
 arch/s390/include/asm/compat.h    | 109 +++-----------------------
 arch/sparc/include/asm/compat.h   |  39 ++++------
 arch/x86/include/asm/compat.h     | 114 +++-------------------------
 include/asm-generic/compat.h      | 122 ++++++++++++++++++++++++++++++
 8 files changed, 191 insertions(+), 419 deletions(-)
arch/arm64/include/asm/compat.h +1 -0
index eaa6ca062d89..f54f295efae3 100644
@@ -5,9 +5,18 @@
 #ifndef __ASM_COMPAT_H
 #define __ASM_COMPAT_H
 
+#define COMPAT_RLIM_INFINITY           0xffffffff

...

arch/arm64/include/asm/compat.h

Quoted 3 lines
arch/arm64/include/asm/compat.h +3 -0
+#ifndef COMPAT_RLIM_INFINITY
+#define COMPAT_RLIM_INFINITY   0x7fffffff
+#endif

While this is a correct conversion, I think the default should be 0xffffffff, to match the asm-generic RLIM_INFINITY definition, with only mips and sparc getting the exception

Quoted 7 lines
arch/arm64/include/asm/compat.h +0 -7
-struct compat_flock {
-       short           l_type;
-       short           l_whence;
-       compat_off_t    l_start;
-       compat_off_t    l_len;
-       compat_pid_t    l_pid;
-};

...

arch/arm64/include/asm/compat.h

Quoted 9 lines
arch/arm64/include/asm/compat.h +9 -0
+#ifndef compat_flock
+struct compat_flock {
+       compat_short_t  l_type;
+       compat_short_t  l_whence;
+       compat_off_t    l_start;
+       compat_off_t    l_len;
+       compat_pid_t    l_pid;
+} __attribute__((packed));
+#endif

You are adding __attribute__((packed)) here, which I think has no effect on the layout on the structure on any of the architectures but it does change the alignment requirements needlessly.

Better leave it without the attribute.

Quoted 7 lines
arch/arm64/include/asm/compat.h +0 -7
-struct compat_flock64 {
-       short           l_type;
-       short           l_whence;
-       compat_loff_t   l_start;
-       compat_loff_t   l_len;
-       compat_pid_t    l_pid;
-};

...

arch/arm64/include/asm/compat.h

Quoted 9 lines
arch/arm64/include/asm/compat.h +9 -0
+#ifndef compat_flock64
+struct compat_flock64 {
+       compat_short_t  l_type;
+       compat_short_t  l_whence;
+       compat_loff_t   l_start;
+       compat_loff_t   l_len;
+       compat_pid_t    l_pid;
+} __attribute__((packed));
+#endif

This one is different: on all architectures other than x86, the added packed attribute changes the size of the structure by removing the four padding bytes at the end. x86 originally added the attribute here to work around the weirdness of the x86-32 ABI that aligns 64-bit values on a 4-byte boundary.

The easiest workaround would be to have x86 keep its custom definition. A slightly nicer version would drop the attribute on x86 as well but instead change the compat_loff_t definition to use compat_s64 instead of s64, giving it the correct alignment.

Quoted 14 lines
arch/arm64/include/asm/compat.h +0 -14
-struct compat_statfs {
-       int             f_type;
-       int             f_bsize;
-       int             f_blocks;
-       int             f_bfree;
-       int             f_bavail;
-       int             f_files;
-       int             f_ffree;
-       compat_fsid_t   f_fsid;
-       int             f_namelen;      /* SunOS ignores this field. */
-       int             f_frsize;
-       int             f_flags;
-       int             f_spare[4];
-};

...

Quoted 6 lines
arch/arm64/include/asm/compat.h +6 -0
+#ifndef compat_statfs
+struct compat_statfs {
+       compat_uint_t   f_type;
+       compat_uint_t   f_bsize;
+       compat_uint_t   f_blocks;
+       compat_uint_t   f_bfree;

arch/arm64/include/asm/compat.h

Quoted 10 lines
arch/arm64/include/asm/compat.h +10 -0
+       compat_uint_t   f_bavail;
+       compat_uint_t   f_files;
+       compat_uint_t   f_ffree;
+       __kernel_fsid_t f_fsid;
+       compat_uint_t   f_namelen;
+       compat_uint_t   f_frsize;
+       compat_uint_t   f_flags;
+       compat_uint_t   f_spare[4];
+} __attribute__((packed));
+#endif

None of the architectures use the packed attribute at the moment, so please don't add one here.

Changing compat_fsid_t to __kernel_fsid_t is harmless, but seems unnecessary.

Changing the signed int to an unsigned int (regardless of notation) may be a change in behavior. s390 is the only architecture using unsigned members here at the moment, as of b8668fd0a7e1 ("s390/uapi: change struct statfs[64] member types to unsigned values").
The description of that patch sounds like this was changed to fix a bug, but I don't see what the actual problem would be in the put_compat_statfs().

For the moment I'd suggest leaving this with the signed version, with s390 being another exception next to mips. We can follow-up with merging s390 into the common definition using either the signed or unsigned types, but I think that needs to be a separate patch with a detailed explanation.

+#ifndef compat_ipc64_perm

Quoted 48 lines
arch/arm64/include/asm/compat.h +48 -0
+struct compat_ipc64_perm {
+       compat_key_t key;
+       __compat_uid32_t uid;
+       __compat_gid32_t gid;
+       __compat_uid32_t cuid;
+       __compat_gid32_t cgid;
+       compat_mode_t   mode;
+       unsigned char   __pad1[4 - sizeof(compat_mode_t)];
+       compat_ushort_t seq;
+       compat_ushort_t __pad2;
+       compat_ulong_t  unused1;
+       compat_ulong_t  unused2;
+} __attribute__((packed));
+
+struct compat_semid64_ds {
+       struct compat_ipc64_perm sem_perm;
+       compat_ulong_t sem_otime;
+       compat_ulong_t sem_otime_high;
+       compat_ulong_t sem_ctime;
+       compat_ulong_t sem_ctime_high;
+       compat_ulong_t sem_nsems;
+       compat_ulong_t __unused3;
+       compat_ulong_t __unused4;
+} __attribute__((packed));
+
+struct compat_msqid64_ds {
+       struct compat_ipc64_perm msg_perm;
+       compat_ulong_t msg_stime;
+       compat_ulong_t msg_stime_high;
+       compat_ulong_t msg_rtime;
+       compat_ulong_t msg_rtime_high;
+       compat_ulong_t msg_ctime;
+       compat_ulong_t msg_ctime_high;
+       compat_ulong_t msg_cbytes;
+       compat_ulong_t msg_qnum;
+       compat_ulong_t msg_qbytes;
+       compat_pid_t   msg_lspid;
+       compat_pid_t   msg_lrpid;
+       compat_ulong_t __unused4;
+       compat_ulong_t __unused5;
+} __attribute__((packed));
+
+struct compat_shmid64_ds {
+       struct compat_ipc64_perm shm_perm;
+       compat_size_t  shm_segsz;
+       compat_ulong_t shm_atime;
+       compat_ulong_t shm_atime_high;
+       compat_ulong_t shm_dtime;

arch/arm64/include/asm/compat.h

Quoted 10 lines
arch/arm64/include/asm/compat.h +10 -0
+       compat_ulong_t shm_dtime_high;
+       compat_ulong_t shm_ctime;
+       compat_ulong_t shm_ctime_high;
+       compat_pid_t   shm_cpid;
+       compat_pid_t   shm_lpid;
+       compat_ulong_t shm_nattch;
+       compat_ulong_t __unused4;
+       compat_ulong_t __unused5;
+} __attribute__((packed));
+#endif

I checked these in detail, looking at the seven architectures, and your conversion looks exactly right (I had initially missed the part about compat_mode_t that you got right).

As with compat_flock, the packed attribute has no impact on the layout here, but please drop it anyway for consistency.

Arnd

#2 lore raw

From: Arnd Bergmann

Quoted 1 line

Sent: 20 January 2022 11:52

..

Quoted 2 lines

As with compat_flock, the packed attribute has no impact on the layout here, but please drop it anyway for consistency.

Never mind the structure layout, because 'packed' allows the structure to be aligned on any boundary it forces the compiler to use byte memory accesses and shifts on some architectures. This is a horrid performance penalty.

'packed' should only be specified for structures that can occur on any address boundary.
ie basically never.

If you need to remove the implicit pad before a field (eg 64bit fields on x64-32) then you can mark the field itself as 'packed'. Although, in that case, putting the attribute on the type (compat_s64) is generally cleaner.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author maintainer
#3 lore raw
In reply to Arnd Bergmann
Quoted 46 lines · Arnd Bergmann
Quoted 43 lines · On Thu, Jan 20, 2022 at 8:38 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

There are 7 64bit architectures that support Linux COMPAT mode to run 32bit applications. A lot of definitions are duplicate:
- COMPAT_USER_HZ
- COMPAT_RLIM_INFINITY
- COMPAT_OFF_T_MAX
- __compat_uid_t, __compat_uid_t
- compat_dev_t
- compat_ipc_pid_t
- struct compat_flock
- struct compat_flock64
- struct compat_statfs
- struct compat_ipc64_perm, compat_semid64_ds, compat_msqid64_ds, compat_shmid64_ds

Cleanup duplicate definitions and merge them into asm-generic.

---
 arch/arm64/include/asm/compat.h   | 108 +++-----------------------
 arch/mips/include/asm/compat.h    |  24 ++----
 arch/parisc/include/asm/compat.h  |  47 ++----------
 arch/powerpc/include/asm/compat.h |  47 ++----------
 arch/s390/include/asm/compat.h    | 109 +++-----------------------
 arch/sparc/include/asm/compat.h   |  39 ++++------
 arch/x86/include/asm/compat.h     | 114 +++-------------------------
 include/asm-generic/compat.h      | 122 ++++++++++++++++++++++++++++++
 8 files changed, 191 insertions(+), 419 deletions(-)
arch/arm64/include/asm/compat.h +1 -0
index eaa6ca062d89..f54f295efae3 100644
@@ -5,9 +5,18 @@
 #ifndef __ASM_COMPAT_H
 #define __ASM_COMPAT_H
 
+#define COMPAT_RLIM_INFINITY           0xffffffff

...

Quoted 7 lines

arch/arm64/include/asm/compat.h

Quoted 3 lines
arch/arm64/include/asm/compat.h +3 -0
+#ifndef COMPAT_RLIM_INFINITY
+#define COMPAT_RLIM_INFINITY   0x7fffffff
+#endif

While this is a correct conversion, I think the default should be 0xffffffff, to match the asm-generic RLIM_INFINITY definition, with only mips and sparc getting the exception

Okay

Quoted 23 lines
Quoted 8 lines
arch/arm64/include/asm/compat.h +0 -7
-struct compat_flock {
-       short           l_type;
-       short           l_whence;
-       compat_off_t    l_start;
-       compat_off_t    l_len;
-       compat_pid_t    l_pid;
-};

...

arch/arm64/include/asm/compat.h

Quoted 9 lines
arch/arm64/include/asm/compat.h +9 -0
+#ifndef compat_flock
+struct compat_flock {
+       compat_short_t  l_type;
+       compat_short_t  l_whence;
+       compat_off_t    l_start;
+       compat_off_t    l_len;
+       compat_pid_t    l_pid;
+} __attribute__((packed));
+#endif

You are adding __attribute__((packed)) here, which I think has no effect on the layout on the structure on any of the architectures but it does change the alignment requirements needlessly.

Quoted 1 line

Better leave it without the attribute.

Okay

Quoted 26 lines
Quoted 8 lines
arch/arm64/include/asm/compat.h +0 -7
-struct compat_flock64 {
-       short           l_type;
-       short           l_whence;
-       compat_loff_t   l_start;
-       compat_loff_t   l_len;
-       compat_pid_t    l_pid;
-};

...

arch/arm64/include/asm/compat.h

Quoted 9 lines
arch/arm64/include/asm/compat.h +9 -0
+#ifndef compat_flock64
+struct compat_flock64 {
+       compat_short_t  l_type;
+       compat_short_t  l_whence;
+       compat_loff_t   l_start;
+       compat_loff_t   l_len;
+       compat_pid_t    l_pid;
+} __attribute__((packed));
+#endif

This one is different: on all architectures other than x86, the added packed attribute changes the size of the structure by removing the four padding bytes at the end. x86 originally added the attribute here to work around the weirdness of the x86-32 ABI that aligns 64-bit values on a 4-byte boundary.

Quoted 5 lines

The easiest workaround would be to have x86 keep its custom definition. A slightly nicer version would drop the attribute on x86 as well but instead change the compat_loff_t definition to use compat_s64 instead of s64, giving it the correct alignment.

Okay, I would leave x86 origin first.

Quoted 36 lines
Quoted 15 lines
arch/arm64/include/asm/compat.h +0 -14
-struct compat_statfs {
-       int             f_type;
-       int             f_bsize;
-       int             f_blocks;
-       int             f_bfree;
-       int             f_bavail;
-       int             f_files;
-       int             f_ffree;
-       compat_fsid_t   f_fsid;
-       int             f_namelen;      /* SunOS ignores this field. */
-       int             f_frsize;
-       int             f_flags;
-       int             f_spare[4];
-};

...

Quoted 6 lines
arch/arm64/include/asm/compat.h +6 -0
+#ifndef compat_statfs
+struct compat_statfs {
+       compat_uint_t   f_type;
+       compat_uint_t   f_bsize;
+       compat_uint_t   f_blocks;
+       compat_uint_t   f_bfree;

arch/arm64/include/asm/compat.h

Quoted 10 lines
arch/arm64/include/asm/compat.h +10 -0
+       compat_uint_t   f_bavail;
+       compat_uint_t   f_files;
+       compat_uint_t   f_ffree;
+       __kernel_fsid_t f_fsid;
+       compat_uint_t   f_namelen;
+       compat_uint_t   f_frsize;
+       compat_uint_t   f_flags;
+       compat_uint_t   f_spare[4];
+} __attribute__((packed));
+#endif

None of the architectures use the packed attribute at the moment, so please don't add one here.

Quoted 2 lines

Changing compat_fsid_t to __kernel_fsid_t is harmless, but seems unnecessary.

Okay. I would add another
typedef __kernel_fsid_t compat_fsid_t;
in the file.

Quoted 10 lines

Changing the signed int to an unsigned int (regardless of notation) may be a change in behavior. s390 is the only architecture using unsigned members here at the moment, as of b8668fd0a7e1 ("s390/uapi: change struct statfs[64] member types to unsigned values").
The description of that patch sounds like this was changed to fix a bug, but I don't see what the actual problem would be in the put_compat_statfs().

Quoted 5 lines

For the moment I'd suggest leaving this with the signed version, with s390 being another exception next to mips. We can follow-up with merging s390 into the common definition using either the signed or unsigned types, but I think that needs to be a separate patch with a detailed explanation.

Okay, I would leave s390 origin first.

Quoted 69 lines

+#ifndef compat_ipc64_perm

Quoted 48 lines
arch/arm64/include/asm/compat.h +48 -0
+struct compat_ipc64_perm {
+       compat_key_t key;
+       __compat_uid32_t uid;
+       __compat_gid32_t gid;
+       __compat_uid32_t cuid;
+       __compat_gid32_t cgid;
+       compat_mode_t   mode;
+       unsigned char   __pad1[4 - sizeof(compat_mode_t)];
+       compat_ushort_t seq;
+       compat_ushort_t __pad2;
+       compat_ulong_t  unused1;
+       compat_ulong_t  unused2;
+} __attribute__((packed));
+
+struct compat_semid64_ds {
+       struct compat_ipc64_perm sem_perm;
+       compat_ulong_t sem_otime;
+       compat_ulong_t sem_otime_high;
+       compat_ulong_t sem_ctime;
+       compat_ulong_t sem_ctime_high;
+       compat_ulong_t sem_nsems;
+       compat_ulong_t __unused3;
+       compat_ulong_t __unused4;
+} __attribute__((packed));
+
+struct compat_msqid64_ds {
+       struct compat_ipc64_perm msg_perm;
+       compat_ulong_t msg_stime;
+       compat_ulong_t msg_stime_high;
+       compat_ulong_t msg_rtime;
+       compat_ulong_t msg_rtime_high;
+       compat_ulong_t msg_ctime;
+       compat_ulong_t msg_ctime_high;
+       compat_ulong_t msg_cbytes;
+       compat_ulong_t msg_qnum;
+       compat_ulong_t msg_qbytes;
+       compat_pid_t   msg_lspid;
+       compat_pid_t   msg_lrpid;
+       compat_ulong_t __unused4;
+       compat_ulong_t __unused5;
+} __attribute__((packed));
+
+struct compat_shmid64_ds {
+       struct compat_ipc64_perm shm_perm;
+       compat_size_t  shm_segsz;
+       compat_ulong_t shm_atime;
+       compat_ulong_t shm_atime_high;
+       compat_ulong_t shm_dtime;

arch/arm64/include/asm/compat.h

Quoted 10 lines
arch/arm64/include/asm/compat.h +10 -0
+       compat_ulong_t shm_dtime_high;
+       compat_ulong_t shm_ctime;
+       compat_ulong_t shm_ctime_high;
+       compat_pid_t   shm_cpid;
+       compat_pid_t   shm_lpid;
+       compat_ulong_t shm_nattch;
+       compat_ulong_t __unused4;
+       compat_ulong_t __unused5;
+} __attribute__((packed));
+#endif

I checked these in detail, looking at the seven architectures, and your conversion looks exactly right (I had initially missed the part about compat_mode_t that you got right).

As with compat_flock, the packed attribute has no impact on the layout here, but please drop it anyway for consistency.

Arnd

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/