From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 AC8293E3140 for ; Wed, 20 May 2026 13:52:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779285155; cv=none; b=YOkWspffI5IxBeaGnxYzuE4Hca4HNjyvy4EUIfrLGbIjzoU2YmY5iLkieoLkDeVT4VDI0CcNss7JhP/ZnEUo/LiTPZLKw7HynBy/yHEIl421wu+d11DrEYJTjHadTdgDkPpjz/WwnRx73dfbJ8h3JKzv0bOUYSaT7BWC8xtXTbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779285155; c=relaxed/simple; bh=8P3QXodJnUM+lW8e+syZNYOapKB9rtZDgllWY+gd5zU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PhgRllUxix8iFbhPbJ4PAfeH1Zq3B5OCVBeO3nvdwms+At7AGrRWfDZLjmE5ClehzR53QDsuv+AA2BL9Ur0HddQY0OV0w7PJz4HpLRjD27uqsMk2Tedg+eQNb4OwN7jjo8u7jegWUrAB9xjrAJDs0lkZFhd18hTPVTymseD4AJc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=desiato.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=iFvZG3Oe; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=desiato.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iFvZG3Oe" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=sZtfa5e11apFou1TJeCmQDi4iVZgL0Y74MyLZe6af2g=; b=iFvZG3OeTWvx2S0w+JLfeQ3tpQ kf8VwrvxgFd80foRDD1SvQ+aVypOoMdFI4tLpFwuKTsCMqJ3kEKdv8zPh9C+H/qWTc6LeJxOCsjCA ubTDnh8jjqqZHFFKuXMrvEA1llwO4MXrfI8PbgS27TMhl3XHflmWdtl+eFuqcQ1LlWfcVL0TEVptB Hu8K0M66k2I9AxrTj0dCSw5DjLdRDpgnbTAHCFXAowtYedsGwe9DBRHahzG/NjZPCaqkxZz5uXu7b qw3doRt08vGN8F0k0FmKakAz4UuzshIaNTJ5KGeeIKf1lDWgHByh5L6hbTWI3K6Z/EclH1CV1ZWfL BE/Q8ZfQ==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by desiato.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wPhLF-0000000Gz9x-3Xqv; Wed, 20 May 2026 13:52:10 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wPhLF-000000009tQ-2c2z; Wed, 20 May 2026 14:52:09 +0100 From: David Woodhouse To: Richard Cochran , Wen Gu , David Woodhouse , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Stultz , Thomas Gleixner , Stephen Boyd , Anna-Maria Behnsen , Frederic Weisbecker , Shuah Khan , Peter Zijlstra , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Arnd Bergmann , Miroslav Lichvar , Julien Ridoux , Ryan Luu , linux-kernel@vger.kernel.org Cc: David Woodhouse Subject: [RFC PATCH v3 04/10] timekeeping: Guard against divide-by-zero in timekeeping_adjust Date: Wed, 20 May 2026 14:33:43 +0100 Message-ID: <20260520135207.37826-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520135207.37826-1-dwmw2@infradead.org> References: <20260520135207.37826-1-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse When the TSC clocksource is recalibrated (e.g. on KVM guests with clocksource=tsc), cycle_interval can momentarily be zero during the transition. Guard the div64_u64 in timekeeping_adjust() to prevent a divide-by-zero oops. This can be triggered on KVM guests that force clocksource=tsc when the guest's measured TSC frequency doesn't match what KVM reported, causing a recalibration during boot. Signed-off-by: David Woodhouse Assisted-by: Kiro:claude-opus-4.6-1m --- kernel/time/timekeeping.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 95973e45d456..0d5faa5d13d7 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2336,6 +2336,8 @@ static void timekeeping_adjust(struct timekeeper *tk, s64 offset) if (likely(tk->ntp_tick == ntp_tl)) { mult = tk->tkr_mono.mult - tk->ntp_err_mult; } else { + if (unlikely(!tk->cycle_interval)) + return; tk->ntp_tick = ntp_tl; mult = div64_u64(tk->ntp_tick >> tk->ntp_error_shift, tk->cycle_interval); -- 2.54.0