idpf: Fix data race in idpf_net_dim
Subsystems (3)
PATCH 1/1 idpf: Fix data race in idpf_net_dim
In idpf_net_dim(), some statistics protected by u64_stats_sync, are read and accumulated in ignorance of possible u64_stats_fetch_retry() events. The correct way to copy statistics is already illustrated by idpf_add_queue_stats(). Fix this by reading them into temporary variables first.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +11 -5
@@ -3956,7 +3956,7 @@ static void idpf_update_dim_sample(struct idpf_q_vector *q_vector,static void idpf_net_dim (struct idpf_q_vector *q_vector) {struct dim_sample dim_sample = { }; -u64 packets, bytes; +u64 packets, bytes, pkts, bts;u32 i;if (!IDPF_ITR_IS_DYNAMIC (q_vector->tx_intr_mode))
@@ -3968,9 +3968,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector)do { start =u64_stats_fetch_begin (&txq->stats_sync); - packets +=u64_stats_read (&txq->q_stats.packets); - bytes +=u64_stats_read (&txq->q_stats.bytes); + pkts =u64_stats_read (&txq->q_stats.packets); + bts =u64_stats_read (&txq->q_stats.bytes); }while (u64_stats_fetch_retry (&txq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->tx_dim,
@@ -3987,9 +3990,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector)do { start =u64_stats_fetch_begin (&rxq->stats_sync); - packets +=u64_stats_read (&rxq->q_stats.packets); - bytes +=u64_stats_read (&rxq->q_stats.bytes); + pkts =u64_stats_read (&rxq->q_stats.packets); + bts =u64_stats_read (&rxq->q_stats.bytes); }while (u64_stats_fetch_retry (&rxq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->rx_dim,
Signature · 1 line
2.51.0
Quoted 11 lines · David Yang
In
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>---
It seems ovs_vport_get_upcall_stats() has a similar bug, are you interested to fix it as well ?
Thanks !
Quoted 14 lines · Eric Dumazet
Quoted 11 lines · David Yang
In
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>---
Quoted 6 lines
Reviewed-by Eric Dumazet <[email protected]>It seems
ovs_vport_get_upcall_stats()has a similar bug, are you interested to fix it as well ?Thanks !
Sure, I'll take a look at it.
Dear David,
Thank you for your patch.
Am 19.01.26 um 17:27 schrieb David Yang:
Quoted 5 lines
In
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.
It’d be great if you also documented a test case.
Quoted 12 lines
Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/idpf/idpf_txrx.c +0
-0
drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_update_dim_sample(struct idpf_q_vector *q_vector, · line 3959
Quoted 5 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +1
-1@@ -3956,7 +3956,7 @@ static void idpf_update_dim_sample(struct idpf_q_vector *q_vector,static void idpf_net_dim (struct idpf_q_vector *q_vector) {struct dim_sample dim_sample = { }; -u64 packets, bytes; +u64 packets, bytes, pkts, bts;
The new variable names are ambiguous. Would _tmp or so be better?
Quoted 23 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5
-3u32 i;if (!IDPF_ITR_IS_DYNAMIC (q_vector->tx_intr_mode))@@ -3968,9 +3968,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector)do { start =u64_stats_fetch_begin (&txq->stats_sync); - packets +=u64_stats_read (&txq->q_stats.packets); - bytes +=u64_stats_read (&txq->q_stats.bytes); + pkts =u64_stats_read (&txq->q_stats.packets); + bts =u64_stats_read (&txq->q_stats.bytes); }while (u64_stats_fetch_retry (&txq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->tx_dim,@@ -3987,9 +3990,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector) do { start = u64_stats_fetch_begin(&rxq->stats_sync); - packets += u64_stats_read(&rxq->q_stats.packets);
drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_net_dim(struct idpf_q_vector *q_vector) · line 4001
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5
-1- bytes +=u64_stats_read (&rxq->q_stats.bytes); + pkts =u64_stats_read (&rxq->q_stats.packets); + bts =u64_stats_read (&rxq->q_stats.bytes); }while (u64_stats_fetch_retry (&rxq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->rx_dim,
Kind regards,
Paul
[Cc: Remove bouncing [email protected] and [email protected]]
Am 20.01.26 um 17:50 schrieb Paul Menzel:
Quoted 67 lines
Dear David,
Thank you for your patch.
Am 19.01.26 um 17:27 schrieb David Yang:
Quoted 5 lines
In
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.It’d be great if you also documented a test case.
Quoted 12 lines
Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>---
drivers/net/ethernet/intel/idpf/idpf_txrx.c| 16 +++++++++++-----1 file changed, 11 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/idpf/idpf_txrx.c +0
-0drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_update_dim_sample(struct idpf_q_vector *q_vector, · line 3959
Quoted 5 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +1
-1@@ -3956,7 +3956,7 @@ static void idpf_update_dim_sample(struct idpf_q_vector *q_vector, static void idpf_net_dim(struct idpf_q_vector *q_vector) { struct dim_sample dim_sample = { }; - u64 packets, bytes; + u64 packets, bytes, pkts, bts;The new variable names are ambiguous. Would
_tmpor so be better?Quoted 18 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5
-2u32 i; if (!IDPF_ITR_IS_DYNAMIC(q_vector->tx_intr_mode))@@ -3968,9 +3968,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector) do { start = u64_stats_fetch_begin(&txq->stats_sync); - packets += u64_stats_read(&txq->q_stats.packets); - bytes += u64_stats_read(&txq->q_stats.bytes); + pkts = u64_stats_read(&txq->q_stats.packets); + bts = u64_stats_read(&txq->q_stats.bytes); } while (u64_stats_fetch_retry(&txq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->tx_dim,@@ -3987,9 +3990,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector) do { start = u64_stats_fetch_begin(&rxq->stats_sync);drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_net_dim(struct idpf_q_vector *q_vector) · line 3999
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5
-2- packets += u64_stats_read(&rxq->q_stats.packets); - bytes += u64_stats_read(&rxq->q_stats.bytes); + pkts = u64_stats_read(&rxq->q_stats.packets); + bts = u64_stats_read(&rxq->q_stats.bytes); } while (u64_stats_fetch_retry(&rxq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->rx_dim,Kind regards,
Paul
Quoted 6 lines · Paul Menzel
Dear David,
Thank you for your patch.
Quoted 9 lines
Am 19.01.26 um 17:27 schrieb David Yang:
Quoted 5 lines
In
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.It’d be great if you also documented a test case.
Sorry, I didn't get what "documente a test case" means. Triggering the bug would require precise timing between the writer and reader. If u64_stats_fetch_retry() returns true you already know the previous critical section was invalid, which is documented in u64_stats_sync.h.
Quoted 58 lines
Quoted 12 lines
Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/idpf/idpf_txrx.c +0
-0drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_update_dim_sample(struct idpf_q_vector *q_vector, · line 3959
Quoted 5 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +1
-1@@ -3956,7 +3956,7 @@ static void idpf_update_dim_sample(struct idpf_q_vector *q_vector,static void idpf_net_dim (struct idpf_q_vector *q_vector) {struct dim_sample dim_sample = { }; -u64 packets, bytes; +u64 packets, bytes, pkts, bts;The new variable names are ambiguous. Would
_tmpor so be better?Quoted 23 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5
-3u32 i;if (!IDPF_ITR_IS_DYNAMIC (q_vector->tx_intr_mode))@@ -3968,9 +3968,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector)do { start =u64_stats_fetch_begin (&txq->stats_sync); - packets +=u64_stats_read (&txq->q_stats.packets); - bytes +=u64_stats_read (&txq->q_stats.bytes); + pkts =u64_stats_read (&txq->q_stats.packets); + bts =u64_stats_read (&txq->q_stats.bytes); }while (u64_stats_fetch_retry (&txq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->tx_dim,@@ -3987,9 +3990,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector) do { start = u64_stats_fetch_begin(&rxq->stats_sync); - packets += u64_stats_read(&rxq->q_stats.packets);drivers/net/ethernet/intel/idpf/idpf_txrx.c static void idpf_net_dim(struct idpf_q_vector *q_vector) · line 4001
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_txrx.c +5
-1- bytes +=u64_stats_read (&rxq->q_stats.bytes); + pkts =u64_stats_read (&rxq->q_stats.packets); + bts =u64_stats_read (&rxq->q_stats.bytes); }while (u64_stats_fetch_retry (&rxq->stats_sync, start)); + + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector->rx_dim,Kind regards,
Paul
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 11 lines · On Tue, 20 Jan 2026 00:27:16 +0800 you wrote:
In
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events. The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>[...]
Here is the summary with links:
- [net] idpf: Fix data race in idpf_net_dim
https://git.kernel.org/netdev/net/c/5fbe395cd1fd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 84 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of David Yang
Sent: Monday, January 19, 2026 5:27 PM
To: [email protected]
Cc: David Yang <[email protected]>; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Pavan Kumar Linga <[email protected]>; Burra, Phani R <[email protected]>; Willem de Bruijn <[email protected]>; Alan Brady <[email protected]>; Samudrala, Sridhar <[email protected]>; Hay, Joshua A <[email protected]>; [email protected]; linux- [email protected]
Subject: [Intel-wired-lan] [PATCH net] idpf: Fix data race inidpf_net_dimIn
idpf_net_dim(), some statistics protected byu64_stats_sync, are read and accumulated in ignorance of possibleu64_stats_fetch_retry()events.
The correct way to copy statistics is already illustrated byidpf_add_queue_stats(). Fix this by reading them into temporary variables first.Fixes c2d548cad150 ("idpf: add TX splitq napi poll support")Fixes 3a8845af66ed ("idpf: add RX splitq napi poll support")Signed-off-by David Yang <[email protected]>--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/idpf/idpf_txrx.c +0
-0@@ -3956,7 +3956,7 @@ static void idpf_update_dim_sample(struct
idpf_q_vector*q_vector, static voididpf_net_dim(struct idpf_q_vector *q_vector){drivers/net/ethernet/intel/idpf/idpf_txrx.c +6
-3struct dim_sample dim_sample = { }; -u64 packets, bytes; +u64 packets, bytes, pkts, bts;u32 i;if (!IDPF_ITR_IS_DYNAMIC (q_vector->tx_intr_mode))@@ -3968,9 +3968,12 @@ static void idpf_net_dim(struct idpf_q_vector *q_vector)do { start =u64_stats_fetch_begin (&txq->stats_sync); - packets +=u64_stats_read (&txq->q_stats.packets); - bytes +=u64_stats_read (&txq->q_stats.bytes); + pkts =u64_stats_read (&txq->q_stats.packets); + bts =u64_stats_read (&txq->q_stats.bytes); }while (u64_stats_fetch_retry (&txq->stats_sync, start)); + + packets += pkts; + bytes += bts; }idpf_update_dim_sample(q_vector,
&dim_sample, &q_vector-Quoted 1 line
tx_dim, @@ -3987,9 +3990,12 @@ static void idpf_net_dim(struct
idpf_q_vector*q_vector)drivers/net/ethernet/intel/idpf/idpf_txrx.c +2
-2do { start = u64_stats_fetch_begin(&rxq->stats_sync); - packets += u64_stats_read(&rxq->q_stats.packets); - bytes += u64_stats_read(&rxq->q_stats.bytes); + pkts = u64_stats_read(&rxq->q_stats.packets); + bts = u64_stats_read(&rxq->q_stats.bytes); } while (u64_stats_fetch_retry(&rxq->stats_sync,start));
drivers/net/ethernet/intel/idpf/idpf_txrx.c +3
-0+ + packets += pkts; + bytes += bts; } idpf_update_dim_sample(q_vector, &dim_sample, &q_vector-Quoted 1 line
rx_dim,
Quoted 2 lines
--
2.51.0