| Eric Auger | dd87396 | 2017-12-13 17:59:23 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 2 | #ifndef _LINUX_VHOST_H |
| 3 | #define _LINUX_VHOST_H |
| 4 | /* Userspace interface for in-kernel virtio accelerators. */ |
| 5 | |
| 6 | /* vhost is used to reduce the number of system calls involved in virtio. |
| 7 | * |
| 8 | * Existing virtio net code is used in the guest without modification. |
| 9 | * |
| 10 | * This header includes interface used by userspace hypervisor for |
| 11 | * device configuration. |
| 12 | */ |
| 13 | |
| Paolo Bonzini | da054c6 | 2019-01-04 09:27:31 +0100 | [diff] [blame] | 14 | #include <linux/vhost_types.h> |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 15 | #include <linux/types.h> |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 16 | #include <linux/ioctl.h> |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 17 | |
| Cornelia Huck | f76b348 | 2020-06-09 16:26:53 +0200 | [diff] [blame] | 18 | #define VHOST_FILE_UNBIND -1 |
| 19 | |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 20 | /* ioctls */ |
| 21 | |
| 22 | #define VHOST_VIRTIO 0xAF |
| 23 | |
| 24 | /* Features bitmask for forward compatibility. Transport bits are used for |
| 25 | * vhost specific features. */ |
| 26 | #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) |
| 27 | #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) |
| 28 | |
| 29 | /* Set current process as the (exclusive) owner of this file descriptor. This |
| 30 | * must be called before any other vhost command. Further calls to |
| 31 | * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ |
| 32 | #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) |
| 33 | /* Give up ownership, and reset the device to default values. |
| 34 | * Allows subsequent call to VHOST_OWNER_SET to succeed. */ |
| Yuanhan Liu | 60915dc | 2015-11-11 21:24:37 +0800 | [diff] [blame] | 35 | #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 36 | |
| 37 | /* Set up/modify memory layout */ |
| 38 | #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) |
| 39 | |
| 40 | /* Write logging setup. */ |
| 41 | /* Memory writes can optionally be logged by setting bit at an offset |
| 42 | * (calculated from the physical address) from specified log base. |
| 43 | * The bit is set using an atomic 32 bit operation. */ |
| 44 | /* Set base address for logging. */ |
| 45 | #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) |
| 46 | /* Specify an eventfd file descriptor to signal on log write. */ |
| 47 | #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) |
| 48 | |
| 49 | /* Ring setup. */ |
| 50 | /* Set number of descriptors in ring. This parameter can not |
| 51 | * be modified while ring is running (bound to a device). */ |
| 52 | #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) |
| 53 | /* Set addresses for the ring. */ |
| 54 | #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) |
| 55 | /* Base value where queue looks for available descriptors */ |
| 56 | #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state) |
| 57 | /* Get accessor: reads index, writes value in num */ |
| 58 | #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state) |
| 59 | |
| Greg Kurz | 332f640 | 2015-06-17 15:23:29 +0200 | [diff] [blame] | 60 | /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN |
| 61 | * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL). |
| 62 | * The byte order cannot be changed while the device is active: trying to do so |
| 63 | * returns -EBUSY. |
| 64 | * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is |
| 65 | * set. |
| 66 | * Not all kernel configurations support this ioctl, but all configurations that |
| 67 | * support SET also support GET. |
| 68 | */ |
| 69 | #define VHOST_VRING_LITTLE_ENDIAN 0 |
| 70 | #define VHOST_VRING_BIG_ENDIAN 1 |
| 71 | #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state) |
| 72 | #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) |
| 73 | |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 74 | /* The following ioctls use eventfd file descriptors to signal and poll |
| 75 | * for events. */ |
| 76 | |
| 77 | /* Set eventfd to poll for added buffers */ |
| 78 | #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) |
| 79 | /* Set eventfd to signal when buffers have beed used */ |
| 80 | #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) |
| 81 | /* Set eventfd to signal an error */ |
| 82 | #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) |
| Paolo Bonzini | b89485a | 2016-03-25 13:15:01 +0100 | [diff] [blame] | 83 | /* Set busy loop timeout (in us) */ |
| 84 | #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \ |
| 85 | struct vhost_vring_state) |
| 86 | /* Get busy loop timeout (in us) */ |
| 87 | #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ |
| 88 | struct vhost_vring_state) |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 89 | |
| Cornelia Huck | d36f7de | 2018-08-08 16:19:49 +0200 | [diff] [blame] | 90 | /* Set or get vhost backend capability */ |
| 91 | |
| Cornelia Huck | d36f7de | 2018-08-08 16:19:49 +0200 | [diff] [blame] | 92 | #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) |
| Cornelia Huck | 8f3cd25 | 2018-10-11 11:44:05 +0200 | [diff] [blame] | 93 | #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) |
| Cornelia Huck | d36f7de | 2018-08-08 16:19:49 +0200 | [diff] [blame] | 94 | |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 95 | /* VHOST_NET specific defines */ |
| 96 | |
| 97 | /* Attach virtio net ring to a raw socket, or tap device. |
| 98 | * The socket must be already bound to an ethernet device, this device will be |
| 99 | * used for transmit. Pass fd -1 to unbind from the socket and the transmit |
| 100 | * device. This can be used to stop the ring (e.g. for migration). */ |
| 101 | #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file) |
| 102 | |
| Paolo Bonzini | da054c6 | 2019-01-04 09:27:31 +0100 | [diff] [blame] | 103 | /* VHOST_SCSI specific defines */ |
| Alexey Kardashevskiy | e098b45 | 2013-06-12 17:26:55 +1000 | [diff] [blame] | 104 | |
| 105 | #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target) |
| 106 | #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target) |
| 107 | /* Changing this breaks userspace. */ |
| 108 | #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int) |
| 109 | /* Set and get the events missed flag */ |
| 110 | #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32) |
| 111 | #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32) |
| 112 | |
| Cornelia Huck | dbdfea9 | 2016-08-15 17:37:44 +0200 | [diff] [blame] | 113 | /* VHOST_VSOCK specific defines */ |
| 114 | |
| 115 | #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64) |
| 116 | #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int) |
| 117 | |
| Cornelia Huck | dc6f8d4 | 2020-04-27 12:24:14 +0200 | [diff] [blame] | 118 | /* VHOST_VDPA specific defines */ |
| 119 | |
| 120 | /* Get the device id. The device ids follow the same definition of |
| 121 | * the device id defined in virtio-spec. |
| 122 | */ |
| 123 | #define VHOST_VDPA_GET_DEVICE_ID _IOR(VHOST_VIRTIO, 0x70, __u32) |
| 124 | /* Get and set the status. The status bits follow the same definition |
| 125 | * of the device status defined in virtio-spec. |
| 126 | */ |
| 127 | #define VHOST_VDPA_GET_STATUS _IOR(VHOST_VIRTIO, 0x71, __u8) |
| 128 | #define VHOST_VDPA_SET_STATUS _IOW(VHOST_VIRTIO, 0x72, __u8) |
| 129 | /* Get and set the device config. The device config follows the same |
| 130 | * definition of the device config defined in virtio-spec. |
| 131 | */ |
| 132 | #define VHOST_VDPA_GET_CONFIG _IOR(VHOST_VIRTIO, 0x73, \ |
| 133 | struct vhost_vdpa_config) |
| 134 | #define VHOST_VDPA_SET_CONFIG _IOW(VHOST_VIRTIO, 0x74, \ |
| 135 | struct vhost_vdpa_config) |
| 136 | /* Enable/disable the ring. */ |
| 137 | #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, \ |
| 138 | struct vhost_vring_state) |
| 139 | /* Get the max ring size. */ |
| 140 | #define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16) |
| 141 | |
| Cornelia Huck | f76b348 | 2020-06-09 16:26:53 +0200 | [diff] [blame] | 142 | /* Set event fd for config interrupt*/ |
| 143 | #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) |
| Eric Farman | b3c818a | 2021-01-04 21:20:56 +0100 | [diff] [blame] | 144 | |
| 145 | /* Get the valid iova range */ |
| 146 | #define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ |
| 147 | struct vhost_vdpa_iova_range) |
| Alex Williamson | e408206 | 2022-05-13 08:20:08 -0600 | [diff] [blame] | 148 | /* Get the config size */ |
| 149 | #define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32) |
| 150 | |
| 151 | /* Get the count of all virtqueues */ |
| 152 | #define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32) |
| 153 | |
| Chenyi Qiang | d525f73 | 2022-09-15 17:10:35 +0800 | [diff] [blame] | 154 | /* Get the number of virtqueue groups. */ |
| 155 | #define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32) |
| 156 | |
| 157 | /* Get the number of address spaces. */ |
| 158 | #define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int) |
| 159 | |
| 160 | /* Get the group for a virtqueue: read index, write group in num, |
| 161 | * The virtqueue index is stored in the index field of |
| 162 | * vhost_vring_state. The group for this specific virtqueue is |
| 163 | * returned via num field of vhost_vring_state. |
| 164 | */ |
| 165 | #define VHOST_VDPA_GET_VRING_GROUP _IOWR(VHOST_VIRTIO, 0x7B, \ |
| 166 | struct vhost_vring_state) |
| 167 | /* Set the ASID for a virtqueue group. The group index is stored in |
| 168 | * the index field of vhost_vring_state, the ASID associated with this |
| 169 | * group is stored at num field of vhost_vring_state. |
| 170 | */ |
| 171 | #define VHOST_VDPA_SET_GROUP_ASID _IOW(VHOST_VIRTIO, 0x7C, \ |
| 172 | struct vhost_vring_state) |
| 173 | |
| 174 | /* Suspend a device so it does not process virtqueue requests anymore |
| 175 | * |
| 176 | * After the return of ioctl the device must preserve all the necessary state |
| 177 | * (the virtqueue vring base plus the possible device specific states) that is |
| 178 | * required for restoring in the future. The device must not change its |
| 179 | * configuration after that point. |
| 180 | */ |
| 181 | #define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D) |
| 182 | |
| David 'Digit' Turner | c5c0fdb | 2023-04-05 19:21:09 +0200 | [diff] [blame] | 183 | /* Resume a device so it can resume processing virtqueue requests |
| 184 | * |
| 185 | * After the return of this ioctl the device will have restored all the |
| 186 | * necessary states and it is fully operational to continue processing the |
| 187 | * virtqueue descriptors. |
| 188 | */ |
| 189 | #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) |
| 190 | |
| Jan Kiszka | 51b24e3 | 2011-06-08 16:10:56 +0200 | [diff] [blame] | 191 | #endif |