X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fdevices%2Fvirtio%2Fvhost_user.c;h=7094a00fb337c1a060e5adce064c0463b1fe68f9;hb=7d697185437722ffce23a2d0b8838fc390cc6c84;hp=796be4b80a2892dc18fba2eec0309efe57ff579d;hpb=28812a0d938d5113787ed7a9ee4b210515c4168b;p=vpp.git diff --git a/src/vnet/devices/virtio/vhost_user.c b/src/vnet/devices/virtio/vhost_user.c index 796be4b80a2..7094a00fb33 100644 --- a/src/vnet/devices/virtio/vhost_user.c +++ b/src/vnet/devices/virtio/vhost_user.c @@ -91,16 +91,16 @@ 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]); } @@ -116,12 +116,13 @@ unmap_all_mem_regions (vhost_user_intf_t * vui) } } -static void +static_always_inline void vhost_user_tx_thread_placement (vhost_user_intf_t * vui) { //Let's try to assign one queue to each thread - u32 qid = 0; + u32 qid; u32 thread_index = 0; + vui->use_tx_spinlock = 0; while (1) { @@ -156,67 +157,27 @@ vhost_user_tx_thread_placement (vhost_user_intf_t * vui) * @brief Unassign existing interface/queue to thread mappings and re-assign * new interface/queue to thread mappings */ -static void -vhost_user_rx_thread_placement () +static_always_inline void +vhost_user_rx_thread_placement (vhost_user_intf_t * vui, u32 qid) { - vhost_user_main_t *vum = &vhost_user_main; - vhost_user_intf_t *vui; - vhost_user_vring_t *txvq; + vhost_user_vring_t *txvq = &vui->vrings[qid]; vnet_main_t *vnm = vnet_get_main (); - u32 qid; int rv; - u16 *queue; - - // Scrap all existing mappings for all interfaces/queues - /* *INDENT-OFF* */ - pool_foreach (vui, vum->vhost_user_interfaces, { - vec_foreach (queue, vui->rx_queues) - { - 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); - } - vec_reset_length (vui->rx_queues); - }); - /* *INDENT-ON* */ - - // Create the rx_queues for all interfaces - /* *INDENT-OFF* */ - pool_foreach (vui, vum->vhost_user_interfaces, { - for (qid = 0; qid < VHOST_VRING_MAX_N / 2; qid++) - { - txvq = &vui->vrings[VHOST_VRING_IDX_TX (qid)]; - if (txvq->started) - { - if (txvq->mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN) - /* Set polling as the default */ - txvq->mode = VNET_HW_INTERFACE_RX_MODE_POLLING; - vec_add1 (vui->rx_queues, qid); - } - } - }); - /* *INDENT-ON* */ - - // Assign new mappings for all interfaces/queues - /* *INDENT-OFF* */ - pool_foreach (vui, vum->vhost_user_interfaces, { - vnet_hw_interface_set_input_node (vnm, vui->hw_if_index, - vhost_user_input_node.index); - vec_foreach (queue, vui->rx_queues) - { - vnet_hw_interface_assign_rx_thread (vnm, vui->hw_if_index, *queue, - ~0); - txvq = &vui->vrings[VHOST_VRING_IDX_TX (*queue)]; - 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); - } - }); - /* *INDENT-ON* */ + u32 q = qid >> 1; + + ASSERT ((qid & 1) == 1); // should be odd + // Assign new queue mappings for the interface + vnet_hw_interface_set_input_node (vnm, vui->hw_if_index, + vhost_user_input_node.index); + vnet_hw_interface_assign_rx_thread (vnm, vui->hw_if_index, q, ~0); + if (txvq->mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN) + /* Set polling as the default */ + txvq->mode = VNET_HW_INTERFACE_RX_MODE_POLLING; + txvq->qid = q; + rv = vnet_hw_interface_set_rx_mode (vnm, vui->hw_if_index, q, txvq->mode); + if (rv) + vu_log_warn (vui, "unable to set rx mode for interface %d, " + "queue %d: rc=%d", vui->hw_if_index, q, rv); } /** @brief Returns whether at least one TX and one RX vring are enabled */ @@ -232,22 +193,21 @@ vhost_user_intf_ready (vhost_user_intf_t * vui) return found[0] && found[1]; } -static void +static_always_inline 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); } static void @@ -277,6 +237,18 @@ vhost_user_callfd_read_ready (clib_file_t * uf) return 0; } +static_always_inline void +vhost_user_thread_placement (vhost_user_intf_t * vui, u32 qid) +{ + if (qid & 1) // RX is odd, TX is even + { + if (vui->vrings[qid].qid == -1) + vhost_user_rx_thread_placement (vui, qid); + } + else + vhost_user_tx_thread_placement (vui); +} + static clib_error_t * vhost_user_kickfd_read_ready (clib_file_t * uf) { @@ -288,14 +260,16 @@ 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; - vhost_user_update_iface_state (vui); - vlib_worker_thread_barrier_release (vlib_get_main ()); + if (vui->vrings[qid].started == 0) + { + vui->vrings[qid].started = 1; + vhost_user_thread_placement (vui, qid); + vhost_user_update_iface_state (vui); + } } vhost_user_set_interrupt_pending (vui, uf->private_data); @@ -306,10 +280,11 @@ 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; + vring->qid = -1; /* * We have a bug with some qemu 2.5, and this may be a fix. @@ -328,6 +303,7 @@ static_always_inline void vhost_user_vring_close (vhost_user_intf_t * vui, u32 qid) { vhost_user_vring_t *vring = &vui->vrings[qid]; + if (vring->kickfd_idx != ~0) { clib_file_t *uf = pool_elt_at_index (file_main.file_pool, @@ -347,7 +323,12 @@ vhost_user_vring_close (vhost_user_intf_t * vui, u32 qid) close (vring->errfd); vring->errfd = -1; } + + // save the qid so that we don't need to unassign and assign_rx_thread + // when the interface comes back up. They are expensive calls. + u16 q = vui->vrings[qid].qid; vhost_user_vring_init (vui, qid); + vui->vrings[qid].qid = q; } static_always_inline void @@ -364,19 +345,19 @@ 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 * vhost_user_socket_read (clib_file_t * uf) { - int n, i; + int n, i, j; int fd, number_of_fds = 0; int fds[VHOST_MEMORY_MAX_NREGIONS]; vhost_user_msg_t msg; @@ -388,13 +369,14 @@ vhost_user_socket_read (clib_file_t * uf) u8 q; clib_file_t template = { 0 }; vnet_main_t *vnm = vnet_get_main (); + vlib_main_t *vm = vlib_get_main (); vui = pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data); 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; @@ -410,26 +392,24 @@ vhost_user_socket_read (clib_file_t * uf) n = recvmsg (uf->file_descriptor, &mh, 0); - /* Stop workers to avoid end of the world */ - vlib_worker_thread_barrier_sync (vlib_get_main ()); - if (n != VHOST_USER_MSG_HDR_SZ) { 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; } @@ -441,13 +421,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; } @@ -458,12 +438,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; } } @@ -482,14 +463,25 @@ vhost_user_socket_read (clib_file_t * uf) (1ULL << FEAT_VHOST_USER_F_PROTOCOL_FEATURES) | (1ULL << FEAT_VIRTIO_F_VERSION_1); msg.u64 &= vui->feature_mask; + + if (vui->enable_gso) + msg.u64 |= FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS; + 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); + n = + send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0); + if (n != (msg.size + VHOST_USER_MSG_HDR_SZ)) + { + vu_log_debug (vui, "could not send message response"); + goto close_socket; + } 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; @@ -504,72 +496,105 @@ vhost_user_socket_read (clib_file_t * uf) (vui->features & (1 << FEAT_VIRTIO_F_ANY_LAYOUT)) ? 1 : 0; ASSERT (vui->virtio_net_hdr_sz < VLIB_BUFFER_PRE_DATA_SIZE); + vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vui->hw_if_index); + if (vui->enable_gso && + ((vui->features & FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS) + == FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS)) + hw->flags |= + (VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO | + VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD); + else + hw->flags &= ~(VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO | + VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD); vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0); - vui->is_up = 0; - - /*for (q = 0; q < VHOST_VRING_MAX_N; q++) - vhost_user_vring_close(&vui->vrings[q]); */ - + vui->is_ready = 0; + vhost_user_update_iface_state (vui); 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); + + /* Do the mmap without barrier sync */ + void *region_mmap_addr[VHOST_MEMORY_MAX_NREGIONS]; for (i = 0; i < msg.memory.nregions; i++) { - clib_memcpy (&(vui->regions[i]), &msg.memory.regions[i], - sizeof (vhost_user_memory_region_t)); - long page_sz = get_huge_page_size (fds[i]); /* align size to page */ - ssize_t map_sz = (vui->regions[i].memory_size + - vui->regions[i].mmap_offset + + ssize_t map_sz = (msg.memory.regions[i].memory_size + + msg.memory.regions[i].mmap_offset + page_sz - 1) & ~(page_sz - 1); - vui->region_mmap_addr[i] = mmap (0, map_sz, PROT_READ | PROT_WRITE, - MAP_SHARED, fds[i], 0); + region_mmap_addr[i] = mmap (0, map_sz, PROT_READ | PROT_WRITE, + MAP_SHARED, fds[i], 0); + if (region_mmap_addr[i] == MAP_FAILED) + { + vu_log_err (vui, "failed to map memory. errno is %d", errno); + for (j = 0; j < i; j++) + munmap (region_mmap_addr[j], map_sz); + goto close_socket; + } + 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], + region_mmap_addr[i], page_sz); + } + + vlib_worker_thread_barrier_sync (vm); + unmap_all_mem_regions (vui); + for (i = 0; i < msg.memory.nregions; i++) + { + clib_memcpy_fast (&(vui->regions[i]), &msg.memory.regions[i], + sizeof (vhost_user_memory_region_t)); + + vui->region_mmap_addr[i] = region_mmap_addr[i]; vui->region_guest_addr_lo[i] = vui->regions[i].guest_phys_addr; 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); - - if (vui->region_mmap_addr[i] == MAP_FAILED) - { - clib_warning ("failed to map memory. errno is %d", errno); - goto close_socket; - } vui->region_mmap_addr[i] += vui->regions[i].mmap_offset; vui->region_mmap_fd[i] = fds[i]; vui->nregions++; } + + /* + * Re-compute desc, used, and avail descriptor table if vring address + * is set. + */ + for (q = 0; q < VHOST_VRING_MAX_N; q++) + { + if (vui->vrings[q].desc_user_addr && + vui->vrings[q].used_user_addr && vui->vrings[q].avail_user_addr) + { + vui->vrings[q].desc = + map_user_mem (vui, vui->vrings[q].desc_user_addr); + vui->vrings[q].used = + map_user_mem (vui, vui->vrings[q].used_user_addr); + vui->vrings[q].avail = + map_user_mem (vui, vui->vrings[q].avail_user_addr); + } + } + vlib_worker_thread_barrier_release (vm); 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 */ @@ -579,39 +604,43 @@ 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; } - vui->vrings[msg.state.index].desc = (vring_desc_t *) - map_user_mem (vui, msg.addr.desc_user_addr); - vui->vrings[msg.state.index].used = (vring_used_t *) - map_user_mem (vui, msg.addr.used_user_addr); - vui->vrings[msg.state.index].avail = (vring_avail_t *) - map_user_mem (vui, msg.addr.avail_user_addr); + vring_desc_t *desc = map_user_mem (vui, msg.addr.desc_user_addr); + vring_used_t *used = map_user_mem (vui, msg.addr.used_user_addr); + vring_avail_t *avail = map_user_mem (vui, msg.addr.avail_user_addr); - if ((vui->vrings[msg.state.index].desc == NULL) || - (vui->vrings[msg.state.index].used == NULL) || - (vui->vrings[msg.state.index].avail == NULL)) + if ((desc == NULL) || (used == NULL) || (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; } + vui->vrings[msg.state.index].desc_user_addr = msg.addr.desc_user_addr; + vui->vrings[msg.state.index].used_user_addr = msg.addr.used_user_addr; + vui->vrings[msg.state.index].avail_user_addr = msg.addr.avail_user_addr; + + vlib_worker_thread_barrier_sync (vm); + vui->vrings[msg.state.index].desc = desc; + vui->vrings[msg.state.index].used = used; + vui->vrings[msg.state.index].avail = avail; + vui->vrings[msg.state.index].log_guest_addr = msg.addr.log_guest_addr; vui->vrings[msg.state.index].log_used = (msg.addr.flags & (1 << VHOST_VRING_F_LOG)) ? 1 : 0; @@ -619,9 +648,7 @@ vhost_user_socket_read (clib_file_t * uf) /* Spec says: If VHOST_USER_F_PROTOCOL_FEATURES has not been negotiated, the ring is initialized in an enabled state. */ if (!(vui->features & (1 << FEAT_VHOST_USER_F_PROTOCOL_FEATURES))) - { - vui->vrings[msg.state.index].enabled = 1; - } + vui->vrings[msg.state.index].enabled = 1; vui->vrings[msg.state.index].last_used_idx = vui->vrings[msg.state.index].last_avail_idx = @@ -629,19 +656,22 @@ vhost_user_socket_read (clib_file_t * uf) /* tell driver that we don't want interrupts */ vui->vrings[msg.state.index].used->flags = VRING_USED_F_NO_NOTIFY; + vlib_worker_thread_barrier_release (vm); + vhost_user_update_iface_state (vui); 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); @@ -658,7 +688,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; } @@ -673,8 +703,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); @@ -690,7 +720,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; } @@ -706,13 +736,14 @@ vhost_user_socket_read (clib_file_t * uf) //When no kickfd is set, the queue is initialized as started vui->vrings[q].kickfd_idx = ~0; vui->vrings[q].started = 1; + vhost_user_thread_placement (vui, q); } - + vhost_user_update_iface_state (vui); 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); @@ -728,24 +759,26 @@ vhost_user_socket_read (clib_file_t * uf) } else vui->vrings[q].errfd = -1; - 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); + vlib_worker_thread_barrier_sync (vm); vui->vrings[msg.state.index].last_avail_idx = msg.state.num; + vlib_worker_thread_barrier_release (vm); break; 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; } + /* protection is needed to prevent rx/tx from changing last_avail_idx */ + vlib_worker_thread_barrier_sync (vm); /* * Copy last_avail_idx from the vring before closing it because * closing the vring also initializes the vring last_avail_idx @@ -754,68 +787,84 @@ vhost_user_socket_read (clib_file_t * uf) msg.flags |= 4; msg.size = sizeof (msg.state); - /* Spec says: Client must [...] stop ring upon receiving VHOST_USER_GET_VRING_BASE. */ + /* + * 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); + vlib_worker_thread_barrier_release (vm); + 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); + n = + send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0); + if (n != (msg.size + VHOST_USER_MSG_HDR_SZ)) + { + vu_log_debug (vui, "could not send message response"); + goto close_socket; + } + vhost_user_update_iface_state (vui); 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)); - goto close_socket; - } + if (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"); - goto close_socket; - } + if (!(vui->protocol_features & (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD))) + { + vu_log_debug (vui, "VHOST_USER_PROTOCOL_F_LOG_SHMFD not set but " + "VHOST_USER_SET_LOG_BASE received"); + goto close_socket; + } - fd = fds[0]; - /* align size to page */ - long page_sz = get_huge_page_size (fd); - ssize_t map_sz = - (msg.log.size + msg.log.offset + page_sz - 1) & ~(page_sz - 1); + fd = fds[0]; + /* align size to page */ + long page_sz = get_huge_page_size (fd); + ssize_t map_sz = + (msg.log.size + msg.log.offset + page_sz - 1) & ~(page_sz - 1); - vui->log_base_addr = mmap (0, map_sz, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0); + void *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, + log_base_addr); - if (vui->log_base_addr == MAP_FAILED) - { - clib_warning ("failed to map memory. errno is %d", errno); - goto close_socket; - } - - vui->log_base_addr += msg.log.offset; - vui->log_size = msg.log.size; + if (log_base_addr == MAP_FAILED) + { + vu_log_err (vui, "failed to map memory. errno is %d", errno); + goto close_socket; + } - msg.flags |= 4; - msg.size = sizeof (msg.u64); + vlib_worker_thread_barrier_sync (vm); + vui->log_base_addr = log_base_addr; + vui->log_base_addr += msg.log.offset; + vui->log_size = msg.log.size; + vlib_worker_thread_barrier_release (vm); - break; - } + msg.flags |= 4; + msg.size = sizeof (msg.u64); + n = + send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0); + if (n != (msg.size + VHOST_USER_MSG_HDR_SZ)) + { + vu_log_debug (vui, "could not send message response"); + goto close_socket; + } + break; 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; case VHOST_USER_GET_PROTOCOL_FEATURES: @@ -823,68 +872,67 @@ 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); + n = + send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0); + if (n != (msg.size + VHOST_USER_MSG_HDR_SZ)) + { + vu_log_debug (vui, "could not send message response"); + goto close_socket; + } 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; - break; case VHOST_USER_GET_QUEUE_NUM: 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); + n = + send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0); + if (n != (msg.size + VHOST_USER_MSG_HDR_SZ)) + { + vu_log_debug (vui, "could not send message response"); + goto close_socket; + } 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; } vui->vrings[msg.state.index].enabled = msg.state.num; + vhost_user_thread_placement (vui, msg.state.index); + vhost_user_update_iface_state (vui); 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; } - /* if we need to reply */ - if (msg.flags & 4) - { - n = - 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"); - goto close_socket; - } - } - - vhost_user_update_iface_state (vui); - vlib_worker_thread_barrier_release (vlib_get_main ()); return 0; close_socket: + vlib_worker_thread_barrier_sync (vm); vhost_user_if_disconnect (vui); + vlib_worker_thread_barrier_release (vm); vhost_user_update_iface_state (vui); - vlib_worker_thread_barrier_release (vlib_get_main ()); return 0; } @@ -896,10 +944,9 @@ 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 (); vlib_worker_thread_barrier_release (vm); return 0; } @@ -925,13 +972,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; @@ -943,13 +990,10 @@ vhost_user_socksvr_accept_ready (clib_file_t * uf) static clib_error_t * vhost_user_init (vlib_main_t * vm) { - clib_error_t *error; vhost_user_main_t *vum = &vhost_user_main; vlib_thread_main_t *tm = vlib_get_thread_main (); - error = vlib_call_init_function (vm, ip4_init); - if (error) - return error; + vum->log_default = vlib_log_register_class ("vhost-user", 0); vum->coalesce_frames = 32; vum->coalesce_time = 1e-3; @@ -971,7 +1015,12 @@ vhost_user_init (vlib_main_t * vm) return 0; } -VLIB_INIT_FUNCTION (vhost_user_init); +/* *INDENT-OFF* */ +VLIB_INIT_FUNCTION (vhost_user_init) = +{ + .runs_after = VLIB_INITS("ip4_init"), +}; +/* *INDENT-ON* */ static uword vhost_user_send_interrupt_process (vlib_main_t * vm, @@ -981,7 +1030,7 @@ vhost_user_send_interrupt_process (vlib_main_t * vm, f64 timeout = 3153600000.0 /* 100 years */ ; uword event_type, *event_data = 0; vhost_user_main_t *vum = &vhost_user_main; - u16 *queue; + u16 qid; f64 now, poll_time_remaining; f64 next_timeout; u8 stop_timer = 0; @@ -1019,13 +1068,13 @@ vhost_user_send_interrupt_process (vlib_main_t * vm, /* *INDENT-OFF* */ pool_foreach (vui, vum->vhost_user_interfaces, { next_timeout = timeout; - vec_foreach (queue, vui->rx_queues) + for (qid = 0; qid < VHOST_VRING_MAX_N / 2; qid += 2) { - vhost_user_vring_t *rxvq = - &vui->vrings[VHOST_VRING_IDX_RX (*queue)]; - vhost_user_vring_t *txvq = - &vui->vrings[VHOST_VRING_IDX_TX (*queue)]; + vhost_user_vring_t *rxvq = &vui->vrings[qid]; + vhost_user_vring_t *txvq = &vui->vrings[qid + 1]; + if (txvq->qid == -1) + continue; if (txvq->n_since_last_int) { if (now >= txvq->int_deadline) @@ -1158,7 +1207,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); } } @@ -1189,10 +1238,29 @@ vhost_user_term_if (vhost_user_intf_t * vui) // disconnect interface sockets vhost_user_if_disconnect (vui); + vhost_user_update_gso_interface_count (vui, 0 /* delete */ ); vhost_user_update_iface_state (vui); for (q = 0; q < VHOST_VRING_MAX_N; q++) { + // Remove existing queue mapping for the interface + if (q & 1) + { + int rv; + vnet_main_t *vnm = vnet_get_main (); + vhost_user_vring_t *txvq = &vui->vrings[q]; + + if (txvq->qid != -1) + { + rv = vnet_hw_interface_unassign_rx_thread (vnm, + vui->hw_if_index, + q >> 1); + if (rv) + vu_log_warn (vui, "unable to unassign interface %d, " + "queue %d: rc=%d", vui->hw_if_index, q >> 1, rv); + } + } + clib_mem_free ((void *) vui->vring_locks[q]); } @@ -1217,38 +1285,41 @@ vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, u32 sw_if_index) vhost_user_intf_t *vui; int rv = 0; vnet_hw_interface_t *hwif; - u16 *queue; + u16 qid; - if (!(hwif = vnet_get_sup_hw_interface (vnm, sw_if_index)) || - hwif->dev_class_index != vhost_user_device_class.index) + if (! + (hwif = + vnet_get_sup_hw_interface_api_visible_or_null (vnm, 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); - vec_foreach (queue, vui->rx_queues) - { - vhost_user_vring_t *txvq; + vu_log_debug (vui, "Deleting vhost-user interface %s (instance %d)", + hwif->name, hwif->dev_instance); - txvq = &vui->vrings[VHOST_VRING_IDX_TX (*queue)]; - if ((vum->ifq_count > 0) && - ((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) || - (txvq->mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE))) - { - vum->ifq_count--; - // Stop the timer if there is no more interrupt interface/queue - if ((vum->ifq_count == 0) && - (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0)) - { - vlib_process_signal_event (vm, - vhost_user_send_interrupt_node.index, - VHOST_USER_EVENT_STOP_TIMER, 0); - break; - } - } - } + for (qid = 1; qid < VHOST_VRING_MAX_N / 2; qid += 2) + { + vhost_user_vring_t *txvq = &vui->vrings[qid]; + + if (txvq->qid == -1) + continue; + if ((vum->ifq_count > 0) && + ((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) || + (txvq->mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE))) + { + vum->ifq_count--; + // Stop the timer if there is no more interrupt interface/queue + if ((vum->ifq_count == 0) && + (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0)) + { + vlib_process_signal_event (vm, + vhost_user_send_interrupt_node.index, + VHOST_USER_EVENT_STOP_TIMER, 0); + break; + } + } + } // Disable and reset interface vhost_user_term_if (vui); @@ -1359,8 +1430,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); } /* @@ -1371,7 +1440,7 @@ vhost_user_vui_init (vnet_main_t * vnm, vhost_user_intf_t * vui, int server_sock_fd, const char *sock_filename, - u64 feature_mask, u32 * sw_if_index) + u64 feature_mask, u32 * sw_if_index, u8 enable_gso) { vnet_sw_interface_t *sw; int q; @@ -1397,11 +1466,28 @@ 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; vui->if_index = vui - vum->vhost_user_interfaces; + vui->enable_gso = enable_gso; + /* + * enable_gso takes precedence over configurable feature mask if there + * is a clash. + * if feature mask disables gso, but enable_gso is configured, + * then gso is enable + * if feature mask enables gso, but enable_gso is not configured, + * then gso is enable + * + * if gso is enable via feature mask, it must enable both host and guest + * gso feature mask, we don't support one sided GSO or partial GSO. + */ + if ((vui->enable_gso == 0) && + ((feature_mask & FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS) == + (FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS))) + vui->enable_gso = 1; + vhost_user_update_gso_interface_count (vui, 1 /* add */ ); mhash_set_mem (&vum->if_index_by_sock_name, vui->sock_filename, &vui->if_index, 0); @@ -1418,7 +1504,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, @@ -1432,7 +1518,8 @@ vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm, u8 is_server, u32 * sw_if_index, u64 feature_mask, - u8 renumber, u32 custom_dev_instance, u8 * hwaddr) + u8 renumber, u32 custom_dev_instance, u8 * hwaddr, + u8 enable_gso) { vhost_user_intf_t *vui = NULL; u32 sw_if_idx = ~0; @@ -1466,11 +1553,16 @@ vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm, } } + /* Protect the uninitialized vui from being dispatched by rx/tx */ + vlib_worker_thread_barrier_sync (vm); pool_get (vhost_user_main.vhost_user_interfaces, vui); - vhost_user_create_ethernet (vnm, vm, vui, hwaddr); + vlib_worker_thread_barrier_release (vm); + vhost_user_vui_init (vnm, vui, server_sock_fd, sock_filename, - feature_mask, &sw_if_idx); + feature_mask, &sw_if_idx, enable_gso); + vnet_sw_interface_set_mtu (vnm, vui->sw_if_index, 9000); + vhost_user_rx_thread_placement (vui, 1); if (renumber) vnet_interface_name_renumber (sw_if_idx, custom_dev_instance); @@ -1489,7 +1581,8 @@ vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm, const char *sock_filename, u8 is_server, u32 sw_if_index, - u64 feature_mask, u8 renumber, u32 custom_dev_instance) + u64 feature_mask, u8 renumber, u32 custom_dev_instance, + u8 enable_gso) { vhost_user_main_t *vum = &vhost_user_main; vhost_user_intf_t *vui = NULL; @@ -1499,8 +1592,10 @@ vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm, vnet_hw_interface_t *hwif; uword *if_index; - if (!(hwif = vnet_get_sup_hw_interface (vnm, sw_if_index)) || - hwif->dev_class_index != vhost_user_device_class.index) + if (! + (hwif = + vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index)) + || hwif->dev_class_index != vhost_user_device_class.index) return VNET_API_ERROR_INVALID_SW_IF_INDEX; if (sock_filename == NULL || !(strlen (sock_filename) > 0)) @@ -1524,7 +1619,7 @@ vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm, vhost_user_term_if (vui); vhost_user_vui_init (vnm, vui, server_sock_fd, - sock_filename, feature_mask, &sw_if_idx); + sock_filename, feature_mask, &sw_if_idx, enable_gso); if (renumber) vnet_interface_name_renumber (sw_if_idx, custom_dev_instance); @@ -1550,17 +1645,22 @@ vhost_user_connect_command_fn (vlib_main_t * vm, u8 hwaddr[6]; u8 *hw = NULL; clib_error_t *error = NULL; + u8 enable_gso = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; + /* GSO feature is disable by default */ + feature_mask &= ~FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "socket %s", &sock_filename)) ; else if (unformat (line_input, "server")) is_server = 1; + else if (unformat (line_input, "gso")) + enable_gso = 1; else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask)) ; else @@ -1584,7 +1684,8 @@ vhost_user_connect_command_fn (vlib_main_t * vm, 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, + enable_gso))) { error = clib_error_return (0, "vhost_user_create_if returned %d", rv); goto done; @@ -1623,7 +1724,7 @@ vhost_user_delete_command_fn (vlib_main_t * vm, &sw_if_index)) { vnet_hw_interface_t *hwif = - vnet_get_sup_hw_interface (vnm, sw_if_index); + vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index); if (hwif == NULL || vhost_user_device_class.index != hwif->dev_class_index) { @@ -1709,7 +1810,7 @@ show_vhost_user_command_fn (vlib_main_t * vm, vhost_user_intf_t *vui; u32 hw_if_index, *hw_if_indices = 0; vnet_hw_interface_t *hi; - u16 *queue; + u16 qid; u32 ci; int i, j, q; int show_descr = 0; @@ -1770,15 +1871,19 @@ show_vhost_user_command_fn (vlib_main_t * vm, vlib_cli_output (vm, "Virtio vhost-user interfaces"); vlib_cli_output (vm, "Global:\n coalesce frames %d time %e", vum->coalesce_frames, vum->coalesce_time); - vlib_cli_output (vm, " number of rx virtqueues in interrupt mode: %d", + vlib_cli_output (vm, " Number of rx virtqueues in interrupt mode: %d", vum->ifq_count); + vlib_cli_output (vm, " Number of GSO interfaces: %d", vum->gso_count); for (i = 0; i < vec_len (hw_if_indices); i++) { 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]); + if (vui->enable_gso) + vlib_cli_output (vm, " GSO enable"); vlib_cli_output (vm, "virtio_net_hdr_sz %d\n" " features mask (0x%llx): \n" @@ -1815,20 +1920,24 @@ show_vhost_user_command_fn (vlib_main_t * vm, vlib_cli_output (vm, " rx placement: "); - vec_foreach (queue, vui->rx_queues) - { - vnet_main_t *vnm = vnet_get_main (); - uword thread_index; - vnet_hw_interface_rx_mode mode; - - thread_index = vnet_get_device_input_thread_index (vnm, - vui->hw_if_index, - *queue); - vnet_hw_interface_get_rx_mode (vnm, vui->hw_if_index, *queue, &mode); - vlib_cli_output (vm, " thread %d on vring %d, %U\n", - thread_index, VHOST_VRING_IDX_TX (*queue), - format_vnet_hw_interface_rx_mode, mode); - } + for (qid = 1; qid < VHOST_VRING_MAX_N / 2; qid += 2) + { + vnet_main_t *vnm = vnet_get_main (); + uword thread_index; + vnet_hw_interface_rx_mode mode; + vhost_user_vring_t *txvq = &vui->vrings[qid]; + + if (txvq->qid == -1) + continue; + thread_index = + vnet_get_device_input_thread_index (vnm, vui->hw_if_index, + qid >> 1); + vnet_hw_interface_get_rx_mode (vnm, vui->hw_if_index, qid >> 1, + &mode); + vlib_cli_output (vm, " thread %d on vring %d, %U\n", + thread_index, qid, + format_vnet_hw_interface_rx_mode, mode); + } vlib_cli_output (vm, " tx placement: %s\n", vui->use_tx_spinlock ? "spin-lock" : "lock-free"); @@ -1981,8 +2090,9 @@ done: VLIB_CLI_COMMAND (vhost_user_connect_command, static) = { .path = "create vhost-user", .short_help = "create vhost-user socket [server] " - "[feature-mask ] [hwaddr ] [renumber ] ", + "[feature-mask ] [hwaddr ] [renumber ] [gso]", .function = vhost_user_connect_command_fn, + .is_mp_safe = 1, }; /* *INDENT-ON* */ @@ -2146,63 +2256,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 ", - .function = debug_vhost_user_command_fn, -}; -/* *INDENT-ON* */ static clib_error_t * vhost_user_config (vlib_main_t * vm, unformat_input_t * input) @@ -2225,7 +2278,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");