Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2556149lqp; Mon, 25 Mar 2024 02:28:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9XjAnJgmV6oMW70L0UoLoqxGJ0nvRA/mQWF7PBOXNIgikDIlJGag1HC7KYUtqI95jPNnkEB3GjcbgHrJ0Pu56s69GJ+ao/9jcRjZcbQ== X-Google-Smtp-Source: AGHT+IGVMDVXIgsbl/lz3K8Z/PaPbO662Ys07cZ3Hoz2RmrRh47exabJIIm1obUyj2Zw/zJm/ym9 X-Received: by 2002:a05:6358:7213:b0:17f:58cb:2d3a with SMTP id h19-20020a056358721300b0017f58cb2d3amr7167238rwa.19.1711358907998; Mon, 25 Mar 2024 02:28:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711358907; cv=pass; d=google.com; s=arc-20160816; b=nJLq13Svjn28VzeU7amQIiYSi22qO6Ou+Zk7rLLrKpft+Dx3Y5zjBPdkP5HKNK/CQI i4pZz7kuMcBr8u2zxB4Ohxbqv5BaA7NX9dbiFiVjb1Jy9Sv573eyqlEjk0Z7tDCSZQOm hJ1kn403sspT6zuTfAdR1yOvDYgPWGr9L+MRcZU5XXODXCw8i4CI0tcxqGdy27WTvYZh k8SAzS5OzwL4XNW8u/+9oBPy0ol0QeVuEyfgvHo9yF6YqR50NfLF4+juU4qK4x3yD4m4 EVUa5ObxzvRDv0l2z44w+HLZvNp8m7WVIQwIJgeXT6yVORXCQI3yKOoBXNYq4A8UD5by mf1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=J4uNu0Pn5f7tFtHva+YfRPZg7ejgL8X4r+el9aTWRz8=; fh=Kup36vPmDrRX/ZED4HiLo7D05zuBWldEjkgKP/N/E5c=; b=VWmcq5IoTUcFYArL4uoAYacTuCPyyg/jBTYDLo3ZhxyfvzjqIx47sB725fPUhhLQnh 6nIHqVRIXnL1Nm1RbMJSi5kj/hZw9rFQlFfq3xXf9nIhHJ58IUw3lXkbfZlHQBSCuueG SqhpCWONqElJp3ao3Tr6BKJb9ibaooo9ujMGTQ9GCoHLwytK6gngT59kKondRibVzCof DvVGwR6VSu2KBFaUE/T83i3WXQqouJnr2fOeOFPNsVNNb3KuhkW6UELB8bVrfeMH3IOY a6encniBr4+Xw6LyH/eHMZ5+xYHy+12fJ3ADFVqAZVEINb0+F1C8DJKXXQDZknnHoq5t YDaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WCdF9eKm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115820-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bv67-20020a632e46000000b005e84c73a015si6940960pgb.766.2024.03.25.02.28.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:28:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115820-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WCdF9eKm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115820-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115820-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7FB1D29D369 for ; Mon, 25 Mar 2024 09:28:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C0693767EA; Mon, 25 Mar 2024 03:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WCdF9eKm" 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 7603C145B14; Sun, 24 Mar 2024 23:13:28 +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=1711322008; cv=none; b=AkJD8aVf4ICXwrox6Yqe18oKYD5Gk7voa7dEtBsw/qdFccsG3hZcOWoG8CpxmUnONj1VSonQ4miEX+fTTLPClyfHMb8i6PaR1ZfLijUJ1swBfy6NoN0D+CcMUoss12Blv7W/y0G53bWnpxLPZwbl0zprwIl+Kf6WZib62uhK1NE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322008; c=relaxed/simple; bh=B3uX13bPY3oPqfMAjAydIOnWt9hPXstTi1/cilrePB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nLk9nXlpA6mJeeZxC6K1PFKB1YYCkmTmpkBVtSVyrTQ4hlJMqlE1TsWu2gUVJ7cmIJ1cwdMJDfKanKTp4mcPznX0skz/94vK4UrxXDlC3BTc2b8yxrpz3vALmWWxIUAfXzMSEWfj20VpUH5r1kNfVp+7okRQ/qGCwNWJKty8tO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WCdF9eKm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A18C9C433F1; Sun, 24 Mar 2024 23:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322008; bh=B3uX13bPY3oPqfMAjAydIOnWt9hPXstTi1/cilrePB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WCdF9eKmdig+K9Q+pdaeXlci4OSalE4J5soQqX9kMNSb4Wtkjz4RtpkvvqPUKNZwy P34nfZ7Wk9v8jmNgpmX98P06tZBj3TOt5C6kWrbZ4RlN971GoPnSxIH5HdTYx72OVX LdW/aJcOz2gTkeB6iyBfkTbxjsBHh3Epsr0IB3h7Pz0BSzUAq1TwXvSFPWtJE5BzMV YxQFKtFTzNeIraqF3WtXEhCoUZlj3mGGmdKVF9k/EGMCYn8KJ0l5/kg37lHptYILiQ cxnhzyyRRjUQSUpgHNKv84bgo5FkWWNyOBXH2EWdBfFcx0zmqjtKD6cOcrEM4pKS8t Z+fnhEMG/lLLw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Hilber , Thomas Gleixner , John Stultz , Sasha Levin Subject: [PATCH 6.1 080/451] timekeeping: Fix cross-timestamp interpolation for non-x86 Date: Sun, 24 Mar 2024 19:05:56 -0400 Message-ID: <20240324231207.1351418-81-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-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: 8bit 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 == 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 == 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 supporting 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@opensynergy.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 1749a712f72d1..b158cbef4d8dc 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1261,10 +1261,8 @@ int get_device_system_crosststamp(int (*get_time_fn) tk_core.timekeeper.offs_real); base_raw = tk->tkr_raw.base; - nsec_real = timekeeping_cycles_to_ns(&tk->tkr_mono, - system_counterval.cycles); - nsec_raw = timekeeping_cycles_to_ns(&tk->tkr_raw, - system_counterval.cycles); + nsec_real = timekeeping_cycles_to_ns(&tk->tkr_mono, cycles); + nsec_raw = timekeeping_cycles_to_ns(&tk->tkr_raw, cycles); } while (read_seqcount_retry(&tk_core.seq, seq)); xtstamp->sys_realtime = ktime_add_ns(base_real, nsec_real); -- 2.43.0