Vhost-User: Fix bind sockaddr length
[vpp.git] / vnet / vnet / devices / virtio / vhost-user.c
index 9747b92..7dc7d0e 100644 (file)
@@ -140,7 +140,7 @@ static int vhost_user_name_renumber (vnet_hw_interface_t * hi,
 }
 
 
-static inline void * map_guest_mem(vhost_user_intf_t * vui, u64 addr)
+static inline void * map_guest_mem(vhost_user_intf_t * vui, uword addr)
 {
   int i;
   for (i=0; i<vui->nregions; i++) {
@@ -153,7 +153,7 @@ static inline void * map_guest_mem(vhost_user_intf_t * vui, u64 addr)
   return 0;
 }
 
-static inline void * map_user_mem(vhost_user_intf_t * vui, u64 addr)
+static inline void * map_user_mem(vhost_user_intf_t * vui, uword addr)
 {
   int i;
   for (i=0; i<vui->nregions; i++) {
@@ -1031,7 +1031,7 @@ static u32 vhost_user_if_input ( vlib_main_t * vm,
         error = VHOST_USER_INPUT_FUNC_ERROR_UNDERSIZED_FRAME;
       }
 
-      VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b);
+      VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b_head);
 
       vnet_buffer (b_head)->sw_if_index[VLIB_RX] = vui->sw_if_index;
       vnet_buffer (b_head)->sw_if_index[VLIB_TX] = (u32)~0;
@@ -1144,6 +1144,8 @@ VLIB_REGISTER_NODE (vhost_user_input_node) = {
   },
 };
 
+VLIB_NODE_FUNCTION_MULTIARCH (vhost_user_input_node, vhost_user_input)
+
 static uword
 vhost_user_intfc_tx (vlib_main_t * vm,
                  vlib_node_runtime_t * node,
@@ -1216,7 +1218,8 @@ vhost_user_intfc_tx (vlib_main_t * vm,
         error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
         goto done;
       }
-      CLIB_PREFETCH(buffer_addr, clib_min(rxvq->desc[desc_current].len, 500), STORE);
+      CLIB_PREFETCH(buffer_addr, clib_min(rxvq->desc[desc_current].len,
+       4*CLIB_CACHE_LINE_BYTES), STORE);
 
       virtio_net_hdr_mrg_rxbuf_t * hdr = (virtio_net_hdr_mrg_rxbuf_t *) buffer_addr;
       hdr->hdr.flags = 0;
@@ -1372,6 +1375,9 @@ VNET_DEVICE_CLASS (vhost_user_dev_class,static) = {
   .no_flatten_output_chains = 1,
 };
 
+VLIB_DEVICE_TX_FUNCTION_MULTIARCH (vhost_user_dev_class,
+                                  vhost_user_intfc_tx)
+
 static uword
 vhost_user_process (vlib_main_t * vm,
               vlib_node_runtime_t * rt,
@@ -1481,8 +1487,8 @@ int vhost_user_delete_if(vnet_main_t * vnm, vlib_main_t * vm,
 // init server socket on specified sock_filename
 static int vhost_user_init_server_sock(const char * sock_filename, int *sockfd)
 {
-  int rv = 0, len;
-  struct sockaddr_un un;
+  int rv = 0;
+  struct sockaddr_un un = {};
   int fd;
   /* create listening socket */
   fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -1497,9 +1503,7 @@ static int vhost_user_init_server_sock(const char * sock_filename, int *sockfd)
   /* remove if exists */
   unlink( (char *) sock_filename);
 
-  len = strlen((char *) un.sun_path) + strlen((char *) sock_filename);
-
-  if (bind(fd, (struct sockaddr *) &un, len) == -1) {
+  if (bind(fd, (struct sockaddr *) &un, sizeof(un)) == -1) {
     rv = VNET_API_ERROR_SYSCALL_ERROR_2;
     goto error;
   }
@@ -1642,7 +1646,7 @@ static void vhost_user_vui_register(vlib_main_t * vm, vhost_user_intf_t *vui)
   if (tm->n_vlib_mains == 1)
     vlib_node_set_state (vm, vhost_user_input_node.index,
                          VLIB_NODE_STATE_POLLING);
-  else if (!dm->have_io_threads)
+  else
     vlib_node_set_state (vlib_mains[cpu_index], vhost_user_input_node.index,
                          VLIB_NODE_STATE_POLLING);
 
@@ -1659,18 +1663,10 @@ int vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
                          u8 *hwaddr)
 {
   vhost_user_intf_t * vui = NULL;
-  dpdk_main_t * dm = &dpdk_main;
-  vlib_thread_main_t * tm = vlib_get_thread_main();
   u32 sw_if_idx = ~0;
   int sockfd = -1;
   int rv = 0;
 
-  if (tm->n_vlib_mains > 1 && dm->have_io_threads)
-    {
-      clib_warning("vhost-user interfaces are not supported with multiple io threads");
-      return -1;
-    }
-
   if (is_server) {
       if ((rv = vhost_user_init_server_sock (sock_filename, &sockfd)) != 0) {
           return rv;
@@ -1780,12 +1776,16 @@ vhost_user_connect_command_fn (vlib_main_t * vm,
 
   vnet_main_t *vnm = vnet_get_main();
 
-  vhost_user_create_if(vnm, vm, (char *)sock_filename,
+  int rv;
+  if ((rv = vhost_user_create_if(vnm, vm, (char *)sock_filename,
                        is_server, &sw_if_index, feature_mask,
-                       renumber, custom_dev_instance, hw);
+                       renumber, custom_dev_instance, hw))) {
+      vec_free(sock_filename);
+      return clib_error_return (0, "vhost_user_create_if returned %d", rv);
+  }
 
   vec_free(sock_filename);
-
+  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
   return 0;
 }
 
@@ -1948,7 +1948,7 @@ show_vhost_user_command_fn (vlib_main_t * vm,
         vui->regions[j].memory_size,
         vui->regions[j].userspace_addr,
         vui->regions[j].mmap_offset,
-        (u64) vui->region_mmap_addr[j]);
+        pointer_to_uword( vui->region_mmap_addr[j]) );
     }
     for (q = 0; q < vui->num_vrings; q++) {
       vlib_cli_output(vm, "\n Virtqueue %d\n", q);
@@ -1981,7 +1981,7 @@ show_vhost_user_command_fn (vlib_main_t * vm,
             vui->vrings[q].desc[j].len,
             vui->vrings[q].desc[j].flags,
             vui->vrings[q].desc[j].next,
-            (u64) map_guest_mem(vui, vui->vrings[q].desc[j].addr));}
+            pointer_to_uword(map_guest_mem(vui, vui->vrings[q].desc[j].addr)));}
       }
     }
     vlib_cli_output (vm, "\n");