vdso/vsyscall: Avoid slow division loop in auxiliary clock update
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Mon, 25 Aug 2025 13:26:35 +0000 (15:26 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 3 Sep 2025 09:55:11 +0000 (11:55 +0200)
commit762af5a2aa0ad18da1316666dae30d369268d44c
tree3e8d9d5856483062cb11eca04aa063cbb0a09491
parentb320789d6883cc00ac78ce83bccbfe7ed58afcf0
vdso/vsyscall: Avoid slow division loop in auxiliary clock update

The call to __iter_div_u64_rem() in vdso_time_update_aux() is a wrapper
around subtraction. It cannot be used to divide large numbers, as that
introduces long, computationally expensive delays.  A regular u64 division
is also not possible in the timekeeper update path as it can be too slow.

Instead of splitting the ktime_t offset into into second and subsecond
components during the timekeeper update fast-path, do it together with the
adjustment of tk->offs_aux in the slow-path. Equivalent to the handling of
offs_boot and monotonic_to_boot.

Reuse the storage of monotonic_to_boot for the new field, as it is not used
by auxiliary timekeepers.

Fixes: 380b84e168e5 ("vdso/vsyscall: Update auxiliary clock data in the datapage")
Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250825-vdso-auxclock-division-v1-1-a1d32a16a313@linutronix.de
Closes: https://lore.kernel.org/lkml/aKwsNNWsHJg8IKzj@localhost/
include/linux/timekeeper_internal.h
kernel/time/timekeeping.c
kernel/time/vsyscall.c