lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250604005049.4147522-49-sashal@kernel.org>
Date: Tue,  3 Jun 2025 20:49:40 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
	stable@...r.kernel.org
Cc: Jason Xing <kernelxing@...cent.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Sasha Levin <sashal@...nel.org>,
	mcoquelin.stm32@...il.com,
	alexandre.torgue@...s.st.com,
	rmk+kernel@...linux.org.uk,
	0x1207@...il.com,
	andrew@...n.ch,
	pabeni@...hat.com,
	hayashi.kunihiko@...ionext.com,
	vladimir.oltean@....com,
	netdev@...r.kernel.org,
	linux-stm32@...md-mailman.stormreply.com,
	linux-arm-kernel@...ts.infradead.org
Subject: [PATCH AUTOSEL 6.15 049/118] net: stmmac: generate software timestamp just before the doorbell

From: Jason Xing <kernelxing@...cent.com>

[ Upstream commit 33d4cc81fcd930fdbcca7ac9e8959225cbec0a5e ]

Make sure the call of skb_tx_timestamp is as close as possbile to the
doorbell.

The patch also adjusts the order of setting SKBTX_IN_PROGRESS and
generate software timestamp so that without SOF_TIMESTAMPING_OPT_TX_SWHW
being set the software and hardware timestamps will not appear in the
error queue of socket nearly at the same time (Please see __skb_tstamp_tx()).

Signed-off-by: Jason Xing <kernelxing@...cent.com>
Link: https://patch.msgid.link/20250510134812.48199-4-kerneljasonxing@gmail.com
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---

Based on my comprehensive analysis, here is my assessment: **YES** This
commit should be backported to stable kernel trees. Here's my detailed
analysis: ## Code Analysis The commit moves `skb_tx_timestamp(skb)`
calls to execute immediately before the hardware "doorbell" operations:
1. **In `stmmac_tso_xmit()`**: Moves `skb_tx_timestamp(skb)` from line
4483 to line 4532, placing it right before
`stmmac_flush_tx_descriptors()` 2. **In `stmmac_xmit()`**: Moves
`skb_tx_timestamp(skb)` from line 4759 to line 4823, placing it between
`stmmac_enable_dma_transmission()` and `stmmac_flush_tx_descriptors()`
## Why This Should Be Backported ### 1. **Follows Established Kernel
Patterns** This change aligns with the kernel documentation requirement
that drivers "call skb_tx_timestamp() as close to passing sk_buff to
hardware as possible." It matches the exact pattern used in the NFP
driver fix (Similar Commit #5) that was marked "Backport Status: YES" -
both move `skb_tx_timestamp()` immediately before the hardware doorbell
operation. ### 2. **Addresses Real Timing Accuracy Issues** The original
code creates a problematic gap between when the software timestamp is
recorded and when the packet is actually handed to hardware. This
affects: - PTP (Precision Time Protocol) synchronization accuracy -
Network performance debugging tools that rely on precise timestamps -
Applications using SOF_TIMESTAMPING_OPT_TX_SWHW that need correlated
SW/HW timestamps ### 3. **Fixes Race Condition** The commit message
specifically mentions reordering to prevent software and hardware
timestamps from appearing in the socket error queue "nearly at the same
time" without SOF_TIMESTAMPING_OPT_TX_SWHW. This indicates it addresses
a race condition in the timestamp handling logic in `__skb_tstamp_tx()`.
### 4. **Minimal Risk of Regression** This is a simple reordering of
existing function calls with no new functionality or complex logic
changes. The transformation is identical to multiple other network
drivers that have been successfully backported. ### 5. **Important for
Embedded Systems** The STMMAC driver is widely used in embedded systems
and SoCs where precise timing is often critical for industrial
applications, making accurate timestamping particularly important. ###
6. **Matches Reference Patterns** The Similar Commit #5 (NFP driver)
with "Backport Status: YES" shows this exact same type of fix - moving
`skb_tx_timestamp()` to just before the hardware doorbell - was deemed
appropriate for backporting. The STMMAC commit follows this same proven
pattern. This commit fixes a legitimate timing/correctness issue with
minimal risk and follows established patterns that have been approved
for stable backporting in other drivers.

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 59d07d0d3369d..6c90a88f7b0ea 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -4488,8 +4488,6 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (priv->sarc_type)
 		stmmac_set_desc_sarc(priv, first, priv->sarc_type);
 
-	skb_tx_timestamp(skb);
-
 	if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
 		     priv->hwts_tx_en)) {
 		/* declare that device is doing timestamping */
@@ -4522,6 +4520,7 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
 	}
 
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
+	skb_tx_timestamp(skb);
 
 	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
@@ -4765,8 +4764,6 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (priv->sarc_type)
 		stmmac_set_desc_sarc(priv, first, priv->sarc_type);
 
-	skb_tx_timestamp(skb);
-
 	/* Ready to fill the first descriptor and set the OWN bit w/o any
 	 * problems because all the descriptors are actually ready to be
 	 * passed to the DMA engine.
@@ -4813,7 +4810,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
 	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
-
+	skb_tx_timestamp(skb);
 	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
 
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ