1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
4 /* Userspace interface for in-kernel virtio accelerators. */
6 /* vhost is used to reduce the number of system calls involved in virtio.
8 * Existing virtio net code is used in the guest without modification.
10 * This header includes interface used by userspace hypervisor for
11 * device configuration.
14 #include <linux/types.h>
16 #include <linux/ioctl.h>
17 #include <linux/virtio_config.h>
18 #include <linux/virtio_ring.h>
20 struct vhost_vring_state
{
25 struct vhost_vring_file
{
27 int fd
; /* Pass -1 to unbind from file. */
31 struct vhost_vring_addr
{
36 /* Whether log address is valid. If set enables logging. */
37 #define VHOST_VRING_F_LOG 0
39 /* Start of array of descriptors (virtually contiguous) */
41 /* Used structure address. Must be 32 bit aligned */
43 /* Available structure address. Must be 16 bit aligned */
44 __u64 avail_user_addr
;
45 /* Logging support. */
46 /* Log writes to used structure, at offset calculated from specified
47 * address. Address must be 32 bit aligned. */
51 /* no alignment requirement */
52 struct vhost_iotlb_msg
{
56 #define VHOST_ACCESS_RO 0x1
57 #define VHOST_ACCESS_WO 0x2
58 #define VHOST_ACCESS_RW 0x3
60 #define VHOST_IOTLB_MISS 1
61 #define VHOST_IOTLB_UPDATE 2
62 #define VHOST_IOTLB_INVALIDATE 3
63 #define VHOST_IOTLB_ACCESS_FAIL 4
67 #define VHOST_IOTLB_MSG 0x1
68 #define VHOST_IOTLB_MSG_V2 0x2
73 struct vhost_iotlb_msg iotlb
;
82 struct vhost_iotlb_msg iotlb
;
87 struct vhost_memory_region
{
88 __u64 guest_phys_addr
;
89 __u64 memory_size
; /* bytes */
91 __u64 flags_padding
; /* No flags are currently specified. */
94 /* All region addresses and sizes must be 4K aligned. */
95 #define VHOST_PAGE_SIZE 0x1000
100 struct vhost_memory_region regions
[0];
105 #define VHOST_VIRTIO 0xAF
107 /* Features bitmask for forward compatibility. Transport bits are used for
108 * vhost specific features. */
109 #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
110 #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
112 /* Set current process as the (exclusive) owner of this file descriptor. This
113 * must be called before any other vhost command. Further calls to
114 * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
115 #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
116 /* Give up ownership, and reset the device to default values.
117 * Allows subsequent call to VHOST_OWNER_SET to succeed. */
118 #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
120 /* Set up/modify memory layout */
121 #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
123 /* Write logging setup. */
124 /* Memory writes can optionally be logged by setting bit at an offset
125 * (calculated from the physical address) from specified log base.
126 * The bit is set using an atomic 32 bit operation. */
127 /* Set base address for logging. */
128 #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
129 /* Specify an eventfd file descriptor to signal on log write. */
130 #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
133 /* Set number of descriptors in ring. This parameter can not
134 * be modified while ring is running (bound to a device). */
135 #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
136 /* Set addresses for the ring. */
137 #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
138 /* Base value where queue looks for available descriptors */
139 #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
140 /* Get accessor: reads index, writes value in num */
141 #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
143 /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
144 * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
145 * The byte order cannot be changed while the device is active: trying to do so
147 * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
149 * Not all kernel configurations support this ioctl, but all configurations that
150 * support SET also support GET.
152 #define VHOST_VRING_LITTLE_ENDIAN 0
153 #define VHOST_VRING_BIG_ENDIAN 1
154 #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
155 #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
157 /* The following ioctls use eventfd file descriptors to signal and poll
160 /* Set eventfd to poll for added buffers */
161 #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
162 /* Set eventfd to signal when buffers have beed used */
163 #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
164 /* Set eventfd to signal an error */
165 #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
166 /* Set busy loop timeout (in us) */
167 #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \
168 struct vhost_vring_state)
169 /* Get busy loop timeout (in us) */
170 #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
171 struct vhost_vring_state)
173 /* Set or get vhost backend capability */
175 /* Use message type V2 */
176 #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
178 #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
179 #define VHOST_GET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x26, __u64)
181 /* VHOST_NET specific defines */
183 /* Attach virtio net ring to a raw socket, or tap device.
184 * The socket must be already bound to an ethernet device, this device will be
185 * used for transmit. Pass fd -1 to unbind from the socket and the transmit
186 * device. This can be used to stop the ring (e.g. for migration). */
187 #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
190 /* Log all write descriptors. Can be changed while device is active. */
191 #define VHOST_F_LOG_ALL 26
192 /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
193 #define VHOST_NET_F_VIRTIO_NET_HDR 27
195 /* VHOST_SCSI specific definitions */
198 * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
200 * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
201 * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
202 * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
203 * All the targets under vhost_wwpn can be seen and used by guset.
206 #define VHOST_SCSI_ABI_VERSION 1
208 struct vhost_scsi_target
{
210 char vhost_wwpn
[224]; /* TRANSPORT_IQN_LEN */
211 unsigned short vhost_tpgt
;
212 unsigned short reserved
;
215 #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
216 #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
217 /* Changing this breaks userspace. */
218 #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
219 /* Set and get the events missed flag */
220 #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
221 #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
223 /* VHOST_VSOCK specific defines */
225 #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64)
226 #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int)