From nobody Fri Dec 19 20:14:45 2025 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 9C7882888EB; Sun, 24 Mar 2024 23:47:07 +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=1711324028; cv=none; b=MSkTa+O/KeCflATOV7yI3Qm9NJXnJFYZosxsrAcnZTrlTYhvW/9hvkKjfUgxDIer1AvLEUGtGu+NNdxcmrQbXRzZYAtDPIPBG4YA9gd8KnTCypG6Kf28sbFG8c1UtRykyNzvfjOZ2ch+veytt/zIr+0S11P8SrKX4XXbOSCE+rE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711324028; c=relaxed/simple; bh=5b7W79Vlv/Kmt5tTngf7pb5Y3IdZqI9FDgkRFlz9aSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnfg5KwyJ9ANIVheiZwdkUJpqr8ENQbqF9++mQRh/BDGxD5Cd2GYZnC0TmjMBliB74nVAjLQ0vfSWfpwh4+9x72RHmjwKtuRyMWM8jgNJdv7U1pyAHP2aqJwV3gpGGQ02XOPWSU1BPcPqq1GGGec/QwBbR0V3m6lAJp1Wo05BcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rTpmuhKD; 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="rTpmuhKD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDA44C43399; Sun, 24 Mar 2024 23:47:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711324027; bh=5b7W79Vlv/Kmt5tTngf7pb5Y3IdZqI9FDgkRFlz9aSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rTpmuhKDH2im9LMRfu/j2BOuO/vfUg8EBikqrkHiR0Dv2OHM81v5gu6YihCLCY8x8 aRP+ZIaPCbXfPC8JSPB9O2kcNGBNo6PUi3MotXN3JNXLXH/mCm2QtaLinQ+FuyDkZG FP4GnSsQ8ftppunGxLAJBDK+bhyOlUFZtETR3EHdNLyb6uE0ZmeKGN9XvWl3EWvds/ Xr/q1jSwEMsxsCK0tQel1bJS2k/7D/cf56zVAGMTS6L8QLFvXWrhoujMYSPKsXcOUR +hbEmelVGld/FzjApVapLCBFBd5qXocl+Wddpfu0sFCma4fs6eWmpSakvgCWfh/OQJ 79mA9Cc/jnpWA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Hilber , Thomas Gleixner , John Stultz , Sasha Levin Subject: [PATCH 5.4 028/183] timekeeping: Fix cross-timestamp interpolation for non-x86 Date: Sun, 24 Mar 2024 19:44:01 -0400 Message-ID: <20240324234638.1355609-29-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324234638.1355609-1-sashal@kernel.org> References: <20240324234638.1355609-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Peter Hilber [ Upstream commit 14274d0bd31b4debf28284604589f596ad2e99f2 ] So far, get_device_system_crosststamp() unconditionally passes system_counterval.cycles to timekeeping_cycles_to_ns(). But when interpolating system time (do_interp =3D=3D true), system_counterval.cycles= is before tkr_mono.cycle_last, contrary to the timekeeping_cycles_to_ns() expectations. On x86, CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE will mitigate on interpolating, setting delta to 0. With delta =3D=3D 0, xtstamp->sys_monoraw and xtstamp->sys_realtime are then set to the last update time, as implicitly expected by adjust_historical_crosststamp(). On other architectures, the resulting nonsense xtstamp->sys_monoraw and xtstamp->sys_realtime corrupt the xtstamp (ts) adjustment in adjust_historical_crosststamp(). Fix this by deriving xtstamp->sys_monoraw and xtstamp->sys_realtime from the last update time when interpolating, by using the local variable "cycles". The local variable already has the right value when interpolating, unlike system_counterval.cycles. Fixes: 2c756feb18d9 ("time: Add history to cross timestamp interface suppor= ting slower devices") Signed-off-by: Peter Hilber Signed-off-by: Thomas Gleixner Acked-by: John Stultz Link: https://lore.kernel.org/r/20231218073849.35294-4-peter.hilber@opensyn= ergy.com Signed-off-by: Sasha Levin --- kernel/time/timekeeping.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 2a43c26e913e9..c202dbd87860c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1174,10 +1174,8 @@ int get_device_system_crosststamp(int (*get_time_fn) tk_core.timekeeper.offs_real); base_raw =3D tk->tkr_raw.base; =20 - nsec_real =3D timekeeping_cycles_to_ns(&tk->tkr_mono, - system_counterval.cycles); - nsec_raw =3D timekeeping_cycles_to_ns(&tk->tkr_raw, - system_counterval.cycles); + nsec_real =3D timekeeping_cycles_to_ns(&tk->tkr_mono, cycles); + nsec_raw =3D timekeeping_cycles_to_ns(&tk->tkr_raw, cycles); } while (read_seqcount_retry(&tk_core.seq, seq)); =20 xtstamp->sys_realtime =3D ktime_add_ns(base_real, nsec_real); --=20 2.43.0