From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF9093BCD11; Thu, 16 Jul 2026 13:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784210309; cv=none; b=UXQZlNAW9bmcFHE0iCqk5jJ+cK33ka18VKsZBWSuJgY5Ixx4kcgCVZNGZ9LbJa4lmjtofaUF2VtqvJdTJGhNKLftIgaIPpcUIeCVn65RbiyW7hwEsrIwERixSvT/tj2VrIdBWQ8ThauG7l8Izfj6cwfXUNmVX8PxlFBMh0SK0S8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784210309; c=relaxed/simple; bh=65rj3CuSAbODFsSq8fiuGAA3s6aTvAKIBfUE93A6dPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E/4evAJROJaMI4wVi7x24MWqbiX/QEF130MTJTu9pVIaH2YihcfSC0RNgxdwIr3ikI2Tz8h7OjXw8em2/oOPvY7/Lt+GAnUAz1PeXJ2zGeTxZqnq0UL36Yq7461sTwcgtBWuvEuOZW8ud5yyzht3h9lxxlxJ5tWs4esqh5ueY2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rTxC6BYC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rTxC6BYC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 160131F000E9; Thu, 16 Jul 2026 13:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784210308; bh=Bsw9DqnKVmuE2ycwLzhknqfI4TdkzI0i/lQteK64C/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rTxC6BYC1w+YRSgUdZPf6gJKgYd+1njlh/QnkCp6CrbbMQdHZ2x3OwY5HvLwhWYM3 NY6Xq9XJbxsxecS1htINPara3FtXkCR6bh0vSjOeDzk+eoqWf2nfR7hERayfjOe2As 6XZNWnCPXnLQ3DuRvBIIBwcRQE2h/L5Fc7J4AnsY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mikhail Gavrilov , Thomas Gleixner , Breno Leitao , Oleg Nesterov Subject: [PATCH 7.1 517/518] timekeeping: Register default clocksource before taking tk_core.lock Date: Thu, 16 Jul 2026 15:33:05 +0200 Message-ID: <20260716133059.151072616@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133047.772246337@linuxfoundation.org> References: <20260716133047.772246337@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikhail Gavrilov 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(). Fixes: f24df84cbe05 ("time/jiffies: Register jiffies clocksource before usage") Signed-off-by: Mikhail Gavrilov Signed-off-by: Thomas Gleixner Reported-by: Breno Leitao Reported-by: Oleg Nesterov Reviewed-by: Breno Leitao Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260616070914.65818-1-mikhail.v.gavrilov@gmail.com Signed-off-by: Greg Kroah-Hartman --- kernel/time/timekeeping.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1980,13 +1980,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);