Remove c-11 memcpy checks from perf-critical code
[vpp.git] / src / vnet / devices / virtio / vhost_user.c
index a8a7ae8..d13ea3b 100644 (file)
@@ -73,7 +73,9 @@ get_huge_page_size (int fd)
 static void
 unmap_all_mem_regions (vhost_user_intf_t * vui)
 {
-  int i, r;
+  int i, r, q;
+  vhost_user_vring_t *vq;
+
   for (i = 0; i < vui->nregions; i++)
     {
       if (vui->region_mmap_addr[i] != MAP_FAILED)
@@ -89,21 +91,29 @@ unmap_all_mem_regions (vhost_user_intf_t * vui)
            munmap (vui->region_mmap_addr[i] - vui->regions[i].mmap_offset,
                    map_sz);
 
-         DBG_SOCK
-           ("unmap memory region %d addr 0x%lx len 0x%lx page_sz 0x%x", i,
-            vui->region_mmap_addr[i], map_sz, page_sz);
+         vu_log_debug (vui, "unmap memory region %d addr 0x%lx len 0x%lx "
+                       "page_sz 0x%x", i, vui->region_mmap_addr[i], map_sz,
+                       page_sz);
 
          vui->region_mmap_addr[i] = MAP_FAILED;
 
          if (r == -1)
            {
-             clib_warning ("failed to unmap memory region (errno %d)",
-                           errno);
+             vu_log_err (vui, "failed to unmap memory region (errno %d)",
+                         errno);
            }
          close (vui->region_mmap_fd[i]);
        }
     }
   vui->nregions = 0;
+
+  for (q = 0; q < VHOST_VRING_MAX_N; q++)
+    {
+      vq = &vui->vrings[q];
+      vq->avail = 0;
+      vq->used = 0;
+      vq->desc = 0;
+    }
 }
 
 static void
@@ -165,8 +175,8 @@ vhost_user_rx_thread_placement ()
          rv = vnet_hw_interface_unassign_rx_thread (vnm, vui->hw_if_index,
                                                     *queue);
          if (rv)
-           clib_warning ("Warning: unable to unassign interface %d, "
-                         "queue %d: rc=%d", vui->hw_if_index, *queue, rv);
+           vu_log_warn (vui, "unable to unassign interface %d, "
+                        "queue %d: rc=%d", vui->hw_if_index, *queue, rv);
        }
       vec_reset_length (vui->rx_queues);
   });
@@ -202,8 +212,8 @@ vhost_user_rx_thread_placement ()
          rv = vnet_hw_interface_set_rx_mode (vnm, vui->hw_if_index, *queue,
                                              txvq->mode);
          if (rv)
-           clib_warning ("Warning: unable to set rx mode for interface %d, "
-                         "queue %d: rc=%d", vui->hw_if_index, *queue, rv);
+           vu_log_warn (vui, "unable to set rx mode for interface %d, "
+                        "queue %d: rc=%d", vui->hw_if_index, *queue, rv);
        }
   });
   /* *INDENT-ON* */
@@ -226,15 +236,16 @@ static void
 vhost_user_update_iface_state (vhost_user_intf_t * vui)
 {
   /* if we have pointers to descriptor table, go up */
-  int is_up = vhost_user_intf_ready (vui);
-  if (is_up != vui->is_up)
+  int is_ready = vhost_user_intf_ready (vui);
+  if (is_ready != vui->is_ready)
     {
-      DBG_SOCK ("interface %d %s", vui->sw_if_index,
-               is_up ? "ready" : "down");
-      vnet_hw_interface_set_flags (vnet_get_main (), vui->hw_if_index,
-                                  is_up ? VNET_HW_INTERFACE_FLAG_LINK_UP :
-                                  0);
-      vui->is_up = is_up;
+      vu_log_debug (vui, "interface %d %s", vui->sw_if_index,
+                   is_ready ? "ready" : "down");
+      if (vui->admin_up)
+       vnet_hw_interface_set_flags (vnet_get_main (), vui->hw_if_index,
+                                    is_ready ? VNET_HW_INTERFACE_FLAG_LINK_UP
+                                    : 0);
+      vui->is_ready = is_ready;
     }
   vhost_user_rx_thread_placement ();
   vhost_user_tx_thread_placement (vui);
@@ -278,9 +289,9 @@ vhost_user_kickfd_read_ready (clib_file_t * uf)
   u32 qid = uf->private_data & 0xff;
 
   n = read (uf->file_descriptor, ((char *) &buff), 8);
-  DBG_SOCK ("if %d KICK queue %d", uf->private_data >> 8, qid);
+  vu_log_debug (vui, "if %d KICK queue %d", uf->private_data >> 8, qid);
   if (!vui->vrings[qid].started ||
-      (vhost_user_intf_ready (vui) != vui->is_up))
+      (vhost_user_intf_ready (vui) != vui->is_ready))
     {
       vlib_worker_thread_barrier_sync (vlib_get_main ());
       vui->vrings[qid].started = 1;
@@ -296,7 +307,7 @@ static_always_inline void
 vhost_user_vring_init (vhost_user_intf_t * vui, u32 qid)
 {
   vhost_user_vring_t *vring = &vui->vrings[qid];
-  memset (vring, 0, sizeof (*vring));
+  clib_memset (vring, 0, sizeof (*vring));
   vring->kickfd_idx = ~0;
   vring->callfd_idx = ~0;
   vring->errfd = -1;
@@ -354,13 +365,13 @@ vhost_user_if_disconnect (vhost_user_intf_t * vui)
       vui->clib_file_index = ~0;
     }
 
-  vui->is_up = 0;
+  vui->is_ready = 0;
 
   for (q = 0; q < VHOST_VRING_MAX_N; q++)
     vhost_user_vring_close (vui, q);
 
   unmap_all_mem_regions (vui);
-  DBG_SOCK ("interface ifindex %d disconnected", vui->sw_if_index);
+  vu_log_debug (vui, "interface ifindex %d disconnected", vui->sw_if_index);
 }
 
 static clib_error_t *
@@ -383,8 +394,8 @@ vhost_user_socket_read (clib_file_t * uf)
 
   char control[CMSG_SPACE (VHOST_MEMORY_MAX_NREGIONS * sizeof (int))];
 
-  memset (&mh, 0, sizeof (mh));
-  memset (control, 0, sizeof (control));
+  clib_memset (&mh, 0, sizeof (mh));
+  clib_memset (control, 0, sizeof (control));
 
   for (i = 0; i < VHOST_MEMORY_MAX_NREGIONS; i++)
     fds[i] = -1;
@@ -407,19 +418,20 @@ vhost_user_socket_read (clib_file_t * uf)
     {
       if (n == -1)
        {
-         DBG_SOCK ("recvmsg returned error %d %s", errno, strerror (errno));
+         vu_log_debug (vui, "recvmsg returned error %d %s", errno,
+                       strerror (errno));
        }
       else
        {
-         DBG_SOCK ("n (%d) != VHOST_USER_MSG_HDR_SZ (%d)",
-                   n, VHOST_USER_MSG_HDR_SZ);
+         vu_log_debug (vui, "n (%d) != VHOST_USER_MSG_HDR_SZ (%d)",
+                       n, VHOST_USER_MSG_HDR_SZ);
        }
       goto close_socket;
     }
 
   if (mh.msg_flags & MSG_CTRUNC)
     {
-      DBG_SOCK ("MSG_CTRUNC is set");
+      vu_log_debug (vui, "MSG_CTRUNC is set");
       goto close_socket;
     }
 
@@ -431,13 +443,13 @@ vhost_user_socket_read (clib_file_t * uf)
        VHOST_MEMORY_MAX_NREGIONS * sizeof (int)))
     {
       number_of_fds = (cmsg->cmsg_len - CMSG_LEN (0)) / sizeof (int);
-      clib_memcpy (fds, CMSG_DATA (cmsg), number_of_fds * sizeof (int));
+      clib_memcpy_fast (fds, CMSG_DATA (cmsg), number_of_fds * sizeof (int));
     }
 
   /* version 1, no reply bit set */
   if ((msg.flags & 7) != 1)
     {
-      DBG_SOCK ("malformed message received. closing socket");
+      vu_log_debug (vui, "malformed message received. closing socket");
       goto close_socket;
     }
 
@@ -448,12 +460,13 @@ vhost_user_socket_read (clib_file_t * uf)
            msg.size);
     if (rv < 0)
       {
-       DBG_SOCK ("read failed %s", strerror (errno));
+       vu_log_debug (vui, "read failed %s", strerror (errno));
        goto close_socket;
       }
     else if (rv != msg.size)
       {
-       DBG_SOCK ("message too short (read %dB should be %dB)", rv, msg.size);
+       vu_log_debug (vui, "message too short (read %dB should be %dB)", rv,
+                     msg.size);
        goto close_socket;
       }
   }
@@ -473,13 +486,13 @@ vhost_user_socket_read (clib_file_t * uf)
        (1ULL << FEAT_VIRTIO_F_VERSION_1);
       msg.u64 &= vui->feature_mask;
       msg.size = sizeof (msg.u64);
-      DBG_SOCK ("if %d msg VHOST_USER_GET_FEATURES - reply 0x%016llx",
-               vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_GET_FEATURES - reply "
+                   "0x%016llx", vui->hw_if_index, msg.u64);
       break;
 
     case VHOST_USER_SET_FEATURES:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_FEATURES features 0x%016llx",
-               vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_FEATURES features "
+                   "0x%016llx", vui->hw_if_index, msg.u64);
 
       vui->features = msg.u64;
 
@@ -495,7 +508,7 @@ vhost_user_socket_read (clib_file_t * uf)
 
       ASSERT (vui->virtio_net_hdr_sz < VLIB_BUFFER_PRE_DATA_SIZE);
       vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
-      vui->is_up = 0;
+      vui->is_ready = 0;
 
       /*for (q = 0; q < VHOST_VRING_MAX_N; q++)
          vhost_user_vring_close(&vui->vrings[q]); */
@@ -503,29 +516,29 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_MEM_TABLE:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_MEM_TABLE nregions %d",
-               vui->hw_if_index, msg.memory.nregions);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_MEM_TABLE nregions %d",
+                   vui->hw_if_index, msg.memory.nregions);
 
       if ((msg.memory.nregions < 1) ||
          (msg.memory.nregions > VHOST_MEMORY_MAX_NREGIONS))
        {
 
-         DBG_SOCK ("number of mem regions must be between 1 and %i",
-                   VHOST_MEMORY_MAX_NREGIONS);
+         vu_log_debug (vui, "number of mem regions must be between 1 and %i",
+                       VHOST_MEMORY_MAX_NREGIONS);
 
          goto close_socket;
        }
 
       if (msg.memory.nregions != number_of_fds)
        {
-         DBG_SOCK ("each memory region must have FD");
+         vu_log_debug (vui, "each memory region must have FD");
          goto close_socket;
        }
       unmap_all_mem_regions (vui);
       for (i = 0; i < msg.memory.nregions; i++)
        {
-         clib_memcpy (&(vui->regions[i]), &msg.memory.regions[i],
-                      sizeof (vhost_user_memory_region_t));
+         clib_memcpy_fast (&(vui->regions[i]), &msg.memory.regions[i],
+                           sizeof (vhost_user_memory_region_t));
 
          long page_sz = get_huge_page_size (fds[i]);
 
@@ -540,14 +553,13 @@ vhost_user_socket_read (clib_file_t * uf)
          vui->region_guest_addr_hi[i] = vui->regions[i].guest_phys_addr +
            vui->regions[i].memory_size;
 
-         DBG_SOCK
-           ("map memory region %d addr 0 len 0x%lx fd %d mapped 0x%lx "
-            "page_sz 0x%x", i, map_sz, fds[i], vui->region_mmap_addr[i],
-            page_sz);
+         vu_log_debug (vui, "map memory region %d addr 0 len 0x%lx fd %d "
+                       "mapped 0x%lx page_sz 0x%x", i, map_sz, fds[i],
+                       vui->region_mmap_addr[i], page_sz);
 
          if (vui->region_mmap_addr[i] == MAP_FAILED)
            {
-             clib_warning ("failed to map memory. errno is %d", errno);
+             vu_log_err (vui, "failed to map memory. errno is %d", errno);
              goto close_socket;
            }
          vui->region_mmap_addr[i] += vui->regions[i].mmap_offset;
@@ -558,8 +570,8 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_VRING_NUM:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_VRING_NUM idx %d num %d",
-               vui->hw_if_index, msg.state.index, msg.state.num);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_NUM idx %d num %d",
+                   vui->hw_if_index, msg.state.index, msg.state.num);
 
       if ((msg.state.num > 32768) ||   /* maximum ring size is 32768 */
          (msg.state.num == 0) ||       /* it cannot be zero */
@@ -569,20 +581,20 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_VRING_ADDR:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_VRING_ADDR idx %d",
-               vui->hw_if_index, msg.state.index);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_ADDR idx %d",
+                   vui->hw_if_index, msg.state.index);
 
       if (msg.state.index >= VHOST_VRING_MAX_N)
        {
-         DBG_SOCK ("invalid vring index VHOST_USER_SET_VRING_ADDR:"
-                   " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
+         vu_log_debug (vui, "invalid vring index VHOST_USER_SET_VRING_ADDR:"
+                       " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
          goto close_socket;
        }
 
       if (msg.size < sizeof (msg.addr))
        {
-         DBG_SOCK ("vhost message is too short (%d < %d)",
-                   msg.size, sizeof (msg.addr));
+         vu_log_debug (vui, "vhost message is too short (%d < %d)",
+                       msg.size, sizeof (msg.addr));
          goto close_socket;
        }
 
@@ -597,8 +609,8 @@ vhost_user_socket_read (clib_file_t * uf)
          (vui->vrings[msg.state.index].used == NULL) ||
          (vui->vrings[msg.state.index].avail == NULL))
        {
-         DBG_SOCK ("failed to map user memory for hw_if_index %d",
-                   vui->hw_if_index);
+         vu_log_debug (vui, "failed to map user memory for hw_if_index %d",
+                       vui->hw_if_index);
          goto close_socket;
        }
 
@@ -622,16 +634,17 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_OWNER:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_OWNER", vui->hw_if_index);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_OWNER", vui->hw_if_index);
       break;
 
     case VHOST_USER_RESET_OWNER:
-      DBG_SOCK ("if %d msg VHOST_USER_RESET_OWNER", vui->hw_if_index);
+      vu_log_debug (vui, "if %d msg VHOST_USER_RESET_OWNER",
+                   vui->hw_if_index);
       break;
 
     case VHOST_USER_SET_VRING_CALL:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_VRING_CALL %d",
-               vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_CALL %d",
+                   vui->hw_if_index, msg.u64);
 
       q = (u8) (msg.u64 & 0xFF);
 
@@ -648,7 +661,7 @@ vhost_user_socket_read (clib_file_t * uf)
        {
          if (number_of_fds != 1)
            {
-             DBG_SOCK ("More than one fd received !");
+             vu_log_debug (vui, "More than one fd received !");
              goto close_socket;
            }
 
@@ -663,8 +676,8 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_VRING_KICK:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_VRING_KICK %d",
-               vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_KICK %d",
+                   vui->hw_if_index, msg.u64);
 
       q = (u8) (msg.u64 & 0xFF);
 
@@ -680,7 +693,7 @@ vhost_user_socket_read (clib_file_t * uf)
        {
          if (number_of_fds != 1)
            {
-             DBG_SOCK ("More than one fd received !");
+             vu_log_debug (vui, "More than one fd received !");
              goto close_socket;
            }
 
@@ -701,8 +714,8 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_VRING_ERR:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_VRING_ERR %d",
-               vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_ERR %d",
+                   vui->hw_if_index, msg.u64);
 
       q = (u8) (msg.u64 & 0xFF);
 
@@ -722,8 +735,8 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     case VHOST_USER_SET_VRING_BASE:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_VRING_BASE idx %d num %d",
-               vui->hw_if_index, msg.state.index, msg.state.num);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_BASE idx %d num %d",
+                   vui->hw_if_index, msg.state.index, msg.state.num);
 
       vui->vrings[msg.state.index].last_avail_idx = msg.state.num;
       break;
@@ -731,8 +744,8 @@ vhost_user_socket_read (clib_file_t * uf)
     case VHOST_USER_GET_VRING_BASE:
       if (msg.state.index >= VHOST_VRING_MAX_N)
        {
-         DBG_SOCK ("invalid vring index VHOST_USER_GET_VRING_BASE:"
-                   " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
+         vu_log_debug (vui, "invalid vring index VHOST_USER_GET_VRING_BASE:"
+                       " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
          goto close_socket;
        }
 
@@ -746,32 +759,32 @@ vhost_user_socket_read (clib_file_t * uf)
 
       /* Spec says: Client must [...] stop ring upon receiving VHOST_USER_GET_VRING_BASE. */
       vhost_user_vring_close (vui, msg.state.index);
-      DBG_SOCK ("if %d msg VHOST_USER_GET_VRING_BASE idx %d num %d",
-               vui->hw_if_index, msg.state.index, msg.state.num);
+      vu_log_debug (vui, "if %d msg VHOST_USER_GET_VRING_BASE idx %d num %d",
+                   vui->hw_if_index, msg.state.index, msg.state.num);
       break;
 
     case VHOST_USER_NONE:
-      DBG_SOCK ("if %d msg VHOST_USER_NONE", vui->hw_if_index);
+      vu_log_debug (vui, "if %d msg VHOST_USER_NONE", vui->hw_if_index);
 
       break;
 
     case VHOST_USER_SET_LOG_BASE:
       {
-       DBG_SOCK ("if %d msg VHOST_USER_SET_LOG_BASE", vui->hw_if_index);
+       vu_log_debug (vui, "if %d msg VHOST_USER_SET_LOG_BASE",
+                     vui->hw_if_index);
 
        if (msg.size != sizeof (msg.log))
          {
-           DBG_SOCK
-             ("invalid msg size for VHOST_USER_SET_LOG_BASE: %d instead of %d",
-              msg.size, sizeof (msg.log));
+           vu_log_debug (vui, "invalid msg size for VHOST_USER_SET_LOG_BASE:"
+                         " %d instead of %d", msg.size, sizeof (msg.log));
            goto close_socket;
          }
 
        if (!
            (vui->protocol_features & (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD)))
          {
-           DBG_SOCK
-             ("VHOST_USER_PROTOCOL_F_LOG_SHMFD not set but VHOST_USER_SET_LOG_BASE received");
+           vu_log_debug (vui, "VHOST_USER_PROTOCOL_F_LOG_SHMFD not set but "
+                         "VHOST_USER_SET_LOG_BASE received");
            goto close_socket;
          }
 
@@ -784,13 +797,13 @@ vhost_user_socket_read (clib_file_t * uf)
        vui->log_base_addr = mmap (0, map_sz, PROT_READ | PROT_WRITE,
                                   MAP_SHARED, fd, 0);
 
-       DBG_SOCK
-         ("map log region addr 0 len 0x%lx off 0x%lx fd %d mapped 0x%lx",
-          map_sz, msg.log.offset, fd, vui->log_base_addr);
+       vu_log_debug (vui, "map log region addr 0 len 0x%lx off 0x%lx fd %d "
+                     "mapped 0x%lx", map_sz, msg.log.offset, fd,
+                     vui->log_base_addr);
 
        if (vui->log_base_addr == MAP_FAILED)
          {
-           clib_warning ("failed to map memory. errno is %d", errno);
+           vu_log_err (vui, "failed to map memory. errno is %d", errno);
            goto close_socket;
          }
 
@@ -804,7 +817,7 @@ vhost_user_socket_read (clib_file_t * uf)
       }
 
     case VHOST_USER_SET_LOG_FD:
-      DBG_SOCK ("if %d msg VHOST_USER_SET_LOG_FD", vui->hw_if_index);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_LOG_FD", vui->hw_if_index);
 
       break;
 
@@ -813,15 +826,13 @@ vhost_user_socket_read (clib_file_t * uf)
       msg.u64 = (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |
        (1 << VHOST_USER_PROTOCOL_F_MQ);
       msg.size = sizeof (msg.u64);
-      DBG_SOCK
-       ("if %d msg VHOST_USER_GET_PROTOCOL_FEATURES - reply 0x%016llx",
-        vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_GET_PROTOCOL_FEATURES - "
+                   "reply 0x%016llx", vui->hw_if_index, msg.u64);
       break;
 
     case VHOST_USER_SET_PROTOCOL_FEATURES:
-      DBG_SOCK
-       ("if %d msg VHOST_USER_SET_PROTOCOL_FEATURES features 0x%016llx",
-        vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_SET_PROTOCOL_FEATURES "
+                   "features 0x%016llx", vui->hw_if_index, msg.u64);
 
       vui->protocol_features = msg.u64;
 
@@ -831,18 +842,18 @@ vhost_user_socket_read (clib_file_t * uf)
       msg.flags |= 4;
       msg.u64 = VHOST_VRING_MAX_N;
       msg.size = sizeof (msg.u64);
-      DBG_SOCK ("if %d msg VHOST_USER_GET_QUEUE_NUM - reply %d",
-               vui->hw_if_index, msg.u64);
+      vu_log_debug (vui, "if %d msg VHOST_USER_GET_QUEUE_NUM - reply %d",
+                   vui->hw_if_index, msg.u64);
       break;
 
     case VHOST_USER_SET_VRING_ENABLE:
-      DBG_SOCK ("if %d VHOST_USER_SET_VRING_ENABLE: %s queue %d",
-               vui->hw_if_index, msg.state.num ? "enable" : "disable",
-               msg.state.index);
+      vu_log_debug (vui, "if %d VHOST_USER_SET_VRING_ENABLE: %s queue %d",
+                   vui->hw_if_index, msg.state.num ? "enable" : "disable",
+                   msg.state.index);
       if (msg.state.index >= VHOST_VRING_MAX_N)
        {
-         DBG_SOCK ("invalid vring index VHOST_USER_SET_VRING_ENABLE:"
-                   " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
+         vu_log_debug (vui, "invalid vring idx VHOST_USER_SET_VRING_ENABLE:"
+                       " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
          goto close_socket;
        }
 
@@ -850,8 +861,8 @@ vhost_user_socket_read (clib_file_t * uf)
       break;
 
     default:
-      DBG_SOCK ("unknown vhost-user message %d received. closing socket",
-               msg.request);
+      vu_log_debug (vui, "unknown vhost-user message %d received. "
+                   "closing socket", msg.request);
       goto close_socket;
     }
 
@@ -862,7 +873,7 @@ vhost_user_socket_read (clib_file_t * uf)
        send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
       if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
        {
-         DBG_SOCK ("could not send message response");
+         vu_log_debug (vui, "could not send message response");
          goto close_socket;
        }
     }
@@ -886,7 +897,7 @@ vhost_user_socket_error (clib_file_t * uf)
   vhost_user_intf_t *vui =
     pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
 
-  DBG_SOCK ("socket error on if %d", vui->sw_if_index);
+  vu_log_debug (vui, "socket error on if %d", vui->sw_if_index);
   vlib_worker_thread_barrier_sync (vm);
   vhost_user_if_disconnect (vui);
   vhost_user_rx_thread_placement ();
@@ -915,13 +926,13 @@ vhost_user_socksvr_accept_ready (clib_file_t * uf)
 
   if (vui->clib_file_index != ~0)
     {
-      DBG_SOCK ("Close client socket for vhost interface %d, fd %d",
-               vui->sw_if_index, UNIX_GET_FD (vui->clib_file_index));
+      vu_log_debug (vui, "Close client socket for vhost interface %d, fd %d",
+                   vui->sw_if_index, UNIX_GET_FD (vui->clib_file_index));
       clib_file_del (&file_main, file_main.file_pool + vui->clib_file_index);
     }
 
-  DBG_SOCK ("New client socket for vhost interface %d, fd %d",
-           vui->sw_if_index, client_fd);
+  vu_log_debug (vui, "New client socket for vhost interface %d, fd %d",
+               vui->sw_if_index, client_fd);
   template.read_function = vhost_user_socket_read;
   template.error_function = vhost_user_socket_error;
   template.file_descriptor = client_fd;
@@ -941,6 +952,8 @@ vhost_user_init (vlib_main_t * vm)
   if (error)
     return error;
 
+  vum->log_default = vlib_log_register_class ("vhost-user", 0);
+
   vum->coalesce_frames = 32;
   vum->coalesce_time = 1e-3;
 
@@ -1148,7 +1161,7 @@ vhost_user_process (vlib_main_t * vm,
 
                  if (retval)
                    {
-                     DBG_SOCK ("getsockopt returned %d", retval);
+                     vu_log_debug (vui, "getsockopt returned %d", retval);
                      vhost_user_if_disconnect (vui);
                    }
                }
@@ -1213,11 +1226,11 @@ vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, u32 sw_if_index)
       hwif->dev_class_index != vhost_user_device_class.index)
     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
 
-  DBG_SOCK ("Deleting vhost-user interface %s (instance %d)",
-           hwif->name, hwif->dev_instance);
-
   vui = pool_elt_at_index (vum->vhost_user_interfaces, hwif->dev_instance);
 
+  vu_log_debug (vui, "Deleting vhost-user interface %s (instance %d)",
+               hwif->name, hwif->dev_instance);
+
   vec_foreach (queue, vui->rx_queues)
   {
     vhost_user_vring_t *txvq;
@@ -1349,8 +1362,6 @@ vhost_user_create_ethernet (vnet_main_t * vnm, vlib_main_t * vm,
 
   if (error)
     clib_error_report (error);
-
-  vnet_sw_interface_set_mtu (vnm, vui->sw_if_index, 9000);
 }
 
 /*
@@ -1387,7 +1398,7 @@ vhost_user_vui_init (vnet_main_t * vnm,
   strncpy (vui->sock_filename, sock_filename,
           ARRAY_LEN (vui->sock_filename) - 1);
   vui->sock_errno = 0;
-  vui->is_up = 0;
+  vui->is_ready = 0;
   vui->feature_mask = feature_mask;
   vui->clib_file_index = ~0;
   vui->log_base_addr = 0;
@@ -1408,7 +1419,7 @@ vhost_user_vui_init (vnet_main_t * vnm,
     {
       vui->vring_locks[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
                                                    CLIB_CACHE_LINE_BYTES);
-      memset ((void *) vui->vring_locks[q], 0, CLIB_CACHE_LINE_BYTES);
+      clib_memset ((void *) vui->vring_locks[q], 0, CLIB_CACHE_LINE_BYTES);
     }
 
   vec_validate (vui->per_cpu_tx_qid,
@@ -1461,6 +1472,7 @@ vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm,
   vhost_user_create_ethernet (vnm, vm, vui, hwaddr);
   vhost_user_vui_init (vnm, vui, server_sock_fd, sock_filename,
                       feature_mask, &sw_if_idx);
+  vnet_sw_interface_set_mtu (vnm, vui->sw_if_index, 9000);
 
   if (renumber)
     vnet_interface_name_renumber (sw_if_idx, custom_dev_instance);
@@ -1767,8 +1779,9 @@ show_vhost_user_command_fn (vlib_main_t * vm,
     {
       hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
       vui = pool_elt_at_index (vum->vhost_user_interfaces, hi->dev_instance);
-      vlib_cli_output (vm, "Interface: %s (ifindex %d)",
-                      hi->name, hw_if_indices[i]);
+      vlib_cli_output (vm, "Interface: %U (ifindex %d)",
+                      format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
+                      hw_if_indices[i]);
 
       vlib_cli_output (vm, "virtio_net_hdr_sz %d\n"
                       " features mask (0x%llx): \n"
@@ -2136,63 +2149,6 @@ VLIB_CLI_COMMAND (show_vhost_user_command, static) = {
 };
 /* *INDENT-ON* */
 
-clib_error_t *
-debug_vhost_user_command_fn (vlib_main_t * vm,
-                            unformat_input_t * input,
-                            vlib_cli_command_t * cmd)
-{
-  unformat_input_t _line_input, *line_input = &_line_input;
-  clib_error_t *error = NULL;
-  vhost_user_main_t *vum = &vhost_user_main;
-  u8 onoff = 0;
-  u8 input_found = 0;
-
-  /* Get a line of input. */
-  if (!unformat_user (input, unformat_line_input, line_input))
-    return clib_error_return (0, "missing argument");
-
-  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
-    {
-      if (input_found)
-       {
-         error = clib_error_return (0, "unknown input `%U'",
-                                    format_unformat_error, line_input);
-         goto done;
-       }
-
-      if (unformat (line_input, "on"))
-       {
-         input_found = 1;
-         onoff = 1;
-       }
-      else if (unformat (line_input, "off"))
-       {
-         input_found = 1;
-         onoff = 0;
-       }
-      else
-       {
-         error = clib_error_return (0, "unknown input `%U'",
-                                    format_unformat_error, line_input);
-         goto done;
-       }
-    }
-
-  vum->debug = onoff;
-
-done:
-  unformat_free (line_input);
-
-  return error;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (debug_vhost_user_command, static) = {
-    .path = "debug vhost-user",
-    .short_help = "debug vhost-user <on | off>",
-    .function = debug_vhost_user_command_fn,
-};
-/* *INDENT-ON* */
 
 static clib_error_t *
 vhost_user_config (vlib_main_t * vm, unformat_input_t * input)
@@ -2215,7 +2171,6 @@ vhost_user_config (vlib_main_t * vm, unformat_input_t * input)
   return 0;
 }
 
-
 /* vhost-user { ... } configuration. */
 VLIB_CONFIG_FUNCTION (vhost_user_config, "vhost-user");