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 192A843CED; Tue, 19 Mar 2024 15:16:54 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A857C40298; Tue, 19 Mar 2024 15:16:53 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2129.outbound.protection.outlook.com [40.107.20.129]) by mails.dpdk.org (Postfix) with ESMTP id 8230740041 for ; Tue, 19 Mar 2024 15:16:51 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LUDDoJVEh1gXEDECv+FP+pscjHc5xb78cKSo9FZ1GTicsrV2gPiidNwwkxHyxZAq7gBy7tWlpE7tEMgQ6dyxEnb/4gb9Vl04+KqyCRnh97J/5T//d3c4O06P7WUvFHiRP204xIKp9sUnYE7YSyktvLsDdbUWqCfsEdnggxhmdkwYx5mVL3+nXzYOF0ujlkCgL6AvULMwNzfXU0N5iGdanXDrMyGM1Iu5ddYOg/cSWKVs0ocVKOH+VZynVlmB+eTDuou2IDAIXc4vJgVKtOv6Po2DY3F1V40Xfn4KQg+wJNoAUWeoyn+ZYX/+3jQ2oqkisqaIK6cnTgdmDm6wA0dhQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YendMzuVWEnoLuMtF3E5ZkC551L+cQkVb3+aIdnBheg=; b=CY9HdfNlureb2FE/XoIQI5wZY7JxL8kfnADXURz76hu1JaRyHNhl5HwgOFxORT+d0TN64LwW3Ebk13cRcATEOF3yDL/O/k40IBw2as8BHFLpAnPJquuvoLOxMjGVInXhlpayZMuJBNP5BNu5yfMJGrxTVHq0KxrcMfkpznbqQPUDSdPNk/Uij9fe4z8qcalXMcCqv5sBGvWTtr1qiUW0pUKHq5MSik3xvZLPEW/n52+1S4oF9mcFXt20nOm8fqOZJvVekHgyX9fUoOu0TkrZShFZh77UAdECYUKSbGbnhpBLw+VVLM0L2Gf8aqS5JNZ40++LECTldDI/t6vDCc/M1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YendMzuVWEnoLuMtF3E5ZkC551L+cQkVb3+aIdnBheg=; b=FC0tyBL8U473b1QRYf1dh7MzpgkOs/r1nCDxMLBOIe44sYiZj9euyECPa81b6Gja7tV5Smg5y8IwZzFy16bczOYeDRV/R9OqjBi+KJ9F3jJCYqxQobBvvgMgeXMZG16wZJYMGB9nZU5itAvx9R3DkZSfM9NG70Ei/m+WtS8f08M= Received: from PA4PR83MB0526.EURPRD83.prod.outlook.com (2603:10a6:102:26b::17) by AM7PR83MB0401.EURPRD83.prod.outlook.com (2603:10a6:20b:1be::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12; Tue, 19 Mar 2024 14:16:46 +0000 Received: from PA4PR83MB0526.EURPRD83.prod.outlook.com ([fe80::f0b:6b7f:eef8:2bcc]) by PA4PR83MB0526.EURPRD83.prod.outlook.com ([fe80::f0b:6b7f:eef8:2bcc%2]) with mapi id 15.20.7409.010; Tue, 19 Mar 2024 14:16:46 +0000 From: Alan Elder To: Long Li , Ferruh Yigit , Andrew Rybchenko CC: "dev@dpdk.org" , stephen Subject: [PATCH v3] net/netvsc: fix number Tx queues > Rx queues Thread-Topic: [PATCH v3] net/netvsc: fix number Tx queues > Rx queues Thread-Index: AQHaeggTqFpeoId2+UWfevTY136nBg== Date: Tue, 19 Mar 2024 14:16:46 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=979ac031-206c-4225-b627-540697dac625; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2024-02-29T19:11:26Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PA4PR83MB0526:EE_|AM7PR83MB0401:EE_ x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2tz5PnoysicaCvrGyWbdVXa6gl5tEH3frPRUPj5WMP2Ar2chLvRfPf5rorXG4/tCDfPi5As0IvDN6vEjtWL7jyJGYEdJmEPLHWlfPRcime7APJyuQNvSU/H7eh1aJ9pnKrNbpXOvkMxkX+K8HiwHZtTwxdjfhAYAihDzpAZdZJcA8TrAOrY+3Uv5Vh1t0To4eaE0mcrDNrVgo6byFFd5qYgjOb9VDYDUluieU81DprXWMeq84NEEceleVdWV2x2e0Ovt3OJqu9hMfKZRG7iCBnfzZb9QHZOtcZRXqEmwvZCX1+6+4DRkrZ+C5Mg/U/HjuQYP/eix/ldS1+wfN3f+1LCZET8521l7FTnPdqzlix74JLxV+b4h/LWT9MPmbnfoVwMciU99KPZmsc6TtWT0wrzAx7Eisb0XLV+Xx7AtILaOlGg2GHhDeClUQaCo4Zaq5hRaYyQRnyrczhCJK7CnXpNWeNwKnmAGrrgBrJrvXI+DkUfqOjVCIb6Ye4Z+/Z5/e3DbCHjOucp9TW6Vib3OIYXubem6LMH8eJ0yupAF/3KwrwIQo7Wvr72q5L5D0cd8LeO44xfhQ8lZwMVuWYnCm1b+Ic4JtUAozTDrumuDZQtWkrxU1JiZab5o6NZJA0VeyoWoXJK8NIZovpIEQB6N9a6hkTj4lD8Vn0XHZMPpG5w= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR83MB0526.EURPRD83.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(1800799015)(366007)(376005); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?4anX2cCDZpQ3B1PkKd+AWiymjsjFt+mdYfk+N0rS8UjrXsMpSNgxW113RFKK?= =?us-ascii?Q?qCDbJMTDTwU9vqPvLL8AOcN3/HLPWhsTj8u6fgERAIPccaKp98msbp1xlJiC?= =?us-ascii?Q?Dh6/POV8ITjEGPKinDtjdke4yv4VdBirxISyCduy6LR5EWuVcP50XhIKVCzL?= =?us-ascii?Q?Bd+i7pZn+5ni2VZS3s296QCpg84it7irXWBJDnoqlubaUErMPXntzIXAZkzG?= =?us-ascii?Q?K/0VyRP16tPvuocRs1bkaqOfLq5DGxNFonJw4T7JUlZyFiMR9k7fGuU+FD1C?= =?us-ascii?Q?pQMtotOH+HODyBknlT7xammczm/bnMuchWyIwOvJyHpDFiboDZVQ4x5Ea7Zf?= =?us-ascii?Q?G/rbtz/wmYeHFQ9NEdzcgyX8XKahOkf7Qj2sLiT9oRV7te01/4nhiLqDytps?= =?us-ascii?Q?VfFz195Rm1DyobtWNZMOUSR3UW68dMi5U+JcBSAlJx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ihpF4CN3QAdLrl1cUmgUqf7r/LeWkLo2fuiec7mz?= =?us-ascii?Q?K/ku5SovcW4qDCVt/xT93MPs9lXLK+C+ilIVK3FH+EwdjmAJMOYUXGfxsNbQ?= =?us-ascii?Q?mVELLLjH26eKW6V2rrw7YLC3P1K+SRVkbNKbsEVVfpO4urupYHmUO+2oDfUT?= =?us-ascii?Q?MQsMhPa+K1qWyGm5UQYEzLgdKENmRe3g32Tm?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR83MB0526.EURPRD83.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2df7f4a0-3f15-4c61-b35c-08dc481f35e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2024 14:16:46.4991 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: t6AM08LU70NfkJjkMQtxEnpELV8ooAUmNKuj2iIbXM0m8vL+OBD4EiPVV0zJTynUr02ZY1rJe8+gCe3BXDCkrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR83MB0401 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 >=3D number Rx queues there was a segfault. 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") Cc: sthemmin@microsoft.com Cc: stable@dpdk.org Signed-off-by: Alan Elder --- v3: * Handle case of Rx queue creation failure in hn_dev_tx_queue_setup. * Re-use rx queue if it has already been allocated. * Don't allocate an mbuf if pool is NULL. This avoids segfault if RSS configuration is incorrect. v2: * Remove function declaration for static non-member function --- drivers/net/netvsc/hn_ethdev.c | 9 +++++ drivers/net/netvsc/hn_rxtx.c | 70 +++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.= c index b8a32832d7..d7e3f12346 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, =20 if (reta_conf[idx].mask & mask) hv->rss_ind[i] =3D 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] >=3D dev->data->nb_rx_queues) { + PMD_DRV_LOG(ERR, "RSS distributing traffic to invalid Rx queue"); + return -EINVAL; + } } =20 err =3D 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 9bf1ec5509..e23880c176 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 =3D NULL; } =20 +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 =3D dev->data->dev_private; struct hn_tx_queue *txq; + struct hn_rx_queue *rxq =3D NULL; char name[RTE_MEMPOOL_NAMESIZE]; uint32_t tx_free_thresh; int err =3D -ENOMEM; @@ -301,6 +313,27 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, goto error; } =20 + /* + * 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 >=3D dev->data->nb_rx_queues) { + rxq =3D hn_rx_queue_alloc(hv, queue_idx, socket_id); + + if (!rxq) { + err =3D -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 =3D NULL; + rxq->rx_ring =3D NULL; + } + txq->agg_szmax =3D RTE_MIN(hv->chim_szmax, hv->rndis_agg_size); txq->agg_pktmax =3D hv->rndis_agg_pkts; txq->agg_align =3D hv->rndis_agg_align; @@ -311,12 +344,15 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev, socket_id, tx_conf); if (err =3D=3D 0) { dev->data->tx_queues[queue_idx] =3D txq; + if (rxq !=3D NULL) + dev->data->rx_queues[queue_idx] =3D rxq; return 0; } =20 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; } @@ -364,6 +400,13 @@ hn_dev_tx_queue_release(struct rte_eth_dev *dev, uint1= 6_t qid) if (!txq) return; =20 + /* + * Free any Rx queues allocated for a Tx queue without a corresponding + * Rx queue + */ + if (qid >=3D dev->data->nb_rx_queues) + hn_rx_queue_free_common(dev->data->rx_queues[qid]); + rte_mempool_free(txq->txdesc_pool); =20 rte_memzone_free(txq->tx_rndis_mz); @@ -552,10 +595,12 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct = hn_rx_bufinfo *rxb, const struct hn_rxinfo *info) { struct hn_data *hv =3D rxq->hv; - struct rte_mbuf *m; + struct rte_mbuf *m =3D NULL; bool use_extbuf =3D false; =20 - m =3D rte_pktmbuf_alloc(rxq->mb_pool); + if (likely(rxq->mb_pool !=3D NULL)) + m =3D rte_pktmbuf_alloc(rxq->mb_pool); + if (unlikely(!m)) { struct rte_eth_dev *dev =3D &rte_eth_devices[rxq->port_id]; @@ -942,7 +987,15 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, if (queue_idx =3D=3D 0) { rxq =3D hv->primary; } else { - rxq =3D 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 =3D hn_rx_queue_alloc(hv, queue_idx, socket_id); + else + rxq =3D dev->data->rx_queues[queue_idx]; + if (!rxq) return -ENOMEM; } @@ -975,9 +1028,10 @@ hn_dev_rx_queue_setup(struct rte_eth_dev *dev, =20 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; } =20 @@ -998,9 +1052,7 @@ hn_rx_queue_free(struct hn_rx_queue *rxq, bool keep_pr= imary) if (keep_primary && rxq =3D=3D rxq->hv->primary) return; =20 - rte_free(rxq->rxbuf_info); - rte_free(rxq->event_buf); - rte_free(rxq); + hn_rx_queue_free_common(rxq); } =20 void --=20 2.25.1