From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379727; b=oOHVLNXWk3krKOrzskIMlw2lRlc9CQJJ1g4jocD3jVczrY1kaRaLv1VHePRKPGu+vORk xfdtaI0kWIrBTu20vCDSATpLZIzexxMFPfiKOCE+LRM22pH2KzteVnEZGfaYVZYCz62za Yh0FEepZM4tSglZkLbXRa+NxQtIT7sRy5hthMnUECe72FD+wWSTO8bHzEphXUX1D6dKVy cE9ZKDl43N/bBJqntLfoheLMCgwjYLLRpWVf1XHhOgvAWsJRlES8aGYql8AmM/088ahYH WURYAkndGs+INstYMzt1p0AvUjviOIfBR2FwzCTyrZGcq/dQAqQAMqUWXfH3upn3twQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379727; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=snRRzVoLekjyTq/pQyrl7A3CbhTLb44lUklcr/RvoKc=; b=TaPgujPfTZDDGSIG086bLGWZKSj5hjiZ91i1QR60S8t/niHEvS0fMZRhnvvDbPm6zCXx 46NGpXReCDOUfHTzfJQ8snb69wZ8cc3kWOFxF7bswZVqXlZB83ljEkQAFJoHtjdDR623d +CdF9KqlckFp+RgpjmCZM6XT2WsVmdSfwyJ8J3cTF1vze6XUEf//v60GN9y776zw4gSwi Yy98isbjDzGt1MF0EYAwrQkEwHblQ2BiY1dLHVQApPWjtBZHI6Hh2TwtstyfOj84iLGJY cNipTyThqZ7muMkNtAL6TYl5WJix+qD11bSb4knd/V+XSReUb7Z1H8TCS2rwALKP59w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CqToVZZp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 366BD606A322; Fri, 4 Dec 2026 10:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=CqToVZZp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F28E1F000CE; Fri, 4 Dec 2026 10:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379727; bh=snRRzVoLekjyTq/pQyrl7A3CbhTLb44lUklcr/RvoKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CqToVZZpp1TOG0a86ff0kEvO5NXdfR8sKxNloxkk+grlRpkw+d05XlTzPPIzHVohA YBuXTqhYI0WSpcu1lb8r7huHhTY8bGKI7GCAdUzoi67GtCYxLDiH1aR1gd10QRikGM ChRoRX+FhAhSjxMcMmAodtG97EaAb6qvkgJ/Bn8Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, James Hilliard , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0061/1167] ptp: vclock: serialize extended samples with counter updates Date: Fri, 4 Dec 2026 18:51:28 +0900 Message-ID: <20261204100703.671641369@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Hilliard [ Upstream commit d3fcce5afe3bb62e8f7a2efb29e43da4fe4ae1f3 ] The extended and cross-timestamp callbacks sample the physical clock before taking the virtual clock mutex. A concurrent frequency adjustment can advance the timecounter and change its multiplier in between, so the older sample is converted using a different frequency than the one in effect when it was taken. Take the mutex before sampling and keep it held through the conversion. Retain timecounter_cyc2time() and its existing conversion window. A PHC sample need not advance the counter: for example, e1000e explicitly allows non-monotonic SYSTIM readings. Treating a slightly older sample as a forward delta would instead advance virtual time by nearly a full counter wrap. This race was found by code inspection of the virtual clock sampling paths. Fixes: f0067ebfc42b ("ptp: add gettimex64() to virtual clocks.") Fixes: 21fad63084c2 ("ptp: add getcrosststamp() to virtual clocks.") Signed-off-by: James Hilliard Link: https://patch.msgid.link/20261026-ptp-vclock-sampling-v6-4-e705612541f1@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/ptp/ptp_vclock.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/ptp/ptp_vclock.c b/drivers/ptp/ptp_vclock.c index d112934351dc9..16c6eca5d2c16 100644 --- a/drivers/ptp/ptp_vclock.c +++ b/drivers/ptp/ptp_vclock.c @@ -115,20 +115,18 @@ static int ptp_vclock_gettimex(struct ptp_clock_info *ptp, struct ptp_clock *pptp = vclock->pclock; struct timespec64 pts; int err; - u64 ns; - - err = pptp->info->getcyclesx64(pptp->info, &pts, sts); - if (err) - return err; if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); - mutex_unlock(&vclock->lock); + err = pptp->info->getcyclesx64(pptp->info, &pts, sts); + if (!err) { + u64 ns = timecounter_cyc2time(&vclock->tc, timespec64_to_ns(&pts)); - *ts = ns_to_timespec64(ns); + *ts = ns_to_timespec64(ns); + } + mutex_unlock(&vclock->lock); - return 0; + return err; } static int ptp_vclock_settime(struct ptp_clock_info *ptp, @@ -154,20 +152,18 @@ static int ptp_vclock_getcrosststamp(struct ptp_clock_info *ptp, struct ptp_vclock *vclock = info_to_vclock(ptp); struct ptp_clock *pptp = vclock->pclock; int err; - u64 ns; - - err = pptp->info->getcrosscycles(pptp->info, xtstamp); - if (err) - return err; if (mutex_lock_interruptible(&vclock->lock)) return -EINTR; - ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device)); - mutex_unlock(&vclock->lock); + err = pptp->info->getcrosscycles(pptp->info, xtstamp); + if (!err) { + u64 ns = timecounter_cyc2time(&vclock->tc, ktime_to_ns(xtstamp->device)); - xtstamp->device = ns_to_ktime(ns); + xtstamp->device = ns_to_ktime(ns); + } + mutex_unlock(&vclock->lock); - return 0; + return err; } static long ptp_vclock_refresh(struct ptp_clock_info *ptp) -- 2.53.0