All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t in userspace
@ 2022-06-21 12:03 ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2022-06-21 12:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arch, linux-api, libc-alpha, arnd, ltp, David.Laight, zack,
	dhowells, Cyril Hrubis

This changes the __u64 and __s64 in userspace on 64bit platforms from
long long (unsigned) int to just long (unsigned) int in order to match
the uint64_t and int64_t size in userspace for C code.

We cannot make the change for C++ since that would be non-backwards
compatible change and may cause possible regressions and even
compilation failures, e.g. overloaded function may no longer find a
correct match.

This allows us to use the kernel structure definitions in userspace in C
code. For example we can use PRIu64 and PRId64 modifiers in printf() to
print structure membere. Morever with this there would be no need to
redefine these structures in an libc implementations as it is done now.

Consider for example the newly added statx() syscall. If we use the
header from uapi we will get warnings when attempting to print it's
members as:

	printf("%" PRIu64 "\n", stx.stx_size);

We get:

	warning: format '%lu' expects argument of type 'long unsigned int',
	         but argument 5 has type '__u64' {aka 'long long unsigned int'}

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/uapi/asm-generic/types.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

v2: Make sure we do not break C++ applications
v3: Update commit message to explain C++ exclusion

diff --git a/include/uapi/asm-generic/types.h b/include/uapi/asm-generic/types.h
index dfaa50d99d8f..11e468a39d1e 100644
--- a/include/uapi/asm-generic/types.h
+++ b/include/uapi/asm-generic/types.h
@@ -1,9 +1,16 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _ASM_GENERIC_TYPES_H
 #define _ASM_GENERIC_TYPES_H
+
+#include <asm/bitsperlong.h>
+
 /*
- * int-ll64 is used everywhere now.
+ * int-ll64 is used everywhere in kernel now.
  */
-#include <asm-generic/int-ll64.h>
+#if !defined(__KERNEL__) && !defined(__cplusplus) && __BITSPERLONG == 64
+# include <asm-generic/int-l64.h>
+#else
+# include <asm-generic/int-ll64.h>
+#endif
 
 #endif /* _ASM_GENERIC_TYPES_H */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t in userspace
@ 2022-06-21 12:03 ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2022-06-21 12:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arch, libc-alpha, arnd, linux-api, dhowells, David.Laight,
	zack, ltp

This changes the __u64 and __s64 in userspace on 64bit platforms from
long long (unsigned) int to just long (unsigned) int in order to match
the uint64_t and int64_t size in userspace for C code.

We cannot make the change for C++ since that would be non-backwards
compatible change and may cause possible regressions and even
compilation failures, e.g. overloaded function may no longer find a
correct match.

This allows us to use the kernel structure definitions in userspace in C
code. For example we can use PRIu64 and PRId64 modifiers in printf() to
print structure membere. Morever with this there would be no need to
redefine these structures in an libc implementations as it is done now.

Consider for example the newly added statx() syscall. If we use the
header from uapi we will get warnings when attempting to print it's
members as:

	printf("%" PRIu64 "\n", stx.stx_size);

We get:

	warning: format '%lu' expects argument of type 'long unsigned int',
	         but argument 5 has type '__u64' {aka 'long long unsigned int'}

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/uapi/asm-generic/types.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

v2: Make sure we do not break C++ applications
v3: Update commit message to explain C++ exclusion

diff --git a/include/uapi/asm-generic/types.h b/include/uapi/asm-generic/types.h
index dfaa50d99d8f..11e468a39d1e 100644
--- a/include/uapi/asm-generic/types.h
+++ b/include/uapi/asm-generic/types.h
@@ -1,9 +1,16 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 #ifndef _ASM_GENERIC_TYPES_H
 #define _ASM_GENERIC_TYPES_H
+
+#include <asm/bitsperlong.h>
+
 /*
- * int-ll64 is used everywhere now.
+ * int-ll64 is used everywhere in kernel now.
  */
-#include <asm-generic/int-ll64.h>
+#if !defined(__KERNEL__) && !defined(__cplusplus) && __BITSPERLONG == 64
+# include <asm-generic/int-l64.h>
+#else
+# include <asm-generic/int-ll64.h>
+#endif
 
 #endif /* _ASM_GENERIC_TYPES_H */
-- 
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t in userspace
  2022-06-21 12:03 ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Cyril Hrubis
@ 2022-06-21 13:01   ` Alejandro Colomar
  -1 siblings, 0 replies; 10+ messages in thread
From: Alejandro Colomar @ 2022-06-21 13:01 UTC (permalink / raw)
  To: Cyril Hrubis, linux-kernel
  Cc: linux-arch, libc-alpha, linux-api, dhowells, David.Laight, zack,
	ltp, linux-man

On 6/21/22 14:03, Cyril Hrubis wrote:
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace for C code.
> 
> We cannot make the change for C++ since that would be non-backwards
> compatible change and may cause possible regressions and even
> compilation failures, e.g. overloaded function may no longer find a
> correct match.
> 
> This allows us to use the kernel structure definitions in userspace in C
> code. For example we can use PRIu64 and PRId64 modifiers in printf() to
> print structure membere. Morever with this there would be no need to
> redefine these structures in an libc implementations as it is done now.
> 
> Consider for example the newly added statx() syscall. If we use the
> header from uapi we will get warnings when attempting to print it's
> members as:
> 
> 	printf("%" PRIu64 "\n", stx.stx_size);
> 
> We get:
> 
> 	warning: format '%lu' expects argument of type 'long unsigned int',
> 	         but argument 5 has type '__u64' {aka 'long long unsigned int'}
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

Acked-by: Alejandro Colomar <alx.manpages@gmail.com>

> ---
>   include/uapi/asm-generic/types.h | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> v2: Make sure we do not break C++ applications
> v3: Update commit message to explain C++ exclusion
> 
> diff --git a/include/uapi/asm-generic/types.h b/include/uapi/asm-generic/types.h
> index dfaa50d99d8f..11e468a39d1e 100644

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t in userspace
@ 2022-06-21 13:01   ` Alejandro Colomar
  0 siblings, 0 replies; 10+ messages in thread
From: Alejandro Colomar @ 2022-06-21 13:01 UTC (permalink / raw)
  To: Cyril Hrubis, linux-kernel
  Cc: linux-arch, linux-man, libc-alpha, linux-api, dhowells,
	David.Laight, zack, ltp

On 6/21/22 14:03, Cyril Hrubis wrote:
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace for C code.
> 
> We cannot make the change for C++ since that would be non-backwards
> compatible change and may cause possible regressions and even
> compilation failures, e.g. overloaded function may no longer find a
> correct match.
> 
> This allows us to use the kernel structure definitions in userspace in C
> code. For example we can use PRIu64 and PRId64 modifiers in printf() to
> print structure membere. Morever with this there would be no need to
> redefine these structures in an libc implementations as it is done now.
> 
> Consider for example the newly added statx() syscall. If we use the
> header from uapi we will get warnings when attempting to print it's
> members as:
> 
> 	printf("%" PRIu64 "\n", stx.stx_size);
> 
> We get:
> 
> 	warning: format '%lu' expects argument of type 'long unsigned int',
> 	         but argument 5 has type '__u64' {aka 'long long unsigned int'}
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

Acked-by: Alejandro Colomar <alx.manpages@gmail.com>

> ---
>   include/uapi/asm-generic/types.h | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> v2: Make sure we do not break C++ applications
> v3: Update commit message to explain C++ exclusion
> 
> diff --git a/include/uapi/asm-generic/types.h b/include/uapi/asm-generic/types.h
> index dfaa50d99d8f..11e468a39d1e 100644

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t in userspace
  2022-06-21 12:03 ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Cyril Hrubis
@ 2022-06-21 13:04   ` David Laight
  -1 siblings, 0 replies; 10+ messages in thread
From: David Laight @ 2022-06-21 13:04 UTC (permalink / raw)
  To: 'Cyril Hrubis', linux-kernel
  Cc: linux-arch, linux-api, libc-alpha, arnd, ltp, zack, dhowells

From: Cyril Hrubis 
> Sent: 21 June 2022 13:04
> 
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace for C code.
> 
> We cannot make the change for C++ since that would be non-backwards
> compatible change and may cause possible regressions and even
> compilation failures, e.g. overloaded function may no longer find a
> correct match.

Isn't is enough just to mention C++ name mangling?

	David

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t in userspace
@ 2022-06-21 13:04   ` David Laight
  0 siblings, 0 replies; 10+ messages in thread
From: David Laight @ 2022-06-21 13:04 UTC (permalink / raw)
  To: 'Cyril Hrubis', linux-kernel
  Cc: linux-arch, libc-alpha, arnd, linux-api, dhowells, zack, ltp

From: Cyril Hrubis 
> Sent: 21 June 2022 13:04
> 
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace for C code.
> 
> We cannot make the change for C++ since that would be non-backwards
> compatible change and may cause possible regressions and even
> compilation failures, e.g. overloaded function may no longer find a
> correct match.

Isn't is enough just to mention C++ name mangling?

	David

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t in userspace
  2022-06-21 13:04   ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " David Laight
@ 2022-06-21 14:15     ` Cyril Hrubis
  -1 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2022-06-21 14:15 UTC (permalink / raw)
  To: David Laight
  Cc: linux-kernel, linux-arch, linux-api, libc-alpha, arnd, ltp, zack,
	dhowells

Hi!
> > This changes the __u64 and __s64 in userspace on 64bit platforms from
> > long long (unsigned) int to just long (unsigned) int in order to match
> > the uint64_t and int64_t size in userspace for C code.
> > 
> > We cannot make the change for C++ since that would be non-backwards
> > compatible change and may cause possible regressions and even
> > compilation failures, e.g. overloaded function may no longer find a
> > correct match.
> 
> Isn't is enough just to mention C++ name mangling?

I just picked up the argument that was brought up in the discussion
about the v1 patch and used it as a concrete example. Mangling is I
guess more straightforward example of a breakage. I can change the
description if there is consensus that such description would be better.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t in userspace
@ 2022-06-21 14:15     ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2022-06-21 14:15 UTC (permalink / raw)
  To: David Laight
  Cc: linux-arch, libc-alpha, arnd, linux-api, linux-kernel, dhowells,
	zack, ltp

Hi!
> > This changes the __u64 and __s64 in userspace on 64bit platforms from
> > long long (unsigned) int to just long (unsigned) int in order to match
> > the uint64_t and int64_t size in userspace for C code.
> > 
> > We cannot make the change for C++ since that would be non-backwards
> > compatible change and may cause possible regressions and even
> > compilation failures, e.g. overloaded function may no longer find a
> > correct match.
> 
> Isn't is enough just to mention C++ name mangling?

I just picked up the argument that was brought up in the discussion
about the v1 patch and used it as a concrete example. Mangling is I
guess more straightforward example of a breakage. I can change the
description if there is consensus that such description would be better.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t in userspace
  2022-06-21 12:03 ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Cyril Hrubis
@ 2022-06-23  7:48   ` Arnd Bergmann
  -1 siblings, 0 replies; 10+ messages in thread
From: Arnd Bergmann @ 2022-06-23  7:48 UTC (permalink / raw)
  To: Cyril Hrubis
  Cc: Linux Kernel Mailing List, linux-arch, Linux API, GNU C Library,
	Arnd Bergmann, LTP List, David Laight, Zack Weinberg,
	David Howells

On Tue, Jun 21, 2022 at 2:03 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace for C code.
>
> We cannot make the change for C++ since that would be non-backwards
> compatible change and may cause possible regressions and even
> compilation failures, e.g. overloaded function may no longer find a
> correct match.
>
> This allows us to use the kernel structure definitions in userspace in C
> code. For example we can use PRIu64 and PRId64 modifiers in printf() to
> print structure membere. Morever with this there would be no need to
> redefine these structures in an libc implementations as it is done now.
>
> Consider for example the newly added statx() syscall. If we use the
> header from uapi we will get warnings when attempting to print it's
> members as:
>
>         printf("%" PRIu64 "\n", stx.stx_size);
>
> We get:
>
>         warning: format '%lu' expects argument of type 'long unsigned int',
>                  but argument 5 has type '__u64' {aka 'long long unsigned int'}
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

I understand the problem you are solving here, but I'm not convinced
that this is actually an overall improvement as you introduce two
similar problems in its place:

- any application that has previously used the correct %ll or %ull format
  strings for members of kernel data structures now gains a new warning

- After your patch, neither the PRIu64 nor the "%ull" format strings are
  portable across old and new kernel headers, so applications are now
  forced to add an explicit cast to 'unsigned long long' or 'uint64_t' to
  every print statement for these members if they want to guarantee a
  clean build.

Do you have an estimate of how many build time warnings in common
packages actually get fixed by your patch, compared to the number
of warnings that get introduced?

        Arnd

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t in userspace
@ 2022-06-23  7:48   ` Arnd Bergmann
  0 siblings, 0 replies; 10+ messages in thread
From: Arnd Bergmann @ 2022-06-23  7:48 UTC (permalink / raw)
  To: Cyril Hrubis
  Cc: linux-arch, GNU C Library, Arnd Bergmann, Linux API,
	Linux Kernel Mailing List, David Howells, David Laight,
	Zack Weinberg, LTP List

On Tue, Jun 21, 2022 at 2:03 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> This changes the __u64 and __s64 in userspace on 64bit platforms from
> long long (unsigned) int to just long (unsigned) int in order to match
> the uint64_t and int64_t size in userspace for C code.
>
> We cannot make the change for C++ since that would be non-backwards
> compatible change and may cause possible regressions and even
> compilation failures, e.g. overloaded function may no longer find a
> correct match.
>
> This allows us to use the kernel structure definitions in userspace in C
> code. For example we can use PRIu64 and PRId64 modifiers in printf() to
> print structure membere. Morever with this there would be no need to
> redefine these structures in an libc implementations as it is done now.
>
> Consider for example the newly added statx() syscall. If we use the
> header from uapi we will get warnings when attempting to print it's
> members as:
>
>         printf("%" PRIu64 "\n", stx.stx_size);
>
> We get:
>
>         warning: format '%lu' expects argument of type 'long unsigned int',
>                  but argument 5 has type '__u64' {aka 'long long unsigned int'}
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

I understand the problem you are solving here, but I'm not convinced
that this is actually an overall improvement as you introduce two
similar problems in its place:

- any application that has previously used the correct %ll or %ull format
  strings for members of kernel data structures now gains a new warning

- After your patch, neither the PRIu64 nor the "%ull" format strings are
  portable across old and new kernel headers, so applications are now
  forced to add an explicit cast to 'unsigned long long' or 'uint64_t' to
  every print statement for these members if they want to guarantee a
  clean build.

Do you have an estimate of how many build time warnings in common
packages actually get fixed by your patch, compared to the number
of warnings that get introduced?

        Arnd

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-23  7:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 12:03 [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t in userspace Cyril Hrubis
2022-06-21 12:03 ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Cyril Hrubis
2022-06-21 13:01 ` [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t " Alejandro Colomar
2022-06-21 13:01   ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Alejandro Colomar
2022-06-21 13:04 ` [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t " David Laight
2022-06-21 13:04   ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " David Laight
2022-06-21 14:15   ` [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t " Cyril Hrubis
2022-06-21 14:15     ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Cyril Hrubis
2022-06-23  7:48 ` [PATCH v3] uapi: Make __{u,s}64 match {u,}int64_t " Arnd Bergmann
2022-06-23  7:48   ` [LTP] [PATCH v3] uapi: Make __{u, s}64 match {u, }int64_t " Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.