summaryrefslogtreecommitdiff
path: root/kernel/time
AgeCommit message (Collapse)Author
3 daysMerge branch 'master' of ↵Mark Brown
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
3 daysMerge branch 'main' of ↵Mark Brown
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git
4 daysMerge branch 'timekeeping-next' of https://github.com/Rust-for-Linux/linux.gitMark Brown
5 dayshrtimer: Add hrtimer_forward_safe_from_callback()FUJITA Tomonori
A hrtimer can be started while its callback runs. hrtimer_forward() writes the expiry without the base lock, so the caller has to serialize it against a concurrent hrtimer_start(). Otherwise the write can change the sort key of a queued timer. Add a variant which does the check and the update with the base lock held. If the timer is already queued, the expiry is left alone and the expiry set by hrtimer_start() wins. The first user is the Rust hrtimer abstraction. Safe Rust code can start a timer while its callback runs, so forward() in the callback can only be a safe API if the core handles a concurrent start. Suggested-by: Thomas Gleixner <tglx@kernel.org> Link: https://lore.kernel.org/all/877bk3ixp5.ffs@fw13/ Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by: Thomas Gleixner <tglx@kernel.org> Link: https://msgid.link/20261101232829.593680-2-tomo@flapping.org Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
5 daysMerge branch into tip/master: 'timers/vdso'Ingo Molnar
# New commits in timers/vdso: 689868cc2af9 ("vdso/gettimeofday: Replace the clock_data array with regular members") 40b7421a2e85 ("vdso/gettimeofday: Assert that the clockid fits into the u32 bitmask") Signed-off-by: Ingo Molnar <mingo@kernel.org>
5 daysMerge branch into tip/master: 'timers/nohz'Ingo Molnar
# New commits in timers/nohz: 109fad8c8a71 ("timers/nohz: Mark got_idle_tick accesses as same-CPU races") 3f1eb85d954a ("rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU()") 438b55d86a1a ("tick/sched: Make kernel parameter skew_tick boolean") Signed-off-by: Ingo Molnar <mingo@kernel.org>
7 daysalarmtimer: Trace the requested expiry when starting an alarmAvi Weiss
alarm_start_timer() traces alarm->node.expires before updating it, so alarmtimer_start reports the previous deadline on rearm. Move the tracepoint after assigning the new expiry time. Fixes: 183d00b72713 ("alarmtimer: Provide alarm_start_timer()") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261101192401.858702-2-thnkslprpt@gmail.com
7 daysalarmtimer: Return early if try_module_get() failsThomas Weißschuh
Simplify the logic by returning early if try_module_get() fails. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261102-alarmtimer-locking-v1-3-3c79a698aeae@weissschuh.net
7 daysalarmtimer: Return early if platform_device_register_data() failsThomas Weißschuh
Simplify the logic by returning on error instead of having to handle the potential error in each following operation. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261102-alarmtimer-locking-v1-2-3c79a698aeae@weissschuh.net
7 daysalarmtimer: Drop the spinlock around the rtcdev variableThomas Weißschuh
The spinlock serializes calls to alarmtimer_rtc_add_device(), making sure the 'rtcdev' variable is written only once. It also protects the read of the 'rtcdev' variable in alarmtimer_get_rtcdev(). But alarmtimer_rtc_add_device() is already synchronized externally through the driver core's subsystem lock. So the additional spinlock can be dropped and replaced with WRITE_ONCE()/READ_ONCE() for consistent access. This removes lock/unlock operations from the alarmtimer's clock callbacks. [ tglx: Massage change log ] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261102-alarmtimer-locking-v1-1-3c79a698aeae@weissschuh.net
7 daysalarmtimer: Reset the expiry time in alarm_init()Shashank Mohan Jain
timerfd_gettime() on a CLOCK_REALTIME_ALARM or CLOCK_BOOTTIME_ALARM timerfd keeps reporting the remaining time of the previous setting after the timer has been disarmed: struct itimerspec arm = { .it_value.tv_sec = 100 }; struct itimerspec disarm = { }, cur; fd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0); timerfd_settime(fd, 0, &arm, NULL); timerfd_settime(fd, 0, &disarm, NULL); timerfd_gettime(fd, &cur); leaves 99.99... seconds in cur.it_value, and the value counts down until the old expiry time has passed. The same value is returned as old_value by the next timerfd_settime() and shown as it_value in /proc/<pid>/fdinfo/<fd>. A zero it_value is how timerfd_gettime() tells user space that a timer is disarmed, and the timerfds on the hrtimer based clocks report zero here. timerfd_setup() initializes the timer again on every timerfd_settime(). For the hrtimer based clocks hrtimer_setup() clears the expiry time, so timerfd_get_remaining() finds an expiry time in the past for a disarmed timer and returns 0. alarm_init() does not touch alarm->node.expires, timerqueue_init() only clears the rbtree node, and alarm_expires_remaining() computes the remaining time from the expiry time of the previous setting. Reset the expiry time in alarm_init(), like hrtimer_setup() does for a hrtimer. The other callers of alarm_init() start the alarm, which sets the expiry time, before anything reads it. Tested in qemu with a program doing the above for both alarm clocks (the VM has an RTC, which timerfd does not need for these clocks): it_value, old_value and fdinfo are zero after the disarm with this change. Fixes: 11ffa9d6065f ("timerfd: Add alarm timers") Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261011051943.60520-2-jain.sm@gmail.com
7 dayshrtimer: Refresh softirq deadline after clock changes in low-res modeAvi Weiss
In periodic low-resolution mode, hrtimer_run_queues() updates the clock base offsets at each tick but does not refresh softirq_expires_next. When CLOCK_REALTIME is moved forward, an expired soft hrtimer can therefore remain pending until the old monotonic deadline is reached. Reevaluate the next expiry when hrtimer_update_base() observes a new clock-was-set sequence, before checking whether to raise HRTIMER_SOFTIRQ. Fixes: 5da70160462e ("hrtimer: Implement support for softirq based hrtimers") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://patch.msgid.link/20261101172344.426489-1-thnkslprpt@gmail.com
7 daystimers/itimer: Preserve nonzero remaining time for active timersAvi Weiss
itimer_get_remtime() preserves positive remainders below one microsecond, but struct timeval only stores whole microseconds. So, for example, the conversion to tv_usec truncates a 500 ns remainder to zero, causing getitimer(ITIMER_REAL) to report an active timer as disarmed. Clamp active remainders below one microsecond to one microsecond so they remain nonzero after conversion. Fixes: 2ff678b8da64 ("[PATCH] hrtimer: switch itimers to hrtimer") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261102070148.1064849-2-thnkslprpt@gmail.com
7 daystimer_list: Stop hrtimer queue traversal after seq_file overflowAvi Weiss
When /proc/timer_list overflows its seq_file buffer, seq_file retries formatting with a larger buffer. print_active_timers() nevertheless continues scanning the remaining hrtimers, restarting its quadratic traversal even though the overflowing attempt will be discarded. Stop traversing at next_one when the seq_file has overflowed. Preserve the SysRq console path, which passes a NULL seq_file pointer. In a (virtual) two-CPU KVM guest with 2,048 timerfds pinned to one CPU, median reader CPU time for a complete /proc/timer_list read fell from 51.1 ms to 14.6 ms. Repeated tests showed no material slowdown for non-overflowing reads (13.7us before versus 13.8 after). Short reads, seek-to-start, and SysRq-Q tests also look fine. Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261103103438.2154751-2-thnkslprpt@gmail.com
7 dayshrtimer: Retrigger local timers after clock changesAvi Weiss
clock_was_set() selects CPUs whose hrtimer deadlines move earlier after a clock change. smp_call_function_many() excludes the calling CPU even when it is in the mask, leaving its clock event programmed for the old deadline. An overdue realtime timer can then expire only when a later event triggers timer handling. Use on_each_cpu_mask() to retrigger the local CPU when selected, without interrupting CPUs with unaffected deadlines. Fixes: 81d741d3460c ("hrtimer: Avoid unnecessary SMP function calls in clock_was_set()") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://patch.msgid.link/20261101141552.644764-2-thnkslprpt@gmail.com
7 daysclockevents: Match the CPU when unbinding devices via sysfsAvi Weiss
Clockevent devices belonging to different CPUs can share the same name. The sysfs unbind handler selects the first matching name from the global device list, which can cause a request for one CPU to unbind another CPU's device or incorrectly return -EBUSY. Check the device's CPU mask when selecting the clockevent to unbind so that the request targets a device eligible for the specified CPU. Fixes: 03e13cf5ee60 ("clockevents: Implement unbind functionality") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://patch.msgid.link/20261101141120.367124-1-thnkslprpt@gmail.com
7 daystimekeeping: Initialize TAI offset to 37 secondsMiroslav Lichvar
With Resolution 5 of the 28th CGPM (continuous UTC becoming effective on 20 May 2027) [1] and no leap second announced for the last possible date at the end of the year 2026 [2], no more leap seconds or other leaps in UTC are expected for at least a few hundred years. The TAI-UTC offset can be assumed now to be constant (37 seconds). Set the offset in the timekeeping initialization to the expected value to not require it to be set in user space via ADJ_TAI. It can still be changed, and leap seconds can still be set, but nothing should be expected to do that anymore. Existing applications are expected to either set the offset to the same value, or not touch it at all if they see it is not zero. [1] https://www.bipm.org/en/cgpm-2026/resolution-5 [2] https://datacenter.iers.org/data/16/bulletinc-072.txt Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Acked-by: David Woodhouse <dwmw@amazon.co.uk> Link: https://patch.msgid.link/20261105135316.2465369-1-mlichvar@redhat.com
7 daystimekeeping: Refresh auxiliary base before offset validationAvi Weiss
timekeeping_forward_now() can advance an auxiliary timekeeper across a second boundary without refreshing tkr_mono.base. The negative-time check in __timekeeping_inject_offset() then uses the stale base and rejects valid ADJ_SETOFFSET adjustments with -EINVAL. Refresh the derived timekeeper data before calculating the current auxiliary time, as aux_clock_set() already does. On 7.4-rc1, a valid negative adjustment fails at the first second rollover. The patched kernel accepts all 12 tested rollover adjustments and continues to reject invalid negative offsets. Fixes: 2c8aea59c206 ("timekeeping: Add auxiliary clock support to __timekeeping_inject_offset()") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261103090605.1292660-1-thnkslprpt@gmail.com
7 daystimekeeping: Reject cross timestamps for invalid AUX clocksAvi Weiss
get_device_system_crosststamp() accepts AUX clock IDs even when the corresponding timekeeper is disabled. A never-enabled AUX timekeeper has no initialized clocksource, and a previously enabled one can retain stale timekeeping data. Return -ENODEV before calling the device timestamp callback when the selected timekeeper is invalid. Fixes: 9aebde8af6fe ("timekeeping: Add support for AUX clock cross timestamping") Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261031122218.118921-1-thnkslprpt@gmail.com
7 daystimekeeping: Read getboottime64() offsets under the sequence counterHungyu Lin
getboottime64() computes the wall-clock boot timestamp from offs_real minus offs_boot without checking tk_core.seq. A concurrent timekeeping update can leave the reader with an inconsistent pair of offsets or, on 32-bit systems, a torn 64-bit offset, producing an incorrect boot timestamp. Read both offsets under tk_core.seq and retry if an update overlaps the sample. Convert the resulting local value to a timespec64 afterward. Fixes: 7c3f1a573237 ("Introduce boot based time") Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Acked-by: John Stultz <jstultz@google.com> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261030054227.35453-2-dennylin0707@gmail.com
7 daystimers/nohz: Mark got_idle_tick accesses as same-CPU racesKunwu Chan
got_idle_tick is a per-CPU flag set by the tick interrupt handler in tick_sched_do_timer() and read and cleared by the idle path in tick_nohz_idle_got_tick(). The flag is intentionally accessed without ordering or locking; a concurrent set can be overwritten by the clear. Use WRITE_ONCE_THIS_CPU() and READ_ONCE_THIS_CPU() to identify these as intentional races between execution contexts on the same CPU, rather than accesses that may race across CPUs. Suggested-by: Thomas Gleixner <tglx@kernel.org> Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://patch.msgid.link/20261007022859.60101-3-kunwu.chan@gmail.com
7 daysvdso/gettimeofday: Replace the clock_data array with regular membersThomas Weißschuh
The clock_data array is not used as such. The two entries have different semantics and nearly all users only work on one of them. The fact that they are kept in an array makes accesses to the clocksource data clunky and non-obvious to understand. Replace the array with two regular fields. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261102-vdso-cleanup-v1-1-f878c03881e8@weissschuh.net
7 daystick/sched: Make kernel parameter skew_tick booleanSergey Shtylyov
The kernel parameter skew_tick requires an integer value, despite being boolean in nature, and the parser functions ignores errors. Convert the static variable sched_skew_tick to 'bool' and thus use kstrtobool() to parse the parameter's value and return an eventual parser error to the caller. The input values 0 and 1 keep working as before. As the variable can only be set at boot time mark it __ro_after_init. Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool. Suggested-by: Thomas Gleixner <tglx@kernel.org> Signed-off-by: Sergey Shtylyov <s.shtylyov@auroraos.dev> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20261001202417.73273-1-s.shtylyov@auroraos.dev
11 daysnet: restrict message_cost and message_burst to non-negative valuesJiayuan Chen
net.core.message_cost and net.core.message_burst feed the interval and burst of net_ratelimit_state, but neither rejects negative values: message_burst uses plain proc_dointvec, and message_cost uses proc_dointvec_jiffies, which happily stores -1 second as -HZ jiffies. Since commit a940d145cc38 ("ratelimit: Warn if ->interval or ->burst are negative"), ___ratelimit() splats on such values, so the next net_ratelimit() caller warns, e.g. a martian source log: Negative interval (-250) or burst (10): Uninitialized ratelimit_state structure? WARNING: lib/ratelimit.c:43 at ___ratelimit+0x56e/0x960, CPU#1: ping/3218 RIP: 0010:___ratelimit+0x578/0x960 Call Trace: <IRQ> net_ratelimit+0x1c/0x30 ip_handle_martian_source+0x1bb/0x340 ip_route_input_slow+0x1057/0x3650 ip_route_input_noref+0x104/0x260 arp_process+0x109b/0x2510 arp_rcv+0x381/0x460 __netif_receive_skb_one_core+0x173/0x1c0 __netif_receive_skb+0x21/0x150 process_backlog+0x37e/0x1200 __napi_poll.constprop.0+0xa5/0x5e0 net_rx_action+0x4c0/0xf70 handle_softirqs+0x204/0x9b0 __do_softirq+0x10/0x18 do_softirq.part.0+0x49/0xd0 </IRQ> Negative values never meant anything here: 0 already expresses both "no limit" (interval) and "suppress everything" (burst). Reject them at write time. message_burst can simply use proc_dointvec_minmax with extra1 = 0. proc_dointvec_jiffies has no minmax variant, so add proc_dointvec_jiffies_minmax(), mirroring proc_dointvec_ms_jiffies_minmax(), and use it for message_cost with extra1 = 0. Note that like the ms variant, extra1/extra2 are compared against the converted jiffies value. Fixes: a940d145cc38 ("ratelimit: Warn if ->interval or ->burst are negative") Suggested-by: Joel Granados <joel.granados@kernel.org> Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20261101061331.286404-6-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2026-11-01Merge tag 'timers-urgent-2026-11-01' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull timer fixes from Ingo Molnar: - Fix on-stack hrtimer cleanup in play_idle_precise(), and add the hrtimer_on_stack cleanup class to facilitate the fix (Hui Su) - Fix clock_getres() system call's handling of NULL output pointer in the !CONFIG_POSIX_TIMERS case (Hungyu Lin) - Fix get_cpu_itimer() to return TICK_NSEC when the sampled CPU time is exactly equal to the nonzero expiry (Hungyu Lin) - Fix do_timens_ktime_to_host() time offset subtraction underflow check (Hungyu Lin) - Report zero remaining time for disarmed SIGEV_NONE posix timers, and add a self-test to detect this bug in the future (Hung-Jui Lin) - Fix NOHZ 'full kick' handling bug that can cause missed tick updates (Peng Wang) - Fix field access bug in the vdso/gettimeofday code that works only by accident (Thomas Weißschuh) - Fix & prevent immediate clocksource watchdog rerun after a delay (Karl Mehltretter) * tag 'timers-urgent-2026-11-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: clocksource: Prevent immediate watchdog rerun after a delay vdso/gettimeofday: Correct the read of tz_minuteswest and tz_dsttime tick/nohz: Reevaluate the tick for kicks flushed outside hardirq selftests: timers: Add a test for disarmed SIGEV_NONE timers posix-timers: Report zero remaining time for disarmed SIGEV_NONE timers time/namespace: Fix overflow when converting absolute deadlines timers/itimer: Keep a nonzero value at CPU timer expiry posix-timers: Accept NULL clock_getres() output in stubs sched/idle: Use hrtimer cleanup class in play_idle_precise() hrtimer: Add cleanup class for on-stack timers
2026-10-27clocksource: Prevent immediate watchdog rerun after a delayKarl Mehltretter
The watchdog rewrite made the clocksource check handle long intervals between two measurements, but missed that the timer expiry needs to be rebased after such a delay. When a watchdog invocation is delayed by more than one interval, adding WATCHDOG_INTERVAL to the previous expiry leaves the timer expiry in the past. That causes an immediate second invocation. The resulting short measurement interval can mark a clocksource unstable. Cure this by rearming the timer based on jiffies, which places the next expiry one full watchdog interval into the future. Fixes: 763aacf86f1b ("clocksource: Rewrite watchdog code completely") Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261026010200.96371-1-kmehltretter@gmail.com Closes: https://lore.kernel.org/r/20261010065509.72916-1-kmehltretter@gmail.com/
2026-10-25Merge tag 'timers-urgent-2026-10-25' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull timer fixes from Ingo Molnar: - Clear timer_base::pending_map on CPU hot-unplug, that can cause temporal timeout processing anomalous on the next hot-replug (Liang Hao) - Fix PID refcount leak in the posix-cpu-timers do_cpu_nanosleep() signal path (Cen Zhang) - Require (CAP_SYS_TIME) permission to set auxiliary clocks via aux_clock_set() (Daehyeon Ko) - Update offsets on sequence counter retry in ktime_get_update_offsets_now() (Thomas Weißschuh) * tag 'timers-urgent-2026-10-25' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: timekeeping: Update offsets on sequence counter retry in ktime_get_update_offsets_now() timekeeping: Require permission to set auxiliary clocks posix-cpu-timers: Fix pid refcount leak in do_cpu_nanosleep() signal path timers: Clear pending_map on CPU hotplug
2026-10-25tick/nohz: Reevaluate the tick for kicks flushed outside hardirqPeng Wang
The nohz full kick relies on interrupt exit to reevaluate the tick. However, a remote kick can also be flushed from task context without an interrupt exit guaranteed to follow. If a tick dependency is set or an earlier timer is queued after the idle-exit reevaluation, the required tick update can be delayed until another interrupt. Reevaluate the tick directly from the callback outside hardirq context. Keep the existing interrupt exit handling for hardirq callbacks. The offline flush remains harmless because tick_sched_timer_dying() has already cleared TS_FLAG_NOHZ. Fixes: 4b44a21dd640 ("irq_work, smp: Allow irq_work on call_single_queue") Fixes: a5183862e76f ("tick/nohz: Conditionally restart tick on idle exit") Suggested-by: Frederic Weisbecker <frederic@kernel.org> Co-developed-by: He Rongguang <herongguang@linux.alibaba.com> Signed-off-by: He Rongguang <herongguang@linux.alibaba.com> Signed-off-by: Peng Wang <peng_wang@linux.alibaba.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261023145101.8217-1-peng_wang@linux.alibaba.com
2026-10-25posix-timers: Report zero remaining time for disarmed SIGEV_NONE timersHung-Jui Lin
SIGEV_NONE timers are never queued. common_timer_get() emulates their expiry by computing the remaining time from the stored expiry value. Because an armed SIGEV_NONE oneshot timer is not queued, its it_status stays POSIX_TIMER_DISARMED. So common_timer_get() cannot use it_status to skip a disarmed SIGEV_NONE timer and evaluates the stored expiry value for all SIGEV_NONE timers. Disarming a timer with timer_settime() and a zero it_value cancels the timer and sets it_status to POSIX_TIMER_DISARMED, but leaves the expiry value unchanged. As a consequence, timer_gettime() on a disarmed SIGEV_NONE timer reports the remaining time of the previous arming until that time has passed, instead of zero as POSIX requires for a disarmed timer. Example with a CLOCK_MONOTONIC timer armed with it_value = 10ms and it_interval = 100ms, then disarmed with an all-zero itimerspec: armed: it_value = 0.009999000 it_interval = 0.100000000 disarmed: it_value = 0.008700792 it_interval = 0.000000000 SIGEV_SIGNAL timers and SIGEV_NONE CPU timers report zero in the same situation. All clocks which use common_timer_get() are affected, including the alarm timer clocks. Mark SIGEV_NONE timers as POSIX_TIMER_ARMED when they are armed, so that common_timer_get() returns early for every disarmed timer. Forward SIGEV_NONE interval timers in common_timer_get() regardless of it_status, as they are never queued and therefore never forwarded by the expiry code. After the change the disarmed timer above reports zero. Armed SIGEV_NONE oneshot and interval timers on CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME and CLOCK_BOOTTIME_ALARM still report their remaining time, and the posix_timers selftest passes. Fixes: becf8b5d00f4 ("[PATCH] hrtimer: convert posix timers completely") Signed-off-by: Hung-Jui Lin <alex.lin.programmer@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261023151411.28685-1-alex.lin.programmer@gmail.com
2026-10-25time/namespace: Fix overflow when converting absolute deadlinesHungyu Lin
do_timens_ktime_to_host() subtracts the namespace offset from an absolute deadline and clamps the result to [0, KTIME_MAX]. A negative offset can make a large deadline overflow to a negative value. Since ktime_t is signed and KTIME_MAX is its maximum value, the subsequent comparison against KTIME_MAX can never detect this overflow. For example, with a -1 second boottime offset, an absolute CLOCK_BOOTTIME timerfd deadline of KTIME_MAX can expire immediately. An absolute clock_nanosleep() using the same clock and deadline can also return immediately instead of waiting. The earlier tim < offset check already handles the lower bound. A negative subtraction result in the remaining branch therefore indicates overflow. Detect that result and clamp it to KTIME_MAX. Fixes: 89dd8eecfe961 ("time: Add do_timens_ktime_to_host() helper") Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261020233433.20997-1-dennylin0707@gmail.com
2026-10-25timers/itimer: Keep a nonzero value at CPU timer expiryHungyu Lin
get_cpu_itimer() returns a zero remaining time when the sampled CPU time is exactly equal to the nonzero expiry. This makes an armed ITIMER_VIRTUAL or ITIMER_PROF timer appear disarmed. The cputime cleanup replaced cputime_le(), which implements <=, with <. Restore the inclusive comparison so the equality case returns TICK_NSEC, like the overdue case and set_process_cpu_timer(). Fixes: 648616343cdb ("[S390] cputime: add sparse checking and cleanup") Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261020223957.87842-1-dennylin0707@gmail.com
2026-10-25posix-timers: Accept NULL clock_getres() output in stubsHungyu Lin
With CONFIG_POSIX_TIMERS disabled, clock_getres() returns -EFAULT for a supported clock when the result pointer is NULL. POSIX permits a NULL result pointer to suppress returning the clock resolution. Only copy the result when a destination is provided, in both the native and time32 stubs. This matches the full POSIX timer implementation and preserves clock ID validation. Fixes: baa73d9e478f ("posix-timers: Make them configurable") Fixes: d822cdcce43f ("posix-timers: Move compat versions of clock_gettime/settime/getres") Signed-off-by: Hungyu Lin <dennylin0707@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261020161121.85042-1-dennylin0707@gmail.com
2026-10-25hrtimer: Add cleanup class for on-stack timersHui Su
hrtimer_setup_on_stack() requires callers to destroy the timer before its backing stack storage goes out of scope, but the setup interface does not encode the required teardown pairing. Add an hrtimer_on_stack cleanup class that pairs on-stack setup with destroy_hrtimer_on_stack(). Document the existing setup API's lifetime requirement. The cleanup class provides debug-object teardown, not timer cancellation. Callers must ensure that no hrtimer operation can still access the timer before the scope ends; in particular, the timer must no longer be queued and any running callback must have completed. Signed-off-by: Hui Su <sh_def@163.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/5f48c32490d19f51035e4209174f9cfe44472c71.1792083743.git.sh_def@163.com
2026-10-23timekeeping: Update offsets on sequence counter retry in ↵Thomas Weißschuh (Schneider Electric)
ktime_get_update_offsets_now() The sequence counter of the cwsseq target is modified during the sequence counter loop. If the loop retries, cwsseq will now match but the offsets contain the values from the previous loop iteration. These are not guaranteed to be consistent in themselves or with the current loops "now. Save the target's original sequence counter value so that the update also happens on loop retries. Fixes: 868a3e915f7f ("hrtimer: Make offset update smarter") Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261023-timekeeping-clock_was_set_seq-v1-1-61c4c53d031c@linutronix.de
2026-10-23timekeeping: Require permission to set auxiliary clocksDaehyeon Ko
The generic clock_settime() entry point delegates permission checks to each clock-specific callback. aux_clock_set() does not perform one. Once an administrator enables an auxiliary clock, any local process can therefore change the global clock offset. A test process running as UID and GID 65534 with no effective, permitted, inheritable, or ambient capabilities set CLOCK_AUX0 successfully, and a separate process observed the new value. The same process was denied by clock_adjtime(). An AppArmor profile denying sys_time also blocked CLOCK_REALTIME changes but did not see the auxiliary clock operation. Call security_settime64() before mutating the auxiliary timekeeper. This matches CLOCK_REALTIME's permission model, enforces initial-user-namespace CAP_SYS_TIME, and gives LSMs the settime hook while preserving authorized clock changes. Fixes: 60ecc26ec5af ("timekeeping: Provide time setter for auxiliary clocks") Signed-off-by: Daehyeon Ko <4ncienth@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Tested-by: shaos <shawnq1@163.com> Acked-by: John Stultz <jstultz@google.com> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261019080324.4147815-1-4ncienth@gmail.com
2026-10-23posix-cpu-timers: Fix pid refcount leak in do_cpu_nanosleep() signal pathCen Zhang (Microsoft)
do_cpu_nanosleep() sleeps on a temporary k_itimer whose reference on the target's struct pid is taken by posix_cpu_timer_create() and dropped by posix_cpu_timer_del(). When a signal ends the sleep, the timer is disarmed with posix_cpu_timer_set(), but posix_cpu_timer_del() is only called for a result of 0 or TIMER_RETRY. If the target thread or process has exited in the meantime, timer_lock_sighand() finds no task, posix_cpu_timer_set() returns -ESRCH and the pid reference is leaked. An unprivileged user can trigger this: sleep on the CPU clock of a thread, let that thread exit, then signal the sleeper. Each round leaks one struct pid. Repeating it exhausts unreclaimable slab memory within minutes: Out of memory: Killed process 150 (poc) total-vm:789292kB, anon-rss:484kB Kernel panic - not syncing: System is deadlocked on memory Fix this by also calling posix_cpu_timer_del() on -ESRCH. With the target gone, the deletion is safe. It finds no task either and only drops the pid reference. Fixes: e26d70d271ee ("posix-timers: Cleanup reaped target handling") Reported-by: AutonomousCodeSecurity@microsoft.com Signed-off-by: Cen Zhang (Microsoft) <cenzhang@linux.microsoft.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261012235149.66531-1-cenzhang@linux.microsoft.com
2026-10-23Merge tag 'modules-7.4-rc1' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux Pull module updates from Petr Pavlu: - Ignore local labels and mapping symbols during module load These symbols were already ignored during kallsyms address-to-symbol lookups. Filter them out earlier during module loading to reduce lookup overhead and prevent them from appearing in /proc/kallsyms. - Fix potentially incorrect access of SetOnce<T> when setting Rust module parameters. - Fix a potential read of an uninitialized count when printing taint information for unloaded modules. - Allocate the kmod argument array using kmalloc_array() in preparation for conversion to type-aware allocators. - Clean up includes in linux/kmod.h Add explicit includes of linux/umh.h to files that use usermode helpers. Then clean up the #include list in linux/kmod.h, notably removing the compatibility linux/umh.h include. - Remove the error-injection.h include from linux/module.h Add explicit includes of linux/error-injection.h to files that use the ALLOW_ERROR_INJECTION() macro and currently rely on it being provided indirectly via linux/module.h. Then remove the unnecessary linux/error-injection.h include from linux/module.h. - Replace __MODULE_STRING() with __stringify() in various drivers in preparation for removing the former macro. * tag 'modules-7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux: drivers: Replace __MODULE_STRING() with __stringify() module: Fix uninitialized count read of unloaded taint tracking record rust: module_param: Fix potentially incorrect access of `SetOnce<T>` module: Remove the error-injection.h include from linux/module.h drm/xe: Include error-injection.h for ALLOW_ERROR_INJECTION() drm/i915: Include error-injection.h for ALLOW_ERROR_INJECTION() syscalls: Include error-injection.h for ALLOW_ERROR_INJECTION() net: Include error-injection.h for ALLOW_ERROR_INJECTION() block: Include error-injection.h for ALLOW_ERROR_INJECTION() module: Bring includes in linux/kmod.h up to date time/jiffies: Include linux/sysctl.h for proc_int_u2k_conv_uop(), ... umh, treewide: Explicitly include linux/umh.h where needed modules/kmod: Allocate argv with kmalloc_array() module/kallsyms: Ignore local labels and mapping symbols during module load module/kallsyms: Refactor current symbol filtering into is_core_symbol() module/kallsyms: Rename is_mapping_symbol() to is_ignored_kernel_symbol()
2026-10-21Merge tag 'timers-vdso-2026-10-20' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull VDSO updates from Thomas Gleixner: "Updates for the VDSO subsystem: - Ensure that the CLOCK_AUX base calculations are properly scaled against the base timekeeper. The update function failed to take the fractional nanosecond part into account, which results in a rounding error. - Cleanup and consolidate the vsyscall headers to get rid of pointless copies all over the architectures. - Replace a runtime conditional in the time getter function for namespaced clocks by simple pointer arithmetic which speeds up the read function" * tag 'timers-vdso-2026-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: vdso/vsyscall: Keep the CLOCK_AUX base scaled vdso/math64: Add and use __iter_div64_u64_rem() vdso/math64: Use OPTIMIZER_HIDE_VAR() in __iter_div_u64_rem() vdso/gettimeofday: Avoid runtime conditional in do_hres_timens() vdso: Remove __ASSEMBLER__ guards from vsyscall.h vdso: Add asm-generic/vdso/vsyscall.h vdso: Remove unnecessary vdso/vsyscall.h includes riscv/hwprobe: Include vdso/datapage.h arm64/vdso: Delete asm/vdso/vsyscall.h inclusions x86/vdso: Delete asm/vdso/vsyscall.h inclusions sparc/vdso: Delete asm/vdso/vsyscall.h inclusion s390/vdso: Delete asm/vdso/vsyscall.h inclusions sparc/vdso: Move __VDSO_PAGES to asm/vdso.h x86/vdso: Move vDSO page definitions to asm/vdso.h vdso: Delete asm-generic/vdso/vsyscall.h vdso/vsyscall: Define fallback time synchronization functions in vsyscall.c vdso/getrandom: Define fallback __arch_get_vdso_u_rng_data() in getrandom.c vdso/gettimeofday: Define fallback __arch_get_vdso_u_time_data() in gettimeofday.c vdso: Move the kernel-side time update helpers to a new header
2026-10-21Merge tag 'timers-nohz-2026-10-20' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull NOHZ updates from Thomas Gleixner: "Updates for the tick/NOHZ machinery: - Add the BLOCK_SOFTIRQ to the hotplug safe local softirq pending mask to prevent false positive error messages. A BLOCK_SOFTIRQ can be pending when a CPU goes offline as the subsequent cleanup will take care of the outstanding completions. - Remove a few redundant invocations of local_irq_save/restore() and timekeeping_max_deferment() to speed up the NOHZ idle transitions" * tag 'timers-nohz-2026-10-20' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: tick/nohz: Avoid unused timekeeping_max_deferment() calls tick/nohz: Remove redundant local_irq_save()/restore() tick/nohz: Add BLOCK_SOFTIRQ to the hotplug safe mask
2026-10-21Merge tag 'timers-core-2026-10-20' of ↵Linus Torvalds
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-20Merge tag 'sched-core-2026-10-18' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull scheduler updates from Ingo Molnar: "Kconfig updates: - Simplify PREEMPT_DYNAMIC (Mark Rutland) Fair scheduler updates: - Remove redundant RUN_TO_PARITY check (Elif Topuz) - Declare augmented callbacks per field, fix rb_add_augmented_cached() descent (Yiwei Lin, Peter Zijlstra) - Restart fair hrtick after same-task repicks (Shubhang Kaushik) - Improve the scheduling latency of short slice tasks (Vincent Guittot) Deadline/RT scheduler updates: - Check start_dl_timer expiry with ktime_before() (Liang Hao) - irq_work: CPU-hotplug improvements on PREEMPT_RT (Sebastian Andrzej Siewior) Energy-aware scheduling updates: - Implement the steal_governor, introduce preferred CPUs and steal-driven vCPU backoff (Shrikanth Hegde) Multi-processor load-balancing updates: - Enable preferred SMT siblings on NVIDIA Olympus (Andrea Righi) - Randomize equally shallow idle CPU picks (Christian Loehle) - Remove redundant core_sched_seq (Hui Su) Cache-aware scheduling updates: - Avoid publishing partial LLC utilization (Jemmy Wong) NUMA-balancing updates: - Reset NUMA fault locality after scan period update (Eric Kim) Proxy execution updates: - Ongoing work to implement sleeping owner handling for proxy execution (John Stultz, Vasily Gorbik) - Preparatory steps to make sched_ext compatible with proxy execution (Andrea Righi) Scheduler infrastructure updates & fixes: - Remove the RCU wait from PSI trigger destruction (Shakeel Butt) - Avoid modifying wait-entry on failed priority registration (Hui Su) - Use the new static key API for sched_feat (Hongyan Xia) - Convert paravirt_steal to new static key APIs (Hongyan Xia) - cputime: Don't account idle time twice after dyntick-idle (Stian Halseth) Scheduler debugging updates: - Set TIF_NEED_RESCHED before calling __trace_set_need_resched() (Sechang Lim) - Fix context analysis errors in non-preferred CPU push (Shrikanth Hegde) Misc cleanups and fixes by Christian Loehle, Shubhang Kaushik, Thomas Huth and Vladimir Zapolskiy" * tag 'sched-core-2026-10-18' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (64 commits) sched: Replace nr_iowait_cpu() with a bool accessor Revert "sched/fair: Remove dead code on enqueue_task_fair()" sched/cache: Avoid publishing partial LLC utilization sched/cputime: Don't account idle time twice after dyntick-idle sched/psi: Remove the RCU wait from trigger destruction sched/eevdf: Remove redundant RUN_TO_PARITY check sched/wait: Avoid modifying entry on failed priority registration rbtree_test: Use rb_add_augmented_cached() for the cached augmented test rbtree: Update augmented data on the way down in rb_add_augmented_cached() rbtree: Declare augmented callbacks per field with RB_AUG() rbtree_test: Use rb_add() and rb_add_cached() for the basic tests smpboot: Don't park the thread if work is pending irq_work: Flush lazy work CPU down on PREEMPT_RT irq_work: Update a comment regarding CPU hotplug invocation sched/topology: Add asymmetric SMT packing override sched/fair: Honor asymmetric SMT priority in idle selection sched: Set TIF_NEED_RESCHED before calling __trace_set_need_resched() sched/core: Fix context analysis errors in non-preferred CPU push virt/steal_governor: Enable the driver virt/steal_governor: Implement steal_governor policy loop ...
2026-10-20timers: Clear pending_map on CPU hotplugLiang Hao
CPU hotplug migration leaves pending_map bits set on the outgoing CPU while its wheel vectors are empty. After re-online, a later next_expiry recalc can treat those empty buckets as pending and temporarily pull next_expiry forward until collect drains the bits. Clear pending_map under the base lock after migration in timers_dead_cpu(). Fixes: 500462a9de65 ("timers: Switch to a non-cascading wheel") Signed-off-by: Liang Hao <haohlliang@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20260930063621.37740-1-haohlliang@gmail.com
2026-10-16sched/cputime: Don't account idle time twice after dyntick-idleStian Halseth
On idle exit the dyntick-idle accounting accounts the time up to now, then the tick is restarted on its old period. The first tick accounts a whole TICK_NSEC to whatever runs, although the part of that period before the idle exit has just been accounted as idle time, or with IRQ_TIME_ACCOUNTING as IRQ time. That is up to a full tick per idle exit, and /proc/stat reports more idle time than wall time. Record how much of the current tick period dyntick-idle has accounted, and leave it out of the tick that ends the period. Fixes: cf6444c3e1bb7 ("tick/sched: Unify idle cputime accounting") Signed-off-by: Stian Halseth <stian@itx.no> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lore.kernel.org/all/20261004142724.3896396-1-stian@itx.no/ Link: https://patch.msgid.link/20261007142950.547604-1-stian@itx.no
2026-10-15vdso/vsyscall: Keep the CLOCK_AUX base scaledZhan Xusheng
The vDSO basetime of a clock is stored in the scaled nanoseconds of tkr_mono, so that the reader can floor the base and the cycle delta together in vdso_calc_ns(). vdso_time_update_aux() instead shifts the base down to nanoseconds, adds the offset, and shifts it back up, which zeroes the fractional nanoseconds of xtime_nsec. The reader then floors the base and the delta separately: ktime_get_aux(): base + ((delta * mult + xtime_nsec) >> shift) vdso: base + (xtime_nsec >> shift) + ((delta * mult) >> shift) Since floor(a) + floor(b) <= floor(a + b), the vDSO reports 0 or 1 ns below the syscall for the same clock. It is not a monotonicity problem: across an update the step is floor(a + d) - floor(a) - floor(d), which is 0 or 1, never negative. Add the offset in scaled nanoseconds as the other high resolution clocks do, and normalise with __iter_div64_u64_rem() so that the stored base stays below one second and the userspace fast-path does not iterate more in __iter_div_u64_rem(). Only the sub-second field changes. (a + (b << shift)) >> shift is exactly (a >> shift) + b, so the seconds carried out of the normalisation are the same as before; what the old form dropped was the low shift bits of the remainder. monotonic_to_aux.tv_nsec is a normalised timespec64 fraction, so it stays below NSEC_PER_SEC even for a negative offset, and the sum stays below 2 * (NSEC_PER_SEC << shift). The largest shift clocks_calc_mult_shift() can pick is 32, which makes that 8.6e18 against a u64 limit of 1.8e19. Fixes: 380b84e168e5 ("vdso/vsyscall: Update auxiliary clock data in the datapage") Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20261002153104.1347978-4-zhanxusheng@xiaomi.com
2026-10-15vdso/math64: Add and use __iter_div64_u64_rem()Zhan Xusheng
The vDSO basetimes for CLOCK_MONOTONIC and CLOCK_BOOTTIME are stored in the scaled nanoseconds of tkr_mono, so normalising them requires a division by NSEC_PER_SEC << shift. That divisor does not fit the u32 parameter of __iter_div_u64_rem(), so update_vdso_time_data() open-codes the same iterative division twice. Repeated subtraction is the appropriate form at these two sites because the quotient never exceeds one. accumulate_nsecs_to_secs() keeps xtime_nsec below one scaled second, and the offset added to it is a normalised timespec64 fraction, so the dividend stays below twice the divisor. That bound holds on every architecture, which matters more here than the cost of a division on any particular one. Add __iter_div64_u64_rem(), the u64-divisor counterpart of __iter_div_u64_rem(), and use it at both sites. Return the quotient as a u32 for consistency with the u32-divisor variant; the bound above leaves no use for a wider type. Store the remainder directly into the basetime, as the coarse clocks already do. The CLOCK_BOOTTIME copy of the CLOCK_MONOTONIC values then takes both fields from the same place. Folding the two open-coded loops into one inlined helper removes 16 bytes of vsyscall.o text on x86-64 with gcc 13. No functional change. Suggested-by: David Laight <david.laight.linux@gmail.com> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20261002153104.1347978-3-zhanxusheng@xiaomi.com
2026-10-15vdso/vsyscall: Define fallback time synchronization functions in vsyscall.cThomas Weißschuh
__arch_update_vdso_clock() and __arch_sync_vdso_time_data() are only used in vsyscall.c. vsyscall.h has become a dumping ground for different kinds of fallbacks. Move the fallback function definitions into vsyscall.c. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20260909-vdso-asm-generic-vsyscall-h-v1-4-63ae856cc659@linutronix.de
2026-10-15vdso: Move the kernel-side time update helpers to a new headerThomas Weißschuh
The vdso/ header namespace is meant for symbols which are usable from vDSO userspace code. However vdso_update_begin() and vdso_update_end() are only usable from the kernel. Move them into a new header in the linux/ namespace. Also rename them to make clear that they are only for time-related data. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Link: https://patch.msgid.link/20260909-vdso-asm-generic-vsyscall-h-v1-1-63ae856cc659@linutronix.de
2026-09-29time/kunit: Add time64_to_tm() case beyond 32-bit day countKarl Mehltretter
The existing date range test covers +/-80,000 years around the epoch, far below the day count at which a 32-bit long wraps (2^31 days, roughly 5.88 million years). Add a case at exactly 2^31 days after the epoch. Without the preceding fix a 32-bit kernel returns tm_year=-5879541 and wrong month, day, day-of-year and weekday; with it the result matches 64-bit kernels. Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Assisted-by: LLM Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20260925165702.51677-3-kmehltretter@gmail.com
2026-09-29time: Prevent time64_to_tm() day truncation on 32-bitKarl Mehltretter
time64_to_tm() accepts a 64-bit seconds value, but stores the quotient in long. On a 32-bit kernel the day count therefore wraps when it reaches 2^31, even though the corresponding year remains representable in struct tm. This is reachable when formatting externally supplied timestamps. For example, NILFS recovery copies the little-endian 64-bit ss_create field from an on-disk segment summary into time64_t. Its sysfs attributes then print that value with %ptTs, whose formatter calls time64_to_tm(). A corrupted image can consequently produce an architecture-dependent printed date. Keep the day quotient in s64 while leaving the seconds-within-day remainder as long. Use div_s64_rem() for the weekday calculation so 32-bit builds do not require compiler runtime division helpers. Fixes: e6c2682a1da3 ("time: Add time64_to_tm()") Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Assisted-by: LLM Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20260925165702.51677-2-kmehltretter@gmail.com
2026-09-29timekeeping: Use READ_ONCE/WRITE_ONCE() for ktime_sec to prevent tearingThomas Weißschuh
The timekeeper update path uses a bulk memcpy() to synchronize the timekeeper structure, which is not guaranteed to be atomic. This allows for torn reads in ktime_get_seconds() which bypasses the sequence counter protection for performance. To prevent reading a torn ktime_sec value, enforce atomic-like access by using WRITE_ONCE() for the critical field before the bulk memcpy() in timekeeping_update_from_shadow(). Correspondingly, use READ_ONCE() in ktime_get_seconds() to ensure a fresh, consistent load from memory. The same was done for xtime_sec and ktime_get_real_seconds() in commit d7fc133bf91f ("timekeeping: Use READ_ONCE/WRITE_ONCE() for xtime_sec to prevent tearing"). Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Acked-by: John Stultz <jstultz@google.com> Link: https://patch.msgid.link/20260903-timekeeping-ktime_sec-v1-1-b33017536aa9@linutronix.de