vhost.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef _LINUX_VHOST_H
  2. #define _LINUX_VHOST_H
  3. /* Userspace interface for in-kernel virtio accelerators. */
  4. /* vhost is used to reduce the number of system calls involved in virtio.
  5. *
  6. * Existing virtio net code is used in the guest without modification.
  7. *
  8. * This header includes interface used by userspace hypervisor for
  9. * device configuration.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/ioctl.h>
  13. #include <linux/virtio_config.h>
  14. #include <linux/virtio_ring.h>
  15. struct vhost_vring_state {
  16. unsigned int index;
  17. unsigned int num;
  18. };
  19. struct vhost_vring_file {
  20. unsigned int index;
  21. int fd; /* Pass -1 to unbind from file. */
  22. };
  23. struct vhost_vring_addr {
  24. unsigned int index;
  25. /* Option flags. */
  26. unsigned int flags;
  27. /* Flag values: */
  28. /* Whether log address is valid. If set enables logging. */
  29. #define VHOST_VRING_F_LOG 0
  30. /* Start of array of descriptors (virtually contiguous) */
  31. __u64 desc_user_addr;
  32. /* Used structure address. Must be 32 bit aligned */
  33. __u64 used_user_addr;
  34. /* Available structure address. Must be 16 bit aligned */
  35. __u64 avail_user_addr;
  36. /* Logging support. */
  37. /* Log writes to used structure, at offset calculated from specified
  38. * address. Address must be 32 bit aligned. */
  39. __u64 log_guest_addr;
  40. };
  41. struct vhost_memory_region {
  42. __u64 guest_phys_addr;
  43. __u64 memory_size; /* bytes */
  44. __u64 userspace_addr;
  45. __u64 flags_padding; /* No flags are currently specified. */
  46. };
  47. /* All region addresses and sizes must be 4K aligned. */
  48. #define VHOST_PAGE_SIZE 0x1000
  49. struct vhost_memory {
  50. __u32 nregions;
  51. __u32 padding;
  52. struct vhost_memory_region regions[0];
  53. };
  54. /* ioctls */
  55. #define VHOST_VIRTIO 0xAF
  56. /* Features bitmask for forward compatibility. Transport bits are used for
  57. * vhost specific features. */
  58. #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
  59. #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
  60. /* Set current process as the (exclusive) owner of this file descriptor. This
  61. * must be called before any other vhost command. Further calls to
  62. * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
  63. #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
  64. /* Give up ownership, and reset the device to default values.
  65. * Allows subsequent call to VHOST_OWNER_SET to succeed. */
  66. #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
  67. /* Set up/modify memory layout */
  68. #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
  69. /* Write logging setup. */
  70. /* Memory writes can optionally be logged by setting bit at an offset
  71. * (calculated from the physical address) from specified log base.
  72. * The bit is set using an atomic 32 bit operation. */
  73. /* Set base address for logging. */
  74. #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
  75. /* Specify an eventfd file descriptor to signal on log write. */
  76. #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
  77. /* Ring setup. */
  78. /* Set number of descriptors in ring. This parameter can not
  79. * be modified while ring is running (bound to a device). */
  80. #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
  81. /* Set addresses for the ring. */
  82. #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
  83. /* Base value where queue looks for available descriptors */
  84. #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
  85. /* Get accessor: reads index, writes value in num */
  86. #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
  87. /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
  88. * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
  89. * The byte order cannot be changed while the device is active: trying to do so
  90. * returns -EBUSY.
  91. * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
  92. * set.
  93. * Not all kernel configurations support this ioctl, but all configurations that
  94. * support SET also support GET.
  95. */
  96. #define VHOST_VRING_LITTLE_ENDIAN 0
  97. #define VHOST_VRING_BIG_ENDIAN 1
  98. #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
  99. #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
  100. /* The following ioctls use eventfd file descriptors to signal and poll
  101. * for events. */
  102. /* Set eventfd to poll for added buffers */
  103. #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
  104. /* Set eventfd to signal when buffers have beed used */
  105. #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
  106. /* Set eventfd to signal an error */
  107. #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
  108. /* VHOST_NET specific defines */
  109. /* Attach virtio net ring to a raw socket, or tap device.
  110. * The socket must be already bound to an ethernet device, this device will be
  111. * used for transmit. Pass fd -1 to unbind from the socket and the transmit
  112. * device. This can be used to stop the ring (e.g. for migration). */
  113. #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
  114. /* Feature bits */
  115. /* Log all write descriptors. Can be changed while device is active. */
  116. #define VHOST_F_LOG_ALL 26
  117. /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
  118. #define VHOST_NET_F_VIRTIO_NET_HDR 27
  119. /* VHOST_SCSI specific definitions */
  120. /*
  121. * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
  122. *
  123. * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
  124. * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
  125. * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
  126. * All the targets under vhost_wwpn can be seen and used by guset.
  127. */
  128. #define VHOST_SCSI_ABI_VERSION 1
  129. struct vhost_scsi_target {
  130. int abi_version;
  131. char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
  132. unsigned short vhost_tpgt;
  133. unsigned short reserved;
  134. };
  135. #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
  136. #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
  137. /* Changing this breaks userspace. */
  138. #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
  139. /* Set and get the events missed flag */
  140. #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
  141. #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
  142. #endif