8 Copyright 2014 Virtual Open Systems Sarl.
9 Copyright 2019 Intel Corporation
10 Licence: This work is licensed under the terms of the GNU GPL,
11 version 2 or later. See the COPYING file in the top-level
14 .. contents:: Table of Contents
19 This protocol is aiming to complement the ``ioctl`` interface used to
20 control the vhost implementation in the Linux kernel. It implements
21 the control plane needed to establish virtqueue sharing with a user
22 space process on the same host. It uses communication over a Unix
23 domain socket to share file descriptors in the ancillary data of the
26 The protocol defines 2 sides of the communication, *front-end* and
27 *back-end*. The *front-end* is the application that shares its virtqueues, in
28 our case QEMU. The *back-end* is the consumer of the virtqueues.
30 In the current implementation QEMU is the *front-end*, and the *back-end*
31 is the external process consuming the virtio queues, for example a
32 software Ethernet switch running in user space, such as Snabbswitch,
33 or a block device back-end processing read & write to a virtual
34 disk. In order to facilitate interoperability between various back-end
35 implementations, it is recommended to follow the :ref:`Backend program
36 conventions <backend_conventions>`.
38 The *front-end* and *back-end* can be either a client (i.e. connecting) or
39 server (listening) in the socket communication.
41 Support for platforms other than Linux
42 --------------------------------------
44 While vhost-user was initially developed targeting Linux, nowadays it
45 is supported on any platform that provides the following features:
47 - A way for requesting shared memory represented by a file descriptor
48 so it can be passed over a UNIX domain socket and then mapped by the
51 - AF_UNIX sockets with SCM_RIGHTS, so QEMU and the other process can
52 exchange messages through it, including ancillary data when needed.
54 - Either eventfd or pipe/pipe2. On platforms where eventfd is not
55 available, QEMU will automatically fall back to pipe2 or, as a last
56 resort, pipe. Each file descriptor will be used for receiving or
57 sending events by reading or writing (respectively) an 8-byte value
58 to the corresponding it. The 8-value itself has no meaning and
59 should not be interpreted.
64 .. Note:: All numbers are in the machine native byte order.
66 A vhost-user message consists of 3 header fields and a payload.
68 +---------+-------+------+---------+
69 | request | flags | size | payload |
70 +---------+-------+------+---------+
75 :request: 32-bit type of the request
77 :flags: 32-bit bit field
79 - Lower 2 bits are the version (currently 0x01)
80 - Bit 2 is the reply flag - needs to be sent on each reply from the back-end
81 - Bit 3 is the need_reply flag - see :ref:`REPLY_ACK <reply_ack>` for
84 :size: 32-bit size of the payload
89 Depending on the request type, **payload** can be:
91 A single 64-bit integer
92 ^^^^^^^^^^^^^^^^^^^^^^^
98 :u64: a 64-bit unsigned integer
100 A vring state description
101 ^^^^^^^^^^^^^^^^^^^^^^^^^
107 :index: a 32-bit index
109 :num: a 32-bit number
111 A vring address description
112 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
114 +-------+-------+------+------------+------+-----------+-----+
115 | index | flags | size | descriptor | used | available | log |
116 +-------+-------+------+------------+------+-----------+-----+
118 :index: a 32-bit vring index
120 :flags: a 32-bit vring flags
122 :descriptor: a 64-bit ring address of the vring descriptor table
124 :used: a 64-bit ring address of the vring used ring
126 :available: a 64-bit ring address of the vring available ring
128 :log: a 64-bit guest address for logging
130 Note that a ring address is an IOVA if ``VIRTIO_F_IOMMU_PLATFORM`` has
131 been negotiated. Otherwise it is a user address.
133 Memory region description
134 ^^^^^^^^^^^^^^^^^^^^^^^^^
136 +---------------+------+--------------+-------------+
137 | guest address | size | user address | mmap offset |
138 +---------------+------+--------------+-------------+
140 :guest address: a 64-bit guest address of the region
144 :user address: a 64-bit user address
146 :mmap offset: 64-bit offset where region starts in the mapped memory
148 When the ``VHOST_USER_PROTOCOL_F_XEN_MMAP`` protocol feature has been
149 successfully negotiated, the memory region description contains two extra
152 +---------------+------+--------------+-------------+----------------+-------+
153 | guest address | size | user address | mmap offset | xen mmap flags | domid |
154 +---------------+------+--------------+-------------+----------------+-------+
156 :xen mmap flags: 32-bit bit field
158 - Bit 0 is set for Xen foreign memory mapping.
159 - Bit 1 is set for Xen grant memory mapping.
160 - Bit 8 is set if the memory region can not be mapped in advance, and memory
161 areas within this region must be mapped / unmapped only when required by the
162 back-end. The back-end shouldn't try to map the entire region at once, as the
163 front-end may not allow it. The back-end should rather map only the required
164 amount of memory at once and unmap it after it is used.
166 :domid: a 32-bit Xen hypervisor specific domain id.
168 Single memory region description
169 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177 A region is represented by Memory region description.
179 Multiple Memory regions description
180 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182 +-------------+---------+---------+-----+---------+
183 | num regions | padding | region0 | ... | region7 |
184 +-------------+---------+---------+-----+---------+
186 :num regions: a 32-bit number of regions
190 A region is represented by Memory region description.
195 +----------+------------+
196 | log size | log offset |
197 +----------+------------+
199 :log size: size of area used for logging
201 :log offset: offset from start of supplied file descriptor where
202 logging starts (i.e. where guest address 0 would be
208 +------+------+--------------+-------------------+------+
209 | iova | size | user address | permissions flags | type |
210 +------+------+--------------+-------------------+------+
212 :iova: a 64-bit I/O virtual address programmed by the guest
216 :user address: a 64-bit user address
218 :permissions flags: an 8-bit value:
222 - 3: Read/Write access
224 :type: an 8-bit IOTLB message type:
227 - 3: IOTLB invalidate
228 - 4: IOTLB access fail
230 Virtio device config space
231 ^^^^^^^^^^^^^^^^^^^^^^^^^^
233 +--------+------+-------+---------+
234 | offset | size | flags | payload |
235 +--------+------+-------+---------+
237 :offset: a 32-bit offset of virtio device's configuration space
239 :size: a 32-bit configuration space access size in bytes
241 :flags: a 32-bit value:
242 - 0: Vhost front-end messages used for writable fields
243 - 1: Vhost front-end messages used for live migration
245 :payload: Size bytes array holding the contents of the virtio
246 device's configuration space
248 Vring area description
249 ^^^^^^^^^^^^^^^^^^^^^^
251 +-----+------+--------+
252 | u64 | size | offset |
253 +-----+------+--------+
255 :u64: a 64-bit integer contains vring index and flags
257 :size: a 64-bit size of this area
259 :offset: a 64-bit offset of this area from the start of the
260 supplied file descriptor
265 +-----------+-------------+------------+------------+
266 | mmap size | mmap offset | num queues | queue size |
267 +-----------+-------------+------------+------------+
269 :mmap size: a 64-bit size of area to track inflight I/O
271 :mmap offset: a 64-bit offset of this area from the start
272 of the supplied file descriptor
274 :num queues: a 16-bit number of virtqueues
276 :queue size: a 16-bit size of virtqueues
285 :UUID: 16 bytes UUID, whose first three components (a 32-bit value, then
286 two 16-bit values) are stored in big endian.
291 In QEMU the vhost-user message is implemented with the following struct:
295 typedef struct VhostUserMsg {
296 VhostUserRequest request;
301 struct vhost_vring_state state;
302 struct vhost_vring_addr addr;
303 VhostUserMemory memory;
305 struct vhost_iotlb_msg iotlb;
306 VhostUserConfig config;
307 VhostUserVringArea area;
308 VhostUserInflight inflight;
310 } QEMU_PACKED VhostUserMsg;
315 The protocol for vhost-user is based on the existing implementation of
316 vhost for the Linux Kernel. Most messages that can be sent via the
317 Unix domain socket implementing vhost-user have an equivalent ioctl to
318 the kernel implementation.
320 The communication consists of the *front-end* sending message requests and
321 the *back-end* sending message replies. Most of the requests don't require
322 replies. Here is a list of the ones that do:
324 * ``VHOST_USER_GET_FEATURES``
325 * ``VHOST_USER_GET_PROTOCOL_FEATURES``
326 * ``VHOST_USER_GET_VRING_BASE``
327 * ``VHOST_USER_SET_LOG_BASE`` (if ``VHOST_USER_PROTOCOL_F_LOG_SHMFD``)
328 * ``VHOST_USER_GET_INFLIGHT_FD`` (if ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD``)
332 :ref:`REPLY_ACK <reply_ack>`
333 The section on ``REPLY_ACK`` protocol extension.
335 There are several messages that the front-end sends with file descriptors passed
336 in the ancillary data:
338 * ``VHOST_USER_ADD_MEM_REG``
339 * ``VHOST_USER_SET_MEM_TABLE``
340 * ``VHOST_USER_SET_LOG_BASE`` (if ``VHOST_USER_PROTOCOL_F_LOG_SHMFD``)
341 * ``VHOST_USER_SET_LOG_FD``
342 * ``VHOST_USER_SET_VRING_KICK``
343 * ``VHOST_USER_SET_VRING_CALL``
344 * ``VHOST_USER_SET_VRING_ERR``
345 * ``VHOST_USER_SET_BACKEND_REQ_FD`` (previous name ``VHOST_USER_SET_SLAVE_REQ_FD``)
346 * ``VHOST_USER_SET_INFLIGHT_FD`` (if ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD``)
348 If *front-end* is unable to send the full message or receives a wrong
349 reply it will close the connection. An optional reconnection mechanism
352 If *back-end* detects some error such as incompatible features, it may also
353 close the connection. This should only happen in exceptional circumstances.
355 Any protocol extensions are gated by protocol feature bits, which
356 allows full backwards compatibility on both front-end and back-end. As
357 older back-ends don't support negotiating protocol features, a feature
358 bit was dedicated for this purpose::
360 #define VHOST_USER_F_PROTOCOL_FEATURES 30
362 Note that VHOST_USER_F_PROTOCOL_FEATURES is the UNUSED (30) feature
363 bit defined in `VIRTIO 1.1 6.3 Legacy Interface: Reserved Feature Bits
364 <https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1-4130003>`_.
365 VIRTIO devices do not advertise this feature bit and therefore VIRTIO
366 drivers cannot negotiate it.
368 This reserved feature bit was reused by the vhost-user protocol to add
369 vhost-user protocol feature negotiation in a backwards compatible
370 fashion. Old vhost-user front-end and back-end implementations continue to
371 work even though they are not aware of vhost-user protocol feature
377 Rings can be in one of three states:
379 * stopped: the back-end must not process the ring at all.
381 * started but disabled: the back-end must process the ring without
382 causing any side effects. For example, for a networking device,
383 in the disabled state the back-end must not supply any new RX packets,
384 but must process and discard any TX packets.
386 * started and enabled.
388 Each ring is initialized in a stopped state. The back-end must start
389 ring upon receiving a kick (that is, detecting that file descriptor is
390 readable) on the descriptor specified by ``VHOST_USER_SET_VRING_KICK``
391 or receiving the in-band message ``VHOST_USER_VRING_KICK`` if negotiated,
392 and stop ring upon receiving ``VHOST_USER_GET_VRING_BASE``.
394 Rings can be enabled or disabled by ``VHOST_USER_SET_VRING_ENABLE``.
396 If ``VHOST_USER_F_PROTOCOL_FEATURES`` has not been negotiated, the
397 ring starts directly in the enabled state.
399 If ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, the ring is
400 initialized in a disabled state and is enabled by
401 ``VHOST_USER_SET_VRING_ENABLE`` with parameter 1.
403 While processing the rings (whether they are enabled or not), the back-end
404 must support changing some configuration aspects on the fly.
406 Multiple queue support
407 ----------------------
409 Many devices have a fixed number of virtqueues. In this case the front-end
410 already knows the number of available virtqueues without communicating with the
413 Some devices do not have a fixed number of virtqueues. Instead the maximum
414 number of virtqueues is chosen by the back-end. The number can depend on host
415 resource availability or back-end implementation details. Such devices are called
416 multiple queue devices.
418 Multiple queue support allows the back-end to advertise the maximum number of
419 queues. This is treated as a protocol extension, hence the back-end has to
420 implement protocol features first. The multiple queues feature is supported
421 only when the protocol feature ``VHOST_USER_PROTOCOL_F_MQ`` (bit 0) is set.
423 The max number of queues the back-end supports can be queried with message
424 ``VHOST_USER_GET_QUEUE_NUM``. Front-end should stop when the number of requested
425 queues is bigger than that.
427 As all queues share one connection, the front-end uses a unique index for each
428 queue in the sent message to identify a specified queue.
430 The front-end enables queues by sending message ``VHOST_USER_SET_VRING_ENABLE``.
431 vhost-user-net has historically automatically enabled the first queue pair.
433 Back-ends should always implement the ``VHOST_USER_PROTOCOL_F_MQ`` protocol
434 feature, even for devices with a fixed number of virtqueues, since it is simple
435 to implement and offers a degree of introspection.
437 Front-ends must not rely on the ``VHOST_USER_PROTOCOL_F_MQ`` protocol feature for
438 devices with a fixed number of virtqueues. Only true multiqueue devices
439 require this protocol feature.
444 During live migration, the front-end may need to track the modifications
445 the back-end makes to the memory mapped regions. The front-end should mark
446 the dirty pages in a log. Once it complies to this logging, it may
447 declare the ``VHOST_F_LOG_ALL`` vhost feature.
449 To start/stop logging of data/used ring writes, the front-end may send
450 messages ``VHOST_USER_SET_FEATURES`` with ``VHOST_F_LOG_ALL`` and
451 ``VHOST_USER_SET_VRING_ADDR`` with ``VHOST_VRING_F_LOG`` in ring's
452 flags set to 1/0, respectively.
454 All the modifications to memory pointed by vring "descriptor" should
455 be marked. Modifications to "used" vring should be marked if
456 ``VHOST_VRING_F_LOG`` is part of ring's flags.
458 Dirty pages are of size::
460 #define VHOST_LOG_PAGE 0x1000
462 The log memory fd is provided in the ancillary data of
463 ``VHOST_USER_SET_LOG_BASE`` message when the back-end has
464 ``VHOST_USER_PROTOCOL_F_LOG_SHMFD`` protocol feature.
466 The size of the log is supplied as part of ``VhostUserMsg`` which
467 should be large enough to cover all known guest addresses. Log starts
468 at the supplied offset in the supplied file descriptor. The log
469 covers from address 0 to the maximum of guest regions. In pseudo-code,
470 to mark page at ``addr`` as dirty::
472 page = addr / VHOST_LOG_PAGE
473 log[page / 8] |= 1 << page % 8
475 Where ``addr`` is the guest physical address.
477 Use atomic operations, as the log may be concurrently manipulated.
479 Note that when logging modifications to the used ring (when
480 ``VHOST_VRING_F_LOG`` is set for this ring), ``log_guest_addr`` should
481 be used to calculate the log offset: the write to first byte of the
482 used ring is logged at this offset from log start. Also note that this
483 value might be outside the legal guest physical address range
484 (i.e. does not have to be covered by the ``VhostUserMemory`` table), but
485 the bit offset of the last byte of the ring must fall within the size
486 supplied by ``VhostUserLog``.
488 ``VHOST_USER_SET_LOG_FD`` is an optional message with an eventfd in
489 ancillary data, it may be used to inform the front-end that the log has
492 Once the source has finished migration, rings will be stopped by the
493 source. No further update must be done before rings are restarted.
495 In postcopy migration the back-end is started before all the memory has
496 been received from the source host, and care must be taken to avoid
497 accessing pages that have yet to be received. The back-end opens a
498 'userfault'-fd and registers the memory with it; this fd is then
499 passed back over to the front-end. The front-end services requests on the
500 userfaultfd for pages that are accessed and when the page is available
501 it performs WAKE ioctl's on the userfaultfd to wake the stalled
502 back-end. The front-end indicates support for this via the
503 ``VHOST_USER_PROTOCOL_F_PAGEFAULT`` feature.
508 The front-end sends a list of vhost memory regions to the back-end using the
509 ``VHOST_USER_SET_MEM_TABLE`` message. Each region has two base
510 addresses: a guest address and a user address.
512 Messages contain guest addresses and/or user addresses to reference locations
513 within the shared memory. The mapping of these addresses works as follows.
515 User addresses map to the vhost memory region containing that user address.
517 When the ``VIRTIO_F_IOMMU_PLATFORM`` feature has not been negotiated:
519 * Guest addresses map to the vhost memory region containing that guest
522 When the ``VIRTIO_F_IOMMU_PLATFORM`` feature has been negotiated:
524 * Guest addresses are also called I/O virtual addresses (IOVAs). They are
525 translated to user addresses via the IOTLB.
527 * The vhost memory region guest address is not used.
532 When the ``VIRTIO_F_IOMMU_PLATFORM`` feature has been negotiated, the
533 front-end sends IOTLB entries update & invalidation by sending
534 ``VHOST_USER_IOTLB_MSG`` requests to the back-end with a ``struct
535 vhost_iotlb_msg`` as payload. For update events, the ``iotlb`` payload
536 has to be filled with the update message type (2), the I/O virtual
537 address, the size, the user virtual address, and the permissions
538 flags. Addresses and size must be within vhost memory regions set via
539 the ``VHOST_USER_SET_MEM_TABLE`` request. For invalidation events, the
540 ``iotlb`` payload has to be filled with the invalidation message type
541 (3), the I/O virtual address and the size. On success, the back-end is
542 expected to reply with a zero payload, non-zero otherwise.
544 The back-end relies on the back-end communication channel (see :ref:`Back-end
545 communication <backend_communication>` section below) to send IOTLB miss
546 and access failure events, by sending ``VHOST_USER_BACKEND_IOTLB_MSG``
547 requests to the front-end with a ``struct vhost_iotlb_msg`` as
548 payload. For miss events, the iotlb payload has to be filled with the
549 miss message type (1), the I/O virtual address and the permissions
550 flags. For access failure event, the iotlb payload has to be filled
551 with the access failure message type (4), the I/O virtual address and
552 the permissions flags. For synchronization purpose, the back-end may
553 rely on the reply-ack feature, so the front-end may send a reply when
554 operation is completed if the reply-ack feature is negotiated and
555 back-ends requests a reply. For miss events, completed operation means
556 either front-end sent an update message containing the IOTLB entry
557 containing requested address and permission, or front-end sent nothing if
558 the IOTLB miss message is invalid (invalid IOVA or permission).
560 The front-end isn't expected to take the initiative to send IOTLB update
561 messages, as the back-end sends IOTLB miss messages for the guest virtual
562 memory areas it needs to access.
564 .. _backend_communication:
566 Back-end communication
567 ----------------------
569 An optional communication channel is provided if the back-end declares
570 ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` protocol feature, to allow the
571 back-end to make requests to the front-end.
573 The fd is provided via ``VHOST_USER_SET_BACKEND_REQ_FD`` ancillary data.
575 A back-end may then send ``VHOST_USER_BACKEND_*`` messages to the front-end
576 using this fd communication channel.
578 If ``VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD`` protocol feature is
579 negotiated, back-end can send file descriptors (at most 8 descriptors in
580 each message) to front-end via ancillary data using this fd communication
583 Inflight I/O tracking
584 ---------------------
586 To support reconnecting after restart or crash, back-end may need to
587 resubmit inflight I/Os. If virtqueue is processed in order, we can
588 easily achieve that by getting the inflight descriptors from
589 descriptor table (split virtqueue) or descriptor ring (packed
590 virtqueue). However, it can't work when we process descriptors
591 out-of-order because some entries which store the information of
592 inflight descriptors in available ring (split virtqueue) or descriptor
593 ring (packed virtqueue) might be overridden by new entries. To solve
594 this problem, the back-end need to allocate an extra buffer to store this
595 information of inflight descriptors and share it with front-end for
596 persistent. ``VHOST_USER_GET_INFLIGHT_FD`` and
597 ``VHOST_USER_SET_INFLIGHT_FD`` are used to transfer this buffer
598 between front-end and back-end. And the format of this buffer is described
601 +---------------+---------------+-----+---------------+
602 | queue0 region | queue1 region | ... | queueN region |
603 +---------------+---------------+-----+---------------+
605 N is the number of available virtqueues. The back-end could get it from num
606 queues field of ``VhostUserInflight``.
608 For split virtqueue, queue region can be implemented as:
612 typedef struct DescStateSplit {
613 /* Indicate whether this descriptor is inflight or not.
614 * Only available for head-descriptor. */
620 /* Maintain a list for the last batch of used descriptors.
621 * Only available when batching is used for submitting */
624 /* Used to preserve the order of fetching available descriptors.
625 * Only available for head-descriptor. */
629 typedef struct QueueRegionSplit {
630 /* The feature flags of this region. Now it's initialized to 0. */
633 /* The version of this region. It's 1 currently.
634 * Zero value indicates an uninitialized buffer */
637 /* The size of DescStateSplit array. It's equal to the virtqueue size.
638 * The back-end could get it from queue size field of VhostUserInflight. */
641 /* The head of list that track the last batch of used descriptors. */
642 uint16_t last_batch_head;
644 /* Store the idx value of used ring */
647 /* Used to track the state of each descriptor in descriptor table */
648 DescStateSplit desc[];
651 To track inflight I/O, the queue region should be processed as follows:
653 When receiving available buffers from the driver:
655 #. Get the next available head-descriptor index from available ring, ``i``
657 #. Set ``desc[i].counter`` to the value of global counter
659 #. Increase global counter by 1
661 #. Set ``desc[i].inflight`` to 1
663 When supplying used buffers to the driver:
665 1. Get corresponding used head-descriptor index, i
667 2. Set ``desc[i].next`` to ``last_batch_head``
669 3. Set ``last_batch_head`` to ``i``
671 #. Steps 1,2,3 may be performed repeatedly if batching is possible
673 #. Increase the ``idx`` value of used ring by the size of the batch
675 #. Set the ``inflight`` field of each ``DescStateSplit`` entry in the batch to 0
677 #. Set ``used_idx`` to the ``idx`` value of used ring
681 #. If the value of ``used_idx`` does not match the ``idx`` value of
682 used ring (means the inflight field of ``DescStateSplit`` entries in
683 last batch may be incorrect),
685 a. Subtract the value of ``used_idx`` from the ``idx`` value of
686 used ring to get last batch size of ``DescStateSplit`` entries
688 #. Set the ``inflight`` field of each ``DescStateSplit`` entry to 0 in last batch
689 list which starts from ``last_batch_head``
691 #. Set ``used_idx`` to the ``idx`` value of used ring
693 #. Resubmit inflight ``DescStateSplit`` entries in order of their
696 For packed virtqueue, queue region can be implemented as:
700 typedef struct DescStatePacked {
701 /* Indicate whether this descriptor is inflight or not.
702 * Only available for head-descriptor. */
708 /* Link to the next free entry */
711 /* Link to the last entry of descriptor list.
712 * Only available for head-descriptor. */
715 /* The length of descriptor list.
716 * Only available for head-descriptor. */
719 /* Used to preserve the order of fetching available descriptors.
720 * Only available for head-descriptor. */
726 /* The descriptor flags */
729 /* The buffer length */
732 /* The buffer address */
736 typedef struct QueueRegionPacked {
737 /* The feature flags of this region. Now it's initialized to 0. */
740 /* The version of this region. It's 1 currently.
741 * Zero value indicates an uninitialized buffer */
744 /* The size of DescStatePacked array. It's equal to the virtqueue size.
745 * The back-end could get it from queue size field of VhostUserInflight. */
748 /* The head of free DescStatePacked entry list */
751 /* The old head of free DescStatePacked entry list */
752 uint16_t old_free_head;
754 /* The used index of descriptor ring */
757 /* The old used index of descriptor ring */
758 uint16_t old_used_idx;
760 /* Device ring wrap counter */
761 uint8_t used_wrap_counter;
763 /* The old device ring wrap counter */
764 uint8_t old_used_wrap_counter;
769 /* Used to track the state of each descriptor fetched from descriptor ring */
770 DescStatePacked desc[];
773 To track inflight I/O, the queue region should be processed as follows:
775 When receiving available buffers from the driver:
777 #. Get the next available descriptor entry from descriptor ring, ``d``
779 #. If ``d`` is head descriptor,
781 a. Set ``desc[old_free_head].num`` to 0
783 #. Set ``desc[old_free_head].counter`` to the value of global counter
785 #. Increase global counter by 1
787 #. Set ``desc[old_free_head].inflight`` to 1
789 #. If ``d`` is last descriptor, set ``desc[old_free_head].last`` to
792 #. Increase ``desc[old_free_head].num`` by 1
794 #. Set ``desc[free_head].addr``, ``desc[free_head].len``,
795 ``desc[free_head].flags``, ``desc[free_head].id`` to ``d.addr``,
796 ``d.len``, ``d.flags``, ``d.id``
798 #. Set ``free_head`` to ``desc[free_head].next``
800 #. If ``d`` is last descriptor, set ``old_free_head`` to ``free_head``
802 When supplying used buffers to the driver:
804 1. Get corresponding used head-descriptor entry from descriptor ring,
807 2. Get corresponding ``DescStatePacked`` entry, ``e``
809 3. Set ``desc[e.last].next`` to ``free_head``
811 4. Set ``free_head`` to the index of ``e``
813 #. Steps 1,2,3,4 may be performed repeatedly if batching is possible
815 #. Increase ``used_idx`` by the size of the batch and update
816 ``used_wrap_counter`` if needed
818 #. Update ``d.flags``
820 #. Set the ``inflight`` field of each head ``DescStatePacked`` entry
823 #. Set ``old_free_head``, ``old_used_idx``, ``old_used_wrap_counter``
824 to ``free_head``, ``used_idx``, ``used_wrap_counter``
828 #. If ``used_idx`` does not match ``old_used_idx`` (means the
829 ``inflight`` field of ``DescStatePacked`` entries in last batch may
832 a. Get the next descriptor ring entry through ``old_used_idx``, ``d``
834 #. Use ``old_used_wrap_counter`` to calculate the available flags
836 #. If ``d.flags`` is not equal to the calculated flags value (means
837 back-end has submitted the buffer to guest driver before crash, so
838 it has to commit the in-progres update), set ``old_free_head``,
839 ``old_used_idx``, ``old_used_wrap_counter`` to ``free_head``,
840 ``used_idx``, ``used_wrap_counter``
842 #. Set ``free_head``, ``used_idx``, ``used_wrap_counter`` to
843 ``old_free_head``, ``old_used_idx``, ``old_used_wrap_counter``
844 (roll back any in-progress update)
846 #. Set the ``inflight`` field of each ``DescStatePacked`` entry in
849 #. Resubmit inflight ``DescStatePacked`` entries in order of their
852 In-band notifications
853 ---------------------
855 In some limited situations (e.g. for simulation) it is desirable to
856 have the kick, call and error (if used) signals done via in-band
857 messages instead of asynchronous eventfd notifications. This can be
858 done by negotiating the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS``
861 Note that due to the fact that too many messages on the sockets can
862 cause the sending application(s) to block, it is not advised to use
863 this feature unless absolutely necessary. It is also considered an
864 error to negotiate this feature without also negotiating
865 ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK``,
866 the former is necessary for getting a message channel from the back-end
867 to the front-end, while the latter needs to be used with the in-band
868 notification messages to block until they are processed, both to avoid
869 blocking later and for proper processing (at least in the simulation
870 use case.) As it has no other way of signalling this error, the back-end
871 should close the connection as a response to a
872 ``VHOST_USER_SET_PROTOCOL_FEATURES`` message that sets the in-band
873 notifications feature flag without the other two.
880 #define VHOST_USER_PROTOCOL_F_MQ 0
881 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
882 #define VHOST_USER_PROTOCOL_F_RARP 2
883 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
884 #define VHOST_USER_PROTOCOL_F_MTU 4
885 #define VHOST_USER_PROTOCOL_F_BACKEND_REQ 5
886 #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6
887 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
888 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8
889 #define VHOST_USER_PROTOCOL_F_CONFIG 9
890 #define VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD 10
891 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
892 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12
893 #define VHOST_USER_PROTOCOL_F_RESET_DEVICE 13
894 #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14
895 #define VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 15
896 #define VHOST_USER_PROTOCOL_F_STATUS 16
897 #define VHOST_USER_PROTOCOL_F_XEN_MMAP 17
898 #define VHOST_USER_PROTOCOL_F_SHARED_OBJECT 18
900 Front-end message types
901 -----------------------
903 ``VHOST_USER_GET_FEATURES``
905 :equivalent ioctl: ``VHOST_GET_FEATURES``
906 :request payload: N/A
907 :reply payload: ``u64``
909 Get from the underlying vhost implementation the features bitmask.
910 Feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` signals back-end support
911 for ``VHOST_USER_GET_PROTOCOL_FEATURES`` and
912 ``VHOST_USER_SET_PROTOCOL_FEATURES``.
914 ``VHOST_USER_SET_FEATURES``
916 :equivalent ioctl: ``VHOST_SET_FEATURES``
917 :request payload: ``u64``
920 Enable features in the underlying vhost implementation using a
921 bitmask. Feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` signals
922 back-end support for ``VHOST_USER_GET_PROTOCOL_FEATURES`` and
923 ``VHOST_USER_SET_PROTOCOL_FEATURES``.
925 ``VHOST_USER_GET_PROTOCOL_FEATURES``
927 :equivalent ioctl: ``VHOST_GET_FEATURES``
928 :request payload: N/A
929 :reply payload: ``u64``
931 Get the protocol feature bitmask from the underlying vhost
932 implementation. Only legal if feature bit
933 ``VHOST_USER_F_PROTOCOL_FEATURES`` is present in
934 ``VHOST_USER_GET_FEATURES``. It does not need to be acknowledged by
935 ``VHOST_USER_SET_FEATURES``.
938 Back-ends that report ``VHOST_USER_F_PROTOCOL_FEATURES`` must
939 support this message even before ``VHOST_USER_SET_FEATURES`` was
942 ``VHOST_USER_SET_PROTOCOL_FEATURES``
944 :equivalent ioctl: ``VHOST_SET_FEATURES``
945 :request payload: ``u64``
948 Enable protocol features in the underlying vhost implementation.
950 Only legal if feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` is present in
951 ``VHOST_USER_GET_FEATURES``. It does not need to be acknowledged by
952 ``VHOST_USER_SET_FEATURES``.
955 Back-ends that report ``VHOST_USER_F_PROTOCOL_FEATURES`` must support
956 this message even before ``VHOST_USER_SET_FEATURES`` was called.
958 ``VHOST_USER_SET_OWNER``
960 :equivalent ioctl: ``VHOST_SET_OWNER``
961 :request payload: N/A
964 Issued when a new connection is established. It marks the sender
965 as the front-end that owns of the session. This can be used on the *back-end*
966 as a "session start" flag.
968 ``VHOST_USER_RESET_OWNER``
970 :request payload: N/A
973 .. admonition:: Deprecated
975 This is no longer used. Used to be sent to request disabling all
976 rings, but some back-ends interpreted it to also discard connection
977 state (this interpretation would lead to bugs). It is recommended
978 that back-ends either ignore this message, or use it to disable all
981 ``VHOST_USER_SET_MEM_TABLE``
983 :equivalent ioctl: ``VHOST_SET_MEM_TABLE``
984 :request payload: multiple memory regions description
985 :reply payload: (postcopy only) multiple memory regions description
987 Sets the memory map regions on the back-end so it can translate the
988 vring addresses. In the ancillary data there is an array of file
989 descriptors for each memory mapped region. The size and ordering of
990 the fds matches the number and ordering of memory regions.
992 When ``VHOST_USER_POSTCOPY_LISTEN`` has been received,
993 ``SET_MEM_TABLE`` replies with the bases of the memory mapped
994 regions to the front-end. The back-end must have mmap'd the regions but
995 not yet accessed them and should not yet generate a userfault
999 ``NEED_REPLY_MASK`` is not set in this case. QEMU will then
1000 reply back to the list of mappings with an empty
1001 ``VHOST_USER_SET_MEM_TABLE`` as an acknowledgement; only upon
1002 reception of this message may the guest start accessing the memory
1003 and generating faults.
1005 ``VHOST_USER_SET_LOG_BASE``
1007 :equivalent ioctl: ``VHOST_SET_LOG_BASE``
1008 :request payload: u64
1011 Sets logging shared memory space.
1013 When the back-end has ``VHOST_USER_PROTOCOL_F_LOG_SHMFD`` protocol feature,
1014 the log memory fd is provided in the ancillary data of
1015 ``VHOST_USER_SET_LOG_BASE`` message, the size and offset of shared
1016 memory area provided in the message.
1018 ``VHOST_USER_SET_LOG_FD``
1020 :equivalent ioctl: ``VHOST_SET_LOG_FD``
1021 :request payload: N/A
1024 Sets the logging file descriptor, which is passed as ancillary data.
1026 ``VHOST_USER_SET_VRING_NUM``
1028 :equivalent ioctl: ``VHOST_SET_VRING_NUM``
1029 :request payload: vring state description
1032 Set the size of the queue.
1034 ``VHOST_USER_SET_VRING_ADDR``
1036 :equivalent ioctl: ``VHOST_SET_VRING_ADDR``
1037 :request payload: vring address description
1040 Sets the addresses of the different aspects of the vring.
1042 ``VHOST_USER_SET_VRING_BASE``
1044 :equivalent ioctl: ``VHOST_SET_VRING_BASE``
1045 :request payload: vring state description
1048 Sets the base offset in the available vring.
1050 ``VHOST_USER_GET_VRING_BASE``
1052 :equivalent ioctl: ``VHOST_USER_GET_VRING_BASE``
1053 :request payload: vring state description
1054 :reply payload: vring state description
1056 Get the available vring base offset.
1058 ``VHOST_USER_SET_VRING_KICK``
1060 :equivalent ioctl: ``VHOST_SET_VRING_KICK``
1061 :request payload: ``u64``
1064 Set the event file descriptor for adding buffers to the vring. It is
1065 passed in the ancillary data.
1067 Bits (0-7) of the payload contain the vring index. Bit 8 is the
1068 invalid FD flag. This flag is set when there is no file descriptor
1069 in the ancillary data. This signals that polling should be used
1070 instead of waiting for the kick. Note that if the protocol feature
1071 ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` has been negotiated
1072 this message isn't necessary as the ring is also started on the
1073 ``VHOST_USER_VRING_KICK`` message, it may however still be used to
1074 set an event file descriptor (which will be preferred over the
1075 message) or to enable polling.
1077 ``VHOST_USER_SET_VRING_CALL``
1079 :equivalent ioctl: ``VHOST_SET_VRING_CALL``
1080 :request payload: ``u64``
1083 Set the event file descriptor to signal when buffers are used. It is
1084 passed in the ancillary data.
1086 Bits (0-7) of the payload contain the vring index. Bit 8 is the
1087 invalid FD flag. This flag is set when there is no file descriptor
1088 in the ancillary data. This signals that polling will be used
1089 instead of waiting for the call. Note that if the protocol features
1090 ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` and
1091 ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` have been negotiated this message
1092 isn't necessary as the ``VHOST_USER_BACKEND_VRING_CALL`` message can be
1093 used, it may however still be used to set an event file descriptor
1094 or to enable polling.
1096 ``VHOST_USER_SET_VRING_ERR``
1098 :equivalent ioctl: ``VHOST_SET_VRING_ERR``
1099 :request payload: ``u64``
1102 Set the event file descriptor to signal when error occurs. It is
1103 passed in the ancillary data.
1105 Bits (0-7) of the payload contain the vring index. Bit 8 is the
1106 invalid FD flag. This flag is set when there is no file descriptor
1107 in the ancillary data. Note that if the protocol features
1108 ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` and
1109 ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` have been negotiated this message
1110 isn't necessary as the ``VHOST_USER_BACKEND_VRING_ERR`` message can be
1111 used, it may however still be used to set an event file descriptor
1112 (which will be preferred over the message).
1114 ``VHOST_USER_GET_QUEUE_NUM``
1116 :equivalent ioctl: N/A
1117 :request payload: N/A
1120 Query how many queues the back-end supports.
1122 This request should be sent only when ``VHOST_USER_PROTOCOL_F_MQ``
1123 is set in queried protocol features by
1124 ``VHOST_USER_GET_PROTOCOL_FEATURES``.
1126 ``VHOST_USER_SET_VRING_ENABLE``
1128 :equivalent ioctl: N/A
1129 :request payload: vring state description
1132 Signal the back-end to enable or disable corresponding vring.
1134 This request should be sent only when
1135 ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated.
1137 ``VHOST_USER_SEND_RARP``
1139 :equivalent ioctl: N/A
1140 :request payload: ``u64``
1143 Ask vhost user back-end to broadcast a fake RARP to notify the migration
1144 is terminated for guest that does not support GUEST_ANNOUNCE.
1146 Only legal if feature bit ``VHOST_USER_F_PROTOCOL_FEATURES`` is
1147 present in ``VHOST_USER_GET_FEATURES`` and protocol feature bit
1148 ``VHOST_USER_PROTOCOL_F_RARP`` is present in
1149 ``VHOST_USER_GET_PROTOCOL_FEATURES``. The first 6 bytes of the
1150 payload contain the mac address of the guest to allow the vhost user
1151 back-end to construct and broadcast the fake RARP.
1153 ``VHOST_USER_NET_SET_MTU``
1155 :equivalent ioctl: N/A
1156 :request payload: ``u64``
1159 Set host MTU value exposed to the guest.
1161 This request should be sent only when ``VIRTIO_NET_F_MTU`` feature
1162 has been successfully negotiated, ``VHOST_USER_F_PROTOCOL_FEATURES``
1163 is present in ``VHOST_USER_GET_FEATURES`` and protocol feature bit
1164 ``VHOST_USER_PROTOCOL_F_NET_MTU`` is present in
1165 ``VHOST_USER_GET_PROTOCOL_FEATURES``.
1167 If ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, the back-end must
1168 respond with zero in case the specified MTU is valid, or non-zero
1171 ``VHOST_USER_SET_BACKEND_REQ_FD`` (previous name ``VHOST_USER_SET_SLAVE_REQ_FD``)
1173 :equivalent ioctl: N/A
1174 :request payload: N/A
1177 Set the socket file descriptor for back-end initiated requests. It is passed
1178 in the ancillary data.
1180 This request should be sent only when
1181 ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, and protocol
1182 feature bit ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` bit is present in
1183 ``VHOST_USER_GET_PROTOCOL_FEATURES``. If
1184 ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, the back-end must
1185 respond with zero for success, non-zero otherwise.
1187 ``VHOST_USER_IOTLB_MSG``
1189 :equivalent ioctl: N/A (equivalent to ``VHOST_IOTLB_MSG`` message type)
1190 :request payload: ``struct vhost_iotlb_msg``
1191 :reply payload: ``u64``
1193 Send IOTLB messages with ``struct vhost_iotlb_msg`` as payload.
1195 The front-end sends such requests to update and invalidate entries in the
1196 device IOTLB. The back-end has to acknowledge the request with sending
1197 zero as ``u64`` payload for success, non-zero otherwise.
1199 This request should be send only when ``VIRTIO_F_IOMMU_PLATFORM``
1200 feature has been successfully negotiated.
1202 ``VHOST_USER_SET_VRING_ENDIAN``
1204 :equivalent ioctl: ``VHOST_SET_VRING_ENDIAN``
1205 :request payload: vring state description
1208 Set the endianness of a VQ for legacy devices. Little-endian is
1209 indicated with state.num set to 0 and big-endian is indicated with
1210 state.num set to 1. Other values are invalid.
1212 This request should be sent only when
1213 ``VHOST_USER_PROTOCOL_F_CROSS_ENDIAN`` has been negotiated.
1214 Backends that negotiated this feature should handle both
1215 endiannesses and expect this message once (per VQ) during device
1216 configuration (ie. before the front-end starts the VQ).
1218 ``VHOST_USER_GET_CONFIG``
1220 :equivalent ioctl: N/A
1221 :request payload: virtio device config space
1222 :reply payload: virtio device config space
1224 When ``VHOST_USER_PROTOCOL_F_CONFIG`` is negotiated, this message is
1225 submitted by the vhost-user front-end to fetch the contents of the
1226 virtio device configuration space, vhost-user back-end's payload size
1227 MUST match the front-end's request, vhost-user back-end uses zero length of
1228 payload to indicate an error to the vhost-user front-end. The vhost-user
1229 front-end may cache the contents to avoid repeated
1230 ``VHOST_USER_GET_CONFIG`` calls.
1232 ``VHOST_USER_SET_CONFIG``
1234 :equivalent ioctl: N/A
1235 :request payload: virtio device config space
1238 When ``VHOST_USER_PROTOCOL_F_CONFIG`` is negotiated, this message is
1239 submitted by the vhost-user front-end when the Guest changes the virtio
1240 device configuration space and also can be used for live migration
1241 on the destination host. The vhost-user back-end must check the flags
1242 field, and back-ends MUST NOT accept SET_CONFIG for read-only
1243 configuration space fields unless the live migration bit is set.
1245 ``VHOST_USER_CREATE_CRYPTO_SESSION``
1247 :equivalent ioctl: N/A
1248 :request payload: crypto session description
1249 :reply payload: crypto session description
1251 Create a session for crypto operation. The back-end must return
1252 the session id, 0 or positive for success, negative for failure.
1253 This request should be sent only when
1254 ``VHOST_USER_PROTOCOL_F_CRYPTO_SESSION`` feature has been
1255 successfully negotiated. It's a required feature for crypto
1258 ``VHOST_USER_CLOSE_CRYPTO_SESSION``
1260 :equivalent ioctl: N/A
1261 :request payload: ``u64``
1264 Close a session for crypto operation which was previously
1265 created by ``VHOST_USER_CREATE_CRYPTO_SESSION``.
1267 This request should be sent only when
1268 ``VHOST_USER_PROTOCOL_F_CRYPTO_SESSION`` feature has been
1269 successfully negotiated. It's a required feature for crypto
1272 ``VHOST_USER_POSTCOPY_ADVISE``
1274 :request payload: N/A
1275 :reply payload: userfault fd
1277 When ``VHOST_USER_PROTOCOL_F_PAGEFAULT`` is supported, the front-end
1278 advises back-end that a migration with postcopy enabled is underway,
1279 the back-end must open a userfaultfd for later use. Note that at this
1280 stage the migration is still in precopy mode.
1282 ``VHOST_USER_POSTCOPY_LISTEN``
1284 :request payload: N/A
1287 The front-end advises back-end that a transition to postcopy mode has
1288 happened. The back-end must ensure that shared memory is registered
1289 with userfaultfd to cause faulting of non-present pages.
1291 This is always sent sometime after a ``VHOST_USER_POSTCOPY_ADVISE``,
1292 and thus only when ``VHOST_USER_PROTOCOL_F_PAGEFAULT`` is supported.
1294 ``VHOST_USER_POSTCOPY_END``
1296 :request payload: N/A
1297 :reply payload: ``u64``
1299 The front-end advises that postcopy migration has now completed. The back-end
1300 must disable the userfaultfd. The reply is an acknowledgement
1303 When ``VHOST_USER_PROTOCOL_F_PAGEFAULT`` is supported, this message
1304 is sent at the end of the migration, after
1305 ``VHOST_USER_POSTCOPY_LISTEN`` was previously sent.
1307 The value returned is an error indication; 0 is success.
1309 ``VHOST_USER_GET_INFLIGHT_FD``
1311 :equivalent ioctl: N/A
1312 :request payload: inflight description
1315 When ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD`` protocol feature has
1316 been successfully negotiated, this message is submitted by the front-end to
1317 get a shared buffer from back-end. The shared buffer will be used to
1318 track inflight I/O by back-end. QEMU should retrieve a new one when vm
1321 ``VHOST_USER_SET_INFLIGHT_FD``
1323 :equivalent ioctl: N/A
1324 :request payload: inflight description
1327 When ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD`` protocol feature has
1328 been successfully negotiated, this message is submitted by the front-end to
1329 send the shared inflight buffer back to the back-end so that the back-end
1330 could get inflight I/O after a crash or restart.
1332 ``VHOST_USER_GPU_SET_SOCKET``
1334 :equivalent ioctl: N/A
1335 :request payload: N/A
1338 Sets the GPU protocol socket file descriptor, which is passed as
1339 ancillary data. The GPU protocol is used to inform the front-end of
1340 rendering state and updates. See vhost-user-gpu.rst for details.
1342 ``VHOST_USER_RESET_DEVICE``
1344 :equivalent ioctl: N/A
1345 :request payload: N/A
1348 Ask the vhost user back-end to disable all rings and reset all
1349 internal device state to the initial state, ready to be
1350 reinitialized. The back-end retains ownership of the device
1351 throughout the reset operation.
1353 Only valid if the ``VHOST_USER_PROTOCOL_F_RESET_DEVICE`` protocol
1354 feature is set by the back-end.
1356 ``VHOST_USER_VRING_KICK``
1358 :equivalent ioctl: N/A
1359 :request payload: vring state description
1362 When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol
1363 feature has been successfully negotiated, this message may be
1364 submitted by the front-end to indicate that a buffer was added to
1365 the vring instead of signalling it using the vring's kick file
1366 descriptor or having the back-end rely on polling.
1368 The state.num field is currently reserved and must be set to 0.
1370 ``VHOST_USER_GET_MAX_MEM_SLOTS``
1372 :equivalent ioctl: N/A
1373 :request payload: N/A
1376 When the ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol
1377 feature has been successfully negotiated, this message is submitted
1378 by the front-end to the back-end. The back-end should return the message with a
1379 u64 payload containing the maximum number of memory slots for
1380 QEMU to expose to the guest. The value returned by the back-end
1381 will be capped at the maximum number of ram slots which can be
1382 supported by the target platform.
1384 ``VHOST_USER_ADD_MEM_REG``
1386 :equivalent ioctl: N/A
1387 :request payload: N/A
1388 :reply payload: single memory region description
1390 When the ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol
1391 feature has been successfully negotiated, this message is submitted
1392 by the front-end to the back-end. The message payload contains a memory
1393 region descriptor struct, describing a region of guest memory which
1394 the back-end device must map in. When the
1395 ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol feature has
1396 been successfully negotiated, along with the
1397 ``VHOST_USER_REM_MEM_REG`` message, this message is used to set and
1398 update the memory tables of the back-end device.
1400 Exactly one file descriptor from which the memory is mapped is
1401 passed in the ancillary data.
1403 In postcopy mode (see ``VHOST_USER_POSTCOPY_LISTEN``), the back-end
1404 replies with the bases of the memory mapped region to the front-end.
1405 For further details on postcopy, see ``VHOST_USER_SET_MEM_TABLE``.
1406 They apply to ``VHOST_USER_ADD_MEM_REG`` accordingly.
1408 ``VHOST_USER_REM_MEM_REG``
1410 :equivalent ioctl: N/A
1411 :request payload: N/A
1412 :reply payload: single memory region description
1414 When the ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol
1415 feature has been successfully negotiated, this message is submitted
1416 by the front-end to the back-end. The message payload contains a memory
1417 region descriptor struct, describing a region of guest memory which
1418 the back-end device must unmap. When the
1419 ``VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS`` protocol feature has
1420 been successfully negotiated, along with the
1421 ``VHOST_USER_ADD_MEM_REG`` message, this message is used to set and
1422 update the memory tables of the back-end device.
1424 The memory region to be removed is identified by its guest address,
1425 user address and size. The mmap offset is ignored.
1427 No file descriptors SHOULD be passed in the ancillary data. For
1428 compatibility with existing incorrect implementations, the back-end MAY
1429 accept messages with one file descriptor. If a file descriptor is
1430 passed, the back-end MUST close it without using it otherwise.
1432 ``VHOST_USER_SET_STATUS``
1434 :equivalent ioctl: VHOST_VDPA_SET_STATUS
1435 :request payload: ``u64``
1438 When the ``VHOST_USER_PROTOCOL_F_STATUS`` protocol feature has been
1439 successfully negotiated, this message is submitted by the front-end to
1440 notify the back-end with updated device status as defined in the Virtio
1443 ``VHOST_USER_GET_STATUS``
1445 :equivalent ioctl: VHOST_VDPA_GET_STATUS
1446 :request payload: N/A
1447 :reply payload: ``u64``
1449 When the ``VHOST_USER_PROTOCOL_F_STATUS`` protocol feature has been
1450 successfully negotiated, this message is submitted by the front-end to
1451 query the back-end for its device status as defined in the Virtio
1454 ``VHOST_USER_GET_SHARED_OBJECT``
1456 :equivalent ioctl: N/A
1457 :request payload: ``struct VhostUserShared``
1458 :reply payload: dmabuf fd
1460 When the ``VHOST_USER_PROTOCOL_F_SHARED_OBJECT`` protocol
1461 feature has been successfully negotiated, and the UUID is found
1462 in the exporters cache, this message is submitted by the front-end
1463 to retrieve a given dma-buf fd from a given back-end, determined by
1464 the requested UUID. Back-end will reply passing the fd when the operation
1465 is successful, or no fd otherwise.
1467 Back-end message types
1468 ----------------------
1470 For this type of message, the request is sent by the back-end and the reply
1471 is sent by the front-end.
1473 ``VHOST_USER_BACKEND_IOTLB_MSG`` (previous name ``VHOST_USER_SLAVE_IOTLB_MSG``)
1475 :equivalent ioctl: N/A (equivalent to ``VHOST_IOTLB_MSG`` message type)
1476 :request payload: ``struct vhost_iotlb_msg``
1479 Send IOTLB messages with ``struct vhost_iotlb_msg`` as payload.
1480 The back-end sends such requests to notify of an IOTLB miss, or an IOTLB
1481 access failure. If ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is
1482 negotiated, and back-end set the ``VHOST_USER_NEED_REPLY`` flag, the front-end
1483 must respond with zero when operation is successfully completed, or
1484 non-zero otherwise. This request should be send only when
1485 ``VIRTIO_F_IOMMU_PLATFORM`` feature has been successfully
1488 ``VHOST_USER_BACKEND_CONFIG_CHANGE_MSG`` (previous name ``VHOST_USER_SLAVE_CONFIG_CHANGE_MSG``)
1490 :equivalent ioctl: N/A
1491 :request payload: N/A
1494 When ``VHOST_USER_PROTOCOL_F_CONFIG`` is negotiated, vhost-user
1495 back-end sends such messages to notify that the virtio device's
1496 configuration space has changed, for those host devices which can
1497 support such feature, host driver can send ``VHOST_USER_GET_CONFIG``
1498 message to the back-end to get the latest content. If
1499 ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, and the back-end sets the
1500 ``VHOST_USER_NEED_REPLY`` flag, the front-end must respond with zero when
1501 operation is successfully completed, or non-zero otherwise.
1503 ``VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG`` (previous name ``VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG``)
1505 :equivalent ioctl: N/A
1506 :request payload: vring area description
1509 Sets host notifier for a specified queue. The queue index is
1510 contained in the ``u64`` field of the vring area description. The
1511 host notifier is described by the file descriptor (typically it's a
1512 VFIO device fd) which is passed as ancillary data and the size
1513 (which is mmap size and should be the same as host page size) and
1514 offset (which is mmap offset) carried in the vring area
1515 description. QEMU can mmap the file descriptor based on the size and
1516 offset to get a memory range. Registering a host notifier means
1517 mapping this memory range to the VM as the specified queue's notify
1518 MMIO region. The back-end sends this request to tell QEMU to de-register
1519 the existing notifier if any and register the new notifier if the
1520 request is sent with a file descriptor.
1522 This request should be sent only when
1523 ``VHOST_USER_PROTOCOL_F_HOST_NOTIFIER`` protocol feature has been
1524 successfully negotiated.
1526 ``VHOST_USER_BACKEND_VRING_CALL`` (previous name ``VHOST_USER_SLAVE_VRING_CALL``)
1528 :equivalent ioctl: N/A
1529 :request payload: vring state description
1532 When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol
1533 feature has been successfully negotiated, this message may be
1534 submitted by the back-end to indicate that a buffer was used from
1535 the vring instead of signalling this using the vring's call file
1536 descriptor or having the front-end relying on polling.
1538 The state.num field is currently reserved and must be set to 0.
1540 ``VHOST_USER_BACKEND_VRING_ERR`` (previous name ``VHOST_USER_SLAVE_VRING_ERR``)
1542 :equivalent ioctl: N/A
1543 :request payload: vring state description
1546 When the ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` protocol
1547 feature has been successfully negotiated, this message may be
1548 submitted by the back-end to indicate that an error occurred on the
1549 specific vring, instead of signalling the error file descriptor
1550 set by the front-end via ``VHOST_USER_SET_VRING_ERR``.
1552 The state.num field is currently reserved and must be set to 0.
1554 ``VHOST_USER_BACKEND_SHARED_OBJECT_ADD``
1556 :equivalent ioctl: N/A
1557 :request payload: ``struct VhostUserShared``
1560 When the ``VHOST_USER_PROTOCOL_F_SHARED_OBJECT`` protocol
1561 feature has been successfully negotiated, this message can be submitted
1562 by the backends to add themselves as exporters to the virtio shared lookup
1563 table. The back-end device gets associated with a UUID in the shared table.
1564 The back-end is responsible of keeping its own table with exported dma-buf fds.
1565 When another back-end tries to import the resource associated with the UUID,
1566 it will send a message to the front-end, which will act as a proxy to the
1567 exporter back-end. If ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, and
1568 the back-end sets the ``VHOST_USER_NEED_REPLY`` flag, the front-end must
1569 respond with zero when operation is successfully completed, or non-zero
1572 ``VHOST_USER_BACKEND_SHARED_OBJECT_REMOVE``
1574 :equivalent ioctl: N/A
1575 :request payload: ``struct VhostUserShared``
1578 When the ``VHOST_USER_PROTOCOL_F_SHARED_OBJECT`` protocol
1579 feature has been successfully negotiated, this message can be submitted
1580 by the backend to remove themselves from to the virtio-dmabuf shared
1581 table API. The shared table will remove the back-end device associated with
1582 the UUID. If ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, and the
1583 back-end sets the ``VHOST_USER_NEED_REPLY`` flag, the front-end must respond
1584 with zero when operation is successfully completed, or non-zero otherwise.
1586 ``VHOST_USER_BACKEND_SHARED_OBJECT_LOOKUP``
1588 :equivalent ioctl: N/A
1589 :request payload: ``struct VhostUserShared``
1590 :reply payload: dmabuf fd and ``u64``
1592 When the ``VHOST_USER_PROTOCOL_F_SHARED_OBJECT`` protocol
1593 feature has been successfully negotiated, this message can be submitted
1594 by the backends to retrieve a given dma-buf fd from the virtio-dmabuf
1595 shared table given a UUID. Frontend will reply passing the fd and a zero
1596 when the operation is successful, or non-zero otherwise. Note that if the
1597 operation fails, no fd is sent to the backend.
1601 VHOST_USER_PROTOCOL_F_REPLY_ACK
1602 -------------------------------
1604 The original vhost-user specification only demands replies for certain
1605 commands. This differs from the vhost protocol implementation where
1606 commands are sent over an ``ioctl()`` call and block until the back-end
1609 With this protocol extension negotiated, the sender (QEMU) can set the
1610 ``need_reply`` [Bit 3] flag to any command. This indicates that the
1611 back-end MUST respond with a Payload ``VhostUserMsg`` indicating success
1612 or failure. The payload should be set to zero on success or non-zero
1613 on failure, unless the message already has an explicit reply body.
1615 The reply payload gives QEMU a deterministic indication of the result
1616 of the command. Today, QEMU is expected to terminate the main vhost-user
1617 loop upon receiving such errors. In future, qemu could be taught to be more
1618 resilient for selective requests.
1620 For the message types that already solicit a reply from the back-end,
1621 the presence of ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` or need_reply bit
1622 being set brings no behavioural change. (See the Communication_
1623 section for details.)
1625 .. _backend_conventions:
1627 Backend program conventions
1628 ===========================
1630 vhost-user back-ends can provide various devices & services and may
1631 need to be configured manually depending on the use case. However, it
1632 is a good idea to follow the conventions listed here when
1633 possible. Users, QEMU or libvirt, can then rely on some common
1634 behaviour to avoid heterogeneous configuration and management of the
1635 back-end programs and facilitate interoperability.
1637 Each back-end installed on a host system should come with at least one
1638 JSON file that conforms to the vhost-user.json schema. Each file
1639 informs the management applications about the back-end type, and binary
1640 location. In addition, it defines rules for management apps for
1641 picking the highest priority back-end when multiple match the search
1642 criteria (see ``@VhostUserBackend`` documentation in the schema file).
1644 If the back-end is not capable of enabling a requested feature on the
1645 host (such as 3D acceleration with virgl), or the initialization
1646 failed, the back-end should fail to start early and exit with a status
1647 != 0. It may also print a message to stderr for further details.
1649 The back-end program must not daemonize itself, but it may be
1650 daemonized by the management layer. It may also have a restricted
1651 access to the system.
1653 File descriptors 0, 1 and 2 will exist, and have regular
1654 stdin/stdout/stderr usage (they may have been redirected to /dev/null
1655 by the management layer, or to a log handler).
1657 The back-end program must end (as quickly and cleanly as possible) when
1658 the SIGTERM signal is received. Eventually, it may receive SIGKILL by
1659 the management layer after a few seconds.
1661 The following command line options have an expected behaviour. They
1662 are mandatory, unless explicitly said differently:
1666 This option specify the location of the vhost-user Unix domain socket.
1667 It is incompatible with --fd.
1671 When this argument is given, the back-end program is started with the
1672 vhost-user socket as file descriptor FDNUM. It is incompatible with
1675 --print-capabilities
1677 Output to stdout the back-end capabilities in JSON format, and then
1678 exit successfully. Other options and arguments should be ignored, and
1679 the back-end program should not perform its normal function. The
1680 capabilities can be reported dynamically depending on the host
1683 The JSON output is described in the ``vhost-user.json`` schema, by
1684 ```@VHostUserBackendCapabilities``. Example:
1699 Command line options:
1703 Specify the linux input device.
1709 Do no request exclusive access to the input device.
1716 Command line options:
1720 Specify the GPU DRM render node.
1726 Enable virgl rendering support.
1733 Command line options:
1737 Specify block device or file path.