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 4444845DB9 for ; Wed, 27 Nov 2024 18:22:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3C3164069F; Wed, 27 Nov 2024 18:22:04 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id EBBF7402E4 for ; Wed, 27 Nov 2024 18:22:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732728122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZsM/32ppA25ec5KHdgitwSp01vKLnZ243XtkIrxR70I=; b=Sxcs6W5EpXyARZ0En5JaDsF7BZesBUwL9Wed4rrfJru6EU21n31UWGT6NSZLZoMOn3igla pMcaAyNXpSG32s8we72oS+gSm++OANRlRXF2uw+zn32zjn3L5x3FQCVwO8xFGVQl9lSmWm qhC90Zt4YZcqIZ4hituk5ctXX40qvHY= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-wog4LmJ2MZaYggZKy5PMPQ-1; Wed, 27 Nov 2024 12:22:00 -0500 X-MC-Unique: wog4LmJ2MZaYggZKy5PMPQ-1 X-Mimecast-MFC-AGG-ID: wog4LmJ2MZaYggZKy5PMPQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C91019560A3; Wed, 27 Nov 2024 17:21:59 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.192.52]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B9A430001A2; Wed, 27 Nov 2024 17:21:57 +0000 (UTC) From: Kevin Traynor To: Alan Elder Cc: Long Li , dpdk stable Subject: patch 'net/netvsc: fix using Tx queue higher than Rx queues' has been queued to stable release 21.11.9 Date: Wed, 27 Nov 2024 17:18:17 +0000 Message-ID: <20241127171916.690404-70-ktraynor@redhat.com> In-Reply-To: <20241127171916.690404-1-ktraynor@redhat.com> References: <20241127171916.690404-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: u0JbhfulKLQcE86mDhbt3qwiMlree92-kbKAUDS732U_1732728119 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org 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 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 Signed-off-by: Long Li --- 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@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)