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=1795617812; b=lkAvB7zHayXRIt6tHyLHgrYBJV31HpjLnRcZ3trSoTa7lhaOHfavKmsBM+EFiqMr/7H1 3UnXq1A+VmQG0+g9FmoEchqC3Z0uPxff/H46Hiusj6VfJXG+Kk+VeEqb7oWndrWvV8hhX 5ISauD0oUuoIk9k8RkXPiPU6H5n8aauKmNzhvzqVqEkFuMDfv5s1yfUkbEv34HFMfgXVc kHNO4v1kIhtBy3MvjP1orlbxQlJj9TqgcKkWPvkGome84uz/ebJ4bpfLmXCri3cDihxlr iQ3CXh5LBTBjk7ySXx1XhbVTkPPb31HpBlYPMZI64RD/bxmDvHwjP9Q8Raqd/3Q7aiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795617812; 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=9U2sim0FoYr1cJJJTuD57FI2yru+aRYg6kKEW/ctOwo=; b=eXDun0IZAdW8TrGajX9bXZAiRCrHt2G2uyKLOjRfU8TRyGCgntPYhCSsj1Wuhr+E1/TI Ym1WkBuaq+LbAEUlJ6msS59ir6oKoNEpzL3bfUfrBSLKRk6/5E3t6HvtsaY8cYjSLxS9I xe9PjKcN5Scb5jjP/hhhjoRU9qY/6nnBEVOp4As6KR99P8pu/vg7tcVhKe8KSeH5nsZ85 OxqoPhnV7gFSAj0CRNkvrvrP7PTgYMLL1KiuCDgagQ0x+Ej1TFD8BjpIKajyxcZQ8uphG 53vBfDJizkxWr/sxaMQ5DSXQIaqb47Ag/ycohDj7cXaTGiDgDh5SUcNT9c15o5G7MKg== 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=D4tY7YUD; 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 481C0606A326; Wed, 25 Nov 2026 14:43:32 +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=D4tY7YUD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80BB11F000D1; Wed, 25 Nov 2026 14:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795617812; bh=9U2sim0FoYr1cJJJTuD57FI2yru+aRYg6kKEW/ctOwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D4tY7YUD/DkZ3IN6VROHoRbl/yHP9bbR5AL3RMBuhunbdeaatxLOIPuFZ59svhMh5 /Wud0819VWDrIvIBjL28Nn59aLaUe0c9yLg1HZRJJnzjtnKpLUpZmQA1RY6LcLWVYk UdqJJnqHbcyIJxAT6FMY6r1YI3KRXIuDpZhBedqc= 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 7.3 0083/1005] ptp: vclock: serialize extended samples with counter updates Date: Wed, 25 Nov 2026 15:23:41 +0100 Message-ID: <20261125143823.685971595@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143821.729802100@linuxfoundation.org> References: <20261125143821.729802100@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 b97f3a8772602..679ae40916f7e 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