consolidate the flock uapi definitions
Hi all,
currently we deal with the slight differents in the various architecture variants of the flock and flock64 stuctures in a very cruft way. This series switches to just use small arch hooks and define the rest in asm-generic and linux/compat.h instead.
Diffstat:
arch/arm64/include/asm/compat.h | 20 -------------------- arch/mips/include/asm/compat.h | 23 ++--------------------- arch/mips/include/uapi/asm/fcntl.h | 28 +++------------------------- arch/parisc/include/asm/compat.h | 16 ---------------- arch/powerpc/include/asm/compat.h | 20 -------------------- arch/s390/include/asm/compat.h | 20 -------------------- arch/sparc/include/asm/compat.h | 22 +--------------------- arch/x86/include/asm/compat.h | 24 +++--------------------- include/linux/compat.h | 31 +++++++++++++++++++++++++++++++ include/uapi/asm-generic/fcntl.h | 21 +++++++-------------- tools/include/uapi/asm-generic/fcntl.h | 21 +++++++-------------- 11 files changed, 54 insertions(+), 192 deletions(-)
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/5 uapi: remove the unused HAVE_ARCH_STRUCT_FLOCK64 define
--- include/uapi/asm-generic/fcntl.h | 2 -- tools/include/uapi/asm-generic/fcntl.h | 2 -- 2 files changed, 4 deletions(-)
include/uapi/asm-generic/fcntl.h +0 -2
@@ -203,7 +203,6 @@ struct flock { };#endif -#ifndef HAVE_ARCH_STRUCT_FLOCK64 #ifndef __ARCH_FLOCK64_PAD#define __ARCH_FLOCK64_PAD#endif
@@ -216,6 +215,5 @@ struct flock64 {__kernel_pid_t l_pid; __ARCH_FLOCK64_PAD }; -#endif #endif /* _ASM_GENERIC_FCNTL_H */
tools/include/uapi/asm-generic/fcntl.h +0 -2
@@ -202,7 +202,6 @@ struct flock { };#endif -#ifndef HAVE_ARCH_STRUCT_FLOCK64 #ifndef __ARCH_FLOCK64_PAD#define __ARCH_FLOCK64_PAD#endif
@@ -215,6 +214,5 @@ struct flock64 {__kernel_pid_t l_pid; __ARCH_FLOCK64_PAD }; -#endif #endif /* _ASM_GENERIC_FCNTL_H */
Signature · 7 lines
2.30.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Arnd Bergmann
maintainerRe: [PATCH 1/5] uapi: remove the unused HAVE_ARCH_STRUCT_FLOCK64 define
Quoted 2 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
The patch looks good, but I'd like to see a description for each one. How about:
| The check was added when Stephen Rothwell created the file, but | no architecture ever defined it.
Arnd
Re: [PATCH 1/5] uapi: remove the unused HAVE_ARCH_STRUCT_FLOCK64 define
Hi Arnd,
Quoted 10 lines · On Mon, 12 Apr 2021 11:55:41 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 2 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>The patch looks good, but I'd like to see a description for each one. How about:
| The check was added when Stephen Rothwell created the file, but | no architecture ever defined it.
Actually it was used by the xtensa architecture until Dec, 2006.
Signature · 2 lines
Cheers, Stephen Rothwell
PATCH 2/5 uapi: simplify __ARCH_FLOCK{,64}_PAD a little
In reply to Christoph HellwigDon't bother to define emtpty versions of the macros if the architecture doesn't define them.
--- include/uapi/asm-generic/fcntl.h | 12 ++++-------- tools/include/uapi/asm-generic/fcntl.h | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-)
include/uapi/asm-generic/fcntl.h +4 -8
@@ -189,22 +189,16 @@ struct f_owner_ex {#define F_LINUX_SPECIFIC_BASE 1024#ifndef HAVE_ARCH_STRUCT_FLOCK -#ifndef __ARCH_FLOCK_PAD -#define __ARCH_FLOCK_PAD -#endif -struct flock {short l_type;short l_whence;__kernel_off_t l_start;__kernel_off_t l_len;__kernel_pid_t l_pid; +#ifdef __ARCH_FLOCK_PAD __ARCH_FLOCK_PAD -};#endif - -#ifndef __ARCH_FLOCK64_PAD -#define __ARCH_FLOCK64_PAD +};#endif struct flock64 {
@@ -213,7 +207,9 @@ struct flock64 {__kernel_loff_t l_start;__kernel_loff_t l_len;__kernel_pid_t l_pid; +#ifdef __ARCH_FLOCK64_PAD__ARCH_FLOCK64_PAD +#endif };#endif /* _ASM_GENERIC_FCNTL_H */
tools/include/uapi/asm-generic/fcntl.h +4 -8
@@ -188,22 +188,16 @@ struct f_owner_ex {#define F_LINUX_SPECIFIC_BASE 1024#ifndef HAVE_ARCH_STRUCT_FLOCK -#ifndef __ARCH_FLOCK_PAD -#define __ARCH_FLOCK_PAD -#endif -struct flock {short l_type;short l_whence;__kernel_off_t l_start;__kernel_off_t l_len;__kernel_pid_t l_pid; +#ifdef __ARCH_FLOCK_PAD __ARCH_FLOCK_PAD -};#endif - -#ifndef __ARCH_FLOCK64_PAD -#define __ARCH_FLOCK64_PAD +};#endif struct flock64 {
@@ -212,7 +206,9 @@ struct flock64 {__kernel_loff_t l_start;__kernel_loff_t l_len;__kernel_pid_t l_pid; +#ifdef __ARCH_FLOCK64_PAD__ARCH_FLOCK64_PAD +#endif };#endif /* _ASM_GENERIC_FCNTL_H */
Signature · 1 line
2.30.1
PATCH 3/5 uapi: merge the 32-bit mips struct flock into the generic one
In reply to Christoph HellwigAdd a new __ARCH_FLOCK_EXTRA_SYSID macro following the style of __ARCH_FLOCK_PAD to avoid having a separate definition just for one architecture.
--- arch/mips/include/uapi/asm/fcntl.h | 26 +++----------------------- include/uapi/asm-generic/fcntl.h | 5 +++-- tools/include/uapi/asm-generic/fcntl.h | 5 +++-- 3 files changed, 9 insertions(+), 27 deletions(-)
arch/mips/include/uapi/asm/fcntl.h +3 -23
@@ -50,30 +50,10 @@#define F_SETLKW64 35#endif -/* -* The flavours of struct flock. "struct flock" is the ABI compliant -* variant. Finally struct flock64 is the LFS variant of struct flock. As -* a historic accident and inconsistence with the ABI definition it doesn't -* contain all the same fields as struct flock. -*/ -#if _MIPS_SIM != _MIPS_SIM_ABI64 - -#include <linux/types.h> - -struct flock { -short l_type; -short l_whence; -__kernel_off_t l_start; -__kernel_off_t l_len; -long l_sysid; -__kernel_pid_t l_pid; -long pad[4 ]; -}; - -#define HAVE_ARCH_STRUCT_FLOCK - -#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */ +#define __ARCH_FLOCK_EXTRA_SYSID long l_sysid; +#define __ARCH_FLOCK_PAD long pad[4]; +#endif #include <asm-generic/fcntl.h>
include/uapi/asm-generic/fcntl.h +3 -2
@@ -188,18 +188,19 @@ struct f_owner_ex {#define F_LINUX_SPECIFIC_BASE 1024 -#ifndef HAVE_ARCH_STRUCT_FLOCK struct flock {short l_type;short l_whence;__kernel_off_t l_start;__kernel_off_t l_len; +#ifdef __ARCH_FLOCK_EXTRA_SYSID + __ARCH_FLOCK_EXTRA_SYSID +#endif __kernel_pid_t l_pid;#ifdef __ARCH_FLOCK_PAD __ARCH_FLOCK_PAD#endif }; -#endif struct flock64 {short l_type;
tools/include/uapi/asm-generic/fcntl.h +3 -2
@@ -187,18 +187,19 @@ struct f_owner_ex {#define F_LINUX_SPECIFIC_BASE 1024 -#ifndef HAVE_ARCH_STRUCT_FLOCK struct flock {short l_type;short l_whence;__kernel_off_t l_start;__kernel_off_t l_len; +#ifdef __ARCH_FLOCK_EXTRA_SYSID + __ARCH_FLOCK_EXTRA_SYSID +#endif __kernel_pid_t l_pid;#ifdef __ARCH_FLOCK_PAD __ARCH_FLOCK_PAD#endif }; -#endif struct flock64 {short l_type;
Signature · 7 lines
2.30.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 4/5 uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
In reply to Christoph HellwigThe F_GETLK64/F_SETLK64/F_SETLKW64 commands are only implemented for 32-bit syscall APIs, but we also need them for compat handling on 64-bit kernels.
Given that redefining them is rather error prone, as shown by parisc getting the opcodes wrong currently, just use the existing definitions for the compat handling.
In theory we could try to hide them from userspace; but given that only MIPS manages to properly do that while the asm-generic version used by most architectures relies on a Kconfig symbol that is never set by userspace there doesn't seem to be much of a point to even bother.
--- arch/arm64/include/asm/compat.h | 4 ---- arch/mips/include/asm/compat.h | 4 ---- arch/mips/include/uapi/asm/fcntl.h | 2 -- arch/powerpc/include/asm/compat.h | 4 ---- arch/s390/include/asm/compat.h | 4 ---- arch/sparc/include/asm/compat.h | 4 ---- arch/x86/include/asm/compat.h | 4 ---- include/uapi/asm-generic/fcntl.h | 2 -- tools/include/uapi/asm-generic/fcntl.h | 2 -- 9 files changed, 30 deletions(-)
arch/arm64/include/asm/compat.h +0 -4
@@ -74,10 +74,6 @@ struct compat_flock {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;
arch/mips/include/asm/compat.h +0 -4
@@ -60,10 +60,6 @@ struct compat_flock {s32 pad[4 ]; }; -#define F_GETLK64 33 -#define F_SETLK64 34 -#define F_SETLKW64 35 -struct compat_flock64 {short l_type;short l_whence;
arch/mips/include/uapi/asm/fcntl.h +0 -2
@@ -44,11 +44,9 @@#define F_SETOWN 24/* for sockets. */ #define F_GETOWN 23/* for sockets. */ -#ifndef __mips64#define F_GETLK64 33/* using 'struct flock64' */ #define F_SETLK64 34#define F_SETLKW64 35 -#endif #if _MIPS_SIM != _MIPS_SIM_ABI64#define __ARCH_FLOCK_EXTRA_SYSID long l_sysid;
arch/powerpc/include/asm/compat.h +0 -4
@@ -56,10 +56,6 @@ struct compat_flock {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;
arch/s390/include/asm/compat.h +0 -4
@@ -111,10 +111,6 @@ struct compat_flock {compat_pid_t l_pid; }; -#define F_GETLK64 12 -#define F_SETLK64 13 -#define F_SETLKW64 14 -struct compat_flock64 {short l_type;short l_whence;
arch/sparc/include/asm/compat.h +0 -4
@@ -85,10 +85,6 @@ struct compat_flock {short __unused; }; -#define F_GETLK64 12 -#define F_SETLK64 13 -#define F_SETLKW64 14 -struct compat_flock64 {short l_type;short l_whence;
arch/x86/include/asm/compat.h +0 -4
@@ -59,10 +59,6 @@ struct compat_flock {compat_pid_t l_pid; }; -#define F_GETLK64 12/* using 'struct flock64' */ -#define F_SETLK64 13 -#define F_SETLKW64 14 -/* * IA32 uses 4 byte alignment for 64 bit quantities, * so we need to pack this structure.
include/uapi/asm-generic/fcntl.h +0 -2
@@ -116,13 +116,11 @@#define F_GETSIG 11/* for sockets. */ #endif -#ifndef CONFIG_64BIT #ifndef F_GETLK64 #define F_GETLK64 12/* using 'struct flock64' */ #define F_SETLK64 13#define F_SETLKW64 14#endif -#endif #ifndef F_SETOWN_EX #define F_SETOWN_EX 15
tools/include/uapi/asm-generic/fcntl.h +0 -2
@@ -115,13 +115,11 @@#define F_GETSIG 11/* for sockets. */ #endif -#ifndef CONFIG_64BIT #ifndef F_GETLK64 #define F_GETLK64 12/* using 'struct flock64' */ #define F_SETLK64 13#define F_SETLKW64 14#endif -#endif #ifndef F_SETOWN_EX #define F_SETOWN_EX 15
Signature · 1 line
2.30.1
Re: [PATCH 4/5] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
Quoted 3 lines · Christoph Hellwig
The F_GETLK64/F_SETLK64/F_SETLKW64 commands are only implemented for 32-bit syscall APIs, but we also need them for compat handling on 64-bit kernels.
Ok.
Quoted 3 lines
Given that redefining them is rather error prone, as shown by parisc getting the opcodes wrong currently, just use the existing definitions for the compat handling.
Can you please show me where parisc gets it currently wrong? I'm somehow blind to see it and of course I'd like to fix it in stable kernel series if that's true...
Other than that, thanks for this cleanup!
You may add:
Thanks!
Helge
Quoted 161 lines
In theory we could try to hide them from userspace; but given that only MIPS manages to properly do that while the asm-generic version used by most architectures relies on a
Kconfigsymbol that is never set by userspace there doesn't seem to be much of a point to even bother.Signed-off-by Christoph Hellwig <[email protected]>--- arch/arm64/include/asm/compat.h | 4 ---- arch/mips/include/asm/compat.h | 4 ---- arch/mips/include/uapi/asm/fcntl.h | 2 -- arch/powerpc/include/asm/compat.h | 4 ---- arch/s390/include/asm/compat.h | 4 ---- arch/sparc/include/asm/compat.h | 4 ---- arch/x86/include/asm/compat.h | 4 ---- include/uapi/asm-generic/fcntl.h | 2 -- tools/include/uapi/asm-generic/fcntl.h | 2 -- 9 files changed, 30 deletions(-)arch/arm64/include/asm/compat.h +0
-4@@ -74,10 +74,6 @@ struct compat_flock {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;arch/mips/include/asm/compat.h +0
-4@@ -60,10 +60,6 @@ struct compat_flock {s32 pad[4 ]; }; -#define F_GETLK64 33 -#define F_SETLK64 34 -#define F_SETLKW64 35 -struct compat_flock64 {short l_type;short l_whence;arch/mips/include/uapi/asm/fcntl.h +0
-2@@ -44,11 +44,9 @@#define F_SETOWN 24/* for sockets. */ #define F_GETOWN 23/* for sockets. */ -#ifndef __mips64#define F_GETLK64 33/* using 'struct flock64' */ #define F_SETLK64 34#define F_SETLKW64 35 -#endif #if _MIPS_SIM != _MIPS_SIM_ABI64#define __ARCH_FLOCK_EXTRA_SYSID long l_sysid;arch/powerpc/include/asm/compat.h +0
-4@@ -56,10 +56,6 @@ struct compat_flock {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;arch/s390/include/asm/compat.h +0
-4@@ -111,10 +111,6 @@ struct compat_flock {compat_pid_t l_pid; }; -#define F_GETLK64 12 -#define F_SETLK64 13 -#define F_SETLKW64 14 -struct compat_flock64 {short l_type;short l_whence;arch/sparc/include/asm/compat.h +0
-4@@ -85,10 +85,6 @@ struct compat_flock {short __unused; }; -#define F_GETLK64 12 -#define F_SETLK64 13 -#define F_SETLKW64 14 -struct compat_flock64 {short l_type;short l_whence;arch/x86/include/asm/compat.h +0
-4@@ -59,10 +59,6 @@ struct compat_flock {compat_pid_t l_pid; }; -#define F_GETLK64 12/* using 'struct flock64' */ -#define F_SETLK64 13 -#define F_SETLKW64 14 -/* * IA32 uses 4 byte alignment for 64 bit quantities, * so we need to pack this structure. include/uapi/asm-generic/fcntl.h +0
-2@@ -116,13 +116,11 @@#define F_GETSIG 11/* for sockets. */ #endif -#ifndef CONFIG_64BIT #ifndef F_GETLK64 #define F_GETLK64 12/* using 'struct flock64' */ #define F_SETLK64 13#define F_SETLKW64 14#endif -#endif #ifndef F_SETOWN_EX #define F_SETOWN_EX 15tools/include/uapi/asm-generic/fcntl.h +0
-2@@ -115,13 +115,11 @@#define F_GETSIG 11/* for sockets. */ #endif -#ifndef CONFIG_64BIT #ifndef F_GETLK64 #define F_GETLK64 12/* using 'struct flock64' */ #define F_SETLK64 13#define F_SETLKW64 14#endif -#endif #ifndef F_SETOWN_EX #define F_SETOWN_EX 15
Re: [PATCH 4/5] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
Quoted 7 lines · Helge Deller
Quoted 3 lines · Christoph Hellwig
The F_GETLK64/F_SETLK64/F_SETLKW64 commands are only implemented for 32-bit syscall APIs, but we also need them for compat handling on 64-bit kernels.
Ok.
Quoted 7 lines
Quoted 3 lines
Given that redefining them is rather error prone, as shown by parisc getting the opcodes wrong currently, just use the existing definitions for the compat handling.
Can you please show me where parisc gets it currently wrong? I'm somehow blind to see it and of course I'd like to fix it in stable kernel series if that's true...
Looking again I think my comment was wrong, I thought parisc would fall back to the asm-generic version with different code points for the compat case, but parisc actually already defines the constants unconditionally like this patch does for everyone else. So I'll retract that part of the comment.
Helge Deller
maintainerRe: [PATCH 4/5] uapi: always define F_GETLK64/F_SETLK64/F_SETLKW64 in fcntl.h
Quoted 16 lines · Christoph Hellwig
Quoted 7 lines · Helge Deller
Quoted 3 lines · Christoph Hellwig
The F_GETLK64/F_SETLK64/F_SETLKW64 commands are only implemented for 32-bit syscall APIs, but we also need them for compat handling on 64-bit kernels.
Ok.
Quoted 7 lines
Quoted 3 lines
Given that redefining them is rather error prone, as shown by parisc getting the opcodes wrong currently, just use the existing definitions for the compat handling.
Can you please show me where parisc gets it currently wrong? I'm somehow blind to see it and of course I'd like to fix it in stable kernel series if that's true...
Quoted 5 lines
Looking again I think my comment was wrong, I thought parisc would fall back to the asm-generic version with different code points for the compat case, but parisc actually already defines the constants unconditionally like this patch does for everyone else. So I'll retract that part of the comment.
Ok, good.
Thanks for checking!
Helge
PATCH 5/5 compat: consolidate the compat_flock{,64} definition
In reply to Christoph HellwigProvide a single common definition for the compat_flock and compat_flock64 structures using the same tricks as for the native variants. An extra define is added for the packing required on x86.
--- arch/arm64/include/asm/compat.h | 16 ---------------- arch/mips/include/asm/compat.h | 19 ++----------------- arch/parisc/include/asm/compat.h | 16 ---------------- arch/powerpc/include/asm/compat.h | 16 ---------------- arch/s390/include/asm/compat.h | 16 ---------------- arch/sparc/include/asm/compat.h | 18 +----------------- arch/x86/include/asm/compat.h | 20 +++----------------- include/linux/compat.h | 31 +++++++++++++++++++++++++++++++ 8 files changed, 37 insertions(+), 115 deletions(-)
arch/arm64/include/asm/compat.h +0 -16
@@ -66,22 +66,6 @@ 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; -}; - -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;
arch/mips/include/asm/compat.h +2 -17
@@ -50,23 +50,8 @@ struct compat_stat {s32 st_pad4[14 ]; }; -struct compat_flock { -short l_type; -short l_whence; -compat_off_t l_start; -compat_off_t l_len; -s32 l_sysid; -compat_pid_t l_pid; -s32 pad[4 ]; -}; - -struct compat_flock64 { -short l_type; -short l_whence; -compat_loff_t l_start; -compat_loff_t l_len; -compat_pid_t l_pid; -}; +#define __ARCH_COMPAT_FLOCK_EXTRA_SYSID s32 l_sysid; +#define __ARCH_COMPAT_FLOCK_PAD s32 pad[4];struct compat_statfs {int f_type;
arch/parisc/include/asm/compat.h +0 -16
@@ -54,22 +54,6 @@ struct compat_stat {u32 st_spare4[3 ]; }; -struct compat_flock { -short l_type; -short l_whence; -compat_off_t l_start; -compat_off_t l_len; -compat_pid_t l_pid; -}; - -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 {s32 f_type;s32 f_bsize;
arch/powerpc/include/asm/compat.h +0 -16
@@ -48,22 +48,6 @@ struct compat_stat {u32 __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; -}; - -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;
arch/s390/include/asm/compat.h +0 -16
@@ -103,22 +103,6 @@ struct compat_stat {u32 __unused5; }; -struct compat_flock { -short l_type; -short l_whence; -compat_off_t l_start; -compat_off_t l_len; -compat_pid_t l_pid; -}; - -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 {u32 f_type;u32 f_bsize;
arch/sparc/include/asm/compat.h +1 -17
@@ -76,23 +76,7 @@ struct compat_stat64 {unsigned int __unused5; }; -struct compat_flock { -short l_type; -short l_whence; -compat_off_t l_start; -compat_off_t l_len; -compat_pid_t l_pid; -short __unused; -}; - -struct compat_flock64 { -short l_type; -short l_whence; -compat_loff_t l_start; -compat_loff_t l_len; -compat_pid_t l_pid; -short __unused; -}; +#define __ARCH_COMPAT_FLOCK_PAD short __unused;struct compat_statfs {int f_type;
arch/x86/include/asm/compat.h +3 -17
@@ -51,25 +51,11 @@ struct compat_stat {u32 __unused5; }; -struct compat_flock { -short l_type; -short l_whence; -compat_off_t l_start; -compat_off_t l_len; -compat_pid_t l_pid; -}; -/* -* IA32 uses 4 byte alignment for 64 bit quantities, -* so we need to pack this structure. +* IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the +* compat flock64 structure. */ -struct compat_flock64 { -short l_type; -short l_whence; -compat_loff_t l_start; -compat_loff_t l_len; -compat_pid_t l_pid; -} __attribute__((packed)); +#define __ARCH_NEED_COMPAT_FLOCK64_PACKEDstruct compat_statfs {int f_type;
include/linux/compat.h +31 -0
@@ -258,6 +258,37 @@ struct compat_rlimit {compat_ulong_t rlim_max; }; +#ifdef __ARCH_NEED_COMPAT_FLOCK64_PACKED +#define __ARCH_COMPAT_FLOCK64_PACK __attribute__((packed)) +#else +#define __ARCH_COMPAT_FLOCK64_PACK +#endif + +struct compat_flock { +short l_type; +short l_whence; +compat_off_t l_start; +compat_off_t l_len; +#ifdef __ARCH_COMPAT_FLOCK_EXTRA_SYSID + __ARCH_COMPAT_FLOCK_EXTRA_SYSID +#endif +compat_pid_t l_pid; +#ifdef __ARCH_COMPAT_FLOCK_PAD + __ARCH_COMPAT_FLOCK_PAD +#endif +}; + +struct compat_flock64 { +short l_type; +short l_whence; +compat_loff_t l_start; +compat_loff_t l_len; +compat_pid_t l_pid; +#ifdef __ARCH_COMPAT_FLOCK64_PAD + __ARCH_COMPAT_FLOCK64_PAD +#endif +} __ARCH_COMPAT_FLOCK64_PACK; +struct compat_rusage {struct old_timeval32 ru_utime;struct old_timeval32 ru_stime;
Signature · 1 line
2.30.1
RE: [PATCH 5/5] compat: consolidate the compat_flock{,64} definition
From: Christoph Hellwig
Quoted 6 lines
Sent: 12 April 2021 09:56
Provide a single common definition for the
compat_flockandcompat_flock64structures using the same tricks as for the native variants. An extra define is added for the packing required on x86.
...
Quoted 6 lines
/*
- * IA32 uses 4 byte alignment for 64 bit quantities,
- * so we need to pack this structure.
+ * IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the
+ * compat flock64 structure.
*/
arch/x86/include/asm/compat.h struct compat_stat { · line 58
Quoted 8 lines
arch/x86/include/asm/compat.h +1
-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; -} __attribute__((packed)); +#define __ARCH_NEED_COMPAT_FLOCK64_PACKED
That shouldn't need to be packed at all.
(Since the 32bit variant isn't packed.)
compat_loff_t should itself have __attribute__((aligned(4))) probably inherited from compat_s64.
So l_start will be at offset 4 without the __packed.
I'm guessing that compat_pid_t is 16 bits?
So the native 32bit version has an unnamed 2 byte structure pad. The 'packed' removes this pad from the compat structure.
AFAICT (apart from mips) the __ARCH_COMPAT_FLOCK_PAD is just adding an explicit pad for the implicit pad the compiler would generate because compat_pid_t is 16 bits.
If the padding need not be named for the 64bit system calls. (Where there is probably rather more padding all over the place.) then it doesn't need to be named for the compat variants.
Even the mips extra padding could be removed. F_GETLK might be expected to do a read-write of them, so return EFAULT if not mapped.
But nothing should be testing the EFAULT is returned!
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
RE: [PATCH 5/5] compat: consolidate the compat_flock{,64} definition
From: David Laight
Quoted 1 line
Sent: 12 April 2021 10:37
...
Quoted 7 lines
I'm guessing that
compat_pid_tis 16 bits?
So the native 32bit version has an unnamed 2 byte structure pad. The 'packed' removes this pad from the compat structure.AFAICT (apart from mips) the
__ARCH_COMPAT_FLOCK_PADis just adding an explicit pad for the implicit pad the compiler would generate becausecompat_pid_tis 16 bits.
I've just looked at the header.compat_pid_t is 32 bits.
So Linux must have gained 32bit pids at some earlier time. (Historically Unix pids were 16 bit - even on 32bit systems.)
Which makes the explicit pad in 'sparc' rather 'interesting'.
Actually the tail pad can just be removed from the compat structures.
Just a comment that mips and sparc have extra fields in the uapi header is enough.
The kernel never needs to read/write the pad. userspace must provide the pad in case the kernel writes it.
oh - compat_loff_t is only used in a couple of other places. neither care in any way about the alignment. (Provided get_user() doesn't fault on a 8n+4 aligned address.)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Arnd Bergmann
maintainerRe: [PATCH 5/5] compat: consolidate the compat_flock{,64} definition
Quoted 10 lines · David Laight
From: David Laight > Sent: 12 April 2021 10:37
...Quoted 7 lines
I'm guessing that
compat_pid_tis 16 bits?
So the native 32bit version has an unnamed 2 byte structure pad. The 'packed' removes this pad from the compat structure.AFAICT (apart from mips) the
__ARCH_COMPAT_FLOCK_PADis just adding an explicit pad for the implicit pad the compiler would generate becausecompat_pid_tis 16 bits.
Quoted 6 lines
I've just looked at the header.
compat_pid_tis 32 bits.
So Linux must have gained 32bit pids at some earlier time. (Historically Unix pids were 16 bit - even on 32bit systems.)Which makes the explicit pad in 'sparc' rather 'interesting'.
I saw it was there since the sparc kernel support got merged in linux-1.3, possibly copied from an older sunos version.
Quoted 3 lines
oh -
compat_loff_tis only used in a couple of other places. neither care in any way about the alignment. (Providedget_user()doesn't fault on a 8n+4 aligned address.)
Ah right, I also see that after this series it's only used in to other
places: compat_resume_swap_area, which could also lose the __packed annotation, and in the declaration of compat_sys_sendfile64, where it makes no difference.
Arnd
RE: [PATCH 5/5] compat: consolidate the compat_flock{,64} definition
From: Arnd Bergmann
Quoted 18 lines
Sent: 12 April 2021 12:26
Quoted 15 lines · David Laight
From: David Laight > Sent: 12 April 2021 10:37
...Quoted 7 lines
I'm guessing that
compat_pid_tis 16 bits?
So the native 32bit version has an unnamed 2 byte structure pad. The 'packed' removes this pad from the compat structure.AFAICT (apart from mips) the
__ARCH_COMPAT_FLOCK_PADis just adding an explicit pad for the implicit pad the compiler would generate becausecompat_pid_tis 16 bits.I've just looked at the header.
compat_pid_tis 32 bits.
So Linux must have gained 32bit pids at some earlier time. (Historically Unix pids were 16 bit - even on 32bit systems.)
Quoted 4 lines
Quoted 1 line
Which makes the explicit pad in 'sparc' rather 'interesting'.
I saw it was there since the sparc kernel support got merged in linux-1.3, possibly copied from an older sunos version.
Which had a 16bit pid when I used it.
So this is a bug in the sparc merge!
The explicit 'short' pad could be removed from the 64bit variant because there are always 4 bytes of pad after l_pid.
But it does extend the application structure on 32bit sparc so must remain in the uapi header.
It doesn't need to be in the 'compat' definition.
Quoted 7 lines
Quoted 3 lines
oh -
compat_loff_tis only used in a couple of other places. neither care in any way about the alignment. (Providedget_user()doesn't fault on a 8n+4 aligned address.)Ah right, I also see that after this series it's only used in to other
places:compat_resume_swap_area, which could also lose the__packedannotation,
That structure just defines 0 and 8, the structure size doesn't matter and the offsets are 'passed to' get_user() so byte accesses aren't performed.
Quoted 2 lines
and in the declaration of
compat_sys_sendfile64, where it makes no difference.
Which should probably use get_user() rather than copy_from_user().
Although some architectures may need fallback code for misaligned get_user() ?
Or is there a general 'cop out' that structures passed to the kernel are required to be correctly aligned.
They should be aligned unless the kernel is 'playing games' like reading 'struct pollfd' as a 64bit item.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Arnd Bergmann
maintainerQuoted 7 lines · Christoph Hellwig
Hi all,
currently we deal with the slight differents in the various architecture variants of the flock and flock64 stuctures in a very cruft way. This series switches to just use small arch hooks and define the rest in asm-generic and
linux/compat.hinstead.
Nice cleanup. I can merge it through the asm-generic tree if you like, though it's a little late just ahead of the merge window.
I would not want to change the compat_loff_t definition to compat_s64 to avoid the padding at this time, though that might be a useful cleanup for a future cycle.
Arnd
From: Arnd Bergmann
Quoted 11 lines
Sent: 12 April 2021 11:04
Quoted 7 lines · Christoph Hellwig
Hi all,
currently we deal with the slight differents in the various architecture variants of the flock and flock64 stuctures in a very cruft way. This series switches to just use small arch hooks and define the rest in asm-generic and
linux/compat.hinstead.
Quoted 6 lines
Nice cleanup. I can merge it through the asm-generic tree if you like, though it's a little late just ahead of the merge window.
I would not want to change the
compat_loff_tdefinition tocompat_s64to avoid the padding at this time, though that might be a useful cleanup for a future cycle.
Is x86 the only architecture that has 32bit and 64bit variants where the 32bit variant aligns 64bit items on 32bit boundaries?
I've just checked MIPS and ARM, and I'm fairly sure sparc 64bit aligns them.
Are there any others?
Might also be interesting to check whether compat_loff_t gets used anywhere else - where the x64-64 compat code will get it wrong.
ISTM that fixing compat_loff_t shouldn't have any fallout.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Arnd Bergmann
maintainerQuoted 16 lines · David Laight
From: Arnd Bergmann
Quoted 14 lines
Sent: 12 April 2021 11:04
Quoted 7 lines · Christoph Hellwig
Hi all,
currently we deal with the slight differents in the various architecture variants of the flock and flock64 stuctures in a very cruft way. This series switches to just use small arch hooks and define the rest in asm-generic and
linux/compat.hinstead.Nice cleanup. I can merge it through the asm-generic tree if you like, though it's a little late just ahead of the merge window.
Quoted 6 lines
Quoted 3 lines
I would not want to change the
compat_loff_tdefinition tocompat_s64to avoid the padding at this time, though that might be a useful cleanup for a future cycle.Is x86 the only architecture that has 32bit and 64bit variants where the 32bit variant aligns 64bit items on 32bit boundaries?
Yes.
Quoted 1 line
ISTM that fixing
compat_loff_tshouldn't have any fallout.
That is my assumption as well, but I still wouldn't take the risk one week before the merge window.
Arnd
Quoted 8 lines · Christoph Hellwig
Hi all,
currently we deal with the slight differents in the various architecture variants of the flock and flock64 stuctures in a very cruft way. This series switches to just use small arch hooks and define the rest in asm-generic and
linux/compat.hinstead.Diffstat:
Quoted 12 lines
arch/arm64/include/asm/compat.h | 20 -------------------- arch/mips/include/asm/compat.h | 23 ++--------------------- arch/mips/include/uapi/asm/fcntl.h | 28 +++------------------------- arch/parisc/include/asm/compat.h | 16 ---------------- arch/powerpc/include/asm/compat.h | 20 -------------------- arch/s390/include/asm/compat.h | 20 -------------------- arch/sparc/include/asm/compat.h | 22 +--------------------- arch/x86/include/asm/compat.h | 24 +++--------------------- include/linux/compat.h | 31 +++++++++++++++++++++++++++++++ include/uapi/asm-generic/fcntl.h | 21 +++++++-------------- tools/include/uapi/asm-generic/fcntl.h | 21 +++++++-------------- 11 files changed, 54 insertions(+), 192 deletions(-)
for the s390 bits: