From patchwork Tue May 16 11:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huangdengdui X-Patchwork-Id: 126885 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B9BCD42B22; Tue, 16 May 2023 14:03:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5DFA6410EE; Tue, 16 May 2023 14:03:10 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id C21F54068E for ; Tue, 16 May 2023 13:00:24 +0200 (CEST) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QLCrv0fjHzsS47 for ; Tue, 16 May 2023 18:58:23 +0800 (CST) Received: from localhost.huawei.com (10.50.163.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 16 May 2023 19:00:21 +0800 From: Dengdui Huang To: CC: , Subject: [PATCH] app/testpmd: fix segment fault with invalid queue id Date: Tue, 16 May 2023 19:00:21 +0800 Message-ID: <20230516110021.1801443-1-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500011.china.huawei.com (7.185.36.84) X-CFilter-Loop: Reflected X-Mailman-Approved-At: Tue, 16 May 2023 14:03:09 +0200 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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; } From patchwork Mon May 22 13:09:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huangdengdui X-Patchwork-Id: 127163 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7E7A242B71; Mon, 22 May 2023 15:09:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 553F4410D7; Mon, 22 May 2023 15:09:52 +0200 (CEST) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 10A9340EE5 for ; Mon, 22 May 2023 15:09:50 +0200 (CEST) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QPyNd4RNfz18LXR; Mon, 22 May 2023 21:05:21 +0800 (CST) Received: from localhost.huawei.com (10.50.163.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 22 May 2023 21:09:48 +0800 From: Dengdui Huang To: CC: , , , , , , , , , Subject: [PATCH v2 2/2] app/testpmd: fix segment fault with invalid queue id Date: Mon, 22 May 2023 21:09:47 +0800 Message-ID: <20230522130947.345390-3-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230522130947.345390-1-huangdengdui@huawei.com> References: <20230516110021.1801443-1-huangdengdui@huawei.com> <20230522130947.345390-1-huangdengdui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500011.china.huawei.com (7.185.36.84) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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. 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 --- app/test-pmd/cmdline.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 7b20bef4e9..334434497c 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -12275,12 +12275,13 @@ cmd_show_rx_tx_desc_status_parsed(void *parsed_result, struct cmd_show_rx_tx_desc_status_result *res = parsed_result; 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_dev_is_valid_rxq(res->cmd_pid, res->cmd_qid) != 0) { + fprintf(stderr, + "Invalid input: port id = %d, queue id = %d\n", + res->cmd_pid, res->cmd_qid); + return; + } rc = rte_eth_rx_descriptor_status(res->cmd_pid, res->cmd_qid, res->cmd_did); if (rc < 0) { @@ -12296,6 +12297,12 @@ 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_dev_is_valid_txq(res->cmd_pid, res->cmd_qid) != 0) { + fprintf(stderr, + "Invalid input: port id = %d, queue id = %d\n", + res->cmd_pid, res->cmd_qid); + return; + } rc = rte_eth_tx_descriptor_status(res->cmd_pid, res->cmd_qid, res->cmd_did); if (rc < 0) { @@ -12375,8 +12382,10 @@ cmd_show_rx_queue_desc_used_count_parsed(void *parsed_result, struct cmd_show_rx_queue_desc_used_count_result *res = parsed_result; 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_dev_is_valid_rxq(res->cmd_pid, res->cmd_qid) != 0) { + fprintf(stderr, + "Invalid input: port id = %d, queue id = %d\n", + res->cmd_pid, res->cmd_qid); return; }