From patchwork Thu May 25 07:03:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dengdui Huang X-Patchwork-Id: 127368 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 89E6042B95; Thu, 25 May 2023 09:03:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 41FD842670; Thu, 25 May 2023 09:03:12 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 756FD40DF8 for ; Thu, 25 May 2023 09:03:08 +0200 (CEST) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QRf600L46zqTQh; Thu, 25 May 2023 14:58:32 +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; Thu, 25 May 2023 15:03:03 +0800 From: Dengdui Huang To: CC: , , , , , , , , , Subject: [PATCH v3 1/2] ethdev: add API to check if queue is available Date: Thu, 25 May 2023 15:03:01 +0800 Message-ID: <20230525070302.3745541-2-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230525070302.3745541-1-huangdengdui@huawei.com> References: <20230516110021.1801443-1-huangdengdui@huawei.com> <20230525070302.3745541-1-huangdengdui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 The API rte_eth_dev_rxq/txq_avail which is used to check if Rx/Tx queue is available. Signed-off-by: Dengdui Huang --- doc/guides/rel_notes/release_23_07.rst | 6 +++++ lib/ethdev/rte_ethdev.c | 22 ++++++++++++++++ lib/ethdev/rte_ethdev.h | 36 ++++++++++++++++++++++++++ lib/ethdev/version.map | 4 +++ 4 files changed, 68 insertions(+) diff --git a/doc/guides/rel_notes/release_23_07.rst b/doc/guides/rel_notes/release_23_07.rst index a9b1293689..399fe342db 100644 --- a/doc/guides/rel_notes/release_23_07.rst +++ b/doc/guides/rel_notes/release_23_07.rst @@ -56,6 +56,12 @@ New Features ======================================================= +* **Added ethdev Rx/Tx queue ID check API.** + + Added ethdev Rx/Tx queue ID check API which provides functions + for check if Rx/Tx queue is available. + + Removed Items ------------- diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 4d03255683..5534bcce23 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -771,6 +771,28 @@ eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id) return 0; } +int +rte_eth_dev_rxq_avail(uint16_t port_id, uint16_t queue_id) +{ + struct rte_eth_dev *dev; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + dev = &rte_eth_devices[port_id]; + + return eth_dev_validate_rx_queue(dev, queue_id); +} + +int +rte_eth_dev_txq_avail(uint16_t port_id, uint16_t queue_id) +{ + struct rte_eth_dev *dev; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + dev = &rte_eth_devices[port_id]; + + return eth_dev_validate_tx_queue(dev, queue_id); +} + int rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id) { diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 99fe9e238b..13b71f75f3 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -2665,6 +2665,42 @@ int rte_eth_dev_socket_id(uint16_t port_id); */ int rte_eth_dev_is_valid_port(uint16_t port_id); +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Check if Rx queue is available. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param queue_id + * The index of the receive queue. + * @return + * - -ENODEV: if *port_id* is invalid. + * - -EINVAL: if queue is out of range or not been setup. + * - 0 if Rx queue is available. + */ +__rte_experimental +int rte_eth_dev_rxq_avail(uint16_t port_id, uint16_t queue_id); + +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Check if Tx queue is available. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param queue_id + * The index of the transmit queue. + * @return + * - -ENODEV: if *port_id* is invalid. + * - -EINVAL: if queue is out of range or not been setup. + * - 0 if Tx queue is available. + */ +__rte_experimental +int rte_eth_dev_txq_avail(uint16_t port_id, uint16_t queue_id); + /** * Start specified Rx queue of a port. It is used when rx_deferred_start * flag of the specified queue is true. diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 357d1a88c0..4b51f821cb 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -299,6 +299,10 @@ EXPERIMENTAL { rte_flow_action_handle_query_update; rte_flow_async_action_handle_query_update; rte_flow_async_create_by_index; + + # added in 23.07 + rte_eth_dev_rxq_avail; + rte_eth_dev_txq_avail; }; INTERNAL { From patchwork Thu May 25 07:03:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dengdui Huang X-Patchwork-Id: 127367 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 7B94942B95; Thu, 25 May 2023 09:03:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 25027410DC; Thu, 25 May 2023 09:03:11 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 7002C40DDB for ; Thu, 25 May 2023 09:03:08 +0200 (CEST) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QRf7p57W1zLptm; Thu, 25 May 2023 15:00:06 +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; Thu, 25 May 2023 15:03:03 +0800 From: Dengdui Huang To: CC: , , , , , , , , , Subject: [PATCH v3 2/2] app/testpmd: fix segment fault with invalid queue ID Date: Thu, 25 May 2023 15:03:02 +0800 Message-ID: <20230525070302.3745541-3-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230525070302.3745541-1-huangdengdui@huawei.com> References: <20230516110021.1801443-1-huangdengdui@huawei.com> <20230525070302.3745541-1-huangdengdui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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..2863b5ebda 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_rxq_avail(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_txq_avail(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_rxq_avail(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; }