DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Weijun Pan <wpan3636@gmail.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbox@nvidia.com>,
	Jan Blunck <jblunck@infradead.org>
Cc: dev@dpdk.org, Weijun Pan <wpan3636@gmail.com>, stable@dpdk.org
Subject: [PATCH] net/vhost: preserve Tx ownership on VLAN failure
Date: Sun, 26 Jul 2026 12:02:58 -0500	[thread overview]
Message-ID: <20260726170258.8791-1-wpan3636@gmail.com> (raw)

The Tx path compacts the input mbuf array after software VLAN
insertion fails. Later packets are moved into the failed packet's
slot while the failed mbuf is freed.

The returned count then no longer identifies a prefix of the original
burst. An application freeing the unsent suffix can therefore free
duplicate or stale mbuf pointers.

Stop preprocessing at the first VLAN insertion failure and leave the
failed mbuf and the remaining suffix owned by the caller. Count only
packets prepared for vhost enqueue but not accepted as missed.

Bugzilla ID: 1884
Fixes: f63d356ee993 ("net/vhost: insert/strip VLAN header in software")
Cc: stable@dpdk.org

Signed-off-by: Weijun Pan <wpan3636@gmail.com>
---
Cc: Jan Blunck <jblunck@infradead.org>

Tested:
- Full x86_64 debug build with AddressSanitizer.
- Two-process net_vhost and virtio-user data-path test.
- Forced VLAN insertion failure on packet 1 by removing its headroom.
- rte_eth_tx_burst() returned 1 and preserved the unsent suffix.
- testpmd received 1 packet with no RX errors or missed packets.

 drivers/net/vhost/rte_eth_vhost.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 05940f2461..9a85f1e26d 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -474,19 +474,17 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 		/* Do VLAN tag insertion */
 		if (m->ol_flags & RTE_MBUF_F_TX_VLAN) {
 			int error = rte_vlan_insert(&m);
-			if (unlikely(error)) {
-				rte_pktmbuf_free(m);
-				continue;
-			}
+
+			if (unlikely(error))
+				break;
 		}
 
 		if (r->internal->tx_sw_csum)
 			vhost_dev_tx_sw_csum(m);
 
-
-		bufs[nb_send] = m;
-		++nb_send;
+		bufs[i] = m;
 	}
+	nb_send = i;
 
 	/* Enqueue packets to guest RX queue */
 	while (nb_send) {
@@ -506,7 +504,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 	for (i = 0; likely(i < nb_tx); i++)
 		nb_bytes += bufs[i]->pkt_len;
 
-	nb_missed = nb_bufs - nb_tx;
+	nb_missed = nb_send;
 
 	r->stats.pkts += nb_tx;
 	r->stats.bytes += nb_bytes;
-- 
2.34.1


                 reply	other threads:[~2026-07-26 17:03 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=20260726170258.8791-1-wpan3636@gmail.com \
    --to=wpan3636@gmail.com \
    --cc=chenbox@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=jblunck@infradead.org \
    --cc=maxime.coquelin@redhat.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