2
0

vhost.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. /* ioctls */
  16. #define VHOST_VIRTIO 0xAF
  17. /* Features bitmask for forward compatibility. Transport bits are used for
  18. * vhost specific features. */
  19. #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
  20. #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
  21. /* Set current process as the (exclusive) owner of this file descriptor. This
  22. * must be called before any other vhost command. Further calls to
  23. * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
  24. #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
  25. /* Give up ownership, and reset the device to default values.
  26. * Allows subsequent call to VHOST_OWNER_SET to succeed. */
  27. #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
  28. /* Set up/modify memory layout */
  29. #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
  30. /* Write logging setup. */
  31. /* Memory writes can optionally be logged by setting bit at an offset
  32. * (calculated from the physical address) from specified log base.
  33. * The bit is set using an atomic 32 bit operation. */
  34. /* Set base address for logging. */
  35. #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
  36. /* Specify an eventfd file descriptor to signal on log write. */
  37. #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
  38. /* Ring setup. */
  39. /* Set number of descriptors in ring. This parameter can not
  40. * be modified while ring is running (bound to a device). */
  41. #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
  42. /* Set addresses for the ring. */
  43. #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
  44. /* Base value where queue looks for available descriptors */
  45. #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
  46. /* Get accessor: reads index, writes value in num */
  47. #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
  48. /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
  49. * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
  50. * The byte order cannot be changed while the device is active: trying to do so
  51. * returns -EBUSY.
  52. * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
  53. * set.
  54. * Not all kernel configurations support this ioctl, but all configurations that
  55. * support SET also support GET.
  56. */
  57. #define VHOST_VRING_LITTLE_ENDIAN 0
  58. #define VHOST_VRING_BIG_ENDIAN 1
  59. #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
  60. #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
  61. /* The following ioctls use eventfd file descriptors to signal and poll
  62. * for events. */
  63. /* Set eventfd to poll for added buffers */
  64. #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
  65. /* Set eventfd to signal when buffers have beed used */
  66. #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
  67. /* Set eventfd to signal an error */
  68. #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
  69. /* Set busy loop timeout (in us) */
  70. #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \
  71. struct vhost_vring_state)
  72. /* Get busy loop timeout (in us) */
  73. #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
  74. struct vhost_vring_state)
  75. /* Set or get vhost backend capability */
  76. /* Use message type V2 */
  77. #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
  78. #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
  79. #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
  80. /* VHOST_NET specific defines */
  81. /* Attach virtio net ring to a raw socket, or tap device.
  82. * The socket must be already bound to an ethernet device, this device will be
  83. * used for transmit. Pass fd -1 to unbind from the socket and the transmit
  84. * device. This can be used to stop the ring (e.g. for migration). */
  85. #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
  86. /* VHOST_SCSI specific defines */
  87. #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
  88. #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
  89. /* Changing this breaks userspace. */
  90. #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
  91. /* Set and get the events missed flag */
  92. #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
  93. #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
  94. /* VHOST_VSOCK specific defines */
  95. #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64)
  96. #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int)
  97. #endif