vhost: fix VDUSE devices registration

Message ID 20250131130957.293562-1-maxime.coquelin@redhat.com (mailing list archive)
State Awaiting Upstream
Delegated to: Maxime Coquelin
Headers
Series vhost: fix VDUSE devices registration |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing warning Testing issues
ci/iol-broadcom-Performance success Performance Testing PASS

Commit Message

Maxime Coquelin Jan. 31, 2025, 1:09 p.m. UTC
This patch fixes a regression in vhost_driver_register()
causing VDUSE devices registration to fail systematically
because the return value was initialized to -1 and not
changed later on for this type of devices.

Fixes: 4d2aa150769b ("vhost: remove check around mutex init")

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/socket.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
  

Comments

Chenbo Xia Feb. 6, 2025, 8:35 a.m. UTC | #1
> On Jan 31, 2025, at 21:09, Maxime Coquelin <maxime.coquelin@redhat.com> wrote:
> 
> External email: Use caution opening links or attachments
> 
> 
> This patch fixes a regression in vhost_driver_register()
> causing VDUSE devices registration to fail systematically
> because the return value was initialized to -1 and not
> changed later on for this type of devices.
> 
> Fixes: 4d2aa150769b ("vhost: remove check around mutex init")
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
> lib/vhost/socket.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
> index 433a42bf80..894a0f0dcb 100644
> --- a/lib/vhost/socket.c
> +++ b/lib/vhost/socket.c
> @@ -893,7 +893,6 @@ vhost_user_socket_mem_free(struct vhost_user_socket *vsocket)
> int
> rte_vhost_driver_register(const char *path, uint64_t flags)
> {
> -       int ret = -1;
>        struct vhost_user_socket *vsocket;
> 
>        if (!path)
> @@ -997,7 +996,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>        } else {
> #ifndef RTE_LIBRTE_VHOST_POSTCOPY
>                VHOST_CONFIG_LOG(path, ERR, "Postcopy requested but not compiled");
> -               ret = -1;
>                goto out_mutex;
> #endif
>        }
> @@ -1012,15 +1010,14 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>                } else {
>                        vsocket->is_server = true;
>                }
> -               ret = create_unix_socket(vsocket);
> -               if (ret < 0)
> +               if (create_unix_socket(vsocket) < 0)
>                        goto out_mutex;
>        }
> 
>        vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
> 
>        pthread_mutex_unlock(&vhost_user.mutex);
> -       return ret;
> +       return 0;
> 
> out_mutex:
>        if (pthread_mutex_destroy(&vsocket->conn_mutex)) {
> @@ -1028,8 +1025,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>        }
> out:
>        pthread_mutex_unlock(&vhost_user.mutex);
> -
> -       return ret;
> +       return -1;
> }
> 
> static bool
> --
> 2.48.1
> 

Reviewed-by: Chenbo Xia <chenbox@nvidia.com>
  
Maxime Coquelin Feb. 7, 2025, 2:12 p.m. UTC | #2
On 1/31/25 2:09 PM, Maxime Coquelin wrote:
> This patch fixes a regression in vhost_driver_register()
> causing VDUSE devices registration to fail systematically
> because the return value was initialized to -1 and not
> changed later on for this type of devices.
> 
> Fixes: 4d2aa150769b ("vhost: remove check around mutex init")
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>   lib/vhost/socket.c | 10 +++-------
>   1 file changed, 3 insertions(+), 7 deletions(-)
> 

Applied to next-virtio/for-next-net.

Thanks,
Maxime
  

Patch

diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index 433a42bf80..894a0f0dcb 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -893,7 +893,6 @@  vhost_user_socket_mem_free(struct vhost_user_socket *vsocket)
 int
 rte_vhost_driver_register(const char *path, uint64_t flags)
 {
-	int ret = -1;
 	struct vhost_user_socket *vsocket;
 
 	if (!path)
@@ -997,7 +996,6 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 	} else {
 #ifndef RTE_LIBRTE_VHOST_POSTCOPY
 		VHOST_CONFIG_LOG(path, ERR, "Postcopy requested but not compiled");
-		ret = -1;
 		goto out_mutex;
 #endif
 	}
@@ -1012,15 +1010,14 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 		} else {
 			vsocket->is_server = true;
 		}
-		ret = create_unix_socket(vsocket);
-		if (ret < 0)
+		if (create_unix_socket(vsocket) < 0)
 			goto out_mutex;
 	}
 
 	vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
 
 	pthread_mutex_unlock(&vhost_user.mutex);
-	return ret;
+	return 0;
 
 out_mutex:
 	if (pthread_mutex_destroy(&vsocket->conn_mutex)) {
@@ -1028,8 +1025,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 	}
 out:
 	pthread_mutex_unlock(&vhost_user.mutex);
-
-	return ret;
+	return -1;
 }
 
 static bool