public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
@ 2019-09-30 13:32 Lukasz Majewski
  2019-09-30 15:30 ` Joseph Myers
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Lukasz Majewski @ 2019-09-30 13:32 UTC (permalink / raw)
  To: Joseph Myers, Paul Eggert
  Cc: Alistair Francis, Arnd Bergmann, Alistair Francis, GNU C Library,
	Adhemerval Zanella, Florian Weimer, Carlos O'Donell,
	Stepan Golosunov, Florian Weimer, Zack Weinberg, Lukasz Majewski

Those functions allow easy conversion between Y2038 safe struct
__timespec64 and other time related data structures (like struct timeval
or struct timespec).

* include/time.h (valid_timeval_to_timespec64): Add.
* include/time.h (valid_timespec_to_timespec64): Likewise.
* include/time.h (valid_timespec64_to_timespec): Likewise.
* include/time.h (valid_timespec64_to_timeval): Likewise.

---
Changes for v10:
- Provide only conversion functions to work on "valid" time structures
  (no need to provide any excessive checks)
- Return values instead of pointers

Changes for v9:
- Update comments to be more concise and describe return values from
  conversion functions (according to Joseph's request).

Changes for v8:
- None

Changes for v7:
- None

Changes for v6:
- Remove the #ifdef guard on __ASSUME_TIME64_SYSCALLS as those functions
  may be needed for fallback execution paths (on e.g. __clock_settime64).

Changes for v5:
- This code is now only compiled in when __ASSUME_TIME64_SYSCALLS is NOT
  defined. Previously it was depending on #if __TIMESIZE != 64.

Changes for v4:
- None

Changes for v3:
- Remove misleading comments regarding clearing tv_pad values during
  conversion (as Linux kernel on its own ignores upper 32 bits of tv_nsec).

Changes for v3:
- Remove timespec64_clear_padding function - as kernel ignores upper 32
  bits of tv_nsec when passed via syscall to the Linux kernel

Changes for v2:
- Add timespec64_clear_padding function
---
 include/time.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/include/time.h b/include/time.h
index 9727786634..9878c2b2ca 100644
--- a/include/time.h
+++ b/include/time.h
@@ -178,5 +178,54 @@ in_time_t_range (__time64_t t)
   return s == t;
 }
 
+/* Convert a known valid struct timeval into a struct __timespec64.  */
+static inline struct __timespec64
+valid_timeval_to_timespec64 (const struct timeval tv)
+{
+  struct __timespec64 ts64;
+
+  ts64.tv_sec = tv.tv_sec;
+  ts64.tv_nsec = tv.tv_usec * 1000;
+
+  return ts64;
+}
+
+/* Convert a known valid struct timespec into a struct __timespec64.  */
+static inline struct __timespec64
+valid_timespec_to_timespec64 (const struct timespec ts)
+{
+  struct __timespec64 ts64;
+
+  ts64.tv_sec = ts.tv_sec;
+  ts64.tv_nsec = ts.tv_nsec;
+
+  return ts64;
+}
+
+/* Convert a valid and within range of struct timespec, struct
+   __timespec64 into a struct timespec.  */
+static inline struct timespec
+valid_timespec64_to_timespec (const struct __timespec64 ts64)
+{
+  struct timespec ts;
+
+  ts.tv_sec = (time_t) ts64.tv_sec;
+  ts.tv_nsec = ts64.tv_nsec;
+
+  return ts;
+}
+
+/* Convert a valid and within range of struct timeval struct
+   __timespec64 into a struct timeval.  */
+static inline struct timeval
+valid_timespec64_to_timeval (const struct __timespec64 ts64)
+{
+  struct timeval tv;
+
+  tv.tv_sec = (time_t) ts64.tv_sec;
+  tv.tv_usec = ts64.tv_nsec / 1000;
+
+  return tv;
+}
 #endif
 #endif
-- 
2.20.1

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-09-30 13:32 [PATCH v10] y2038: Provide conversion helpers for struct __timespec64 Lukasz Majewski
@ 2019-09-30 15:30 ` Joseph Myers
  2019-10-01 13:26 ` Joseph Myers
  2019-12-04 10:19 ` Dmitry V. Levin
  2 siblings, 0 replies; 15+ messages in thread
From: Joseph Myers @ 2019-09-30 15:30 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

On Mon, 30 Sep 2019, Lukasz Majewski wrote:

> Those functions allow easy conversion between Y2038 safe struct
> __timespec64 and other time related data structures (like struct timeval
> or struct timespec).
> 
> * include/time.h (valid_timeval_to_timespec64): Add.
> * include/time.h (valid_timespec_to_timespec64): Likewise.
> * include/time.h (valid_timespec64_to_timespec): Likewise.
> * include/time.h (valid_timespec64_to_timeval): Likewise.
> 
> ---
> Changes for v10:
> - Provide only conversion functions to work on "valid" time structures
>   (no need to provide any excessive checks)
> - Return values instead of pointers

This patch is OK, please commit.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-09-30 13:32 [PATCH v10] y2038: Provide conversion helpers for struct __timespec64 Lukasz Majewski
  2019-09-30 15:30 ` Joseph Myers
@ 2019-10-01 13:26 ` Joseph Myers
  2019-10-01 14:05   ` Lukasz Majewski
  2019-12-04 10:19 ` Dmitry V. Levin
  2 siblings, 1 reply; 15+ messages in thread
From: Joseph Myers @ 2019-10-01 13:26 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

This has broken the build of glibc for i686-gnu as struct timeval isn't 
defined at this point in the build.

In file included from /scratch/jmyers/glibc-bot/install/compilers/i686-gnu/sysroot/include/hurd/hurd_types.h:24,
                 from ../hurd/hurd.h:30,
                 from ../sysdeps/hurd/include/hurd.h:2,
                 from hurdid.c:18:
../include/time.h:183:51: error: parameter 1 ('tv') has incomplete type
 valid_timeval_to_timespec64 (const struct timeval tv)
                              ~~~~~~~~~~~~~~~~~~~~~^~
../include/time.h:221:1: error: return type is an incomplete type
 valid_timespec64_to_timeval (const struct __timespec64 ts64)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/time.h: In function 'valid_timespec64_to_timeval':
../include/time.h:223:18: error: storage size of 'tv' isn't known
   struct timeval tv;
                  ^~

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-10-01 13:26 ` Joseph Myers
@ 2019-10-01 14:05   ` Lukasz Majewski
  2019-10-01 15:25     ` Joseph Myers
  2019-10-01 21:54     ` Lukasz Majewski
  0 siblings, 2 replies; 15+ messages in thread
From: Lukasz Majewski @ 2019-10-01 14:05 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

[-- Attachment #1: Type: text/plain, Size: 1517 bytes --]

Hi Joseph,

> This has broken the build of glibc for i686-gnu as struct timeval
> isn't defined at this point in the build.

I've been using glibc-many.py script and the diff between builds w/
this patch was the same.

I had the UNRESOLVED: for i686-gnu glibc (with and without this patch)
And this seems like the one for hurd...

As there are already patches applied on top of this one - I suppose that
I shall provide incremental fix for it.

> 
> In file included from
> /scratch/jmyers/glibc-bot/install/compilers/i686-gnu/sysroot/include/hurd/hurd_types.h:24,
> from ../hurd/hurd.h:30, from ../sysdeps/hurd/include/hurd.h:2,
>                  from hurdid.c:18:
> ../include/time.h:183:51: error: parameter 1 ('tv') has incomplete
> type valid_timeval_to_timespec64 (const struct timeval tv)
>                               ~~~~~~~~~~~~~~~~~~~~~^~
> ../include/time.h:221:1: error: return type is an incomplete type
>  valid_timespec64_to_timeval (const struct __timespec64 ts64)
>  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../include/time.h: In function 'valid_timespec64_to_timeval':
> ../include/time.h:223:18: error: storage size of 'tv' isn't known
>    struct timeval tv;
>                   ^~
> 

I will submit fix ASAP.


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-10-01 14:05   ` Lukasz Majewski
@ 2019-10-01 15:25     ` Joseph Myers
  2019-10-01 21:54     ` Lukasz Majewski
  1 sibling, 0 replies; 15+ messages in thread
From: Joseph Myers @ 2019-10-01 15:25 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

On Tue, 1 Oct 2019, Lukasz Majewski wrote:

> I had the UNRESOLVED: for i686-gnu glibc (with and without this patch)
> And this seems like the one for hurd...

If you had UNRESOLVED rather than FAIL that means the build was broken at 
the time you did the "compilers" build.  You need to do the "compilers" 
build at a time when all glibc configurations are building OK, in order 
for it to be a good basis for testing the "glibcs" build.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-10-01 14:05   ` Lukasz Majewski
  2019-10-01 15:25     ` Joseph Myers
@ 2019-10-01 21:54     ` Lukasz Majewski
  2019-10-01 21:58       ` Joseph Myers
  1 sibling, 1 reply; 15+ messages in thread
From: Lukasz Majewski @ 2019-10-01 21:54 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

[-- Attachment #1: Type: text/plain, Size: 2389 bytes --]

Hi Joseph,

> Hi Joseph,
> 
> > This has broken the build of glibc for i686-gnu as struct timeval
> > isn't defined at this point in the build.  
> 
> I've been using glibc-many.py script and the diff between builds w/
> this patch was the same.
> 
> I had the UNRESOLVED: for i686-gnu glibc (with and without this patch)
> And this seems like the one for hurd...
> 
> As there are already patches applied on top of this one - I suppose
> that I shall provide incremental fix for it.
> 
> > 
> > In file included from
> > /scratch/jmyers/glibc-bot/install/compilers/i686-gnu/sysroot/include/hurd/hurd_types.h:24,
> > from ../hurd/hurd.h:30, from ../sysdeps/hurd/include/hurd.h:2,
> >                  from hurdid.c:18:
> > ../include/time.h:183:51: error: parameter 1 ('tv') has incomplete
> > type valid_timeval_to_timespec64 (const struct timeval tv)
> >                               ~~~~~~~~~~~~~~~~~~~~~^~
> > ../include/time.h:221:1: error: return type is an incomplete type
> >  valid_timespec64_to_timeval (const struct __timespec64 ts64)
> >  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ../include/time.h: In function 'valid_timespec64_to_timeval':
> > ../include/time.h:223:18: error: storage size of 'tv' isn't known
> >    struct timeval tv;
> >                   ^~
> >   
> 
> I will submit fix ASAP.

It seems to me like it would be best to add the missing
#include <sys/time.h> to HURD's #include <hurd/hurd_types.h> as it also
includes for example struct timespec header. However, is is not so
simple as this file is in hurd compiler includes 
(glibc-many-build/install/compilers/i686-gnu/sysroot/include/hurd/hurd_types.h).

The other option would be to add #include <sys/time.h> just before
struct __timespec64 conversion in ./include/time.h

I'm going to submit such patch for review.

> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> lukma@denx.de


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-10-01 21:54     ` Lukasz Majewski
@ 2019-10-01 21:58       ` Joseph Myers
  2019-10-01 22:15         ` Lukasz Majewski
  0 siblings, 1 reply; 15+ messages in thread
From: Joseph Myers @ 2019-10-01 21:58 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

On Tue, 1 Oct 2019, Lukasz Majewski wrote:

> It seems to me like it would be best to add the missing
> #include <sys/time.h> to HURD's #include <hurd/hurd_types.h> as it also
> includes for example struct timespec header. However, is is not so
> simple as this file is in hurd compiler includes 
> (glibc-many-build/install/compilers/i686-gnu/sysroot/include/hurd/hurd_types.h).
> 
> The other option would be to add #include <sys/time.h> just before
> struct __timespec64 conversion in ./include/time.h
> 
> I'm going to submit such patch for review.

How about including <bits/types/struct_timeval.h> in include/time.h 
(inside the !_ISOMAC conditional)?  It already includes 
<bits/types/locale_t.h>, for example; since it's using struct timeval, it 
seems natural for it to include the corresponding header (rather than a 
more general sys/time.h include).

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-10-01 21:58       ` Joseph Myers
@ 2019-10-01 22:15         ` Lukasz Majewski
  0 siblings, 0 replies; 15+ messages in thread
From: Lukasz Majewski @ 2019-10-01 22:15 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Paul Eggert, Alistair Francis, Arnd Bergmann, Alistair Francis,
	GNU C Library, Adhemerval Zanella, Florian Weimer,
	Carlos O'Donell, Stepan Golosunov, Florian Weimer,
	Zack Weinberg

[-- Attachment #1: Type: text/plain, Size: 1300 bytes --]

Hi Joseph,

> On Tue, 1 Oct 2019, Lukasz Majewski wrote:
> 
> > It seems to me like it would be best to add the missing
> > #include <sys/time.h> to HURD's #include <hurd/hurd_types.h> as it
> > also includes for example struct timespec header. However, is is
> > not so simple as this file is in hurd compiler includes 
> > (glibc-many-build/install/compilers/i686-gnu/sysroot/include/hurd/hurd_types.h).
> > 
> > The other option would be to add #include <sys/time.h> just before
> > struct __timespec64 conversion in ./include/time.h
> > 
> > I'm going to submit such patch for review.  
> 
> How about including <bits/types/struct_timeval.h> in include/time.h 
> (inside the !_ISOMAC conditional)?  It already includes 
> <bits/types/locale_t.h>, for example; since it's using struct
> timeval, it seems natural for it to include the corresponding header
> (rather than a more general sys/time.h include).
> 

Thanks for the hint. I will prepare and submit (after some testing)
patch using the above approach.


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-09-30 13:32 [PATCH v10] y2038: Provide conversion helpers for struct __timespec64 Lukasz Majewski
  2019-09-30 15:30 ` Joseph Myers
  2019-10-01 13:26 ` Joseph Myers
@ 2019-12-04 10:19 ` Dmitry V. Levin
  2019-12-04 10:34   ` Florian Weimer
                     ` (2 more replies)
  2 siblings, 3 replies; 15+ messages in thread
From: Dmitry V. Levin @ 2019-12-04 10:19 UTC (permalink / raw)
  To: libc-alpha
  Cc: Lukasz Majewski, Joseph Myers, Paul Eggert, Alistair Francis,
	Arnd Bergmann, Alistair Francis, Adhemerval Zanella,
	Florian Weimer, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

[-- Attachment #1: Type: text/plain, Size: 3738 bytes --]

On Mon, Sep 30, 2019 at 03:31:34PM +0200, Lukasz Majewski wrote:
> Those functions allow easy conversion between Y2038 safe struct
> __timespec64 and other time related data structures (like struct timeval
> or struct timespec).
> 
> * include/time.h (valid_timeval_to_timespec64): Add.
> * include/time.h (valid_timespec_to_timespec64): Likewise.
> * include/time.h (valid_timespec64_to_timespec): Likewise.
> * include/time.h (valid_timespec64_to_timeval): Likewise.
> 
> ---
> Changes for v10:
> - Provide only conversion functions to work on "valid" time structures
>   (no need to provide any excessive checks)
> - Return values instead of pointers
> 
> Changes for v9:
> - Update comments to be more concise and describe return values from
>   conversion functions (according to Joseph's request).
> 
> Changes for v8:
> - None
> 
> Changes for v7:
> - None
> 
> Changes for v6:
> - Remove the #ifdef guard on __ASSUME_TIME64_SYSCALLS as those functions
>   may be needed for fallback execution paths (on e.g. __clock_settime64).
> 
> Changes for v5:
> - This code is now only compiled in when __ASSUME_TIME64_SYSCALLS is NOT
>   defined. Previously it was depending on #if __TIMESIZE != 64.
> 
> Changes for v4:
> - None
> 
> Changes for v3:
> - Remove misleading comments regarding clearing tv_pad values during
>   conversion (as Linux kernel on its own ignores upper 32 bits of tv_nsec).
> 
> Changes for v3:
> - Remove timespec64_clear_padding function - as kernel ignores upper 32
>   bits of tv_nsec when passed via syscall to the Linux kernel
> 
> Changes for v2:
> - Add timespec64_clear_padding function
> ---
>  include/time.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/include/time.h b/include/time.h
> index 9727786634..9878c2b2ca 100644
> --- a/include/time.h
> +++ b/include/time.h
> @@ -178,5 +178,54 @@ in_time_t_range (__time64_t t)
>    return s == t;
>  }
>  
> +/* Convert a known valid struct timeval into a struct __timespec64.  */
> +static inline struct __timespec64
> +valid_timeval_to_timespec64 (const struct timeval tv)
> +{
> +  struct __timespec64 ts64;
> +
> +  ts64.tv_sec = tv.tv_sec;
> +  ts64.tv_nsec = tv.tv_usec * 1000;
> +
> +  return ts64;
> +}
> +
> +/* Convert a known valid struct timespec into a struct __timespec64.  */
> +static inline struct __timespec64
> +valid_timespec_to_timespec64 (const struct timespec ts)
> +{
> +  struct __timespec64 ts64;
> +
> +  ts64.tv_sec = ts.tv_sec;
> +  ts64.tv_nsec = ts.tv_nsec;
> +
> +  return ts64;
> +}
> +
> +/* Convert a valid and within range of struct timespec, struct
> +   __timespec64 into a struct timespec.  */
> +static inline struct timespec
> +valid_timespec64_to_timespec (const struct __timespec64 ts64)
> +{
> +  struct timespec ts;
> +
> +  ts.tv_sec = (time_t) ts64.tv_sec;
> +  ts.tv_nsec = ts64.tv_nsec;
> +
> +  return ts;
> +}
> +
> +/* Convert a valid and within range of struct timeval struct
> +   __timespec64 into a struct timeval.  */
> +static inline struct timeval
> +valid_timespec64_to_timeval (const struct __timespec64 ts64)
> +{
> +  struct timeval tv;
> +
> +  tv.tv_sec = (time_t) ts64.tv_sec;
> +  tv.tv_usec = ts64.tv_nsec / 1000;
> +
> +  return tv;
> +}
>  #endif
>  #endif

Unfortunately, this didn't work out as intended because Linux kernel prior
to commit 7b8474466ed97be458c825f34a85f2c2b84c3f95 (including released
version v5.4) did not zero the upper 32-bits of tv_nsec on 32-bit
architectures, which means that we have to do it in
valid_timeval_to_timespec64 and valid_timespec_to_timespec64 instead.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-12-04 10:19 ` Dmitry V. Levin
@ 2019-12-04 10:34   ` Florian Weimer
  2019-12-04 11:04     ` Lukasz Majewski
  2019-12-04 11:11   ` Arnd Bergmann
  2019-12-04 12:07   ` Joseph Myers
  2 siblings, 1 reply; 15+ messages in thread
From: Florian Weimer @ 2019-12-04 10:34 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: libc-alpha, Lukasz Majewski, Joseph Myers, Paul Eggert,
	Alistair Francis, Arnd Bergmann, Alistair Francis,
	Adhemerval Zanella, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

* Dmitry V. Levin:

> Unfortunately, this didn't work out as intended because Linux kernel prior
> to commit 7b8474466ed97be458c825f34a85f2c2b84c3f95 (including released
> version v5.4) did not zero the upper 32-bits of tv_nsec on 32-bit
> architectures, which means that we have to do it in
> valid_timeval_to_timespec64 and valid_timespec_to_timespec64 instead.

Can't we treat this as a critical kernel bug that needs fixing before
the kernels become usable?

I'm concern that this will make initializers for struct timespec64
invalid.  glibc can't intercept everything that goes into the kernel.

Thanks,
Florian

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-12-04 10:34   ` Florian Weimer
@ 2019-12-04 11:04     ` Lukasz Majewski
  2019-12-09  0:08       ` Dmitry V. Levin
  0 siblings, 1 reply; 15+ messages in thread
From: Lukasz Majewski @ 2019-12-04 11:04 UTC (permalink / raw)
  To: Florian Weimer
  Cc: Dmitry V. Levin, libc-alpha, Joseph Myers, Paul Eggert,
	Alistair Francis, Arnd Bergmann, Alistair Francis,
	Adhemerval Zanella, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

[-- Attachment #1: Type: text/plain, Size: 1198 bytes --]

Hi Florian,

> * Dmitry V. Levin:
> 
> > Unfortunately, this didn't work out as intended because Linux
> > kernel prior to commit 7b8474466ed97be458c825f34a85f2c2b84c3f95
> > (including released version v5.4) did not zero the upper 32-bits of
> > tv_nsec on 32-bit architectures, which means that we have to do it
> > in valid_timeval_to_timespec64 and valid_timespec_to_timespec64
> > instead.  
> 
> Can't we treat this as a critical kernel bug that needs fixing before
> the kernels become usable?
> 
> I'm concern that this will make initializers for struct timespec64
> invalid.  glibc can't intercept everything that goes into the kernel.
> 

There was a discussion regarding explicit clearing of data passed /
read from the kernel during development of this patch.

The agreement was that we rely on the kernel in this matter and no
explicit clearing is necessary in glibc.

> Thanks,
> Florian
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-12-04 10:19 ` Dmitry V. Levin
  2019-12-04 10:34   ` Florian Weimer
@ 2019-12-04 11:11   ` Arnd Bergmann
  2019-12-04 12:07   ` Joseph Myers
  2 siblings, 0 replies; 15+ messages in thread
From: Arnd Bergmann @ 2019-12-04 11:11 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: GNU C Library, Lukasz Majewski, Joseph Myers, Paul Eggert,
	Alistair Francis, Alistair Francis, Adhemerval Zanella,
	Florian Weimer, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

On Wed, Dec 4, 2019 at 11:19 AM Dmitry V. Levin <ldv@altlinux.org> wrote:
> On Mon, Sep 30, 2019 at 03:31:34PM +0200, Lukasz Majewski wrote:
>
> Unfortunately, this didn't work out as intended because Linux kernel prior
> to commit 7b8474466ed97be458c825f34a85f2c2b84c3f95 (including released
> version v5.4) did not zero the upper 32-bits of tv_nsec on 32-bit
> architectures, which means that we have to do it in
> valid_timeval_to_timespec64 and valid_timespec_to_timespec64 instead.

Are you sure that patch actually makes a difference? On compat mode
in 64-bit architectures, the mask was still applied, and on native
32-bit modes, we get into a signed integer overflow when assigning the
tv_nsec from a 64-bit member in __kernel_timespec to a 32-bit member
in timespec64, but as the kernel is built with -fno-strict-overflow that
should still produce the correct result (truncating to 32 bit).

The patch is still useful for clarity but I fear I misread it originally
and thought it made a difference when in practice it does not actually
change the behavior, so the patch description ended overstating
the impact.

       Arnd

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-12-04 10:19 ` Dmitry V. Levin
  2019-12-04 10:34   ` Florian Weimer
  2019-12-04 11:11   ` Arnd Bergmann
@ 2019-12-04 12:07   ` Joseph Myers
  2 siblings, 0 replies; 15+ messages in thread
From: Joseph Myers @ 2019-12-04 12:07 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: libc-alpha, Lukasz Majewski, Paul Eggert, Alistair Francis,
	Arnd Bergmann, Alistair Francis, Adhemerval Zanella,
	Florian Weimer, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

On Wed, 4 Dec 2019, Dmitry V. Levin wrote:

> Unfortunately, this didn't work out as intended because Linux kernel prior
> to commit 7b8474466ed97be458c825f34a85f2c2b84c3f95 (including released
> version v5.4) did not zero the upper 32-bits of tv_nsec on 32-bit
> architectures, which means that we have to do it in
> valid_timeval_to_timespec64 and valid_timespec_to_timespec64 instead.

"have to do it in valid_timeval_to_timespec64 and 
valid_timespec_to_timespec64" can't be the answer.

Remember that all the functions using 64-bit time are intended in future 
to be user-visible functions that will be called directly by user code 
with _TIME_BITS=64.  That is, it is those functions that have to handle 
the padding being uninitialized.  And so it is those functions, receiving 
64-bit-time structures on input, that have to copy the structures (many 
can legitimately be called with inputs in read-only memory, they can't 
write to the inputs unless the definition of the function semantics says 
they can) and zero the padding if supporting kernels that don't do so 
themselves - not any callers that convert from 32-bit.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-12-04 11:04     ` Lukasz Majewski
@ 2019-12-09  0:08       ` Dmitry V. Levin
  2019-12-09 16:03         ` Florian Weimer
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry V. Levin @ 2019-12-09  0:08 UTC (permalink / raw)
  To: Lukasz Majewski
  Cc: Florian Weimer, libc-alpha, Joseph Myers, Paul Eggert,
	Alistair Francis, Arnd Bergmann, Alistair Francis,
	Adhemerval Zanella, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

[-- Attachment #1: Type: text/plain, Size: 1542 bytes --]

On Wed, Dec 04, 2019 at 12:04:32PM +0100, Lukasz Majewski wrote:
> Hi Florian,
> 
> > * Dmitry V. Levin:
> > 
> > > Unfortunately, this didn't work out as intended because Linux
> > > kernel prior to commit 7b8474466ed97be458c825f34a85f2c2b84c3f95
> > > (including released version v5.4) did not zero the upper 32-bits of
> > > tv_nsec on 32-bit architectures, which means that we have to do it
> > > in valid_timeval_to_timespec64 and valid_timespec_to_timespec64
> > > instead.  
> > 
> > Can't we treat this as a critical kernel bug that needs fixing before
> > the kernels become usable?
> > 
> > I'm concern that this will make initializers for struct timespec64
> > invalid.  glibc can't intercept everything that goes into the kernel.
> > 
> 
> There was a discussion regarding explicit clearing of data passed /
> read from the kernel during development of this patch.
> 
> The agreement was that we rely on the kernel in this matter and no
> explicit clearing is necessary in glibc.

So the agreement was to push the garbage to the kernel assuming it will
handle the matter?

Has anybody considered what it will look like in a tracer's output?

clock_nanosleep_time64(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=13185818429535213454}, {tv_sec=0, tv_nsec=111245472}) = ? ERESTART_RESTARTBLOCK (Interrupted by signal)

Confusing, isn't it?

This happens because the type of syscall argument on the kernel side is a
pointer to struct __kernel_timespec where the type of tv_nsec is long long.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64
  2019-12-09  0:08       ` Dmitry V. Levin
@ 2019-12-09 16:03         ` Florian Weimer
  0 siblings, 0 replies; 15+ messages in thread
From: Florian Weimer @ 2019-12-09 16:03 UTC (permalink / raw)
  To: Dmitry V. Levin
  Cc: Lukasz Majewski, libc-alpha, Joseph Myers, Paul Eggert,
	Alistair Francis, Arnd Bergmann, Alistair Francis,
	Adhemerval Zanella, Carlos O'Donell, Stepan Golosunov,
	Florian Weimer, Zack Weinberg

* Dmitry V. Levin:

> So the agreement was to push the garbage to the kernel assuming it will
> handle the matter?

Yes.

> Has anybody considered what it will look like in a tracer's output?
>
> clock_nanosleep_time64(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=13185818429535213454}, {tv_sec=0, tv_nsec=111245472}) = ? ERESTART_RESTARTBLOCK (Interrupted by signal)
>
> Confusing, isn't it?
>
> This happens because the type of syscall argument on the kernel side is a
> pointer to struct __kernel_timespec where the type of tv_nsec is long long.

Looks like strace needs to mask the values in its output.  I really
don't see another way.

Thanks,
Florian

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

end of thread, other threads:[~2019-12-09 16:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-30 13:32 [PATCH v10] y2038: Provide conversion helpers for struct __timespec64 Lukasz Majewski
2019-09-30 15:30 ` Joseph Myers
2019-10-01 13:26 ` Joseph Myers
2019-10-01 14:05   ` Lukasz Majewski
2019-10-01 15:25     ` Joseph Myers
2019-10-01 21:54     ` Lukasz Majewski
2019-10-01 21:58       ` Joseph Myers
2019-10-01 22:15         ` Lukasz Majewski
2019-12-04 10:19 ` Dmitry V. Levin
2019-12-04 10:34   ` Florian Weimer
2019-12-04 11:04     ` Lukasz Majewski
2019-12-09  0:08       ` Dmitry V. Levin
2019-12-09 16:03         ` Florian Weimer
2019-12-04 11:11   ` Arnd Bergmann
2019-12-04 12:07   ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).