patch 'net/netvsc: fix using Tx queue higher than Rx queues' has been queued to stable release 21.11.9

Kevin Traynor ktraynor at redhat.com
Wed Nov 27 18:18:17 CET 2024


Hi,

FYI, your patch has been queued to stable release 21.11.9

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/02/24. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/b140a98cc6532d9f37470b2b19c1a4be4b9845e8

Thanks.

Kevin

---
>From b140a98cc6532d9f37470b2b19c1a4be4b9845e8 Mon Sep 17 00:00:00 2001
From: Alan Elder <alan.elder at microsoft.com>
Date: Thu, 17 Oct 2024 12:20:29 -0700
Subject: [PATCH] net/netvsc: fix using Tx queue higher than Rx queues

[ upstream commit e90020535c03cf9e60448ba623cac3301f111dae ]

The previous code allowed the number of Tx queues to be set higher than
the number of Rx queues.  If a packet was sent on a Tx queue with index
>= number Rx queues there was a segfault due to accessing beyond the end
of the dev->data->rx_queues[] array.

This commit fixes the issue by creating an Rx queue for every Tx queue
meaning that an event buffer is allocated to handle receiving Tx
completion messages.

mbuf pool and Rx ring are not allocated for these additional Rx queues
and RSS configuration ensures that no packets are received on them.

Fixes: 4e9c73e96e83 ("net/netvsc: add Hyper-V network device")

Signed-off-by: Alan Elder <alan.elder at microsoft.com>
Signed-off-by: Long Li <longli at microsoft.com>
---
 drivers/net/netvsc/hn_ethdev.c |  9 +++++
 drivers/net/netvsc/hn_rxtx.c   | 69 +++++++++++++++++++++++++++++-----
 2 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index 787139c0b2..39110f0176 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -313,4 +313,13 @@ static int hn_rss_reta_update(struct rte_eth_dev *dev,
 		if (reta_conf[idx].mask & mask)
 			hv->rss_ind[i] = reta_conf[idx].reta[shift];
+
+		/*
+		 * Ensure we don't allow config that directs traffic to an Rx
+		 * queue that we aren't going to poll
+		 */
+		if (hv->rss_ind[i] >=  dev->data->nb_rx_queues) {
+			PMD_DRV_LOG(ERR, "RSS distributing traffic to invalid Rx queue");
+			return -EINVAL;
+		}
 	}
 
diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
index aba206565d..69588bc264 100644
--- a/drivers/net/netvsc/hn_rxtx.c
+++ b/drivers/net/netvsc/hn_rxtx.c
@@ -235,4 +235,15 @@ static void hn_reset_txagg(struct hn_tx_queue *txq)
 }
 
+static void
+hn_rx_queue_free_common(struct hn_rx_queue *rxq)
+{
+	if (!rxq)
+		return;
+
+	rte_free(rxq->rxbuf_info);
+	rte_free(rxq->event_buf);
+	rte_free(rxq);
+}
+
 int
 hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
@@ -244,4 +255,5 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 	struct hn_data *hv = dev->data->dev_private;
 	struct hn_tx_queue *txq;
+	struct hn_rx_queue *rxq = NULL;
 	char name[RTE_MEMPOOL_NAMESIZE];
 	uint32_t tx_free_thresh;
@@ -302,4 +314,25 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 	}
 
+	/*
+	 * If there are more Tx queues than Rx queues, allocate rx_queues
+	 * with event buffer so that Tx completion messages can still be
+	 * received
+	 */
+	if (queue_idx >= dev->data->nb_rx_queues) {
+		rxq = hn_rx_queue_alloc(hv, queue_idx, socket_id);
+
+		if (!rxq) {
+			err = -ENOMEM;
+			goto error;
+		}
+
+		/*
+		 * Don't allocate mbuf pool or rx ring.  RSS is always configured
+		 * to ensure packets aren't received by this Rx queue.
+		 */
+		rxq->mb_pool = NULL;
+		rxq->rx_ring = NULL;
+	}
+
 	txq->agg_szmax  = RTE_MIN(hv->chim_szmax, hv->rndis_agg_size);
 	txq->agg_pktmax = hv->rndis_agg_pkts;
@@ -312,4 +345,6 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 	if (err == 0) {
 		dev->data->tx_queues[queue_idx] = txq;
+		if (rxq != NULL)
+			dev->data->rx_queues[queue_idx] = rxq;
 		return 0;
 	}
@@ -319,4 +354,5 @@ error:
 		rte_mempool_free(txq->txdesc_pool);
 	rte_memzone_free(txq->tx_rndis_mz);
+	hn_rx_queue_free_common(rxq);
 	rte_free(txq);
 	return err;
@@ -365,4 +401,10 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
 	if (!txq)
 		return;
+	/*
+	 * Free any Rx queues allocated for a Tx queue without a corresponding
+	 * Rx queue
+	 */
+	if (qid >= dev->data->nb_rx_queues)
+		hn_rx_queue_free_common(dev->data->rx_queues[qid]);
 
 	if (txq->txdesc_pool)
@@ -555,8 +597,10 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,
 {
 	struct hn_data *hv = rxq->hv;
-	struct rte_mbuf *m;
+	struct rte_mbuf *m = NULL;
 	bool use_extbuf = false;
 
-	m = rte_pktmbuf_alloc(rxq->mb_pool);
+	if (likely(rxq->mb_pool != NULL))
+		m = rte_pktmbuf_alloc(rxq->mb_pool);
+
 	if (unlikely(!m)) {
 		struct rte_eth_dev *dev =
@@ -945,5 +989,13 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
 		rxq = hv->primary;
 	} else {
-		rxq = hn_rx_queue_alloc(hv, queue_idx, socket_id);
+		/*
+		 * If the number of Tx queues was previously greater than the
+		 * number of Rx queues, we may already have allocated an rxq.
+		 */
+		if (!dev->data->rx_queues[queue_idx])
+			rxq = hn_rx_queue_alloc(hv, queue_idx, socket_id);
+		else
+			rxq = dev->data->rx_queues[queue_idx];
+
 		if (!rxq)
 			return -ENOMEM;
@@ -978,7 +1030,8 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
 fail:
 	rte_ring_free(rxq->rx_ring);
-	rte_free(rxq->rxbuf_info);
-	rte_free(rxq->event_buf);
-	rte_free(rxq);
+	/* Only free rxq if it was created in this function. */
+	if (!dev->data->rx_queues[queue_idx])
+		hn_rx_queue_free_common(rxq);
+
 	return error;
 }
@@ -1001,7 +1054,5 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary)
 		return;
 
-	rte_free(rxq->rxbuf_info);
-	rte_free(rxq->event_buf);
-	rte_free(rxq);
+	hn_rx_queue_free_common(rxq);
 }
 
-- 
2.47.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2024-11-27 17:17:40.466360543 +0000
+++ 0070-net-netvsc-fix-using-Tx-queue-higher-than-Rx-queues.patch	2024-11-27 17:17:38.264269575 +0000
@@ -1 +1 @@
-From e90020535c03cf9e60448ba623cac3301f111dae Mon Sep 17 00:00:00 2001
+From b140a98cc6532d9f37470b2b19c1a4be4b9845e8 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit e90020535c03cf9e60448ba623cac3301f111dae ]
+
@@ -19 +20,0 @@
-Cc: stable at dpdk.org
@@ -29 +30 @@
-index f8cb05a118..1736cb5d07 100644
+index 787139c0b2..39110f0176 100644
@@ -32 +33 @@
-@@ -314,4 +314,13 @@ static int hn_rss_reta_update(struct rte_eth_dev *dev,
+@@ -313,4 +313,13 @@ static int hn_rss_reta_update(struct rte_eth_dev *dev,
@@ -47 +48 @@
-index 870f62e5fa..52aedb001f 100644
+index aba206565d..69588bc264 100644
@@ -50 +51 @@
-@@ -223,4 +223,15 @@ static void hn_reset_txagg(struct hn_tx_queue *txq)
+@@ -235,4 +235,15 @@ static void hn_reset_txagg(struct hn_tx_queue *txq)
@@ -66 +67 @@
-@@ -232,4 +243,5 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
+@@ -244,4 +255,5 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
@@ -72 +73 @@
-@@ -290,4 +302,25 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
+@@ -302,4 +314,25 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
@@ -98 +99 @@
-@@ -300,4 +333,6 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
+@@ -312,4 +345,6 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
@@ -105,2 +106,2 @@
-@@ -306,4 +341,5 @@ error:
- 	rte_mempool_free(txq->txdesc_pool);
+@@ -319,4 +354,5 @@ error:
+ 		rte_mempool_free(txq->txdesc_pool);
@@ -111 +112 @@
-@@ -352,4 +388,10 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
+@@ -365,4 +401,10 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
@@ -121,2 +122,2 @@
- 	rte_mempool_free(txq->txdesc_pool);
-@@ -541,8 +583,10 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,
+ 	if (txq->txdesc_pool)
+@@ -555,8 +597,10 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,
@@ -135 +136 @@
-@@ -931,5 +975,13 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
+@@ -945,5 +989,13 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
@@ -150 +151 @@
-@@ -964,7 +1016,8 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
+@@ -978,7 +1030,8 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev,
@@ -162 +163 @@
-@@ -987,7 +1040,5 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary)
+@@ -1001,7 +1054,5 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary)



More information about the stable mailing list