From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 572611DDA18 for ; Wed, 4 Mar 2026 18:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772650173; cv=none; b=PA4e6C3Hdf5zetdeUWNRKFpYE3CfzO8oLx/8rPgSwV0JcSg2xWrKCeO+Q9REAbDZKEDHRJ/HkfTuDMb44+sTosNBw95020ZhvQ1j/qzHsANJ603Bi4KFnjPDUykN5LSmaGYq/vtDQfPxeT9I4EzOfjlqshFppHPDHpsvi/my3Y4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772650173; c=relaxed/simple; bh=Xa5O9QMb2/oX2iJm3e3j20vjIVd/MudZ9VDfu9KGkcY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=dJcmhrtqvQFUGtwcej8k7Y7GGtzZ+rqmhoL3IgVb5j6MDAPT6BF8IRu9oqwqvFc0167H5j+hiGDKTGW3fm5xmIPgWIRE91+6g8OcvKAzdpD0VfHODz+6QPHY+wMB5XESWeLWvkqiwi2RrTloDWLlvw5tO4LypxNxt2O9IRc3Zvg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R74Zg+hw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R74Zg+hw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C373C4CEF7; Wed, 4 Mar 2026 18:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772650172; bh=Xa5O9QMb2/oX2iJm3e3j20vjIVd/MudZ9VDfu9KGkcY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=R74Zg+hw6us+nr1emtDaPJjSEKtLP94gkIn/P8oW58NoVEiKKeMTUNAJKNRfaNv6+ yp4OljQlBmHCokPb4cbzeT+e8kCzG6BzJ6UlLbgnPxu5WZKKyFc12rfUP065+rG7Ti 38WwLTJEw55g1yKVjCIofw4IFYSVaA2ALBPzrN+tkixPpckrqanNR2NNGK10yl9nV6 I5wz4ErXWL86FX87v4PsOulZkcx8P2e8qmJ+G3+iQH4+pGOnh5B9Nd0CeS7NpfmB// UIamN426S/VRRWOQ8QqECXX7MvPJpCbzY02M4f6Sh9CDJHUVct+qu02lmS08WCwhjR FIPWPpqHxRtKA== From: Thomas Gleixner To: Nathan Chancellor Cc: LKML , Anna-Maria Behnsen , John Stultz , Stephen Boyd , Daniel Lezcano , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , x86@kernel.org, Peter Zijlstra , Frederic Weisbecker , Eric Dumazet Subject: [patch 20/48] clocksource: Update clocksource::freq_khz on registration In-Reply-To: <87h5qvsajx.ffs@tglx> References: <20260224163022.795809588@kernel.org> <20260224163430.076565985@kernel.org> <20260303012905.GA978396@ax162> <87jyvtyo6o.ffs@tglx> <20260303173809.GA1114907@ax162> <87ecm0zmsf.ffs@tglx> <20260303213027.GA2168957@ax162> <87h5qvsajx.ffs@tglx> Date: Wed, 04 Mar 2026 19:49:29 +0100 Message-ID: <87cy1jsa4m.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Borislav reported a division by zero in the timekeeping code and random hangs with the new coupled clocksource/clockevent functionality. It turned out that the TSC clocksource is not always updating the freq_khz field of the clocksource on registration. The coupled mode conversion calculation requires the frequency and as it's not initialized the resulting factor is zero or a random value. As a consequence this causes a division by zero or random boot hangs. Instead of chasing down all clocksources which fail to update that member, fill it in at registration time where the caller has to supply the frequency anyway. Except for special clocksources like jiffies which never can have coupled mode. To make this more robust put a check into the registration function to validate that the caller supplied a frequency if the coupled mode feature bit is set. If not, emit a warning and clear the feature bit. Fixes: cd38bdb8e696 ("timekeeping: Provide infrastructure for coupled clockevents") Reported-by: Borislav Petkov Reported-by: Nathan Chancellor Signed-off-by: Thomas Gleixner --- kernel/time/clocksource.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c @@ -1169,6 +1169,9 @@ void __clocksource_update_freq_scale(str clocks_calc_mult_shift(&cs->mult, &cs->shift, freq, NSEC_PER_SEC / scale, sec * scale); + + /* Update cs::freq_khz */ + cs->freq_khz = div_u64((u64)freq * scale, 1000); } /* @@ -1241,6 +1244,10 @@ int __clocksource_register_scale(struct if (WARN_ON_ONCE((unsigned int)cs->id >= CSID_MAX)) cs->id = CSID_GENERIC; + + if (WARN_ON_ONCE(!freq && cs->flags & CLOCK_SOURCE_HAS_COUPLED_CLOCK_EVENT)) + cs->flags &= ~CLOCK_SOURCE_HAS_COUPLED_CLOCK_EVENT; + if (cs->vdso_clock_mode < 0 || cs->vdso_clock_mode >= VDSO_CLOCKMODE_MAX) { pr_warn("clocksource %s registered with invalid VDSO mode %d. Disabling VDSO support.\n",