Skip to contentSkip to conversation

x86: make stat/statfs 64-bit for x86_64 kernels

PATCH In review Mike Frysinger 2 participants 8 messages May 9, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: make stat/statfs 64-bit for x86_64 kernels

When including these headers in the x32 ABI, the structs get declared with 32bit sizes which is incorrect. Use long long and such to make it work both with x32 and x86_64.

---
 arch/x86/include/uapi/asm/stat.h   | 38 +++++++++++++++++++-------------------
 arch/x86/include/uapi/asm/statfs.h |  5 +++++
 2 files changed, 24 insertions(+), 19 deletions(-)
arch/x86/include/uapi/asm/stat.h +19 -19
index 7b3ddc3..e9d6951 100644
@@ -78,26 +78,26 @@ struct stat64 {
 #else /* __i386__ */
 
 struct stat {
-	unsigned long	st_dev;
-	unsigned long	st_ino;
-	unsigned long	st_nlink;
-
-	unsigned int	st_mode;
-	unsigned int	st_uid;
-	unsigned int	st_gid;
-	unsigned int	__pad0;
-	unsigned long	st_rdev;
-	long		st_size;
-	long		st_blksize;
-	long		st_blocks;	/* Number 512-byte blocks allocated. */
+	unsigned long long	st_dev;
+	unsigned long long	st_ino;
+	unsigned long long	st_nlink;
 
-	unsigned long	st_atime;
-	unsigned long	st_atime_nsec;
-	unsigned long	st_mtime;
-	unsigned long	st_mtime_nsec;
-	unsigned long	st_ctime;
-	unsigned long   st_ctime_nsec;
-	long		__unused[3];
+	unsigned int		st_mode;
+	unsigned int		st_uid;
+	unsigned int		st_gid;
+	unsigned int		__pad0;
+	unsigned long long	st_rdev;
+	long long		st_size;
+	long long		st_blksize;
+	long long		st_blocks;	/* Number 512-byte blocks allocated. */
+
+	unsigned long long	st_atime;
+	unsigned long long	st_atime_nsec;
+	unsigned long long	st_mtime;
+	unsigned long long	st_mtime_nsec;
+	unsigned long long	st_ctime;
+	unsigned long long	st_ctime_nsec;
+	long long		__unused[3];
 };
 
 /* We don't need to memset the whole thing just to initialize the padding */
arch/x86/include/uapi/asm/statfs.h +5 -0
index 2d0adbf..3cb5744 100644
@@ -8,5 +8,10 @@
  */
 #define ARCH_PACK_COMPAT_STATFS64 __attribute__((packed,aligned(4)))
 
+/* For x86-64, both the 64bit and x32 ABIs have 64bit fields. */
+#ifdef __x86_64__
+#define __statfs_word __u64
+#endif
+
 #include <asm-generic/statfs.h>
 #endif /* _ASM_X86_STATFS_H */
Signature · 1 line
1.8.2.1
#1 lore raw
Quoted 5 lines · Mike Frysinger

When including these headers in the x32 ABI, the structs get declared with 32bit sizes which is incorrect. Use long long and such to make it work both with x32 and x86_64.

I'm not sure if it is okay to change the types, even within the same size. Perhaps use __u64/__s64?

-hpa

#2 lore raw
Quoted 7 lines · On Thursday 09 May 2013 00:04:03 H. Peter Anvin wrote:
Quoted 3 lines · Mike Frysinger

When including these headers in the x32 ABI, the structs get declared with 32bit sizes which is incorrect. Use long long and such to make it work both with x32 and x86_64.

I'm not sure if it is okay to change the types, even within the same size. Perhaps use __u64/__s64?

sorry, i don't follow. changing types isn't ok (unsigned long to unsigned long long), but changing to __u64 is ok (unsigned long to __u64 which is typedefed to unsigned long long) ?

i don't have a problem using __u64/__s64, i just don't understand your logic. -mike

#3 lore raw
Quoted 9 lines · Mike Frysinger
Quoted 7 lines · On Thursday 09 May 2013 00:04:03 H. Peter Anvin wrote:
Quoted 3 lines · Mike Frysinger

When including these headers in the x32 ABI, the structs get declared with 32bit sizes which is incorrect. Use long long and such to make it work both with x32 and x86_64.

I'm not sure if it is okay to change the types, even within the same size. Perhaps use __u64/__s64?

Quoted 7 lines

sorry, i don't follow. changing types isn't ok (unsigned long to unsigned long long), but changing to __u64 is ok (unsigned long to __u64 which is typedefed to unsigned long long) ?

i don't have a problem using __u64/__s64, i just don't understand your logic.

In userspace, __u64 is often defined as "unsigned long" on 64 bits.

-hpa

#4 lore raw
Quoted 10 lines · On Thursday 09 May 2013 00:18:15 H. Peter Anvin wrote:
Quoted 9 lines · Mike Frysinger
Quoted 7 lines · On Thursday 09 May 2013 00:04:03 H. Peter Anvin wrote:
Quoted 3 lines · Mike Frysinger

When including these headers in the x32 ABI, the structs get declared with 32bit sizes which is incorrect. Use long long and such to make it work both with x32 and x86_64.

I'm not sure if it is okay to change the types, even within the same size. Perhaps use __u64/__s64?

Quoted 8 lines
Quoted 6 lines

sorry, i don't follow. changing types isn't ok (unsigned long to unsigned long long), but changing to __u64 is ok (unsigned long to __u64 which is typedefed to unsigned long long) ?

i don't have a problem using __u64/__s64, i just don't understand your logic.

In userspace, __u64 is often defined as "unsigned long" on 64 bits.

my tests would seem to indicate otherwise, at least for x86:

$ gcc -E - <<<"#include <linux/types.h>" | grep '__u64;'
__extension__ typedef unsigned long long __u64;
$ gcc -m32 -E - <<<"#include <linux/types.h>" | grep '__u64;'
__extension__ typedef unsigned long long __u64;
$ gcc -mx32 -E - <<<"#include <linux/types.h>" | grep '__u64;'
__extension__ typedef unsigned long long __u64;

and doing a printf("%i\n", sizeof(__u64)) shows 8 for each of the above builds -mike

#5 lore raw

Hm... Okay, I'm mistaken then. I guess it doesn't matter.

Quoted 33 lines · Mike Frysinger
Quoted 10 lines · On Thursday 09 May 2013 00:18:15 H. Peter Anvin wrote:
Quoted 9 lines · Mike Frysinger
Quoted 7 lines · On Thursday 09 May 2013 00:04:03 H. Peter Anvin wrote:
Quoted 3 lines · Mike Frysinger

When including these headers in the x32 ABI, the structs get declared with 32bit sizes which is incorrect. Use long long and such to make it work both with x32 and x86_64.

I'm not sure if it is okay to change the types, even within the same size. Perhaps use __u64/__s64?

Quoted 8 lines
Quoted 6 lines

sorry, i don't follow. changing types isn't ok (unsigned long to unsigned long long), but changing to __u64 is ok (unsigned long to __u64 which is typedefed to unsigned long long) ?

i don't have a problem using __u64/__s64, i just don't understand your logic.

In userspace, __u64 is often defined as "unsigned long" on 64 bits.

my tests would seem to indicate otherwise, at least for x86:

$ gcc -E - <<<"#include <linux/types.h>" | grep '__u64;'
__extension__ typedef unsigned long long __u64;
$ gcc -m32 -E - <<<"#include <linux/types.h>" | grep '__u64;'
__extension__ typedef unsigned long long __u64;
$ gcc -mx32 -E - <<<"#include <linux/types.h>" | grep '__u64;'
__extension__ typedef unsigned long long __u64;

and doing a printf("%i\n", sizeof(__u64)) shows 8 for each of the above builds
-mike

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#6 lore raw
In reply to Mike Frysinger
Quoted 6 lines · Mike Frysinger
arch/x86/include/uapi/asm/statfs.h +0 -0
index 2d0adbf..3cb5744 100644

arch/x86/include/uapi/asm/statfs.h line 17

Quoted 10 lines
arch/x86/include/uapi/asm/statfs.h +5 -0
@@ -8,5 +8,10 @@
  */
 #define ARCH_PACK_COMPAT_STATFS64 __attribute__((packed,aligned(4)))
 
+/* For x86-64, both the 64bit and x32 ABIs have 64bit fields. */
+#ifdef __x86_64__
+#define __statfs_word __u64
+#endif
+
 #include <asm-generic/statfs.h>
 #endif /* _ASM_X86_STATFS_H */

... or is this what you meant to use?

-hpa

#7 lore raw
Quoted 9 lines · On Thursday 09 May 2013 00:04:28 H. Peter Anvin wrote:
Quoted 8 lines · Mike Frysinger
arch/x86/include/uapi/asm/statfs.h +5 -0
+/* For x86-64, both the 64bit and x32 ABIs have 64bit fields. */
+#ifdef __x86_64__
+#define __statfs_word __u64
+#endif
+
Quoted 4 lines
Quoted 2 lines

#include <asm-generic/statfs.h>
#endif /* _ASM_X86_STATFS_H */

... or is this what you meant to use?

i didn't intend to use this for stat. that macro is a hook the common asm- generic/statfs.h header provides for arches.

although maybe the better fix for statfs.h is to do:

include/uapi/asm-generic/statfs.h +1 -1
@@ -13,7 +13,7 @@
  */
 #ifndef __statfs_word
 #if __BITS_PER_LONG == 64
-#define __statfs_word long
+#define __statfs_word __u64
 #else
 #define __statfs_word __u32
 #endif

-mike