veth: fix data race in veth_get_ethtool_stats
Subsystems (3)
PATCH 1/1 veth: fix data race in veth_get_ethtool_stats
In veth_get_ethtool_stats(), some statistics protected by u64_stats_sync, are read and accumulated in ignorance of possible u64_stats_fetch_retry() events. These statistics, peer_tq_xdp_xmit and peer_tq_xdp_xmit_err, are already accumulated by veth_xdp_xmit(). Fix this by reading them into a temporary buffer first.
--- drivers/net/veth.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/veth.c +6 -2
@@ -228,16 +228,20 @@ static void veth_get_ethtool_stats(struct net_device *dev,const struct veth_rq_stats *rq_stats = &rcv_priv->rq[i].stats;const void *base = (void *)&rq_stats->vs;unsigned int start, tx_idx = idx; +u64 buf[VETH_TQ_STATS_LEN ];size_t offset; - tx_idx += (i % dev->real_num_tx_queues) *VETH_TQ_STATS_LEN ;do { start =u64_stats_fetch_begin (&rq_stats->syncp);for (j =0 ; j <VETH_TQ_STATS_LEN ; j++) { offset = veth_tq_stats_desc[j].offset; - data[tx_idx + j] += *(u64 *)(base + offset); + buf[j] = *(u64 *)(base + offset); } }while (u64_stats_fetch_retry (&rq_stats->syncp, start)); + + tx_idx += (i % dev->real_num_tx_queues) *VETH_TQ_STATS_LEN ; +for (j =0 ; j <VETH_TQ_STATS_LEN ; j++) + data[tx_idx + j] += buf[j]; } pp_idx = idx + dev->real_num_tx_queues *VETH_TQ_STATS_LEN ;
Signature · 1 line
2.51.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 14 Jan 2026 20:24:45 +0800 you wrote:
In
veth_get_ethtool_stats(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. These statistics,peer_tq_xdp_xmitandpeer_tq_xdp_xmit_err, are already accumulated byveth_xdp_xmit(). Fix this by reading them into a temporary buffer first.Signed-off-by David Yang <[email protected]>[...]
Here is the summary with links:
- [net-next] veth: fix data race in veth_get_ethtool_stats
https://git.kernel.org/netdev/net/c/b47adaab8b3d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html