unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Lukasz Majewski <lukma@denx.de>
Cc: Alistair Francis <alistair.francis@wdc.com>,
	GNU C Library <libc-alpha@sourceware.org>,
	 Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	Florian Weimer <fweimer@redhat.com>,
	 Palmer Dabbelt <palmer@sifive.com>,
	macro@wdc.com, Zong Li <zongbox@gmail.com>,
	 Zong Li <zong@andestech.com>,
	Alistair Francis <alistair23@gmail.com>,
	 Joseph Myers <joseph@codesourcery.com>
Subject: Re: [RFC v2 03/20] y2038: linux: Provide __clock_settime64 implementation
Date: Tue, 25 Jun 2019 18:39:11 +0200	[thread overview]
Message-ID: <CAK8P3a3AUgWzuZaZR5p2brmK16cMviidTf6A4aZ=mXVuNySbpA@mail.gmail.com> (raw)
In-Reply-To: <20190625175125.03375ead@jawa>

On Tue, Jun 25, 2019 at 5:51 PM Lukasz Majewski <lukma@denx.de> wrote:
> > On Tue, Jun 25, 2019 at 2:11 AM Alistair Francis
> > <alistair.francis@wdc.com> wrote:
> >
> > >  weak_alias (__clock_settime, clock_settime)
> > > +
> > > +#if __TIMESIZE != 64
> > > +int
> > > +__clock_settime (clockid_t clock_id, const struct timespec *tp)
> > > +{
> > > +  struct __timespec64 ts64;
> > > +
> > > +  valid_timespec_to_timespec64 (tp, &ts64);
> > > +  return __clock_settime64 (clock_id, &ts64);
> > > +}
> > > +#endif
> >
> > I missed this when Lukasz first posted this, but I would still
> > prefer this to be changed.
> >
> > Having clock_settime() (using the weak_alias) call into
> > __clock_settime64() means that a kernel that warns about
> > old user space calling into the old syscall never notices this.
>
> Could you be more specific here?
>
>
> I thought that we do not care about the legacy systems (i.e. those
> which don't switch to 64 bit time syscalls before Y2038).
>
> The assumption is to not break anything and use 64 bit time related
> syscalls after v5.1 kernel (i.e. clock_settime64 and friends on systems
> with __WORDSIZE=32).
>
> Syscalls, which handle only 32 bit time would be used as fallback.

I don't mind falling back on the 32-bit implementation from a time64 syscall
when running on the old kernel, that part is required to make new binaries
run on pre-5.1 kernel.

Your __clock_settime however does the reverse: you have an application
that calls clock_settime(), the alias redirects that to __clock_settime(),
and that converts it into the 64-bit structure and passes it into
__clock_settime64(), which then calls the time64 syscall before falling
back to calling the time32 syscall.

This is problematic in the scenario that you have an embedded system
you deploy today, and turn off the time32 syscalls in the kernel.
All applications are built against the time64 glibc interfaces, except
for one tool that someone forgot. This calls the old clock_settime()
with a 32-bit time, which gets converted into and passed into
clock_settime64 in the kernel where it successfully sets the time at
boot.

In 2038, it stops working because of the time_t overflow that was
not caught during validation. If we call the time32 interface here, it
breaks immediately on kernels that return -ENOSYS from
clock_gettime(), which makes the validation easier and more reliable.

> > Can you please leave the existing clock_settime()
>
> I think that some pseudo code would shed some more light on your idea.

What I mean is to have

#ifdef __NR_clock_settime
int
__clock_settime (clockid_t clock_id, const struct timespec *tp)
{
  return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
}
#endif

This will do the right thing on 64-bit architectures (which use time64
always), on new 32-bit architectures (not provide __clock_settime
at all, clock_settime() should be an alias for __clock_settime64())
and on old 32-bit architectures (work as expected on existing
kernels, fail with -ENOSYS when we want it to).

> and most notably from:
> https://sourceware.org/glibc/wiki/Y2038ProofnessDesign#clock_gettime.28.29
> recommended by glibc for the syscalls conversion for 64 bit.
>
> It also uses the __ASSUME_TIME64_SYSCALLS flag.

I thought it was covered in there, but maybe that changed.

      Arnd

  reply	other threads:[~2019-06-25 16:39 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-25  0:08 [RFC v2 00/20] RISC-V glibc port for the 32-bit Alistair Francis
2019-06-25  0:08 ` [RFC v2 01/20] y2038: Introduce internal for glibc struct __timespec64 Alistair Francis
2019-06-25  0:08 ` [RFC v2 02/20] y2038: Provide conversion helpers for " Alistair Francis
2019-06-25  0:08 ` [RFC v2 03/20] y2038: linux: Provide __clock_settime64 implementation Alistair Francis
2019-06-25 11:05   ` Arnd Bergmann
2019-06-25 15:51     ` Lukasz Majewski
2019-06-25 16:39       ` Arnd Bergmann [this message]
2019-06-26  9:07         ` Lukasz Majewski
2019-06-26 12:36           ` Arnd Bergmann
2019-06-26 15:03             ` Lukasz Majewski
2019-06-26 15:11               ` Florian Weimer
2019-06-26 22:49                 ` Lukasz Majewski
2019-06-27  7:14                   ` Florian Weimer
2019-06-27  7:36                     ` Lukasz Majewski
2019-06-26 18:58               ` Arnd Bergmann
2019-06-26 22:55                 ` Lukasz Majewski
2019-06-27  7:45                   ` Arnd Bergmann
2019-06-27 10:35                     ` Lukasz Majewski
2019-06-27 13:32                       ` Arnd Bergmann
2019-06-27 14:07                         ` Lukasz Majewski
2019-06-27 14:57                           ` Arnd Bergmann
2019-06-27 15:23                             ` Lukasz Majewski
2019-06-27 15:45                               ` Arnd Bergmann
2019-06-27 16:16                                 ` Lukasz Majewski
2019-06-27 21:25                                   ` Arnd Bergmann
2019-06-27 22:08                                     ` Lukasz Majewski
2019-07-04  0:04                                       ` Alistair Francis
2019-07-04  8:13                                         ` Lukasz Majewski
2019-07-08  9:32                                           ` Lukasz Majewski
2019-06-27 20:08                           ` Alistair Francis
2019-06-27 21:02                             ` Lukasz Majewski
2019-07-08 10:49         ` Joseph Myers
2019-06-25  0:08 ` [RFC v2 04/20] include/time.h: Fix conflicting timespec types on 32-bit Alistair Francis
2019-06-25 11:17   ` Arnd Bergmann
2019-06-25 22:20     ` Alistair Francis
2019-06-25  0:08 ` [RFC v2 05/20] sysdeps/nanosleep: Use clock_nanosleep_time64 if avaliable Alistair Francis
2019-06-25  8:24   ` Andreas Schwab
2019-06-25  8:59   ` Arnd Bergmann
2019-06-26 18:20     ` Alistair Francis
2019-06-25  0:09 ` [RFC v2 06/20] sysdeps/futex: Use futex_time64 " Alistair Francis
2019-06-25 11:14   ` Florian Weimer
2019-06-25 11:26     ` Andreas Schwab
2019-06-25 11:41       ` Arnd Bergmann
2019-06-25 12:06         ` Florian Weimer
2019-06-25 13:32           ` Arnd Bergmann
2019-06-25  0:09 ` [RFC v2 07/20] sysdeps/gettimeofday: Use clock_gettime64 " Alistair Francis
2019-06-27 13:14   ` Adhemerval Zanella
2019-07-03 23:49     ` Alistair Francis
2019-07-24 20:22   ` Joseph Myers
2019-07-24 23:00     ` Alistair Francis
2019-07-25 12:57       ` Arnd Bergmann
2019-07-25 17:03         ` Paul Eggert
2019-07-25 17:21           ` Zack Weinberg
2019-07-25 18:53             ` Arnd Bergmann
2019-07-26 13:01               ` Florian Weimer
2019-07-26 13:08                 ` Zack Weinberg
2019-07-25 21:23       ` Joseph Myers
2019-06-25  0:09 ` [RFC v2 08/20] sysdeps/wait: Use waitid " Alistair Francis
2019-06-25  8:16   ` Andreas Schwab
2019-06-25 10:55   ` Zack Weinberg
2019-06-25 11:06     ` Florian Weimer
2019-06-25 12:00       ` Arnd Bergmann
2019-06-25 12:10         ` Florian Weimer
2019-06-25 13:29           ` Arnd Bergmann
2019-06-25 13:39             ` Arnd Bergmann
2019-06-25 13:47               ` Florian Weimer
2019-06-25 14:04                 ` Arnd Bergmann
2019-06-25 14:08                   ` Florian Weimer
2019-06-25 14:21                     ` Arnd Bergmann
2019-06-25 14:29                       ` Florian Weimer
2019-06-26 14:37                         ` Arnd Bergmann
2019-06-26 15:48                           ` Florian Weimer
2019-06-26 16:28                             ` Andreas Schwab
2019-07-08 12:09                               ` Florian Weimer
2019-07-08 12:34                                 ` Andreas Schwab
2019-07-08 12:36                                   ` Florian Weimer
2019-07-09 22:57                                     ` Alistair Francis
2019-07-10  7:33                                       ` Andreas Schwab
2019-07-10 17:47                                         ` Alistair Francis
2019-07-25 15:49                                     ` Joseph Myers
2019-06-26 21:08                             ` Arnd Bergmann
2019-06-27  7:33                               ` Florian Weimer
2019-06-27  8:25                                 ` Andreas Schwab
2019-06-27 10:21                                 ` Arnd Bergmann
2019-06-27 11:12                                   ` Florian Weimer
2019-06-27 15:24                                     ` Arnd Bergmann
2019-07-03 23:50                                       ` Alistair Francis
2019-06-25 23:51         ` Alistair Francis
2019-06-25  0:09 ` [RFC v2 09/20] sysdeps/getrlimit: Use prlimit64 " Alistair Francis
2019-06-25 11:11   ` Florian Weimer
2019-06-25 20:45     ` Alistair Francis
2019-06-25 21:10       ` Florian Weimer
2019-06-25 23:38         ` Alistair Francis
2019-06-25  0:09 ` [RFC v2 10/20] Documentation for the RISC-V 32-bit port Alistair Francis
2019-06-25  0:09 ` [RFC v2 11/20] RISC-V: Use 64-bit time_t and off_t for RV32 and RV64 Alistair Francis
2019-06-25  0:09 ` [RFC v2 12/20] RISC-V: Support dynamic loader for the 32-bit Alistair Francis
2019-06-25  0:09 ` [RFC v2 13/20] RISC-V: Add path of library directories " Alistair Francis
2019-06-25  0:09 ` [RFC v2 14/20] RISC-V: The ABI implementation " Alistair Francis
2019-06-25  0:09 ` [RFC v2 15/20] RISC-V: Hard float support for the 32 bit Alistair Francis
2019-06-25  0:09 ` [RFC v2 16/20] RISC-V: Regenerate ULPs of RISC-V Alistair Francis
2019-06-25  0:09 ` [RFC v2 17/20] RISC-V: Add ABI lists Alistair Francis
2019-06-25  0:09 ` [RFC v2 18/20] RISC-V: Build Infastructure for the 32-bit Alistair Francis
2019-06-25  0:09 ` [RFC v2 19/20] RISC-V: Fix llrint and llround missing exceptions on RV32 Alistair Francis
2019-06-25  0:09 ` [RFC v2 20/20] Add RISC-V 32-bit target to build-many-glibcs.py Alistair Francis
2019-06-25 11:15 ` [RFC v2 00/20] RISC-V glibc port for the 32-bit Florian Weimer
2019-06-25 12:07   ` Arnd Bergmann
2019-07-04  8:47 ` Jim Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK8P3a3AUgWzuZaZR5p2brmK16cMviidTf6A4aZ=mXVuNySbpA@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=adhemerval.zanella@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=alistair23@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=lukma@denx.de \
    --cc=macro@wdc.com \
    --cc=palmer@sifive.com \
    --cc=zong@andestech.com \
    --cc=zongbox@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).