Blame SOURCES/0001-net-enic-fix-crash-due-to-static-max-number-of-queue.patch

a6040a
From acc4c80cf3b5fb3c0f87bcb7c4eb68958f60ef15 Mon Sep 17 00:00:00 2001
a6040a
From: Hyong Youb Kim <hyonkim@cisco.com>
a6040a
Date: Mon, 22 Jan 2018 17:05:28 -0800
a6040a
Subject: [PATCH] net/enic: fix crash due to static max number of queues
a6040a
a6040a
[ upstream commit 6c45c330589d334c4f7b729e61ae30a6acfcc119 ]
a6040a
a6040a
ENIC_CQ_MAX, ENIC_WQ_MAX and others are arbitrary values that
a6040a
prevent the app from using more queues when they are available on
a6040a
hardware. Remove them and dynamically allocate vnic_cq and such
a6040a
arrays to accommodate all available hardware queues.
a6040a
a6040a
As a side effect of removing ENIC_CQ_MAX, this commit fixes a segfault
a6040a
that would happen when the app requests more than 16 CQs, because
a6040a
enic_set_vnic_res() does not consider ENIC_CQ_MAX. For example, the
a6040a
following command causes a crash.
a6040a
a6040a
testpmd -- --rxq=16 --txq=16
a6040a
a6040a
Fixes: ce93d3c36db0 ("net/enic: fix resource check failures when bonding devices")
a6040a
a6040a
Signed-off-by: Hyong Youb Kim <hyonkim@cisco.com>
a6040a
Reviewed-by: John Daley <johndale@cisco.com>
a6040a
---
a6040a
 drivers/net/enic/enic.h        | 25 +++++++++---------------
a6040a
 drivers/net/enic/enic_ethdev.c | 20 ++------------------
a6040a
 drivers/net/enic/enic_main.c   | 43 ++++++++++++++++++++++++++++++++----------
a6040a
 3 files changed, 44 insertions(+), 44 deletions(-)
a6040a
a6040a
diff --git a/drivers/net/enic/enic.h b/drivers/net/enic/enic.h
a6040a
index e36ec385c..a43fddc5f 100644
a6040a
--- a/drivers/net/enic/enic.h
a6040a
+++ b/drivers/net/enic/enic.h
a6040a
@@ -53,13 +53,6 @@
a6040a
 #define DRV_DESCRIPTION		"Cisco VIC Ethernet NIC Poll-mode Driver"
a6040a
 #define DRV_COPYRIGHT		"Copyright 2008-2015 Cisco Systems, Inc"
a6040a
 
a6040a
-#define ENIC_WQ_MAX		8
a6040a
-/* With Rx scatter support, we use two RQs on VIC per RQ used by app. Both
a6040a
- * RQs use the same CQ.
a6040a
- */
a6040a
-#define ENIC_RQ_MAX		16
a6040a
-#define ENIC_CQ_MAX		(ENIC_WQ_MAX + (ENIC_RQ_MAX / 2))
a6040a
-#define ENIC_INTR_MAX		(ENIC_CQ_MAX + 2)
a6040a
 #define ENIC_MAX_MAC_ADDR	64
a6040a
 
a6040a
 #define VLAN_ETH_HLEN           18
a6040a
@@ -150,17 +143,17 @@ struct enic {
a6040a
 	unsigned int flags;
a6040a
 	unsigned int priv_flags;
a6040a
 
a6040a
-	/* work queue */
a6040a
-	struct vnic_wq wq[ENIC_WQ_MAX];
a6040a
-	unsigned int wq_count;
a6040a
+	/* work queue (len = conf_wq_count) */
a6040a
+	struct vnic_wq *wq;
a6040a
+	unsigned int wq_count; /* equals eth_dev nb_tx_queues */
a6040a
 
a6040a
-	/* receive queue */
a6040a
-	struct vnic_rq rq[ENIC_RQ_MAX];
a6040a
-	unsigned int rq_count;
a6040a
+	/* receive queue (len = conf_rq_count) */
a6040a
+	struct vnic_rq *rq;
a6040a
+	unsigned int rq_count; /* equals eth_dev nb_rx_queues */
a6040a
 
a6040a
-	/* completion queue */
a6040a
-	struct vnic_cq cq[ENIC_CQ_MAX];
a6040a
-	unsigned int cq_count;
a6040a
+	/* completion queue (len = conf_cq_count) */
a6040a
+	struct vnic_cq *cq;
a6040a
+	unsigned int cq_count; /* equals rq_count + wq_count */
a6040a
 
a6040a
 	/* interrupt resource */
a6040a
 	struct vnic_intr intr;
a6040a
diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
a6040a
index 669dbf336..98391b008 100644
a6040a
--- a/drivers/net/enic/enic_ethdev.c
a6040a
+++ b/drivers/net/enic/enic_ethdev.c
a6040a
@@ -205,13 +205,7 @@ static int enicpmd_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
a6040a
 		return -E_RTE_SECONDARY;
a6040a
 
a6040a
 	ENICPMD_FUNC_TRACE();
a6040a
-	if (queue_idx >= ENIC_WQ_MAX) {
a6040a
-		dev_err(enic,
a6040a
-			"Max number of TX queues exceeded.  Max is %d\n",
a6040a
-			ENIC_WQ_MAX);
a6040a
-		return -EINVAL;
a6040a
-	}
a6040a
-
a6040a
+	RTE_ASSERT(queue_idx < enic->conf_wq_count);
a6040a
 	eth_dev->data->tx_queues[queue_idx] = (void *)&enic->wq[queue_idx];
a6040a
 
a6040a
 	ret = enic_alloc_wq(enic, queue_idx, socket_id, nb_desc);
a6040a
@@ -325,17 +319,7 @@ static int enicpmd_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
a6040a
 
a6040a
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
a6040a
 		return -E_RTE_SECONDARY;
a6040a
-
a6040a
-	/* With Rx scatter support, two RQs are now used on VIC per RQ used
a6040a
-	 * by the application.
a6040a
-	 */
a6040a
-	if (queue_idx * 2 >= ENIC_RQ_MAX) {
a6040a
-		dev_err(enic,
a6040a
-			"Max number of RX queues exceeded.  Max is %d. This PMD uses 2 RQs on VIC per RQ used by DPDK.\n",
a6040a
-			ENIC_RQ_MAX);
a6040a
-		return -EINVAL;
a6040a
-	}
a6040a
-
a6040a
+	RTE_ASSERT(enic_rte_rq_idx_to_sop_idx(queue_idx) < enic->conf_rq_count);
a6040a
 	eth_dev->data->rx_queues[queue_idx] =
a6040a
 		(void *)&enic->rq[enic_rte_rq_idx_to_sop_idx(queue_idx)];
a6040a
 
a6040a
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
a6040a
index 8af0ccd3c..1694aed12 100644
a6040a
--- a/drivers/net/enic/enic_main.c
a6040a
+++ b/drivers/net/enic/enic_main.c
a6040a
@@ -1075,6 +1075,9 @@ static void enic_dev_deinit(struct enic *enic)
a6040a
 	vnic_dev_notify_unset(enic->vdev);
a6040a
 
a6040a
 	rte_free(eth_dev->data->mac_addrs);
a6040a
+	rte_free(enic->cq);
a6040a
+	rte_free(enic->rq);
a6040a
+	rte_free(enic->wq);
a6040a
 }
a6040a
 
a6040a
 
a6040a
@@ -1082,27 +1085,28 @@ int enic_set_vnic_res(struct enic *enic)
a6040a
 {
a6040a
 	struct rte_eth_dev *eth_dev = enic->rte_dev;
a6040a
 	int rc = 0;
a6040a
+	unsigned int required_rq, required_wq, required_cq;
a6040a
 
a6040a
-	/* With Rx scatter support, two RQs are now used per RQ used by
a6040a
-	 * the application.
a6040a
-	 */
a6040a
-	if (enic->conf_rq_count < eth_dev->data->nb_rx_queues) {
a6040a
+	/* Always use two vNIC RQs per eth_dev RQ, regardless of Rx scatter. */
a6040a
+	required_rq = eth_dev->data->nb_rx_queues * 2;
a6040a
+	required_wq = eth_dev->data->nb_tx_queues;
a6040a
+	required_cq = eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues;
a6040a
+
a6040a
+	if (enic->conf_rq_count < required_rq) {
a6040a
 		dev_err(dev, "Not enough Receive queues. Requested:%u which uses %d RQs on VIC, Configured:%u\n",
a6040a
 			eth_dev->data->nb_rx_queues,
a6040a
-			eth_dev->data->nb_rx_queues * 2, enic->conf_rq_count);
a6040a
+			required_rq, enic->conf_rq_count);
a6040a
 		rc = -EINVAL;
a6040a
 	}
a6040a
-	if (enic->conf_wq_count < eth_dev->data->nb_tx_queues) {
a6040a
+	if (enic->conf_wq_count < required_wq) {
a6040a
 		dev_err(dev, "Not enough Transmit queues. Requested:%u, Configured:%u\n",
a6040a
 			eth_dev->data->nb_tx_queues, enic->conf_wq_count);
a6040a
 		rc = -EINVAL;
a6040a
 	}
a6040a
 
a6040a
-	if (enic->conf_cq_count < (eth_dev->data->nb_rx_queues +
a6040a
-				   eth_dev->data->nb_tx_queues)) {
a6040a
+	if (enic->conf_cq_count < required_cq) {
a6040a
 		dev_err(dev, "Not enough Completion queues. Required:%u, Configured:%u\n",
a6040a
-			(eth_dev->data->nb_rx_queues +
a6040a
-			 eth_dev->data->nb_tx_queues), enic->conf_cq_count);
a6040a
+			required_cq, enic->conf_cq_count);
a6040a
 		rc = -EINVAL;
a6040a
 	}
a6040a
 
a6040a
@@ -1307,6 +1311,25 @@ static int enic_dev_init(struct enic *enic)
a6040a
 		dev_err(enic, "See the ENIC PMD guide for more information.\n");
a6040a
 		return -EINVAL;
a6040a
 	}
a6040a
+	/* Queue counts may be zeros. rte_zmalloc returns NULL in that case. */
a6040a
+	enic->cq = rte_zmalloc("enic_vnic_cq", sizeof(struct vnic_cq) *
a6040a
+			       enic->conf_cq_count, 8);
a6040a
+	enic->rq = rte_zmalloc("enic_vnic_rq", sizeof(struct vnic_rq) *
a6040a
+			       enic->conf_rq_count, 8);
a6040a
+	enic->wq = rte_zmalloc("enic_vnic_wq", sizeof(struct vnic_wq) *
a6040a
+			       enic->conf_wq_count, 8);
a6040a
+	if (enic->conf_cq_count > 0 && enic->cq == NULL) {
a6040a
+		dev_err(enic, "failed to allocate vnic_cq, aborting.\n");
a6040a
+		return -1;
a6040a
+	}
a6040a
+	if (enic->conf_rq_count > 0 && enic->rq == NULL) {
a6040a
+		dev_err(enic, "failed to allocate vnic_rq, aborting.\n");
a6040a
+		return -1;
a6040a
+	}
a6040a
+	if (enic->conf_wq_count > 0 && enic->wq == NULL) {
a6040a
+		dev_err(enic, "failed to allocate vnic_wq, aborting.\n");
a6040a
+		return -1;
a6040a
+	}
a6040a
 
a6040a
 	/* Get the supported filters */
a6040a
 	enic_fdir_info(enic);
a6040a
-- 
a6040a
2.14.3
a6040a