All of lore.kernel.org
 help / color / mirror / Atom feed
From: longli@linuxonhyperv.com
To: Matan Azrad <matan@nvidia.com>, Ferruh Yigit <ferruh.yigit@xilinx.com>
Cc: dev@dpdk.org, Karanjot Singh <ksingh1@paloaltonetworks.com>,
	Long Li <longli@microsoft.com>
Subject: [Patch v2] net/mlx5: fix verbs fd leak in the secondary process
Date: Wed,  6 Jul 2022 10:48:53 -0700	[thread overview]
Message-ID: <1657129733-12126-2-git-send-email-longli@linuxonhyperv.com> (raw)
In-Reply-To: <1657129733-12126-1-git-send-email-longli@linuxonhyperv.com>

From: Long Li <longli@microsoft.com>

FDs passed from rte_mp_msg are duplicated to the secondary process and
need to be closed.

Fixes: 9a8ab29b84 ("net/mlx5: replace IPC socket with EAL API")
Signed-off-by: Long Li <longli@microsoft.com>
---
Change in v2: handle error case where mlx5_proc_priv_init() might fail

 drivers/net/mlx5/linux/mlx5_mp_os.c | 6 +++++-
 drivers/net/mlx5/linux/mlx5_os.c    | 8 +++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_mp_os.c b/drivers/net/mlx5/linux/mlx5_mp_os.c
index c448a3e9eb..0ba2208fe0 100644
--- a/drivers/net/mlx5/linux/mlx5_mp_os.c
+++ b/drivers/net/mlx5/linux/mlx5_mp_os.c
@@ -177,14 +177,18 @@ struct rte_mp_msg mp_res;
 			mlx5_tx_uar_uninit_secondary(dev);
 			mlx5_proc_priv_uninit(dev);
 			ret = mlx5_proc_priv_init(dev);
-			if (ret)
+			if (ret) {
+				close(mp_msg->fds[0]);
 				return -rte_errno;
+			}
 			ret = mlx5_tx_uar_init_secondary(dev, mp_msg->fds[0]);
 			if (ret) {
+				close(mp_msg->fds[0]);
 				mlx5_proc_priv_uninit(dev);
 				return -rte_errno;
 			}
 		}
+		close(mp_msg->fds[0]);
 		rte_mb();
 		mp_init_msg(&priv->mp_id, &mp_res, param->type);
 		res->result = 0;
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index c29fe3d92b..69ae3c944b 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -933,6 +933,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name);
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
 		struct mlx5_mp_id mp_id;
+		int fd;
 
 		eth_dev = rte_eth_dev_attach_secondary(name);
 		if (eth_dev == NULL) {
@@ -949,11 +950,12 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			return NULL;
 		mlx5_mp_id_init(&mp_id, eth_dev->data->port_id);
 		/* Receive command fd from primary process */
-		err = mlx5_mp_req_verbs_cmd_fd(&mp_id);
-		if (err < 0)
+		fd = mlx5_mp_req_verbs_cmd_fd(&mp_id);
+		if (fd < 0)
 			goto err_secondary;
 		/* Remap UAR for Tx queues. */
-		err = mlx5_tx_uar_init_secondary(eth_dev, err);
+		err = mlx5_tx_uar_init_secondary(eth_dev, fd);
+		close(fd);
 		if (err)
 			goto err_secondary;
 		/*
-- 
2.17.1


  reply	other threads:[~2022-07-06 17:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 17:48 [Patch v2] net/mlx4: fix verbs fd leak in the secondary process longli
2022-07-06 17:48 ` longli [this message]
2022-07-07  9:43   ` [Patch v2] net/mlx5: " Slava Ovsiienko
2022-08-14 13:50   ` Raslan Darawsheh
2022-07-07  9:44 ` [Patch v2] net/mlx4: " Slava Ovsiienko
2022-08-14 13:50 ` Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1657129733-12126-2-git-send-email-longli@linuxonhyperv.com \
    --to=longli@linuxonhyperv.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@xilinx.com \
    --cc=ksingh1@paloaltonetworks.com \
    --cc=longli@microsoft.com \
    --cc=matan@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.