From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 1EAD95383F9; Wed, 23 Sep 2026 14:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790174651; cv=none; b=s7DMr1p0IL42kJd2msZ0lfcA4gjAqFIOTS90QJ6QqS6TPh7N9poI/EU9vHPCVonQhlawJ36d0G785PfEwlT5dbkatpWVjBhlV0NJMJmOEPBl+0iJq0RiXyQ0vyH0AKVNhp5FL6k/U+sOM2A5pYkZ5c5eEl98S2R6zGW6olGuU0g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790174651; c=relaxed/simple; bh=BOlUvFB9oRfsxtU87Dj8j/51G2/83mrEdSGu8IJYTv0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XRDZiNjqw8Bd/njRqm1TCN13P+ozFLiOtgWvYrR9SrwC4pzlH1UWHKn66zbpasSthjgQ1NSCpqORHuQ5FhwPjMNdwGWIjYalM9zPIsoy8YhBu6045oM8inNawOdG+HCX8MFvlL3NeplW7GveoweWCjORoPjqCVrtpn+uvjYdJmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=k2fQM6UC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="k2fQM6UC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77E751F000FF; Wed, 23 Sep 2026 14:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790174650; bh=ZhSl2uGQvlVKMf/wg3Ze33SKeJqriwcEwgfmEoS3UHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=k2fQM6UCJ5aTd488j8d3io8GulGqYycsgu3e2xSbpGmhJAKmwc6RXDtUv+DnLfIOn nMieT2TaKcitkoYT6wfgUlzXrATsyAcuDpK4FyV0xvWc7qBfMEVzV/DvHiXBZjEObU Xr4VAVla3+GLsfYIMvzk2I/y5EFlijTDX0gczz68= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nicolai Buchwitz , =?UTF-8?q?Th=C3=A9o=20Lebrun?= , James Clark , Paolo Abeni , Sasha Levin Subject: [PATCH 6.18 183/398] net: macb: fix ordering around PTP timestamp read Date: Wed, 23 Sep 2026 16:04:17 +0200 Message-ID: <20260923140648.175947612@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260923140643.441954610@linuxfoundation.org> References: <20260923140643.441954610@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Clark [ Upstream commit 9ca4ba24259183ce15665be86b2956cd896c4687 ] PTP_SYS_OFFSET_EXTENDED returns system timestamps that do not correctly bracket the PHC register read on MACB/GEM. On a Raspberry Pi 5, the returned interval can be as short as 37 ns, while an ordered register read takes approximately 1 us. This biases the midpoint used by phc2sys, causing CLOCK_REALTIME to run approximately 0.5 us ahead when synchronized to the PHC. gem_tsu_get_time() reads the nanoseconds register using the driver's relaxed MMIO accessor. On weakly ordered systems, the subsequent system timestamp can be taken before the register read completes. The internal smp_rmb() in the pre-timestamp path also does not guarantee ordering against the subsequent MMIO read. Add rmb() before and after the bracketed nanoseconds read in both the normal and seconds rollover paths so the system timestamps bracket the PHC read. Adding the post-read barrier increases the minimum interval on the same Raspberry Pi 5 to approximately 1 us. Fixes: e51bb5c2784c ("net: macb: ptp: Switch to gettimex64() interface") Tested-by: Nicolai Buchwitz # Raspberry Pi CM5, min bracket 37 ns -> 981 ns Reviewed-by: Nicolai Buchwitz Reviewed-by: Théo Lebrun Assisted-by: LLM Signed-off-by: James Clark Link: https://patch.msgid.link/20260915045823.76100-1-jjc@jclark.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/ethernet/cadence/macb_ptp.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c index d961a5faf355d..97b72f633d3bc 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -48,7 +48,12 @@ static int gem_tsu_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts, spin_lock_irqsave(&bp->tsu_clk_lock, flags); ptp_read_system_prets(sts); + /* explicit barriers are needed because gem_readl() is relaxed */ + if (sts) + rmb(); first = gem_readl(bp, TN); + if (sts) + rmb(); ptp_read_system_postts(sts); secl = gem_readl(bp, TSL); sech = gem_readl(bp, TSH); @@ -60,7 +65,11 @@ static int gem_tsu_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts, * (assume all done within 1s) */ ptp_read_system_prets(sts); + if (sts) + rmb(); ts->tv_nsec = gem_readl(bp, TN); + if (sts) + rmb(); ptp_read_system_postts(sts); secl = gem_readl(bp, TSL); sech = gem_readl(bp, TSH); -- 2.53.0