vhost-user: fix missing speculative enqueue unwind
[vpp.git] / src / vnet / devices / virtio / vhost-user.c
index 3fbcee9..9b8c188 100644 (file)
@@ -1677,6 +1677,10 @@ vhost_user_if_input (vlib_main_t * vm,
                  if (PREDICT_FALSE
                      (vum->cpus[cpu_index].rx_buffers_len == 0))
                    {
+                     /* Cancel speculation */
+                     to_next--;
+                     n_left_to_next++;
+
                      /*
                       * Checking if there are some left buffers.
                       * If not, just rewind the used buffers and stop.
@@ -2326,12 +2330,16 @@ vhost_user_process (vlib_main_t * vm,
                           sizeof (sun.sun_path) - 1);
 
                  /* Avoid hanging VPP if the other end does not accept */
-                 fcntl(sockfd, F_SETFL, O_NONBLOCK);
+                 if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
+                      clib_unix_warning ("fcntl");
+
                  if (connect (sockfd, (struct sockaddr *) &sun,
                               sizeof (struct sockaddr_un)) == 0)
                    {
                      /* Set the socket to blocking as it was before */
-                     fcntl(sockfd, F_SETFL, 0);
+                      if (fcntl(sockfd, F_SETFL, 0) < 0)
+                        clib_unix_warning ("fcntl2");
+
                      vui->sock_errno = 0;
                      template.file_descriptor = sockfd;
                      template.private_data =
@@ -2386,12 +2394,19 @@ VLIB_REGISTER_NODE (vhost_user_process_node,static) = {
 static void
 vhost_user_term_if (vhost_user_intf_t * vui)
 {
+  int q;
+
   // Delete configured thread pinning
   vec_reset_length (vui->workers);
   // disconnect interface sockets
   vhost_user_if_disconnect (vui);
   vhost_user_update_iface_state (vui);
 
+  for (q = 0; q < VHOST_VRING_MAX_N; q++)
+    {
+      clib_mem_free ((void *) vui->vring_locks[q]);
+    }
+
   if (vui->unix_server_index != ~0)
     {
       //Close server socket
@@ -2422,9 +2437,6 @@ vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, u32 sw_if_index)
   // Disable and reset interface
   vhost_user_term_if (vui);
 
-  // Back to pool
-  pool_put (vum->vhost_user_interfaces, vui);
-
   // Reset renumbered iface
   if (hwif->dev_instance <
       vec_len (vum->show_dev_instance_by_real_dev_instance))
@@ -2432,6 +2444,10 @@ vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, u32 sw_if_index)
 
   // Delete ethernet interface
   ethernet_delete_interface (vnm, vui->hw_if_index);
+
+  // Back to pool
+  pool_put (vum->vhost_user_interfaces, vui);
+
   return rv;
 }