idpf: fix a race in txq wakeup
Subsystems (3)
PATCH v3 1/1 idpf: fix a race in txq wakeup
Add a helper function to correctly handle the lockless synchronization when the sender needs to block. The paradigm is
if (no_resources()) {
stop_queue();
barrier();
if (!no_resources())
restart_queue();
}netif_subqueue_maybe_stop already handles the paradigm correctly, but the code split the check for resources in three parts, the first one (descriptors) followed the protocol, but the other two (completions and tx_buf) were only doing the first part and so race prone.
Luckily netif_subqueue_maybe_stop macro already allows you to use a function to evaluate the start/stop conditions so the fix only requires the right helper function to evaluate all the conditions at once.
The patch removes idpf_tx_maybe_stop_common since it's no longer needed and instead adjusts separately the conditions for singleq and splitq.
Note that idpf_tx_buf_hw_update doesn't need to check for resources since that will be covered in idpf_tx_splitq_frame.
To reproduce:
Reduce the threshold for pending completions to increase the chances of hitting this pause by changing your kernel:
drivers/net/ethernet/intel/idpf/idpf_txrx.h
-#define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq) ((txcq)->desc_count >> 1)
+#define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq) ((txcq)->desc_count >> 4)
Use pktgen to force the host to push small pkts very aggressively:
./pktgen_sample02_multiqueue.sh -i eth1 -s 100 -6 -d $IP -m $MAC \
-p 10000-10000 -t 16 -n 0 -v -x -c 64
---
v3:
- Fix typo in commit message
v2:
- Fix typos
- Fix RCT in singleq function
- No inline in c files
- Submit to iwl-net and add Fixes tag
.../ethernet/intel/idpf/idpf_singleq_txrx.c | 9 ++-- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 45 +++++++------------ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 8 ---- 3 files changed, 22 insertions(+), 40 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c +5 -4
@@ -362,17 +362,18 @@ netdev_tx_t idpf_tx_singleq_frame(struct sk_buff *skb, {struct idpf_tx_offload_params offload = { };struct idpf_tx_buf *first; +int csum, tso, needed;unsigned int count;__be16 protocol; -int csum, tso; count =idpf_tx_desc_count_required (tx_q, skb);if (unlikely (!count))return idpf_tx_drop_skb (tx_q, skb); -if (idpf_tx_maybe_stop_common (tx_q, - count +IDPF_TX_DESCS_PER_CACHE_LINE + -IDPF_TX_DESCS_FOR_CTX )) { + needed = count +IDPF_TX_DESCS_PER_CACHE_LINE +IDPF_TX_DESCS_FOR_CTX ; +if (!netif_subqueue_maybe_stop (tx_q->netdev, tx_q->idx, +IDPF_DESC_UNUSED (tx_q), + needed, needed)) {idpf_tx_buf_hw_update (tx_q, tx_q->next_to_use, false);u64_stats_update_begin (&tx_q->stats_sync);
drivers/net/ethernet/intel/idpf/idpf_txrx.c +17 -28
64 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +0 -8
@@ -1037,12 +1037,4 @@ bool idpf_rx_singleq_buf_hw_alloc_all(struct idpf_rx_queue *rxq, u16 cleaned_count);int idpf_tso (struct sk_buff *skb,struct idpf_tx_offload_params *off); -static inline bool idpf_tx_maybe_stop_common (struct idpf_tx_queue *tx_q, -u32 needed) -{ -return !netif_subqueue_maybe_stop (tx_q->netdev, tx_q->idx, -IDPF_DESC_UNUSED (tx_q), - needed, needed); -} -#endif /* !_IDPF_TXRX_H_ */
Signature · 1 line
2.49.0.967.g6a0df3ecc3-goog
Quoted 46 lines · Brian Vazquez
Add a helper function to correctly handle the lockless synchronization when the sender needs to block. The paradigm is
if (no_resources()) { stop_queue(); barrier(); if (!no_resources()) restart_queue(); }
netif_subqueue_maybe_stopalready handles the paradigm correctly, but the code split the check for resources in three parts, the first one (descriptors) followed the protocol, but the other two (completions andtx_buf) were only doing the first part and so race prone.Luckily
netif_subqueue_maybe_stopmacro already allows you to use a function to evaluate the start/stop conditions so the fix only requires the right helper function to evaluate all the conditions at once.The patch removes
idpf_tx_maybe_stop_commonsince it's no longer needed and instead adjusts separately the conditions for singleq and splitq.Note that
idpf_tx_buf_hw_updatedoesn't need to check for resources since that will be covered inidpf_tx_splitq_frame.To reproduce:
Reduce the threshold for pending completions to increase the chances of hitting this pause by changing your kernel:
drivers/net/ethernet/intel/idpf/idpf_txrx.h(quoted diff) +1
-1-#define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq) ((txcq)->desc_count >> 1) +#define IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq) ((txcq)->desc_count >> 4)Use pktgen to force the host to push small pkts very aggressively:
./pktgen_sample02_multiqueue.sh -i eth1 -s 100 -6 -d $IP -m $MAC \
-p 10000-10000 -t 16 -n 0 -v -x -c 64Fixes 6818c4d5b3c2 ("idpf: add splitq start_xmit")Reviewed-by Jacob Keller <[email protected]>Reviewed-by Madhu Chittim <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Brian Vazquez <[email protected]>Signed-off-by Luigi Rizzo <[email protected]>
Quoted 8 lines
---
v3:
- Fix typo in commit message
v2:
- Fix typos
- Fix RCT in singleq function
- No inline in c files
- Submit to iwl-net and add Fixes tag
Thanks Brian,
This version looks good to me.
Quoted 62 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Brian Vazquez
Sent: Thursday, May 1, 2025 10:06 AM
To: Brian Vazquez <[email protected]>; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]
Cc: David Decotigny <[email protected]>; Singhai, Anjali <[email protected]>; Samudrala, Sridhar <[email protected]>; [email protected]; [email protected]; Tantilov, Emil S <[email protected]>; Brian Vazquez <[email protected]>; Keller, Jacob E <[email protected]>; Chittim, Madhu <[email protected]>; Hay, Joshua A <[email protected]>; Luigi Rizzo <[email protected]>
Subject: [Intel-wired-lan] [iwl-net PATCH v3] idpf: fix a race in txq wakeupAdd a helper function to correctly handle the lockless synchronization when the sender needs to block. The paradigm is
if (no_resources()) { stop_queue(); barrier(); if (!no_resources()) restart_queue(); }
netif_subqueue_maybe_stopalready handles the paradigm correctly, but the code split the check for resources in three parts, the first one (descriptors) followed the protocol, but the other two (completions andtx_buf) were only doing the first part and so race prone.Luckily
netif_subqueue_maybe_stopmacro already allows you to use a function to evaluate the start/stop conditions so the fix only requires the right helper function to evaluate all the conditions at once.The patch removes
idpf_tx_maybe_stop_commonsince it's no longer needed and instead adjusts separately the conditions for singleq and splitq.Note that
idpf_tx_buf_hw_updatedoesn't need to check for resources since that will be covered inidpf_tx_splitq_frame.To reproduce:
Reduce the threshold for pending completions to increase the chances of hitting this pause by changing your kernel:
drivers/net/ethernet/intel/idpf/idpf_txrx.h-#define
IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq)((txcq)->desc_countQuoted 1 line
Quoted 1 line
1)
+#define
IDPF_TX_COMPLQ_OVERFLOW_THRESH(txcq)((txcq)->desc_countQuoted 1 line
Quoted 1 line
4)
Use pktgen to force the host to push small pkts very aggressively:
./pktgen_sample02_multiqueue.sh -i eth1 -s 100 -6 -d $IP -m $MAC \
-p 10000-10000 -t 16 -n 0 -v -x -c 64
Quoted 8 lines
Fixes 6818c4d5b3c2 ("idpf: add splitq start_xmit")Reviewed-by Jacob Keller <[email protected]>Reviewed-by Madhu Chittim <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Brian Vazquez <[email protected]>Signed-off-by Luigi Rizzo <[email protected]>---
2.49.0.967.g6a0df3ecc3-goog