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 intended to
21 be a software Ethernet switch running in user space, such as Snabbswitch.
23 Master and slave can be either a client (i.e. connecting) or server (listening)
24 in the socket communication.
29 Note that all numbers are in the machine native byte order. A vhost-user message
30 consists of 3 header fields and a payload:
32 ------------------------------------
33 | request | flags | size | payload |
34 ------------------------------------
36 * Request: 32-bit type of the request
37 * Flags: 32-bit bit field:
38 - Lower 2 bits are the version (currently 0x01)
39 - Bit 2 is the reply flag - needs to be sent on each reply from the slave
40 * Size - 32-bit size of the payload
43 Depending on the request type, payload can be:
45 * A single 64-bit integer
50 u64: a 64-bit unsigned integer
52 * A vring state description
60 * A vring address description
61 --------------------------------------------------------------
62 | index | flags | size | descriptor | used | available | log |
63 --------------------------------------------------------------
65 Index: a 32-bit vring index
66 Flags: a 32-bit vring flags
67 Descriptor: a 64-bit user address of the vring descriptor table
68 Used: a 64-bit user address of the vring used ring
69 Available: a 64-bit user address of the vring available ring
70 Log: a 64-bit guest address for logging
72 * Memory regions description
73 ---------------------------------------------------
74 | num regions | padding | region0 | ... | region7 |
75 ---------------------------------------------------
77 Num regions: a 32-bit number of regions
81 -----------------------------------------------------
82 | guest address | size | user address | mmap offset |
83 -----------------------------------------------------
85 Guest address: a 64-bit guest address of the region
87 User address: a 64-bit user address
88 mmap offset: 64-bit offset where region starts in the mapped memory
90 In QEMU the vhost-user message is implemented with the following struct:
92 typedef struct VhostUserMsg {
93 VhostUserRequest request;
98 struct vhost_vring_state state;
99 struct vhost_vring_addr addr;
100 VhostUserMemory memory;
102 } QEMU_PACKED VhostUserMsg;
107 The protocol for vhost-user is based on the existing implementation of vhost
108 for the Linux Kernel. Most messages that can be sent via the Unix domain socket
109 implementing vhost-user have an equivalent ioctl to the kernel implementation.
111 The communication consists of master sending message requests and slave sending
112 message replies. Most of the requests don't require replies. Here is a list of
116 * VHOST_GET_VRING_BASE
118 There are several messages that the master sends with file descriptors passed
119 in the ancillary data:
121 * VHOST_SET_MEM_TABLE
123 * VHOST_SET_VRING_KICK
124 * VHOST_SET_VRING_CALL
125 * VHOST_SET_VRING_ERR
127 If Master is unable to send the full message or receives a wrong reply it will
128 close the connection. An optional reconnection mechanism can be implemented.
132 The protocol supports multiple queues by setting all index fields in the sent
133 messages to a properly calculated value.
138 * VHOST_USER_GET_FEATURES
141 Equivalent ioctl: VHOST_GET_FEATURES
145 Get from the underlying vhost implementation the features bitmask.
147 * VHOST_USER_SET_FEATURES
150 Ioctl: VHOST_SET_FEATURES
153 Enable features in the underlying vhost implementation using a bitmask.
155 * VHOST_USER_SET_OWNER
158 Equivalent ioctl: VHOST_SET_OWNER
161 Issued when a new connection is established. It sets the current Master
162 as an owner of the session. This can be used on the Slave as a
163 "session start" flag.
165 * VHOST_USER_RESET_OWNER
168 Equivalent ioctl: VHOST_RESET_OWNER
171 Issued when a new connection is about to be closed. The Master will no
172 longer own this connection (and will usually close it).
174 * VHOST_USER_SET_MEM_TABLE
177 Equivalent ioctl: VHOST_SET_MEM_TABLE
178 Master payload: memory regions description
180 Sets the memory map regions on the slave so it can translate the vring
181 addresses. In the ancillary data there is an array of file descriptors
182 for each memory mapped region. The size and ordering of the fds matches
183 the number and ordering of memory regions.
185 * VHOST_USER_SET_LOG_BASE
188 Equivalent ioctl: VHOST_SET_LOG_BASE
191 Sets the logging base address.
193 * VHOST_USER_SET_LOG_FD
196 Equivalent ioctl: VHOST_SET_LOG_FD
199 Sets the logging file descriptor, which is passed as ancillary data.
201 * VHOST_USER_SET_VRING_NUM
204 Equivalent ioctl: VHOST_SET_VRING_NUM
205 Master payload: vring state description
207 Sets the number of vrings for this owner.
209 * VHOST_USER_SET_VRING_ADDR
212 Equivalent ioctl: VHOST_SET_VRING_ADDR
213 Master payload: vring address description
216 Sets the addresses of the different aspects of the vring.
218 * VHOST_USER_SET_VRING_BASE
221 Equivalent ioctl: VHOST_SET_VRING_BASE
222 Master payload: vring state description
224 Sets the base offset in the available vring.
226 * VHOST_USER_GET_VRING_BASE
229 Equivalent ioctl: VHOST_USER_GET_VRING_BASE
230 Master payload: vring state description
231 Slave payload: vring state description
233 Get the available vring base offset.
235 * VHOST_USER_SET_VRING_KICK
238 Equivalent ioctl: VHOST_SET_VRING_KICK
241 Set the event file descriptor for adding buffers to the vring. It
242 is passed in the ancillary data.
243 Bits (0-7) of the payload contain the vring index. Bit 8 is the
244 invalid FD flag. This flag is set when there is no file descriptor
245 in the ancillary data. This signals that polling should be used
246 instead of waiting for a kick.
248 * VHOST_USER_SET_VRING_CALL
251 Equivalent ioctl: VHOST_SET_VRING_CALL
254 Set the event file descriptor to signal when buffers are used. It
255 is passed in the ancillary data.
256 Bits (0-7) of the payload contain the vring index. Bit 8 is the
257 invalid FD flag. This flag is set when there is no file descriptor
258 in the ancillary data. This signals that polling will be used
259 instead of waiting for the call.
261 * VHOST_USER_SET_VRING_ERR
264 Equivalent ioctl: VHOST_SET_VRING_ERR
267 Set the event file descriptor to signal when error occurs. It
268 is passed in the ancillary data.
269 Bits (0-7) of the payload contain the vring index. Bit 8 is the
270 invalid FD flag. This flag is set when there is no file descriptor
271 in the ancillary data.