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;
466 msg.size = sizeof (msg.u64);
467 vu_log_debug (vui, "if %d msg VHOST_USER_GET_FEATURES - reply "
468 "0x%016llx", vui->hw_if_index, msg.u64);
470 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
471 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
473 vu_log_debug (vui, "could not send message response");
478 case VHOST_USER_SET_FEATURES:
479 vu_log_debug (vui, "if %d msg VHOST_USER_SET_FEATURES features "
480 "0x%016llx", vui->hw_if_index, msg.u64);
482 vui->features = msg.u64;
485 ((1 << FEAT_VIRTIO_NET_F_MRG_RXBUF) |
486 (1ULL << FEAT_VIRTIO_F_VERSION_1)))
487 vui->virtio_net_hdr_sz = 12;
489 vui->virtio_net_hdr_sz = 10;
492 (vui->features & (1 << FEAT_VIRTIO_F_ANY_LAYOUT)) ? 1 : 0;
494 ASSERT (vui->virtio_net_hdr_sz < VLIB_BUFFER_PRE_DATA_SIZE);
495 vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
497 vhost_user_update_iface_state (vui);
500 case VHOST_USER_SET_MEM_TABLE:
501 vu_log_debug (vui, "if %d msg VHOST_USER_SET_MEM_TABLE nregions %d",
502 vui->hw_if_index, msg.memory.nregions);
504 if ((msg.memory.nregions < 1) ||
505 (msg.memory.nregions > VHOST_MEMORY_MAX_NREGIONS))
507 vu_log_debug (vui, "number of mem regions must be between 1 and %i",
508 VHOST_MEMORY_MAX_NREGIONS);
512 if (msg.memory.nregions != number_of_fds)
514 vu_log_debug (vui, "each memory region must have FD");
518 /* Do the mmap without barrier sync */
519 void *region_mmap_addr[VHOST_MEMORY_MAX_NREGIONS];
520 for (i = 0; i < msg.memory.nregions; i++)
522 long page_sz = get_huge_page_size (fds[i]);
524 /* align size to page */
525 ssize_t map_sz = (msg.memory.regions[i].memory_size +
526 msg.memory.regions[i].mmap_offset +
527 page_sz - 1) & ~(page_sz - 1);
529 region_mmap_addr[i] = mmap (0, map_sz, PROT_READ | PROT_WRITE,
530 MAP_SHARED, fds[i], 0);
531 if (region_mmap_addr[i] == MAP_FAILED)
533 vu_log_err (vui, "failed to map memory. errno is %d", errno);
534 for (j = 0; j < i; j++)
535 munmap (region_mmap_addr[j], map_sz);
538 vu_log_debug (vui, "map memory region %d addr 0 len 0x%lx fd %d "
539 "mapped 0x%lx page_sz 0x%x", i, map_sz, fds[i],
540 region_mmap_addr[i], page_sz);
543 vlib_worker_thread_barrier_sync (vm);
544 unmap_all_mem_regions (vui);
545 for (i = 0; i < msg.memory.nregions; i++)
547 clib_memcpy_fast (&(vui->regions[i]), &msg.memory.regions[i],
548 sizeof (vhost_user_memory_region_t));
550 vui->region_mmap_addr[i] = region_mmap_addr[i];
551 vui->region_guest_addr_lo[i] = vui->regions[i].guest_phys_addr;
552 vui->region_guest_addr_hi[i] = vui->regions[i].guest_phys_addr +
553 vui->regions[i].memory_size;
555 vui->region_mmap_addr[i] += vui->regions[i].mmap_offset;
556 vui->region_mmap_fd[i] = fds[i];
562 * Re-compute desc, used, and avail descriptor table if vring address
565 for (q = 0; q < VHOST_VRING_MAX_N; q++)
567 if (vui->vrings[q].desc_user_addr &&
568 vui->vrings[q].used_user_addr && vui->vrings[q].avail_user_addr)
570 vui->vrings[q].desc =
571 map_user_mem (vui, vui->vrings[q].desc_user_addr);
572 vui->vrings[q].used =
573 map_user_mem (vui, vui->vrings[q].used_user_addr);
574 vui->vrings[q].avail =
575 map_user_mem (vui, vui->vrings[q].avail_user_addr);
578 vlib_worker_thread_barrier_release (vm);
581 case VHOST_USER_SET_VRING_NUM:
582 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_NUM idx %d num %d",
583 vui->hw_if_index, msg.state.index, msg.state.num);
585 if ((msg.state.num > 32768) || /* maximum ring size is 32768 */
586 (msg.state.num == 0) || /* it cannot be zero */
587 ((msg.state.num - 1) & msg.state.num)) /* must be power of 2 */
589 vui->vrings[msg.state.index].qsz_mask = msg.state.num - 1;
592 case VHOST_USER_SET_VRING_ADDR:
593 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_ADDR idx %d",
594 vui->hw_if_index, msg.state.index);
596 if (msg.state.index >= VHOST_VRING_MAX_N)
598 vu_log_debug (vui, "invalid vring index VHOST_USER_SET_VRING_ADDR:"
599 " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
603 if (msg.size < sizeof (msg.addr))
605 vu_log_debug (vui, "vhost message is too short (%d < %d)",
606 msg.size, sizeof (msg.addr));
610 vring_desc_t *desc = map_user_mem (vui, msg.addr.desc_user_addr);
611 vring_used_t *used = map_user_mem (vui, msg.addr.used_user_addr);
612 vring_avail_t *avail = map_user_mem (vui, msg.addr.avail_user_addr);
614 if ((desc == NULL) || (used == NULL) || (avail == NULL))
616 vu_log_debug (vui, "failed to map user memory for hw_if_index %d",
621 vui->vrings[msg.state.index].desc_user_addr = msg.addr.desc_user_addr;
622 vui->vrings[msg.state.index].used_user_addr = msg.addr.used_user_addr;
623 vui->vrings[msg.state.index].avail_user_addr = msg.addr.avail_user_addr;
625 vlib_worker_thread_barrier_sync (vm);
626 vui->vrings[msg.state.index].desc = desc;
627 vui->vrings[msg.state.index].used = used;
628 vui->vrings[msg.state.index].avail = avail;
630 vui->vrings[msg.state.index].log_guest_addr = msg.addr.log_guest_addr;
631 vui->vrings[msg.state.index].log_used =
632 (msg.addr.flags & (1 << VHOST_VRING_F_LOG)) ? 1 : 0;
634 /* Spec says: If VHOST_USER_F_PROTOCOL_FEATURES has not been negotiated,
635 the ring is initialized in an enabled state. */
636 if (!(vui->features & (1 << FEAT_VHOST_USER_F_PROTOCOL_FEATURES)))
637 vui->vrings[msg.state.index].enabled = 1;
639 vui->vrings[msg.state.index].last_used_idx =
640 vui->vrings[msg.state.index].last_avail_idx =
641 vui->vrings[msg.state.index].used->idx;
643 /* tell driver that we don't want interrupts */
644 vui->vrings[msg.state.index].used->flags = VRING_USED_F_NO_NOTIFY;
645 vlib_worker_thread_barrier_release (vm);
646 vhost_user_update_iface_state (vui);
649 case VHOST_USER_SET_OWNER:
650 vu_log_debug (vui, "if %d msg VHOST_USER_SET_OWNER", vui->hw_if_index);
653 case VHOST_USER_RESET_OWNER:
654 vu_log_debug (vui, "if %d msg VHOST_USER_RESET_OWNER",
658 case VHOST_USER_SET_VRING_CALL:
659 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_CALL %d",
660 vui->hw_if_index, msg.u64);
662 q = (u8) (msg.u64 & 0xFF);
664 /* if there is old fd, delete and close it */
665 if (vui->vrings[q].callfd_idx != ~0)
667 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
668 vui->vrings[q].callfd_idx);
669 clib_file_del (&file_main, uf);
670 vui->vrings[q].callfd_idx = ~0;
673 if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
675 if (number_of_fds != 1)
677 vu_log_debug (vui, "More than one fd received !");
681 template.read_function = vhost_user_callfd_read_ready;
682 template.file_descriptor = fds[0];
683 template.private_data =
684 ((vui - vhost_user_main.vhost_user_interfaces) << 8) + q;
685 vui->vrings[q].callfd_idx = clib_file_add (&file_main, &template);
688 vui->vrings[q].callfd_idx = ~0;
691 case VHOST_USER_SET_VRING_KICK:
692 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_KICK %d",
693 vui->hw_if_index, msg.u64);
695 q = (u8) (msg.u64 & 0xFF);
697 if (vui->vrings[q].kickfd_idx != ~0)
699 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
700 vui->vrings[q].kickfd_idx);
701 clib_file_del (&file_main, uf);
702 vui->vrings[q].kickfd_idx = ~0;
705 if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
707 if (number_of_fds != 1)
709 vu_log_debug (vui, "More than one fd received !");
713 template.read_function = vhost_user_kickfd_read_ready;
714 template.file_descriptor = fds[0];
715 template.private_data =
716 (((uword) (vui - vhost_user_main.vhost_user_interfaces)) << 8) +
718 vui->vrings[q].kickfd_idx = clib_file_add (&file_main, &template);
722 //When no kickfd is set, the queue is initialized as started
723 vui->vrings[q].kickfd_idx = ~0;
724 vui->vrings[q].started = 1;
725 vhost_user_thread_placement (vui, q);
727 vhost_user_update_iface_state (vui);
730 case VHOST_USER_SET_VRING_ERR:
731 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_ERR %d",
732 vui->hw_if_index, msg.u64);
734 q = (u8) (msg.u64 & 0xFF);
736 if (vui->vrings[q].errfd != -1)
737 close (vui->vrings[q].errfd);
739 if (!(msg.u64 & VHOST_USER_VRING_NOFD_MASK))
741 if (number_of_fds != 1)
744 vui->vrings[q].errfd = fds[0];
747 vui->vrings[q].errfd = -1;
750 case VHOST_USER_SET_VRING_BASE:
751 vu_log_debug (vui, "if %d msg VHOST_USER_SET_VRING_BASE idx %d num %d",
752 vui->hw_if_index, msg.state.index, msg.state.num);
753 vlib_worker_thread_barrier_sync (vm);
754 vui->vrings[msg.state.index].last_avail_idx = msg.state.num;
755 vlib_worker_thread_barrier_release (vm);
758 case VHOST_USER_GET_VRING_BASE:
759 if (msg.state.index >= VHOST_VRING_MAX_N)
761 vu_log_debug (vui, "invalid vring index VHOST_USER_GET_VRING_BASE:"
762 " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
766 /* protection is needed to prevent rx/tx from changing last_avail_idx */
767 vlib_worker_thread_barrier_sync (vm);
769 * Copy last_avail_idx from the vring before closing it because
770 * closing the vring also initializes the vring last_avail_idx
772 msg.state.num = vui->vrings[msg.state.index].last_avail_idx;
774 msg.size = sizeof (msg.state);
777 * Spec says: Client must [...] stop ring upon receiving
778 * VHOST_USER_GET_VRING_BASE
780 vhost_user_vring_close (vui, msg.state.index);
781 vlib_worker_thread_barrier_release (vm);
782 vu_log_debug (vui, "if %d msg VHOST_USER_GET_VRING_BASE idx %d num %d",
783 vui->hw_if_index, msg.state.index, msg.state.num);
785 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
786 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
788 vu_log_debug (vui, "could not send message response");
791 vhost_user_update_iface_state (vui);
794 case VHOST_USER_NONE:
795 vu_log_debug (vui, "if %d msg VHOST_USER_NONE", vui->hw_if_index);
798 case VHOST_USER_SET_LOG_BASE:
799 vu_log_debug (vui, "if %d msg VHOST_USER_SET_LOG_BASE",
802 if (msg.size != sizeof (msg.log))
804 vu_log_debug (vui, "invalid msg size for VHOST_USER_SET_LOG_BASE:"
805 " %d instead of %d", msg.size, sizeof (msg.log));
809 if (!(vui->protocol_features & (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD)))
811 vu_log_debug (vui, "VHOST_USER_PROTOCOL_F_LOG_SHMFD not set but "
812 "VHOST_USER_SET_LOG_BASE received");
817 /* align size to page */
818 long page_sz = get_huge_page_size (fd);
820 (msg.log.size + msg.log.offset + page_sz - 1) & ~(page_sz - 1);
822 void *log_base_addr = mmap (0, map_sz, PROT_READ | PROT_WRITE,
825 vu_log_debug (vui, "map log region addr 0 len 0x%lx off 0x%lx fd %d "
826 "mapped 0x%lx", map_sz, msg.log.offset, fd,
829 if (log_base_addr == MAP_FAILED)
831 vu_log_err (vui, "failed to map memory. errno is %d", errno);
835 vlib_worker_thread_barrier_sync (vm);
836 vui->log_base_addr = log_base_addr;
837 vui->log_base_addr += msg.log.offset;
838 vui->log_size = msg.log.size;
839 vlib_worker_thread_barrier_release (vm);
842 msg.size = sizeof (msg.u64);
844 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
845 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
847 vu_log_debug (vui, "could not send message response");
852 case VHOST_USER_SET_LOG_FD:
853 vu_log_debug (vui, "if %d msg VHOST_USER_SET_LOG_FD", vui->hw_if_index);
856 case VHOST_USER_GET_PROTOCOL_FEATURES:
858 msg.u64 = (1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |
859 (1 << VHOST_USER_PROTOCOL_F_MQ);
860 msg.size = sizeof (msg.u64);
861 vu_log_debug (vui, "if %d msg VHOST_USER_GET_PROTOCOL_FEATURES - "
862 "reply 0x%016llx", vui->hw_if_index, msg.u64);
864 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
865 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
867 vu_log_debug (vui, "could not send message response");
872 case VHOST_USER_SET_PROTOCOL_FEATURES:
873 vu_log_debug (vui, "if %d msg VHOST_USER_SET_PROTOCOL_FEATURES "
874 "features 0x%016llx", vui->hw_if_index, msg.u64);
875 vui->protocol_features = msg.u64;
878 case VHOST_USER_GET_QUEUE_NUM:
880 msg.u64 = VHOST_VRING_MAX_N;
881 msg.size = sizeof (msg.u64);
882 vu_log_debug (vui, "if %d msg VHOST_USER_GET_QUEUE_NUM - reply %d",
883 vui->hw_if_index, msg.u64);
885 send (uf->file_descriptor, &msg, VHOST_USER_MSG_HDR_SZ + msg.size, 0);
886 if (n != (msg.size + VHOST_USER_MSG_HDR_SZ))
888 vu_log_debug (vui, "could not send message response");
893 case VHOST_USER_SET_VRING_ENABLE:
894 vu_log_debug (vui, "if %d VHOST_USER_SET_VRING_ENABLE: %s queue %d",
895 vui->hw_if_index, msg.state.num ? "enable" : "disable",
897 if (msg.state.index >= VHOST_VRING_MAX_N)
899 vu_log_debug (vui, "invalid vring idx VHOST_USER_SET_VRING_ENABLE:"
900 " %d >= %d", msg.state.index, VHOST_VRING_MAX_N);
904 vui->vrings[msg.state.index].enabled = msg.state.num;
905 vhost_user_thread_placement (vui, msg.state.index);
906 vhost_user_update_iface_state (vui);
910 vu_log_debug (vui, "unknown vhost-user message %d received. "
911 "closing socket", msg.request);
918 vlib_worker_thread_barrier_sync (vm);
919 vhost_user_if_disconnect (vui);
920 vlib_worker_thread_barrier_release (vm);
921 vhost_user_update_iface_state (vui);
925 static clib_error_t *
926 vhost_user_socket_error (clib_file_t * uf)
928 vlib_main_t *vm = vlib_get_main ();
929 vhost_user_main_t *vum = &vhost_user_main;
930 vhost_user_intf_t *vui =
931 pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
933 vu_log_debug (vui, "socket error on if %d", vui->sw_if_index);
934 vlib_worker_thread_barrier_sync (vm);
935 vhost_user_if_disconnect (vui);
936 vlib_worker_thread_barrier_release (vm);
940 static clib_error_t *
941 vhost_user_socksvr_accept_ready (clib_file_t * uf)
943 int client_fd, client_len;
944 struct sockaddr_un client;
945 clib_file_t template = { 0 };
946 vhost_user_main_t *vum = &vhost_user_main;
947 vhost_user_intf_t *vui;
949 vui = pool_elt_at_index (vum->vhost_user_interfaces, uf->private_data);
951 client_len = sizeof (client);
952 client_fd = accept (uf->file_descriptor,
953 (struct sockaddr *) &client,
954 (socklen_t *) & client_len);
957 return clib_error_return_unix (0, "accept");
959 if (vui->clib_file_index != ~0)
961 vu_log_debug (vui, "Close client socket for vhost interface %d, fd %d",
962 vui->sw_if_index, UNIX_GET_FD (vui->clib_file_index));
963 clib_file_del (&file_main, file_main.file_pool + vui->clib_file_index);
966 vu_log_debug (vui, "New client socket for vhost interface %d, fd %d",
967 vui->sw_if_index, client_fd);
968 template.read_function = vhost_user_socket_read;
969 template.error_function = vhost_user_socket_error;
970 template.file_descriptor = client_fd;
971 template.private_data = vui - vhost_user_main.vhost_user_interfaces;
972 vui->clib_file_index = clib_file_add (&file_main, &template);
976 static clib_error_t *
977 vhost_user_init (vlib_main_t * vm)
980 vhost_user_main_t *vum = &vhost_user_main;
981 vlib_thread_main_t *tm = vlib_get_thread_main ();
983 error = vlib_call_init_function (vm, ip4_init);
987 vum->log_default = vlib_log_register_class ("vhost-user", 0);
989 vum->coalesce_frames = 32;
990 vum->coalesce_time = 1e-3;
992 vec_validate (vum->cpus, tm->n_vlib_mains - 1);
995 vec_foreach (cpu, vum->cpus)
997 /* This is actually not necessary as validate already zeroes it
998 * Just keeping the loop here for later because I am lazy. */
999 cpu->rx_buffers_len = 0;
1002 vum->random = random_default_seed ();
1004 mhash_init_c_string (&vum->if_index_by_sock_name, sizeof (uword));
1009 VLIB_INIT_FUNCTION (vhost_user_init);
1012 vhost_user_send_interrupt_process (vlib_main_t * vm,
1013 vlib_node_runtime_t * rt, vlib_frame_t * f)
1015 vhost_user_intf_t *vui;
1016 f64 timeout = 3153600000.0 /* 100 years */ ;
1017 uword event_type, *event_data = 0;
1018 vhost_user_main_t *vum = &vhost_user_main;
1020 f64 now, poll_time_remaining;
1026 poll_time_remaining =
1027 vlib_process_wait_for_event_or_clock (vm, timeout);
1028 event_type = vlib_process_get_events (vm, &event_data);
1029 vec_reset_length (event_data);
1032 * Use the remaining timeout if it is less than coalesce time to avoid
1033 * resetting the existing timer in the middle of expiration
1035 timeout = poll_time_remaining;
1036 if (vlib_process_suspend_time_is_zero (timeout) ||
1037 (timeout > vum->coalesce_time))
1038 timeout = vum->coalesce_time;
1040 now = vlib_time_now (vm);
1043 case VHOST_USER_EVENT_STOP_TIMER:
1047 case VHOST_USER_EVENT_START_TIMER:
1049 if (!vlib_process_suspend_time_is_zero (poll_time_remaining))
1055 pool_foreach (vui, vum->vhost_user_interfaces, {
1056 next_timeout = timeout;
1057 for (qid = 0; qid < VHOST_VRING_MAX_N / 2; qid += 2)
1059 vhost_user_vring_t *rxvq = &vui->vrings[qid];
1060 vhost_user_vring_t *txvq = &vui->vrings[qid + 1];
1062 if (txvq->qid == -1)
1064 if (txvq->n_since_last_int)
1066 if (now >= txvq->int_deadline)
1067 vhost_user_send_call (vm, txvq);
1069 next_timeout = txvq->int_deadline - now;
1072 if (rxvq->n_since_last_int)
1074 if (now >= rxvq->int_deadline)
1075 vhost_user_send_call (vm, rxvq);
1077 next_timeout = rxvq->int_deadline - now;
1080 if ((next_timeout < timeout) && (next_timeout > 0.0))
1081 timeout = next_timeout;
1088 clib_warning ("BUG: unhandled event type %d", event_type);
1091 /* No less than 1 millisecond */
1095 timeout = 3153600000.0;
1101 VLIB_REGISTER_NODE (vhost_user_send_interrupt_node) = {
1102 .function = vhost_user_send_interrupt_process,
1103 .type = VLIB_NODE_TYPE_PROCESS,
1104 .name = "vhost-user-send-interrupt-process",
1109 vhost_user_process (vlib_main_t * vm,
1110 vlib_node_runtime_t * rt, vlib_frame_t * f)
1112 vhost_user_main_t *vum = &vhost_user_main;
1113 vhost_user_intf_t *vui;
1114 struct sockaddr_un sun;
1116 clib_file_t template = { 0 };
1117 f64 timeout = 3153600000.0 /* 100 years */ ;
1118 uword *event_data = 0;
1121 sun.sun_family = AF_UNIX;
1122 template.read_function = vhost_user_socket_read;
1123 template.error_function = vhost_user_socket_error;
1127 vlib_process_wait_for_event_or_clock (vm, timeout);
1128 vlib_process_get_events (vm, &event_data);
1129 vec_reset_length (event_data);
1134 pool_foreach (vui, vum->vhost_user_interfaces, {
1136 if (vui->unix_server_index == ~0) { //Nothing to do for server sockets
1137 if (vui->clib_file_index == ~0)
1140 ((sockfd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0))
1143 * 1st time error or new error for this interface,
1144 * spit out the message and record the error
1146 if (!vui->sock_errno || (vui->sock_errno != errno))
1149 ("Error: Could not open unix socket for %s",
1150 vui->sock_filename);
1151 vui->sock_errno = errno;
1156 /* try to connect */
1157 strncpy (sun.sun_path, (char *) vui->sock_filename,
1158 sizeof (sun.sun_path) - 1);
1160 /* Avoid hanging VPP if the other end does not accept */
1161 if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
1162 clib_unix_warning ("fcntl");
1164 if (connect (sockfd, (struct sockaddr *) &sun,
1165 sizeof (struct sockaddr_un)) == 0)
1167 /* Set the socket to blocking as it was before */
1168 if (fcntl(sockfd, F_SETFL, 0) < 0)
1169 clib_unix_warning ("fcntl2");
1171 vui->sock_errno = 0;
1172 template.file_descriptor = sockfd;
1173 template.private_data =
1174 vui - vhost_user_main.vhost_user_interfaces;
1175 vui->clib_file_index = clib_file_add (&file_main, &template);
1177 /* This sockfd is considered consumed */
1182 vui->sock_errno = errno;
1187 /* check if socket is alive */
1189 socklen_t len = sizeof (error);
1190 int fd = UNIX_GET_FD(vui->clib_file_index);
1192 getsockopt (fd, SOL_SOCKET, SO_ERROR, &error, &len);
1196 vu_log_debug (vui, "getsockopt returned %d", retval);
1197 vhost_user_if_disconnect (vui);
1208 VLIB_REGISTER_NODE (vhost_user_process_node,static) = {
1209 .function = vhost_user_process,
1210 .type = VLIB_NODE_TYPE_PROCESS,
1211 .name = "vhost-user-process",
1216 * Disables and reset interface structure.
1217 * It can then be either init again, or removed from used interfaces.
1220 vhost_user_term_if (vhost_user_intf_t * vui)
1223 vhost_user_main_t *vum = &vhost_user_main;
1225 // disconnect interface sockets
1226 vhost_user_if_disconnect (vui);
1227 vhost_user_update_iface_state (vui);
1229 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1231 // Remove existing queue mapping for the interface
1235 vnet_main_t *vnm = vnet_get_main ();
1236 vhost_user_vring_t *txvq = &vui->vrings[q];
1238 if (txvq->qid != -1)
1240 rv = vnet_hw_interface_unassign_rx_thread (vnm,
1244 vu_log_warn (vui, "unable to unassign interface %d, "
1245 "queue %d: rc=%d", vui->hw_if_index, q >> 1, rv);
1249 clib_mem_free ((void *) vui->vring_locks[q]);
1252 if (vui->unix_server_index != ~0)
1254 //Close server socket
1255 clib_file_t *uf = pool_elt_at_index (file_main.file_pool,
1256 vui->unix_server_index);
1257 clib_file_del (&file_main, uf);
1258 vui->unix_server_index = ~0;
1259 unlink (vui->sock_filename);
1262 mhash_unset (&vum->if_index_by_sock_name, vui->sock_filename,
1267 vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, u32 sw_if_index)
1269 vhost_user_main_t *vum = &vhost_user_main;
1270 vhost_user_intf_t *vui;
1272 vnet_hw_interface_t *hwif;
1277 vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index))
1278 || hwif->dev_class_index != vhost_user_device_class.index)
1279 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1281 vui = pool_elt_at_index (vum->vhost_user_interfaces, hwif->dev_instance);
1283 vu_log_debug (vui, "Deleting vhost-user interface %s (instance %d)",
1284 hwif->name, hwif->dev_instance);
1286 for (qid = 1; qid < VHOST_VRING_MAX_N / 2; qid += 2)
1288 vhost_user_vring_t *txvq = &vui->vrings[qid];
1290 if (txvq->qid == -1)
1292 if ((vum->ifq_count > 0) &&
1293 ((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
1294 (txvq->mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE)))
1297 // Stop the timer if there is no more interrupt interface/queue
1298 if ((vum->ifq_count == 0) &&
1299 (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
1301 vlib_process_signal_event (vm,
1302 vhost_user_send_interrupt_node.index,
1303 VHOST_USER_EVENT_STOP_TIMER, 0);
1309 // Disable and reset interface
1310 vhost_user_term_if (vui);
1312 // Reset renumbered iface
1313 if (hwif->dev_instance <
1314 vec_len (vum->show_dev_instance_by_real_dev_instance))
1315 vum->show_dev_instance_by_real_dev_instance[hwif->dev_instance] = ~0;
1317 // Delete ethernet interface
1318 ethernet_delete_interface (vnm, vui->hw_if_index);
1321 pool_put (vum->vhost_user_interfaces, vui);
1326 static clib_error_t *
1327 vhost_user_exit (vlib_main_t * vm)
1329 vnet_main_t *vnm = vnet_get_main ();
1330 vhost_user_main_t *vum = &vhost_user_main;
1331 vhost_user_intf_t *vui;
1333 vlib_worker_thread_barrier_sync (vlib_get_main ());
1335 pool_foreach (vui, vum->vhost_user_interfaces, {
1336 vhost_user_delete_if (vnm, vm, vui->sw_if_index);
1339 vlib_worker_thread_barrier_release (vlib_get_main ());
1343 VLIB_MAIN_LOOP_EXIT_FUNCTION (vhost_user_exit);
1346 * Open server unix socket on specified sock_filename.
1349 vhost_user_init_server_sock (const char *sock_filename, int *sock_fd)
1352 struct sockaddr_un un = { };
1354 /* create listening socket */
1355 if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
1356 return VNET_API_ERROR_SYSCALL_ERROR_1;
1358 un.sun_family = AF_UNIX;
1359 strncpy ((char *) un.sun_path, (char *) sock_filename,
1360 sizeof (un.sun_path) - 1);
1362 /* remove if exists */
1363 unlink ((char *) sock_filename);
1365 if (bind (fd, (struct sockaddr *) &un, sizeof (un)) == -1)
1367 rv = VNET_API_ERROR_SYSCALL_ERROR_2;
1371 if (listen (fd, 1) == -1)
1373 rv = VNET_API_ERROR_SYSCALL_ERROR_3;
1386 * Create ethernet interface for vhost user interface.
1389 vhost_user_create_ethernet (vnet_main_t * vnm, vlib_main_t * vm,
1390 vhost_user_intf_t * vui, u8 * hwaddress)
1392 vhost_user_main_t *vum = &vhost_user_main;
1394 clib_error_t *error;
1396 /* create hw and sw interface */
1399 clib_memcpy (hwaddr, hwaddress, 6);
1403 random_u32 (&vum->random);
1404 clib_memcpy (hwaddr + 2, &vum->random, sizeof (vum->random));
1409 error = ethernet_register_interface
1411 vhost_user_device_class.index,
1412 vui - vum->vhost_user_interfaces /* device instance */ ,
1413 hwaddr /* ethernet address */ ,
1414 &vui->hw_if_index, 0 /* flag change */ );
1417 clib_error_report (error);
1421 * Initialize vui with specified attributes
1424 vhost_user_vui_init (vnet_main_t * vnm,
1425 vhost_user_intf_t * vui,
1427 const char *sock_filename,
1428 u64 feature_mask, u32 * sw_if_index)
1430 vnet_sw_interface_t *sw;
1432 vhost_user_main_t *vum = &vhost_user_main;
1433 vnet_hw_interface_t *hw;
1435 hw = vnet_get_hw_interface (vnm, vui->hw_if_index);
1436 sw = vnet_get_hw_sw_interface (vnm, vui->hw_if_index);
1437 if (server_sock_fd != -1)
1439 clib_file_t template = { 0 };
1440 template.read_function = vhost_user_socksvr_accept_ready;
1441 template.file_descriptor = server_sock_fd;
1442 template.private_data = vui - vum->vhost_user_interfaces; //hw index
1443 vui->unix_server_index = clib_file_add (&file_main, &template);
1447 vui->unix_server_index = ~0;
1450 vui->sw_if_index = sw->sw_if_index;
1451 strncpy (vui->sock_filename, sock_filename,
1452 ARRAY_LEN (vui->sock_filename) - 1);
1453 vui->sock_errno = 0;
1455 vui->feature_mask = feature_mask;
1456 vui->clib_file_index = ~0;
1457 vui->log_base_addr = 0;
1458 vui->if_index = vui - vum->vhost_user_interfaces;
1459 mhash_set_mem (&vum->if_index_by_sock_name, vui->sock_filename,
1462 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1463 vhost_user_vring_init (vui, q);
1465 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
1466 vnet_hw_interface_set_flags (vnm, vui->hw_if_index, 0);
1469 *sw_if_index = vui->sw_if_index;
1471 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1473 vui->vring_locks[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
1474 CLIB_CACHE_LINE_BYTES);
1475 clib_memset ((void *) vui->vring_locks[q], 0, CLIB_CACHE_LINE_BYTES);
1478 vec_validate (vui->per_cpu_tx_qid,
1479 vlib_get_thread_main ()->n_vlib_mains - 1);
1480 vhost_user_tx_thread_placement (vui);
1484 vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm,
1485 const char *sock_filename,
1489 u8 renumber, u32 custom_dev_instance, u8 * hwaddr)
1491 vhost_user_intf_t *vui = NULL;
1494 int server_sock_fd = -1;
1495 vhost_user_main_t *vum = &vhost_user_main;
1498 if (sock_filename == NULL || !(strlen (sock_filename) > 0))
1500 return VNET_API_ERROR_INVALID_ARGUMENT;
1503 if_index = mhash_get (&vum->if_index_by_sock_name, (void *) sock_filename);
1508 vui = &vum->vhost_user_interfaces[*if_index];
1509 *sw_if_index = vui->sw_if_index;
1511 return VNET_API_ERROR_IF_ALREADY_EXISTS;
1517 vhost_user_init_server_sock (sock_filename, &server_sock_fd)) != 0)
1523 /* Protect the uninitialized vui from being dispatched by rx/tx */
1524 vlib_worker_thread_barrier_sync (vm);
1525 pool_get (vhost_user_main.vhost_user_interfaces, vui);
1526 vhost_user_create_ethernet (vnm, vm, vui, hwaddr);
1527 vlib_worker_thread_barrier_release (vm);
1529 vhost_user_vui_init (vnm, vui, server_sock_fd, sock_filename,
1530 feature_mask, &sw_if_idx);
1531 vnet_sw_interface_set_mtu (vnm, vui->sw_if_index, 9000);
1532 vhost_user_rx_thread_placement (vui, 1);
1535 vnet_interface_name_renumber (sw_if_idx, custom_dev_instance);
1538 *sw_if_index = sw_if_idx;
1540 // Process node must connect
1541 vlib_process_signal_event (vm, vhost_user_process_node.index, 0, 0);
1547 vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm,
1548 const char *sock_filename,
1551 u64 feature_mask, u8 renumber, u32 custom_dev_instance)
1553 vhost_user_main_t *vum = &vhost_user_main;
1554 vhost_user_intf_t *vui = NULL;
1556 int server_sock_fd = -1;
1558 vnet_hw_interface_t *hwif;
1563 vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index))
1564 || hwif->dev_class_index != vhost_user_device_class.index)
1565 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1567 if (sock_filename == NULL || !(strlen (sock_filename) > 0))
1568 return VNET_API_ERROR_INVALID_ARGUMENT;
1570 vui = vec_elt_at_index (vum->vhost_user_interfaces, hwif->dev_instance);
1573 * Disallow changing the interface to have the same path name
1574 * as other interface
1576 if_index = mhash_get (&vum->if_index_by_sock_name, (void *) sock_filename);
1577 if (if_index && (*if_index != vui->if_index))
1578 return VNET_API_ERROR_IF_ALREADY_EXISTS;
1580 // First try to open server socket
1582 if ((rv = vhost_user_init_server_sock (sock_filename,
1583 &server_sock_fd)) != 0)
1586 vhost_user_term_if (vui);
1587 vhost_user_vui_init (vnm, vui, server_sock_fd,
1588 sock_filename, feature_mask, &sw_if_idx);
1591 vnet_interface_name_renumber (sw_if_idx, custom_dev_instance);
1593 // Process node must connect
1594 vlib_process_signal_event (vm, vhost_user_process_node.index, 0, 0);
1600 vhost_user_connect_command_fn (vlib_main_t * vm,
1601 unformat_input_t * input,
1602 vlib_cli_command_t * cmd)
1604 unformat_input_t _line_input, *line_input = &_line_input;
1605 u8 *sock_filename = NULL;
1608 u64 feature_mask = (u64) ~ (0ULL);
1610 u32 custom_dev_instance = ~0;
1613 clib_error_t *error = NULL;
1615 /* Get a line of input. */
1616 if (!unformat_user (input, unformat_line_input, line_input))
1619 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1621 if (unformat (line_input, "socket %s", &sock_filename))
1623 else if (unformat (line_input, "server"))
1625 else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
1629 (line_input, "hwaddr %U", unformat_ethernet_address, hwaddr))
1631 else if (unformat (line_input, "renumber %d", &custom_dev_instance))
1637 error = clib_error_return (0, "unknown input `%U'",
1638 format_unformat_error, line_input);
1643 vnet_main_t *vnm = vnet_get_main ();
1646 if ((rv = vhost_user_create_if (vnm, vm, (char *) sock_filename,
1647 is_server, &sw_if_index, feature_mask,
1648 renumber, custom_dev_instance, hw)))
1650 error = clib_error_return (0, "vhost_user_create_if returned %d", rv);
1654 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (),
1658 vec_free (sock_filename);
1659 unformat_free (line_input);
1665 vhost_user_delete_command_fn (vlib_main_t * vm,
1666 unformat_input_t * input,
1667 vlib_cli_command_t * cmd)
1669 unformat_input_t _line_input, *line_input = &_line_input;
1670 u32 sw_if_index = ~0;
1671 vnet_main_t *vnm = vnet_get_main ();
1672 clib_error_t *error = NULL;
1674 /* Get a line of input. */
1675 if (!unformat_user (input, unformat_line_input, line_input))
1678 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1680 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
1683 (line_input, "%U", unformat_vnet_sw_interface, vnm,
1686 vnet_hw_interface_t *hwif =
1687 vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
1689 vhost_user_device_class.index != hwif->dev_class_index)
1691 error = clib_error_return (0, "Not a vhost interface");
1697 error = clib_error_return (0, "unknown input `%U'",
1698 format_unformat_error, line_input);
1703 vhost_user_delete_if (vnm, vm, sw_if_index);
1706 unformat_free (line_input);
1712 vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm,
1713 vhost_user_intf_details_t ** out_vuids)
1716 vhost_user_main_t *vum = &vhost_user_main;
1717 vhost_user_intf_t *vui;
1718 vhost_user_intf_details_t *r_vuids = NULL;
1719 vhost_user_intf_details_t *vuid = NULL;
1720 u32 *hw_if_indices = 0;
1721 vnet_hw_interface_t *hi;
1728 pool_foreach (vui, vum->vhost_user_interfaces,
1729 vec_add1 (hw_if_indices, vui->hw_if_index);
1732 for (i = 0; i < vec_len (hw_if_indices); i++)
1734 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
1735 vui = pool_elt_at_index (vum->vhost_user_interfaces, hi->dev_instance);
1737 vec_add2 (r_vuids, vuid, 1);
1738 vuid->sw_if_index = vui->sw_if_index;
1739 vuid->virtio_net_hdr_sz = vui->virtio_net_hdr_sz;
1740 vuid->features = vui->features;
1741 vuid->num_regions = vui->nregions;
1742 vuid->is_server = vui->unix_server_index != ~0;
1743 vuid->sock_errno = vui->sock_errno;
1744 strncpy ((char *) vuid->sock_filename, (char *) vui->sock_filename,
1745 sizeof (vuid->sock_filename));
1746 vuid->sock_filename[ARRAY_LEN (vuid->sock_filename) - 1] = '\0';
1747 s = format (s, "%v%c", hi->name, 0);
1749 strncpy ((char *) vuid->if_name, (char *) s,
1750 ARRAY_LEN (vuid->if_name) - 1);
1755 vec_free (hw_if_indices);
1757 *out_vuids = r_vuids;
1763 show_vhost_user_command_fn (vlib_main_t * vm,
1764 unformat_input_t * input,
1765 vlib_cli_command_t * cmd)
1767 clib_error_t *error = 0;
1768 vnet_main_t *vnm = vnet_get_main ();
1769 vhost_user_main_t *vum = &vhost_user_main;
1770 vhost_user_intf_t *vui;
1771 u32 hw_if_index, *hw_if_indices = 0;
1772 vnet_hw_interface_t *hi;
1782 struct feat_struct *feat_entry;
1784 static struct feat_struct feat_array[] = {
1785 #define _(s,b) { .str = #s, .bit = b, },
1786 foreach_virtio_net_feature
1791 #define foreach_protocol_feature \
1792 _(VHOST_USER_PROTOCOL_F_MQ) \
1793 _(VHOST_USER_PROTOCOL_F_LOG_SHMFD)
1795 static struct feat_struct proto_feat_array[] = {
1796 #define _(s) { .str = #s, .bit = s},
1797 foreach_protocol_feature
1802 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1805 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1807 hi = vnet_get_hw_interface (vnm, hw_if_index);
1808 if (vhost_user_device_class.index != hi->dev_class_index)
1810 error = clib_error_return (0, "unknown input `%U'",
1811 format_unformat_error, input);
1814 vec_add1 (hw_if_indices, hw_if_index);
1816 else if (unformat (input, "descriptors") || unformat (input, "desc"))
1820 error = clib_error_return (0, "unknown input `%U'",
1821 format_unformat_error, input);
1825 if (vec_len (hw_if_indices) == 0)
1827 pool_foreach (vui, vum->vhost_user_interfaces,
1828 vec_add1 (hw_if_indices, vui->hw_if_index);
1831 vlib_cli_output (vm, "Virtio vhost-user interfaces");
1832 vlib_cli_output (vm, "Global:\n coalesce frames %d time %e",
1833 vum->coalesce_frames, vum->coalesce_time);
1834 vlib_cli_output (vm, " number of rx virtqueues in interrupt mode: %d",
1837 for (i = 0; i < vec_len (hw_if_indices); i++)
1839 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
1840 vui = pool_elt_at_index (vum->vhost_user_interfaces, hi->dev_instance);
1841 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
1842 format_vnet_hw_if_index_name, vnm, hw_if_indices[i],
1845 vlib_cli_output (vm, "virtio_net_hdr_sz %d\n"
1846 " features mask (0x%llx): \n"
1847 " features (0x%llx): \n",
1848 vui->virtio_net_hdr_sz, vui->feature_mask,
1851 feat_entry = (struct feat_struct *) &feat_array;
1852 while (feat_entry->str)
1854 if (vui->features & (1ULL << feat_entry->bit))
1855 vlib_cli_output (vm, " %s (%d)", feat_entry->str,
1860 vlib_cli_output (vm, " protocol features (0x%llx)",
1861 vui->protocol_features);
1862 feat_entry = (struct feat_struct *) &proto_feat_array;
1863 while (feat_entry->str)
1865 if (vui->protocol_features & (1ULL << feat_entry->bit))
1866 vlib_cli_output (vm, " %s (%d)", feat_entry->str,
1871 vlib_cli_output (vm, "\n");
1873 vlib_cli_output (vm, " socket filename %s type %s errno \"%s\"\n\n",
1875 (vui->unix_server_index != ~0) ? "server" : "client",
1876 strerror (vui->sock_errno));
1878 vlib_cli_output (vm, " rx placement: ");
1880 for (qid = 1; qid < VHOST_VRING_MAX_N / 2; qid += 2)
1882 vnet_main_t *vnm = vnet_get_main ();
1884 vnet_hw_interface_rx_mode mode;
1885 vhost_user_vring_t *txvq = &vui->vrings[qid];
1887 if (txvq->qid == -1)
1890 vnet_get_device_input_thread_index (vnm, vui->hw_if_index,
1892 vnet_hw_interface_get_rx_mode (vnm, vui->hw_if_index, qid >> 1,
1894 vlib_cli_output (vm, " thread %d on vring %d, %U\n",
1896 format_vnet_hw_interface_rx_mode, mode);
1899 vlib_cli_output (vm, " tx placement: %s\n",
1900 vui->use_tx_spinlock ? "spin-lock" : "lock-free");
1902 vec_foreach_index (ci, vui->per_cpu_tx_qid)
1904 vlib_cli_output (vm, " thread %d on vring %d\n", ci,
1905 VHOST_VRING_IDX_RX (vui->per_cpu_tx_qid[ci]));
1908 vlib_cli_output (vm, "\n");
1910 vlib_cli_output (vm, " Memory regions (total %d)\n", vui->nregions);
1914 vlib_cli_output (vm,
1915 " region fd guest_phys_addr memory_size userspace_addr mmap_offset mmap_addr\n");
1916 vlib_cli_output (vm,
1917 " ====== ===== ================== ================== ================== ================== ==================\n");
1919 for (j = 0; j < vui->nregions; j++)
1921 vlib_cli_output (vm,
1922 " %d %-5d 0x%016lx 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n",
1923 j, vui->region_mmap_fd[j],
1924 vui->regions[j].guest_phys_addr,
1925 vui->regions[j].memory_size,
1926 vui->regions[j].userspace_addr,
1927 vui->regions[j].mmap_offset,
1928 pointer_to_uword (vui->region_mmap_addr[j]));
1930 for (q = 0; q < VHOST_VRING_MAX_N; q++)
1932 if (!vui->vrings[q].started)
1935 vlib_cli_output (vm, "\n Virtqueue %d (%s%s)\n", q,
1936 (q & 1) ? "RX" : "TX",
1937 vui->vrings[q].enabled ? "" : " disabled");
1939 vlib_cli_output (vm,
1940 " qsz %d last_avail_idx %d last_used_idx %d\n",
1941 vui->vrings[q].qsz_mask + 1,
1942 vui->vrings[q].last_avail_idx,
1943 vui->vrings[q].last_used_idx);
1945 if (vui->vrings[q].avail && vui->vrings[q].used)
1946 vlib_cli_output (vm,
1947 " avail.flags %x avail.idx %d used.flags %x used.idx %d\n",
1948 vui->vrings[q].avail->flags,
1949 vui->vrings[q].avail->idx,
1950 vui->vrings[q].used->flags,
1951 vui->vrings[q].used->idx);
1953 int kickfd = UNIX_GET_FD (vui->vrings[q].kickfd_idx);
1954 int callfd = UNIX_GET_FD (vui->vrings[q].callfd_idx);
1955 vlib_cli_output (vm, " kickfd %d callfd %d errfd %d\n",
1956 kickfd, callfd, vui->vrings[q].errfd);
1960 vlib_cli_output (vm, "\n descriptor table:\n");
1961 vlib_cli_output (vm,
1962 " id addr len flags next user_addr\n");
1963 vlib_cli_output (vm,
1964 " ===== ================== ===== ====== ===== ==================\n");
1965 for (j = 0; j < vui->vrings[q].qsz_mask + 1; j++)
1968 vlib_cli_output (vm,
1969 " %-5d 0x%016lx %-5d 0x%04x %-5d 0x%016lx\n",
1970 j, vui->vrings[q].desc[j].addr,
1971 vui->vrings[q].desc[j].len,
1972 vui->vrings[q].desc[j].flags,
1973 vui->vrings[q].desc[j].next,
1974 pointer_to_uword (map_guest_mem
1976 vui->vrings[q].desc[j].
1981 vlib_cli_output (vm, "\n");
1984 vec_free (hw_if_indices);
1993 * Create a vHost User interface. Once created, a new virtual interface
1994 * will exist with the name '<em>VirtualEthernet0/0/x</em>', where '<em>x</em>'
1995 * is the next free index.
1997 * There are several parameters associated with a vHost interface:
1999 * - <b>socket <socket-filename></b> - Name of the linux socket used by hypervisor
2000 * and VPP to manage the vHost interface. If in '<em>server</em>' mode, VPP will
2001 * create the socket if it does not already exist. If in '<em>client</em>' mode,
2002 * hypervisor will create the socket if it does not already exist. The VPP code
2003 * is indifferent to the file location. However, if SELinux is enabled, then the
2004 * socket needs to be created in '<em>/var/run/vpp/</em>'.
2006 * - <b>server</b> - Optional flag to indicate that VPP should be the server for
2007 * the linux socket. If not provided, VPP will be the client. In '<em>server</em>'
2008 * mode, the VM can be reset without tearing down the vHost Interface. In
2009 * '<em>client</em>' mode, VPP can be reset without bringing down the VM and
2010 * tearing down the vHost Interface.
2012 * - <b>feature-mask <hex></b> - Optional virtio/vhost feature set negotiated at
2013 * startup. <b>This is intended for degugging only.</b> It is recommended that this
2014 * parameter not be used except by experienced users. By default, all supported
2015 * features will be advertised. Otherwise, provide the set of features desired.
2016 * - 0x000008000 (15) - VIRTIO_NET_F_MRG_RXBUF
2017 * - 0x000020000 (17) - VIRTIO_NET_F_CTRL_VQ
2018 * - 0x000200000 (21) - VIRTIO_NET_F_GUEST_ANNOUNCE
2019 * - 0x000400000 (22) - VIRTIO_NET_F_MQ
2020 * - 0x004000000 (26) - VHOST_F_LOG_ALL
2021 * - 0x008000000 (27) - VIRTIO_F_ANY_LAYOUT
2022 * - 0x010000000 (28) - VIRTIO_F_INDIRECT_DESC
2023 * - 0x040000000 (30) - VHOST_USER_F_PROTOCOL_FEATURES
2024 * - 0x100000000 (32) - VIRTIO_F_VERSION_1
2026 * - <b>hwaddr <mac-addr></b> - Optional ethernet address, can be in either
2027 * X:X:X:X:X:X unix or X.X.X cisco format.
2029 * - <b>renumber <dev_instance></b> - Optional parameter which allows the instance
2030 * in the name to be specified. If instance already exists, name will be used
2031 * anyway and multiple instances will have the same name. Use with caution.
2034 * Example of how to create a vhost interface with VPP as the client and all features enabled:
2035 * @cliexstart{create vhost-user socket /var/run/vpp/vhost1.sock}
2036 * VirtualEthernet0/0/0
2038 * Example of how to create a vhost interface with VPP as the server and with just
2039 * multiple queues enabled:
2040 * @cliexstart{create vhost-user socket /var/run/vpp/vhost2.sock server feature-mask 0x40400000}
2041 * VirtualEthernet0/0/1
2043 * Once the vHost interface is created, enable the interface using:
2044 * @cliexcmd{set interface state VirtualEthernet0/0/0 up}
2047 VLIB_CLI_COMMAND (vhost_user_connect_command, static) = {
2048 .path = "create vhost-user",
2049 .short_help = "create vhost-user socket <socket-filename> [server] "
2050 "[feature-mask <hex>] [hwaddr <mac-addr>] [renumber <dev_instance>] ",
2051 .function = vhost_user_connect_command_fn,
2057 * Delete a vHost User interface using the interface name or the
2058 * software interface index. Use the '<em>show interface</em>'
2059 * command to determine the software interface index. On deletion,
2060 * the linux socket will not be deleted.
2063 * Example of how to delete a vhost interface by name:
2064 * @cliexcmd{delete vhost-user VirtualEthernet0/0/1}
2065 * Example of how to delete a vhost interface by software interface index:
2066 * @cliexcmd{delete vhost-user sw_if_index 1}
2069 VLIB_CLI_COMMAND (vhost_user_delete_command, static) = {
2070 .path = "delete vhost-user",
2071 .short_help = "delete vhost-user {<interface> | sw_if_index <sw_idx>}",
2072 .function = vhost_user_delete_command_fn,
2076 * Display the attributes of a single vHost User interface (provide interface
2077 * name), multiple vHost User interfaces (provide a list of interface names seperated
2078 * by spaces) or all Vhost User interfaces (omit an interface name to display all
2079 * vHost interfaces).
2083 * Example of how to display a vhost interface:
2084 * @cliexstart{show vhost-user VirtualEthernet0/0/0}
2085 * Virtio vhost-user interfaces
2087 * coalesce frames 32 time 1e-3
2088 * Interface: VirtualEthernet0/0/0 (ifindex 1)
2089 * virtio_net_hdr_sz 12
2090 * features mask (0xffffffffffffffff):
2091 * features (0x50408000):
2092 * VIRTIO_NET_F_MRG_RXBUF (15)
2093 * VIRTIO_NET_F_MQ (22)
2094 * VIRTIO_F_INDIRECT_DESC (28)
2095 * VHOST_USER_F_PROTOCOL_FEATURES (30)
2096 * protocol features (0x3)
2097 * VHOST_USER_PROTOCOL_F_MQ (0)
2098 * VHOST_USER_PROTOCOL_F_LOG_SHMFD (1)
2100 * socket filename /var/run/vpp/vhost1.sock type client errno "Success"
2103 * thread 1 on vring 1
2104 * thread 1 on vring 5
2105 * thread 2 on vring 3
2106 * thread 2 on vring 7
2107 * tx placement: spin-lock
2108 * thread 0 on vring 0
2109 * thread 1 on vring 2
2110 * thread 2 on vring 0
2112 * Memory regions (total 2)
2113 * region fd guest_phys_addr memory_size userspace_addr mmap_offset mmap_addr
2114 * ====== ===== ================== ================== ================== ================== ==================
2115 * 0 60 0x0000000000000000 0x00000000000a0000 0x00002aaaaac00000 0x0000000000000000 0x00002aab2b400000
2116 * 1 61 0x00000000000c0000 0x000000003ff40000 0x00002aaaaacc0000 0x00000000000c0000 0x00002aababcc0000
2119 * qsz 256 last_avail_idx 0 last_used_idx 0
2120 * avail.flags 1 avail.idx 128 used.flags 1 used.idx 0
2121 * kickfd 62 callfd 64 errfd -1
2124 * qsz 256 last_avail_idx 0 last_used_idx 0
2125 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2126 * kickfd 65 callfd 66 errfd -1
2129 * qsz 256 last_avail_idx 0 last_used_idx 0
2130 * avail.flags 1 avail.idx 128 used.flags 1 used.idx 0
2131 * kickfd 63 callfd 70 errfd -1
2134 * qsz 256 last_avail_idx 0 last_used_idx 0
2135 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2136 * kickfd 72 callfd 74 errfd -1
2138 * Virtqueue 4 (TX disabled)
2139 * qsz 256 last_avail_idx 0 last_used_idx 0
2140 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2141 * kickfd 76 callfd 78 errfd -1
2143 * Virtqueue 5 (RX disabled)
2144 * qsz 256 last_avail_idx 0 last_used_idx 0
2145 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2146 * kickfd 80 callfd 82 errfd -1
2148 * Virtqueue 6 (TX disabled)
2149 * qsz 256 last_avail_idx 0 last_used_idx 0
2150 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2151 * kickfd 84 callfd 86 errfd -1
2153 * Virtqueue 7 (RX disabled)
2154 * qsz 256 last_avail_idx 0 last_used_idx 0
2155 * avail.flags 1 avail.idx 0 used.flags 1 used.idx 0
2156 * kickfd 88 callfd 90 errfd -1
2160 * The optional '<em>descriptors</em>' parameter will display the same output as
2161 * the previous example but will include the descriptor table for each queue.
2162 * The output is truncated below:
2163 * @cliexstart{show vhost-user VirtualEthernet0/0/0 descriptors}
2164 * Virtio vhost-user interfaces
2166 * coalesce frames 32 time 1e-3
2167 * Interface: VirtualEthernet0/0/0 (ifindex 1)
2168 * virtio_net_hdr_sz 12
2169 * features mask (0xffffffffffffffff):
2170 * features (0x50408000):
2171 * VIRTIO_NET_F_MRG_RXBUF (15)
2172 * VIRTIO_NET_F_MQ (22)
2175 * qsz 256 last_avail_idx 0 last_used_idx 0
2176 * avail.flags 1 avail.idx 128 used.flags 1 used.idx 0
2177 * kickfd 62 callfd 64 errfd -1
2180 * id addr len flags next user_addr
2181 * ===== ================== ===== ====== ===== ==================
2182 * 0 0x0000000010b6e974 2060 0x0002 1 0x00002aabbc76e974
2183 * 1 0x0000000010b6e034 2060 0x0002 2 0x00002aabbc76e034
2184 * 2 0x0000000010b6d6f4 2060 0x0002 3 0x00002aabbc76d6f4
2185 * 3 0x0000000010b6cdb4 2060 0x0002 4 0x00002aabbc76cdb4
2186 * 4 0x0000000010b6c474 2060 0x0002 5 0x00002aabbc76c474
2187 * 5 0x0000000010b6bb34 2060 0x0002 6 0x00002aabbc76bb34
2188 * 6 0x0000000010b6b1f4 2060 0x0002 7 0x00002aabbc76b1f4
2189 * 7 0x0000000010b6a8b4 2060 0x0002 8 0x00002aabbc76a8b4
2190 * 8 0x0000000010b69f74 2060 0x0002 9 0x00002aabbc769f74
2191 * 9 0x0000000010b69634 2060 0x0002 10 0x00002aabbc769634
2192 * 10 0x0000000010b68cf4 2060 0x0002 11 0x00002aabbc768cf4
2194 * 249 0x0000000000000000 0 0x0000 250 0x00002aab2b400000
2195 * 250 0x0000000000000000 0 0x0000 251 0x00002aab2b400000
2196 * 251 0x0000000000000000 0 0x0000 252 0x00002aab2b400000
2197 * 252 0x0000000000000000 0 0x0000 253 0x00002aab2b400000
2198 * 253 0x0000000000000000 0 0x0000 254 0x00002aab2b400000
2199 * 254 0x0000000000000000 0 0x0000 255 0x00002aab2b400000
2200 * 255 0x0000000000000000 0 0x0000 32768 0x00002aab2b400000
2203 * qsz 256 last_avail_idx 0 last_used_idx 0
2209 VLIB_CLI_COMMAND (show_vhost_user_command, static) = {
2210 .path = "show vhost-user",
2211 .short_help = "show vhost-user [<interface> [<interface> [..]]] [descriptors]",
2212 .function = show_vhost_user_command_fn,
2217 static clib_error_t *
2218 vhost_user_config (vlib_main_t * vm, unformat_input_t * input)
2220 vhost_user_main_t *vum = &vhost_user_main;
2222 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2224 if (unformat (input, "coalesce-frames %d", &vum->coalesce_frames))
2226 else if (unformat (input, "coalesce-time %f", &vum->coalesce_time))
2228 else if (unformat (input, "dont-dump-memory"))
2229 vum->dont_dump_vhost_user_memory = 1;
2231 return clib_error_return (0, "unknown input `%U'",
2232 format_unformat_error, input);
2238 /* vhost-user { ... } configuration. */
2239 VLIB_CONFIG_FUNCTION (vhost_user_config, "vhost-user");
2242 vhost_user_unmap_all (void)
2244 vhost_user_main_t *vum = &vhost_user_main;
2245 vhost_user_intf_t *vui;
2247 if (vum->dont_dump_vhost_user_memory)
2249 pool_foreach (vui, vum->vhost_user_interfaces,
2250 unmap_all_mem_regions (vui);
2256 * fd.io coding-style-patch-verification: ON
2259 * eval: (c-set-style "gnu")