Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ganji Aravind <ganji.aravind@chelsio.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, vishal@chelsio.com, rahul.lakkireddy@chelsio.com
Subject: [PATCH net 2/2] cxgb4: Fix race between loopback and normal Tx path
Date: Tue, 18 Aug 2020 21:10:58 +0530	[thread overview]
Message-ID: <20200818154058.1770002-3-ganji.aravind@chelsio.com> (raw)
In-Reply-To: <20200818154058.1770002-1-ganji.aravind@chelsio.com>

Even after Tx queues are marked stopped, there exists a
small window where the current packet in the normal Tx
path is still being sent out and loopback selftest ends
up corrupting the same Tx ring. So, ensure selftest takes
the Tx lock to synchronize access the Tx ring.

Fixes: 7235ffae3d2c ("cxgb4: add loopback ethtool self-test")
Signed-off-by: Ganji Aravind <ganji.aravind@chelsio.com>
---
 drivers/net/ethernet/chelsio/cxgb4/sge.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index 7c9fe4bc235b..869431a1eedd 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -2561,11 +2561,14 @@ int cxgb4_selftest_lb_pkt(struct net_device *netdev)
 	lb->loopback = 1;
 
 	q = &adap->sge.ethtxq[pi->first_qset];
+	__netif_tx_lock(q->txq, smp_processor_id());
 
 	reclaim_completed_tx(adap, &q->q, -1, true);
 	credits = txq_avail(&q->q) - ndesc;
-	if (unlikely(credits < 0))
+	if (unlikely(credits < 0)) {
+		__netif_tx_unlock(q->txq);
 		return -ENOMEM;
+	}
 
 	wr = (void *)&q->q.desc[q->q.pidx];
 	memset(wr, 0, sizeof(struct tx_desc));
@@ -2598,6 +2601,7 @@ int cxgb4_selftest_lb_pkt(struct net_device *netdev)
 	init_completion(&lb->completion);
 	txq_advance(&q->q, ndesc);
 	cxgb4_ring_tx_db(adap, &q->q, ndesc);
+	__netif_tx_unlock(q->txq);
 
 	/* wait for the pkt to return */
 	ret = wait_for_completion_timeout(&lb->completion, 10 * HZ);
-- 
2.26.2


  parent reply	other threads:[~2020-08-18 15:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-18 15:40 [PATCH net 0/2]cxgb4: Fix ethtool selftest flits calculation Ganji Aravind
2020-08-18 15:40 ` [PATCH net 1/2] cxgb4: Fix work request size calculation for loopback test Ganji Aravind
2020-08-18 19:33   ` Jesse Brandeburg
2020-08-18 15:40 ` Ganji Aravind [this message]
2020-08-18 19:35   ` [PATCH net 2/2] cxgb4: Fix race between loopback and normal Tx path Jesse Brandeburg
2020-08-18 20:03 ` [PATCH net 0/2]cxgb4: Fix ethtool selftest flits calculation David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200818154058.1770002-3-ganji.aravind@chelsio.com \
    --to=ganji.aravind@chelsio.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=rahul.lakkireddy@chelsio.com \
    --cc=vishal@chelsio.com \
    --subject='Re: [PATCH net 2/2] cxgb4: Fix race between loopback and normal Tx path' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).