patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com,
	Chaoyong He <chaoyong.he@corigine.com>,
	stable@dpdk.org
Subject: [PATCH v2] net/nfp: fix the Tx descriptor free logic of nfd3
Date: Thu, 18 May 2023 19:02:47 +0800	[thread overview]
Message-ID: <20230518110247.1559733-1-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20230512020712.616206-1-chaoyong.he@corigine.com>

In the Tx descriptor free logic of nfd3, the former logic might force
cast a negative number into a very big unsigned number, and which will
cause potential problem in the xmit loop.

The xmit loop will continue in the place where it should break, and will
overwrite the Tx descriptor which is not free to use by the PMD.

Fixes: 74a640dac864 ("net/nfp: avoid modulo operations for handling ring wrapping")
Cc: stable@dpdk.org

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>
---
v2:
* Rebase to the latest main branch.
---
 drivers/net/nfp/nfd3/nfp_nfd3.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/nfp/nfd3/nfp_nfd3.h b/drivers/net/nfp/nfd3/nfp_nfd3.h
index 7bf2349904..e772bc4711 100644
--- a/drivers/net/nfp/nfd3/nfp_nfd3.h
+++ b/drivers/net/nfp/nfd3/nfp_nfd3.h
@@ -52,10 +52,14 @@ struct nfp_net_nfd3_tx_desc {
 static inline uint32_t
 nfp_net_nfd3_free_tx_desc(struct nfp_net_txq *txq)
 {
+	uint32_t free_desc;
+
 	if (txq->wr_p >= txq->rd_p)
-		return txq->tx_count - (txq->wr_p - txq->rd_p) - 8;
+		free_desc = txq->tx_count - (txq->wr_p - txq->rd_p);
 	else
-		return txq->rd_p - txq->wr_p - 8;
+		free_desc = txq->rd_p - txq->wr_p;
+
+	return (free_desc > 8) ? (free_desc - 8) : 0;
 }
 
 /*
-- 
2.39.1


  parent reply	other threads:[~2023-05-18 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-12  2:07 [PATCH] " Chaoyong He
2023-05-18 10:33 ` Ferruh Yigit
2023-05-18 10:49   ` Chaoyong He
2023-05-18 11:02 ` Chaoyong He [this message]
2023-05-18 14:43   ` [PATCH v2] " Ferruh Yigit

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=20230518110247.1559733-1-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=niklas.soderlund@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=stable@dpdk.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).