logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

vhost.h (10238B)


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