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>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Ori Kam <orika@nvidia.com>,
Konstantin Ananyev <konstantin.ananyev@huawei.com>
Subject: [PATCH v3 3/8] pdump: validate queues before installing callbacks
Date: Tue, 1 Dec 2026 11:31:12 -0800 [thread overview]
Message-ID: <20261201193243.1008280-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20261201193243.1008280-1-stephen@networkplumber.org>
Check for hairpin queue before enabling queues to detect
errors before registering callbacks. An explicit queue number is
also now range checked against the number of queues on the port.
A port with a hairpin queue set up for a flow rule still has normal
queues worth capturing, and asking for all queues is the common case.
Skip the hairpin queues there and log which ones were left out, rather
than failing the whole request. Naming a hairpin queue explicitly is
still an error, since that capture would never produce a packet.
If the skipping leaves nothing at all, the enable fails. A capture
with no callbacks installed delivers no packets, so the client would
sit waiting for traffic that cannot arrive. The count is taken across
both directions, so capturing rx and tx still works when only one of
them has a non hairpin queue.
The other failure possible is running out of memory while adding a
callback. Remove the callbacks already installed for the request
when that happens, rather than leaving them referencing a ring the
client is about to free. Only callbacks using this request's ring
are removed, so an unrelated capture on the port is left alone.
Bugzilla ID: 2075
Fixes: cf5516696d77 ("ethdev: add hairpin queue")
Fixes: 278f945402c5 ("pdump: add new library for packet capture")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/pdump/rte_pdump.c | 209 ++++++++++++++++++++++++++++++++----------
1 file changed, 162 insertions(+), 47 deletions(-)
diff --git a/lib/pdump/rte_pdump.c b/lib/pdump/rte_pdump.c
index 56a12f96ca..eb4bd11acc 100644
--- a/lib/pdump/rte_pdump.c
+++ b/lib/pdump/rte_pdump.c
@@ -8,6 +8,7 @@
#include <rte_alarm.h>
#include <rte_mbuf.h>
#include <rte_ethdev.h>
+#include <ethdev_driver.h>
#include <rte_lcore.h>
#include <rte_log.h>
#include <rte_memzone.h>
@@ -250,6 +251,65 @@ pdump_tx(uint16_t port, uint16_t queue,
}
+/*
+ * Check all queues before changing any. Capturing all queues skips the
+ * hairpin ones, since a port set up for hairpin still has normal queues
+ * worth capturing. Asking for a hairpin queue by number is an error.
+ *
+ * Returns the number of queues to act on, so the caller can tell a
+ * request that does nothing from one that works on a single direction.
+ */
+static int
+pdump_check_queues(uint16_t port, uint16_t queue, uint16_t end_q,
+ bool rx, uint16_t operation)
+{
+ struct rte_eth_dev *dev = &rte_eth_devices[port];
+ bool all = queue == RTE_PDUMP_ALL_QUEUES;
+ const char *dir = rx ? "rx" : "tx";
+ uint16_t qid, count = 0;
+
+ qid = all ? 0 : queue;
+ for (; qid < end_q; qid++) {
+ const struct pdump_rxtx_cbs *cbs =
+ rx ? &rx_cbs[port][qid] : &tx_cbs[port][qid];
+
+ /* hairpin queues do not pass through rx/tx burst */
+ if (rx ? rte_eth_dev_is_rx_hairpin_queue(dev, qid) :
+ rte_eth_dev_is_tx_hairpin_queue(dev, qid)) {
+ if (all) {
+ if (operation == ENABLE)
+ PDUMP_LOG_LINE(NOTICE,
+ "skipping hairpin %s queue port=%u queue=%u",
+ dir, port, qid);
+ continue;
+ }
+ PDUMP_LOG_LINE(ERR,
+ "cannot capture on hairpin %s queue port=%u queue=%u",
+ dir, port, qid);
+ return -EINVAL;
+ }
+
+ /* a port can only be captured by one client at a time */
+ if (operation == ENABLE && cbs->cb != NULL) {
+ PDUMP_LOG_LINE(ERR,
+ "%s callback for port=%u queue=%u, already exists",
+ dir, port, qid);
+ return -EEXIST;
+ }
+ if (operation == DISABLE && cbs->cb == NULL) {
+ if (all)
+ continue;
+ PDUMP_LOG_LINE(ERR,
+ "no existing %s callback for port=%u queue=%u",
+ dir, port, qid);
+ return -EINVAL;
+ }
+ ++count;
+ }
+
+ return count;
+}
+
static int
pdump_register_rx_callbacks(enum pdump_version ver,
uint16_t end_q, uint16_t port, uint16_t queue,
@@ -257,19 +317,20 @@ pdump_register_rx_callbacks(enum pdump_version ver,
struct rte_bpf *filter,
uint16_t operation, uint32_t snaplen)
{
+ struct rte_eth_dev *dev = &rte_eth_devices[port];
uint16_t qid;
qid = (queue == RTE_PDUMP_ALL_QUEUES) ? 0 : queue;
for (; qid < end_q; qid++) {
struct pdump_rxtx_cbs *cbs = &rx_cbs[port][qid];
+ if (rte_eth_dev_is_rx_hairpin_queue(dev, qid))
+ continue;
+
+ if (operation == DISABLE && cbs->cb == NULL)
+ continue;
+
if (operation == ENABLE) {
- if (cbs->cb) {
- PDUMP_LOG_LINE(ERR,
- "rx callback for port=%d queue=%d, already exists",
- port, qid);
- return -EEXIST;
- }
cbs->use_count = 0;
cbs->ver = ver;
cbs->ring = ring;
@@ -281,8 +342,8 @@ pdump_register_rx_callbacks(enum pdump_version ver,
pdump_rx, cbs);
if (cbs->cb == NULL) {
PDUMP_LOG_LINE(ERR,
- "failed to add rx callback, errno=%d",
- rte_errno);
+ "failed to add rx callback port=%u queue=%u: %s",
+ port, qid, rte_strerror(rte_errno));
return -rte_errno;
}
@@ -290,12 +351,14 @@ pdump_register_rx_callbacks(enum pdump_version ver,
} else if (operation == DISABLE) {
int ret;
- if (cbs->cb == NULL) {
- PDUMP_LOG_LINE(ERR,
- "no existing rx callback for port=%d queue=%d",
- port, qid);
- return -EINVAL;
- }
+ /*
+ * An undo passes the ring to remove only what the
+ * failed request installed. A client disable has no
+ * ring and removes whatever is there.
+ */
+ if (ring != NULL && cbs->ring != ring)
+ continue;
+
ret = rte_eth_remove_rx_callback(port, qid, cbs->cb);
if (ret < 0) {
PDUMP_LOG_LINE(ERR,
@@ -318,20 +381,20 @@ pdump_register_tx_callbacks(enum pdump_version ver,
struct rte_bpf *filter,
uint16_t operation, uint32_t snaplen)
{
-
+ struct rte_eth_dev *dev = &rte_eth_devices[port];
uint16_t qid;
qid = (queue == RTE_PDUMP_ALL_QUEUES) ? 0 : queue;
for (; qid < end_q; qid++) {
struct pdump_rxtx_cbs *cbs = &tx_cbs[port][qid];
+ if (rte_eth_dev_is_tx_hairpin_queue(dev, qid))
+ continue;
+
+ if (operation == DISABLE && cbs->cb == NULL)
+ continue;
+
if (operation == ENABLE) {
- if (cbs->cb) {
- PDUMP_LOG_LINE(ERR,
- "tx callback for port=%d queue=%d, already exists",
- port, qid);
- return -EEXIST;
- }
cbs->use_count = 0;
cbs->ver = ver;
cbs->ring = ring;
@@ -343,20 +406,22 @@ pdump_register_tx_callbacks(enum pdump_version ver,
cbs);
if (cbs->cb == NULL) {
PDUMP_LOG_LINE(ERR,
- "failed to add tx callback, errno=%d",
- rte_errno);
+ "failed to add tx callback port=%u queue=%u: %s",
+ port, qid, rte_strerror(rte_errno));
return -rte_errno;
}
memset(&pdump_stats->tx[port][qid], 0, sizeof(struct rte_pdump_stats));
} else if (operation == DISABLE) {
int ret;
- if (cbs->cb == NULL) {
- PDUMP_LOG_LINE(ERR,
- "no existing tx callback for port=%d queue=%d",
- port, qid);
- return -EINVAL;
- }
+ /*
+ * An undo passes the ring to remove only what the
+ * failed request installed. A client disable has no
+ * ring and removes whatever is there.
+ */
+ if (ring != NULL && cbs->ring != ring)
+ continue;
+
ret = rte_eth_remove_tx_callback(port, qid, cbs->cb);
if (ret < 0) {
PDUMP_LOG_LINE(ERR,
@@ -376,8 +441,10 @@ pdump_register_tx_callbacks(enum pdump_version ver,
static int
set_pdump_rxtx_cbs(const struct pdump_request *p)
{
- uint16_t nb_rx_q = 0, nb_tx_q = 0, end_q, queue;
+ struct rte_eth_dev_info dev_info;
+ uint16_t nb_rx_q, nb_tx_q, queue;
uint16_t port;
+ int nb_queues;
int ret = 0;
struct rte_bpf *filter = NULL;
uint32_t flags;
@@ -422,18 +489,15 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
return -EINVAL;
}
- /* validation if packet capture is for all queues */
- if (queue == RTE_PDUMP_ALL_QUEUES) {
- struct rte_eth_dev_info dev_info;
-
- ret = rte_eth_dev_info_get(port, &dev_info);
- if (ret != 0) {
- PDUMP_LOG_LINE(ERR,
- "Error during getting device (port %u) info: %s",
- port, strerror(-ret));
- return ret;
- }
+ ret = rte_eth_dev_info_get(port, &dev_info);
+ if (ret != 0) {
+ PDUMP_LOG_LINE(ERR,
+ "Error during getting device (port %u) info: %s",
+ port, strerror(-ret));
+ return ret;
+ }
+ if (queue == RTE_PDUMP_ALL_QUEUES) {
nb_rx_q = dev_info.nb_rx_queues;
nb_tx_q = dev_info.nb_tx_queues;
if (nb_rx_q == 0 && flags & RTE_PDUMP_FLAG_RX) {
@@ -452,26 +516,77 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)
"both tx&rx queues must be non zero");
return -EINVAL;
}
+ } else {
+ if (((flags & RTE_PDUMP_FLAG_RX) && queue >= dev_info.nb_rx_queues) ||
+ ((flags & RTE_PDUMP_FLAG_TX) && queue >= dev_info.nb_tx_queues)) {
+ PDUMP_LOG_LINE(ERR,
+ "invalid queue %u for port %u", queue, port);
+ return -EINVAL;
+ }
+ nb_rx_q = nb_tx_q = queue + 1;
+ }
+
+ /* check all queues before changing any */
+ nb_queues = 0;
+ if (flags & RTE_PDUMP_FLAG_RX) {
+ ret = pdump_check_queues(port, queue, nb_rx_q, true, operation);
+ if (ret < 0)
+ return ret;
+ nb_queues += ret;
+ }
+ if (flags & RTE_PDUMP_FLAG_TX) {
+ ret = pdump_check_queues(port, queue, nb_tx_q, false, operation);
+ if (ret < 0)
+ return ret;
+ nb_queues += ret;
+ }
+
+ /*
+ * A capture with no callbacks would never deliver a packet and the
+ * client would wait for traffic that cannot arrive. One direction
+ * being all hairpin is fine as long as the other has a queue.
+ */
+ if (nb_queues == 0 && operation == ENABLE) {
+ PDUMP_LOG_LINE(ERR, "no queue available to capture on port=%u",
+ port);
+ return -EINVAL;
}
/* register RX callback */
if (flags & RTE_PDUMP_FLAG_RX) {
- end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_rx_q : queue + 1;
- ret = pdump_register_rx_callbacks(p->ver, end_q, port, queue,
+ ret = pdump_register_rx_callbacks(p->ver, nb_rx_q, port, queue,
ring, mp, filter,
operation, p->snaplen);
if (ret < 0)
- return ret;
+ goto undo;
}
/* register TX callback */
if (flags & RTE_PDUMP_FLAG_TX) {
- end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_tx_q : queue + 1;
- ret = pdump_register_tx_callbacks(p->ver, end_q, port, queue,
+ ret = pdump_register_tx_callbacks(p->ver, nb_tx_q, port, queue,
ring, mp, filter,
operation, p->snaplen);
if (ret < 0)
- return ret;
+ goto undo;
+ }
+
+ return 0;
+
+undo:
+ /*
+ * Remove the callbacks already installed, they reference a ring the
+ * client is about to free. Registration is called directly here
+ * because the checks above reject this half enabled state.
+ */
+ if (operation == ENABLE) {
+ if (flags & RTE_PDUMP_FLAG_RX)
+ pdump_register_rx_callbacks(p->ver, nb_rx_q, port, queue,
+ ring, mp, filter,
+ DISABLE, p->snaplen);
+ if (flags & RTE_PDUMP_FLAG_TX)
+ pdump_register_tx_callbacks(p->ver, nb_tx_q, port, queue,
+ ring, mp, filter,
+ DISABLE, p->snaplen);
}
return ret;
--
2.53.0
next prev parent reply other threads:[~2026-12-01 19:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 14:16 [PATCH 0/4] pdump: fix capture on ports with hairpin queues Stephen Hemminger
2026-10-28 14:16 ` [PATCH 1/4] ethdev: reject hairpin queue in add first Rx callback Stephen Hemminger
2026-10-28 14:16 ` [PATCH 2/4] pdump: fix error code when adding callback fails Stephen Hemminger
2026-10-28 14:16 ` [PATCH 3/4] pdump: skip hairpin queues Stephen Hemminger
2026-10-28 14:16 ` [PATCH 4/4] pdump: undo partial enable on failure Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 0/6] pdump: fix bugs related to hairpin queues Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 1/6] ethdev: reject hairpin queue in add first Rx callback Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 2/6] pdump: fix error code when adding callback fails Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 3/6] pdump: validate queues before installing callbacks Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 4/6] pdump: release BPF filter on error Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 5/6] pdump: report secondary process failures Stephen Hemminger
2026-11-27 21:07 ` [PATCH v2 6/6] app/dumpcap: disable capture on the interface that failed Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 0/8] pdump: fix error handling on failed enable Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 1/8] ethdev: reject hairpin queue in add first Rx callback Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 2/8] pdump: fix error code when adding callback fails Stephen Hemminger
2026-12-01 19:31 ` Stephen Hemminger [this message]
2026-12-01 19:31 ` [PATCH v3 4/8] pdump: release BPF filter on error Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 5/8] eal: fix IPC request when no handler is registered Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 6/8] test/mp: check request with no registered handler Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 7/8] pdump: report secondary process failures Stephen Hemminger
2026-12-01 19:31 ` [PATCH v3 8/8] test/pdump: check secondary process result Stephen Hemminger
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=20261201193243.1008280-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=konstantin.ananyev@huawei.com \
--cc=orika@nvidia.com \
--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