From patchwork Mon Apr 15 14:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Elder X-Patchwork-Id: 139282 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org 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: 8S8n1WodLMUuCJHo1jem/HiXbK7Vy+sE1U0/wkz9XLEv+ANSGGdDmwfs8W6L6pLrY1QG89ZMnYNG2oER5nwJ+bpIA0b9yNl/4mA7LtI3LMfXZGZsLYXS6BUCv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aGztB5SEodtZ5vegfzo1aGYQNgr0EYrEIBJMS4c/oOaD2mSqUjYQCchsK/nqMPUbYhim7XtrDZgI4lgKgn/oZ8pUCSER0IccfA6DSR9/RCGyBe0A71xP+VJlV14AkylR/dxzJxyxgg4rP5Fx7W+/pWar7ur986u5J+g== 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: Aw1Bz5jPdxHB+4LmOT3YhcXB7vsPmpSduv317vHivBsPhqpt0XcpPIZ0z6Ln7Xhp9F3l8EX6cvYcTJr9a5oS8bHIoZEfSIQUPXtNwjPQo13n+If5015cgzMgr4dGjDEhpfeULg0vjKCRANvzqa/Y2snGGYQm24Q9e3lSujrA0GraMBmosuunhFujf4QLS50JORdDQGBh+HkbFVbRVAGAggBukpkYRnIPDX+IHIB+fM9lST80uyiNy3IHHEtVou3YJZhQWv7Lu8VdL0Rvf0B/TaXh6MeGvnXYqlv/CSGZJv0z+uwM4Yxp8KejiEDwBQf8ZY2WDTHe6oR0HBHwTvWbFfWaVotNe0lsUm1UeuW8MdFZivaeRRLNkXONshRk6/at/dHbNzqRUZriqSgRFJUeF+VYf1VQovXvYrTbrabgMk3Imluv3A7HlHTE9sTnmJ9vlPEpAUybmJMGZatEW6CzHE18QJoD1QKFAGEAg47w7FltvbcdF+VcilwxwnXUKBYAvu7O5dmk5/toJncQA90HTdveZ/VUQ6+ysxt1iJ4fN9eH53yMkrtJ3L1zQXnVJ5VZX4zFUqE5ayBeGR2ShPvj79S/CoDy1YQFKV1bexbhFC1zmNF0DEVx5lYVrghsqLiy2XtVVCcKoHfLng09U3QCbMufRPDbokSIct7Av9JPa59k4Fnm+QxOzHtirBvaeScNUo+wANwjJ3ApbPZjRcVrDAQ35kf8VVtQ+LKnTre9SFS+MJdNCZ7+INJ/RTEQpSL48gEXlHYhddAm9V4I2V4z/cPssKk8pCHhMvbDNmYoSxxgCc5buIeEAtvbziN2WZakSkKzkqZLpbaGZ7M3Y7g7TJqObhXrJTyEhwO/2BzRbpIsEEVvIRKNrnmOAKpwQQOayla8gm6piW/27FHj9NT6W0/fDnQi+Rx4LAZ/3a0+q10MehLbySEMcDzfTUtC+yO19cWX0ketoUUryXJUQz9jsC+DW4wMULZ645rykgjBrf1JZwGj3mJ8DeaX3O07MfYBW8P6WvW0oqVfnwJSfSHFRDsrOXUs5eDSZT9SZ/Jdl0nJA2eWTk52pEziQG/22mILtIl/GSMHaZp70ER+rPJFzkLzswnc1wX/nFGmlnYuCCyGgn6uAq3EcmK1Sk0CuGIlq8MC7v+8YstdpfvToemrzyEheqOHELVmmzxq+whne6Myc7WZ3ntG0Dbh6PDh8GmTnG1x86s4VPKpKx74fZ3q0hTR6h+h73ZTpGjDes22zPNG1FHhZYZoXqkAVbEwiOVfpVJyNfGIoc3Wvv5uSsUoKqBVP6ZqddYKuHdIabQYmcIgSIUbW7Fscdgnjm4esX2usfwwEKNdIIgSG/yozS9aLYyq1ewdB3LNuuwXgHYwGVPnTlHJScn56qKIWUzumwbp0EoXRUIxs9t8SA/BODEhYkbgYvvM+lpQjIleHGcfYEXplPPtgaNdLtauN9C8PlP2fY2UJjD3fqqjveJx/u3LuozCjjIFWmETtvGci/Ved4P6MYsbpEkhE6rn9GiNxkxU89FIjzJh5IB2R+iW6yUXtzHo6JMfOveA1xgxmefkuNTe52eZEnhIuEno5Uzy5mRL 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 >= 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 = 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 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 --- 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(-) 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; } @@ -364,6 +400,13 @@ 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); 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 = 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 +987,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 +1028,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 +1052,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.25.1 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, 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 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 = 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;