DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dengdui Huang <huangdengdui@huawei.com>
To: <dev@dpdk.org>
Cc: <lihuisong@huawei.com>, <liuyonglong@huawei.com>
Subject: [PATCH] app/testpmd: fix segment fault with invalid queue id
Date: Tue, 16 May 2023 19:00:21 +0800	[thread overview]
Message-ID: <20230516110021.1801443-1-huangdengdui@huawei.com> (raw)

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

dpdk-testpmd -a 0000:01:00.0 -- -i
testpmd> show port 0 rxq 99 desc used count
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 7b20bef4e9..624752c320 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -12273,14 +12273,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) {
@@ -12296,6 +12309,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) {
@@ -12373,10 +12402,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


             reply	other threads:[~2023-05-16 12:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 11:00 Dengdui Huang [this message]
2023-05-16 15:12 ` Stephen Hemminger
2023-05-19 10:18   ` huangdengdui
2023-05-22 13:09 ` [PATCH v2 0/2] add API and use it to fix a bug Dengdui Huang
2023-05-22 13:09   ` [PATCH v2 1/2] ethdev: add API to check queue ID validity Dengdui Huang
2023-05-22 13:58     ` Andrew Rybchenko
2023-05-24  7:38       ` huangdengdui
2023-05-24  9:03         ` Andrew Rybchenko
2023-05-31 16:31       ` Ferruh Yigit
2023-06-01 22:13         ` Ferruh Yigit
2023-06-02  1:36           ` huangdengdui
2023-05-22 13:09   ` [PATCH v2 2/2] app/testpmd: fix segment fault with invalid queue id Dengdui Huang
2023-05-25  7:03 ` [PATCH v3 0/2] add Rx/Tx queue ID check API and use it to fix a bug Dengdui Huang
2023-05-25  7:03   ` [PATCH v3 1/2] ethdev: add API to check if queue is available Dengdui Huang
2023-05-25  7:03   ` [PATCH v3 2/2] app/testpmd: fix segment fault with invalid queue ID Dengdui Huang
2023-06-02  7:52 ` [PATCH v4 0/2] add Rx/Tx queue ID check API and use it to fix a bug Dengdui Huang
2023-06-02  7:52   ` [PATCH v4 1/2] ethdev: add API to check if queue is valid Dengdui Huang
2023-06-02 12:47     ` Ferruh Yigit
2023-06-05  1:24       ` huangdengdui
2023-06-02  7:52   ` [PATCH v4 2/2] app/testpmd: fix segment fault with invalid queue ID Dengdui Huang
2023-06-02 12:47     ` Ferruh Yigit
2023-06-05  2:27 ` [PATCH v5 0/2] add Rx/Tx queue ID check API and use it to fix a bug Dengdui Huang
2023-06-05  2:27   ` [PATCH v5 1/2] ethdev: add API to check if queue is valid Dengdui Huang
2023-06-06  9:06     ` Ferruh Yigit
2023-06-05  2:27   ` [PATCH v5 2/2] app/testpmd: fix segment fault with invalid queue ID Dengdui Huang
2023-06-06  9:07   ` [PATCH v5 0/2] add Rx/Tx queue ID check API and use it to fix a bug Ferruh Yigit

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=20230516110021.1801443-1-huangdengdui@huawei.com \
    --to=huangdengdui@huawei.com \
    --cc=dev@dpdk.org \
    --cc=lihuisong@huawei.com \
    --cc=liuyonglong@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).