Skip to contentSkip to conversation

Use __kernel_long_t/__kernel_ulong_t in <linux/resource.h>

PATCH In review H.J. Lu 3 participants 8 messages Dec 25, 2013 – Dec 26, 2013

lore
Share & tools
lore

H.J. Lu

author
#0 lore raw

PATCH 1/1 Use __kernel_long_t/__kernel_ulong_t in <linux/resource.h>

Both x32 and x86-64 use the same struct rusage and struct rlimit for system calls. But x32 log is 32-bit. This patch change uapi <linux/resource.h> to use __kernel_long_t in struct rusage and __kernel_ulong_t in and struct rlimit.

---
 include/uapi/linux/resource.h | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
include/uapi/linux/resource.h +16 -16
index e0ed284..36fb3b5 100644
@@ -23,25 +23,25 @@
 struct	rusage {
 	struct timeval ru_utime;	/* user time used */
 	struct timeval ru_stime;	/* system time used */
-	long	ru_maxrss;		/* maximum resident set size */
-	long	ru_ixrss;		/* integral shared memory size */
-	long	ru_idrss;		/* integral unshared data size */
-	long	ru_isrss;		/* integral unshared stack size */
-	long	ru_minflt;		/* page reclaims */
-	long	ru_majflt;		/* page faults */
-	long	ru_nswap;		/* swaps */
-	long	ru_inblock;		/* block input operations */
-	long	ru_oublock;		/* block output operations */
-	long	ru_msgsnd;		/* messages sent */
-	long	ru_msgrcv;		/* messages received */
-	long	ru_nsignals;		/* signals received */
-	long	ru_nvcsw;		/* voluntary context switches */
-	long	ru_nivcsw;		/* involuntary " */
+	__kernel_long_t	ru_maxrss;	/* maximum resident set size */
+	__kernel_long_t	ru_ixrss;	/* integral shared memory size */
+	__kernel_long_t	ru_idrss;	/* integral unshared data size */
+	__kernel_long_t	ru_isrss;	/* integral unshared stack size */
+	__kernel_long_t	ru_minflt;	/* page reclaims */
+	__kernel_long_t	ru_majflt;	/* page faults */
+	__kernel_long_t	ru_nswap;	/* swaps */
+	__kernel_long_t	ru_inblock;	/* block input operations */
+	__kernel_long_t	ru_oublock;	/* block output operations */
+	__kernel_long_t	ru_msgsnd;	/* messages sent */
+	__kernel_long_t	ru_msgrcv;	/* messages received */
+	__kernel_long_t	ru_nsignals;	/* signals received */
+	__kernel_long_t	ru_nvcsw;	/* voluntary context switches */
+	__kernel_long_t	ru_nivcsw;	/* involuntary " */
 };
 
 struct rlimit {
-	unsigned long	rlim_cur;
-	unsigned long	rlim_max;
+	__kernel_ulong_t	rlim_cur;
+	__kernel_ulong_t	rlim_max;
 };
 
 #define RLIM64_INFINITY		(~0ULL)
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 4 lines · H.J. Lu

Both x32 and x86-64 use the same struct rusage and struct rlimit for system calls. But x32 log is 32-bit. This patch change uapi <linux/resource.h> to use __kernel_long_t in struct rusage and __kernel_ulong_t in and struct rlimit.

a) please send all your related patches as a series
b) explain how these changes to shared ABI headers:

1) do not break any architecture, especially mips N32 which is the MIPS equivalent of x32
2) do not break existing x32 binaries
3) fix existing and future x32 binaries

c) why you suddenly need these changes now and not when the x32 ABI support was submitted and hopefully heavily tested

author
#2 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · H.J. Lu

Both x32 and x86-64 use the same struct rusage and struct rlimit for system calls. But x32 log is 32-bit. This patch change uapi <linux/resource.h> to use __kernel_long_t in struct rusage and __kernel_ulong_t in and struct rlimit.

a) please send all your related patches as a series

My patches are independent of each other. They can be applied in order.

Quoted 4 lines

b) explain how these changes to shared ABI headers:

1) do not break any architecture, especially mips N32 which is the MIPS equivalent of x32

I am not familiar with N32 system call interface. My patch may break N32 if N32 __kernel_long_t doesn't match what is used. I will update my patches to limit my changes to __BITS_PER_LONG == 64.

Quoted 2 lines

2) do not break existing x32 binaries
3) fix existing and future x32 binaries

My patches just update kernel uabi header files to match x32 system calls. They don't break any x32 binaries, current and future.

Quoted 2 lines

c) why you suddenly need these changes now and not when the x32 ABI support was submitted and hopefully heavily tested

Kernel headers had been wrong for -m32/-mx32 on x86-64 for a long long time. Linux/x86-64 normally use header files from glibc, which avoids broken kernel header files. Kernel uabi header files fix -m32, but not -mx32, which I am working on now.

Thanks.

Signature · 1 line
H.J.
author
#3 lore raw
Quoted 7 lines · H.J. Lu
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · H.J. Lu

Both x32 and x86-64 use the same struct rusage and struct rlimit for system calls. But x32 log is 32-bit. This patch change uapi <linux/resource.h> to use __kernel_long_t in struct rusage and __kernel_ulong_t in and struct rlimit.

Quoted 5 lines
Quoted 1 line

a) please send all your related patches as a series

My patches are independent of each other. They can be applied in order.

I meant to say "they can be applied in any order."

Signature · 1 line
H.J.
#4 lore raw
In reply to H.J. Lu
Quoted 10 lines · H.J. Lu
Quoted 3 lines

c) why you suddenly need these changes now and not when the x32 ABI support was submitted and hopefully heavily tested

Kernel headers had been wrong for -m32/-mx32 on x86-64 for a long long time. Linux/x86-64 normally use header files from glibc, which avoids broken kernel header files. Kernel uabi header files fix -m32, but not -mx32, which I am working on now.

In other words, this work is really part of making *libc make use the kernel uabi headers, which is a valuable work. The fact that the kernel headers never got fully ported to x32 is a big reason why x32 is still labeled experimental.

MIPS N32 and ARM64 ILP32 are x32-like ABIs which of course need to not be broken. However, currently __kernel_[u]long_t is [unsigned] long for all ABIs other than x32, so changing [unsigned] long to __kernel_[u]long_t will be a null change for anything but x32. They perhaps *SHOULD* be different for N32 or ARM64 ILP32, but that is for those arch maintainers to set.

However, I believe H.J.'s patches from this morning conditionalizing this on __BITS_PER_LONG are just plain wrong.

-hpa

author
#5 lore raw
Quoted 24 lines · H. Peter Anvin
Quoted 10 lines · H.J. Lu
Quoted 3 lines

c) why you suddenly need these changes now and not when the x32 ABI support was submitted and hopefully heavily tested

Kernel headers had been wrong for -m32/-mx32 on x86-64 for a long long time. Linux/x86-64 normally use header files from glibc, which avoids broken kernel header files. Kernel uabi header files fix -m32, but not -mx32, which I am working on now.

In other words, this work is really part of making *libc make use the kernel uabi headers, which is a valuable work. The fact that the kernel headers never got fully ported to x32 is a big reason why x32 is still labeled experimental.

MIPS N32 and ARM64 ILP32 are x32-like ABIs which of course need to not be broken. However, currently __kernel_[u]long_t is [unsigned] long for all ABIs other than x32, so changing [unsigned] long to __kernel_[u]long_t will be a null change for anything but x32. They perhaps *SHOULD* be different for N32 or ARM64 ILP32, but that is for those arch maintainers to set.

Quoted 2 lines

However, I believe H.J.'s patches from this morning conditionalizing this on __BITS_PER_LONG are just plain wrong.

FWIW, I prefer my first alternative. I only added the second one since I can't test for other ABIs.

I am enclosing my kernel header file checker. It compares kernel header files against glibc header files for -m64, -m32 and -mx32.

Signature · 1 line
H.J.
#6 lore raw
In reply to H.J. Lu
Quoted 6 lines · H.J. Lu
Quoted 2 lines

a) please send all your related patches as a series

My patches are independent of each other. They can be applied in order.

Sure, but the convention in the Linux community is to send them all as a "series" using git send-email, preferably with a introductory cover letter as the "0/N patch" so they arrive in a single thread and can be reviewed together. Otherwise bits tend to get lost in the enormous flood of email that is LKML.

-hpa

author
#7 lore raw
In reply to H.J. Lu
Quoted 4 lines · H.J. Lu

Both x32 and x86-64 use the same struct rusage and struct rlimit for system calls. But x32 log is 32-bit. This patch change uapi <linux/resource.h> to use __kernel_long_t in struct rusage and __kernel_ulong_t in and struct rlimit.

Here is the updated patch which uses __kernel_long_t/__kernel_ulong_t only if __BITS_PER_LONG == 64.

H.J.

Quoted 1 line

From d2a3409eb9aecd545a3f9c384dd55cfc870122ac Mon Sep 17 00:00:00 2001

From: "H.J. Lu" <[email protected]>
Date: Wed, 25 Dec 2013 06:50:33 -0800
Subject: [PATCH] Use __kernel_long_t/__kernel_ulong_t in <linux/resource.h>

Both x32 and x86-64 use the same struct rusage and struct rlimit for system calls. But x32 log is 32-bit. This patch change uapi <linux/resource.h> to use __kernel_long_t in struct rusage and __kernel_ulong_t in and struct rlimit if __BITS_PER_LONG == 64.

---
 include/uapi/linux/resource.h | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
include/uapi/linux/resource.h +24 -2
index e0ed284..87d2daa 100644
@@ -23,6 +23,22 @@
 struct	rusage {
 	struct timeval ru_utime;	/* user time used */
 	struct timeval ru_stime;	/* system time used */
+#if __BITS_PER_LONG == 64
+	__kernel_long_t	ru_maxrss;	/* maximum resident set size */
+	__kernel_long_t	ru_ixrss;	/* integral shared memory size */
+	__kernel_long_t	ru_idrss;	/* integral unshared data size */
+	__kernel_long_t	ru_isrss;	/* integral unshared stack size */
+	__kernel_long_t	ru_minflt;	/* page reclaims */
+	__kernel_long_t	ru_majflt;	/* page faults */
+	__kernel_long_t	ru_nswap;	/* swaps */
+	__kernel_long_t	ru_inblock;	/* block input operations */
+	__kernel_long_t	ru_oublock;	/* block output operations */
+	__kernel_long_t	ru_msgsnd;	/* messages sent */
+	__kernel_long_t	ru_msgrcv;	/* messages received */
+	__kernel_long_t	ru_nsignals;	/* signals received */
+	__kernel_long_t	ru_nvcsw;	/* voluntary context switches */
+	__kernel_long_t	ru_nivcsw;	/* involuntary " */
+#else
 	long	ru_maxrss;		/* maximum resident set size */
 	long	ru_ixrss;		/* integral shared memory size */
 	long	ru_idrss;		/* integral unshared data size */
@@ -37,11 +53,17 @@ struct	rusage {
 	long	ru_nsignals;		/* signals received */
 	long	ru_nvcsw;		/* voluntary context switches */
 	long	ru_nivcsw;		/* involuntary " */
+#endif
 };
 
 struct rlimit {
-	unsigned long	rlim_cur;
-	unsigned long	rlim_max;
+#if __BITS_PER_LONG == 64
+	__kernel_ulong_t	rlim_cur;
+	__kernel_ulong_t	rlim_max;
+#else
+	unsigned long		rlim_cur;
+	unsigned long		rlim_max;
+#endif
 };
 
 #define RLIM64_INFINITY		(~0ULL)
Signature · 1 line
1.8.4.2