DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
	stable@dpdk.org, "Reshma Pattan" <reshma.pattan@intel.com>,
	"Mário Kuka" <kuka@cesnet.cz>
Subject: [PATCH 1/4] pcapng: call writev as needed on highly segmented mbuf
Date: Sun, 15 Nov 2026 11:22:15 -0800	[thread overview]
Message-ID: <20261115192215.504383-1-stephen@networkplumber.org> (raw)

It is possible to have an mbuf with more segments than the
max number of io vectors (1024 on Linux). This is an odd corner
case but it is allowed by DPDK since maximum number of segments
per mbuf is UINT16_MAX.

The old check assumed a single mbuf chain always fit in the
io vector, so a chain longer than IOV_MAX overran the stack
array. Consolidate the checks so now when io vector gets full
it is written. A packet may now be split across writev calls;
the previous flush at packet boundaries was incidental and not
a documented guarantee.

Bugzilla ID: 2133
Fixes: 0744f1c9f991 ("pcapng: fix write more packets than IOV_MAX limit")
Cc: stable@dpdk.org

Reported-by: Anthropic OSS scanner (ANT-2026-DC6DT4HP)
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/pcapng/rte_pcapng.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index df38e4819c..ce71b07d93 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -706,20 +706,6 @@ rte_pcapng_write_packets(rte_pcapng_t *self,
 		epb->timestamp_hi = timestamp >> 32;
 		epb->timestamp_lo = (uint32_t)timestamp;
 
-		/*
-		 * Handle case of highly fragmented and large burst size
-		 * Note: this assumes that max segments per mbuf < IOV_MAX
-		 */
-		if (unlikely(cnt + m->nb_segs >= IOV_MAX)) {
-			ret = writev(self->outfd, iov, cnt);
-			if (unlikely(ret < 0)) {
-				rte_errno = errno;
-				return -1;
-			}
-			total += ret;
-			cnt = 0;
-		}
-
 		/*
 		 * The DPDK port is recorded during pcapng_copy.
 		 * Map that to PCAPNG interface in file.
@@ -727,16 +713,29 @@ rte_pcapng_write_packets(rte_pcapng_t *self,
 		do {
 			iov[cnt].iov_base = rte_pktmbuf_mtod(m, void *);
 			iov[cnt].iov_len = rte_pktmbuf_data_len(m);
-			++cnt;
+
+			/* If current iov is maxed out then send it */
+			if (++cnt == IOV_MAX) {
+				ret = writev(self->outfd, iov, cnt);
+				if (unlikely(ret < 0)) {
+					rte_errno = errno;
+					return -1;
+				}
+				cnt = 0;
+				total += ret;
+			}
 		} while ((m = m->next));
 	}
 
-	ret = writev(self->outfd, iov, cnt);
-	if (unlikely(ret < 0)) {
-		rte_errno = errno;
-		return -1;
+	if (likely(cnt > 0)) {
+		ret = writev(self->outfd, iov, cnt);
+		if (unlikely(ret < 0)) {
+			rte_errno = errno;
+			return -1;
+		}
+		total += ret;
 	}
-	return total + ret;
+	return total;
 }
 
 /* Create new pcapng writer handle */
-- 
2.53.0


                 reply	other threads:[~2026-11-15 19:22 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=20261115192215.504383-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=kuka@cesnet.cz \
    --cc=reshma.pattan@intel.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