patches for DPDK stable branches
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@redhat.com>
To: stable@dpdk.org, xuemingl@nvidia.com
Cc: dkozlyuk@nvidia.com
Subject: [PATCH 20.11] net/mlx5: do not close stdin on error
Date: Fri, 12 Nov 2021 09:44:35 +0100	[thread overview]
Message-ID: <20211112084435.26358-1-david.marchand@redhat.com> (raw)

[ upstream commit 7f49dafe0534b8a8614492c052d7fbe2e87dc6ae ]

If for any reason, a socket could not be opened, mlx5_pmd_socket_init()
could close the 0 fd (which is valid, and has a fair chance to be stdin),
since server_socket == 0 from the variable being in .bss.

Fixes: e6cdc54cc0ef ("net/mlx5: add socket server for external tools")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_socket.c | 29 ++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_socket.c b/drivers/net/mlx5/linux/mlx5_socket.c
index b1f41bc102..24dea5e3c7 100644
--- a/drivers/net/mlx5/linux/mlx5_socket.c
+++ b/drivers/net/mlx5/linux/mlx5_socket.c
@@ -18,7 +18,7 @@
 
 #define MLX5_SOCKET_PATH "/var/tmp/dpdk_net_mlx5_%d"
 
-int server_socket; /* Unix socket for primary process. */
+int server_socket = -1; /* Unix socket for primary process. */
 struct rte_intr_handle server_intr_handle; /* Interrupt handler. */
 
 /**
@@ -117,7 +117,7 @@ mlx5_pmd_socket_handle(void *cb __rte_unused)
 static int
 mlx5_pmd_interrupt_handler_install(void)
 {
-	MLX5_ASSERT(server_socket);
+	MLX5_ASSERT(server_socket != -1);
 	server_intr_handle.fd = server_socket;
 	server_intr_handle.type = RTE_INTR_HANDLE_EXT;
 	return rte_intr_callback_register(&server_intr_handle,
@@ -130,7 +130,7 @@ mlx5_pmd_interrupt_handler_install(void)
 static void
 mlx5_pmd_interrupt_handler_uninstall(void)
 {
-	if (server_socket) {
+	if (server_socket != -1) {
 		mlx5_intr_callback_unregister(&server_intr_handle,
 					      mlx5_pmd_socket_handle,
 					      NULL);
@@ -158,7 +158,7 @@ mlx5_pmd_socket_init(void)
 	int flags;
 
 	MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
-	if (server_socket)
+	if (server_socket != -1)
 		return 0;
 	/*
 	 * Initialize the socket to communicate with the secondary
@@ -173,10 +173,10 @@ mlx5_pmd_socket_init(void)
 	server_socket = ret;
 	flags = fcntl(server_socket, F_GETFL, 0);
 	if (flags == -1)
-		goto error;
+		goto close;
 	ret = fcntl(server_socket, F_SETFL, flags | O_NONBLOCK);
 	if (ret < 0)
-		goto error;
+		goto close;
 	snprintf(sun.sun_path, sizeof(sun.sun_path), MLX5_SOCKET_PATH,
 		 getpid());
 	remove(sun.sun_path);
@@ -184,25 +184,26 @@ mlx5_pmd_socket_init(void)
 	if (ret < 0) {
 		DRV_LOG(WARNING,
 			"cannot bind mlx5 socket: %s", strerror(errno));
-		goto close;
+		goto remove;
 	}
 	ret = listen(server_socket, 0);
 	if (ret < 0) {
 		DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s",
 			strerror(errno));
-		goto close;
+		goto remove;
 	}
 	if (mlx5_pmd_interrupt_handler_install()) {
 		DRV_LOG(WARNING, "cannot register interrupt handler for mlx5 socket: %s",
 			strerror(errno));
-		goto close;
+		goto remove;
 	}
 	return 0;
-close:
+remove:
 	remove(sun.sun_path);
-error:
+close:
 	claim_zero(close(server_socket));
-	server_socket = 0;
+	server_socket = -1;
+error:
 	DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno));
 	return -errno;
 }
@@ -212,11 +213,11 @@ mlx5_pmd_socket_init(void)
  */
 RTE_FINI(mlx5_pmd_socket_uninit)
 {
-	if (!server_socket)
+	if (server_socket == -1)
 		return;
 	mlx5_pmd_interrupt_handler_uninstall();
 	claim_zero(close(server_socket));
-	server_socket = 0;
+	server_socket = -1;
 	MKSTR(path, MLX5_SOCKET_PATH, getpid());
 	claim_zero(remove(path));
 }
-- 
2.23.0


             reply	other threads:[~2021-11-12  8:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12  8:44 David Marchand [this message]
2021-11-27 14:37 ` Xueming(Steven) Li

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=20211112084435.26358-1-david.marchand@redhat.com \
    --to=david.marchand@redhat.com \
    --cc=dkozlyuk@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=xuemingl@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).