From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C9B63A0547 for ; Tue, 9 Feb 2021 04:14:46 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 22D5A1606D2; Tue, 9 Feb 2021 04:14:46 +0100 (CET) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id 9D7884014E for ; Tue, 9 Feb 2021 04:14:44 +0100 (CET) Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DZSd518T5zlHR5; Tue, 9 Feb 2021 11:12:57 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 9 Feb 2021 11:14:39 +0800 From: "Min Hu (Connor)" To: CC: , Date: Tue, 9 Feb 2021 11:14:07 +0800 Message-ID: <1612840447-56296-3-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612840447-56296-1-git-send-email-humin29@huawei.com> References: <1612840447-56296-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-stable] [[PATCH 19.11 2/2] net/hns3: fix xstats with id and names X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Huisong Li [ upstream commit 3213d584b698f41dbef14599a41ab0a7a78739b4 ] Currently, validity check for ids and values in the hns3_dev_xstats_get_by_id API is incorrect, which will cause a problem. Namely, if the ID range of the xstats stats item does not include the basic stats item, the app can not obtain the corresponding xstats statistics in hns3_dev_xstats_get_by_id. Similarly, the hns3_dev_xstats_get_names_by_id interface also has a problem. Although the input parameter verification code cannot be executed due to the implementation of the ethdev framework interface, the driver needs to ensure the correctness of the input parameters. Fixes: 8839c5e202f3 ("net/hns3: support device stats") Cc: stable@dpdk.org --- drivers/net/hns3/hns3_stats.c | 24 ++++++++++++++++++++++-- drivers/net/hns3/hns3_stats.h | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c index 4cf5e8f..571e8b4 100644 --- a/drivers/net/hns3/hns3_stats.c +++ b/drivers/net/hns3/hns3_stats.c @@ -754,9 +754,13 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, char *addr; int ret; - if (ids == NULL || size < cnt_stats) + if (ids == NULL && values == NULL) return cnt_stats; + if (ids == NULL) + if (size < cnt_stats) + return cnt_stats; + /* Update tqp stats by read register */ ret = hns3_update_tqp_stats(hw); if (ret) { @@ -804,6 +808,15 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, } } + if (ids == NULL && values != NULL) { + for (i = 0; i < cnt_stats; i++) + memcpy(&values[i], &values_copy[i], sizeof(values[i])); + + rte_free(values_copy); + + return cnt_stats; + } + for (i = 0; i < size; i++) { if (ids[i] >= cnt_stats) { hns3_err(hw, "ids[%d] (%" PRIx64 ") is invalid, " @@ -852,9 +865,16 @@ hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, uint16_t i, j; uint64_t len; - if (ids == NULL || xstats_names == NULL) + if (xstats_names == NULL) return cnt_stats; + if (ids == NULL) { + if (size < cnt_stats) + return cnt_stats; + + return hns3_dev_xstats_get_names(dev, xstats_names, cnt_stats); + } + len = cnt_stats * sizeof(struct rte_eth_xstat_name); xstats_names_copy = rte_zmalloc("hns3_xstats_names", len, 0); if (xstats_names_copy == NULL) { diff --git a/drivers/net/hns3/hns3_stats.h b/drivers/net/hns3/hns3_stats.h index 365bae0..34c76be 100644 --- a/drivers/net/hns3/hns3_stats.h +++ b/drivers/net/hns3/hns3_stats.h @@ -141,8 +141,8 @@ int hns3_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned int size); int hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, - __rte_unused const uint64_t *ids, - __rte_unused uint64_t *values, + const uint64_t *ids, + uint64_t *values, uint32_t size); int hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, -- 2.7.4