[v2] vhost: fix crash on vhost-user client port deletion

Message ID 20230511145957.33904-1-suntianyuan@baidu.com (mailing list archive)
State New
Delegated to: Maxime Coquelin
Series [v2] vhost: fix crash on vhost-user client port deletion |


Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Functional success Functional PASS
ci/intel-Testing fail Testing issues

Commit Message

suntianyuan May 11, 2023, 2:59 p.m. UTC
  The rte_vhost_driver_unregister() and vhost_user_read_cb() can be
called at the same time by 2 threads. reconn may be added back to
reconn_list by vhost_user_read_cb() after rte_vhost_driver_unregister()
removed from reconn_list. Then rte_vhost_driver_unregister free vsocket,
cause vhost_user_client_reconnect access invalid vsocket memory.

Timeline is as below:
rte_vhost_driver_unregister thread execute vhost_user_remove_reconnect
vhost_user_read_cb thread execute vhost_user_start_client add reconn to
vhost_user_read_cb thread free conn
rte_vhost_driver_unregister thread cannot find conn, then execute
vhost_user_client_reconnect access invalid mem, crash

Signed-off-by: suntianyuan <suntianyuan@baidu.com>
* Fixed coding style issues.

 lib/vhost/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index 669c322e12..72c776d15c 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -1046,8 +1046,6 @@  rte_vhost_driver_unregister(const char *path)
 				goto again;
-		} else if (vsocket->reconnect) {
-			vhost_user_remove_reconnect(vsocket);
@@ -1080,6 +1078,8 @@  rte_vhost_driver_unregister(const char *path)
 		if (vsocket->is_server) {
+		} else if (vsocket->reconnect) {
+			vhost_user_remove_reconnect(vsocket);