From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E6EA7A0524 for ; Mon, 7 Dec 2020 05:30:09 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A2EA2E07; Mon, 7 Dec 2020 05:30:08 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 0A08BE07 for ; Mon, 7 Dec 2020 05:30:05 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from suanmingm@nvidia.com) with SMTP; 7 Dec 2020 06:30:02 +0200 Received: from nvidia.com (mtbc-r640-04.mtbc.labs.mlnx [10.75.70.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 0B74U0xd010363; Mon, 7 Dec 2020 06:30:01 +0200 From: Suanming Mou To: viacheslavo@nvidia.com, matan@nvidia.com Cc: stable@dpdk.org, Suanming Mou Date: Mon, 7 Dec 2020 12:29:58 +0800 Message-Id: <1607315398-354529-1-git-send-email-suanmingm@nvidia.com> X-Mailer: git-send-email 1.8.3.1 Subject: [dpdk-stable] [PATCH 18.11] net/mlx5: fix secondary process resources release X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "stable" From: Suanming Mou [ upstream commit 2786b7bf9084b32dde9a346d92ab1c27f0ffc476 ] When secondary process starts, it will allocate its own process private data, and also does remap to UAR register of the Tx queue. Once the secondary process exits, these resources should be released accordingly. And the shared resources owned by primary should not be touched. Currently, once one port in the secondary process spawn failed, all the other spawned ports will also be released during process exits. However, the mlx5_dev_close() function does not add the cases for secondary process, it means call the mlx5_dev_close() function directly in secondary process releases the resources it should not touch. Add the case for secondary process release to its own resources in mlx5_dev_close() function to help it quits gracefully. Fixes: 3a8207423a0f ("net/mlx5: close all ports on remove") Signed-off-by: Suanming Mou Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5.c | 34 ++++++++++++++++++++++++++++------ drivers/net/mlx5/mlx5_rxtx.h | 1 + drivers/net/mlx5/mlx5_txq.c | 24 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 01fff19..f3503eb 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -304,6 +304,15 @@ unsigned int i; int ret; + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + /* Check if process_private released. */ + if (!dev->process_private) + return; + mlx5_tx_uar_uninit_secondary(dev); + mlx5_proc_priv_uninit(dev); + rte_eth_dev_release_port(dev); + return; + } DRV_LOG(DEBUG, "port %u closing device \"%s\"", dev->data->port_id, ((priv->ctx != NULL) ? priv->ctx->device->name : "")); @@ -849,26 +858,26 @@ DRV_LOG(ERR, "can not attach rte ethdev"); rte_errno = ENOMEM; err = rte_errno; - goto error; + goto err_secondary; } eth_dev->device = dpdk_dev; eth_dev->dev_ops = &mlx5_dev_sec_ops; err = mlx5_proc_priv_init(eth_dev); if (err) { err = rte_errno; - goto error; + goto err_secondary; } /* Receive command fd from primary process */ err = mlx5_socket_connect(eth_dev); if (err < 0) { err = rte_errno; - goto error; + goto err_secondary; } /* Remap UAR for Tx queues. */ err = mlx5_tx_uar_init_secondary(eth_dev, err); if (err) { err = rte_errno; - goto error; + goto err_secondary; } /* * Ethdev pointer is still required as input since @@ -879,6 +888,10 @@ eth_dev->tx_pkt_burst = mlx5_select_tx_function(eth_dev); claim_zero(mlx5_glue->close_device(ctx)); return eth_dev; +err_secondary: + if (eth_dev) + mlx5_dev_close(eth_dev); + return NULL; } /* Check port status. */ err = mlx5_glue->query_port(ctx, 1, &port_attr); @@ -1499,8 +1512,17 @@ struct mlx5_dev_spawn_data { for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) { port = &rte_eth_devices[port_id]; if (port->state != RTE_ETH_DEV_UNUSED && - port->device == &pci_dev->device) - rte_eth_dev_close(port_id); + port->device == &pci_dev->device) { + /* + * mlx5_dev_close() is not registered to secondary + * process, call the close function explicitly for + * secondary process. + */ + if (rte_eal_process_type() == RTE_PROC_SECONDARY) + mlx5_dev_close(&rte_eth_devices[port_id]); + else + rte_eth_dev_close(port_id); + } } return 0; } diff --git a/drivers/net/mlx5/mlx5_rxtx.h b/drivers/net/mlx5/mlx5_rxtx.h index dc2ca5e..583985b 100644 --- a/drivers/net/mlx5/mlx5_rxtx.h +++ b/drivers/net/mlx5/mlx5_rxtx.h @@ -311,6 +311,7 @@ int mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, int mlx5_txq_ibv_release(struct mlx5_txq_ibv *txq_ibv); int mlx5_txq_ibv_releasable(struct mlx5_txq_ibv *txq_ibv); int mlx5_txq_ibv_verify(struct rte_eth_dev *dev); +void mlx5_tx_uar_uninit_secondary(struct rte_eth_dev *dev); struct mlx5_txq_ctrl *mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, unsigned int socket, const struct rte_eth_txconf *conf); diff --git a/drivers/net/mlx5/mlx5_txq.c b/drivers/net/mlx5/mlx5_txq.c index 42ab34a..ea1e86d 100644 --- a/drivers/net/mlx5/mlx5_txq.c +++ b/drivers/net/mlx5/mlx5_txq.c @@ -321,6 +321,30 @@ } /** + * Deinitialize Tx UAR registers for secondary process. + * + * @param dev + * Pointer to Ethernet device. + */ +void +mlx5_tx_uar_uninit_secondary(struct rte_eth_dev *dev) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_txq_data *txq; + struct mlx5_txq_ctrl *txq_ctrl; + unsigned int i; + + assert(rte_eal_process_type() == RTE_PROC_SECONDARY); + for (i = 0; i != priv->txqs_n; ++i) { + if (!(*priv->txqs)[i]) + continue; + txq = (*priv->txqs)[i]; + txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq); + txq_uar_uninit_secondary(txq_ctrl); + } +} + +/** * Initialize Tx UAR registers for secondary process. * * @param dev -- 1.8.3.1