linux/kernel/futex
Linus Torvalds aaf3d47e53 Updates for the core timekeeping and timers subsystem:
- Futher cleanups for the POSIX timer exit/exec related code to simplify
     the code flow and to make it more robust against future changes.
 
   - Prevent tearing of timekeeper::ktime_sec which can be accessed without the
     sequence count protection.
 
     The timekeeper is updated by memcpy() with an uneven sequence count to
     force readers into the retry path. On 64-bit machine the ktime_sec
     member can be accessed atomically without the sequence count
     protection. That is only correct when the update side memcpy()
     guarantees atomicity at the 64-bit granularity. That's not guaranteed
     due to debug options, compilers and instruction availability. If the
     memcpy() does not provide the atomicity then the unprotected readers
     can observe store tearing.
 
     To prevent this write the ktime_sec member before the memcpy() so that
     a non-atomic memcpy() will write the same data. A similar fix has been
     done for the xtime_sec member, but the ktime_sec equivalent was missed.
 
   - Prevent time64_to_tm() day truncation on 32-bit kernels
 
     The function receives a 64-bit seconds value but stores the quotient of
     the computation in a long, which truncates the result for large input
     values. Cure this by using div_s64_rem() which stores the quotient in
     s64 and only leaves the seconds-within-day reminder in a long, which is
     guaranteed to fit. This fix comes with a corresponding kunit test to
     prevent further mishaps.
 
   - Mark data-racy accesses to the hrtimer_sleeper::task member.
 
     The recent updates to KCSAN flagged these benign races. Annotate them
     with new helper functions, convert all existing usage sites and mark
     the task member private after that so that future users which fail to
     use the helpers can be detected automatically.
 
   - Address similar benign KCSAN flagged issues in the hrtimer, timer and
     timer migration code.
 
   - Fixes for a few selftest issues
 -----BEGIN PGP SIGNATURE-----
 
 iQJEBAABCgAuFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAmrX3OwQHHRnbHhAa2Vy
 bmVsLm9yZwAKCRCmGPVMDXSYoXDHD/94X2ix8PjV3YibEd9u86LHLtT9OolBtQgP
 Sum+LB5ARHy4aJGp8N1zGTA6S/zHm7fejrbdTS8xQAdK0BERP7BBIz9XmOq4+147
 S2TViWdL9gH6at3D5EYBuXmdtUqamesg9qB0u2x2pAtJsI5bgIsInpHBKOzmvkAM
 RSOHoQBrmRcSLe9M8PKMze4qS4Y8ckt2QKVXhZ89ncQEjeWC9piQh2yA8kLeFc9L
 6dvRxZTEOtedJM8+5CUHjrUaCac1mT7QbAVpHSjVVPMjvILeUx5bWK/ryTbvnr7e
 askWx+EpZR4+ZQOWDZ/sO99r+WcZNpGu+UGw9ChNrRxhqV6r9OvDFDslokvvn6RN
 ldjkRbbSkqXthEac/jtE3M6E1w6Vh/tLzi1Ow6TstJhwbF6E1WBgafkqjxmWun03
 PZO1M9UOL2uA7od7mJrMKtQskC3/AgviPwUr79owBxkgAUnmtragO+NQrns3ud8O
 921q+dj6WfdTt+FK1wXYjzLOlqV9zUADl1uAUNkf57gxp7ehD5KUJJRPVKrztKKA
 iJo393McWfaAHsb6WiBQfC7z4/akTmCe5S5L7add6u44jXTR+ZkVQwpziGRagXby
 3+7Y/p4HOvZmaEmsUc6I6+/TsIrjttMJY/4i020U/5rKCxZ3ufAy5o1Ept/EteCk
 GeEVNP8f6Q==
 =L9JF
 -----END PGP SIGNATURE-----

Merge tag 'timers-core-2026-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull timer core updates from Thomas Gleixner:
 "Updates for the core timekeeping and timers subsystem:

   - Futher cleanups for the POSIX timer exit/exec related code to
     simplify the code flow and to make it more robust against future
     changes.

   - Prevent tearing of timekeeper::ktime_sec which can be accessed
     without the sequence count protection.

     The timekeeper is updated by memcpy() with an uneven sequence count
     to force readers into the retry path. On 64-bit machine the
     ktime_sec member can be accessed atomically without the sequence
     count protection. That is only correct when the update side
     memcpy() guarantees atomicity at the 64-bit granularity. That's not
     guaranteed due to debug options, compilers and instruction
     availability. If the memcpy() does not provide the atomicity then
     the unprotected readers can observe store tearing.

     To prevent this write the ktime_sec member before the memcpy() so
     that a non-atomic memcpy() will write the same data. A similar fix
     has been done for the xtime_sec member, but the ktime_sec
     equivalent was missed.

   - Prevent time64_to_tm() day truncation on 32-bit kernels

     The function receives a 64-bit seconds value but stores the
     quotient of the computation in a long, which truncates the result
     for large input values. Cure this by using div_s64_rem() which
     stores the quotient in s64 and only leaves the seconds-within-day
     reminder in a long, which is guaranteed to fit. This fix comes with
     a corresponding kunit test to prevent further mishaps.

   - Mark data-racy accesses to the hrtimer_sleeper::task member.

     The recent updates to KCSAN flagged these benign races. Annotate
     them with new helper functions, convert all existing usage sites
     and mark the task member private after that so that future users
     which fail to use the helpers can be detected automatically.

   - Address similar benign KCSAN flagged issues in the hrtimer, timer
     and timer migration code.

   - Fixes for a few selftest issues"

* tag 'timers-core-2026-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (26 commits)
  selftests/timers: clocksource-switch: Fix unchecked open()/read()
  selftests: timers: Measure the CPU timers on the clock they count
  selftests: timers: Count what tick is worth in the drift estimate
  time/kunit: Add time64_to_tm() case beyond 32-bit day count
  time: Prevent time64_to_tm() day truncation on 32-bit
  timekeeping: Use READ_ONCE/WRITE_ONCE() for ktime_sec to prevent tearing
  timers/migration: Mark racy updates to tmigr_event::ignore field
  timers: Mark racy updates to hlist_node::pprev field
  hrtimer: Apply READ_ONCE() to lockless base->running loads
  hrtimer: Mark the hrtimer_sleeper structure's ->task field __private
  hrtimer: Update hrtimer_resolution only if value changes
  futex: Use accessor for hrtimer_sleeper ->task field in requeue
  rtmutex: Use accessor for hrtimer_sleeper ->task field
  net: pktgen: Use accessor for hrtimer_sleeper ->task field
  timers: Use accessor for hrtimer_sleeper ->task field in sleep_timeout.c
  futex: Use accessor for hrtimer_sleeper ->task field in waitwake.c
  io-uring/rw: Use accessor for hrtimer_sleeper ->task field
  wait: Use accessor for hrtimer_sleeper ->task field
  aio: Use accessor for hrtimer_sleeper ->task field
  hrtimer: Mark data-racy accesses to hrtimer_sleeper ->task field
  ...
2026-10-21 11:20:38 -10:00
..
core.c futex: Fix mm reuse handling for FUT_OFF_MMSHARED 2026-10-14 15:11:48 +02:00
futex.h futex: Optimize futex hash bucket access patterns 2026-06-11 13:41:24 +02:00
Makefile futex: Convert to compiler context analysis 2026-03-16 13:16:48 +01:00
pi.c futex: Provide rt_mutex_.*_schedule() equivalents for futex scheduling 2026-09-04 08:14:15 +02:00
requeue.c futex: Use accessor for hrtimer_sleeper ->task field in requeue 2026-09-29 21:02:52 +02:00
syscalls.c futex: Add support for unlocking robust futexes 2026-06-03 11:38:51 +02:00
waitwake.c futex: Use accessor for hrtimer_sleeper ->task field in waitwake.c 2026-09-29 21:02:51 +02:00