From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dekelp@mellanox.com>
Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])
 by dpdk.org (Postfix) with ESMTP id 691111F28
 for <dev@dpdk.org>; Sun,  5 May 2019 13:47:10 +0200 (CEST)
Received: from Internal Mail-Server by MTLPINE2 (envelope-from
 dekelp@mellanox.com)
 with ESMTPS (AES256-SHA encrypted); 5 May 2019 14:47:08 +0300
Received: from mtl-vdi-280.wap.labs.mlnx. (mtl-vdi-280.wap.labs.mlnx
 [10.128.130.87])
 by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x45Bl86I018026;
 Sun, 5 May 2019 14:47:08 +0300
From: Dekel Peled <dekelp@mellanox.com>
To: yskoh@mellanox.com, shahafs@mellanox.com
Cc: dev@dpdk.org, stable@dpdk.org
Date: Sun,  5 May 2019 14:44:24 +0300
Message-Id: <0df2fcb64b1ed5250aea42b65a5791c72291cf0b.1557056580.git.dekelp@mellanox.com>
X-Mailer: git-send-email 1.7.1
In-Reply-To: <02664e0b50e375e0b0d4ee05c8ad554295b0ccde.1556794185.git.dekelp@mellanox.com>
References: <02664e0b50e375e0b0d4ee05c8ad554295b0ccde.1556794185.git.dekelp@mellanox.com>
Subject: [dpdk-dev] [PATCH v3] net/mlx5: fix init with zero Rx queues
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Sun, 05 May 2019 11:47:10 -0000

Recent patch [1] added, at the end of mlx5_dev_configure(), a call to
mlx5_proc_priv_init(), initializing process_private data of eth_dev.
This call is not reached if PMD is started with zero Rx queues.
In this case mlx5_dev_configure() returns earlier due to the check:
	if (rxqs_n == priv->rxqs_n)
		return 0;
In such a scenario, later references to uninitialized process_private
data will result in segmentation fault.
For example see in function txq_uar_init().

This patch changes the check logic. The following code is executed
if (rxqs_n != priv->rxqs_n), and skipped otherwise.
Function mlx5_proc_priv_init() is always invoked, to ensure
process_private data is initialized.

[1] http://patches.dpdk.org/patch/52629/

Fixes: 120dc4a7dcd3 ("net/mlx5: remove device register remap")
Cc: stable@dpdk.org

Signed-off-by: Dekel Peled <dekelp@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>

---
v2: Update logic after code review.
v3: Remove unrelated code that was wrongly added in v2.
---
---
 drivers/net/mlx5/mlx5_ethdev.c | 46 +++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index d1a70fc..80ee98f 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -428,27 +428,31 @@ struct ethtool_link_settings {
 		rte_errno = EINVAL;
 		return -rte_errno;
 	}
-	if (rxqs_n == priv->rxqs_n)
-		return 0;
-	DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
-		dev->data->port_id, priv->rxqs_n, rxqs_n);
-	priv->rxqs_n = rxqs_n;
-	/* If the requested number of RX queues is not a power of two, use the
-	 * maximum indirection table size for better balancing.
-	 * The result is always rounded to the next power of two. */
-	reta_idx_n = (1 << log2above((rxqs_n & (rxqs_n - 1)) ?
-				     priv->config.ind_table_max_size :
-				     rxqs_n));
-	ret = mlx5_rss_reta_index_resize(dev, reta_idx_n);
-	if (ret)
-		return ret;
-	/* When the number of RX queues is not a power of two, the remaining
-	 * table entries are padded with reused WQs and hashes are not spread
-	 * uniformly. */
-	for (i = 0, j = 0; (i != reta_idx_n); ++i) {
-		(*priv->reta_idx)[i] = j;
-		if (++j == rxqs_n)
-			j = 0;
+	if (rxqs_n != priv->rxqs_n) {
+		DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
+			dev->data->port_id, priv->rxqs_n, rxqs_n);
+		priv->rxqs_n = rxqs_n;
+		/*
+		 * If the requested number of RX queues is not a power of two,
+		 * use the maximum indirection table size for better balancing.
+		 * The result is always rounded to the next power of two.
+		 */
+		reta_idx_n = (1 << log2above((rxqs_n & (rxqs_n - 1)) ?
+					     priv->config.ind_table_max_size :
+					     rxqs_n));
+		ret = mlx5_rss_reta_index_resize(dev, reta_idx_n);
+		if (ret)
+			return ret;
+		/*
+		 * When the number of RX queues is not a power of two,
+		 * the remaining table entries are padded with reused WQs
+		 * and hashes are not spread uniformly.
+		 */
+		for (i = 0, j = 0; (i != reta_idx_n); ++i) {
+			(*priv->reta_idx)[i] = j;
+			if (++j == rxqs_n)
+				j = 0;
+		}
 	}
 	ret = mlx5_proc_priv_init(dev);
 	if (ret)
-- 
1.8.3.1

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by dpdk.space (Postfix) with ESMTP id E9E99A0096
	for <public@inbox.dpdk.org>; Sun,  5 May 2019 13:47:13 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id D085129AC;
	Sun,  5 May 2019 13:47:11 +0200 (CEST)
Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])
 by dpdk.org (Postfix) with ESMTP id 691111F28
 for <dev@dpdk.org>; Sun,  5 May 2019 13:47:10 +0200 (CEST)
Received: from Internal Mail-Server by MTLPINE2 (envelope-from
 dekelp@mellanox.com)
 with ESMTPS (AES256-SHA encrypted); 5 May 2019 14:47:08 +0300
Received: from mtl-vdi-280.wap.labs.mlnx. (mtl-vdi-280.wap.labs.mlnx
 [10.128.130.87])
 by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x45Bl86I018026;
 Sun, 5 May 2019 14:47:08 +0300
From: Dekel Peled <dekelp@mellanox.com>
To: yskoh@mellanox.com, shahafs@mellanox.com
Cc: dev@dpdk.org, stable@dpdk.org
Date: Sun,  5 May 2019 14:44:24 +0300
Message-Id:
 <0df2fcb64b1ed5250aea42b65a5791c72291cf0b.1557056580.git.dekelp@mellanox.com>
X-Mailer: git-send-email 1.7.1
In-Reply-To: <02664e0b50e375e0b0d4ee05c8ad554295b0ccde.1556794185.git.dekelp@mellanox.com>
References: <02664e0b50e375e0b0d4ee05c8ad554295b0ccde.1556794185.git.dekelp@mellanox.com>
Subject: [dpdk-dev] [PATCH v3] net/mlx5: fix init with zero Rx queues
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <20190505114424.7yIPh2rD-gvFsDjbpHMvC25lN9S3FFX-BgUMU9EbSNY@z>

Recent patch [1] added, at the end of mlx5_dev_configure(), a call to
mlx5_proc_priv_init(), initializing process_private data of eth_dev.
This call is not reached if PMD is started with zero Rx queues.
In this case mlx5_dev_configure() returns earlier due to the check:
	if (rxqs_n == priv->rxqs_n)
		return 0;
In such a scenario, later references to uninitialized process_private
data will result in segmentation fault.
For example see in function txq_uar_init().

This patch changes the check logic. The following code is executed
if (rxqs_n != priv->rxqs_n), and skipped otherwise.
Function mlx5_proc_priv_init() is always invoked, to ensure
process_private data is initialized.

[1] http://patches.dpdk.org/patch/52629/

Fixes: 120dc4a7dcd3 ("net/mlx5: remove device register remap")
Cc: stable@dpdk.org

Signed-off-by: Dekel Peled <dekelp@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>

---
v2: Update logic after code review.
v3: Remove unrelated code that was wrongly added in v2.
---
---
 drivers/net/mlx5/mlx5_ethdev.c | 46 +++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index d1a70fc..80ee98f 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -428,27 +428,31 @@ struct ethtool_link_settings {
 		rte_errno = EINVAL;
 		return -rte_errno;
 	}
-	if (rxqs_n == priv->rxqs_n)
-		return 0;
-	DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
-		dev->data->port_id, priv->rxqs_n, rxqs_n);
-	priv->rxqs_n = rxqs_n;
-	/* If the requested number of RX queues is not a power of two, use the
-	 * maximum indirection table size for better balancing.
-	 * The result is always rounded to the next power of two. */
-	reta_idx_n = (1 << log2above((rxqs_n & (rxqs_n - 1)) ?
-				     priv->config.ind_table_max_size :
-				     rxqs_n));
-	ret = mlx5_rss_reta_index_resize(dev, reta_idx_n);
-	if (ret)
-		return ret;
-	/* When the number of RX queues is not a power of two, the remaining
-	 * table entries are padded with reused WQs and hashes are not spread
-	 * uniformly. */
-	for (i = 0, j = 0; (i != reta_idx_n); ++i) {
-		(*priv->reta_idx)[i] = j;
-		if (++j == rxqs_n)
-			j = 0;
+	if (rxqs_n != priv->rxqs_n) {
+		DRV_LOG(INFO, "port %u Rx queues number update: %u -> %u",
+			dev->data->port_id, priv->rxqs_n, rxqs_n);
+		priv->rxqs_n = rxqs_n;
+		/*
+		 * If the requested number of RX queues is not a power of two,
+		 * use the maximum indirection table size for better balancing.
+		 * The result is always rounded to the next power of two.
+		 */
+		reta_idx_n = (1 << log2above((rxqs_n & (rxqs_n - 1)) ?
+					     priv->config.ind_table_max_size :
+					     rxqs_n));
+		ret = mlx5_rss_reta_index_resize(dev, reta_idx_n);
+		if (ret)
+			return ret;
+		/*
+		 * When the number of RX queues is not a power of two,
+		 * the remaining table entries are padded with reused WQs
+		 * and hashes are not spread uniformly.
+		 */
+		for (i = 0, j = 0; (i != reta_idx_n); ++i) {
+			(*priv->reta_idx)[i] = j;
+			if (++j == rxqs_n)
+				j = 0;
+		}
 	}
 	ret = mlx5_proc_priv_init(dev);
 	if (ret)
-- 
1.8.3.1