patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH] app/testpmd: fix segment fault with invalid queue id
@ 2023-05-15 10:46 Dengdui Huang
  0 siblings, 0 replies; only message in thread
From: Dengdui Huang @ 2023-05-15 10:46 UTC (permalink / raw)
  To: huangdengdui; +Cc: stable

When input queue id is invalid, it will lead to
Segmentation fault, like:

dpdk-testpmd -a 0000:01:00.0 -- -i
testpmd> show port 0 txq/rxq 99 desc 0 status
Segmentation fault

This patch fixes it.

In addition, this patch add the check for the offset
of the descriptor in case of other anomalies.

Fixes: fae9aa717d6c ("app/testpmd: support checking descriptor status")
Fixes: 3f9acb5c83bb ("ethdev: avoid non-dataplane checks in Rx queue count")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 app/test-pmd/cmdline.c | 50 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 89cb00ecdc..2144434449 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -12255,14 +12255,27 @@ cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
 		__rte_unused void *data)
 {
 	struct cmd_show_rx_tx_desc_status_result *res = parsed_result;
+	struct rte_eth_rxq_info rxq_info;
+	struct rte_eth_txq_info txq_info;
 	int rc;
 
-	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
-		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
-		return;
-	}
-
 	if (!strcmp(res->cmd_keyword, "rxq")) {
+		if (rte_eth_rx_queue_info_get(res->cmd_pid, res->cmd_qid, &rxq_info)) {
+			fprintf(stderr, "Failed to get port %u Rx queue %u info\n",
+				res->cmd_pid, res->cmd_qid);
+			return;
+		}
+
+		if (rxq_info.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
+			fprintf(stderr, "Rx queue %u not started\n", res->cmd_qid);
+			return;
+		}
+
+		if (res->cmd_did >= rxq_info.nb_desc) {
+			fprintf(stderr, "Invalid desc id %u\n", res->cmd_did);
+			return;
+		}
+
 		rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid,
 					     res->cmd_did);
 		if (rc < 0) {
@@ -12278,6 +12291,22 @@ cmd_show_rx_tx_desc_status_parsed(void *parsed_result,
 		else
 			printf("Desc status = UNAVAILABLE\n");
 	} else if (!strcmp(res->cmd_keyword, "txq")) {
+		if (rte_eth_tx_queue_info_get(res->cmd_pid, res->cmd_qid, &txq_info)) {
+			fprintf(stderr, "Failed to get port %u Tx queue %u info\n",
+				res->cmd_pid, res->cmd_qid);
+			return;
+		}
+
+		if (txq_info.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
+			fprintf(stderr, "Tx queue %u not started\n", res->cmd_qid);
+			return;
+		}
+
+		if (res->cmd_did >= txq_info.nb_desc) {
+			fprintf(stderr, "Invalid desc id %u\n", res->cmd_did);
+			return;
+		}
+
 		rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid,
 					     res->cmd_did);
 		if (rc < 0) {
@@ -12355,10 +12384,17 @@ cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result,
 		__rte_unused void *data)
 {
 	struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result;
+	struct rte_eth_rxq_info rxq_info;
 	int rc;
 
-	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
-		fprintf(stderr, "invalid port id %u\n", res->cmd_pid);
+	if (rte_eth_rx_queue_info_get(res->cmd_pid, res->cmd_qid, &rxq_info)) {
+		fprintf(stderr, "Failed to get port %u Rx queue %u info\n",
+			res->cmd_pid, res->cmd_qid);
+		return;
+	}
+
+	if (rxq_info.queue_state != RTE_ETH_QUEUE_STATE_STARTED) {
+		fprintf(stderr, "Rx queue %u not started\n", res->cmd_qid);
 		return;
 	}
 
-- 
2.33.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-15 11:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15 10:46 [PATCH] app/testpmd: fix segment fault with invalid queue id Dengdui Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).