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 BA3B545C9B for ; Tue, 12 Nov 2024 23:08:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AAD3040667; Tue, 12 Nov 2024 23:08:04 +0100 (CET) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mails.dpdk.org (Postfix) with ESMTP id 187ED40667 for ; Tue, 12 Nov 2024 23:08:04 +0100 (CET) Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-382026ba43eso1591429f8f.1 for ; Tue, 12 Nov 2024 14:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731449284; x=1732054084; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/dijgoq6fBqHofe9x13MtYrt1Lgj4DR8PXlUT3Tt8ig=; b=XWRxeN2ZH/GYBjrg0ajUX2cF+U5Zy05u5Q2Rcw7mwHMx9jk90pxh9p4dcHUFBrnY32 aneyUSEZ7uB5+e3OoHTljbWikWS/pW/Q1W83KNUQN3YXI0RTiTwt+PHOj+48bijojCuU ur2OqdlxRYbkmIoGYTNRkI15XNvD+yYBVNcvCYoeBH+xSRd/sVW/KgFEPZtlXZKM1uHy 3AxyCUwa5oG3hhX5FOh2HK+HC5VFjYqvmwflh6K2xykyQiIQA6dGhqceRsfCaLtEOQ9Y RbUKkppfluseNXarK7nngIRIBBAFnWQNcmV3fOUQ+4CuYTtvBmq+xE8Op0LywJ4+bSBW gaHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731449284; x=1732054084; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/dijgoq6fBqHofe9x13MtYrt1Lgj4DR8PXlUT3Tt8ig=; b=ExWOkZWnVIWJkcdkjxOUzlKBCLC++oBU1NkRK8YYTybfWNkz2V7UCwvUuEGgbAorZH 7xwwm5w2fLqKKqjUPMclG++4ubgs3vmyS43z6K1eNtF7EtEX/MAg/3RYNR6XWBUEqKEU Mu34tNlIqURw8zFyLGjyeG2XU0gG38oZWPmh4QG5RXW68nkjbQauqjzQvZszEefyG5tm lbCyDl3gbG84FHkQDt8THbQQMi8A6RsDmk5DZkfcXRTx2l/xIc27AfTxER9mGmkYnpYz LboiNLCPej5sodTO5Zt3iNsEmymf2mqyiApLWmZZtCrOYTCwK15E/RfkxSi/G3qLKhZ2 bq5w== X-Forwarded-Encrypted: i=1; AJvYcCUOM3gbtSvWzD4BMrqu4MN8r8ztCfSJzIXFggxRQ0O6Q8UZdJJIKKHj/2gf9r2dBcJilrgdVfE=@dpdk.org X-Gm-Message-State: AOJu0YwgG0qWq9sFlk8mdTqMZxcmb7NitLtKOtKFQGi0aMu/HDY4CmNQ bAEldCSXi2t3vMxEQpYLOOE/kQeBZaNXEWI28JIhwIYdFd8fGi34 X-Google-Smtp-Source: AGHT+IGnyKTRDn7/kJfQTBYwf908i731uNaGuCtu1oiE8YpbEt4sULMi4Hvfz/0k7cBKr7RPQf5Lew== X-Received: by 2002:a5d:5f53:0:b0:381:f595:fd0a with SMTP id ffacd0b85a97d-3820810ffc0mr2889481f8f.16.1731449283556; Tue, 12 Nov 2024 14:08:03 -0800 (PST) Received: from localhost ([2a01:4b00:d036:ae00:e89d:e9a1:da72:2f9d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed97e206sm16229468f8f.25.2024.11.12.14.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 14:08:02 -0800 (PST) From: luca.boccassi@gmail.com 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 22.11.7 Date: Tue, 12 Nov 2024 22:07:12 +0000 Message-ID: <20241112220754.666489-2-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241112220754.666489-1-luca.boccassi@gmail.com> References: <20241023211704.1216956-79-luca.boccassi@gmail.com> <20241112220754.666489-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 22.11.7 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/14/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/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/44c959d8c30e5383fcadfcb4be5a0475ca6fb828 Thanks. Luca Boccassi --- >From 44c959d8c30e5383fcadfcb4be5a0475ca6fb828 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 d0bbc0a4c0..73db9d38d9 100644 --- a/drivers/net/netvsc/hn_ethdev.c +++ b/drivers/net/netvsc/hn_ethdev.c @@ -313,6 +313,15 @@ 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; + } } err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE); diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c index 6496979f28..fc9df9f3b4 100644 --- a/drivers/net/netvsc/hn_rxtx.c +++ b/drivers/net/netvsc/hn_rxtx.c @@ -234,6 +234,17 @@ static void hn_reset_txagg(struct hn_tx_queue *txq) txq->agg_prevpkt = NULL; } +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, uint16_t queue_idx, uint16_t nb_desc, @@ -243,6 +254,7 @@ 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; int err = -ENOMEM; @@ -301,6 +313,27 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, goto error; } + /* + * 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; txq->agg_align = hv->rndis_agg_align; @@ -311,12 +344,15 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, socket_id, tx_conf); if (err == 0) { dev->data->tx_queues[queue_idx] = txq; + if (rxq != NULL) + dev->data->rx_queues[queue_idx] = rxq; return 0; } 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; } @@ -363,6 +399,12 @@ 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]); rte_mempool_free(txq->txdesc_pool); @@ -552,10 +594,12 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb, const struct hn_rxinfo *info) { 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 = &rte_eth_devices[rxq->port_id]; @@ -942,7 +986,15 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, if (queue_idx == 0) { 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; } @@ -975,9 +1027,10 @@ 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; } @@ -998,9 +1051,7 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary) if (keep_primary && rxq == rxq->hv->primary) return; - rte_free(rxq->rxbuf_info); - rte_free(rxq->event_buf); - rte_free(rxq); + hn_rx_queue_free_common(rxq); } void -- 2.45.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-11-12 22:06:58.765987433 +0000 +++ 0002-net-netvsc-fix-using-Tx-queue-higher-than-Rx-queues.patch 2024-11-12 22:06:58.627306574 +0000 @@ -1 +1 @@ -From e90020535c03cf9e60448ba623cac3301f111dae Mon Sep 17 00:00:00 2001 +From 44c959d8c30e5383fcadfcb4be5a0475ca6fb828 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 d0bbc0a4c0..73db9d38d9 100644 @@ -49 +50 @@ -index 870f62e5fa..52aedb001f 100644 +index 6496979f28..fc9df9f3b4 100644 @@ -52 +53 @@ -@@ -222,6 +222,17 @@ static void hn_reset_txagg(struct hn_tx_queue *txq) +@@ -234,6 +234,17 @@ static void hn_reset_txagg(struct hn_tx_queue *txq) @@ -70 +71 @@ -@@ -231,6 +242,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, +@@ -243,6 +254,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, @@ -78 +79 @@ -@@ -289,6 +301,27 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, +@@ -301,6 +313,27 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, @@ -106 +107 @@ -@@ -299,12 +332,15 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, +@@ -311,12 +344,15 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, @@ -122 +123 @@ -@@ -351,6 +387,12 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid) +@@ -363,6 +399,12 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid) @@ -135 +136 @@ -@@ -540,10 +582,12 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb, +@@ -552,10 +594,12 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb, @@ -150 +151 @@ -@@ -930,7 +974,15 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, +@@ -942,7 +986,15 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, @@ -167 +168 @@ -@@ -963,9 +1015,10 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, +@@ -975,9 +1027,10 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, @@ -181 +182 @@ -@@ -986,9 +1039,7 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary) +@@ -998,9 +1051,7 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_primary)