Skip to contentSkip to conversation

vhost: fix crash on unregistering in client mode

PATCH In review Qiang Zhou 2 participants 2 messages Sep 7, 2018 – Sep 27, 2018

lore
Share & tools
lore

Qiang Zhou

author
#0 lore raw

PATCH 1/1 vhost: fix crash on unregistering in client mode

when rte_vhost_driver_unregister delete the connection fd, the fd lock will prevent the vsocket to be freed. But when vhost_user_msg_handler return error, it will delete vsocket conn_list. And then the fd lock will become invalid. So the vsocket will be freed in rte_vhost_drivere_unregister and the vhost_user_read_cb will reconnect.

To fix this:
move delete vsocket conn after reconnect

---
 lib/librte_vhost/socket.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/librte_vhost/socket.c +5 -5
index d63031747..43da1c51b 100644
@@ -293,16 +293,16 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)
 		if (vsocket->notify_ops->destroy_connection)
 			vsocket->notify_ops->destroy_connection(conn->vid);
 
+		if (vsocket->reconnect) {
+			create_unix_socket(vsocket);
+			vhost_user_start_client(vsocket);
+		}
+
 		pthread_mutex_lock(&vsocket->conn_mutex);
 		TAILQ_REMOVE(&vsocket->conn_list, conn, next);
 		pthread_mutex_unlock(&vsocket->conn_mutex);
 
 		free(conn);
-
-		if (vsocket->reconnect) {
-			create_unix_socket(vsocket);
-			vhost_user_start_client(vsocket);
-		}
 	}
 }
 
Signature · 1 line
2.14.3 (Apple Git-98)
#1 lore raw

Hi Qiang,

Quoted 6 lines · Qiang Zhou

when rte_vhost_driver_unregister delete the connection fd, the fd lock will prevent the vsocket to be freed. But when vhost_user_msg_handler return error, it will delete vsocket conn_list. And then the fd lock will become invalid. So the vsocket will be freed in rte_vhost_drivere_unregister and the vhost_user_read_cb will reconnect.

I am not sure to understand the problem, could you please elaborate?

Quoted 38 lines

To fix this:
move delete vsocket conn after reconnect

---
  lib/librte_vhost/socket.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
lib/librte_vhost/socket.c +5 -5
index d63031747..43da1c51b 100644
@@ -293,16 +293,16 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)
  		if (vsocket->notify_ops->destroy_connection)
  			vsocket->notify_ops->destroy_connection(conn->vid);
 
+		if (vsocket->reconnect) {
+			create_unix_socket(vsocket);
+			vhost_user_start_client(vsocket);
+		}
+
  		pthread_mutex_lock(&vsocket->conn_mutex);
  		TAILQ_REMOVE(&vsocket->conn_list, conn, next);
  		pthread_mutex_unlock(&vsocket->conn_mutex);
 
  		free(conn);
-
-		if (vsocket->reconnect) {
-			create_unix_socket(vsocket);
-			vhost_user_start_client(vsocket);
-		}
  	}
  }