FAILED: patch "[PATCH] timekeeping: Register default clocksource before taking" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 8fa30821180a9a19e78e9f4df1c0ba710252801e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071623-scurvy-remission-1d7e@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8fa30821180a9a19e78e9f4df1c0ba710252801e Mon Sep 17 00:00:00 2001
From: Mikhail Gavrilov <[email protected]>
Date: Tue, 16 Jun 2026 12:09:14 +0500
Subject: [PATCH] timekeeping: Register default clocksource before taking
tk_core.lock
Commit f24df84cbe05 ("time/jiffies: Register jiffies clocksource before usage") moved the jiffies clocksource registration into clocksource_default_clock(), so that it is registered lazily on the first call. __clocksource_register() acquires clocksource_mutex, but the first caller is timekeeping_init(), which invokes clocksource_default_clock() while holding tk_core.lock, a raw spinlock.
Acquiring a sleeping mutex while holding a raw spinlock is invalid.
The default clocksource only has to be registered before tk_setup_internals() consumes its mult/shift/maxadj. Neither clocksource_default_clock(), the ->enable() callback, nor the registration itself need tk_core.lock, so fetch and enable the clock before acquiring the lock. This preserves the "register before usage" ordering while keeping clocksource_mutex out of the raw spinlock section.
clocksource_default_clock() has a second caller, clocksource_done_booting(), which invokes it with clocksource_mutex already held. That path avoids a recursive lock because timekeeping_init() has already run and set cs_jiffies_registered, so the registration is skipped there. This change does not alter that; it only fixes the invalid wait context in timekeeping_init().
kernel/time/timekeeping.c +4 -3
@@ -2061,13 +2061,14 @@ void __init timekeeping_init(void)*/ wall_to_mono =timespec64_sub (boot_offset, wall_time); + clock =clocksource_default_clock (); +if (clock->enable) + clock->enable (clock); +guard (raw_spinlock_irqsave)(&tk_core.lock);ntp_init (); - clock =clocksource_default_clock (); -if (clock->enable) - clock->enable (clock);tk_setup_internals (tks, clock);tk_set_xtime (tks, &wall_time);
Thomas Gleixner
maintainerPATCH 1/1 timekeeping: Register default clocksource before taking tk_core.lock
From: Mikhail Gavrilov <[email protected]>
commit 8fa30821180a9a19e78e9f4df1c0ba710252801e upstream.
Commit f24df84cbe05 ("time/jiffies: Register jiffies clocksource before usage") moved the jiffies clocksource registration into clocksource_default_clock(), so that it is registered lazily on the first call. __clocksource_register() acquires clocksource_mutex, but the first caller is timekeeping_init(), which invokes clocksource_default_clock() while holding tk_core.lock, a raw spinlock.
Acquiring a sleeping mutex while holding a raw spinlock is invalid.
The default clocksource only has to be registered before tk_setup_internals() consumes its mult/shift/maxadj. Neither clocksource_default_clock(), the ->enable() callback, nor the registration itself need tk_core.lock, so fetch and enable the clock before acquiring the lock. This preserves the "register before usage" ordering while keeping clocksource_mutex out of the raw spinlock section.
clocksource_default_clock() has a second caller, clocksource_done_booting(), which invokes it with clocksource_mutex already held. That path avoids a recursive lock because timekeeping_init() has already run and set cs_jiffies_registered, so the registration is skipped there. This change does not alter that; it only fixes the invalid wait context in timekeeping_init().
--- kernel/time/timekeeping.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/time/timekeeping.c +4 -3
@@ -1685,13 +1685,14 @@ void __init timekeeping_init(void)*/ wall_to_mono =timespec64_sub (boot_offset, wall_time); + clock =clocksource_default_clock (); +if (clock->enable) + clock->enable (clock); +raw_spin_lock_irqsave (&timekeeper_lock, flags);write_seqcount_begin (&tk_core.seq);ntp_init (); - clock =clocksource_default_clock (); -if (clock->enable) - clock->enable (clock);tk_setup_internals (tk, clock);tk_set_xtime (tk, &wall_time);
Sasha Levin
maintainerRe: [PATCH 6.12.y] timekeeping: Register default clocksource before taking tk_core.lock
Quoted 4 lines
Commit
f24df84cbe05("time/jiffies: Register jiffies clocksource before usage") moved the jiffies clocksource registration intoclocksource_default_clock(), so that it is registered lazily on the first call.
An identical backport is already queued up for 6.12, thanks!
Signature · 2 lines
Thanks, Sasha