June 2025 | ||||||
Mo | Tu | We | Th | Fr | Sa | Su |
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
001: #ifndef _LINUX_VHOST_H 002: #define _LINUX_VHOST_H 003: /* Userspace interface for in-kernel virtio accelerators. */ 004: 005: /* vhost is used to reduce the number of system calls involved in virtio. 006: * 007: * Existing virtio net code is used in the guest without modification. 008: * 009: * This header includes interface used by userspace hypervisor for 010: * device configuration. 011: */ 012: 013: #include <linux/types.h> 014: 015: #include <linux/ioctl.h> 016: #include <linux/virtio_config.h> 017: #include <linux/virtio_ring.h> 018: 019: struct vhost_vring_state { 020: unsigned int index; 021: unsigned int num; 022: }; 023: 024: struct vhost_vring_file { 025: unsigned int index; 026: int fd; /* Pass -1 to unbind from file. */ 027: 028: }; 029: 030: struct vhost_vring_addr { 031: unsigned int index; 032: /* Option flags. */ 033: unsigned int flags; 034: /* Flag values: */ 035: /* Whether log address is valid. If set enables logging. */ 036: #define VHOST_VRING_F_LOG 0 037: 038: /* Start of array of descriptors (virtually contiguous) */ 039: __u64 desc_user_addr; 040: /* Used structure address. Must be 32 bit aligned */ 041: __u64 used_user_addr; 042: /* Available structure address. Must be 16 bit aligned */ 043: __u64 avail_user_addr; 044: /* Logging support. */ 045: /* Log writes to used structure, at offset calculated from specified 046: * address. Address must be 32 bit aligned. */ 047: __u64 log_guest_addr; 048: }; 049: 050: struct vhost_memory_region { 051: __u64 guest_phys_addr; 052: __u64 memory_size; /* bytes */ 053: __u64 userspace_addr; 054: __u64 flags_padding; /* No flags are currently specified. */ 055: }; 056: 057: /* All region addresses and sizes must be 4K aligned. */ 058: #define VHOST_PAGE_SIZE 0x1000 059: 060: struct vhost_memory { 061: __u32 nregions; 062: __u32 padding; 063: struct vhost_memory_region regions[0]; 064: }; 065: 066: /* ioctls */ 067: 068: #define VHOST_VIRTIO 0xAF 069: 070: /* Features bitmask for forward compatibility. Transport bits are used for 071: * vhost specific features. */ 072: #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) 073: #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) 074: 075: /* Set current process as the (exclusive) owner of this file descriptor. This 076: * must be called before any other vhost command. Further calls to 077: * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ 078: #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) 079: /* Give up ownership, and reset the device to default values. 080: * Allows subsequent call to VHOST_OWNER_SET to succeed. */ 081: #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) 082: 083: /* Set up/modify memory layout */ 084: #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) 085: 086: /* Write logging setup. */ 087: /* Memory writes can optionally be logged by setting bit at an offset 088: * (calculated from the physical address) from specified log base. 089: * The bit is set using an atomic 32 bit operation. */ 090: /* Set base address for logging. */ 091: #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) 092: /* Specify an eventfd file descriptor to signal on log write. */ 093: #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) 094: 095: /* Ring setup. */ 096: /* Set number of descriptors in ring. This parameter can not 097: * be modified while ring is running (bound to a device). */ 098: #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) 099: /* Set addresses for the ring. */ 100: #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) 101: /* Base value where queue looks for available descriptors */ 102: #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state) 103: /* Get accessor: reads index, writes value in num */ 104: #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state) 105: 106: /* The following ioctls use eventfd file descriptors to signal and poll 107: * for events. */ 108: 109: /* Set eventfd to poll for added buffers */ 110: #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) 111: /* Set eventfd to signal when buffers have beed used */ 112: #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) 113: /* Set eventfd to signal an error */ 114: #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) 115: 116: /* VHOST_NET specific defines */ 117: 118: /* Attach virtio net ring to a raw socket, or tap device. 119: * The socket must be already bound to an ethernet device, this device will be 120: * used for transmit. Pass fd -1 to unbind from the socket and the transmit 121: * device. This can be used to stop the ring (e.g. for migration). */ 122: #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file) 123: 124: /* Feature bits */ 125: /* Log all write descriptors. Can be changed while device is active. */ 126: #define VHOST_F_LOG_ALL 26 127: /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ 128: #define VHOST_NET_F_VIRTIO_NET_HDR 27 129: 130: #endif 131: