DPDK patches and discussions
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH v2 2/6] net/hns3: fix xstats statistics with id and names
Date: Wed, 6 Jan 2021 11:46:28 +0800	[thread overview]
Message-ID: <1609904792-63280-3-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1609904792-63280-1-git-send-email-oulijun@huawei.com>

From: Huisong Li <lihuisong@huawei.com>

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

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
V1->V2:
-fix ids and values check
-add hns3_dev_xstats_get_names_by_id check
---
 drivers/net/hns3/hns3_stats.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
index 91168ac..1597af3 100644
--- a/drivers/net/hns3/hns3_stats.c
+++ b/drivers/net/hns3/hns3_stats.c
@@ -933,9 +933,13 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
 	uint32_t i;
 	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) {
@@ -957,6 +961,15 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
 		return -EINVAL;
 	}
 
+	if (ids == NULL && values != NULL) {
+		for (i = 0; i < cnt_stats; i++)
+			memcpy(&values[i], &values_copy[i].value,
+			       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[%u] (%" PRIx64 ") is invalid, "
@@ -1005,9 +1018,16 @@ hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
 	uint64_t len;
 	uint32_t i;
 
-	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);
 	names_copy = rte_zmalloc("hns3_xstats_names", len, 0);
 	if (names_copy == NULL) {
-- 
2.7.4


  parent reply	other threads:[~2021-01-06  3:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13  8:02 [dpdk-dev] [PATCH 0/7] some bugfixes for hns3 Lijun Ou
2020-12-13  8:02 ` [dpdk-dev] [PATCH 1/7] net/hns3: fix incorrect interception with filter director Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 2/7] net/hns3: fix xstats statistics with id Lijun Ou
2020-12-17 15:20   ` Ferruh Yigit
2020-12-18  7:06     ` oulijun
2020-12-18 13:34       ` Ferruh Yigit
2020-12-13  8:03 ` [dpdk-dev] [PATCH 3/7] net/hns3: fix abnormal return value in xstats Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 4/7] net/hns3: fix Rx/Tx abnormal errors stats Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 5/7] net/hns3: fix location of saving ethdev Lijun Ou
2020-12-18 14:11   ` Ferruh Yigit
2020-12-13  8:03 ` [dpdk-dev] [PATCH 6/7] net/hns3: fix directly access with rte device Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 7/7] net/hns3: remove unnecessary memset Lijun Ou
2021-01-06  3:46 ` [dpdk-dev] [PATCH v2 0/6] some bugfixes for hns3 Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 1/6] net/hns3: fix incorrect interception with filter director Lijun Ou
2021-01-19 21:27     ` Thomas Monjalon
2021-01-06  3:46   ` Lijun Ou [this message]
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 3/6] net/hns3: fix abnormal return value in xstats Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 4/6] net/hns3: fix Rx/Tx abnormal errors stats Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 5/6] net/hns3: fix crash with multi-process Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 6/6] net/hns3: remove unnecessary memset Lijun Ou
2021-01-14 23:34   ` [dpdk-dev] [PATCH v2 0/6] some bugfixes for hns3 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=1609904792-63280-3-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.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).