Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27D28606A32D for ; Tue, 1 Dec 2026 19:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=Yznm2tgS Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7896740656; Tue, 1 Dec 2026 20:32:52 +0100 (CET) Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by mails.dpdk.org (Postfix) with ESMTPS id 6631140647 for ; Tue, 1 Dec 2026 20:32:50 +0100 (CET) Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b3a42a4bcdso4976190a91.0 for ; Tue, 01 Dec 2026 11:32:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796153569; x=1796758369; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NS8DzORfHyLEC91AXWHXmm2F2qvYCNDwrubS3XX1Okk=; b=Yznm2tgSipdtLsCc6ul+16rgw1ZJM2IYkpAcEOfvOY4Qe9CfRnwert7qS9ljWvRNmA 1xs4l6Q+VdAYOb1xqEUVu2vPOKJPWO77VUfPxPm/Fdtn7YP5/+iM1QkA2ogjkWpPle9O euEpV8iOFNBINIHx+4omco4jOlvN5McF+hgQNGACnoQYXiEs36oPppSo/cvrNp8hd4bd Dhz/pDHRKpOssMWFawER+HJYASfa/R6JLfU0WCA07xh3XpdZvBVT2T1s/yQd8gbG2A3G 6RivpxeQSeTv6yYNgFQh1OW7H8PRDlw0YILDuU0ghhzIUYsWFL/aoXKf0HhpgBW2Afm4 U/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796153569; x=1796758369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NS8DzORfHyLEC91AXWHXmm2F2qvYCNDwrubS3XX1Okk=; b=kkAmU5zTWneRzogqaXPYnxzrDJaxNiWvUa3QfwIrmzWWaud+ZAiQ2YvtkvzRDZt1eM souH36G9RpwG+agUPfiZS4BXgRLUHczllXdvsHTwja/r/RbBq4Xd6sTQQLwxm550gp7g rA1KQfXmnc1dfWFXFP3SUjMptK53wDjSMsYLPWsAGSaHGatq7QG9xEzjQTXyqnEXQkW6 wDtaUakG5BtWAhqNAkp6AViY3JuLgHIuocA9SgCFHSFxD3pi8kMtwLN/wIDWtCPdTLdb a7r8cEWgi+6+KxyAa45Jsbfw9WHheHLPgRL0WDzDPWSYxJxHmfHdKFNBjHevwTCayG+S GC1g== X-Gm-Message-State: APuU4Z9sG3K26am9Uk+V/Vf8DueMkRN8CFS5DuO23DDfI0geweG3mMCy EnlbLgDeT7EZ8+drmTMtWK8rKQDUvWihnIG2WMiIxoMc6EriGkntYLALYYP0Mdj9vYFPswogZi0 V1F2sBPo= X-Gm-Gg: AZFdTZcyyfgG3BtO+PUbmdxOHUFq/fAKbEMtK2tyGboedv4TDBCTwMhiFjN1p+uGbm4 KviPEke3lXGkgIcw1yHja3QGL2I8ObfZPzrMz8jD+etEHMgCEZwkSe6vmFqRqUC0NTtRzhO900M icmKNNwzGbK6gD6kScpjc8VsS/DLEJZ0I0JhMfFTEU+l3dWLtmVf+eukqEIF/HgcCxwzZXe63ar PRec0CFL4ooPvIk8rtinNznd1eN0BUymwwOFHjl/mlGiWy72XL5gLx14pyLtwiIm+dv/DQlGCM8 aCIHmmg8XtWWEj0IRa8brRZjqSjRMIXTpJJrcPBqaNvqWvtU/ajYYciJnNGNsXh+2luaGghIHBW QTti3mI+HSiooxLhxHVPP5mZ3AbAQye9zcz94EvDGyviobiUQZS/E1GAMdQFVNcZ+e0EdLCoJwR ovuupnw5DiwS+Mpw8QmpDLhrcmqbOuQdLaCWbptexgWyFsP7K+AjZUWGmD4eLLm0IsteVDKPSld YQZ6mDdQWlTMhWS7NzPUQKM+yhLd3V/THe+5d/D2al9mo1PsiI12nbqu/7aQ+1KGO8i8Qt+DQyw 4p1QJS/XDlmKdyllKEFUmm56suyxVS60BCJ2O2evtYTb1ZKZd5GYzkwCwK6zlLR+Cs7T X-Received: by 2002:a17:90b:52cc:b0:3b3:fcd4:36f with SMTP id 98e67ed59e1d1-3b41c966a8cmr36973383a91.43.1796153568574; Tue, 01 Dec 2026 11:32:48 -0800 (PST) Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b21e19fsm23264700a91.0.2026.12.01.11.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 11:32:48 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , stable@dpdk.org, Reshma Pattan , Andrew Rybchenko , Ori Kam , Konstantin Ananyev Subject: [PATCH v3 3/8] pdump: validate queues before installing callbacks Date: Tue, 1 Dec 2026 11:31:12 -0800 Message-ID: <20261201193243.1008280-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201193243.1008280-1-stephen@networkplumber.org> References: <20261028141750.310963-1-stephen@networkplumber.org> <20261201193243.1008280-1-stephen@networkplumber.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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 #include #include +#include #include #include #include @@ -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