From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 DF0AE381B17 for ; Mon, 25 May 2026 13:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779717566; cv=none; b=Fa1vgJl7sOt3wpihnVL24fWa6w/kze3rr65r+8m/f42UndxhZmAaT11MD61X/Q0Z/Ek5NoQnl2OBw9oog41Pzp+r85L0bnYknU3yNlw5LdvcSiLy8E3BmXMR1Sj1cw8hyCaOqutMYlQLz+jkX0Uuaf+L1tddGu6ISkRED1G3Izw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779717566; c=relaxed/simple; bh=+dDUd7fR+X2Q+YKJ8JU4CXSQVbDKTKql/7qWzoG865g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BiwoeiYWmox+jW4Yb7dO8HtmzrS9CsYeAs9yGBKgzVcMrCVdRWAOJSxg3Iyqz/Q3sKkc9b3Xgp3jZbPDnq+VtCvkhjOgQpyz+g9vkUkf0GC7QTGmNjQhZhHbGO3+zzCvHaS7v1O0tctcDOGMvOXYa2uswcUQMSws++oCPXBaphw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=casper.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=wXn8VC4y; arc=none smtp.client-ip=90.155.50.34 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=casper.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wXn8VC4y" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description; bh=uaV8Vb/1AjjJbguyhoit8VsIvlwFRGKv5dqschWpeI4=; b=wXn8VC4yZEV8a1TwknGxZS092Q ArxIllHjOXdS6itaAqy74tPZSgN6DEUuvU1ioslDKActXjYa/niRZi1oByZOQwlAYTXh/B48nA2KW n5eUEs3zYuslrEfYN397s1pSgxIKUsClkGrAFIQ8xwkRNTqE838oy2bfU9OvWo2we7VfH2IIXK8sX UEsRTRyBH44VZeAZ5dofJZ7VUB8U79bhroodRnq0zG+Vj7Zr83XiibRxCCLhWely3MmBclMizariL ZU0IlcL7/q3OYo9c7PLPgh6YRq7jBL/8fLSPc8QTIumqDzZLhlBWvsWH8cXevXTah+Mqdi/c3xJvD /o7uuk+w==; Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wRVpk-0000000HBAP-00MF; Mon, 25 May 2026 13:59:08 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wRVpj-00000000Wrp-1vio; Mon, 25 May 2026 14:59:07 +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 Subject: [PATCH v4 4/7] timekeeping: Guard against divide-by-zero in timekeeping_adjust Date: Mon, 25 May 2026 14:54:36 +0100 Message-ID: <20260525135904.126282-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260525135904.126282-1-dwmw2@infradead.org> References: <20260525135904.126282-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 casper.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 Acked-by: John Stultz --- kernel/time/timekeeping.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 3473a91b11df..75397f5caace 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2404,6 +2404,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