From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
stable@dpdk.org, Tony U <tony@compilex.com>
Subject: [PATCH] raw/ntb: fix Tx of incomplete packets
Date: Tue, 17 Nov 2026 11:30:17 +0000 [thread overview]
Message-ID: <20261117113017.2225641-1-bruce.richardson@intel.com> (raw)
When a Tx descriptor had no room, a zero length or an unmappable
address, the Tx burst stopped after its software ring entry had already
been set to the mbuf, which is still owned by the application. On
device stop, that mbuf was freed a second time.
For multi-segment mbufs, a failure on a later segment also left the
earlier segments enqueued and published to the peer without EOP, with
their ring entries referencing application-owned mbufs.
Check all descriptors of a packet before consuming any of them,
so that the ring is only updated for complete packets.
Bugzilla ID: 2134
Fixes: 11b5c7daf019 ("raw/ntb: add enqueue and dequeue functions")
Cc: stable@dpdk.org
Reported-by: Tony U <tony@compilex.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/raw/ntb/ntb.c | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/drivers/raw/ntb/ntb.c b/drivers/raw/ntb/ntb.c
index 85354b54ed..94802d5f20 100644
--- a/drivers/raw/ntb/ntb.c
+++ b/drivers/raw/ntb/ntb.c
@@ -576,12 +576,13 @@ ntb_enqueue_bufs(struct rte_rawdev *dev,
struct ntb_tx_entry *sw_ring = txq->sw_ring;
struct rte_mbuf *txm;
struct ntb_used tx_used[NTB_MAX_DESC_SIZE];
+ void *seg_addr[NTB_MAX_DESC_SIZE];
+ uint16_t seg_len[NTB_MAX_DESC_SIZE];
volatile struct ntb_desc *tx_item;
uint16_t tx_last, nb_segs, off, last_used, avail_cnt;
uint16_t nb_mbufs = 0;
uint16_t nb_tx = 0;
uint64_t bytes = 0;
- void *buf_addr;
int i;
if (unlikely(dev->started == 0 || !ntb_peer_dev_is_up(hw))) {
@@ -600,35 +601,43 @@ ntb_enqueue_bufs(struct rte_rawdev *dev,
if (txm == NULL || txq->nb_tx_free < txm->nb_segs)
break;
- tx_last = (txq->last_used + txm->nb_segs - 1) &
- (txq->nb_tx_desc - 1);
nb_segs = txm->nb_segs;
+ /* Check all descriptors first so a packet is never partially enqueued. */
for (i = 0; i < nb_segs; i++) {
+ const uint16_t idx = (txq->last_used + i) & (txq->nb_tx_desc - 1);
+
/* Not enough ring space for tx. */
- if (txq->last_used == avail_cnt)
+ if (idx == avail_cnt)
goto end_of_tx;
- sw_ring[txq->last_used].mbuf = txm;
- tx_item = txq->tx_desc_ring + txq->last_used;
+ tx_item = txq->tx_desc_ring + idx;
- if (!tx_item->len) {
+ seg_len[i] = tx_item->len;
+ if (seg_len[i] == 0) {
(hw->ntb_xstats[NTB_TX_ERRS_ID + off])++;
goto end_of_tx;
}
- if (txm->data_len > tx_item->len) {
- NTB_LOG(ERR, "Data length exceeds buf length."
- " Only %u data would be transmitted.",
- tx_item->len);
- txm->data_len = tx_item->len;
- }
/* translate remote virtual addr to bar virtual addr */
- buf_addr = (*hw->ntb_ops->ioremap)(dev, tx_item->addr);
- if (buf_addr == NULL) {
+ seg_addr[i] = (*hw->ntb_ops->ioremap)(dev, tx_item->addr);
+ if (seg_addr[i] == NULL) {
(hw->ntb_xstats[NTB_TX_ERRS_ID + off])++;
NTB_LOG(ERR, "Null remap addr.");
goto end_of_tx;
}
- rte_memcpy(buf_addr, rte_pktmbuf_mtod(txm, void *),
+ }
+
+ tx_last = (txq->last_used + nb_segs - 1) & (txq->nb_tx_desc - 1);
+ for (i = 0; i < nb_segs; i++) {
+ sw_ring[txq->last_used].mbuf = txm;
+
+ if (txm->data_len > seg_len[i]) {
+ NTB_LOG(ERR, "Data length exceeds buf length."
+ " Only %u data would be transmitted.",
+ seg_len[i]);
+ txm->data_len = seg_len[i];
+ }
+
+ rte_memcpy(seg_addr[i], rte_pktmbuf_mtod(txm, void *),
txm->data_len);
tx_used[nb_mbufs].len = txm->data_len;
--
2.55.0
reply other threads:[~2026-11-17 11:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261117113017.2225641-1-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=tony@compilex.com \
/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