pdump: fix capture on ports with hairpin queues
cover pdump: fix capture on ports with hairpin queues
This was reported on dpdk slack channel.
dpdk-dumpcap fails on a port with hairpin queues. The first attempt reports "Unknown error -22" and every later attempt fails with EEXIST until the application is restarted.
Several bugs combine: pdump tries to add callbacks to hairpin queues, the error is returned with the wrong sign, and a partially enabled capture is not undone. Also the first Rx callback API was missing the hairpin check the other callback APIs have.
Stephen Hemminger (4):
ethdev: reject hairpin queue in add first Rx callback
pdump: fix error code when adding callback fails
pdump: skip hairpin queues
pdump: undo partial enable on failure
lib/ethdev/rte_ethdev.c | 5 ++ lib/pdump/rte_pdump.c | 112 +++++++++++++++++++++++++++++++++------- 2 files changed, 98 insertions(+), 19 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/4 ethdev: reject hairpin queue in add first Rx callback
rte_eth_add_rx_callback() and rte_eth_add_tx_callback() refuse hairpin queues, but rte_eth_add_first_rx_callback() was missed. A callback installed on a hairpin queue is never invoked.
--- lib/ethdev/rte_ethdev.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/ethdev/rte_ethdev.c +5 -0
@@ -6173,6 +6173,11 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,return NULL ; } +if (rte_eth_dev_is_rx_hairpin_queue (&rte_eth_devices[port_id], queue_id)) { + rte_errno =EINVAL ; +return NULL ; + } +struct rte_eth_rxtx_callback *cb =rte_zmalloc (NULL ,sizeof (*cb),0 );if (cb ==NULL ) {
Signature · 1 line
2.53.0
PATCH 2/4 pdump: fix error code when adding callback fails
In reply to Stephen HemmingerThe register functions returned positive rte_errno on failure. The caller only checks for negative values, so a failed Rx enable fell through to Tx, and the positive value sent back to the client was negated into rte_errno, giving messages like "Unknown error -22".
--- lib/pdump/rte_pdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/pdump/rte_pdump.c +2 -2
@@ -283,7 +283,7 @@ pdump_register_rx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add rx callback, errno=%d" , rte_errno); -return rte_errno; +return -rte_errno; }memset (&pdump_stats->rx[port][qid],0 ,sizeof (struct rte_pdump_stats ));
@@ -345,7 +345,7 @@ pdump_register_tx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add tx callback, errno=%d" , rte_errno); -return rte_errno; +return -rte_errno; }memset (&pdump_stats->tx[port][qid],0 ,sizeof (struct rte_pdump_stats )); }else if (operation ==DISABLE ) {
Signature · 1 line
2.53.0
PATCH 3/4 pdump: skip hairpin queues
In reply to Stephen HemmingerWhen capturing on all queues, pdump walks nb_rx_queues and nb_tx_queues, which include hairpin queues. Adding a Tx callback to a hairpin queue fails, so capture could not be enabled on any port with hairpin queues configured.
Skip hairpin queues when capturing all queues, and reject an explicit request for a hairpin queue.
--- lib/pdump/rte_pdump.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
lib/pdump/rte_pdump.c +21 -0
@@ -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>
@@ -263,6 +264,16 @@ pdump_register_rx_callbacks(enum pdump_version ver,for (; qid < end_q; qid++) {struct pdump_rxtx_cbs *cbs = &rx_cbs[port][qid]; +/* hairpin queues do not pass through rx burst */ +if (rte_eth_dev_is_rx_hairpin_queue (&rte_eth_devices[port], qid)) { +if (queue ==RTE_PDUMP_ALL_QUEUES ) +continue ; +PDUMP_LOG_LINE (ERR , +"cannot capture on hairpin rx queue port=%d queue=%d" , + port, qid); +return -EINVAL ; + } +if (operation ==ENABLE ) {if (cbs->cb) { PDUMP_LOG_LINE(ERR,
@@ -325,6 +336,16 @@ pdump_register_tx_callbacks(enum pdump_version ver,for (; qid < end_q; qid++) {struct pdump_rxtx_cbs *cbs = &tx_cbs[port][qid]; +/* hairpin queues do not pass through tx burst */ +if (rte_eth_dev_is_tx_hairpin_queue (&rte_eth_devices[port], qid)) { +if (queue ==RTE_PDUMP_ALL_QUEUES ) +continue ; +PDUMP_LOG_LINE (ERR , +"cannot capture on hairpin tx queue port=%d queue=%d" , + port, qid); +return -EINVAL ; + } +if (operation ==ENABLE ) {if (cbs->cb) { PDUMP_LOG_LINE(ERR,
Signature · 1 line
2.53.0
PATCH 4/4 pdump: undo partial enable on failure
In reply to Stephen HemmingerIf enabling capture failed partway, the callbacks already installed were left in place. They still reference the ring and mempool of the client that requested capture, and every later enable on that port fails with EEXIST until the application is restarted.
Remove callbacks installed by the failed request, on the failing direction and on Rx when Tx fails. Also release the BPF filter on the error paths.
--- lib/pdump/rte_pdump.c | 91 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 19 deletions(-)
lib/pdump/rte_pdump.c +72 -19
@@ -251,6 +251,39 @@ pdump_tx(uint16_t port, uint16_t queue, } +/* Remove callbacks on queues [first, last) after a failed enable */ +static void +pdump_unwind_rx_callbacks (uint16_t port,uint16_t first,uint16_t last) +{ +uint16_t qid; + +for (qid = first; qid < last; qid++) { +struct pdump_rxtx_cbs *cbs = &rx_cbs[port][qid]; + +if (cbs->cb ==NULL ) +continue ; +rte_eth_remove_rx_callback (port, qid, cbs->cb); +pdump_cb_wait (cbs); + cbs->cb =NULL ; + } +} + +static void +pdump_unwind_tx_callbacks (uint16_t port,uint16_t first,uint16_t last) +{ +uint16_t qid; + +for (qid = first; qid < last; qid++) { +struct pdump_rxtx_cbs *cbs = &tx_cbs[port][qid]; + +if (cbs->cb ==NULL ) +continue ; +rte_eth_remove_tx_callback (port, qid, cbs->cb); +pdump_cb_wait (cbs); + cbs->cb =NULL ; + } +} + static int pdump_register_rx_callbacks(enum pdump_version ver, uint16_t end_q, uint16_t port, uint16_t queue,
@@ -258,10 +291,11 @@ pdump_register_rx_callbacks(enum pdump_version ver,struct rte_bpf *filter, uint16_t operation, uint32_t snaplen) { - uint16_t qid; + uint16_t first, qid; +int ret; - qid = (queue ==RTE_PDUMP_ALL_QUEUES ) ?0 : queue; -for (; qid < end_q; qid++) { + first = (queue ==RTE_PDUMP_ALL_QUEUES ) ?0 : queue; +for (qid = first; qid < end_q; qid++) {struct pdump_rxtx_cbs *cbs = &rx_cbs[port][qid];/* hairpin queues do not pass through rx burst */
@@ -279,6 +313,7 @@ pdump_register_rx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"rx callback for port=%d queue=%d, already exists" , port, qid); +pdump_unwind_rx_callbacks (port, first, qid);return -EEXIST ; } cbs->use_count =0 ;
@@ -294,13 +329,13 @@ pdump_register_rx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add rx callback, errno=%d" , rte_errno); -return -rte_errno; + ret = -rte_errno; +pdump_unwind_rx_callbacks (port, first, qid); +return ret; }memset (&pdump_stats->rx[port][qid],0 ,sizeof (struct rte_pdump_stats )); }else if (operation ==DISABLE ) { -int ret; -if (cbs->cb ==NULL ) { PDUMP_LOG_LINE(ERR, "no existing rx callback for port=%d queue=%d",
@@ -330,10 +365,11 @@ pdump_register_tx_callbacks(enum pdump_version ver, uint16_t operation, uint32_t snaplen) { -uint16_t qid; +uint16_t first, qid; +int ret; - qid = (queue ==RTE_PDUMP_ALL_QUEUES ) ?0 : queue; -for (; qid < end_q; qid++) { + first = (queue ==RTE_PDUMP_ALL_QUEUES ) ?0 : queue; +for (qid = first; qid < end_q; qid++) {struct pdump_rxtx_cbs *cbs = &tx_cbs[port][qid];/* hairpin queues do not pass through tx burst */
@@ -351,6 +387,7 @@ pdump_register_tx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"tx callback for port=%d queue=%d, already exists" , port, qid); +pdump_unwind_tx_callbacks (port, first, qid);return -EEXIST ; } cbs->use_count =0 ;
@@ -366,12 +403,12 @@ pdump_register_tx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add tx callback, errno=%d" , rte_errno); -return -rte_errno; + ret = -rte_errno; +pdump_unwind_tx_callbacks (port, first, qid); +return ret; }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",
@@ -440,7 +477,8 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"failed to get port id for device id=%s" , p->device); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }/* validation if packet capture is for all queues */
@@ -452,7 +490,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"Error during getting device (port %u) info: %s" , port,strerror (-ret)); -return ret; + goto free_filter; } nb_rx_q = dev_info.nb_rx_queues;
@@ -460,18 +498,21 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)if (nb_rx_q ==0 && flags &RTE_PDUMP_FLAG_RX ) {PDUMP_LOG_LINE (ERR ,"number of rx queues cannot be 0" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }if (nb_tx_q ==0 && flags &RTE_PDUMP_FLAG_TX ) {PDUMP_LOG_LINE (ERR ,"number of tx queues cannot be 0" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }if ((nb_tx_q ==0 || nb_rx_q ==0 ) && flags ==RTE_PDUMP_FLAG_RXTX ) {PDUMP_LOG_LINE (ERR ,"both tx&rx queues must be non zero" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; } }
@@ -482,7 +523,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) ring, mp, filter, operation, p->snaplen);if (ret <0 ) -return ret; + goto free_filter; }/* register TX callback */
@@ -492,8 +533,20 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) ring, mp, filter, operation, p->snaplen);if (ret <0 ) -return ret; + goto unwind_rx; + } + +return 0 ; + +unwind_rx: +if (operation ==ENABLE && (flags &RTE_PDUMP_FLAG_RX )) { + end_q = (queue ==RTE_PDUMP_ALL_QUEUES ) ? nb_rx_q : queue +1 ; +pdump_unwind_rx_callbacks (port, + (queue ==RTE_PDUMP_ALL_QUEUES ) ?0 : queue, end_q); } +free_filter: +if (filter !=NULL ) +rte_bpf_destroy (filter);return ret; }
Signature · 1 line
2.53.0
v2 cover pdump: fix bugs related to hairpin queues
In reply to Stephen HemmingerThis was reported on dpdk slack channel.
dpdk-dumpcap fails on a port with hairpin queues. The first attempt reports "Unknown error -22" and every later attempt fails with EEXIST until the application is restarted.
Several bugs combine: pdump tries to add callbacks to hairpin queues, the error is returned with the wrong sign, and a partially enabled capture is not undone. Also the first Rx callback API was missing the hairpin check the other callback APIs have.
Stephen Hemminger (6):
ethdev: reject hairpin queue in add first Rx callback
pdump: fix error code when adding callback fails
pdump: validate queues before installing callbacks
pdump: release BPF filter on error
pdump: report secondary process failures app/dumpcap: disable capture on the interface that failed
app/dumpcap/main.c | 10 +- lib/ethdev/rte_ethdev.c | 5 + lib/pdump/rte_pdump.c | 242 ++++++++++++++++++++++++++++++---------- 3 files changed, 196 insertions(+), 61 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/6 ethdev: reject hairpin queue in add first Rx callback
rte_eth_add_rx_callback() and rte_eth_add_tx_callback() refuse hairpin queues, but rte_eth_add_first_rx_callback() was missed. A callback installed on a hairpin queue is never invoked.
--- lib/ethdev/rte_ethdev.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/ethdev/rte_ethdev.c +5 -0
@@ -6234,6 +6234,11 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,return NULL ; } +if (rte_eth_dev_is_rx_hairpin_queue (&rte_eth_devices[port_id], queue_id)) { + rte_errno =EINVAL ; +return NULL ; + } +struct rte_eth_rxtx_callback *cb =rte_zmalloc (NULL ,sizeof (*cb),0 );if (cb ==NULL ) {
Signature · 1 line
2.53.0
PATCH v2 2/6 pdump: fix error code when adding callback fails
In reply to Stephen HemmingerThe register functions returned positive rte_errno on failure. The caller only checks for negative values, so a failed Rx enable fell through to Tx, and the positive value sent back to the client was negated into rte_errno, giving messages like "Unknown error -22".
--- lib/pdump/rte_pdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/pdump/rte_pdump.c +2 -2
@@ -283,7 +283,7 @@ pdump_register_rx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add rx callback, errno=%d" , rte_errno); -return rte_errno; +return -rte_errno; }memset (&pdump_stats->rx[port][qid],0 ,sizeof (struct rte_pdump_stats ));
@@ -345,7 +345,7 @@ pdump_register_tx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add tx callback, errno=%d" , rte_errno); -return rte_errno; +return -rte_errno; }memset (&pdump_stats->tx[port][qid],0 ,sizeof (struct rte_pdump_stats )); }else if (operation ==DISABLE ) {
Signature · 1 line
2.53.0
PATCH v2 3/6 pdump: validate queues before installing callbacks
In reply to Stephen HemmingerCheck for hairpin queue before enabling queues to detect errors before registering callbacks.
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.
--- lib/pdump/rte_pdump.c | 177 +++++++++++++++++++++++++++++++----------- 1 file changed, 130 insertions(+), 47 deletions(-)
lib/pdump/rte_pdump.c +130 -47
@@ -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,64 @@ pdump_tx(uint16_t port, uint16_t queue, } +/* +* Check all queues before changing any. Unusable queues are skipped +* when capturing all queues, but rejected if asked for explicitly. +*/ +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) +continue ; +PDUMP_LOG_LINE (ERR , +"cannot capture on hairpin %s queue port=%u queue=%u" , + dir, port, qid); +return -EINVAL ; + } + +if (operation ==ENABLE && cbs->cb !=NULL ) { +if (all) +continue ; +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; + } + +/* Enabling nothing would capture nothing, silently */ +if (count ==0 && operation ==ENABLE ) { +PDUMP_LOG_LINE (ERR ,"no %s queue available on port=%u" , + dir, port); +return -EINVAL ; + } + +return 0 ; +} + static int pdump_register_rx_callbacks(enum pdump_version ver, uint16_t end_q, uint16_t port, uint16_t queue,
@@ -257,19 +316,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 ==ENABLE ? cbs->cb !=NULL : 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 +341,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 +350,6 @@ 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 ; - } ret =rte_eth_remove_rx_callback (port, qid, cbs->cb);if (ret <0 ) { PDUMP_LOG_LINE(ERR,
@@ -318,20 +372,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 ==ENABLE ? cbs->cb !=NULL : 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 +397,14 @@ 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 ; - } ret =rte_eth_remove_tx_callback (port, qid, cbs->cb);if (ret <0 ) { PDUMP_LOG_LINE(ERR,
@@ -376,7 +424,8 @@ 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 ret =0 ;struct rte_bpf *filter =NULL ;
@@ -422,18 +471,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 +498,63 @@ 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 */ +if (flags &RTE_PDUMP_FLAG_RX ) { + ret =pdump_check_queues (port, queue, nb_rx_q, true, operation); +if (ret <0 ) +return ret; + } +if (flags &RTE_PDUMP_FLAG_TX ) { + ret =pdump_check_queues (port, queue, nb_tx_q, false, operation); +if (ret <0 ) +return ret; }/* 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;
Signature · 1 line
2.53.0
PATCH v2 4/6 pdump: release BPF filter on error
In reply to Stephen HemmingerThe BPF filter loaded for a request was leaked if the request failed. A successful enable keeps it, the callbacks reference it.
--- lib/pdump/rte_pdump.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
lib/pdump/rte_pdump.c +17 -8
@@ -468,7 +468,8 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"failed to get port id for device id=%s" , p->device); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; } ret =rte_eth_dev_info_get (port, &dev_info);
@@ -476,7 +477,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"Error during getting device (port %u) info: %s" , port,strerror (-ret)); -return ret; + goto free_filter; }if (queue ==RTE_PDUMP_ALL_QUEUES ) {
@@ -485,25 +486,29 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)if (nb_rx_q ==0 && flags &RTE_PDUMP_FLAG_RX ) {PDUMP_LOG_LINE (ERR ,"number of rx queues cannot be 0" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }if (nb_tx_q ==0 && flags &RTE_PDUMP_FLAG_TX ) {PDUMP_LOG_LINE (ERR ,"number of tx queues cannot be 0" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }if ((nb_tx_q ==0 || nb_rx_q ==0 ) && flags ==RTE_PDUMP_FLAG_RXTX ) {PDUMP_LOG_LINE (ERR ,"both tx&rx queues must be non zero" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; } }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 ; + ret = -EINVAL ; + goto free_filter; } nb_rx_q = nb_tx_q = queue +1 ; }
@@ -512,12 +517,12 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)if (flags &RTE_PDUMP_FLAG_RX ) { ret =pdump_check_queues (port, queue, nb_rx_q, true, operation);if (ret <0 ) -return ret; + goto free_filter; }if (flags &RTE_PDUMP_FLAG_TX ) { ret =pdump_check_queues (port, queue, nb_tx_q, false, operation);if (ret <0 ) -return ret; + goto free_filter; }/* register RX callback */
@@ -557,6 +562,10 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) DISABLE, p->snaplen); } +free_filter: +if (filter !=NULL ) +rte_bpf_destroy (filter); +return ret; }
Signature · 1 line
2.53.0
PATCH v2 5/6 pdump: report secondary process failures
In reply to Stephen HemmingerThe primary broadcasts an enable to every secondary but ignored the replies, so a secondary that could not install its callbacks only logged the error. The client was told the enable succeeded and had no reason to clean up.
Return the first error from the replies. Disable the processes that did enable, so a failed request leaves nothing holding the ring.
--- lib/pdump/rte_pdump.c | 44 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-)
lib/pdump/rte_pdump.c +39 -5
@@ -569,12 +569,13 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)return ret; } -static void +static int pdump_request_to_secondary (const struct pdump_request *req) {struct rte_mp_msg mp_req = { };struct rte_mp_reply mp_reply;struct timespec ts = {.tv_sec =MP_TIMEOUT_S , .tv_nsec =0 }; +int ret =0 , i;PDUMP_LOG_LINE (DEBUG ,"forward req %s to secondary" ,pdump_opname (req->op));
@@ -582,14 +583,34 @@ pdump_request_to_secondary(const struct pdump_request *req)strlcpy (mp_req.name,PDUMP_MP ,sizeof (mp_req.name)); mp_req.len_param =sizeof (*req); -if (rte_mp_request_sync (&mp_req, &mp_reply, &ts) !=0 ) +if (rte_mp_request_sync (&mp_req, &mp_reply, &ts) !=0 ) {PDUMP_LOG_LINE (ERR ,"rte_mp_request_sync failed" ); +return -rte_errno; + } -else if (mp_reply.nb_sent != mp_reply.nb_received) +if (mp_reply.nb_sent != mp_reply.nb_received) {PDUMP_LOG_LINE (ERR ,"not all secondary's replied (sent %u recv %u)" , mp_reply.nb_sent, mp_reply.nb_received); + ret = -ETIMEDOUT ; + } + +/* Report the first failure, a secondary has already undone its own */ +for (i =0 ; i < mp_reply.nb_received; i++) { +const struct pdump_response *resp = + (const struct pdump_response *)mp_reply.msgs[i].param; + +if (resp->err_value !=0 ) { +PDUMP_LOG_LINE (ERR ,"secondary failed to %s: %s" , +pdump_opname (req->op), +rte_strerror (-resp->err_value)); +if (ret ==0 ) + ret = resp->err_value; + } + }free (mp_reply.msgs); + +return ret; }/* Allocate temporary storage for passing state to the alarm thread for deferred handling */
@@ -668,10 +689,23 @@ __pdump_request(void *param)PDUMP_LOG_LINE (DEBUG ,"primary pdump %s" ,pdump_opname (req->op)); ret =set_pdump_rxtx_cbs (req); +if (ret !=0 ) + goto respond;/* Primary process is responsible for broadcasting request to all secondaries */ -if (ret ==0 ) -pdump_request_to_secondary (req); + ret =pdump_request_to_secondary (req); + +/* Undo the processes that did enable, disable ignores the rest */ +if (ret !=0 && req->op ==ENABLE ) { +struct pdump_request undo = *req; + + undo.op =DISABLE ; + undo.prm =NULL ;/* no filter needed to remove callbacks */ +set_pdump_rxtx_cbs (&undo); +pdump_request_to_secondary (&undo); + } + +respond:pdump_send_response (req, ret, bundle->peer);free (bundle);
Signature · 1 line
2.53.0
PATCH v2 6/6 app/dumpcap: disable capture on the interface that failed
In reply to Stephen HemmingerThe unwind after a failed enable stopped at the interface that failed, so callbacks installed before the failure kept referencing the ring after dumpcap freed it.
Disable that interface as well. Promiscuous mode is left alone since it is only set after a successful enable.
--- app/dumpcap/main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
app/dumpcap/main.c +7 -3
@@ -852,12 +852,16 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp)if (ret <0 ) {const struct interface *intf2; -/* unwind any previous enables */ +/* +* Unwind this interface too, enable can fail after +* installing some callbacks. Promiscuous mode is +* not set on it yet. +*/ TAILQ_FOREACH(intf2, &interfaces, next) { -if (intf == intf2) -break ;rte_pdump_disable (intf2->port,RTE_PDUMP_ALL_QUEUES ,RTE_PDUMP_FLAG_RXTX ); +if (intf2 == intf) +break ;if (intf2->opts.promisc_mode)rte_eth_promiscuous_disable (intf2->port); }
Signature · 1 line
2.53.0
v3 cover pdump: fix error handling on failed enable
In reply to Stephen HemmingerPdump/dumpcap was not handling case of hairpin queues. Hairpin Tx queues were being flagged but not Rx queues.
This exposed other issues in MP request handling of missing callbacks and other leaks. The primary/secondary IPC needs to be able to handle when secondary has not registered and when a secondary tries to request something primary can't do.
v3 - needed more complete and robust MP state machine in EAL
- verify request rather than complexity of unwinding
Stephen Hemminger (8):
ethdev: reject hairpin queue in add first Rx callback
pdump: fix error code when adding callback fails
pdump: validate queues before installing callbacks
pdump: release BPF filter on error
eal: fix IPC request when no handler is registered test/mp: check request with no registered handler
pdump: report secondary process failures test/pdump: check secondary process result
app/test/test_mp_secondary.c | 85 ++++++++- app/test/test_pdump.c | 15 +- lib/eal/common/eal_common_proc.c | 55 ++++-- lib/ethdev/rte_ethdev.c | 5 + lib/pdump/rte_pdump.c | 306 ++++++++++++++++++++++++------- 5 files changed, 382 insertions(+), 84 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/8 ethdev: reject hairpin queue in add first Rx callback
rte_eth_add_rx_callback() and rte_eth_add_tx_callback() refuse hairpin queues, but rte_eth_add_first_rx_callback() was missed. A callback installed on a hairpin queue is never invoked.
--- lib/ethdev/rte_ethdev.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/ethdev/rte_ethdev.c +5 -0
@@ -6234,6 +6234,11 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,return NULL ; } +if (rte_eth_dev_is_rx_hairpin_queue (&rte_eth_devices[port_id], queue_id)) { + rte_errno =EINVAL ; +return NULL ; + } +struct rte_eth_rxtx_callback *cb =rte_zmalloc (NULL ,sizeof (*cb),0 );if (cb ==NULL ) {
Signature · 1 line
2.53.0
PATCH v3 2/8 pdump: fix error code when adding callback fails
In reply to Stephen HemmingerThe register functions returned positive rte_errno on failure. The caller only checks for negative values, so a failed Rx enable fell through to Tx, and the positive value sent back to the client was negated into rte_errno, giving messages like "Unknown error -22".
--- lib/pdump/rte_pdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/pdump/rte_pdump.c +2 -2
@@ -283,7 +283,7 @@ pdump_register_rx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add rx callback, errno=%d" , rte_errno); -return rte_errno; +return -rte_errno; }memset (&pdump_stats->rx[port][qid],0 ,sizeof (struct rte_pdump_stats ));
@@ -345,7 +345,7 @@ pdump_register_tx_callbacks(enum pdump_version ver,PDUMP_LOG_LINE (ERR ,"failed to add tx callback, errno=%d" , rte_errno); -return rte_errno; +return -rte_errno; }memset (&pdump_stats->tx[port][qid],0 ,sizeof (struct rte_pdump_stats )); }else if (operation ==DISABLE ) {
Signature · 1 line
2.53.0
PATCH v3 3/8 pdump: validate queues before installing callbacks
In reply to Stephen HemmingerCheck 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
--- lib/pdump/rte_pdump.c | 209 ++++++++++++++++++++++++++++++++---------- 1 file changed, 162 insertions(+), 47 deletions(-)
lib/pdump/rte_pdump.c +162 -47
@@ -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;
Signature · 1 line
2.53.0
PATCH v3 4/8 pdump: release BPF filter on error
In reply to Stephen HemmingerThe BPF filter loaded for a request was leaked if the request failed. A successful enable keeps it, the callbacks reference it.
--- lib/pdump/rte_pdump.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
lib/pdump/rte_pdump.c +19 -9
@@ -486,7 +486,8 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"failed to get port id for device id=%s" , p->device); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; } ret =rte_eth_dev_info_get (port, &dev_info);
@@ -494,7 +495,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"Error during getting device (port %u) info: %s" , port,strerror (-ret)); -return ret; + goto free_filter; }if (queue ==RTE_PDUMP_ALL_QUEUES ) {
@@ -503,25 +504,29 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)if (nb_rx_q ==0 && flags &RTE_PDUMP_FLAG_RX ) {PDUMP_LOG_LINE (ERR ,"number of rx queues cannot be 0" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }if (nb_tx_q ==0 && flags &RTE_PDUMP_FLAG_TX ) {PDUMP_LOG_LINE (ERR ,"number of tx queues cannot be 0" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }if ((nb_tx_q ==0 || nb_rx_q ==0 ) && flags ==RTE_PDUMP_FLAG_RXTX ) {PDUMP_LOG_LINE (ERR ,"both tx&rx queues must be non zero" ); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; } }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 ; + ret = -EINVAL ; + goto free_filter; } nb_rx_q = nb_tx_q = queue +1 ; }
@@ -531,13 +536,13 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)if (flags &RTE_PDUMP_FLAG_RX ) { ret =pdump_check_queues (port, queue, nb_rx_q, true, operation);if (ret <0 ) -return ret; + goto free_filter; 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; + goto free_filter; nb_queues += ret; }
@@ -549,7 +554,8 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)if (nb_queues ==0 && operation ==ENABLE ) {PDUMP_LOG_LINE (ERR ,"no queue available to capture on port=%u" , port); -return -EINVAL ; + ret = -EINVAL ; + goto free_filter; }/* register RX callback */
@@ -589,6 +595,10 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) DISABLE, p->snaplen); } +free_filter: +if (filter !=NULL ) +rte_bpf_destroy (filter); +return ret; }
Signature · 1 line
2.53.0
PATCH v3 5/8 eal: fix IPC request when no handler is registered
In reply to Stephen HemmingerA process only answers an IPC request if it registered an action for that name. When no action is found the request is dropped silently unless EAL init is still in progress, so the requester waits for the full timeout and then sees ETIMEDOUT.
This is what happens when a primary broadcasts a pdump request and any secondary did not call rte_pdump_init() then the primary would wait for timeout on response. The secondary should just respond with MP_IGN.
When secondary sends a request to primary that has not registered an action, then the primary needs to respond to secondary with new reply MP_ERR indicating that this action is not supported.
A secondary request to a primary that is still initializing now fails with ENOTSUP. Before it got MP_IGN and the request returned success with no replies. Waiting is not an option since there is no way to know whether the primary will ever register that action.
The async path counts an MP_ERR as processed so the callback still runs. No in tree user can reach that case today, since the only async requests go from secondary to primary, but rte_mp_request_async is public and dropping the reply would leave its callback pending.
--- lib/eal/common/eal_common_proc.c | 55 ++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 20 deletions(-)
lib/eal/common/eal_common_proc.c +35 -20
@@ -32,7 +32,6 @@#include "eal_memcfg.h" #include "eal_private.h" #include "eal_filesystem.h" -#include "eal_internal_cfg.h" static RTE_ATOMIC (int ) mp_fd =-1 ;static rte_thread_t mp_handle_tid;
@@ -58,6 +57,7 @@ enum mp_type {MP_REQ ,/* Request for information, Will block for a reply */ MP_REP ,/* Response to previously-received request */ MP_IGN ,/* Response telling requester to ignore this response */ + MP_ERR, /* Response telling requester that request not handled */ };/* Message sent from primary EAL to secondary EAL */
@@ -357,25 +357,27 @@ cleanup_msg_fds(const struct rte_mp_msg *msg)static void process_msg (struct mp_msg_internal *m,struct sockaddr_un *s) { -struct pending_request *pending_req;struct action_entry *entry;struct rte_mp_msg *msg = &m->msg;rte_mp_t action =NULL ; -const struct internal_config *internal_conf = -eal_get_internal_configuration ();EAL_LOG (DEBUG ,"msg: %s" , msg->name); -if (m->type ==MP_REP || m->type ==MP_IGN ) { +if (m->type ==MP_REP || m->type ==MP_IGN || m->type ==MP_ERR ) { +struct pending_request *pending_req;struct pending_request *req =NULL ;pthread_mutex_lock (&pending_requests.lock); pending_req =find_request_by_name (s->sun_path, msg->name);if (pending_req) {memcpy (pending_req->reply, msg,sizeof (*msg)); -/* -1 indicates that we've been asked to ignore */ - pending_req->reply_received = - m->type ==MP_REP ?1 :-1 ; + +if (m->type ==MP_REP ) + pending_req->reply_received =1 ; +else if (m->type ==MP_IGN ) + pending_req->reply_received =-1 ; +else /* MP_ERR */ + pending_req->reply_received =-2 ;if (pending_req->type ==REQUEST_TYPE_SYNC )pthread_cond_signal (&pending_req->sync.cond);
@@ -398,18 +400,20 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s) action = entry->action;pthread_mutex_unlock (&mp_mutex_action); -if (!action) { -if (m->type ==MP_REQ && !internal_conf->init_complete) { -/* if this is a request, and init is not yet complete, -* and callback wasn't registered, we should tell the -* requester to ignore our existence because we're not -* yet ready to process this request. +if (action ==NULL ) { +if (m->type ==MP_REQ ) { +/* +* No handler is registered, either because init is not +* complete or because this process does not use the +* feature. A secondary only gets broadcasts from the +* primary and can ignore them. A primary must tell the +* requester it is unsupported. */ -struct rte_mp_msg dummy; +struct rte_mp_msg dummy = {0 }; -memset (&dummy,0 ,sizeof (dummy));strlcpy (dummy.name, msg->name,sizeof (dummy.name)); -mp_send (&dummy, s->sun_path,MP_IGN ); +mp_send (&dummy, s->sun_path, +rte_eal_process_type () ==RTE_PROC_PRIMARY ?MP_ERR :MP_IGN ); }else {EAL_LOG (ERR ,"Cannot find action: %s" , msg->name);
@@ -501,6 +505,13 @@ process_async_request(struct pending_request *sr, const struct timespec *now) }else if (sr->reply_received ==-1 ) {/* we were asked to ignore this process */ reply->nb_sent--; + }else if (sr->reply_received ==-2 ) { +/* +* peer has no handler for this request. Count it as +* processed so the callback still runs, but not as +* received since there is no reply to pass up. +*/ + param->n_responses_processed++; }else if (timeout) {/* count it as processed response, but don't increment * nb_received.
@@ -1019,19 +1030,23 @@ mp_request_sync(const char *dst, struct rte_mp_msg *req,TAILQ_REMOVE (&pending_requests.requests, &pending_req, next); -if (pending_req.reply_received ==0 ) { +switch (pending_req.reply_received) { +case 0 :EAL_LOG (ERR ,"Fail to recv reply for request %s:%s" , dst, req->name); rte_errno =ETIMEDOUT ;return -1 ; - } -if (pending_req.reply_received ==-1 ) { +case -1 :EAL_LOG (DEBUG ,"Asked to ignore response" );/* not receiving this message is not an error, so decrement * number of sent messages */ reply->nb_sent--;return 0 ; +case -2 : +EAL_LOG (DEBUG ,"Request not supported" ); + rte_errno =ENOTSUP ; +return -1 ; } tmp =realloc (reply->msgs,sizeof (msg) * (reply->nb_received +1 ));
Signature · 1 line
2.53.0
PATCH v3 6/8 test/mp: check request with no registered handler
In reply to Stephen HemmingerAdd coverage for requests the peer has no action for. The secondary asks the primary for an action nobody registered and checks that the call fails with ENOTSUP rather than blocking until the timeout.
The async form of the same request is checked as well. Its callback has to run even though no reply comes back, reporting the request as sent and nothing received.
The MP_IGN direction is not covered here. That needs a primary broadcasting to a secondary which did not register the action, and the test primary is blocked waiting for the secondary to exit.
--- app/test/test_mp_secondary.c | 85 +++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-)
app/test/test_mp_secondary.c +84 -1
@@ -53,6 +53,7 @@ test_mp_secondary(void)#endif /* RTE_LIB_LPM */ #include <rte_string_fns.h> +#include <rte_cycles.h> #include "process.h"
@@ -197,6 +198,85 @@ run_object_creation_tests(void)return 0 ; } +#define NO_SUCH_ACTION "test_mp_no_action" +#define MP_WAIT_S 5 + +static int async_replied; +static int async_nb_sent; +static int async_nb_received; + +static int +unsupported_async_reply(const struct rte_mp_msg *request __rte_unused, +const struct rte_mp_reply *reply) +{ + async_nb_sent = reply->nb_sent; + async_nb_received = reply->nb_received; + async_replied =1 ; +return 0 ; +} + +/* +* Run in the secondary to check requests the primary has no handler for. +* The primary answers MP_ERR, so the request fails right away instead of +* waiting for the timeout. +*/ +static int +run_unsupported_request_tests (void ) +{ +struct timespec ts = { .tv_sec =MP_WAIT_S , .tv_nsec =0 }; +struct rte_mp_msg msg = { .len_param =0 , .num_fds =0 }; +struct rte_mp_reply reply = { }; +time_t start; +int ret; + +printf ("### Testing request with no handler in primary:\n" ); + +strlcpy (msg.name,NO_SUCH_ACTION ,sizeof (msg.name)); + + start =time (NULL ); + ret =rte_mp_request_sync (&msg, &reply, &ts); +if (ret ==0 || rte_errno !=ENOTSUP ) { +printf ("Error: rte_mp_request_sync() returned %d errno %d, expected -1/ENOTSUP\n" , + ret, rte_errno); +free (reply.msgs); +return -1 ; + } +/* a dropped request would have cost the full timeout */ +if (time (NULL ) - start >=MP_WAIT_S ) { +printf ("Error: rte_mp_request_sync() waited for the timeout\n" ); +return -1 ; + } +printf ("# Checked rte_mp_request_sync() returns ENOTSUP\n" ); + + async_replied =0 ; +if (rte_mp_request_async (&msg, &ts, unsupported_async_reply) !=0 ) { +printf ("Error: rte_mp_request_async() failed: %s\n" , +rte_strerror (rte_errno)); +return -1 ; + } + +/* the callback runs on the interrupt thread */ +for (int i =0 ; i <MP_WAIT_S *10 && !async_replied; i++) +rte_delay_ms (100 ); + +if (!async_replied) { +printf ("Error: rte_mp_request_async() callback never ran\n" ); +return -1 ; + } +/* +* The request was sent and answered with an error, so the callback +* must see it as sent but carrying no reply. +*/ +if (async_nb_sent !=1 || async_nb_received !=0 ) { +printf ("Error: async reply sent %d received %d, expected 1/0\n" , + async_nb_sent, async_nb_received); +return -1 ; + } +printf ("# Checked rte_mp_request_async() callback runs with no reply\n" ); + +return 0 ; +} +/* if called in a primary process, just spawns off a secondary process to * run validation tests - which brings us right back here again... * if called in a secondary process, this runs a series of API tests to check
@@ -211,7 +291,10 @@ test_mp_secondary(void)printf ("IN SECONDARY PROCESS\n" ); - return run_object_creation_tests(); +if (run_object_creation_tests () <0 ) +return -1 ; + + return run_unsupported_request_tests(); }#endif /* !RTE_EXEC_ENV_WINDOWS */
Signature · 1 line
2.53.0
PATCH v3 7/8 pdump: report secondary process failures
In reply to Stephen HemmingerThe primary broadcasts an enable to every secondary but ignored the replies, so a secondary that could not install its callbacks only logged the error. The client was told the enable succeeded and had no reason to clean up.
Return the first error from the enable replies. Disable the processes that did enable, so a failed request leaves nothing holding the ring. The undo carries the request's ring, so it only removes the callbacks that this request installed, and a secondary with none left is not an error.
A secondary need not own every port. Report a missing port as ENODEV and let the secondary handler treat that as nothing to do, otherwise a process started with a different set of devices would fail the enable for the processes that did install callbacks.
The client has to wait longer than the primary can take, which is the enable broadcast plus the undo broadcast.
A disable reply is not propagated. The primary has already removed its own callbacks and a secondary started after the enable never had any.
This depends on the IPC change earlier in this series. Without it a secondary that never called rte_pdump_init() does not reply at all, the broadcast times out, and every enable fails. Both patches have to be backported together.
--- lib/pdump/rte_pdump.c | 85 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 14 deletions(-)
lib/pdump/rte_pdump.c +71 -14
@@ -261,7 +261,7 @@ pdump_tx(uint16_t port, uint16_t queue,*/ static int pdump_check_queues (uint16_t port,uint16_t queue,uint16_t end_q, -bool rx,uint16_t operation) +bool rx,uint16_t operation,const struct rte_ring *ring) {struct rte_eth_dev *dev = &rte_eth_devices[port];bool all = queue ==RTE_PDUMP_ALL_QUEUES ;
@@ -297,7 +297,11 @@ pdump_check_queues(uint16_t port, uint16_t queue, uint16_t end_q,return -EEXIST ; }if (operation ==DISABLE && cbs->cb ==NULL ) { -if (all) +/* +* An undo carries the ring of the failed request and +* only has to remove what that request installed. +*/ +if (all || ring !=NULL )continue ; PDUMP_LOG_LINE(ERR, "no existing %s callback for port=%u queue=%u",
@@ -486,7 +490,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)PDUMP_LOG_LINE (ERR ,"failed to get port id for device id=%s" , p->device); - ret = -EINVAL ; + ret = -ENODEV ; goto free_filter; }
@@ -534,13 +538,13 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)/* 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); + ret =pdump_check_queues (port, queue, nb_rx_q, true, operation, ring);if (ret <0 ) goto free_filter; nb_queues += ret; }if (flags &RTE_PDUMP_FLAG_TX ) { - ret =pdump_check_queues (port, queue, nb_tx_q, false, operation); + ret =pdump_check_queues (port, queue, nb_tx_q, false, operation, ring);if (ret <0 ) goto free_filter; nb_queues += ret;
@@ -602,12 +606,13 @@ set_pdump_rxtx_cbs(const struct pdump_request *p)return ret; } -static void +static int pdump_request_to_secondary (const struct pdump_request *req) {struct rte_mp_msg mp_req = { };struct rte_mp_reply mp_reply;struct timespec ts = {.tv_sec =MP_TIMEOUT_S , .tv_nsec =0 }; +int ret =0 , i;PDUMP_LOG_LINE (DEBUG ,"forward req %s to secondary" ,pdump_opname (req->op));
@@ -615,14 +620,34 @@ pdump_request_to_secondary(const struct pdump_request *req)strlcpy (mp_req.name,PDUMP_MP ,sizeof (mp_req.name)); mp_req.len_param =sizeof (*req); -if (rte_mp_request_sync (&mp_req, &mp_reply, &ts) !=0 ) -PDUMP_LOG_LINE (ERR ,"rte_mp_request_sync failed" ); +if (rte_mp_request_sync (&mp_req, &mp_reply, &ts) !=0 ) { +PDUMP_LOG_LINE (ERR ,"rte_mp_request_sync failed: %s" , +rte_strerror (rte_errno)); +return -rte_errno; + } -else if (mp_reply.nb_sent != mp_reply.nb_received) -PDUMP_LOG_LINE (ERR ,"not all secondary's replied (sent %u recv %u)" , - mp_reply.nb_sent, mp_reply.nb_received); +/* +* A secondary that failed has already undone its own callbacks. +* A process without pdump registered is skipped by the IPC layer +* rather than counted as a reply, so every reply here is from a +* process that ran the request. +*/ +for (i =0 ; i < mp_reply.nb_received; i++) { +const struct pdump_response *resp = + (const struct pdump_response *)mp_reply.msgs[i].param; + +if (resp->err_value !=0 ) { +PDUMP_LOG_LINE (ERR ,"secondary failed to %s: %s" , +pdump_opname (req->op), +rte_strerror (-resp->err_value)); +if (ret ==0 ) + ret = resp->err_value; + } + }free (mp_reply.msgs); + +return ret; }/* Allocate temporary storage for passing state to the alarm thread for deferred handling */
@@ -682,6 +707,17 @@ pdump_handle_primary_request(const struct rte_mp_msg *mp_msg, const void *peer)/* Can just do it now, no need for interrupt thread */ ret =set_pdump_rxtx_cbs (req); + +/* +* Not every secondary owns every port. A process that does +* not have this one has nothing to install and must not fail +* the request for the processes that do. +*/ +if (ret == -ENODEV ) { +PDUMP_LOG_LINE (DEBUG ,"port %s not present, nothing to do" , + req->device); + ret =0 ; + } }return pdump_send_response (req, ret, peer);
@@ -701,10 +737,30 @@ __pdump_request(void *param)PDUMP_LOG_LINE (DEBUG ,"primary pdump %s" ,pdump_opname (req->op)); ret =set_pdump_rxtx_cbs (req); +if (ret !=0 ) + goto respond;/* Primary process is responsible for broadcasting request to all secondaries */ -if (ret ==0 ) -pdump_request_to_secondary (req); + ret =pdump_request_to_secondary (req); + +if (req->op !=ENABLE ) { +/* +* The primary already removed its callbacks. A secondary +* started after the enable never had any, so its failure +* does not mean the capture is still live. +*/ + ret =0 ; + }else if (ret !=0 ) { +/* Undo the processes that did enable, the rest have nothing */ +struct pdump_request undo = *req; + + undo.op =DISABLE ; + undo.prm =NULL ;/* no filter needed to remove callbacks */ +set_pdump_rxtx_cbs (&undo); +pdump_request_to_secondary (&undo); + } + +respond:pdump_send_response (req, ret, bundle->peer);free (bundle);
@@ -883,7 +939,8 @@ pdump_prepare_client_request(const char *device, uint16_t queue,int ret =-1 ;struct rte_mp_msg mp_req, *mp_rep;struct rte_mp_reply mp_reply; -struct timespec ts = {.tv_sec =MP_TIMEOUT_S , .tv_nsec =0 }; +/* the primary may broadcast an enable and then an undo */ +struct timespec ts = {.tv_sec =2 *MP_TIMEOUT_S +1 , .tv_nsec =0 };struct pdump_request *req = (struct pdump_request *)mp_req.param;struct pdump_response *resp;
Signature · 1 line
2.53.0
PATCH v3 8/8 test/pdump: check secondary process result
In reply to Stephen HemmingerThe test passed even when the secondary failed every pdump call. process_dup() returns the raw status from wait(), which is positive on failure, but the caller folded it in with ret |= and test_pdump() only treats a negative value as an error.
The client secondary also never called rte_pdump_init(), so it had no IPC handler for the requests the primary sends it.
Check the launched process for any non-zero status, and initialize pdump in the client so the enable and disable paths are actually exercised in the secondary.
--- app/test/test_pdump.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
app/test/test_pdump.c +14 -1
@@ -56,6 +56,12 @@ run_pdump_client_tests(void)struct rte_eth_dev *eth_dev =NULL ;char poolname[] ="mbuf_pool_client" ; + ret =rte_pdump_init (); +if (ret <0 ) { +printf ("rte_pdump_init failed\n" ); +return -1 ; + } + ret =test_get_mempool (&mp, poolname);if (ret <0 )return -1 ;
@@ -119,6 +125,11 @@ run_pdump_client_tests(void)if (mp !=NULL )test_mp_free (mp); +if (rte_pdump_uninit () <0 ) { +printf ("rte_pdump_uninit failed\n" ); +return -1 ; + } +return ret; }
@@ -192,7 +203,9 @@ run_pdump_server_tests(void)snprintf (core_str,sizeof (core_str),"%u" ,rte_get_main_lcore ()); ret =test_pdump_init (); - ret |=launch_p (argv1); +/* process_dup() returns the raw wait() status, not a negative errno */ +if (launch_p (argv1) !=0 ) + ret =-1 ; ret |=test_pdump_uninit ();return ret; }
Signature · 1 line
2.53.0