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 5B59EA0C47; Sat, 25 Sep 2021 17:11:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D38CE4003D; Sat, 25 Sep 2021 17:11:42 +0200 (CEST) Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net [5.45.199.163]) by mails.dpdk.org (Postfix) with ESMTP id B33474003C; Sat, 25 Sep 2021 17:11:40 +0200 (CEST) Received: from iva8-c5ee4261001e.qloud-c.yandex.net (iva8-c5ee4261001e.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:a8a6:0:640:c5ee:4261]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 14F492E0B18; Sat, 25 Sep 2021 18:11:40 +0300 (MSK) Received: from iva4-f06c35e68a0a.qloud-c.yandex.net (iva4-f06c35e68a0a.qloud-c.yandex.net [2a02:6b8:c0c:152e:0:640:f06c:35e6]) by iva8-c5ee4261001e.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id PcAOIP45DB-BctSZJJf; Sat, 25 Sep 2021 18:11:40 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1632582700; bh=TxvWFKcSYQ93WwJafnBD8AkbIi2gYQiHegFUNXliXVM=; h=Message-Id:Date:Subject:To:From:Cc; b=1K72tq4TAiPWSfGP6bz+ZLqLOYI532CpweNg2wKwpW7lGMFSMoRtnTnMtBzS+0LvV RhOFjs8pjmAZb34nfM1QfdxkWI7eWG7Pg2EXMU1tCSGRwbWapgseTFnhuhkd7rBYcy 7X+eSvVKUTAcLYGWCOjeXlMWdwmpAxkhu3YlOvY0= Authentication-Results: iva8-c5ee4261001e.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from 172.31.80.59-vpn.dhcp.yndx.net (172.31.80.59-vpn.dhcp.yndx.net [172.31.80.59]) by iva4-f06c35e68a0a.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id RVamNyngBk-BcxW8V17; Sat, 25 Sep 2021 18:11:38 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Vladislav Grishenko To: Matan Azrad , Viacheslav Ovsiienko , Shahaf Shuler , Adrien Mazarguil , Elad Persiko Cc: dev@dpdk.org, stable@dpdk.org Date: Sat, 25 Sep 2021 20:11:29 +0500 Message-Id: <20210925151129.24727-1-themiron@yandex-team.ru> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] net/mlx5: fix xstats get reinitialization 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 Sender: "dev" The mlx5_xstats_get gets the device extended statistics. In this function the driver may reinitialize the structures that are used to read device counters. In case of reinitialization, the number of counters may change, which wouldn't be taken into account by the get API callback and can cause a segmentation fault. In case of insufficient supplied stats table size, ex. zero to query the number of extended stats, reinitialization may never happen and the returned stats number, that is used for subsequent stats getting, will not be sufficient too. This issue is fixed by getting and allocating the counters size after the reinitialization. Fixes: 1a611fdaf6ec ("net/mlx5: support missing counter in extended statistics") Fixes: a4193ae3bc4f ("net/mlx5: support extended statistics") Cc: stable@dpdk.org Signed-off-by: Vladislav Grishenko --- drivers/net/mlx5/mlx5_stats.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c index ae2f5668a7..7dd7724b05 100644 --- a/drivers/net/mlx5/mlx5_stats.c +++ b/drivers/net/mlx5/mlx5_stats.c @@ -39,23 +39,37 @@ mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, unsigned int n) { struct mlx5_priv *priv = dev->data->dev_private; - unsigned int i; - uint64_t counters[n]; struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; - uint16_t mlx5_stats_n = xstats_ctrl->mlx5_stats_n; + uint16_t mlx5_stats_n; + int stats_n; + + stats_n = mlx5_os_get_stats_n(dev); + if (stats_n < 0) + return stats_n; + if (xstats_ctrl->stats_n != stats_n) + mlx5_os_stats_init(dev); + mlx5_stats_n = xstats_ctrl->mlx5_stats_n; if (n >= mlx5_stats_n && stats) { - int stats_n; + uint64_t *counters; + unsigned int i; int ret; - stats_n = mlx5_os_get_stats_n(dev); - if (stats_n < 0) - return stats_n; - if (xstats_ctrl->stats_n != stats_n) - mlx5_os_stats_init(dev); + counters = mlx5_malloc(MLX5_MEM_SYS, sizeof(*counters) * + mlx5_stats_n, 0, + SOCKET_ID_ANY); + if (counters == NULL) { + DRV_LOG(WARNING, "port %u unable to allocate " + "memory for xstats counters", + dev->data->port_id); + rte_errno = ENOMEM; + return -rte_errno; + } ret = mlx5_os_read_dev_counters(dev, counters); - if (ret) + if (ret) { + mlx5_free(counters); return ret; + } for (i = 0; i != mlx5_stats_n; ++i) { stats[i].id = i; if (xstats_ctrl->info[i].dev) { @@ -76,6 +90,7 @@ mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, (counters[i] - xstats_ctrl->base[i]); } } + mlx5_free(counters); } mlx5_stats_n = mlx5_txpp_xstats_get(dev, stats, n, mlx5_stats_n); return mlx5_stats_n; -- 2.17.1