Re: [patch 20/48] clocksource: Update clocksource::freq_khz on registration
From: Borislav Petkov
Date: Wed Mar 04 2026 - 14:12:09 EST
On Wed, Mar 04, 2026 at 07:49:29PM +0100, Thomas Gleixner wrote:
> 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 <bp@xxxxxxxxx>
> Reported-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
> ---
> kernel/time/clocksource.c | 7 +++++++
> 1 file changed, 7 insertions(+)
Tested-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette