4 Copyright (c) 2014 Virtual Open Systems Sarl.
6 This work is licensed under the terms of the GNU GPL, version 2 or later.
7 See the COPYING file in the top-level directory.
10 This protocol is aiming to complement the ioctl interface used to control the
11 vhost implementation in the Linux kernel. It implements the control plane needed
12 to establish virtqueue sharing with a user space process on the same host. It
13 uses communication over a Unix domain socket to share file descriptors in the
14 ancillary data of the message.
16 The protocol defines 2 sides of the communication, master and slave. Master is
17 the application that shares its virtqueues, in our case QEMU. Slave is the
18 consumer of the virtqueues.
20 In the current implementation QEMU is the Master, and the Slave is the
21 external process consuming the virtio queues, for example a software
22 Ethernet switch running in user space, such as Snabbswitch, or a block
23 device backend processing read & write to a virtual disk. In order to
24 facilitate interoperability between various backend implementations,
25 it is recommended to follow the "Backend program conventions"
26 described in this document.
28 Master and slave can be either a client (i.e. connecting) or server (listening)
29 in the socket communication.
34 Note that all numbers are in the machine native byte order. A vhost-user message
35 consists of 3 header fields and a payload:
37 ------------------------------------
38 | request | flags | size | payload |
39 ------------------------------------
41 * Request: 32-bit type of the request
42 * Flags: 32-bit bit field:
43 - Lower 2 bits are the version (currently 0x01)
44 - Bit 2 is the reply flag - needs to be sent on each reply from the slave
45 - Bit 3 is the need_reply flag - see VHOST_USER_PROTOCOL_F_REPLY_ACK for
47 * Size - 32-bit size of the payload
50 Depending on the request type, payload can be:
52 * A single 64-bit integer
57 u64: a 64-bit unsigned integer
59 * A vring state description
67 * A vring address description
68 --------------------------------------------------------------
69 | index | flags | size | descriptor | used | available | log |
70 --------------------------------------------------------------
72 Index: a 32-bit vring index
73 Flags: a 32-bit vring flags
74 Descriptor: a 64-bit ring address of the vring descriptor table
75 Used: a 64-bit ring address of the vring used ring
76 Available: a 64-bit ring address of the vring available ring
77 Log: a 64-bit guest address for logging
79 Note that a ring address is an IOVA if VIRTIO_F_IOMMU_PLATFORM has been
80 negotiated. Otherwise it is a user address.
82 * Memory regions description
83 ---------------------------------------------------
84 | num regions | padding | region0 | ... | region7 |
85 ---------------------------------------------------
87 Num regions: a 32-bit number of regions
91 -----------------------------------------------------
92 | guest address | size | user address | mmap offset |
93 -----------------------------------------------------
95 Guest address: a 64-bit guest address of the region
97 User address: a 64-bit user address
98 mmap offset: 64-bit offset where region starts in the mapped memory
101 ---------------------------
102 | log size | log offset |
103 ---------------------------
104 log size: size of area used for logging
105 log offset: offset from start of supplied file descriptor
106 where logging starts (i.e. where guest address 0 would be logged)
109 ---------------------------------------------------------
110 | iova | size | user address | permissions flags | type |
111 ---------------------------------------------------------
113 IOVA: a 64-bit I/O virtual address programmed by the guest
115 User address: a 64-bit user address
116 Permissions: an 8-bit value:
120 - 3: Read/Write access
121 Type: an 8-bit IOTLB message type:
124 - 3: IOTLB invalidate
125 - 4: IOTLB access fail
127 * Virtio device config space
128 -----------------------------------
129 | offset | size | flags | payload |
130 -----------------------------------
132 Offset: a 32-bit offset of virtio device's configuration space
133 Size: a 32-bit configuration space access size in bytes
134 Flags: a 32-bit value:
135 - 0: Vhost master messages used for writeable fields
136 - 1: Vhost master messages used for live migration
137 Payload: Size bytes array holding the contents of the virtio
138 device's configuration space
140 * Vring area description
141 -----------------------
142 | u64 | size | offset |
143 -----------------------
145 u64: a 64-bit integer contains vring index and flags
146 Size: a 64-bit size of this area
147 Offset: a 64-bit offset of this area from the start of the
148 supplied file descriptor
150 * Inflight description
151 -----------------------------------------------------
152 | mmap size | mmap offset | num queues | queue size |
153 -----------------------------------------------------
155 mmap size: a 64-bit size of area to track inflight I/O
156 mmap offset: a 64-bit offset of this area from the start
157 of the supplied file descriptor
158 num queues: a 16-bit number of virtqueues
159 queue size: a 16-bit size of virtqueues
161 In QEMU the vhost-user message is implemented with the following struct:
163 typedef struct VhostUserMsg {
164 VhostUserRequest request;
169 struct vhost_vring_state state;
170 struct vhost_vring_addr addr;
171 VhostUserMemory memory;
173 struct vhost_iotlb_msg iotlb;
174 VhostUserConfig config;
175 VhostUserVringArea area;
176 VhostUserInflight inflight;
178 } QEMU_PACKED VhostUserMsg;
183 The protocol for vhost-user is based on the existing implementation of vhost
184 for the Linux Kernel. Most messages that can be sent via the Unix domain socket
185 implementing vhost-user have an equivalent ioctl to the kernel implementation.
187 The communication consists of master sending message requests and slave sending
188 message replies. Most of the requests don't require replies. Here is a list of
191 * VHOST_USER_GET_FEATURES
192 * VHOST_USER_GET_PROTOCOL_FEATURES
193 * VHOST_USER_GET_VRING_BASE
194 * VHOST_USER_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD)
195 * VHOST_USER_GET_INFLIGHT_FD (if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)
197 [ Also see the section on REPLY_ACK protocol extension. ]
199 There are several messages that the master sends with file descriptors passed
200 in the ancillary data:
202 * VHOST_USER_SET_MEM_TABLE
203 * VHOST_USER_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD)
204 * VHOST_USER_SET_LOG_FD
205 * VHOST_USER_SET_VRING_KICK
206 * VHOST_USER_SET_VRING_CALL
207 * VHOST_USER_SET_VRING_ERR
208 * VHOST_USER_SET_SLAVE_REQ_FD
209 * VHOST_USER_SET_INFLIGHT_FD (if VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)
211 If Master is unable to send the full message or receives a wrong reply it will
212 close the connection. An optional reconnection mechanism can be implemented.
214 Any protocol extensions are gated by protocol feature bits,
215 which allows full backwards compatibility on both master
217 As older slaves don't support negotiating protocol features,
218 a feature bit was dedicated for this purpose:
219 #define VHOST_USER_F_PROTOCOL_FEATURES 30
221 Starting and stopping rings
222 ----------------------
223 Client must only process each ring when it is started.
225 Client must only pass data between the ring and the
226 backend, when the ring is enabled.
228 If ring is started but disabled, client must process the
229 ring without talking to the backend.
231 For example, for a networking device, in the disabled state
232 client must not supply any new RX packets, but must process
233 and discard any TX packets.
235 If VHOST_USER_F_PROTOCOL_FEATURES has not been negotiated, the ring is initialized
238 If VHOST_USER_F_PROTOCOL_FEATURES has been negotiated, the ring is initialized
239 in a disabled state. Client must not pass data to/from the backend until ring is enabled by
240 VHOST_USER_SET_VRING_ENABLE with parameter 1, or after it has been disabled by
241 VHOST_USER_SET_VRING_ENABLE with parameter 0.
243 Each ring is initialized in a stopped state, client must not process it until
244 ring is started, or after it has been stopped.
246 Client must start ring upon receiving a kick (that is, detecting that file
247 descriptor is readable) on the descriptor specified by
248 VHOST_USER_SET_VRING_KICK, and stop ring upon receiving
249 VHOST_USER_GET_VRING_BASE.
251 While processing the rings (whether they are enabled or not), client must
252 support changing some configuration aspects on the fly.
254 Multiple queue support
255 ----------------------
257 Multiple queue is treated as a protocol extension, hence the slave has to
258 implement protocol features first. The multiple queues feature is supported
259 only when the protocol feature VHOST_USER_PROTOCOL_F_MQ (bit 0) is set.
261 The max number of queue pairs the slave supports can be queried with message
262 VHOST_USER_GET_QUEUE_NUM. Master should stop when the number of
263 requested queues is bigger than that.
265 As all queues share one connection, the master uses a unique index for each
266 queue in the sent message to identify a specified queue. One queue pair
267 is enabled initially. More queues are enabled dynamically, by sending
268 message VHOST_USER_SET_VRING_ENABLE.
273 During live migration, the master may need to track the modifications
274 the slave makes to the memory mapped regions. The client should mark
275 the dirty pages in a log. Once it complies to this logging, it may
276 declare the VHOST_F_LOG_ALL vhost feature.
278 To start/stop logging of data/used ring writes, server may send messages
279 VHOST_USER_SET_FEATURES with VHOST_F_LOG_ALL and VHOST_USER_SET_VRING_ADDR with
280 VHOST_VRING_F_LOG in ring's flags set to 1/0, respectively.
282 All the modifications to memory pointed by vring "descriptor" should
283 be marked. Modifications to "used" vring should be marked if
284 VHOST_VRING_F_LOG is part of ring's flags.
286 Dirty pages are of size:
287 #define VHOST_LOG_PAGE 0x1000
289 The log memory fd is provided in the ancillary data of
290 VHOST_USER_SET_LOG_BASE message when the slave has
291 VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol feature.
293 The size of the log is supplied as part of VhostUserMsg
294 which should be large enough to cover all known guest
295 addresses. Log starts at the supplied offset in the
296 supplied file descriptor.
297 The log covers from address 0 to the maximum of guest
298 regions. In pseudo-code, to mark page at "addr" as dirty:
300 page = addr / VHOST_LOG_PAGE
301 log[page / 8] |= 1 << page % 8
303 Where addr is the guest physical address.
305 Use atomic operations, as the log may be concurrently manipulated.
307 Note that when logging modifications to the used ring (when VHOST_VRING_F_LOG
308 is set for this ring), log_guest_addr should be used to calculate the log
309 offset: the write to first byte of the used ring is logged at this offset from
310 log start. Also note that this value might be outside the legal guest physical
311 address range (i.e. does not have to be covered by the VhostUserMemory table),
312 but the bit offset of the last byte of the ring must fall within
313 the size supplied by VhostUserLog.
315 VHOST_USER_SET_LOG_FD is an optional message with an eventfd in
316 ancillary data, it may be used to inform the master that the log has
319 Once the source has finished migration, rings will be stopped by
320 the source. No further update must be done before rings are
323 In postcopy migration the slave is started before all the memory has been
324 received from the source host, and care must be taken to avoid accessing pages
325 that have yet to be received. The slave opens a 'userfault'-fd and registers
326 the memory with it; this fd is then passed back over to the master.
327 The master services requests on the userfaultfd for pages that are accessed
328 and when the page is available it performs WAKE ioctl's on the userfaultfd
329 to wake the stalled slave. The client indicates support for this via the
330 VHOST_USER_PROTOCOL_F_PAGEFAULT feature.
335 The master sends a list of vhost memory regions to the slave using the
336 VHOST_USER_SET_MEM_TABLE message. Each region has two base addresses: a guest
337 address and a user address.
339 Messages contain guest addresses and/or user addresses to reference locations
340 within the shared memory. The mapping of these addresses works as follows.
342 User addresses map to the vhost memory region containing that user address.
344 When the VIRTIO_F_IOMMU_PLATFORM feature has not been negotiated:
346 * Guest addresses map to the vhost memory region containing that guest
349 When the VIRTIO_F_IOMMU_PLATFORM feature has been negotiated:
351 * Guest addresses are also called I/O virtual addresses (IOVAs). They are
352 translated to user addresses via the IOTLB.
354 * The vhost memory region guest address is not used.
359 When the VIRTIO_F_IOMMU_PLATFORM feature has been negotiated, the master
360 sends IOTLB entries update & invalidation by sending VHOST_USER_IOTLB_MSG
361 requests to the slave with a struct vhost_iotlb_msg as payload. For update
362 events, the iotlb payload has to be filled with the update message type (2),
363 the I/O virtual address, the size, the user virtual address, and the
364 permissions flags. Addresses and size must be within vhost memory regions set
365 via the VHOST_USER_SET_MEM_TABLE request. For invalidation events, the iotlb
366 payload has to be filled with the invalidation message type (3), the I/O virtual
367 address and the size. On success, the slave is expected to reply with a zero
368 payload, non-zero otherwise.
370 The slave relies on the slave communcation channel (see "Slave communication"
371 section below) to send IOTLB miss and access failure events, by sending
372 VHOST_USER_SLAVE_IOTLB_MSG requests to the master with a struct vhost_iotlb_msg
373 as payload. For miss events, the iotlb payload has to be filled with the miss
374 message type (1), the I/O virtual address and the permissions flags. For access
375 failure event, the iotlb payload has to be filled with the access failure
376 message type (4), the I/O virtual address and the permissions flags.
377 For synchronization purpose, the slave may rely on the reply-ack feature,
378 so the master may send a reply when operation is completed if the reply-ack
379 feature is negotiated and slaves requests a reply. For miss events, completed
380 operation means either master sent an update message containing the IOTLB entry
381 containing requested address and permission, or master sent nothing if the IOTLB
382 miss message is invalid (invalid IOVA or permission).
384 The master isn't expected to take the initiative to send IOTLB update messages,
385 as the slave sends IOTLB miss messages for the guest virtual memory areas it
391 An optional communication channel is provided if the slave declares
392 VHOST_USER_PROTOCOL_F_SLAVE_REQ protocol feature, to allow the slave to make
393 requests to the master.
395 The fd is provided via VHOST_USER_SET_SLAVE_REQ_FD ancillary data.
397 A slave may then send VHOST_USER_SLAVE_* messages to the master
398 using this fd communication channel.
400 If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol feature is negotiated,
401 slave can send file descriptors (at most 8 descriptors in each message)
402 to master via ancillary data using this fd communication channel.
404 Inflight I/O tracking
405 ---------------------
407 To support reconnecting after restart or crash, slave may need to resubmit
408 inflight I/Os. If virtqueue is processed in order, we can easily achieve
409 that by getting the inflight descriptors from descriptor table (split virtqueue)
410 or descriptor ring (packed virtqueue). However, it can't work when we process
411 descriptors out-of-order because some entries which store the information of
412 inflight descriptors in available ring (split virtqueue) or descriptor
413 ring (packed virtqueue) might be overrided by new entries. To solve this
414 problem, slave need to allocate an extra buffer to store this information of inflight
415 descriptors and share it with master for persistent. VHOST_USER_GET_INFLIGHT_FD and
416 VHOST_USER_SET_INFLIGHT_FD are used to transfer this buffer between master
417 and slave. And the format of this buffer is described below:
419 -------------------------------------------------------
420 | queue0 region | queue1 region | ... | queueN region |
421 -------------------------------------------------------
423 N is the number of available virtqueues. Slave could get it from num queues
424 field of VhostUserInflight.
426 For split virtqueue, queue region can be implemented as:
428 typedef struct DescStateSplit {
429 /* Indicate whether this descriptor is inflight or not.
430 * Only available for head-descriptor. */
436 /* Maintain a list for the last batch of used descriptors.
437 * Only available when batching is used for submitting */
440 /* Used to preserve the order of fetching available descriptors.
441 * Only available for head-descriptor. */
445 typedef struct QueueRegionSplit {
446 /* The feature flags of this region. Now it's initialized to 0. */
449 /* The version of this region. It's 1 currently.
450 * Zero value indicates an uninitialized buffer */
453 /* The size of DescStateSplit array. It's equal to the virtqueue
454 * size. Slave could get it from queue size field of VhostUserInflight. */
457 /* The head of list that track the last batch of used descriptors. */
458 uint16_t last_batch_head;
460 /* Store the idx value of used ring */
463 /* Used to track the state of each descriptor in descriptor table */
464 DescStateSplit desc[0];
467 To track inflight I/O, the queue region should be processed as follows:
469 When receiving available buffers from the driver:
471 1. Get the next available head-descriptor index from available ring, i
473 2. Set desc[i].counter to the value of global counter
475 3. Increase global counter by 1
477 4. Set desc[i].inflight to 1
479 When supplying used buffers to the driver:
481 1. Get corresponding used head-descriptor index, i
483 2. Set desc[i].next to last_batch_head
485 3. Set last_batch_head to i
487 4. Steps 1,2,3 may be performed repeatedly if batching is possible
489 5. Increase the idx value of used ring by the size of the batch
491 6. Set the inflight field of each DescStateSplit entry in the batch to 0
493 7. Set used_idx to the idx value of used ring
497 1. If the value of used_idx does not match the idx value of used ring (means
498 the inflight field of DescStateSplit entries in last batch may be incorrect),
500 (a) Subtract the value of used_idx from the idx value of used ring to get
501 last batch size of DescStateSplit entries
503 (b) Set the inflight field of each DescStateSplit entry to 0 in last batch
504 list which starts from last_batch_head
506 (c) Set used_idx to the idx value of used ring
508 2. Resubmit inflight DescStateSplit entries in order of their counter value
510 For packed virtqueue, queue region can be implemented as:
512 typedef struct DescStatePacked {
513 /* Indicate whether this descriptor is inflight or not.
514 * Only available for head-descriptor. */
520 /* Link to the next free entry */
523 /* Link to the last entry of descriptor list.
524 * Only available for head-descriptor. */
527 /* The length of descriptor list.
528 * Only available for head-descriptor. */
531 /* Used to preserve the order of fetching available descriptors.
532 * Only available for head-descriptor. */
538 /* The descriptor flags */
541 /* The buffer length */
544 /* The buffer address */
548 typedef struct QueueRegionPacked {
549 /* The feature flags of this region. Now it's initialized to 0. */
552 /* The version of this region. It's 1 currently.
553 * Zero value indicates an uninitialized buffer */
556 /* The size of DescStatePacked array. It's equal to the virtqueue
557 * size. Slave could get it from queue size field of VhostUserInflight. */
560 /* The head of free DescStatePacked entry list */
563 /* The old head of free DescStatePacked entry list */
564 uint16_t old_free_head;
566 /* The used index of descriptor ring */
569 /* The old used index of descriptor ring */
570 uint16_t old_used_idx;
572 /* Device ring wrap counter */
573 uint8_t used_wrap_counter;
575 /* The old device ring wrap counter */
576 uint8_t old_used_wrap_counter;
581 /* Used to track the state of each descriptor fetched from descriptor ring */
582 DescStatePacked desc[0];
585 To track inflight I/O, the queue region should be processed as follows:
587 When receiving available buffers from the driver:
589 1. Get the next available descriptor entry from descriptor ring, d
591 2. If d is head descriptor,
593 (a) Set desc[old_free_head].num to 0
595 (b) Set desc[old_free_head].counter to the value of global counter
597 (c) Increase global counter by 1
599 (d) Set desc[old_free_head].inflight to 1
601 3. If d is last descriptor, set desc[old_free_head].last to free_head
603 4. Increase desc[old_free_head].num by 1
605 5. Set desc[free_head].addr, desc[free_head].len, desc[free_head].flags,
606 desc[free_head].id to d.addr, d.len, d.flags, d.id
608 6. Set free_head to desc[free_head].next
610 7. If d is last descriptor, set old_free_head to free_head
612 When supplying used buffers to the driver:
614 1. Get corresponding used head-descriptor entry from descriptor ring, d
616 2. Get corresponding DescStatePacked entry, e
618 3. Set desc[e.last].next to free_head
620 4. Set free_head to the index of e
622 5. Steps 1,2,3,4 may be performed repeatedly if batching is possible
624 6. Increase used_idx by the size of the batch and update used_wrap_counter if needed
628 8. Set the inflight field of each head DescStatePacked entry in the batch to 0
630 9. Set old_free_head, old_used_idx, old_used_wrap_counter to free_head, used_idx,
635 1. If used_idx does not match old_used_idx (means the inflight field of DescStatePacked
636 entries in last batch may be incorrect),
638 (a) Get the next descriptor ring entry through old_used_idx, d
640 (b) Use old_used_wrap_counter to calculate the available flags
642 (c) If d.flags is not equal to the calculated flags value (means slave has
643 submitted the buffer to guest driver before crash, so it has to commit the
644 in-progres update), set old_free_head, old_used_idx, old_used_wrap_counter
645 to free_head, used_idx, used_wrap_counter
647 2. Set free_head, used_idx, used_wrap_counter to old_free_head, old_used_idx,
648 old_used_wrap_counter (roll back any in-progress update)
650 3. Set the inflight field of each DescStatePacked entry in free list to 0
652 4. Resubmit inflight DescStatePacked entries in order of their counter value
657 #define VHOST_USER_PROTOCOL_F_MQ 0
658 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
659 #define VHOST_USER_PROTOCOL_F_RARP 2
660 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
661 #define VHOST_USER_PROTOCOL_F_MTU 4
662 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
663 #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN 6
664 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
665 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8
666 #define VHOST_USER_PROTOCOL_F_CONFIG 9
667 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10
668 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
669 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12
674 * VHOST_USER_GET_FEATURES
677 Equivalent ioctl: VHOST_GET_FEATURES
681 Get from the underlying vhost implementation the features bitmask.
682 Feature bit VHOST_USER_F_PROTOCOL_FEATURES signals slave support for
683 VHOST_USER_GET_PROTOCOL_FEATURES and VHOST_USER_SET_PROTOCOL_FEATURES.
685 * VHOST_USER_SET_FEATURES
688 Ioctl: VHOST_SET_FEATURES
691 Enable features in the underlying vhost implementation using a bitmask.
692 Feature bit VHOST_USER_F_PROTOCOL_FEATURES signals slave support for
693 VHOST_USER_GET_PROTOCOL_FEATURES and VHOST_USER_SET_PROTOCOL_FEATURES.
695 * VHOST_USER_GET_PROTOCOL_FEATURES
698 Equivalent ioctl: VHOST_GET_FEATURES
702 Get the protocol feature bitmask from the underlying vhost implementation.
703 Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in
704 VHOST_USER_GET_FEATURES.
705 Note: slave that reported VHOST_USER_F_PROTOCOL_FEATURES must support
706 this message even before VHOST_USER_SET_FEATURES was called.
708 * VHOST_USER_SET_PROTOCOL_FEATURES
711 Ioctl: VHOST_SET_FEATURES
714 Enable protocol features in the underlying vhost implementation.
715 Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in
716 VHOST_USER_GET_FEATURES.
717 Note: slave that reported VHOST_USER_F_PROTOCOL_FEATURES must support
718 this message even before VHOST_USER_SET_FEATURES was called.
720 * VHOST_USER_SET_OWNER
723 Equivalent ioctl: VHOST_SET_OWNER
726 Issued when a new connection is established. It sets the current Master
727 as an owner of the session. This can be used on the Slave as a
728 "session start" flag.
730 * VHOST_USER_RESET_OWNER
735 This is no longer used. Used to be sent to request disabling
736 all rings, but some clients interpreted it to also discard
737 connection state (this interpretation would lead to bugs).
738 It is recommended that clients either ignore this message,
739 or use it to disable all rings.
741 * VHOST_USER_SET_MEM_TABLE
744 Equivalent ioctl: VHOST_SET_MEM_TABLE
745 Master payload: memory regions description
746 Slave payload: (postcopy only) memory regions description
748 Sets the memory map regions on the slave so it can translate the vring
749 addresses. In the ancillary data there is an array of file descriptors
750 for each memory mapped region. The size and ordering of the fds matches
751 the number and ordering of memory regions.
753 When VHOST_USER_POSTCOPY_LISTEN has been received, SET_MEM_TABLE replies with
754 the bases of the memory mapped regions to the master. The slave must
755 have mmap'd the regions but not yet accessed them and should not yet generate
756 a userfault event. Note NEED_REPLY_MASK is not set in this case.
757 QEMU will then reply back to the list of mappings with an empty
758 VHOST_USER_SET_MEM_TABLE as an acknowledgment; only upon reception of this
759 message may the guest start accessing the memory and generating faults.
761 * VHOST_USER_SET_LOG_BASE
764 Equivalent ioctl: VHOST_SET_LOG_BASE
768 Sets logging shared memory space.
769 When slave has VHOST_USER_PROTOCOL_F_LOG_SHMFD protocol
770 feature, the log memory fd is provided in the ancillary data of
771 VHOST_USER_SET_LOG_BASE message, the size and offset of shared
772 memory area provided in the message.
775 * VHOST_USER_SET_LOG_FD
778 Equivalent ioctl: VHOST_SET_LOG_FD
781 Sets the logging file descriptor, which is passed as ancillary data.
783 * VHOST_USER_SET_VRING_NUM
786 Equivalent ioctl: VHOST_SET_VRING_NUM
787 Master payload: vring state description
789 Set the size of the queue.
791 * VHOST_USER_SET_VRING_ADDR
794 Equivalent ioctl: VHOST_SET_VRING_ADDR
795 Master payload: vring address description
798 Sets the addresses of the different aspects of the vring.
800 * VHOST_USER_SET_VRING_BASE
803 Equivalent ioctl: VHOST_SET_VRING_BASE
804 Master payload: vring state description
806 Sets the base offset in the available vring.
808 * VHOST_USER_GET_VRING_BASE
811 Equivalent ioctl: VHOST_USER_GET_VRING_BASE
812 Master payload: vring state description
813 Slave payload: vring state description
815 Get the available vring base offset.
817 * VHOST_USER_SET_VRING_KICK
820 Equivalent ioctl: VHOST_SET_VRING_KICK
823 Set the event file descriptor for adding buffers to the vring. It
824 is passed in the ancillary data.
825 Bits (0-7) of the payload contain the vring index. Bit 8 is the
826 invalid FD flag. This flag is set when there is no file descriptor
827 in the ancillary data. This signals that polling should be used
828 instead of waiting for a kick.
830 * VHOST_USER_SET_VRING_CALL
833 Equivalent ioctl: VHOST_SET_VRING_CALL
836 Set the event file descriptor to signal when buffers are used. It
837 is passed in the ancillary data.
838 Bits (0-7) of the payload contain the vring index. Bit 8 is the
839 invalid FD flag. This flag is set when there is no file descriptor
840 in the ancillary data. This signals that polling will be used
841 instead of waiting for the call.
843 * VHOST_USER_SET_VRING_ERR
846 Equivalent ioctl: VHOST_SET_VRING_ERR
849 Set the event file descriptor to signal when error occurs. It
850 is passed in the ancillary data.
851 Bits (0-7) of the payload contain the vring index. Bit 8 is the
852 invalid FD flag. This flag is set when there is no file descriptor
853 in the ancillary data.
855 * VHOST_USER_GET_QUEUE_NUM
858 Equivalent ioctl: N/A
862 Query how many queues the backend supports. This request should be
863 sent only when VHOST_USER_PROTOCOL_F_MQ is set in queried protocol
864 features by VHOST_USER_GET_PROTOCOL_FEATURES.
866 * VHOST_USER_SET_VRING_ENABLE
869 Equivalent ioctl: N/A
870 Master payload: vring state description
872 Signal slave to enable or disable corresponding vring.
873 This request should be sent only when VHOST_USER_F_PROTOCOL_FEATURES
876 * VHOST_USER_SEND_RARP
879 Equivalent ioctl: N/A
882 Ask vhost user backend to broadcast a fake RARP to notify the migration
883 is terminated for guest that does not support GUEST_ANNOUNCE.
884 Only legal if feature bit VHOST_USER_F_PROTOCOL_FEATURES is present in
885 VHOST_USER_GET_FEATURES and protocol feature bit VHOST_USER_PROTOCOL_F_RARP
886 is present in VHOST_USER_GET_PROTOCOL_FEATURES.
887 The first 6 bytes of the payload contain the mac address of the guest to
888 allow the vhost user backend to construct and broadcast the fake RARP.
890 * VHOST_USER_NET_SET_MTU
893 Equivalent ioctl: N/A
896 Set host MTU value exposed to the guest.
897 This request should be sent only when VIRTIO_NET_F_MTU feature has been
898 successfully negotiated, VHOST_USER_F_PROTOCOL_FEATURES is present in
899 VHOST_USER_GET_FEATURES and protocol feature bit
900 VHOST_USER_PROTOCOL_F_NET_MTU is present in
901 VHOST_USER_GET_PROTOCOL_FEATURES.
902 If VHOST_USER_PROTOCOL_F_REPLY_ACK is negotiated, slave must respond
903 with zero in case the specified MTU is valid, or non-zero otherwise.
905 * VHOST_USER_SET_SLAVE_REQ_FD
908 Equivalent ioctl: N/A
911 Set the socket file descriptor for slave initiated requests. It is passed
912 in the ancillary data.
913 This request should be sent only when VHOST_USER_F_PROTOCOL_FEATURES
914 has been negotiated, and protocol feature bit VHOST_USER_PROTOCOL_F_SLAVE_REQ
915 bit is present in VHOST_USER_GET_PROTOCOL_FEATURES.
916 If VHOST_USER_PROTOCOL_F_REPLY_ACK is negotiated, slave must respond
917 with zero for success, non-zero otherwise.
919 * VHOST_USER_IOTLB_MSG
922 Equivalent ioctl: N/A (equivalent to VHOST_IOTLB_MSG message type)
923 Master payload: struct vhost_iotlb_msg
926 Send IOTLB messages with struct vhost_iotlb_msg as payload.
927 Master sends such requests to update and invalidate entries in the device
928 IOTLB. The slave has to acknowledge the request with sending zero as u64
929 payload for success, non-zero otherwise.
930 This request should be send only when VIRTIO_F_IOMMU_PLATFORM feature
931 has been successfully negotiated.
933 * VHOST_USER_SET_VRING_ENDIAN
936 Equivalent ioctl: VHOST_SET_VRING_ENDIAN
937 Master payload: vring state description
939 Set the endianness of a VQ for legacy devices. Little-endian is indicated
940 with state.num set to 0 and big-endian is indicated with state.num set
941 to 1. Other values are invalid.
942 This request should be sent only when VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
944 Backends that negotiated this feature should handle both endiannesses
945 and expect this message once (per VQ) during device configuration
946 (ie. before the master starts the VQ).
948 * VHOST_USER_GET_CONFIG
951 Equivalent ioctl: N/A
952 Master payload: virtio device config space
953 Slave payload: virtio device config space
955 When VHOST_USER_PROTOCOL_F_CONFIG is negotiated, this message is
956 submitted by the vhost-user master to fetch the contents of the virtio
957 device configuration space, vhost-user slave's payload size MUST match
958 master's request, vhost-user slave uses zero length of payload to
959 indicate an error to vhost-user master. The vhost-user master may
960 cache the contents to avoid repeated VHOST_USER_GET_CONFIG calls.
962 * VHOST_USER_SET_CONFIG
965 Equivalent ioctl: N/A
966 Master payload: virtio device config space
969 When VHOST_USER_PROTOCOL_F_CONFIG is negotiated, this message is
970 submitted by the vhost-user master when the Guest changes the virtio
971 device configuration space and also can be used for live migration
972 on the destination host. The vhost-user slave must check the flags
973 field, and slaves MUST NOT accept SET_CONFIG for read-only
974 configuration space fields unless the live migration bit is set.
976 * VHOST_USER_CREATE_CRYPTO_SESSION
979 Equivalent ioctl: N/A
980 Master payload: crypto session description
981 Slave payload: crypto session description
983 Create a session for crypto operation. The server side must return the
984 session id, 0 or positive for success, negative for failure.
985 This request should be sent only when VHOST_USER_PROTOCOL_F_CRYPTO_SESSION
986 feature has been successfully negotiated.
987 It's a required feature for crypto devices.
989 * VHOST_USER_CLOSE_CRYPTO_SESSION
992 Equivalent ioctl: N/A
995 Close a session for crypto operation which was previously
996 created by VHOST_USER_CREATE_CRYPTO_SESSION.
997 This request should be sent only when VHOST_USER_PROTOCOL_F_CRYPTO_SESSION
998 feature has been successfully negotiated.
999 It's a required feature for crypto devices.
1001 * VHOST_USER_POSTCOPY_ADVISE
1004 Slave payload: userfault fd
1006 When VHOST_USER_PROTOCOL_F_PAGEFAULT is supported, the
1007 master advises slave that a migration with postcopy enabled is underway,
1008 the slave must open a userfaultfd for later use.
1009 Note that at this stage the migration is still in precopy mode.
1011 * VHOST_USER_POSTCOPY_LISTEN
1015 Master advises slave that a transition to postcopy mode has happened.
1016 The slave must ensure that shared memory is registered with userfaultfd
1017 to cause faulting of non-present pages.
1019 This is always sent sometime after a VHOST_USER_POSTCOPY_ADVISE, and
1020 thus only when VHOST_USER_PROTOCOL_F_PAGEFAULT is supported.
1022 * VHOST_USER_POSTCOPY_END
1026 Master advises that postcopy migration has now completed. The
1027 slave must disable the userfaultfd. The response is an acknowledgement
1029 When VHOST_USER_PROTOCOL_F_PAGEFAULT is supported, this message
1030 is sent at the end of the migration, after VHOST_USER_POSTCOPY_LISTEN
1031 was previously sent.
1032 The value returned is an error indication; 0 is success.
1034 * VHOST_USER_GET_INFLIGHT_FD
1036 Equivalent ioctl: N/A
1037 Master payload: inflight description
1039 When VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD protocol feature has been
1040 successfully negotiated, this message is submitted by master to get
1041 a shared buffer from slave. The shared buffer will be used to track
1042 inflight I/O by slave. QEMU should retrieve a new one when vm reset.
1044 * VHOST_USER_SET_INFLIGHT_FD
1046 Equivalent ioctl: N/A
1047 Master payload: inflight description
1049 When VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD protocol feature has been
1050 successfully negotiated, this message is submitted by master to send
1051 the shared inflight buffer back to slave so that slave could get
1052 inflight I/O after a crash or restart.
1057 * VHOST_USER_SLAVE_IOTLB_MSG
1060 Equivalent ioctl: N/A (equivalent to VHOST_IOTLB_MSG message type)
1061 Slave payload: struct vhost_iotlb_msg
1064 Send IOTLB messages with struct vhost_iotlb_msg as payload.
1065 Slave sends such requests to notify of an IOTLB miss, or an IOTLB
1066 access failure. If VHOST_USER_PROTOCOL_F_REPLY_ACK is negotiated,
1067 and slave set the VHOST_USER_NEED_REPLY flag, master must respond with
1068 zero when operation is successfully completed, or non-zero otherwise.
1069 This request should be send only when VIRTIO_F_IOMMU_PLATFORM feature
1070 has been successfully negotiated.
1072 * VHOST_USER_SLAVE_CONFIG_CHANGE_MSG
1075 Equivalent ioctl: N/A
1079 When VHOST_USER_PROTOCOL_F_CONFIG is negotiated, vhost-user slave sends
1080 such messages to notify that the virtio device's configuration space has
1081 changed, for those host devices which can support such feature, host
1082 driver can send VHOST_USER_GET_CONFIG message to slave to get the latest
1083 content. If VHOST_USER_PROTOCOL_F_REPLY_ACK is negotiated, and slave set
1084 the VHOST_USER_NEED_REPLY flag, master must respond with zero when
1085 operation is successfully completed, or non-zero otherwise.
1087 * VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG
1090 Equivalent ioctl: N/A
1091 Slave payload: vring area description
1094 Sets host notifier for a specified queue. The queue index is contained
1095 in the u64 field of the vring area description. The host notifier is
1096 described by the file descriptor (typically it's a VFIO device fd) which
1097 is passed as ancillary data and the size (which is mmap size and should
1098 be the same as host page size) and offset (which is mmap offset) carried
1099 in the vring area description. QEMU can mmap the file descriptor based
1100 on the size and offset to get a memory range. Registering a host notifier
1101 means mapping this memory range to the VM as the specified queue's notify
1102 MMIO region. Slave sends this request to tell QEMU to de-register the
1103 existing notifier if any and register the new notifier if the request is
1104 sent with a file descriptor.
1105 This request should be sent only when VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
1106 protocol feature has been successfully negotiated.
1108 VHOST_USER_PROTOCOL_F_REPLY_ACK:
1109 -------------------------------
1110 The original vhost-user specification only demands replies for certain
1111 commands. This differs from the vhost protocol implementation where commands
1112 are sent over an ioctl() call and block until the client has completed.
1114 With this protocol extension negotiated, the sender (QEMU) can set the
1115 "need_reply" [Bit 3] flag to any command. This indicates that
1116 the client MUST respond with a Payload VhostUserMsg indicating success or
1117 failure. The payload should be set to zero on success or non-zero on failure,
1118 unless the message already has an explicit reply body.
1120 The response payload gives QEMU a deterministic indication of the result
1121 of the command. Today, QEMU is expected to terminate the main vhost-user
1122 loop upon receiving such errors. In future, qemu could be taught to be more
1123 resilient for selective requests.
1125 For the message types that already solicit a reply from the client, the
1126 presence of VHOST_USER_PROTOCOL_F_REPLY_ACK or need_reply bit being set brings
1127 no behavioural change. (See the 'Communication' section for details.)
1129 Backend program conventions
1130 ---------------------------
1132 vhost-user backends can provide various devices & services and may
1133 need to be configured manually depending on the use case. However, it
1134 is a good idea to follow the conventions listed here when
1135 possible. Users, QEMU or libvirt, can then rely on some common
1136 behaviour to avoid heterogenous configuration and management of the
1137 backend programs and facilitate interoperability.
1139 Each backend installed on a host system should come with at least one
1140 JSON file that conforms to the vhost-user.json schema. Each file
1141 informs the management applications about the backend type, and binary
1142 location. In addition, it defines rules for management apps for
1143 picking the highest priority backend when multiple match the search
1144 criteria (see @VhostUserBackend documentation in the schema file).
1146 If the backend is not capable of enabling a requested feature on the
1147 host (such as 3D acceleration with virgl), or the initialization
1148 failed, the backend should fail to start early and exit with a status
1149 != 0. It may also print a message to stderr for further details.
1151 The backend program must not daemonize itself, but it may be
1152 daemonized by the management layer. It may also have a restricted
1153 access to the system.
1155 File descriptors 0, 1 and 2 will exist, and have regular
1156 stdin/stdout/stderr usage (they may have been redirected to /dev/null
1157 by the management layer, or to a log handler).
1159 The backend program must end (as quickly and cleanly as possible) when
1160 the SIGTERM signal is received. Eventually, it may receive SIGKILL by
1161 the management layer after a few seconds.
1163 The following command line options have an expected behaviour. They
1164 are mandatory, unless explicitly said differently:
1166 * --socket-path=PATH
1168 This option specify the location of the vhost-user Unix domain socket.
1169 It is incompatible with --fd.
1173 When this argument is given, the backend program is started with the
1174 vhost-user socket as file descriptor FDNUM. It is incompatible with
1177 * --print-capabilities
1179 Output to stdout the backend capabilities in JSON format, and then
1180 exit successfully. Other options and arguments should be ignored, and
1181 the backend program should not perform its normal function. The
1182 capabilities can be reported dynamically depending on the host
1185 The JSON output is described in the vhost-user.json schema, by
1186 @VHostUserBackendCapabilities. Example:
1198 Command line options:
1200 * --evdev-path=PATH (optional)
1202 Specify the linux input device.
1204 * --no-grab (optional)
1206 Do no request exclusive access to the input device.
1211 Command line options:
1213 * --render-node=PATH (optional)
1215 Specify the GPU DRM render node.
1217 * --virgl (optional)
1219 Enable virgl rendering support.