From patchwork Fri May 13 02:53:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111096 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 6BA7DA00C3; Fri, 13 May 2022 05:00:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 66A974283A; Fri, 13 May 2022 04:59:57 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 7C08D40698 for ; Fri, 13 May 2022 04:59:53 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Kztdp1ZQmzhZ2V; Fri, 13 May 2022 10:59:10 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:51 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 1/9] ethdev: specify return value of xstats-get API Date: Fri, 13 May 2022 10:53:49 +0800 Message-ID: <20220513025357.52275-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Currently the value returned when xstats is NULL of rte_eth_xstats_get() is not specified, some PMDs (eg. hns3/ipn3ke/mvpp2/axgbe) return zero while others return the required number of elements. In this patch, special parameter combinations are restricted: 1. specify that xstats is NULL if and only if n is 0. 2. specify that if n is lower than the required number of elements, the function returns the required number of elements. 3. specify that if n is zero, the xstats must be NULL, the function returns the required number of elements. This patch also makes sure that xstats is NULL if n is lower or equal to the number of basic stats when invoke driver's ops. Fixes: ce757f5c9a4d ("ethdev: new method to retrieve extended statistics") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- lib/ethdev/rte_ethdev.c | 4 +++- lib/ethdev/rte_ethdev.h | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 29a3d80466..d9661bd64f 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -2973,6 +2973,8 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (xstats == NULL && n > 0) + return -EINVAL; dev = &rte_eth_devices[port_id]; nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); @@ -2989,7 +2991,7 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, * xstats struct. */ xcount = (*dev->dev_ops->xstats_get)(dev, - xstats ? xstats + count : NULL, + (n > count) ? xstats + count : NULL, (n > count) ? n - count : 0); if (xcount < 0) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 04cff8ee10..04225bba4d 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -3174,9 +3174,13 @@ int rte_eth_xstats_get_names(uint16_t port_id, * @param xstats * A pointer to a table of structure of type *rte_eth_xstat* * to be filled with device statistics ids and values. - * This parameter can be set to NULL if n is 0. + * This parameter can be set to NULL if and only if n is 0. * @param n * The size of the xstats array (number of elements). + * If lower than the required number of elements, the function returns + * the required number of elements. + * If equal to zero, the xstats must be NULL, the function returns the + * required number of elements. * @return * - A positive value lower or equal to n: success. The return value * is the number of entries filled in the stats table. From patchwork Fri May 13 02:53:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111095 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 84808A00C3; Fri, 13 May 2022 04:59:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7A0AB42833; Fri, 13 May 2022 04:59:56 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 86D67427F1 for ; Fri, 13 May 2022 04:59:53 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kztf16VrfzgYtb; Fri, 13 May 2022 10:59:21 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:51 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 2/9] ethdev: optimize xstats-get API's implementation Date: Fri, 13 May 2022 10:53:50 +0800 Message-ID: <20220513025357.52275-3-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 This patch uses eth_dev_get_xstats_basic_count() to retrieve generic statistics count. Signed-off-by: Chengwen Feng Reviewed-by: Andrew Rybchenko --- lib/ethdev/rte_ethdev.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index d9661bd64f..78192c26f7 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -2967,9 +2967,8 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, unsigned int n) { struct rte_eth_dev *dev; - unsigned int count = 0, i; + unsigned int count, i; signed int xcount = 0; - uint16_t nb_rxqs, nb_txqs; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); @@ -2977,13 +2976,7 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, return -EINVAL; dev = &rte_eth_devices[port_id]; - nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); - nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); - - /* Return generic statistics */ - count = RTE_NB_STATS; - if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) - count += (nb_rxqs * RTE_NB_RXQ_STATS) + (nb_txqs * RTE_NB_TXQ_STATS); + count = eth_dev_get_xstats_basic_count(dev); /* implemented by the driver */ if (dev->dev_ops->xstats_get != NULL) { From patchwork Fri May 13 02:53:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111098 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 AFD8AA00C3; Fri, 13 May 2022 05:00:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4684142848; Fri, 13 May 2022 04:59:59 +0200 (CEST) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id E340942831 for ; Fri, 13 May 2022 04:59:53 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Kztd95B55z1JBwg; Fri, 13 May 2022 10:58:37 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:52 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 3/9] net/hns3: adjust return value of xstats-get ops Date: Fri, 13 May 2022 10:53:51 +0800 Message-ID: <20220513025357.52275-4-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Many user (e.g. telemetry) invokes rte_eth_xstats_get(port_id, NULL, 0) to retrieve the required number of elements, but currently hns3 PMD returns zero when xstats is NULL. In the previous patch, the framework defines that the required number of entries should be returned when xstats is NULL and n is zero. And xstats is NULL if and only if n is zero. Based on the preceding constraints, this patch removes the logic of "return zero when xstats is NULL". Fixes: 8839c5e202f3 ("net/hns3: support device stats") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- drivers/net/hns3/hns3_stats.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c index 806720faff..ac1f0d9126 100644 --- a/drivers/net/hns3/hns3_stats.c +++ b/drivers/net/hns3/hns3_stats.c @@ -1020,9 +1020,13 @@ hns3_imissed_stats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, * @praram xstats * A pointer to a table of structure of type *rte_eth_xstat* * to be filled with device statistics ids and values. - * This parameter can be set to NULL if n is 0. + * This parameter can be set to NULL if and only if n is 0. * @param n * The size of the xstats array (number of elements). + * If lower than the required number of elements, the function returns the + * required number of elements. + * If equal to zero, the xstats parameter must be NULL, the function returns + * the required number of elements. * @return * 0 on fail, count(The size of the statistics elements) on success. */ @@ -1041,9 +1045,6 @@ hns3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, int count; int ret; - if (xstats == NULL) - return 0; - count = hns3_xstats_calc_num(dev); if ((int)n < count) return count; From patchwork Fri May 13 02:53:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111097 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 42CB9A00C3; Fri, 13 May 2022 05:00:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 596554283F; Fri, 13 May 2022 04:59:58 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id E05DD42830 for ; Fri, 13 May 2022 04:59:53 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KztY30ZZBzCsW2; Fri, 13 May 2022 10:55:03 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:52 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 4/9] net/ipn3ke: adjust return value of xstats-get ops Date: Fri, 13 May 2022 10:53:52 +0800 Message-ID: <20220513025357.52275-5-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Many user (e.g. telemetry) invokes rte_eth_xstats_get(port_id, NULL, 0) to retrieve the required number of elements, but currently ipn3ke PMD returns zero when xstats is NULL. In the previous patch, the framework defines that the required number of entries should be returned when xstats is NULL and n is zero. And xstats is NULL if and only if n is zero. Based on the preceding constraints, this patch removes the logic of "return zero when xstats is NULL". Fixes: 5a6d883878db ("net/ipn3ke: implement statistics") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- drivers/net/ipn3ke/ipn3ke_representor.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/ipn3ke/ipn3ke_representor.c b/drivers/net/ipn3ke/ipn3ke_representor.c index c9dde1d82e..abbecfdf2e 100644 --- a/drivers/net/ipn3ke/ipn3ke_representor.c +++ b/drivers/net/ipn3ke/ipn3ke_representor.c @@ -2218,9 +2218,6 @@ ipn3ke_rpst_xstats_get struct ipn3ke_rpst_hw_port_stats hw_stats; struct rte_eth_stats stats; - if (!xstats) - return 0; - if (!ethdev) { IPN3KE_AFU_PMD_ERR("ethernet device to get statistics is NULL"); return -EINVAL; From patchwork Fri May 13 02:53:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111099 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 E09E6A00C3; Fri, 13 May 2022 05:00:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 29F794284E; Fri, 13 May 2022 05:00:00 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 19EF3427F1 for ; Fri, 13 May 2022 04:59:54 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kztd95XDfzfbT7; Fri, 13 May 2022 10:58:37 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:52 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 5/9] net/mvpp2: adjust return value of xstats-get ops Date: Fri, 13 May 2022 10:53:53 +0800 Message-ID: <20220513025357.52275-6-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Many user (e.g. telemetry) invokes rte_eth_xstats_get(port_id, NULL, 0) to retrieve the required number of elements, but currently mvpp2 PMD returns zero when xstats is NULL. In the previous patch, the framework defines that the required number of entries should be returned when n is lower than the required number of entries, and makes sure xstats must not be NULL when n is non-zero. This patch removes the logic of "return zero when xstats is NULL", and adds the logic of "return the required number of entries when n is lower than the required number of entries". Fixes: a77b5378cd41 ("net/mrvl: add extended statistics") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- drivers/net/mvpp2/mrvl_ethdev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/mvpp2/mrvl_ethdev.c b/drivers/net/mvpp2/mrvl_ethdev.c index f86701d248..735efb6cfc 100644 --- a/drivers/net/mvpp2/mrvl_ethdev.c +++ b/drivers/net/mvpp2/mrvl_ethdev.c @@ -1626,13 +1626,14 @@ mrvl_xstats_get(struct rte_eth_dev *dev, { struct mrvl_priv *priv = dev->data->dev_private; struct pp2_ppio_statistics ppio_stats; - unsigned int i; + unsigned int i, count; - if (!stats) - return 0; + count = RTE_DIM(mrvl_xstats_tbl); + if (n < count) + return count; pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0); - for (i = 0; i < n && i < RTE_DIM(mrvl_xstats_tbl); i++) { + for (i = 0; i < count; i++) { uint64_t val; if (mrvl_xstats_tbl[i].size == sizeof(uint32_t)) @@ -1648,7 +1649,7 @@ mrvl_xstats_get(struct rte_eth_dev *dev, stats[i].value = val; } - return n; + return count; } /** From patchwork Fri May 13 02:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111100 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 11225A00C3; Fri, 13 May 2022 05:00:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 00E8642855; Fri, 13 May 2022 05:00:01 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 173B740DDE for ; Fri, 13 May 2022 04:59:54 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kztd96gk2zfbWL; Fri, 13 May 2022 10:58:37 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:52 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 6/9] net/axgbe: adjust return value of xstats-get ops Date: Fri, 13 May 2022 10:53:54 +0800 Message-ID: <20220513025357.52275-7-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 Many user (e.g. telemetry) invokes rte_eth_xstats_get(port_id, NULL, 0) to retrieve the required number of elements, but currently axgbe PMD returns zero when xstats is NULL. In the previous patch, the framework defines that the required number of entries should be returned when n is lower than the required number of entries, and makes sure xstats must not be NULL when n is non-zero. This patch removes the logic of "return zero when xstats is NULL", and adds the logic of "return the required number of entries when n is lower than the required number of entries". Fixes: 9d1ef6b2e731 ("net/axgbe: add xstats") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- drivers/net/axgbe/axgbe_ethdev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c index 951da5cc26..e6822fa711 100644 --- a/drivers/net/axgbe/axgbe_ethdev.c +++ b/drivers/net/axgbe/axgbe_ethdev.c @@ -1013,18 +1013,18 @@ axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, struct axgbe_port *pdata = dev->data->dev_private; unsigned int i; - if (!stats) - return 0; + if (n < AXGBE_XSTATS_COUNT) + return AXGBE_XSTATS_COUNT; axgbe_read_mmc_stats(pdata); - for (i = 0; i < n && i < AXGBE_XSTATS_COUNT; i++) { + for (i = 0; i < AXGBE_XSTATS_COUNT; i++) { stats[i].id = i; stats[i].value = *(u64 *)((uint8_t *)&pdata->mmc_stats + axgbe_xstats_strings[i].offset); } - return i; + return AXGBE_XSTATS_COUNT; } static int From patchwork Fri May 13 02:53:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111101 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 BFC99A00C3; Fri, 13 May 2022 05:00:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E004E42859; Fri, 13 May 2022 05:00:01 +0200 (CEST) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 2F6FC42832 for ; Fri, 13 May 2022 04:59:54 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KztY347W6zCsWd; Fri, 13 May 2022 10:55:03 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:52 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 7/9] ethdev: fix memory leak when telemetry xstats Date: Fri, 13 May 2022 10:53:55 +0800 Message-ID: <20220513025357.52275-8-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 'eth_xstats' should be freed after setup telemetry dictionary. This patch fixes it. Fixes: c190daedb9b1 ("ethdev: add telemetry callbacks") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Reviewed-by: Andrew Rybchenko --- lib/ethdev/rte_ethdev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 78192c26f7..1ae686a7aa 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -5580,6 +5580,7 @@ eth_dev_handle_port_xstats(const char *cmd __rte_unused, for (i = 0; i < num_xstats; i++) rte_tel_data_add_dict_u64(d, xstat_names[i].name, eth_xstats[i].value); + free(eth_xstats); return 0; } From patchwork Fri May 13 02:53:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111102 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 40A92A00C3; Fri, 13 May 2022 05:00:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 357CC42863; Fri, 13 May 2022 05:00:03 +0200 (CEST) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 8ABD140698 for ; Fri, 13 May 2022 04:59:54 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KztdB4k9jz1JC03; Fri, 13 May 2022 10:58:38 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:52 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 8/9] ethdev: fix possible null pointer access Date: Fri, 13 May 2022 10:53:56 +0800 Message-ID: <20220513025357.52275-9-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 rte_tel_data_alloc() may return NULL, so the caller should add judgement for it. Fixes: 083b0b310b19 ("ethdev: add common stats for telemetry") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Reviewed-by: Andrew Rybchenko --- lib/ethdev/rte_ethdev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 1ae686a7aa..60c4361256 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -5487,6 +5487,8 @@ eth_dev_add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats, { int q; struct rte_tel_data *q_data = rte_tel_data_alloc(); + if (q_data == NULL) + return; rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL); for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++) rte_tel_data_add_array_u64(q_data, q_stats[q]); From patchwork Fri May 13 02:53:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 111103 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru 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 2F9AEA00C3; Fri, 13 May 2022 05:00:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3483B42868; Fri, 13 May 2022 05:00:04 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 8CB5A40DDE for ; Fri, 13 May 2022 04:59:54 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KztbM18jjzGp1H; Fri, 13 May 2022 10:57:03 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 13 May 2022 10:59:53 +0800 From: Chengwen Feng To: , , , , , , CC: , , Subject: [PATCH v4 9/9] net/cnxk: fix telemetry possible null pointer access Date: Fri, 13 May 2022 10:53:57 +0800 Message-ID: <20220513025357.52275-10-fengchengwen@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> References: <20220416010747.40714-1-fengchengwen@huawei.com> <20220513025357.52275-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 return value of rte_tel_data_alloc() may be null pointer, in this patch, the null check function is added. Fixes: 5ea354a1f2cc ("net/cnxk: support telemetry") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Reviewed-by: Andrew Rybchenko --- drivers/net/cnxk/cnxk_ethdev_telemetry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/cnxk/cnxk_ethdev_telemetry.c b/drivers/net/cnxk/cnxk_ethdev_telemetry.c index 83bc65848c..4fd9048643 100644 --- a/drivers/net/cnxk/cnxk_ethdev_telemetry.c +++ b/drivers/net/cnxk/cnxk_ethdev_telemetry.c @@ -49,6 +49,8 @@ ethdev_tel_handle_info(const char *cmd __rte_unused, rte_tel_data_add_dict_int(d, "n_ports", n_ports); i_data = rte_tel_data_alloc(); + if (i_data == NULL) + return -ENOMEM; rte_tel_data_start_array(i_data, RTE_TEL_U64_VAL); for (i = 0; i < RTE_MAX_ETHPORTS; i++) {