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 7147A43E7B; Mon, 15 Apr 2024 16:40:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E2F044026C; Mon, 15 Apr 2024 16:40:49 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2102.outbound.protection.outlook.com [40.107.21.102]) by mails.dpdk.org (Postfix) with ESMTP id DC83E400EF for ; Mon, 15 Apr 2024 16:40:48 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XS4SssZubSaw6WPSV7Oq7/Lbaf9QoHxr5Fw35YsmBvVDyQMU57Z1ZHs9I9e031+6jmlk9/qKFzaMhPkSaoPrCPirVTw57b6rSvw7EqrRnQhn0gYAtylqjma8xWmbNH5nMLUxTit+PuIXPHxQahOWzHwmRMQSrppra5ylnmBF+EQkCXkehngA1GT+O59ubCY28BVXtpf3I2ECKmbW3dYbaowwYF0Kw53PcpUnJjBr9Lgo5PHZ0Rz90YfUKh01XOh7L/h7sbzEaYx3CEdhkRbvR0tQ7z2+cFWnJa4Xz54Suk1+A8lkgUyZ1p7+U/rifJ6oYqGjj7bV9+bAhA5d8dVpdQ== 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=8UWPmYAHBnwmzVpMswF0+Ip1WAGvdksXVqGv+2S5r44=; b=Oie+MRMKIzD6j+QJbudP4pFTKXRcmz7gevewoSxKpU3DYw4adWC+xneHqeBJB8vPiUGogSQGOEUP6qbCR7lVFDCEyFO97nXfmi4mXGfM0+yL5kxmfJQghYH5jMAgAVDDyLEQ7lNLC/n+KEpX99V3FNyhc6zKtV30SBTzGtQJoN/E8Homm/6VIqU5u/pHB0hjFVt9hQICBB+4KwbQ/HLOY7sGPDsbSo9XKaa9C9hNYK+kdjHlaNZAss56cZAmwrzfYBLD8b3Ah/rnERhSjMMVLD2jL37X2Z2fZsr2V+7q8hHKMNcMFhGSUCHr/kYAlA5lDBvV2waAkQ3Neez4v+B2fA== 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=8UWPmYAHBnwmzVpMswF0+Ip1WAGvdksXVqGv+2S5r44=; b=PihYmPXSWXb79kW+2gQC9oa7Ip2kwNQiZVWOI2uq5JH9BDOLSkoEEwSqld4yfcsp4rJBPYEE2AffgNbmJJ/HHdhMtwLQ7Rifu1J1mGzKjrVDiaJPRhLxZU4mHoe6gZz+cBsP6/L63qg7nzQglk2b4JLSHx00aVfF1w0m9LwwEjI= Received: from PA4PR83MB0526.EURPRD83.prod.outlook.com (2603:10a6:102:26b::17) by PA4PR83MB0526.EURPRD83.prod.outlook.com (2603:10a6:102:26b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.6; Mon, 15 Apr 2024 14:40:45 +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.7519.005; Mon, 15 Apr 2024 14:40:45 +0000 From: Alan Elder To: Long Li , Ferruh Yigit , Andrew Rybchenko CC: "dev@dpdk.org" , stephen Subject: [PATCH v4] net/netvsc: fix number Tx queues > Rx queues Thread-Topic: [PATCH v4] net/netvsc: fix number Tx queues > Rx queues Thread-Index: AQHaj0LlOhmlskdRP0OAUkt+bSOHnA== Date: Mon, 15 Apr 2024 14:40:44 +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; authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PA4PR83MB0526:EE_ x-ms-office365-filtering-correlation-id: a05cacbc-25d5-47db-7976-08dc5d5a086b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|366007|376005|1800799015|38070700009; x-microsoft-antispam-message-info: =?us-ascii?Q?8S8n1WodLMUuCJHo1jem/HiXbK7Vy+sE1U0/wkz9XLEv+ANSGGdDmwfs8W6L?= =?us-ascii?Q?6pLrY1QG89ZMnYNG2oER5nwJ+bpIA0b9yNl/4mA7LtI3LMfXZGZsLYXS6BUC?= =?us-ascii?Q?vhRQuH9bzzElgmH2HPeKjm/3YKag2czPbPcYK5WCJyqPZZBDMslnn7Eim391?= =?us-ascii?Q?SK2f3myCZwgIoLThG/+Nukc2/3nvpjT/p36KE5lWzf8TftclndhD1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rcR72tJjKtUQ9zDQ0RivUI7mnTCze4oPrq?= =?us-ascii?Q?WVyp+wvr9uJlgiPvJUs/5Qom7p4iFOWRJCE3u+z3j3VTK3BAnwNcoMWLecWO?= =?us-ascii?Q?s1jaGztB5SEodtZ5vegfzo1aGYQNgr0EYrEIBJMS4c/oOaD2mSqUjYQCchsK?= =?us-ascii?Q?/nqMPUbYhim7XtrDZgI4lgKgn/oZ8pUCSER0IccfA6DSR9/RCGyBe0A71xP+?= =?us-ascii?Q?VJlV14AkylR/dxzJxyxgg4rP5Fx7W+/pWar7ur986u5J+g=3D=3D?= 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)(366007)(376005)(1800799015)(38070700009); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Aw1Bz5jPdxHB+4LmOT3YhcXB7vsPmpSduv317vHivBsPhqpt0XcpPIZ0z6Ln?= =?us-ascii?Q?7Xhp9F3l8EX6cvYcTJr9a5oS8bHIoZEfSIQUPXtNwjPQo13n+If5015cgzMg?= =?us-ascii?Q?r4dGjDEhpfeULg0vjKCRANvzqa/Y2snGGYQm24Q9e3lSujrA0GraMBmosuun?= =?us-ascii?Q?hFujf4QLS50JORdDQGBh+HkbFVbRVAGAggBukpkYRnIPDX+IHIB+fM9lST80?= =?us-ascii?Q?uyiNy3IHHEtVou3YJZhQWv7Lu8VdL0Rvf0B/TaXh6MeGvnXYqlv/CSGZJv0z?= =?us-ascii?Q?+uwM4Yxp8KejiEDwBQf8ZY2WDTHe6oR0HBHwTvWbFfWaVotNe0lsUm1UeuW8?= =?us-ascii?Q?MdFZivaeRRLNkXONshRk6/at/dHbNzqRUZriqSgRFJUeF+VYf1VQovXvYrTb?= =?us-ascii?Q?rabgMk3Imluv3A7HlHTE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= =?us-ascii?Q?mcIgSIUbW7Fscdgnjm4esX2usfwwEKNdIIgSG/yozS9aLYyq1ewdB3LNuuwX?= =?us-ascii?Q?gHYwGVPnTlHJScn56qKIWUzumwbp0EoXRUIxs9t8SA/BODEhYkbgYvvM+lpQ?= =?us-ascii?Q?jIleHGcfYEXplPPtgaNdLtauN9C8PlP2fY2UJjD3fqqjveJx/u3LuozCjjIF?= =?us-ascii?Q?WmETtvGci/Ved4P6MYsbpEkhE6rn9GiNxkxU89FIjzJh5IB2R+iW6yUXtzHo?= =?us-ascii?Q?6JMfOveA1xgxmefkuNTe52eZEnhIuEno5Uzy5mRL?= 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: a05cacbc-25d5-47db-7976-08dc5d5a086b X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2024 14:40:44.8935 (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: a4zVilRogmCwajlhjENmooGUJ4VkS5Pj6mOhCMo8hyXVR4lixUVsx6g4uUoGShqmdE6mFNL3GcljYKjLVefPSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR83MB0526 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 due to accessing beyond the end = of the dev->data->rx_queues[] array. #0 rte_spinlock_trylock (sl =3D invalid address) at /include/rte_spinlock.h= L63 #1 hn_process_events at /drivers/net/netvsc/hn_rxtx.c L 1129 #2 hn_xmit_pkts at /drivers/net/netvsc/hn_rxtx.c L1553 This commit fixes the issue by creating an Rx queue for every Tx queue mean= ing that an event buffer is allocated to handle receiving Tx completion mes= sages. 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 --- v4: * Include segfault core stack in commit message 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/driver= s/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c index 9bf1ec5509..e23= 880c176 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_t= x_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 -- 2.25.1