2 *------------------------------------------------------------------
5 * Copyright (c) 2014-2018 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <fcntl.h> /* for open */
21 #include <sys/ioctl.h>
22 #include <sys/socket.h>
25 #include <sys/types.h>
26 #include <sys/uio.h> /* for iovec */
27 #include <netinet/in.h>
30 #include <linux/if_arp.h>
31 #include <linux/if_tun.h>
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
36 #include <vnet/ip/ip.h>
38 #include <vnet/ethernet/ethernet.h>
39 #include <vnet/devices/devices.h>
40 #include <vnet/feature/feature.h>
42 #include <vnet/devices/virtio/vhost_user.h>
43 #include <vnet/devices/virtio/vhost_user_inline.h>
47 * @brief vHost User Device Driver.
49 * This file contains the source code for vHost User interface.
53 vlib_node_registration_t vhost_user_send_interrupt_node;
56 vhost_user_main_t vhost_user_main = {
60 VNET_HW_INTERFACE_CLASS (vhost_interface_class, static) = {
66 get_huge_page_size (int fd)
74 unmap_all_mem_regions (vhost_user_intf_t * vui)
77 vhost_user_vring_t *vq;
79 for (i = 0; i < vui->nregions; i++)
81 if (vui->region_mmap_addr[i] != MAP_FAILED)
84 long page_sz = get_huge_page_size (vui->region_mmap_fd[i]);
86 ssize_t map_sz = (vui->regions[i].memory_size +
87 vui->regions[i].mmap_offset +
88 page_sz - 1) & ~(page_sz - 1);
91 munmap (vui->region_mmap_addr[i] - vui->regions[i].mmap_offset,
94 vu_log_debug (vui, "unmap memory region %d addr 0x%lx len 0x%lx "
95 "page_sz 0x%x", i, vui->region_mmap_addr[i], map_sz,
98 vui->region_mmap_addr[i] = MAP_FAILED;
102 vu_log_err (vui, "failed to unmap memory region (errno %d)",
105 close (vui->region_mmap_fd[i]);
110 for (q = 0; q < VHOST_VRING_MAX_N; q++)
112 vq = &vui->vrings[q];
119 static_always_inline void
120 vhost_user_tx_thread_placement (vhost_user_intf_t * vui)
122 //Let's try to assign one queue to each thread
124 u32 thread_index = 0;
126 vui->use_tx_spinlock = 0;
129 for (qid = 0; qid < VHOST_VRING_MAX_N / 2; qid++)
131 vhost_user_vring_t *rxvq = &vui->vrings[VHOST_VRING_IDX_RX (qid)];
132 if (!rxvq->started || !rxvq->enabled)
135 vui->per_cpu_tx_qid[thread_index] = qid;
137 if (thread_index == vlib_get_thread_main ()->n_vlib_mains)
140 //We need to loop, meaning the spinlock has to be used
141 vui->use_tx_spinlock = 1;
142 if (thread_index == 0)
144 //Could not find a single valid one
145 for (thread_index = 0;
146 thread_index < vlib_get_thread_main ()->n_vlib_mains;
149 vui->per_cpu_tx_qid[thread_index] = 0;
157 * @brief Unassign existing interface/queue to thread mappings and re-assign
158 * new interface/queue to thread mappings
160 static_always_inline void
161 vhost_user_rx_thread_placement (vhost_user_intf_t * vui, u32 qid)
163 vhost_user_vring_t *txvq = &vui->vrings[qid];
164 vnet_main_t *vnm = vnet_get_main ();
168 ASSERT ((qid & 1) == 1); // should be odd
169 // Assign new queue mappings for the interface
170 vnet_hw_interface_set_input_node (vnm, vui->hw_if_index,
171 vhost_user_input_node.index);
172 vnet_hw_interface_assign_rx_thread (vnm, vui->hw_if_index, q, ~0);
173 if (txvq->mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
174 /* Set polling as the default */
175 txvq->mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
177 rv = vnet_hw_interface_set_rx_mode (vnm, vui->hw_if_index, q, txvq->mode);
179 vu_log_warn (vui, "unable to set rx mode for interface %d, "
180 "queue %d: rc=%d", vui->hw_if_index, q, rv);
183 /** @brief Returns whether at least one TX and one RX vring are enabled */
184 static_always_inline int
185 vhost_user_intf_ready (vhost_user_intf_t * vui)
187 int i, found[2] = { }; //RX + TX
189 for (i = 0; i < VHOST_VRING_MAX_N; i++)
190 if (vui->vrings[i].started && vui->vrings[i].enabled)
193 return found[0] && found[1];
196 static_always_inline void
197 vhost_user_update_iface_state (vhost_user_intf_t * vui)
199 /* if we have pointers to descriptor table, go up */
200 int is_ready = vhost_user_intf_ready (vui);
201 if (is_ready != vui->is_ready)
203 vu_log_debug (vui, "interface %d %s", vui->sw_if_index,
204 is_ready ? "ready" : "down");
206 vnet_hw_interface_set_flags (vnet_get_main (), vui->hw_if_index,
207 is_ready ? VNET_HW_INTERFACE_FLAG_LINK_UP
209 vui->is_ready = is_ready;
214 vhost_user_set_interrupt_pending (vhost_user_intf_t * vui, u32 ifq)
217 vnet_main_t *vnm = vnet_get_main ();
221 /* Only care about the odd number, or TX, virtqueue */
224 if (vhost_user_intf_ready (vui))
225 // qid >> 1 is to convert virtqueue number to vring queue index
226 vnet_device_input_set_interrupt_pending (vnm, vui->hw_if_index, qid >> 1);
229 static clib_error_t *
230 vhost_user_callfd_read_ready (clib_file_t * uf)
232 __attribute__ ((unused)) int n;
235 n = read (uf->file_descriptor, ((char *) &buff), 8);
240 static_always_inline void
241 vhost_user_thread_placement (vhost_user_intf_t * vui, u32 qid)
243 if (qid & 1) // RX is odd, TX is even
245 if (vui->vrings[qid].qid == -1)
246 vhost_user_rx_thread_placement (vui, qid);
249 vhost_user_tx_thread_placement (vui);
252 static clib_error_t *
253 vhost_user_kickfd_read_ready (clib_file_t * uf)
255 __attribute__ ((unused)) int n;
257 vhost_user_intf_t *vui =
258 pool_elt_at_index (vhost_user_main.vhost_user_interfaces,
259 uf->private_data >> 8);
260 u32 qid = uf->private_data & 0xff;
262 n = read (uf->file_descriptor, ((char *) &buff), 8);
263 vu_log_debug (vui, "if %d KICK queue %d", uf->private_data >> 8, qid);
264 if (!vui->vrings[qid].started ||
265 (vhost_user_intf_ready (vui) != vui->is_ready))
267 if (vui->vrings[qid].started == 0)
269 vui->vrings[qid].started = 1;
270 vhost_user_thread_placement (vui, qid);
271 vhost_user_update_iface_state (vui);
275 vhost_user_set_interrupt_pending (vui, uf->private_data);
279 static_always_inline void
280 vhost_user_vring_init (vhost_user_intf_t * vui, u32 qid)
282 vhost_user_vring_t *vring = &vui->vrings[qid];
283 clib_memset (vring, 0, sizeof (*vring));
284 vring->kickfd_idx = ~0;
285 vring->callfd_idx = ~0;
290 * We have a bug with some qemu 2.5, and this may be a fix.
291 * Feel like interpretation holy text, but this is from vhost-user.txt.
293 * One queue pair is enabled initially. More queues are enabled
294 * dynamically, by sending message VHOST_USER_SET_VRING_ENABLE.
296 * Don't know who's right, but this is what DPDK does.
298 if (qid == 0 || qid == 1)
302 static_always_inline void
303 vhost_user_vring_close (vhost_user_intf_t * vui, u32 qid)
305 vhost_user_vring_t *vring = &vui->vrings[qid];
307 if (vring->kickfd_idx != ~0)
309 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
311 clib_file_del (&file_main, uf);
312 vring->kickfd_idx = ~0;
314 if (vring->callfd_idx != ~0)
316 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
318 clib_file_del (&file_main, uf);
319 vring->callfd_idx = ~0;
321 if (vring->errfd != -1)
323 close (vring->errfd);
327 // save the qid so that we don't need to unassign and assign_rx_thread
328 // when the interface comes back up. They are expensive calls.
329 u16 q = vui->vrings[qid].qid;
330 vhost_user_vring_init (vui, qid);
331 vui->vrings[qid].qid = q;
334 static_always_inline void
335 vhost_user_if_disconnect (vhost_user_intf_t * vui)
337 vnet_main_t *vnm = vnet_get_main ();
340 vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
342 if (vui->clib_file_index != ~0)
344 clib_file_del (&file_main, file_main.file_pool + vui->clib_file_index);
345 vui->clib_file_index = ~0;
350 for (q = 0; q < VHOST_VRING_MAX_N; q++)
351 vhost_user_vring_close (vui, q);
353 unmap_all_mem_regions (vui);
354 vu_log_debug (vui, "interface ifindex %d disconnected", vui->sw_if_index);
357 static clib_error_t *
358 vhost_user_socket_read (clib_file_t * uf)
361 int fd, number_of_fds = 0;
362 int fds[VHOST_MEMORY_MAX_NREGIONS];
363 vhost_user_msg_t msg;
366 vhost_user_main_t *vum = &vhost_user_main;
367 vhost_user_intf_t *vui;
368 struct cmsghdr *cmsg;
370 clib_file_t template = { 0 };
371 vnet_main_t *vnm = vnet_get_main ();
372 vlib_main_t *vm = vlib_get_main ();
374 vui = pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
376 char control[CMSG_SPACE (VHOST_MEMORY_MAX_NREGIONS * sizeof (int))];
378 clib_memset (&mh, 0, sizeof (mh));
379 clib_memset (control, 0, sizeof (control));
381 for (i = 0; i < VHOST_MEMORY_MAX_NREGIONS; i++)
384 /* set the payload */
385 iov[0].iov_base = (void *) &msg;
386 iov[0].iov_len = VHOST_USER_MSG_HDR_SZ;
390 mh.msg_control = control;
391 mh.msg_controllen = sizeof (control);
393 n = recvmsg (uf->file_descriptor, &mh, 0);
395 if (n != VHOST_USER_MSG_HDR_SZ)
399 vu_log_debug (vui, "recvmsg returned error %d %s", errno,
404 vu_log_debug (vui, "n (%d) != VHOST_USER_MSG_HDR_SZ (%d)",
405 n, VHOST_USER_MSG_HDR_SZ);
410 if (mh.msg_flags & MSG_CTRUNC)
412 vu_log_debug (vui, "MSG_CTRUNC is set");
416 cmsg = CMSG_FIRSTHDR (&mh);
418 if (cmsg && (cmsg->cmsg_len > 0) && (cmsg->cmsg_level == SOL_SOCKET) &&
419 (cmsg->cmsg_type == SCM_RIGHTS) &&
420 (cmsg->cmsg_len - CMSG_LEN (0) <=
421 VHOST_MEMORY_MAX_NREGIONS * sizeof (int)))
423 number_of_fds = (cmsg->cmsg_len - CMSG_LEN (0)) / sizeof (int);
424 clib_memcpy_fast (fds, CMSG_DATA (cmsg), number_of_fds * sizeof (int));
427 /* version 1, no reply bit set */
428 if ((msg.flags & 7) != 1)
430 vu_log_debug (vui, "malformed message received. closing socket");
437 read (uf->file_descriptor, ((char *) &msg) + VHOST_USER_MSG_HDR_SZ,
441 vu_log_debug (vui, "read failed %s", strerror (errno));
444 else if (rv != msg.size)
446 vu_log_debug (vui, "message too short (read %dB should be %dB)", rv,
454 case VHOST_USER_GET_FEATURES:
456 msg.u64 = (1ULL << FEAT_VIRTIO_NET_F_MRG_RXBUF) |
457 (1ULL << FEAT_VIRTIO_NET_F_CTRL_VQ) |
458 (1ULL << FEAT_VIRTIO_F_ANY_LAYOUT) |
459 (1ULL << FEAT_VIRTIO_F_INDIRECT_DESC) |
460 (1ULL << FEAT_VHOST_F_LOG_ALL) |
461 (1ULL << FEAT_VIRTIO_NET_F_GUEST_ANNOUNCE) |
462 (1ULL << FEAT_VIRTIO_NET_F_MQ) |
463 (1ULL << FEAT_VHOST_USER_F_PROTOCOL_FEATURES) |
464 (1ULL << FEAT_VIRTIO_F_VERSION_1);
465 msg.u64 &= vui->feature_mask;
468 msg.u64 |= FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS;
470 msg.size = sizeof (msg.u64);
471 vu_log_debug (vui, "if %d msg VHOST_USER_GET_FEATURES - reply "
472 "0x%016llx", vui->hw_if_index, msg.u64);
474 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
475 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
477 vu_log_debug (vui, "could not send message response");
482 case VHOST_USER_SET_FEATURES:
483 vu_log_debug (vui, "if %d msg VHOST_USER_SET_FEATURES features "
484 "0x%016llx", vui->hw_if_index, msg.u64);
486 vui->features = msg.u64;
489 ((1 << FEAT_VIRTIO_NET_F_MRG_RXBUF) |
490 (1ULL << FEAT_VIRTIO_F_VERSION_1)))
491 vui->virtio_net_hdr_sz = 12;
493 vui->virtio_net_hdr_sz = 10;
496 (vui->features & (1 << FEAT_VIRTIO_F_ANY_LAYOUT)) ? 1 : 0;
498 ASSERT (vui->virtio_net_hdr_sz < VLIB_BUFFER_PRE_DATA_SIZE);
499 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vui->hw_if_index);
500 if (vui->enable_gso &&
501 ((vui->features & FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS)
502 == FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS))
504 (VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO |
505 VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD);
507 hw->flags &= ~(VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO |
508 VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD);
509 vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
511 vhost_user_update_iface_state (vui);
514 case VHOST_USER_SET_MEM_TABLE:
515 vu_log_debug (vui, "if %d msg VHOST_USER_SET_MEM_TABLE nregions %d",
516 vui->hw_if_index, msg.memory.nregions);
518 if ((msg.memory.nregions < 1) ||
519 (msg.memory.nregions > VHOST_MEMORY_MAX_NREGIONS))
521 vu_log_debug (vui, "number of mem regions must be between 1 and %i",
522 VHOST_MEMORY_MAX_NREGIONS);
526 if (msg.memory.nregions != number_of_fds)
528 vu_log_debug (vui, "each memory region must have FD");
532 /* Do the mmap without barrier sync */
533 void *region_mmap_addr[VHOST_MEMORY_MAX_NREGIONS];
534 for (i = 0; i < msg.memory.nregions; i++)
536 long page_sz = get_huge_page_size (fds[i]);
538 /* align size to page */
539 ssize_t map_sz = (msg.memory.regions[i].memory_size +
540 msg.memory.regions[i].mmap_offset +
541 page_sz - 1) & ~(page_sz - 1);
543 region_mmap_addr[i] = mmap (0, map_sz, PROT_READ | PROT_WRITE,
544 MAP_SHARED, fds[i], 0);
545 if (region_mmap_addr[i] == MAP_FAILED)
547 vu_log_err (vui, "failed to map memory. errno is %d", errno);
548 for (j = 0; j < i; j++)
549 munmap (region_mmap_addr[j], map_sz);
552 vu_log_debug (vui, "map memory region %d addr 0 len 0x%lx fd %d "
553 "mapped 0x%lx page_sz 0x%x", i, map_sz, fds[i],
554 region_mmap_addr[i], page_sz);
557 vlib_worker_thread_barrier_sync (vm);
558 unmap_all_mem_regions (vui);
559 for (i = 0; i < msg.memory.nregions; i++)
561 clib_memcpy_fast (&(vui->regions[i]), &msg.memory.regions[i],
562 sizeof (vhost_user_memory_region_t));
564 vui->region_mmap_addr[i] = region_mmap_addr[i];
565 vui->region_guest_addr_lo[i] = vui->regions[i].guest_phys_addr;
566 vui->region_guest_addr_hi[i] = vui->regions[i].guest_phys_addr +
567 vui->regions[i].memory_size;
569 vui->region_mmap_addr[i] += vui->regions[i].mmap_offset;
570 vui->region_mmap_fd[i] = fds[i];
576 * Re-compute desc, used, and avail descriptor table if vring address
579 for (q = 0; q < VHOST_VRING_MAX_N; q++)
581 if (vui->vrings[q].desc_user_addr &&
582 vui->vrings[q].used_user_addr && vui->vrings[q].avail_user_addr)
584 vui->vrings[q].desc =
585 map_user_mem (vui, vui->vrings[q].desc_user_addr);
586 vui->vrings[q].used =
587 map_user_mem (vui, vui->vrings[q].used_user_addr);
588 vui->vrings[q].avail =
589 map_user_mem (vui, vui->vrings[q].avail_user_addr);
592 vlib_worker_thread_barrier_release (vm);
595 case VHOST_USER_SET_VRING_NUM:
596 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_NUM idx %d num %d",
597 vui->hw_if_index, msg.state.index, msg.state.num);
599 if ((msg.state.num > 32768) || /* maximum ring size is 32768 */
600 (msg.state.num == 0) || /* it cannot be zero */
601 ((msg.state.num - 1) & msg.state.num)) /* must be power of 2 */
603 vui->vrings[msg.state.index].qsz_mask = msg.state.num - 1;
606 case VHOST_USER_SET_VRING_ADDR:
607 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_ADDR idx %d",
608 vui->hw_if_index, msg.state.index);
610 if (msg.state.index >= VHOST_VRING_MAX_N)
612 vu_log_debug (vui, "invalid vring index VHOST_USER_SET_VRING_ADDR:"
613 " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
617 if (msg.size < sizeof (msg.addr))
619 vu_log_debug (vui, "vhost message is too short (%d < %d)",
620 msg.size, sizeof (msg.addr));
624 vring_desc_t *desc = map_user_mem (vui, msg.addr.desc_user_addr);
625 vring_used_t *used = map_user_mem (vui, msg.addr.used_user_addr);
626 vring_avail_t *avail = map_user_mem (vui, msg.addr.avail_user_addr);
628 if ((desc == NULL) || (used == NULL) || (avail == NULL))
630 vu_log_debug (vui, "failed to map user memory for hw_if_index %d",
635 vui->vrings[msg.state.index].desc_user_addr = msg.addr.desc_user_addr;
636 vui->vrings[msg.state.index].used_user_addr = msg.addr.used_user_addr;
637 vui->vrings[msg.state.index].avail_user_addr = msg.addr.avail_user_addr;
639 vlib_worker_thread_barrier_sync (vm);
640 vui->vrings[msg.state.index].desc = desc;
641 vui->vrings[msg.state.index].used = used;
642 vui->vrings[msg.state.index].avail = avail;
644 vui->vrings[msg.state.index].log_guest_addr = msg.addr.log_guest_addr;
645 vui->vrings[msg.state.index].log_used =
646 (msg.addr.flags & (1 << VHOST_VRING_F_LOG)) ? 1 : 0;
648 /* Spec says: If VHOST_USER_F_PROTOCOL_FEATURES has not been negotiated,
649 the ring is initialized in an enabled state. */
650 if (!(vui->features & (1 << FEAT_VHOST_USER_F_PROTOCOL_FEATURES)))
651 vui->vrings[msg.state.index].enabled = 1;
653 vui->vrings[msg.state.index].last_used_idx =
654 vui->vrings[msg.state.index].last_avail_idx =
655 vui->vrings[msg.state.index].used->idx;
657 /* tell driver that we don't want interrupts */
658 vui->vrings[msg.state.index].used->flags = VRING_USED_F_NO_NOTIFY;
659 vlib_worker_thread_barrier_release (vm);
660 vhost_user_update_iface_state (vui);
663 case VHOST_USER_SET_OWNER:
664 vu_log_debug (vui, "if %d msg VHOST_USER_SET_OWNER", vui->hw_if_index);
667 case VHOST_USER_RESET_OWNER:
668 vu_log_debug (vui, "if %d msg VHOST_USER_RESET_OWNER",
672 case VHOST_USER_SET_VRING_CALL:
673 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_CALL %d",
674 vui->hw_if_index, msg.u64);
676 q = (u8) (msg.u64 & 0xFF);
678 /* if there is old fd, delete and close it */
679 if (vui->vrings[q].callfd_idx != ~0)
681 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
682 vui->vrings[q].callfd_idx);
683 clib_file_del (&file_main, uf);
684 vui->vrings[q].callfd_idx = ~0;
687 if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
689 if (number_of_fds != 1)
691 vu_log_debug (vui, "More than one fd received !");
695 template.read_function = vhost_user_callfd_read_ready;
696 template.file_descriptor = fds[0];
697 template.private_data =
698 ((vui - vhost_user_main.vhost_user_interfaces) << 8) + q;
699 vui->vrings[q].callfd_idx = clib_file_add (&file_main, &template);
702 vui->vrings[q].callfd_idx = ~0;
705 case VHOST_USER_SET_VRING_KICK:
706 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_KICK %d",
707 vui->hw_if_index, msg.u64);
709 q = (u8) (msg.u64 & 0xFF);
711 if (vui->vrings[q].kickfd_idx != ~0)
713 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
714 vui->vrings[q].kickfd_idx);
715 clib_file_del (&file_main, uf);
716 vui->vrings[q].kickfd_idx = ~0;
719 if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
721 if (number_of_fds != 1)
723 vu_log_debug (vui, "More than one fd received !");
727 template.read_function = vhost_user_kickfd_read_ready;
728 template.file_descriptor = fds[0];
729 template.private_data =
730 (((uword) (vui - vhost_user_main.vhost_user_interfaces)) << 8) +
732 vui->vrings[q].kickfd_idx = clib_file_add (&file_main, &template);
736 //When no kickfd is set, the queue is initialized as started
737 vui->vrings[q].kickfd_idx = ~0;
738 vui->vrings[q].started = 1;
739 vhost_user_thread_placement (vui, q);
741 vhost_user_update_iface_state (vui);
744 case VHOST_USER_SET_VRING_ERR:
745 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_ERR %d",
746 vui->hw_if_index, msg.u64);
748 q = (u8) (msg.u64 & 0xFF);
750 if (vui->vrings[q].errfd != -1)
751 close (vui->vrings[q].errfd);
753 if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
755 if (number_of_fds != 1)
758 vui->vrings[q].errfd = fds[0];
761 vui->vrings[q].errfd = -1;
764 case VHOST_USER_SET_VRING_BASE:
765 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_BASE idx %d num %d",
766 vui->hw_if_index, msg.state.index, msg.state.num);
767 vlib_worker_thread_barrier_sync (vm);
768 vui->vrings[msg.state.index].last_avail_idx = msg.state.num;
769 vlib_worker_thread_barrier_release (vm);
772 case VHOST_USER_GET_VRING_BASE:
773 if (msg.state.index >= VHOST_VRING_MAX_N)
775 vu_log_debug (vui, "invalid vring index VHOST_USER_GET_VRING_BASE:"
776 " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
780 /* protection is needed to prevent rx/tx from changing last_avail_idx */
781 vlib_worker_thread_barrier_sync (vm);
783 * Copy last_avail_idx from the vring before closing it because
784 * closing the vring also initializes the vring last_avail_idx
786 msg.state.num = vui->vrings[msg.state.index].last_avail_idx;
788 msg.size = sizeof (msg.state);
791 * Spec says: Client must [...] stop ring upon receiving
792 * VHOST_USER_GET_VRING_BASE
794 vhost_user_vring_close (vui, msg.state.index);
795 vlib_worker_thread_barrier_release (vm);
796 vu_log_debug (vui, "if %d msg VHOST_USER_GET_VRING_BASE idx %d num %d",
797 vui->hw_if_index, msg.state.index, msg.state.num);
799 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
800 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
802 vu_log_debug (vui, "could not send message response");
805 vhost_user_update_iface_state (vui);
808 case VHOST_USER_NONE:
809 vu_log_debug (vui, "if %d msg VHOST_USER_NONE", vui->hw_if_index);
812 case VHOST_USER_SET_LOG_BASE:
813 vu_log_debug (vui, "if %d msg VHOST_USER_SET_LOG_BASE",
816 if (msg.size != sizeof (msg.log))
818 vu_log_debug (vui, "invalid msg size for VHOST_USER_SET_LOG_BASE:"
819 " %d instead of %d", msg.size, sizeof (msg.log));
823 if (!(vui->protocol_features & (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD)))
825 vu_log_debug (vui, "VHOST_USER_PROTOCOL_F_LOG_SHMFD not set but "
826 "VHOST_USER_SET_LOG_BASE received");
831 /* align size to page */
832 long page_sz = get_huge_page_size (fd);
834 (msg.log.size + msg.log.offset + page_sz - 1) & ~(page_sz - 1);
836 void *log_base_addr = mmap (0, map_sz, PROT_READ | PROT_WRITE,
839 vu_log_debug (vui, "map log region addr 0 len 0x%lx off 0x%lx fd %d "
840 "mapped 0x%lx", map_sz, msg.log.offset, fd,
843 if (log_base_addr == MAP_FAILED)
845 vu_log_err (vui, "failed to map memory. errno is %d", errno);
849 vlib_worker_thread_barrier_sync (vm);
850 vui->log_base_addr = log_base_addr;
851 vui->log_base_addr += msg.log.offset;
852 vui->log_size = msg.log.size;
853 vlib_worker_thread_barrier_release (vm);
856 msg.size = sizeof (msg.u64);
858 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
859 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
861 vu_log_debug (vui, "could not send message response");
866 case VHOST_USER_SET_LOG_FD:
867 vu_log_debug (vui, "if %d msg VHOST_USER_SET_LOG_FD", vui->hw_if_index);
870 case VHOST_USER_GET_PROTOCOL_FEATURES:
872 msg.u64 = (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |
873 (1 << VHOST_USER_PROTOCOL_F_MQ);
874 msg.size = sizeof (msg.u64);
875 vu_log_debug (vui, "if %d msg VHOST_USER_GET_PROTOCOL_FEATURES - "
876 "reply 0x%016llx", vui->hw_if_index, msg.u64);
878 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
879 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
881 vu_log_debug (vui, "could not send message response");
886 case VHOST_USER_SET_PROTOCOL_FEATURES:
887 vu_log_debug (vui, "if %d msg VHOST_USER_SET_PROTOCOL_FEATURES "
888 "features 0x%016llx", vui->hw_if_index, msg.u64);
889 vui->protocol_features = msg.u64;
892 case VHOST_USER_GET_QUEUE_NUM:
894 msg.u64 = VHOST_VRING_MAX_N;
895 msg.size = sizeof (msg.u64);
896 vu_log_debug (vui, "if %d msg VHOST_USER_GET_QUEUE_NUM - reply %d",
897 vui->hw_if_index, msg.u64);
899 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
900 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
902 vu_log_debug (vui, "could not send message response");
907 case VHOST_USER_SET_VRING_ENABLE:
908 vu_log_debug (vui, "if %d VHOST_USER_SET_VRING_ENABLE: %s queue %d",
909 vui->hw_if_index, msg.state.num ? "enable" : "disable",
911 if (msg.state.index >= VHOST_VRING_MAX_N)
913 vu_log_debug (vui, "invalid vring idx VHOST_USER_SET_VRING_ENABLE:"
914 " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
918 vui->vrings[msg.state.index].enabled = msg.state.num;
919 vhost_user_thread_placement (vui, msg.state.index);
920 vhost_user_update_iface_state (vui);
924 vu_log_debug (vui, "unknown vhost-user message %d received. "
925 "closing socket", msg.request);
932 vlib_worker_thread_barrier_sync (vm);
933 vhost_user_if_disconnect (vui);
934 vlib_worker_thread_barrier_release (vm);
935 vhost_user_update_iface_state (vui);
939 static clib_error_t *
940 vhost_user_socket_error (clib_file_t * uf)
942 vlib_main_t *vm = vlib_get_main ();
943 vhost_user_main_t *vum = &vhost_user_main;
944 vhost_user_intf_t *vui =
945 pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
947 vu_log_debug (vui, "socket error on if %d", vui->sw_if_index);
948 vlib_worker_thread_barrier_sync (vm);
949 vhost_user_if_disconnect (vui);
950 vlib_worker_thread_barrier_release (vm);
954 static clib_error_t *
955 vhost_user_socksvr_accept_ready (clib_file_t * uf)
957 int client_fd, client_len;
958 struct sockaddr_un client;
959 clib_file_t template = { 0 };
960 vhost_user_main_t *vum = &vhost_user_main;
961 vhost_user_intf_t *vui;
963 vui = pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
965 client_len = sizeof (client);
966 client_fd = accept (uf->file_descriptor,
967 (struct sockaddr *) &client,
968 (socklen_t *) & client_len);
971 return clib_error_return_unix (0, "accept");
973 if (vui->clib_file_index != ~0)
975 vu_log_debug (vui, "Close client socket for vhost interface %d, fd %d",
976 vui->sw_if_index, UNIX_GET_FD (vui->clib_file_index));
977 clib_file_del (&file_main, file_main.file_pool + vui->clib_file_index);
980 vu_log_debug (vui, "New client socket for vhost interface %d, fd %d",
981 vui->sw_if_index, client_fd);
982 template.read_function = vhost_user_socket_read;
983 template.error_function = vhost_user_socket_error;
984 template.file_descriptor = client_fd;
985 template.private_data = vui - vhost_user_main.vhost_user_interfaces;
986 vui->clib_file_index = clib_file_add (&file_main, &template);
990 static clib_error_t *
991 vhost_user_init (vlib_main_t * vm)
993 vhost_user_main_t *vum = &vhost_user_main;
994 vlib_thread_main_t *tm = vlib_get_thread_main ();
996 vum->log_default = vlib_log_register_class ("vhost-user", 0);
998 vum->coalesce_frames = 32;
999 vum->coalesce_time = 1e-3;
1001 vec_validate (vum->cpus, tm->n_vlib_mains - 1);
1004 vec_foreach (cpu, vum->cpus)
1006 /* This is actually not necessary as validate already zeroes it
1007 * Just keeping the loop here for later because I am lazy. */
1008 cpu->rx_buffers_len = 0;
1011 vum->random = random_default_seed ();
1013 mhash_init_c_string (&vum->if_index_by_sock_name, sizeof (uword));
1019 VLIB_INIT_FUNCTION (vhost_user_init) =
1021 .runs_after = VLIB_INITS("ip4_init"),
1026 vhost_user_send_interrupt_process (vlib_main_t * vm,
1027 vlib_node_runtime_t * rt, vlib_frame_t * f)
1029 vhost_user_intf_t *vui;
1030 f64 timeout = 3153600000.0 /* 100 years */ ;
1031 uword event_type, *event_data = 0;
1032 vhost_user_main_t *vum = &vhost_user_main;
1034 f64 now, poll_time_remaining;
1040 poll_time_remaining =
1041 vlib_process_wait_for_event_or_clock (vm, timeout);
1042 event_type = vlib_process_get_events (vm, &event_data);
1043 vec_reset_length (event_data);
1046 * Use the remaining timeout if it is less than coalesce time to avoid
1047 * resetting the existing timer in the middle of expiration
1049 timeout = poll_time_remaining;
1050 if (vlib_process_suspend_time_is_zero (timeout) ||
1051 (timeout > vum->coalesce_time))
1052 timeout = vum->coalesce_time;
1054 now = vlib_time_now (vm);
1057 case VHOST_USER_EVENT_STOP_TIMER:
1061 case VHOST_USER_EVENT_START_TIMER:
1063 if (!vlib_process_suspend_time_is_zero (poll_time_remaining))
1069 pool_foreach (vui, vum->vhost_user_interfaces, {
1070 next_timeout = timeout;
1071 for (qid = 0; qid < VHOST_VRING_MAX_N / 2; qid += 2)
1073 vhost_user_vring_t *rxvq = &vui->vrings[qid];
1074 vhost_user_vring_t *txvq = &vui->vrings[qid + 1];
1076 if (txvq->qid == -1)
1078 if (txvq->n_since_last_int)
1080 if (now >= txvq->int_deadline)
1081 vhost_user_send_call (vm, txvq);
1083 next_timeout = txvq->int_deadline - now;
1086 if (rxvq->n_since_last_int)
1088 if (now >= rxvq->int_deadline)
1089 vhost_user_send_call (vm, rxvq);
1091 next_timeout = rxvq->int_deadline - now;
1094 if ((next_timeout < timeout) && (next_timeout > 0.0))
1095 timeout = next_timeout;
1102 clib_warning ("BUG: unhandled event type %d", event_type);
1105 /* No less than 1 millisecond */
1109 timeout = 3153600000.0;
1115 VLIB_REGISTER_NODE (vhost_user_send_interrupt_node) = {
1116 .function = vhost_user_send_interrupt_process,
1117 .type = VLIB_NODE_TYPE_PROCESS,
1118 .name = "vhost-user-send-interrupt-process",
1123 vhost_user_process (vlib_main_t * vm,
1124 vlib_node_runtime_t * rt, vlib_frame_t * f)
1126 vhost_user_main_t *vum = &vhost_user_main;
1127 vhost_user_intf_t *vui;
1128 struct sockaddr_un sun;
1130 clib_file_t template = { 0 };
1131 f64 timeout = 3153600000.0 /* 100 years */ ;
1132 uword *event_data = 0;
1135 sun.sun_family = AF_UNIX;
1136 template.read_function = vhost_user_socket_read;
1137 template.error_function = vhost_user_socket_error;
1141 vlib_process_wait_for_event_or_clock (vm, timeout);
1142 vlib_process_get_events (vm, &event_data);
1143 vec_reset_length (event_data);
1148 pool_foreach (vui, vum->vhost_user_interfaces, {
1150 if (vui->unix_server_index == ~0) { //Nothing to do for server sockets
1151 if (vui->clib_file_index == ~0)
1154 ((sockfd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0))
1157 * 1st time error or new error for this interface,
1158 * spit out the message and record the error
1160 if (!vui->sock_errno || (vui->sock_errno != errno))
1163 ("Error: Could not open unix socket for %s",
1164 vui->sock_filename);
1165 vui->sock_errno = errno;
1170 /* try to connect */
1171 strncpy (sun.sun_path, (char *) vui->sock_filename,
1172 sizeof (sun.sun_path) - 1);
1174 /* Avoid hanging VPP if the other end does not accept */
1175 if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
1176 clib_unix_warning ("fcntl");
1178 if (connect (sockfd, (struct sockaddr *) &sun,
1179 sizeof (struct sockaddr_un)) == 0)
1181 /* Set the socket to blocking as it was before */
1182 if (fcntl(sockfd, F_SETFL, 0) < 0)
1183 clib_unix_warning ("fcntl2");
1185 vui->sock_errno = 0;
1186 template.file_descriptor = sockfd;
1187 template.private_data =
1188 vui - vhost_user_main.vhost_user_interfaces;
1189 vui->clib_file_index = clib_file_add (&file_main, &template);
1191 /* This sockfd is considered consumed */
1196 vui->sock_errno = errno;
1201 /* check if socket is alive */
1203 socklen_t len = sizeof (error);
1204 int fd = UNIX_GET_FD(vui->clib_file_index);
1206 getsockopt (fd, SOL_SOCKET, SO_ERROR, &error, &len);
1210 vu_log_debug (vui, "getsockopt returned %d", retval);
1211 vhost_user_if_disconnect (vui);
1222 VLIB_REGISTER_NODE (vhost_user_process_node,static) = {
1223 .function = vhost_user_process,
1224 .type = VLIB_NODE_TYPE_PROCESS,
1225 .name = "vhost-user-process",
1230 * Disables and reset interface structure.
1231 * It can then be either init again, or removed from used interfaces.
1234 vhost_user_term_if (vhost_user_intf_t * vui)
1237 vhost_user_main_t *vum = &vhost_user_main;
1239 // disconnect interface sockets
1240 vhost_user_if_disconnect (vui);
1241 vhost_user_update_gso_interface_count (vui, 0 /* delete */ );
1242 vhost_user_update_iface_state (vui);
1244 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1246 // Remove existing queue mapping for the interface
1250 vnet_main_t *vnm = vnet_get_main ();
1251 vhost_user_vring_t *txvq = &vui->vrings[q];
1253 if (txvq->qid != -1)
1255 rv = vnet_hw_interface_unassign_rx_thread (vnm,
1259 vu_log_warn (vui, "unable to unassign interface %d, "
1260 "queue %d: rc=%d", vui->hw_if_index, q >> 1, rv);
1264 clib_mem_free ((void *) vui->vring_locks[q]);
1267 if (vui->unix_server_index != ~0)
1269 //Close server socket
1270 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
1271 vui->unix_server_index);
1272 clib_file_del (&file_main, uf);
1273 vui->unix_server_index = ~0;
1274 unlink (vui->sock_filename);
1277 mhash_unset (&vum->if_index_by_sock_name, vui->sock_filename,
1282 vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, u32 sw_if_index)
1284 vhost_user_main_t *vum = &vhost_user_main;
1285 vhost_user_intf_t *vui;
1287 vnet_hw_interface_t *hwif;
1292 vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index))
1293 || hwif->dev_class_index != vhost_user_device_class.index)
1294 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1296 vui = pool_elt_at_index (vum->vhost_user_interfaces, hwif->dev_instance);
1298 vu_log_debug (vui, "Deleting vhost-user interface %s (instance %d)",
1299 hwif->name, hwif->dev_instance);
1301 for (qid = 1; qid < VHOST_VRING_MAX_N / 2; qid += 2)
1303 vhost_user_vring_t *txvq = &vui->vrings[qid];
1305 if (txvq->qid == -1)
1307 if ((vum->ifq_count > 0) &&
1308 ((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
1309 (txvq->mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE)))
1312 // Stop the timer if there is no more interrupt interface/queue
1313 if ((vum->ifq_count == 0) &&
1314 (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
1316 vlib_process_signal_event (vm,
1317 vhost_user_send_interrupt_node.index,
1318 VHOST_USER_EVENT_STOP_TIMER, 0);
1324 // Disable and reset interface
1325 vhost_user_term_if (vui);
1327 // Reset renumbered iface
1328 if (hwif->dev_instance <
1329 vec_len (vum->show_dev_instance_by_real_dev_instance))
1330 vum->show_dev_instance_by_real_dev_instance[hwif->dev_instance] = ~0;
1332 // Delete ethernet interface
1333 ethernet_delete_interface (vnm, vui->hw_if_index);
1336 pool_put (vum->vhost_user_interfaces, vui);
1341 static clib_error_t *
1342 vhost_user_exit (vlib_main_t * vm)
1344 vnet_main_t *vnm = vnet_get_main ();
1345 vhost_user_main_t *vum = &vhost_user_main;
1346 vhost_user_intf_t *vui;
1348 vlib_worker_thread_barrier_sync (vlib_get_main ());
1350 pool_foreach (vui, vum->vhost_user_interfaces, {
1351 vhost_user_delete_if (vnm, vm, vui->sw_if_index);
1354 vlib_worker_thread_barrier_release (vlib_get_main ());
1358 VLIB_MAIN_LOOP_EXIT_FUNCTION (vhost_user_exit);
1361 * Open server unix socket on specified sock_filename.
1364 vhost_user_init_server_sock (const char *sock_filename, int *sock_fd)
1367 struct sockaddr_un un = { };
1369 /* create listening socket */
1370 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
1371 return VNET_API_ERROR_SYSCALL_ERROR_1;
1373 un.sun_family = AF_UNIX;
1374 strncpy ((char *) un.sun_path, (char *) sock_filename,
1375 sizeof (un.sun_path) - 1);
1377 /* remove if exists */
1378 unlink ((char *) sock_filename);
1380 if (bind (fd, (struct sockaddr *) &un, sizeof (un)) == -1)
1382 rv = VNET_API_ERROR_SYSCALL_ERROR_2;
1386 if (listen (fd, 1) == -1)
1388 rv = VNET_API_ERROR_SYSCALL_ERROR_3;
1401 * Create ethernet interface for vhost user interface.
1404 vhost_user_create_ethernet (vnet_main_t * vnm, vlib_main_t * vm,
1405 vhost_user_intf_t * vui, u8 * hwaddress)
1407 vhost_user_main_t *vum = &vhost_user_main;
1409 clib_error_t *error;
1411 /* create hw and sw interface */
1414 clib_memcpy (hwaddr, hwaddress, 6);
1418 random_u32 (&vum->random);
1419 clib_memcpy (hwaddr + 2, &vum->random, sizeof (vum->random));
1424 error = ethernet_register_interface
1426 vhost_user_device_class.index,
1427 vui - vum->vhost_user_interfaces /* device instance */ ,
1428 hwaddr /* ethernet address */ ,
1429 &vui->hw_if_index, 0 /* flag change */ );
1432 clib_error_report (error);
1436 * Initialize vui with specified attributes
1439 vhost_user_vui_init (vnet_main_t * vnm,
1440 vhost_user_intf_t * vui,
1442 const char *sock_filename,
1443 u64 feature_mask, u32 * sw_if_index, u8 enable_gso)
1445 vnet_sw_interface_t *sw;
1447 vhost_user_main_t *vum = &vhost_user_main;
1448 vnet_hw_interface_t *hw;
1450 hw = vnet_get_hw_interface (vnm, vui->hw_if_index);
1451 sw = vnet_get_hw_sw_interface (vnm, vui->hw_if_index);
1452 if (server_sock_fd != -1)
1454 clib_file_t template = { 0 };
1455 template.read_function = vhost_user_socksvr_accept_ready;
1456 template.file_descriptor = server_sock_fd;
1457 template.private_data = vui - vum->vhost_user_interfaces; //hw index
1458 vui->unix_server_index = clib_file_add (&file_main, &template);
1462 vui->unix_server_index = ~0;
1465 vui->sw_if_index = sw->sw_if_index;
1466 strncpy (vui->sock_filename, sock_filename,
1467 ARRAY_LEN (vui->sock_filename) - 1);
1468 vui->sock_errno = 0;
1470 vui->feature_mask = feature_mask;
1471 vui->clib_file_index = ~0;
1472 vui->log_base_addr = 0;
1473 vui->if_index = vui - vum->vhost_user_interfaces;
1474 vui->enable_gso = enable_gso;
1476 * enable_gso takes precedence over configurable feature mask if there
1478 * if feature mask disables gso, but enable_gso is configured,
1479 * then gso is enable
1480 * if feature mask enables gso, but enable_gso is not configured,
1481 * then gso is enable
1483 * if gso is enable via feature mask, it must enable both host and guest
1484 * gso feature mask, we don't support one sided GSO or partial GSO.
1486 if ((vui->enable_gso == 0) &&
1487 ((feature_mask & FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS) ==
1488 (FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS)))
1489 vui->enable_gso = 1;
1490 vhost_user_update_gso_interface_count (vui, 1 /* add */ );
1491 mhash_set_mem (&vum->if_index_by_sock_name, vui->sock_filename,
1494 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1495 vhost_user_vring_init (vui, q);
1497 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
1498 vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
1501 *sw_if_index = vui->sw_if_index;
1503 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1505 vui->vring_locks[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
1506 CLIB_CACHE_LINE_BYTES);
1507 clib_memset ((void *) vui->vring_locks[q], 0, CLIB_CACHE_LINE_BYTES);
1510 vec_validate (vui->per_cpu_tx_qid,
1511 vlib_get_thread_main ()->n_vlib_mains - 1);
1512 vhost_user_tx_thread_placement (vui);
1516 vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm,
1517 const char *sock_filename,
1521 u8 renumber, u32 custom_dev_instance, u8 * hwaddr,
1524 vhost_user_intf_t *vui = NULL;
1527 int server_sock_fd = -1;
1528 vhost_user_main_t *vum = &vhost_user_main;
1531 if (sock_filename == NULL || !(strlen (sock_filename) > 0))
1533 return VNET_API_ERROR_INVALID_ARGUMENT;
1536 if_index = mhash_get (&vum->if_index_by_sock_name, (void *) sock_filename);
1541 vui = &vum->vhost_user_interfaces[*if_index];
1542 *sw_if_index = vui->sw_if_index;
1544 return VNET_API_ERROR_IF_ALREADY_EXISTS;
1550 vhost_user_init_server_sock (sock_filename, &server_sock_fd)) != 0)
1556 /* Protect the uninitialized vui from being dispatched by rx/tx */
1557 vlib_worker_thread_barrier_sync (vm);
1558 pool_get (vhost_user_main.vhost_user_interfaces, vui);
1559 vhost_user_create_ethernet (vnm, vm, vui, hwaddr);
1560 vlib_worker_thread_barrier_release (vm);
1562 vhost_user_vui_init (vnm, vui, server_sock_fd, sock_filename,
1563 feature_mask, &sw_if_idx, enable_gso);
1564 vnet_sw_interface_set_mtu (vnm, vui->sw_if_index, 9000);
1565 vhost_user_rx_thread_placement (vui, 1);
1568 vnet_interface_name_renumber (sw_if_idx, custom_dev_instance);
1571 *sw_if_index = sw_if_idx;
1573 // Process node must connect
1574 vlib_process_signal_event (vm, vhost_user_process_node.index, 0, 0);
1580 vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm,
1581 const char *sock_filename,
1584 u64 feature_mask, u8 renumber, u32 custom_dev_instance,
1587 vhost_user_main_t *vum = &vhost_user_main;
1588 vhost_user_intf_t *vui = NULL;
1590 int server_sock_fd = -1;
1592 vnet_hw_interface_t *hwif;
1597 vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index))
1598 || hwif->dev_class_index != vhost_user_device_class.index)
1599 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1601 if (sock_filename == NULL || !(strlen (sock_filename) > 0))
1602 return VNET_API_ERROR_INVALID_ARGUMENT;
1604 vui = vec_elt_at_index (vum->vhost_user_interfaces, hwif->dev_instance);
1607 * Disallow changing the interface to have the same path name
1608 * as other interface
1610 if_index = mhash_get (&vum->if_index_by_sock_name, (void *) sock_filename);
1611 if (if_index && (*if_index != vui->if_index))
1612 return VNET_API_ERROR_IF_ALREADY_EXISTS;
1614 // First try to open server socket
1616 if ((rv = vhost_user_init_server_sock (sock_filename,
1617 &server_sock_fd)) != 0)
1620 vhost_user_term_if (vui);
1621 vhost_user_vui_init (vnm, vui, server_sock_fd,
1622 sock_filename, feature_mask, &sw_if_idx, enable_gso);
1625 vnet_interface_name_renumber (sw_if_idx, custom_dev_instance);
1627 // Process node must connect
1628 vlib_process_signal_event (vm, vhost_user_process_node.index, 0, 0);
1634 vhost_user_connect_command_fn (vlib_main_t * vm,
1635 unformat_input_t * input,
1636 vlib_cli_command_t * cmd)
1638 unformat_input_t _line_input, *line_input = &_line_input;
1639 u8 *sock_filename = NULL;
1642 u64 feature_mask = (u64) ~ (0ULL);
1644 u32 custom_dev_instance = ~0;
1647 clib_error_t *error = NULL;
1650 /* Get a line of input. */
1651 if (!unformat_user (input, unformat_line_input, line_input))
1654 /* GSO feature is disable by default */
1655 feature_mask &= ~FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS;
1656 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1658 if (unformat (line_input, "socket %s", &sock_filename))
1660 else if (unformat (line_input, "server"))
1662 else if (unformat (line_input, "gso"))
1664 else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
1668 (line_input, "hwaddr %U", unformat_ethernet_address, hwaddr))
1670 else if (unformat (line_input, "renumber %d", &custom_dev_instance))
1676 error = clib_error_return (0, "unknown input `%U'",
1677 format_unformat_error, line_input);
1682 vnet_main_t *vnm = vnet_get_main ();
1685 if ((rv = vhost_user_create_if (vnm, vm, (char *) sock_filename,
1686 is_server, &sw_if_index, feature_mask,
1687 renumber, custom_dev_instance, hw,
1690 error = clib_error_return (0, "vhost_user_create_if returned %d", rv);
1694 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (),
1698 vec_free (sock_filename);
1699 unformat_free (line_input);
1705 vhost_user_delete_command_fn (vlib_main_t * vm,
1706 unformat_input_t * input,
1707 vlib_cli_command_t * cmd)
1709 unformat_input_t _line_input, *line_input = &_line_input;
1710 u32 sw_if_index = ~0;
1711 vnet_main_t *vnm = vnet_get_main ();
1712 clib_error_t *error = NULL;
1714 /* Get a line of input. */
1715 if (!unformat_user (input, unformat_line_input, line_input))
1718 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1720 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
1723 (line_input, "%U", unformat_vnet_sw_interface, vnm,
1726 vnet_hw_interface_t *hwif =
1727 vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
1729 vhost_user_device_class.index != hwif->dev_class_index)
1731 error = clib_error_return (0, "Not a vhost interface");
1737 error = clib_error_return (0, "unknown input `%U'",
1738 format_unformat_error, line_input);
1743 vhost_user_delete_if (vnm, vm, sw_if_index);
1746 unformat_free (line_input);
1752 vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm,
1753 vhost_user_intf_details_t ** out_vuids)
1756 vhost_user_main_t *vum = &vhost_user_main;
1757 vhost_user_intf_t *vui;
1758 vhost_user_intf_details_t *r_vuids = NULL;
1759 vhost_user_intf_details_t *vuid = NULL;
1760 u32 *hw_if_indices = 0;
1761 vnet_hw_interface_t *hi;
1768 pool_foreach (vui, vum->vhost_user_interfaces,
1769 vec_add1 (hw_if_indices, vui->hw_if_index);
1772 for (i = 0; i < vec_len (hw_if_indices); i++)
1774 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
1775 vui = pool_elt_at_index (vum->vhost_user_interfaces, hi->dev_instance);
1777 vec_add2 (r_vuids, vuid, 1);
1778 vuid->sw_if_index = vui->sw_if_index;
1779 vuid->virtio_net_hdr_sz = vui->virtio_net_hdr_sz;
1780 vuid->features = vui->features;
1781 vuid->num_regions = vui->nregions;
1782 vuid->is_server = vui->unix_server_index != ~0;
1783 vuid->sock_errno = vui->sock_errno;
1784 strncpy ((char *) vuid->sock_filename, (char *) vui->sock_filename,
1785 sizeof (vuid->sock_filename));
1786 vuid->sock_filename[ARRAY_LEN (vuid->sock_filename) - 1] = '\0';
1787 s = format (s, "%v%c", hi->name, 0);
1789 strncpy ((char *) vuid->if_name, (char *) s,
1790 ARRAY_LEN (vuid->if_name) - 1);
1795 vec_free (hw_if_indices);
1797 *out_vuids = r_vuids;
1803 show_vhost_user_command_fn (vlib_main_t * vm,
1804 unformat_input_t * input,
1805 vlib_cli_command_t * cmd)
1807 clib_error_t *error = 0;
1808 vnet_main_t *vnm = vnet_get_main ();
1809 vhost_user_main_t *vum = &vhost_user_main;
1810 vhost_user_intf_t *vui;
1811 u32 hw_if_index, *hw_if_indices = 0;
1812 vnet_hw_interface_t *hi;
1822 struct feat_struct *feat_entry;
1824 static struct feat_struct feat_array[] = {
1825 #define _(s,b) { .str = #s, .bit = b, },
1826 foreach_virtio_net_feature
1831 #define foreach_protocol_feature \
1832 _(VHOST_USER_PROTOCOL_F_MQ) \
1833 _(VHOST_USER_PROTOCOL_F_LOG_SHMFD)
1835 static struct feat_struct proto_feat_array[] = {
1836 #define _(s) { .str = #s, .bit = s},
1837 foreach_protocol_feature
1842 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1845 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1847 hi = vnet_get_hw_interface (vnm, hw_if_index);
1848 if (vhost_user_device_class.index != hi->dev_class_index)
1850 error = clib_error_return (0, "unknown input `%U'",
1851 format_unformat_error, input);
1854 vec_add1 (hw_if_indices, hw_if_index);
1856 else if (unformat (input, "descriptors") || unformat (input, "desc"))
1860 error = clib_error_return (0, "unknown input `%U'",
1861 format_unformat_error, input);
1865 if (vec_len (hw_if_indices) == 0)
1867 pool_foreach (vui, vum->vhost_user_interfaces,
1868 vec_add1 (hw_if_indices, vui->hw_if_index);
1871 vlib_cli_output (vm, "Virtio vhost-user interfaces");
1872 vlib_cli_output (vm, "Global:\n coalesce frames %d time %e",
1873 vum->coalesce_frames, vum->coalesce_time);
1874 vlib_cli_output (vm, " Number of rx virtqueues in interrupt mode: %d",
1876 vlib_cli_output (vm, " Number of GSO interfaces: %d", vum->gso_count);
1878 for (i = 0; i < vec_len (hw_if_indices); i++)
1880 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
1881 vui = pool_elt_at_index (vum->vhost_user_interfaces, hi->dev_instance);
1882 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
1883 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
1885 if (vui->enable_gso)
1886 vlib_cli_output (vm, " GSO enable");
1888 vlib_cli_output (vm, "virtio_net_hdr_sz %d\n"
1889 " features mask (0x%llx): \n"
1890 " features (0x%llx): \n",
1891 vui->virtio_net_hdr_sz, vui->feature_mask,
1894 feat_entry = (struct feat_struct *) &feat_array;
1895 while (feat_entry->str)
1897 if (vui->features & (1ULL << feat_entry->bit))
1898 vlib_cli_output (vm, " %s (%d)", feat_entry->str,
1903 vlib_cli_output (vm, " protocol features (0x%llx)",
1904 vui->protocol_features);
1905 feat_entry = (struct feat_struct *) &proto_feat_array;
1906 while (feat_entry->str)
1908 if (vui->protocol_features & (1ULL << feat_entry->bit))
1909 vlib_cli_output (vm, " %s (%d)", feat_entry->str,
1914 vlib_cli_output (vm, "\n");
1916 vlib_cli_output (vm, " socket filename %s type %s errno \"%s\"\n\n",
1918 (vui->unix_server_index != ~0) ? "server" : "client",
1919 strerror (vui->sock_errno));
1921 vlib_cli_output (vm, " rx placement: ");
1923 for (qid = 1; qid < VHOST_VRING_MAX_N / 2; qid += 2)
1925 vnet_main_t *vnm = vnet_get_main ();
1927 vnet_hw_interface_rx_mode mode;
1928 vhost_user_vring_t *txvq = &vui->vrings[qid];
1930 if (txvq->qid == -1)
1933 vnet_get_device_input_thread_index (vnm, vui->hw_if_index,
1935 vnet_hw_interface_get_rx_mode (vnm, vui->hw_if_index, qid >> 1,
1937 vlib_cli_output (vm, " thread %d on vring %d, %U\n",
1939 format_vnet_hw_interface_rx_mode, mode);
1942 vlib_cli_output (vm, " tx placement: %s\n",
1943 vui->use_tx_spinlock ? "spin-lock" : "lock-free");
1945 vec_foreach_index (ci, vui->per_cpu_tx_qid)
1947 vlib_cli_output (vm, " thread %d on vring %d\n", ci,
1948 VHOST_VRING_IDX_RX (vui->per_cpu_tx_qid[ci]));
1951 vlib_cli_output (vm, "\n");
1953 vlib_cli_output (vm, " Memory regions (total %d)\n", vui->nregions);
1957 vlib_cli_output (vm,
1958 " region fd guest_phys_addr memory_size userspace_addr mmap_offset mmap_addr\n");
1959 vlib_cli_output (vm,
1960 " ====== ===== ================== ================== ================== ================== ==================\n");
1962 for (j = 0; j < vui->nregions; j++)
1964 vlib_cli_output (vm,
1965 " %d %-5d 0x%016lx 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n",
1966 j, vui->region_mmap_fd[j],
1967 vui->regions[j].guest_phys_addr,
1968 vui->regions[j].memory_size,
1969 vui->regions[j].userspace_addr,
1970 vui->regions[j].mmap_offset,
1971 pointer_to_uword (vui->region_mmap_addr[j]));
1973 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1975 if (!vui->vrings[q].started)
1978 vlib_cli_output (vm, "\n Virtqueue %d (%s%s)\n", q,
1979 (q & 1) ? "RX" : "TX",
1980 vui->vrings[q].enabled ? "" : " disabled");
1982 vlib_cli_output (vm,
1983 " qsz %d last_avail_idx %d last_used_idx %d\n",
1984 vui->vrings[q].qsz_mask + 1,
1985 vui->vrings[q].last_avail_idx,
1986 vui->vrings[q].last_used_idx);
1988 if (vui->vrings[q].avail && vui->vrings[q].used)
1989 vlib_cli_output (vm,
1990 " avail.flags %x avail.idx %d used.flags %x used.idx %d\n",
1991 vui->vrings[q].avail->flags,
1992 vui->vrings[q].avail->idx,
1993 vui->vrings[q].used->flags,
1994 vui->vrings[q].used->idx);
1996 int kickfd = UNIX_GET_FD (vui->vrings[q].kickfd_idx);
1997 int callfd = UNIX_GET_FD (vui->vrings[q].callfd_idx);
1998 vlib_cli_output (vm, " kickfd %d callfd %d errfd %d\n",
1999 kickfd, callfd, vui->vrings[q].errfd);
2003 vlib_cli_output (vm, "\n descriptor table:\n");
2004 vlib_cli_output (vm,
2005 " id addr len flags next user_addr\n");
2006 vlib_cli_output (vm,
2007 " ===== ================== ===== ====== ===== ==================\n");
2008 for (j = 0; j < vui->vrings[q].qsz_mask + 1; j++)
2011 vlib_cli_output (vm,
2012 " %-5d 0x%016lx %-5d 0x%04x %-5d 0x%016lx\n",
2013 j, vui->vrings[q].desc[j].addr,
2014 vui->vrings[q].desc[j].len,
2015 vui->vrings[q].desc[j].flags,
2016 vui->vrings[q].desc[j].next,
2017 pointer_to_uword (map_guest_mem
2019 vui->vrings[q].desc[j].
2024 vlib_cli_output (vm, "\n");
2027 vec_free (hw_if_indices);
2036 * Create a vHost User interface. Once created, a new virtual interface
2037 * will exist with the name '<em>VirtualEthernet0/0/x</em>', where '<em>x</em>'
2038 * is the next free index.
2040 * There are several parameters associated with a vHost interface:
2042 * - <b>socket <socket-filename></b> - Name of the linux socket used by hypervisor
2043 * and VPP to manage the vHost interface. If in '<em>server</em>' mode, VPP will
2044 * create the socket if it does not already exist. If in '<em>client</em>' mode,
2045 * hypervisor will create the socket if it does not already exist. The VPP code
2046 * is indifferent to the file location. However, if SELinux is enabled, then the
2047 * socket needs to be created in '<em>/var/run/vpp/</em>'.
2049 * - <b>server</b> - Optional flag to indicate that VPP should be the server for
2050 * the linux socket. If not provided, VPP will be the client. In '<em>server</em>'
2051 * mode, the VM can be reset without tearing down the vHost Interface. In
2052 * '<em>client</em>' mode, VPP can be reset without bringing down the VM and
2053 * tearing down the vHost Interface.
2055 * - <b>feature-mask <hex></b> - Optional virtio/vhost feature set negotiated at
2056 * startup. <b>This is intended for degugging only.</b> It is recommended that this
2057 * parameter not be used except by experienced users. By default, all supported
2058 * features will be advertised. Otherwise, provide the set of features desired.
2059 * - 0x000008000 (15) - VIRTIO_NET_F_MRG_RXBUF
2060 * - 0x000020000 (17) - VIRTIO_NET_F_CTRL_VQ
2061 * - 0x000200000 (21) - VIRTIO_NET_F_GUEST_ANNOUNCE
2062 * - 0x000400000 (22) - VIRTIO_NET_F_MQ
2063 * - 0x004000000 (26) - VHOST_F_LOG_ALL
2064 * - 0x008000000 (27) - VIRTIO_F_ANY_LAYOUT
2065 * - 0x010000000 (28) - VIRTIO_F_INDIRECT_DESC
2066 * - 0x040000000 (30) - VHOST_USER_F_PROTOCOL_FEATURES
2067 * - 0x100000000 (32) - VIRTIO_F_VERSION_1
2069 * - <b>hwaddr <mac-addr></b> - Optional ethernet address, can be in either
2070 * X:X:X:X:X:X unix or X.X.X cisco format.
2072 * - <b>renumber <dev_instance></b> - Optional parameter which allows the instance
2073 * in the name to be specified. If instance already exists, name will be used
2074 * anyway and multiple instances will have the same name. Use with caution.
2077 * Example of how to create a vhost interface with VPP as the client and all features enabled:
2078 * @cliexstart{create vhost-user socket /var/run/vpp/vhost1.sock}
2079 * VirtualEthernet0/0/0
2081 * Example of how to create a vhost interface with VPP as the server and with just
2082 * multiple queues enabled:
2083 * @cliexstart{create vhost-user socket /var/run/vpp/vhost2.sock server feature-mask 0x40400000}
2084 * VirtualEthernet0/0/1
2086 * Once the vHost interface is created, enable the interface using:
2087 * @cliexcmd{set interface state VirtualEthernet0/0/0 up}
2090 VLIB_CLI_COMMAND (vhost_user_connect_command, static) = {
2091 .path = "create vhost-user",
2092 .short_help = "create vhost-user socket <socket-filename> [server] "
2093 "[feature-mask <hex>] [hwaddr <mac-addr>] [renumber <dev_instance>] [gso]",
2094 .function = vhost_user_connect_command_fn,
2100 * Delete a vHost User interface using the interface name or the
2101 * software interface index. Use the '<em>show interface</em>'
2102 * command to determine the software interface index. On deletion,
2103 * the linux socket will not be deleted.
2106 * Example of how to delete a vhost interface by name:
2107 * @cliexcmd{delete vhost-user VirtualEthernet0/0/1}
2108 * Example of how to delete a vhost interface by software interface index:
2109 * @cliexcmd{delete vhost-user sw_if_index 1}
2112 VLIB_CLI_COMMAND (vhost_user_delete_command, static) = {
2113 .path = "delete vhost-user",
2114 .short_help = "delete vhost-user {<interface> | sw_if_index <sw_idx>}",
2115 .function = vhost_user_delete_command_fn,
2119 * Display the attributes of a single vHost User interface (provide interface
2120 * name), multiple vHost User interfaces (provide a list of interface names seperated
2121 * by spaces) or all Vhost User interfaces (omit an interface name to display all
2122 * vHost interfaces).
2126 * Example of how to display a vhost interface:
2127 * @cliexstart{show vhost-user VirtualEthernet0/0/0}
2128 * Virtio vhost-user interfaces
2130 * coalesce frames 32 time 1e-3
2131 * Interface: VirtualEthernet0/0/0 (ifindex 1)
2132 * virtio_net_hdr_sz 12
2133 * features mask (0xffffffffffffffff):
2134 * features (0x50408000):
2135 * VIRTIO_NET_F_MRG_RXBUF (15)
2136 * VIRTIO_NET_F_MQ (22)
2137 * VIRTIO_F_INDIRECT_DESC (28)
2138 * VHOST_USER_F_PROTOCOL_FEATURES (30)
2139 * protocol features (0x3)
2140 * VHOST_USER_PROTOCOL_F_MQ (0)
2141 * VHOST_USER_PROTOCOL_F_LOG_SHMFD (1)
2143 * socket filename /var/run/vpp/vhost1.sock type client errno "Success"
2146 * thread 1 on vring 1
2147 * thread 1 on vring 5
2148 * thread 2 on vring 3
2149 * thread 2 on vring 7
2150 * tx placement: spin-lock
2151 * thread 0 on vring 0
2152 * thread 1 on vring 2
2153 * thread 2 on vring 0
2155 * Memory regions (total 2)
2156 * region fd guest_phys_addr memory_size userspace_addr mmap_offset mmap_addr
2157 * ====== ===== ================== ================== ================== ================== ==================
2158 * 0 60 0x0000000000000000 0x00000000000a0000 0x00002aaaaac00000 0x0000000000000000 0x00002aab2b400000
2159 * 1 61 0x00000000000c0000 0x000000003ff40000 0x00002aaaaacc0000 0x00000000000c0000 0x00002aababcc0000
2162 * qsz 256 last_avail_idx 0 last_used_idx 0
2163 * avail.flags 1 avail.idx 128 used.flags 1 used.idx 0
2164 * kickfd 62 callfd 64 errfd -1
2167 * qsz 256 last_avail_idx 0 last_used_idx 0
2168 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2169 * kickfd 65 callfd 66 errfd -1
2172 * qsz 256 last_avail_idx 0 last_used_idx 0
2173 * avail.flags 1 avail.idx 128 used.flags 1 used.idx 0
2174 * kickfd 63 callfd 70 errfd -1
2177 * qsz 256 last_avail_idx 0 last_used_idx 0
2178 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2179 * kickfd 72 callfd 74 errfd -1
2181 * Virtqueue 4 (TX disabled)
2182 * qsz 256 last_avail_idx 0 last_used_idx 0
2183 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2184 * kickfd 76 callfd 78 errfd -1
2186 * Virtqueue 5 (RX disabled)
2187 * qsz 256 last_avail_idx 0 last_used_idx 0
2188 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2189 * kickfd 80 callfd 82 errfd -1
2191 * Virtqueue 6 (TX disabled)
2192 * qsz 256 last_avail_idx 0 last_used_idx 0
2193 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2194 * kickfd 84 callfd 86 errfd -1
2196 * Virtqueue 7 (RX disabled)
2197 * qsz 256 last_avail_idx 0 last_used_idx 0
2198 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2199 * kickfd 88 callfd 90 errfd -1
2203 * The optional '<em>descriptors</em>' parameter will display the same output as
2204 * the previous example but will include the descriptor table for each queue.
2205 * The output is truncated below:
2206 * @cliexstart{show vhost-user VirtualEthernet0/0/0 descriptors}
2207 * Virtio vhost-user interfaces
2209 * coalesce frames 32 time 1e-3
2210 * Interface: VirtualEthernet0/0/0 (ifindex 1)
2211 * virtio_net_hdr_sz 12
2212 * features mask (0xffffffffffffffff):
2213 * features (0x50408000):
2214 * VIRTIO_NET_F_MRG_RXBUF (15)
2215 * VIRTIO_NET_F_MQ (22)
2218 * qsz 256 last_avail_idx 0 last_used_idx 0
2219 * avail.flags 1 avail.idx 128 used.flags 1 used.idx 0
2220 * kickfd 62 callfd 64 errfd -1
2223 * id addr len flags next user_addr
2224 * ===== ================== ===== ====== ===== ==================
2225 * 0 0x0000000010b6e974 2060 0x0002 1 0x00002aabbc76e974
2226 * 1 0x0000000010b6e034 2060 0x0002 2 0x00002aabbc76e034
2227 * 2 0x0000000010b6d6f4 2060 0x0002 3 0x00002aabbc76d6f4
2228 * 3 0x0000000010b6cdb4 2060 0x0002 4 0x00002aabbc76cdb4
2229 * 4 0x0000000010b6c474 2060 0x0002 5 0x00002aabbc76c474
2230 * 5 0x0000000010b6bb34 2060 0x0002 6 0x00002aabbc76bb34
2231 * 6 0x0000000010b6b1f4 2060 0x0002 7 0x00002aabbc76b1f4
2232 * 7 0x0000000010b6a8b4 2060 0x0002 8 0x00002aabbc76a8b4
2233 * 8 0x0000000010b69f74 2060 0x0002 9 0x00002aabbc769f74
2234 * 9 0x0000000010b69634 2060 0x0002 10 0x00002aabbc769634
2235 * 10 0x0000000010b68cf4 2060 0x0002 11 0x00002aabbc768cf4
2237 * 249 0x0000000000000000 0 0x0000 250 0x00002aab2b400000
2238 * 250 0x0000000000000000 0 0x0000 251 0x00002aab2b400000
2239 * 251 0x0000000000000000 0 0x0000 252 0x00002aab2b400000
2240 * 252 0x0000000000000000 0 0x0000 253 0x00002aab2b400000
2241 * 253 0x0000000000000000 0 0x0000 254 0x00002aab2b400000
2242 * 254 0x0000000000000000 0 0x0000 255 0x00002aab2b400000
2243 * 255 0x0000000000000000 0 0x0000 32768 0x00002aab2b400000
2246 * qsz 256 last_avail_idx 0 last_used_idx 0
2252 VLIB_CLI_COMMAND (show_vhost_user_command, static) = {
2253 .path = "show vhost-user",
2254 .short_help = "show vhost-user [<interface> [<interface> [..]]] [descriptors]",
2255 .function = show_vhost_user_command_fn,
2260 static clib_error_t *
2261 vhost_user_config (vlib_main_t * vm, unformat_input_t * input)
2263 vhost_user_main_t *vum = &vhost_user_main;
2265 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2267 if (unformat (input, "coalesce-frames %d", &vum->coalesce_frames))
2269 else if (unformat (input, "coalesce-time %f", &vum->coalesce_time))
2271 else if (unformat (input, "dont-dump-memory"))
2272 vum->dont_dump_vhost_user_memory = 1;
2274 return clib_error_return (0, "unknown input `%U'",
2275 format_unformat_error, input);
2281 /* vhost-user { ... } configuration. */
2282 VLIB_CONFIG_FUNCTION (vhost_user_config, "vhost-user");
2285 vhost_user_unmap_all (void)
2287 vhost_user_main_t *vum = &vhost_user_main;
2288 vhost_user_intf_t *vui;
2290 if (vum->dont_dump_vhost_user_memory)
2292 pool_foreach (vui, vum->vhost_user_interfaces,
2293 unmap_all_mem_regions (vui);
2299 * fd.io coding-style-patch-verification: ON
2302 * eval: (c-set-style "gnu")