Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201227183842.22030-1-alobakin@pm.me>
Date: Sun, 27 Dec 2020 18:39:03 +0000
From: Alexander Lobakin <alobakin@...me>
To: Rich Felker <dalias@...ifal.cx>, musl@...ts.openwall.com
Cc: Alexander Lobakin <alobakin@...me>
Subject: [PATCH 00/18] time64: always prefer time64 syscalls

Since Linux 4.18, there's an option CONFIG_COMPAT_32BIT_TIME that
allows to ultimately test libc and userland programs if they are
using the latest available syscall variants, time64 variants in
particular.
With this option turned off, old time32 syscalls don't get compiled
at all. The same applies to some deprecated syscalls such as
nanosleep.

Unfortunately, on 32-bit systems Musl fails on this hardly with
at least non-working sleeps, signal and sockets. That's because
Musl currently uses time64 variants only as "fallbacks" when some
of the arguments exceeds 32-bit width.
Moreover, Musl currently prefers deprecated adjtimex over
clock_adjtime, ipc over semtimedop, nanosleep over clock_nanosleep
etc.

As for me, libc should always use the latest available syscalls,
especially when it comes to y2038, and get back to fallbacks only
in case of -ENOSYS (on older systems). Newer systems might just
don't get deprecated stuff compiled in, as it is with mentioned
Kconfig option.
BTW, code size savings from excluding deprecated syscalls are quite
nice (bloat-o-meter):

add/remove: 0/39 grow/shrink: 8/4 up/down: 3464/-10480 (-7016)
Function                                     old     new   delta
sys_timerfd_settime                          180    1604   +1424
sys_rt_sigtimedwait                          236     884    +648
sys_timerfd_gettime                          116     724    +608
sys_pselect6                                 128     356    +228
sys_timer_settime                            256     472    +216
sys_timer_gettime                            116     268    +152
sys_sched_rr_get_interval                    108     260    +152
do_nanosleep.constprop                       424     460     +36
sys_futimesat_time32                           8       -      -8
sys_clock_adjtime32                            8       -      -8
sys_adjtimex_time32                            8       -      -8
sys_utimes_time32                             16       -     -16
nanosleep_copyout                            104      76     -28
poll_select_finish                           600     564     -36
sock_gettstamp                               524     480     -44
ksys_ipc                                     828     784     -44
sys_time32                                    80       -     -80
put_old_itimerspec32                          80       -     -80
sys_sched_rr_get_interval_time32             108       -    -108
sys_timerfd_gettime32                        116       -    -116
sys_timer_gettime32                          116       -    -116
__put_old_timespec32                         124       -    -124
sys_pselect6_time32                          128       -    -128
__do_sys_adjtimex_time32                     144       -    -144
sys_stime32                                  164       -    -164
sys_timerfd_settime32                        180       -    -180
compat_ksys_semtimedop                       188       -    -188
sys_utime32                                  196       -    -196
get_old_itimerspec32                         204       -    -204
sys_utimensat_time32                         216       -    -216
sys_clock_gettime32                          224       -    -224
sys_clock_getres_time32                      232       -    -232
sys_rt_sigtimedwait_time32                   236       -    -236
sys_clock_settime32                          236       -    -236
sys_ppoll_time32                             244       -    -244
do_timer_gettime                             252       -    -252
sys_timer_settime32                          256       -    -256
sys_recvmmsg_time32                          256       -    -256
sched_rr_get_interval                        256       -    -256
__do_sys_clock_adjtime32                     260       -    -260
sys_nanosleep_time32                         276       -    -276
do_compat_futimesat                          300       -    -300
put_old_timex32                              316       -    -316
do_pselect                                   316       -    -316
do_timer_settime.part                        320       -    -320
sys_clock_nanosleep_time32                   340       -    -340
sys_futex_time32                             480       -    -480
get_old_timex32                              480       -    -480
do_sigtimedwait                              696       -    -696
do_timerfd_gettime                           708       -    -708
do_timerfd_settime                          1560       -   -1560
Total: Before=4538992, After=4531976, chg -0.15%

This set ensures that all 18 syscalls are being run as follows:
1. time64 variant.
2. -ENOSYS? time32 variant.
3. -ENOSYS again? Any old stuff (adjtimex, ipc, nanosleep).

With this set, all syscalls and userspace programs work as expected
with CONFIG_COMPAT_32BIT_TIME turned off, just by using time64
variants.
Tested on MIPS32R2 (OABI), Linux 5.11-rc1 (pre) + Musl latest git
snapshot.

Alexander Lobakin (18):
  clock_gettime: prefer time64 variant if available
  clock_settime: prefer time64 variant if available
  clock_adjtime: try adjtimex at last
  clock_getres: use time64 variant by default
  clock_nanosleep: prefer time64 variant if available
  timer_gettime: prefer time64 variant if available
  timer_settime: prefer time64 variant if available
  timerfd_gettime: prefer time64 variant if available
  timerfd_settime: prefer time64 variant if available
  utimensat: prefer time64 variant if available
  pselect, select: prefer time64 variant of pselect6 if available
  poll, ppoll: prefer time64 variant of ppoll if available
  mq_timedsend: prefer time64 variant if available
  mq_timedreceive: prefer time64 variant if available
  semtimedop: prefer time64 variant of semtimedop if available
  [rt_]sigtimedwait: prefer time64 variant if available
  futex: prefer time64 variant if available
  sched_rr_get_interval: use time64 variant if available

 src/internal/pthread_impl.h                | 22 +++++++++++++++++----
 src/ipc/semtimedop.c                       | 20 +++++++++----------
 src/linux/clock_adjtime.c                  | 12 ++++++-----
 src/linux/ppoll.c                          |  8 +++-----
 src/linux/timerfd.c                        | 11 +++--------
 src/mq/mq_timedreceive.c                   |  6 ++----
 src/mq/mq_timedsend.c                      |  6 ++----
 src/sched/sched_rr_get_interval.c          | 21 ++++++++++----------
 src/select/poll.c                          | 23 +++++++++++++++++-----
 src/select/pselect.c                       |  6 ++----
 src/select/select.c                        | 22 +++++++++++----------
 src/signal/sigtimedwait.c                  |  6 ++----
 src/stat/utimensat.c                       |  6 ++----
 src/thread/__timedwait.c                   |  6 ++----
 src/thread/__wait.c                        |  4 ++--
 src/thread/pthread_barrier_wait.c          |  6 +++---
 src/thread/pthread_cond_timedwait.c        | 10 +++++-----
 src/thread/pthread_mutex_timedlock.c       |  8 +++-----
 src/thread/pthread_mutex_trylock.c         |  2 +-
 src/thread/pthread_mutex_unlock.c          |  2 +-
 src/thread/pthread_mutexattr_setprotocol.c |  2 +-
 src/time/clock_getres.c                    | 21 ++++++++++----------
 src/time/clock_gettime.c                   |  4 +---
 src/time/clock_nanosleep.c                 | 22 +++++++++++----------
 src/time/clock_settime.c                   |  6 ++----
 src/time/timer_gettime.c                   |  4 +---
 src/time/timer_settime.c                   |  7 ++-----
 27 files changed, 137 insertions(+), 136 deletions(-)

-- 
2.29.2


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.