Skip to content

Commit 82172b7

Browse files
Mike Marciniszynjgunthorpe
authored andcommitted
IB/hfi1: Correct -EBUSY handling in tx code
The current code mishandles -EBUSY in two ways: - The flow change doesn't test the return from the flush and runs on to process the current packet racing with the wakeup processing - The -EBUSY handling for a single packet inserts the tx into the txlist after the submit call, racing with the same wakeup processing Fix the first by dropping the skb and returning NETDEV_TX_OK. Fix the second by insuring the the list entry within the txreq is inited when allocated. This enables the sleep routine to detect that the txreq has used the non-list api and queue the packet to the txlist. Both flaws can lead to having the flushing thread executing in causing two threads to manipulate the txlist. Fixes: d99dc60 ("IB/hfi1: Add functions to transmit datagram ipoib packets") Link: https://lore.kernel.org/r/20200623204321.108092.83898.stgit@awfm-01.aw.intel.com Reviewed-by: Kaike Wan <kaike.wan@intel.com> Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 822fbd3 commit 82172b7

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

‎drivers/infiniband/hw/hfi1/ipoib_tx.c‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static struct ipoib_txreq *hfi1_ipoib_send_dma_common(struct net_device *dev,
369369
tx->priv = priv;
370370
tx->txq = txp->txq;
371371
tx->skb = skb;
372+
INIT_LIST_HEAD(&tx->txreq.list);
372373

373374
hfi1_ipoib_build_ib_tx_headers(tx, txp);
374375

@@ -469,6 +470,7 @@ static int hfi1_ipoib_send_dma_single(struct net_device *dev,
469470

470471
ret = hfi1_ipoib_submit_tx(txq, tx);
471472
if (likely(!ret)) {
473+
tx_ok:
472474
trace_sdma_output_ibhdr(tx->priv->dd,
473475
&tx->sdma_hdr.hdr,
474476
ib_is_sc5(txp->flow.sc5));
@@ -478,20 +480,8 @@ static int hfi1_ipoib_send_dma_single(struct net_device *dev,
478480

479481
txq->pkts_sent = false;
480482

481-
if (ret == -EBUSY) {
482-
list_add_tail(&tx->txreq.list, &txq->tx_list);
483-
484-
trace_sdma_output_ibhdr(tx->priv->dd,
485-
&tx->sdma_hdr.hdr,
486-
ib_is_sc5(txp->flow.sc5));
487-
hfi1_ipoib_check_queue_depth(txq);
488-
return NETDEV_TX_OK;
489-
}
490-
491-
if (ret == -ECOMM) {
492-
hfi1_ipoib_check_queue_depth(txq);
493-
return NETDEV_TX_OK;
494-
}
483+
if (ret == -EBUSY || ret == -ECOMM)
484+
goto tx_ok;
495485

496486
sdma_txclean(priv->dd, &tx->txreq);
497487
dev_kfree_skb_any(skb);
@@ -509,9 +499,17 @@ static int hfi1_ipoib_send_dma_list(struct net_device *dev,
509499
struct ipoib_txreq *tx;
510500

511501
/* Has the flow change ? */
512-
if (txq->flow.as_int != txp->flow.as_int)
513-
(void)hfi1_ipoib_flush_tx_list(dev, txq);
514-
502+
if (txq->flow.as_int != txp->flow.as_int) {
503+
int ret;
504+
505+
ret = hfi1_ipoib_flush_tx_list(dev, txq);
506+
if (unlikely(ret)) {
507+
if (ret == -EBUSY)
508+
++dev->stats.tx_dropped;
509+
dev_kfree_skb_any(skb);
510+
return NETDEV_TX_OK;
511+
}
512+
}
515513
tx = hfi1_ipoib_send_dma_common(dev, skb, txp);
516514
if (IS_ERR(tx)) {
517515
int ret = PTR_ERR(tx);
@@ -612,6 +610,9 @@ static int hfi1_ipoib_sdma_sleep(struct sdma_engine *sde,
612610

613611
netif_stop_subqueue(txq->priv->netdev, txq->q_idx);
614612

613+
if (list_empty(&txreq->list))
614+
/* came from non-list submit */
615+
list_add_tail(&txreq->list, &txq->tx_list);
615616
if (list_empty(&txq->wait.list))
616617
iowait_queue(pkts_sent, wait->iow, &sde->dmawait);
617618

0 commit comments

Comments
 (0)