diff options
-rw-r--r-- | src/vnet/devices/tap/cli.c | 3 | ||||
-rw-r--r-- | src/vnet/devices/tap/tap.c | 365 | ||||
-rw-r--r-- | src/vnet/devices/tap/tap.h | 1 | ||||
-rw-r--r-- | src/vnet/devices/virtio/virtio.c | 39 | ||||
-rw-r--r-- | src/vnet/devices/virtio/virtio.h | 14 |
5 files changed, 261 insertions, 161 deletions
diff --git a/src/vnet/devices/tap/cli.c b/src/vnet/devices/tap/cli.c index 42fa8d73f35..abec8f07842 100644 --- a/src/vnet/devices/tap/cli.c +++ b/src/vnet/devices/tap/cli.c @@ -42,6 +42,7 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, args.id = ~0; args.tap_flags = 0; args.rv = -1; + args.num_rx_queues = 1; /* Get a line of input. */ if (unformat_user (input, unformat_line_input, line_input)) @@ -74,6 +75,8 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "host-ip6-gw %U", unformat_ip6_address, &args.host_ip6_gw)) args.host_ip6_gw_set = 1; + else if (unformat (line_input, "num-rx-queues %d", &tmp)) + args.num_rx_queues = tmp; else if (unformat (line_input, "rx-ring-size %d", &tmp)) args.rx_ring_sz = tmp; else if (unformat (line_input, "tx-ring-size %d", &tmp)) diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c index a1d5981086c..5f6d720c645 100644 --- a/src/vnet/devices/tap/tap.c +++ b/src/vnet/devices/tap/tap.c @@ -25,7 +25,9 @@ #include <linux/virtio_net.h> #include <linux/vhost.h> #include <sys/eventfd.h> +#include <net/if_arp.h> #include <sched.h> +#include <limits.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> @@ -42,10 +44,16 @@ tap_main_t tap_main; +#define tap_log_err(dev, f, ...) \ + vlib_log (VLIB_LOG_LEVEL_ERR, tap_main.log_default, "tap%u: " f, dev->dev_instance, ## __VA_ARGS__) +#define tap_log_dbg(dev, f, ...) \ + vlib_log (VLIB_LOG_LEVEL_DEBUG, tap_main.log_default, "tap%u: " f, dev->dev_instance, ## __VA_ARGS__) + #define _IOCTL(fd,a,...) \ if (ioctl (fd, a, __VA_ARGS__) < 0) \ { \ err = clib_error_return_unix (0, "ioctl(" #a ")"); \ + tap_log_err (vif, "%U", format_clib_error, err); \ goto error; \ } @@ -78,9 +86,42 @@ open_netns_fd (char *netns) #define TAP_MAX_INSTANCE 1024 +static void +tap_free (vlib_main_t * vm, virtio_if_t * vif) +{ + virtio_main_t *mm = &virtio_main; + tap_main_t *tm = &tap_main; + int i; + + /* *INDENT-OFF* */ + vec_foreach_index (i, vif->vhost_fds) if (vif->vhost_fds[i] != -1) + close (vif->vhost_fds[i]); + vec_foreach_index (i, vif->rxq_vrings) + virtio_vring_free_rx (vm, vif, RX_QUEUE (i)); + vec_foreach_index (i, vif->txq_vrings) + virtio_vring_free_tx (vm, vif, TX_QUEUE (i)); + /* *INDENT-ON* */ + + if (vif->tap_fd != -1) + close (vif->tap_fd); + + vec_free (vif->vhost_fds); + vec_free (vif->rxq_vrings); + vec_free (vif->txq_vrings); + vec_free (vif->host_if_name); + vec_free (vif->net_ns); + vec_free (vif->host_bridge); + clib_error_free (vif->error); + + tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 0); + clib_memset (vif, 0, sizeof (*vif)); + pool_put (mm->interfaces, vif); +} + void tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) { + vlib_thread_main_t *thm = vlib_get_thread_main (); vlib_physmem_main_t *vpm = &vm->physmem_main; vnet_main_t *vnm = vnet_get_main (); virtio_main_t *vim = &virtio_main; @@ -89,14 +130,16 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) vnet_hw_interface_t *hw; int i; int old_netns_fd = -1; - struct ifreq ifr; + struct ifreq ifr = {.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR }; size_t hdrsz; struct vhost_memory *vhost_mem = 0; virtio_if_t *vif = 0; clib_error_t *err = 0; unsigned int tap_features; - int fd = -1; + int tfd, vfd, nfd = -1; char *host_if_name = 0; + unsigned int offload = 0; + u16 num_q_pairs; if (args->id != ~0) { @@ -119,20 +162,104 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) return; } - clib_memset (&ifr, 0, sizeof (ifr)); - pool_get (vim->interfaces, vif); + pool_get_zero (vim->interfaces, vif); + vif->type = VIRTIO_IF_TYPE_TAP; vif->dev_instance = vif - vim->interfaces; - vif->tap_fd = -1; vif->id = args->id; + vif->num_txqs = thm->n_vlib_mains; + vif->num_rxqs = args->num_rx_queues; + num_q_pairs = clib_max (vif->num_rxqs, vif->num_txqs); + + if (ethernet_mac_address_is_zero (args->host_mac_addr)) + ethernet_mac_address_generate (args->host_mac_addr); + clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6); - if ((vif->fd = open ("/dev/vhost-net", O_RDWR | O_NONBLOCK)) < 0) + if ((vif->tap_fd = tfd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0) { - args->rv = VNET_API_ERROR_SYSCALL_ERROR_1; - args->error = clib_error_return_unix (0, "open '/dev/vhost-net'"); + args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; + args->error = clib_error_return_unix (0, "open '/dev/net/tun'"); goto error; } + tap_log_dbg (vif, "open tap fd %d", tfd); - _IOCTL (vif->fd, VHOST_GET_FEATURES, &vif->remote_features); + _IOCTL (tfd, TUNGETFEATURES, &tap_features); + tap_log_dbg (vif, "TUNGETFEATURES: features 0x%lx", tap_features); + if ((tap_features & IFF_VNET_HDR) == 0) + { + args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; + args->error = clib_error_return (0, "vhost-net backend not available"); + goto error; + } + + if ((tap_features & IFF_MULTI_QUEUE) == 0) + { + if (args->num_rx_queues > 1) + { + args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; + args->error = clib_error_return (0, "multiqueue not supported"); + goto error; + } + vif->num_rxqs = vif->num_txqs = num_q_pairs = 1; + } + else + ifr.ifr_flags |= IFF_MULTI_QUEUE; + + hdrsz = sizeof (struct virtio_net_hdr_v1); + if (args->tap_flags & TAP_FLAG_GSO) + { + offload = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6; + vif->gso_enabled = 1; + } + + _IOCTL (tfd, TUNSETIFF, (void *) &ifr); + tap_log_dbg (vif, "TUNSETIFF fd %d name %s flags 0x%x", tfd, + ifr.ifr_ifrn.ifrn_name, ifr.ifr_flags); + + vif->ifindex = if_nametoindex (ifr.ifr_ifrn.ifrn_name); + tap_log_dbg (vif, "ifindex %d", vif->ifindex); + + if (!args->host_if_name) + host_if_name = ifr.ifr_ifrn.ifrn_name; + else + host_if_name = (char *) args->host_if_name; + + fcntl (tfd, F_SETFL, O_NONBLOCK); + + tap_log_dbg (vif, "TUNSETVNETHDRSZ: fd %d vnet_hdr_sz %u", tfd, hdrsz); + _IOCTL (tfd, TUNSETVNETHDRSZ, &hdrsz); + + i = INT_MAX; + tap_log_dbg (vif, "TUNSETSNDBUF: fd %d sndbuf %d", tfd, i); + _IOCTL (tfd, TUNSETSNDBUF, &i); + + tap_log_dbg (vif, "TUNSETOFFLOAD: fd %d offload 0x%lx", tfd, offload); + _IOCTL (tfd, TUNSETOFFLOAD, offload); + + clib_memset (&ifr, 0, sizeof (ifr)); + ifr.ifr_addr.sa_family = ARPHRD_ETHER; + clib_memcpy (ifr.ifr_hwaddr.sa_data, vif->host_mac_addr, 6); + tap_log_dbg (vif, "SIOCSIFHWADDR: fd %d hwaddr %U", tfd, + format_hex_bytes, ifr.ifr_hwaddr.sa_data, 6); + _IOCTL (tfd, SIOCSIFHWADDR, (void *) &ifr); + + /* open vhost-net fd for each queue pair and set ownership */ + for (i = 0; i < num_q_pairs; i++) + { + if ((vfd = open ("/dev/vhost-net", O_RDWR | O_NONBLOCK)) < 0) + { + args->rv = VNET_API_ERROR_SYSCALL_ERROR_1; + args->error = clib_error_return_unix (0, "open '/dev/vhost-net'"); + goto error; + } + vec_add1 (vif->vhost_fds, vfd); + virtio_log_debug (vif, "open vhost-net fd %d qpair %u", vfd, i); + _IOCTL (vfd, VHOST_SET_OWNER, 0); + virtio_log_debug (vif, "VHOST_SET_OWNER: fd %u", vfd); + } + + _IOCTL (vif->vhost_fds[0], VHOST_GET_FEATURES, &vif->remote_features); + virtio_log_debug (vif, "VHOST_GET_FEATURES: features 0x%lx", + vif->remote_features); if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF)) == 0) { @@ -165,68 +292,26 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) virtio_set_net_hdr_size (vif); - _IOCTL (vif->fd, VHOST_SET_FEATURES, &vif->features); - - if ((vif->tap_fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0) - { - args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; - args->error = clib_error_return_unix (0, "open '/dev/net/tun'"); - goto error; - } - - _IOCTL (vif->tap_fd, TUNGETFEATURES, &tap_features); - if ((tap_features & IFF_VNET_HDR) == 0) - { - args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; - args->error = clib_error_return (0, "vhost-net backend not available"); - goto error; - } - - ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR; - _IOCTL (vif->tap_fd, TUNSETIFF, (void *) &ifr); - vif->ifindex = if_nametoindex (ifr.ifr_ifrn.ifrn_name); - - if (!args->host_if_name) - host_if_name = ifr.ifr_ifrn.ifrn_name; - else - host_if_name = (char *) args->host_if_name; - - unsigned int offload = 0; - hdrsz = sizeof (struct virtio_net_hdr_v1); - if (args->tap_flags & TAP_FLAG_GSO) - { - offload = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6; - vif->gso_enabled = 1; - } - else - { - vif->gso_enabled = 0; - } - - _IOCTL (vif->tap_fd, TUNSETOFFLOAD, offload); - _IOCTL (vif->tap_fd, TUNSETVNETHDRSZ, &hdrsz); - _IOCTL (vif->fd, VHOST_SET_OWNER, 0); - /* if namespace is specified, all further netlink messages should be executed after we change our net namespace */ if (args->host_namespace) { old_netns_fd = open ("/proc/self/ns/net", O_RDONLY); - if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1) + if ((nfd = open_netns_fd ((char *) args->host_namespace)) == -1) { args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; args->error = clib_error_return_unix (0, "open_netns_fd '%s'", args->host_namespace); goto error; } - args->error = vnet_netlink_set_link_netns (vif->ifindex, fd, + args->error = vnet_netlink_set_link_netns (vif->ifindex, nfd, host_if_name); if (args->error) { args->rv = VNET_API_ERROR_NETLINK_ERROR; goto error; } - if (setns (fd, CLONE_NEWNET) == -1) + if (setns (nfd, CLONE_NEWNET) == -1) { args->rv = VNET_API_ERROR_SYSCALL_ERROR_3; args->error = clib_error_return_unix (0, "setns '%s'", @@ -255,17 +340,6 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) } } - if (!ethernet_mac_address_is_zero (args->host_mac_addr)) - { - args->error = vnet_netlink_set_link_addr (vif->ifindex, - args->host_mac_addr); - if (args->error) - { - args->rv = VNET_API_ERROR_NETLINK_ERROR; - goto error; - } - } - if (args->host_bridge) { args->error = vnet_netlink_set_link_master (vif->ifindex, @@ -277,7 +351,6 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) } } - if (args->host_ip4_prefix_len) { args->error = vnet_netlink_add_ip4_addr (vif->ifindex, @@ -364,7 +437,26 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) args->host_mtu_size = tm->host_mtu_size; } - /* Set vhost memory table */ + for (i = 0; i < num_q_pairs; i++) + { + if (i < vif->num_rxqs && (args->error = + virtio_vring_init (vm, vif, RX_QUEUE (i), + args->rx_ring_sz))) + { + args->rv = VNET_API_ERROR_INIT_FAILED; + goto error; + } + + if (i < vif->num_txqs && (args->error = + virtio_vring_init (vm, vif, TX_QUEUE (i), + args->tx_ring_sz))) + { + args->rv = VNET_API_ERROR_INIT_FAILED; + goto error; + } + } + + /* setup features and memtable */ i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region); vhost_mem = clib_mem_alloc (i); clib_memset (vhost_mem, 0, i); @@ -373,23 +465,81 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) vhost_mem->regions[0].guest_phys_addr = vpm->base_addr; vhost_mem->regions[0].userspace_addr = vhost_mem->regions[0].guest_phys_addr; - _IOCTL (vif->fd, VHOST_SET_MEM_TABLE, vhost_mem); - if ((args->error = - virtio_vring_init (vm, vif, RX_QUEUE (0), args->rx_ring_sz))) + for (i = 0; i < vhost_mem->nregions; i++) + virtio_log_debug (vif, "memtable region %u memory_size 0x%lx " + "guest_phys_addr 0x%lx userspace_addr 0x%lx", i, + vhost_mem->regions[0].memory_size, + vhost_mem->regions[0].guest_phys_addr, + vhost_mem->regions[0].userspace_addr); + + + for (i = 0; i < num_q_pairs; i++) { - args->rv = VNET_API_ERROR_INIT_FAILED; - goto error; + int fd = vif->vhost_fds[i]; + _IOCTL (fd, VHOST_SET_FEATURES, &vif->features); + virtio_log_debug (vif, "VHOST_SET_FEATURES: fd %u features 0x%lx", + fd, vif->features); + _IOCTL (fd, VHOST_SET_MEM_TABLE, vhost_mem); + virtio_log_debug (vif, "VHOST_SET_MEM_TABLE: fd %u", fd); } - vif->num_rxqs = 1; - if ((args->error = - virtio_vring_init (vm, vif, TX_QUEUE (0), args->tx_ring_sz))) + /* finish initializing queue pair */ + for (i = 0; i < num_q_pairs * 2; i++) { - args->rv = VNET_API_ERROR_INIT_FAILED; - goto error; + struct vhost_vring_addr addr = { 0 }; + struct vhost_vring_state state = { 0 }; + struct vhost_vring_file file = { 0 }; + virtio_vring_t *vring; + u16 qp = i >> 1; + int fd = vif->vhost_fds[qp]; + + if (i & 1) + { + if (qp >= vif->num_txqs) + continue; + vring = vec_elt_at_index (vif->txq_vrings, qp); + } + else + { + if (qp >= vif->num_rxqs) + continue; + vring = vec_elt_at_index (vif->rxq_vrings, qp); + } + + addr.index = state.index = file.index = vring->queue_id & 1; + state.num = vring->size; + virtio_log_debug (vif, "VHOST_SET_VRING_NUM fd %d index %u num %u", fd, + state.index, state.num); + _IOCTL (fd, VHOST_SET_VRING_NUM, &state); + + addr.flags = 0; + addr.desc_user_addr = pointer_to_uword (vring->desc); + addr.avail_user_addr = pointer_to_uword (vring->avail); + addr.used_user_addr = pointer_to_uword (vring->used); + + virtio_log_debug (vif, "VHOST_SET_VRING_ADDR fd %d index %u flags 0x%x " + "desc_user_addr 0x%lx avail_user_addr 0x%lx " + "used_user_addr 0x%lx", fd, addr.index, + addr.flags, addr.desc_user_addr, addr.avail_user_addr, + addr.used_user_addr); + _IOCTL (fd, VHOST_SET_VRING_ADDR, &addr); + + file.fd = vring->call_fd; + virtio_log_debug (vif, "VHOST_SET_VRING_CALL fd %d index %u call_fd %d", + fd, file.index, file.fd); + _IOCTL (fd, VHOST_SET_VRING_CALL, &file); + + file.fd = vring->kick_fd; + virtio_log_debug (vif, "VHOST_SET_VRING_KICK fd %d index %u kick_fd %d", + fd, file.index, file.fd); + _IOCTL (fd, VHOST_SET_VRING_KICK, &file); + + file.fd = tfd; + virtio_log_debug (vif, "VHOST_NET_SET_BACKEND fd %d index %u tap_fd %d", + fd, file.index, file.fd); + _IOCTL (fd, VHOST_NET_SET_BACKEND, &file); } - vif->num_txqs = 1; if (!args->mac_addr_set) ethernet_mac_address_generate (args->mac_addr); @@ -400,7 +550,6 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) vif->net_ns = format (0, "%s%c", args->host_namespace, 0); vif->host_bridge = format (0, "%s%c", args->host_bridge, 0); vif->host_mtu_size = args->host_mtu_size; - clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6); vif->host_ip4_prefix_len = args->host_ip4_prefix_len; vif->host_ip6_prefix_len = args->host_ip6_prefix_len; if (args->host_ip4_prefix_len) @@ -408,7 +557,6 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) if (args->host_ip6_prefix_len) clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16); - vif->type = VIRTIO_IF_TYPE_TAP; args->error = ethernet_register_interface (vnm, virtio_device_class.index, vif->dev_instance, vif->mac_addr, @@ -434,9 +582,14 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) } vnet_hw_interface_set_input_node (vnm, vif->hw_if_index, virtio_input_node.index); - vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, 0, ~0); - vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, 0, - VNET_HW_INTERFACE_RX_MODE_DEFAULT); + + for (i = 0; i < vif->num_rxqs; i++) + { + vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, i, ~0); + vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, i, + VNET_HW_INTERFACE_RX_MODE_DEFAULT); + } + vif->per_interface_next_index = ~0; virtio_vring_set_numa_node (vm, vif, RX_QUEUE (0)); vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; @@ -453,31 +606,15 @@ error: args->error = err; args->rv = VNET_API_ERROR_SYSCALL_ERROR_3; } - if (vif->tap_fd != -1) - close (vif->tap_fd); - if (vif->fd != -1) - close (vif->fd); - vec_foreach_index (i, vif->rxq_vrings) virtio_vring_free_rx (vm, vif, - RX_QUEUE (i)); - vec_foreach_index (i, vif->txq_vrings) virtio_vring_free_tx (vm, vif, - TX_QUEUE (i)); - vec_free (vif->rxq_vrings); - vec_free (vif->txq_vrings); - - vec_free (vif->host_if_name); - vec_free (vif->net_ns); - vec_free (vif->host_bridge); - - clib_memset (vif, 0, sizeof (virtio_if_t)); - pool_put (vim->interfaces, vif); + tap_free (vm, vif); done: if (vhost_mem) clib_mem_free (vhost_mem); if (old_netns_fd != -1) close (old_netns_fd); - if (fd != -1) - close (fd); + if (nfd != -1) + close (nfd); } int @@ -485,7 +622,6 @@ tap_delete_if (vlib_main_t * vm, u32 sw_if_index) { vnet_main_t *vnm = vnet_get_main (); virtio_main_t *mm = &virtio_main; - tap_main_t *tm = &tap_main; int i; virtio_if_t *vif; vnet_hw_interface_t *hw; @@ -506,30 +642,13 @@ tap_delete_if (vlib_main_t * vm, u32 sw_if_index) /* bring down the interface */ vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0); vnet_sw_interface_set_flags (vnm, vif->sw_if_index, 0); - vnet_hw_interface_unassign_rx_thread (vnm, vif->hw_if_index, RX_QUEUE (0)); + for (i = 0; i < vif->num_rxqs; i++) + vnet_hw_interface_unassign_rx_thread (vnm, vif->hw_if_index, i); ethernet_delete_interface (vnm, vif->hw_if_index); vif->hw_if_index = ~0; - if (vif->tap_fd != -1) - close (vif->tap_fd); - if (vif->fd != -1) - close (vif->fd); - - vec_foreach_index (i, vif->rxq_vrings) virtio_vring_free_rx (vm, vif, - RX_QUEUE (i)); - vec_foreach_index (i, vif->txq_vrings) virtio_vring_free_tx (vm, vif, - TX_QUEUE (i)); - vec_free (vif->rxq_vrings); - vec_free (vif->txq_vrings); - - vec_free (vif->host_if_name); - vec_free (vif->net_ns); - vec_free (vif->host_bridge); - - tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 0); - clib_memset (vif, 0, sizeof (*vif)); - pool_put (mm->interfaces, vif); + tap_free (vm, vif); return 0; } diff --git a/src/vnet/devices/tap/tap.h b/src/vnet/devices/tap/tap.h index 45ff1d9910e..46edf02b1e9 100644 --- a/src/vnet/devices/tap/tap.h +++ b/src/vnet/devices/tap/tap.h @@ -27,6 +27,7 @@ typedef struct u32 id; u8 mac_addr_set; u8 mac_addr[6]; + u8 num_rx_queues; u16 rx_ring_sz; u16 tx_ring_sz; u32 tap_flags; diff --git a/src/vnet/devices/virtio/virtio.c b/src/vnet/devices/virtio/virtio.c index da4f755ec10..d3a6e15ac56 100644 --- a/src/vnet/devices/virtio/virtio.c +++ b/src/vnet/devices/virtio/virtio.c @@ -64,11 +64,7 @@ call_read_ready (clib_file_t * uf) clib_error_t * virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz) { - clib_error_t *err = 0; virtio_vring_t *vring; - struct vhost_vring_state state = { 0 }; - struct vhost_vring_addr addr = { 0 }; - struct vhost_vring_file file = { 0 }; clib_file_t t = { 0 }; int i; @@ -87,7 +83,7 @@ virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz) vec_validate_aligned (vif->txq_vrings, TX_QUEUE_ACCESS (idx), CLIB_CACHE_LINE_BYTES); vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (idx)); - if (thm->n_vlib_mains > 1) + if (thm->n_vlib_mains > vif->num_txqs) clib_spinlock_init (&vring->lockp); } else @@ -119,7 +115,9 @@ virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz) vring->size = sz; vring->call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); - vring->kick_fd = eventfd (0, EFD_CLOEXEC); + vring->kick_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); + virtio_log_debug (vif, "vring %u size %u call_fd %d kick_fd %d", idx, + vring->size, vring->call_fd, vring->kick_fd); t.read_function = call_read_ready; t.file_descriptor = vring->call_fd; @@ -128,27 +126,7 @@ virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz) vif->dev_instance, idx); vring->call_file_index = clib_file_add (&file_main, &t); - state.index = idx; - state.num = sz; - _IOCTL (vif->fd, VHOST_SET_VRING_NUM, &state); - - addr.index = idx; - addr.flags = 0; - addr.desc_user_addr = pointer_to_uword (vring->desc); - addr.avail_user_addr = pointer_to_uword (vring->avail); - addr.used_user_addr = pointer_to_uword (vring->used); - _IOCTL (vif->fd, VHOST_SET_VRING_ADDR, &addr); - - file.index = idx; - file.fd = vring->kick_fd; - _IOCTL (vif->fd, VHOST_SET_VRING_KICK, &file); - file.fd = vring->call_fd; - _IOCTL (vif->fd, VHOST_SET_VRING_CALL, &file); - file.fd = vif->tap_fd; - _IOCTL (vif->fd, VHOST_NET_SET_BACKEND, &file); - -error: - return err; + return 0; } inline void @@ -313,6 +291,7 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type) } if (type == VIRTIO_IF_TYPE_TAP) { + u8 *str = 0; if (vif->host_if_name) vlib_cli_output (vm, " name \"%s\"", vif->host_if_name); if (vif->net_ns) @@ -320,7 +299,11 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type) if (vif->host_mtu_size) vlib_cli_output (vm, " host-mtu-size \"%d\"", vif->host_mtu_size); - vlib_cli_output (vm, " fd %d", vif->fd); + + vec_foreach_index (i, vif->vhost_fds) + str = format (str, " %d", vif->vhost_fds[i]); + vlib_cli_output (vm, " vhost-fds%v", str); + vec_free (str); vlib_cli_output (vm, " tap-fd %d", vif->tap_fd); } vlib_cli_output (vm, " gso-enabled %d", vif->gso_enabled); diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h index 2cf1653d1c2..27ecc2238ad 100644 --- a/src/vnet/devices/virtio/virtio.h +++ b/src/vnet/devices/virtio/virtio.h @@ -148,16 +148,10 @@ typedef struct pci_addr_t pci_addr; }; u32 per_interface_next_index; - union - { - int fd; - u32 msix_enabled; - }; - union - { - int tap_fd; - u32 pci_dev_handle; - }; + int *vhost_fds; + int tap_fd; + u32 msix_enabled; + u32 pci_dev_handle; virtio_vring_t *rxq_vrings; virtio_vring_t *txq_vrings; u64 features, remote_features; |