1*621191d7SNuno Das Neves /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2*621191d7SNuno Das Neves /* 3*621191d7SNuno Das Neves * Userspace interfaces for /dev/mshv* devices and derived fds 4*621191d7SNuno Das Neves * 5*621191d7SNuno Das Neves * This file is divided into sections containing data structures and IOCTLs for 6*621191d7SNuno Das Neves * a particular set of related devices or derived file descriptors. 7*621191d7SNuno Das Neves * 8*621191d7SNuno Das Neves * The IOCTL definitions are at the end of each section. They are grouped by 9*621191d7SNuno Das Neves * device/fd, so that new IOCTLs can easily be added with a monotonically 10*621191d7SNuno Das Neves * increasing number. 11*621191d7SNuno Das Neves */ 12*621191d7SNuno Das Neves #ifndef _UAPI_LINUX_MSHV_H 13*621191d7SNuno Das Neves #define _UAPI_LINUX_MSHV_H 14*621191d7SNuno Das Neves 15*621191d7SNuno Das Neves #include <linux/types.h> 16*621191d7SNuno Das Neves 17*621191d7SNuno Das Neves #define MSHV_IOCTL 0xB8 18*621191d7SNuno Das Neves 19*621191d7SNuno Das Neves /* 20*621191d7SNuno Das Neves ******************************************* 21*621191d7SNuno Das Neves * Entry point to main VMM APIs: /dev/mshv * 22*621191d7SNuno Das Neves ******************************************* 23*621191d7SNuno Das Neves */ 24*621191d7SNuno Das Neves 25*621191d7SNuno Das Neves enum { 26*621191d7SNuno Das Neves MSHV_PT_BIT_LAPIC, 27*621191d7SNuno Das Neves MSHV_PT_BIT_X2APIC, 28*621191d7SNuno Das Neves MSHV_PT_BIT_GPA_SUPER_PAGES, 29*621191d7SNuno Das Neves MSHV_PT_BIT_COUNT, 30*621191d7SNuno Das Neves }; 31*621191d7SNuno Das Neves 32*621191d7SNuno Das Neves #define MSHV_PT_FLAGS_MASK ((1 << MSHV_PT_BIT_COUNT) - 1) 33*621191d7SNuno Das Neves 34*621191d7SNuno Das Neves enum { 35*621191d7SNuno Das Neves MSHV_PT_ISOLATION_NONE, 36*621191d7SNuno Das Neves MSHV_PT_ISOLATION_COUNT, 37*621191d7SNuno Das Neves }; 38*621191d7SNuno Das Neves 39*621191d7SNuno Das Neves /** 40*621191d7SNuno Das Neves * struct mshv_create_partition - arguments for MSHV_CREATE_PARTITION 41*621191d7SNuno Das Neves * @pt_flags: Bitmask of 1 << MSHV_PT_BIT_* 42*621191d7SNuno Das Neves * @pt_isolation: MSHV_PT_ISOLATION_* 43*621191d7SNuno Das Neves * 44*621191d7SNuno Das Neves * Returns a file descriptor to act as a handle to a guest partition. 45*621191d7SNuno Das Neves * At this point the partition is not yet initialized in the hypervisor. 46*621191d7SNuno Das Neves * Some operations must be done with the partition in this state, e.g. setting 47*621191d7SNuno Das Neves * so-called "early" partition properties. The partition can then be 48*621191d7SNuno Das Neves * initialized with MSHV_INITIALIZE_PARTITION. 49*621191d7SNuno Das Neves */ 50*621191d7SNuno Das Neves struct mshv_create_partition { 51*621191d7SNuno Das Neves __u64 pt_flags; 52*621191d7SNuno Das Neves __u64 pt_isolation; 53*621191d7SNuno Das Neves }; 54*621191d7SNuno Das Neves 55*621191d7SNuno Das Neves /* /dev/mshv */ 56*621191d7SNuno Das Neves #define MSHV_CREATE_PARTITION _IOW(MSHV_IOCTL, 0x00, struct mshv_create_partition) 57*621191d7SNuno Das Neves 58*621191d7SNuno Das Neves /* 59*621191d7SNuno Das Neves ************************ 60*621191d7SNuno Das Neves * Child partition APIs * 61*621191d7SNuno Das Neves ************************ 62*621191d7SNuno Das Neves */ 63*621191d7SNuno Das Neves 64*621191d7SNuno Das Neves struct mshv_create_vp { 65*621191d7SNuno Das Neves __u32 vp_index; 66*621191d7SNuno Das Neves }; 67*621191d7SNuno Das Neves 68*621191d7SNuno Das Neves enum { 69*621191d7SNuno Das Neves MSHV_SET_MEM_BIT_WRITABLE, 70*621191d7SNuno Das Neves MSHV_SET_MEM_BIT_EXECUTABLE, 71*621191d7SNuno Das Neves MSHV_SET_MEM_BIT_UNMAP, 72*621191d7SNuno Das Neves MSHV_SET_MEM_BIT_COUNT 73*621191d7SNuno Das Neves }; 74*621191d7SNuno Das Neves 75*621191d7SNuno Das Neves #define MSHV_SET_MEM_FLAGS_MASK ((1 << MSHV_SET_MEM_BIT_COUNT) - 1) 76*621191d7SNuno Das Neves 77*621191d7SNuno Das Neves /* The hypervisor's "native" page size */ 78*621191d7SNuno Das Neves #define MSHV_HV_PAGE_SIZE 0x1000 79*621191d7SNuno Das Neves 80*621191d7SNuno Das Neves /** 81*621191d7SNuno Das Neves * struct mshv_user_mem_region - arguments for MSHV_SET_GUEST_MEMORY 82*621191d7SNuno Das Neves * @size: Size of the memory region (bytes). Must be aligned to 83*621191d7SNuno Das Neves * MSHV_HV_PAGE_SIZE 84*621191d7SNuno Das Neves * @guest_pfn: Base guest page number to map 85*621191d7SNuno Das Neves * @userspace_addr: Base address of userspace memory. Must be aligned to 86*621191d7SNuno Das Neves * MSHV_HV_PAGE_SIZE 87*621191d7SNuno Das Neves * @flags: Bitmask of 1 << MSHV_SET_MEM_BIT_*. If (1 << MSHV_SET_MEM_BIT_UNMAP) 88*621191d7SNuno Das Neves * is set, ignore other bits. 89*621191d7SNuno Das Neves * @rsvd: MBZ 90*621191d7SNuno Das Neves * 91*621191d7SNuno Das Neves * Map or unmap a region of userspace memory to Guest Physical Addresses (GPA). 92*621191d7SNuno Das Neves * Mappings can't overlap in GPA space or userspace. 93*621191d7SNuno Das Neves * To unmap, these fields must match an existing mapping. 94*621191d7SNuno Das Neves */ 95*621191d7SNuno Das Neves struct mshv_user_mem_region { 96*621191d7SNuno Das Neves __u64 size; 97*621191d7SNuno Das Neves __u64 guest_pfn; 98*621191d7SNuno Das Neves __u64 userspace_addr; 99*621191d7SNuno Das Neves __u8 flags; 100*621191d7SNuno Das Neves __u8 rsvd[7]; 101*621191d7SNuno Das Neves }; 102*621191d7SNuno Das Neves 103*621191d7SNuno Das Neves enum { 104*621191d7SNuno Das Neves MSHV_IRQFD_BIT_DEASSIGN, 105*621191d7SNuno Das Neves MSHV_IRQFD_BIT_RESAMPLE, 106*621191d7SNuno Das Neves MSHV_IRQFD_BIT_COUNT, 107*621191d7SNuno Das Neves }; 108*621191d7SNuno Das Neves 109*621191d7SNuno Das Neves #define MSHV_IRQFD_FLAGS_MASK ((1 << MSHV_IRQFD_BIT_COUNT) - 1) 110*621191d7SNuno Das Neves 111*621191d7SNuno Das Neves struct mshv_user_irqfd { 112*621191d7SNuno Das Neves __s32 fd; 113*621191d7SNuno Das Neves __s32 resamplefd; 114*621191d7SNuno Das Neves __u32 gsi; 115*621191d7SNuno Das Neves __u32 flags; 116*621191d7SNuno Das Neves }; 117*621191d7SNuno Das Neves 118*621191d7SNuno Das Neves enum { 119*621191d7SNuno Das Neves MSHV_IOEVENTFD_BIT_DATAMATCH, 120*621191d7SNuno Das Neves MSHV_IOEVENTFD_BIT_PIO, 121*621191d7SNuno Das Neves MSHV_IOEVENTFD_BIT_DEASSIGN, 122*621191d7SNuno Das Neves MSHV_IOEVENTFD_BIT_COUNT, 123*621191d7SNuno Das Neves }; 124*621191d7SNuno Das Neves 125*621191d7SNuno Das Neves #define MSHV_IOEVENTFD_FLAGS_MASK ((1 << MSHV_IOEVENTFD_BIT_COUNT) - 1) 126*621191d7SNuno Das Neves 127*621191d7SNuno Das Neves struct mshv_user_ioeventfd { 128*621191d7SNuno Das Neves __u64 datamatch; 129*621191d7SNuno Das Neves __u64 addr; /* legal pio/mmio address */ 130*621191d7SNuno Das Neves __u32 len; /* 1, 2, 4, or 8 bytes */ 131*621191d7SNuno Das Neves __s32 fd; 132*621191d7SNuno Das Neves __u32 flags; 133*621191d7SNuno Das Neves __u8 rsvd[4]; 134*621191d7SNuno Das Neves }; 135*621191d7SNuno Das Neves 136*621191d7SNuno Das Neves struct mshv_user_irq_entry { 137*621191d7SNuno Das Neves __u32 gsi; 138*621191d7SNuno Das Neves __u32 address_lo; 139*621191d7SNuno Das Neves __u32 address_hi; 140*621191d7SNuno Das Neves __u32 data; 141*621191d7SNuno Das Neves }; 142*621191d7SNuno Das Neves 143*621191d7SNuno Das Neves struct mshv_user_irq_table { 144*621191d7SNuno Das Neves __u32 nr; 145*621191d7SNuno Das Neves __u32 rsvd; /* MBZ */ 146*621191d7SNuno Das Neves struct mshv_user_irq_entry entries[]; 147*621191d7SNuno Das Neves }; 148*621191d7SNuno Das Neves 149*621191d7SNuno Das Neves enum { 150*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_TYPE_ACCESSED, 151*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_TYPE_DIRTY, 152*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_TYPE_COUNT /* Count of enum members */ 153*621191d7SNuno Das Neves }; 154*621191d7SNuno Das Neves 155*621191d7SNuno Das Neves enum { 156*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_OP_NOOP, 157*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_OP_CLEAR, 158*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_OP_SET, 159*621191d7SNuno Das Neves MSHV_GPAP_ACCESS_OP_COUNT /* Count of enum members */ 160*621191d7SNuno Das Neves }; 161*621191d7SNuno Das Neves 162*621191d7SNuno Das Neves /** 163*621191d7SNuno Das Neves * struct mshv_gpap_access_bitmap - arguments for MSHV_GET_GPAP_ACCESS_BITMAP 164*621191d7SNuno Das Neves * @access_type: MSHV_GPAP_ACCESS_TYPE_* - The type of access to record in the 165*621191d7SNuno Das Neves * bitmap 166*621191d7SNuno Das Neves * @access_op: MSHV_GPAP_ACCESS_OP_* - Allows an optional clear or set of all 167*621191d7SNuno Das Neves * the access states in the range, after retrieving the current 168*621191d7SNuno Das Neves * states. 169*621191d7SNuno Das Neves * @rsvd: MBZ 170*621191d7SNuno Das Neves * @page_count: Number of pages 171*621191d7SNuno Das Neves * @gpap_base: Base gpa page number 172*621191d7SNuno Das Neves * @bitmap_ptr: Output buffer for bitmap, at least (page_count + 7) / 8 bytes 173*621191d7SNuno Das Neves * 174*621191d7SNuno Das Neves * Retrieve a bitmap of either ACCESSED or DIRTY bits for a given range of guest 175*621191d7SNuno Das Neves * memory, and optionally clear or set the bits. 176*621191d7SNuno Das Neves */ 177*621191d7SNuno Das Neves struct mshv_gpap_access_bitmap { 178*621191d7SNuno Das Neves __u8 access_type; 179*621191d7SNuno Das Neves __u8 access_op; 180*621191d7SNuno Das Neves __u8 rsvd[6]; 181*621191d7SNuno Das Neves __u64 page_count; 182*621191d7SNuno Das Neves __u64 gpap_base; 183*621191d7SNuno Das Neves __u64 bitmap_ptr; 184*621191d7SNuno Das Neves }; 185*621191d7SNuno Das Neves 186*621191d7SNuno Das Neves /** 187*621191d7SNuno Das Neves * struct mshv_root_hvcall - arguments for MSHV_ROOT_HVCALL 188*621191d7SNuno Das Neves * @code: Hypercall code (HVCALL_*) 189*621191d7SNuno Das Neves * @reps: in: Rep count ('repcount') 190*621191d7SNuno Das Neves * out: Reps completed ('repcomp'). MBZ unless rep hvcall 191*621191d7SNuno Das Neves * @in_sz: Size of input incl rep data. <= MSHV_HV_PAGE_SIZE 192*621191d7SNuno Das Neves * @out_sz: Size of output buffer. <= MSHV_HV_PAGE_SIZE. MBZ if out_ptr is 0 193*621191d7SNuno Das Neves * @status: in: MBZ 194*621191d7SNuno Das Neves * out: HV_STATUS_* from hypercall 195*621191d7SNuno Das Neves * @rsvd: MBZ 196*621191d7SNuno Das Neves * @in_ptr: Input data buffer (struct hv_input_*). If used with partition or 197*621191d7SNuno Das Neves * vp fd, partition id field is populated by kernel. 198*621191d7SNuno Das Neves * @out_ptr: Output data buffer (optional) 199*621191d7SNuno Das Neves */ 200*621191d7SNuno Das Neves struct mshv_root_hvcall { 201*621191d7SNuno Das Neves __u16 code; 202*621191d7SNuno Das Neves __u16 reps; 203*621191d7SNuno Das Neves __u16 in_sz; 204*621191d7SNuno Das Neves __u16 out_sz; 205*621191d7SNuno Das Neves __u16 status; 206*621191d7SNuno Das Neves __u8 rsvd[6]; 207*621191d7SNuno Das Neves __u64 in_ptr; 208*621191d7SNuno Das Neves __u64 out_ptr; 209*621191d7SNuno Das Neves }; 210*621191d7SNuno Das Neves 211*621191d7SNuno Das Neves /* Partition fds created with MSHV_CREATE_PARTITION */ 212*621191d7SNuno Das Neves #define MSHV_INITIALIZE_PARTITION _IO(MSHV_IOCTL, 0x00) 213*621191d7SNuno Das Neves #define MSHV_CREATE_VP _IOW(MSHV_IOCTL, 0x01, struct mshv_create_vp) 214*621191d7SNuno Das Neves #define MSHV_SET_GUEST_MEMORY _IOW(MSHV_IOCTL, 0x02, struct mshv_user_mem_region) 215*621191d7SNuno Das Neves #define MSHV_IRQFD _IOW(MSHV_IOCTL, 0x03, struct mshv_user_irqfd) 216*621191d7SNuno Das Neves #define MSHV_IOEVENTFD _IOW(MSHV_IOCTL, 0x04, struct mshv_user_ioeventfd) 217*621191d7SNuno Das Neves #define MSHV_SET_MSI_ROUTING _IOW(MSHV_IOCTL, 0x05, struct mshv_user_irq_table) 218*621191d7SNuno Das Neves #define MSHV_GET_GPAP_ACCESS_BITMAP _IOWR(MSHV_IOCTL, 0x06, struct mshv_gpap_access_bitmap) 219*621191d7SNuno Das Neves /* Generic hypercall */ 220*621191d7SNuno Das Neves #define MSHV_ROOT_HVCALL _IOWR(MSHV_IOCTL, 0x07, struct mshv_root_hvcall) 221*621191d7SNuno Das Neves 222*621191d7SNuno Das Neves /* 223*621191d7SNuno Das Neves ******************************** 224*621191d7SNuno Das Neves * VP APIs for child partitions * 225*621191d7SNuno Das Neves ******************************** 226*621191d7SNuno Das Neves */ 227*621191d7SNuno Das Neves 228*621191d7SNuno Das Neves #define MSHV_RUN_VP_BUF_SZ 256 229*621191d7SNuno Das Neves 230*621191d7SNuno Das Neves /* 231*621191d7SNuno Das Neves * VP state pages may be mapped to userspace via mmap(). 232*621191d7SNuno Das Neves * To specify which state page, use MSHV_VP_MMAP_OFFSET_ values multiplied by 233*621191d7SNuno Das Neves * the system page size. 234*621191d7SNuno Das Neves * e.g. 235*621191d7SNuno Das Neves * long page_size = sysconf(_SC_PAGE_SIZE); 236*621191d7SNuno Das Neves * void *reg_page = mmap(NULL, MSHV_HV_PAGE_SIZE, PROT_READ|PROT_WRITE, 237*621191d7SNuno Das Neves * MAP_SHARED, vp_fd, 238*621191d7SNuno Das Neves * MSHV_VP_MMAP_OFFSET_REGISTERS * page_size); 239*621191d7SNuno Das Neves */ 240*621191d7SNuno Das Neves enum { 241*621191d7SNuno Das Neves MSHV_VP_MMAP_OFFSET_REGISTERS, 242*621191d7SNuno Das Neves MSHV_VP_MMAP_OFFSET_INTERCEPT_MESSAGE, 243*621191d7SNuno Das Neves MSHV_VP_MMAP_OFFSET_GHCB, 244*621191d7SNuno Das Neves MSHV_VP_MMAP_OFFSET_COUNT 245*621191d7SNuno Das Neves }; 246*621191d7SNuno Das Neves 247*621191d7SNuno Das Neves /** 248*621191d7SNuno Das Neves * struct mshv_run_vp - argument for MSHV_RUN_VP 249*621191d7SNuno Das Neves * @msg_buf: On success, the intercept message is copied here. It can be 250*621191d7SNuno Das Neves * interpreted using the relevant hypervisor definitions. 251*621191d7SNuno Das Neves */ 252*621191d7SNuno Das Neves struct mshv_run_vp { 253*621191d7SNuno Das Neves __u8 msg_buf[MSHV_RUN_VP_BUF_SZ]; 254*621191d7SNuno Das Neves }; 255*621191d7SNuno Das Neves 256*621191d7SNuno Das Neves enum { 257*621191d7SNuno Das Neves MSHV_VP_STATE_LAPIC, /* Local interrupt controller state (either arch) */ 258*621191d7SNuno Das Neves MSHV_VP_STATE_XSAVE, /* XSAVE data in compacted form (x86_64) */ 259*621191d7SNuno Das Neves MSHV_VP_STATE_SIMP, 260*621191d7SNuno Das Neves MSHV_VP_STATE_SIEFP, 261*621191d7SNuno Das Neves MSHV_VP_STATE_SYNTHETIC_TIMERS, 262*621191d7SNuno Das Neves MSHV_VP_STATE_COUNT, 263*621191d7SNuno Das Neves }; 264*621191d7SNuno Das Neves 265*621191d7SNuno Das Neves /** 266*621191d7SNuno Das Neves * struct mshv_get_set_vp_state - arguments for MSHV_[GET,SET]_VP_STATE 267*621191d7SNuno Das Neves * @type: MSHV_VP_STATE_* 268*621191d7SNuno Das Neves * @rsvd: MBZ 269*621191d7SNuno Das Neves * @buf_sz: in: 4k page-aligned size of buffer 270*621191d7SNuno Das Neves * out: Actual size of data (on EINVAL, check this to see if buffer 271*621191d7SNuno Das Neves * was too small) 272*621191d7SNuno Das Neves * @buf_ptr: 4k page-aligned data buffer 273*621191d7SNuno Das Neves */ 274*621191d7SNuno Das Neves struct mshv_get_set_vp_state { 275*621191d7SNuno Das Neves __u8 type; 276*621191d7SNuno Das Neves __u8 rsvd[3]; 277*621191d7SNuno Das Neves __u32 buf_sz; 278*621191d7SNuno Das Neves __u64 buf_ptr; 279*621191d7SNuno Das Neves }; 280*621191d7SNuno Das Neves 281*621191d7SNuno Das Neves /* VP fds created with MSHV_CREATE_VP */ 282*621191d7SNuno Das Neves #define MSHV_RUN_VP _IOR(MSHV_IOCTL, 0x00, struct mshv_run_vp) 283*621191d7SNuno Das Neves #define MSHV_GET_VP_STATE _IOWR(MSHV_IOCTL, 0x01, struct mshv_get_set_vp_state) 284*621191d7SNuno Das Neves #define MSHV_SET_VP_STATE _IOWR(MSHV_IOCTL, 0x02, struct mshv_get_set_vp_state) 285*621191d7SNuno Das Neves /* 286*621191d7SNuno Das Neves * Generic hypercall 287*621191d7SNuno Das Neves * Defined above in partition IOCTLs, avoid redefining it here 288*621191d7SNuno Das Neves * #define MSHV_ROOT_HVCALL _IOWR(MSHV_IOCTL, 0x07, struct mshv_root_hvcall) 289*621191d7SNuno Das Neves */ 290*621191d7SNuno Das Neves 291*621191d7SNuno Das Neves #endif 292