1 The Definitive KVM (Kernel-based Virtual Machine) API Documentation
2 ===================================================================
6 The kvm API is a set of ioctls that are issued to control various aspects
7 of a virtual machine. The ioctls belong to three classes
9 - System ioctls: These query and set global attributes which affect the
10 whole kvm subsystem. In addition a system ioctl is used to create
13 - VM ioctls: These query and set attributes that affect an entire virtual
14 machine, for example memory layout. In addition a VM ioctl is used to
15 create virtual cpus (vcpus).
17 Only run VM ioctls from the same process (address space) that was used
20 - vcpu ioctls: These query and set attributes that control the operation
21 of a single virtual cpu.
23 Only run vcpu ioctls from the same thread that was used to create the
28 The kvm API is centered around file descriptors. An initial
29 open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
30 can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
31 handle will create a VM file descriptor which can be used to issue VM
32 ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
33 and return a file descriptor pointing to it. Finally, ioctls on a vcpu
34 fd can be used to control the vcpu, including the important task of
35 actually running guest code.
37 In general file descriptors can be migrated among processes by means
38 of fork() and the SCM_RIGHTS facility of unix domain socket. These
39 kinds of tricks are explicitly not supported by kvm. While they will
40 not cause harm to the host, their actual behavior is not guaranteed by
41 the API. The only supported use is one virtual machine per process,
42 and one vcpu per thread.
46 As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
47 incompatible change are allowed. However, there is an extension
48 facility that allows backward-compatible extensions to the API to be
51 The extension mechanism is not based on on the Linux version number.
52 Instead, kvm defines extension identifiers and a facility to query
53 whether a particular extension identifier is available. If it is, a
54 set of ioctls is available for application use.
58 This section describes ioctls that can be used to control kvm guests.
59 For each ioctl, the following information is provided along with a
62 Capability: which KVM extension provides this ioctl. Can be 'basic',
63 which means that is will be provided by any kernel that supports
64 API version 12 (see section 4.1), or a KVM_CAP_xyz constant, which
65 means availability needs to be checked with KVM_CHECK_EXTENSION
68 Architectures: which instruction set architectures provide this ioctl.
69 x86 includes both i386 and x86_64.
71 Type: system, vm, or vcpu.
73 Parameters: what parameters are accepted by the ioctl.
75 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
76 are not detailed, but errors with specific meanings are.
78 4.1 KVM_GET_API_VERSION
84 Returns: the constant KVM_API_VERSION (=12)
86 This identifies the API version as the stable kvm API. It is not
87 expected that this number will change. However, Linux 2.6.20 and
88 2.6.21 report earlier versions; these are not documented and not
89 supported. Applications should refuse to run if KVM_GET_API_VERSION
90 returns a value other than 12. If this check passes, all ioctls
91 described as 'basic' will be available.
99 Returns: a VM fd that can be used to control the new virtual machine.
101 The new VM has no virtual cpus and no memory. An mmap() of a VM fd
102 will access the virtual machine's physical address space; offset zero
103 corresponds to guest physical address zero. Use of mmap() on a VM fd
104 is discouraged if userspace memory allocation (KVM_CAP_USER_MEMORY) is
107 4.3 KVM_GET_MSR_INDEX_LIST
112 Parameters: struct kvm_msr_list (in/out)
113 Returns: 0 on success; -1 on error
115 E2BIG: the msr index list is to be to fit in the array specified by
118 struct kvm_msr_list {
119 __u32 nmsrs; /* number of msrs in entries */
123 This ioctl returns the guest msrs that are supported. The list varies
124 by kvm version and host processor, but does not change otherwise. The
125 user fills in the size of the indices array in nmsrs, and in return
126 kvm adjusts nmsrs to reflect the actual number of msrs and fills in
127 the indices array with their numbers.
129 Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
130 not returned in the MSR list, as different vcpus can have a different number
131 of banks, as set via the KVM_X86_SETUP_MCE ioctl.
133 4.4 KVM_CHECK_EXTENSION
138 Parameters: extension identifier (KVM_CAP_*)
139 Returns: 0 if unsupported; 1 (or some other positive integer) if supported
141 The API allows the application to query about extensions to the core
142 kvm API. Userspace passes an extension identifier (an integer) and
143 receives an integer that describes the extension availability.
144 Generally 0 means no and 1 means yes, but some extensions may report
145 additional information in the integer return value.
147 4.5 KVM_GET_VCPU_MMAP_SIZE
153 Returns: size of vcpu mmap area, in bytes
155 The KVM_RUN ioctl (cf.) communicates with userspace via a shared
156 memory region. This ioctl returns the size of that region. See the
157 KVM_RUN documentation for details.
159 4.6 KVM_SET_MEMORY_REGION
164 Parameters: struct kvm_memory_region (in)
165 Returns: 0 on success, -1 on error
167 This ioctl is obsolete and has been removed.
174 Parameters: vcpu id (apic id on x86)
175 Returns: vcpu fd on success, -1 on error
177 This API adds a vcpu to a virtual machine. The vcpu id is a small integer
178 in the range [0, max_vcpus).
180 4.7 KVM_GET_DIRTY_LOG (vm ioctl)
185 Parameters: struct kvm_dirty_log (in/out)
186 Returns: 0 on success, -1 on error
188 /* for KVM_GET_DIRTY_LOG */
189 struct kvm_dirty_log {
193 void __user *dirty_bitmap; /* one bit per page */
198 Given a memory slot, return a bitmap containing any pages dirtied
199 since the last call to this ioctl. Bit 0 is the first page in the
200 memory slot. Ensure the entire structure is cleared to avoid padding
203 4.8 KVM_SET_MEMORY_ALIAS
208 Parameters: struct kvm_memory_alias (in)
209 Returns: 0 (success), -1 (error)
211 This ioctl is obsolete and has been removed.
219 Returns: 0 on success, -1 on error
221 EINTR: an unmasked signal is pending
223 This ioctl is used to run a guest virtual cpu. While there are no
224 explicit parameters, there is an implicit parameter block that can be
225 obtained by mmap()ing the vcpu fd at offset 0, with the size given by
226 KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
227 kvm_run' (see below).
234 Parameters: struct kvm_regs (out)
235 Returns: 0 on success, -1 on error
237 Reads the general purpose registers from the vcpu.
241 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
242 __u64 rax, rbx, rcx, rdx;
243 __u64 rsi, rdi, rsp, rbp;
244 __u64 r8, r9, r10, r11;
245 __u64 r12, r13, r14, r15;
254 Parameters: struct kvm_regs (in)
255 Returns: 0 on success, -1 on error
257 Writes the general purpose registers into the vcpu.
259 See KVM_GET_REGS for the data structure.
266 Parameters: struct kvm_sregs (out)
267 Returns: 0 on success, -1 on error
269 Reads special registers from the vcpu.
273 struct kvm_segment cs, ds, es, fs, gs, ss;
274 struct kvm_segment tr, ldt;
275 struct kvm_dtable gdt, idt;
276 __u64 cr0, cr2, cr3, cr4, cr8;
279 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
282 interrupt_bitmap is a bitmap of pending external interrupts. At most
283 one bit may be set. This interrupt has been acknowledged by the APIC
284 but not yet injected into the cpu core.
291 Parameters: struct kvm_sregs (in)
292 Returns: 0 on success, -1 on error
294 Writes special registers into the vcpu. See KVM_GET_SREGS for the
302 Parameters: struct kvm_translation (in/out)
303 Returns: 0 on success, -1 on error
305 Translates a virtual address according to the vcpu's current address
308 struct kvm_translation {
310 __u64 linear_address;
313 __u64 physical_address;
325 Parameters: struct kvm_interrupt (in)
326 Returns: 0 on success, -1 on error
328 Queues a hardware interrupt vector to be injected. This is only
329 useful if in-kernel local APIC is not used.
331 /* for KVM_INTERRUPT */
332 struct kvm_interrupt {
337 Note 'irq' is an interrupt vector, not an interrupt pin or line.
347 Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
354 Parameters: struct kvm_msrs (in/out)
355 Returns: 0 on success, -1 on error
357 Reads model-specific registers from the vcpu. Supported msr indices can
358 be obtained using KVM_GET_MSR_INDEX_LIST.
361 __u32 nmsrs; /* number of msrs in entries */
364 struct kvm_msr_entry entries[0];
367 struct kvm_msr_entry {
373 Application code should set the 'nmsrs' member (which indicates the
374 size of the entries array) and the 'index' member of each array entry.
375 kvm will fill in the 'data' member.
382 Parameters: struct kvm_msrs (in)
383 Returns: 0 on success, -1 on error
385 Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
388 Application code should set the 'nmsrs' member (which indicates the
389 size of the entries array), and the 'index' and 'data' members of each
397 Parameters: struct kvm_cpuid (in)
398 Returns: 0 on success, -1 on error
400 Defines the vcpu responses to the cpuid instruction. Applications
401 should use the KVM_SET_CPUID2 ioctl if available.
404 struct kvm_cpuid_entry {
413 /* for KVM_SET_CPUID */
417 struct kvm_cpuid_entry entries[0];
420 4.20 KVM_SET_SIGNAL_MASK
425 Parameters: struct kvm_signal_mask (in)
426 Returns: 0 on success, -1 on error
428 Defines which signals are blocked during execution of KVM_RUN. This
429 signal mask temporarily overrides the threads signal mask. Any
430 unblocked signal received (except SIGKILL and SIGSTOP, which retain
431 their traditional behaviour) will cause KVM_RUN to return with -EINTR.
433 Note the signal will only be delivered if not blocked by the original
436 /* for KVM_SET_SIGNAL_MASK */
437 struct kvm_signal_mask {
447 Parameters: struct kvm_fpu (out)
448 Returns: 0 on success, -1 on error
450 Reads the floating point state from the vcpu.
452 /* for KVM_GET_FPU and KVM_SET_FPU */
457 __u8 ftwx; /* in fxsave format */
472 Parameters: struct kvm_fpu (in)
473 Returns: 0 on success, -1 on error
475 Writes the floating point state to the vcpu.
477 /* for KVM_GET_FPU and KVM_SET_FPU */
482 __u8 ftwx; /* in fxsave format */
492 4.23 KVM_CREATE_IRQCHIP
494 Capability: KVM_CAP_IRQCHIP
495 Architectures: x86, ia64
498 Returns: 0 on success, -1 on error
500 Creates an interrupt controller model in the kernel. On x86, creates a virtual
501 ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
502 local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
503 only go to the IOAPIC. On ia64, a IOSAPIC is created.
507 Capability: KVM_CAP_IRQCHIP
508 Architectures: x86, ia64
510 Parameters: struct kvm_irq_level
511 Returns: 0 on success, -1 on error
513 Sets the level of a GSI input to the interrupt controller model in the kernel.
514 Requires that an interrupt controller model has been previously created with
515 KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
516 to be set to 1 and then back to 0.
518 struct kvm_irq_level {
521 __s32 status; /* not used for KVM_IRQ_LEVEL */
523 __u32 level; /* 0 or 1 */
528 Capability: KVM_CAP_IRQCHIP
529 Architectures: x86, ia64
531 Parameters: struct kvm_irqchip (in/out)
532 Returns: 0 on success, -1 on error
534 Reads the state of a kernel interrupt controller created with
535 KVM_CREATE_IRQCHIP into a buffer provided by the caller.
538 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
541 char dummy[512]; /* reserving space */
542 struct kvm_pic_state pic;
543 struct kvm_ioapic_state ioapic;
549 Capability: KVM_CAP_IRQCHIP
550 Architectures: x86, ia64
552 Parameters: struct kvm_irqchip (in)
553 Returns: 0 on success, -1 on error
555 Sets the state of a kernel interrupt controller created with
556 KVM_CREATE_IRQCHIP from a buffer provided by the caller.
559 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
562 char dummy[512]; /* reserving space */
563 struct kvm_pic_state pic;
564 struct kvm_ioapic_state ioapic;
568 4.27 KVM_XEN_HVM_CONFIG
570 Capability: KVM_CAP_XEN_HVM
573 Parameters: struct kvm_xen_hvm_config (in)
574 Returns: 0 on success, -1 on error
576 Sets the MSR that the Xen HVM guest uses to initialize its hypercall
577 page, and provides the starting address and size of the hypercall
578 blobs in userspace. When the guest writes the MSR, kvm copies one
579 page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
582 struct kvm_xen_hvm_config {
594 Capability: KVM_CAP_ADJUST_CLOCK
597 Parameters: struct kvm_clock_data (out)
598 Returns: 0 on success, -1 on error
600 Gets the current timestamp of kvmclock as seen by the current guest. In
601 conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
604 struct kvm_clock_data {
605 __u64 clock; /* kvmclock current value */
612 Capability: KVM_CAP_ADJUST_CLOCK
615 Parameters: struct kvm_clock_data (in)
616 Returns: 0 on success, -1 on error
618 Sets the current timestamp of kvmclock to the value specified in its parameter.
619 In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
622 struct kvm_clock_data {
623 __u64 clock; /* kvmclock current value */
628 4.29 KVM_GET_VCPU_EVENTS
630 Capability: KVM_CAP_VCPU_EVENTS
631 Extended by: KVM_CAP_INTR_SHADOW
634 Parameters: struct kvm_vcpu_event (out)
635 Returns: 0 on success, -1 on error
637 Gets currently pending exceptions, interrupts, and NMIs as well as related
640 struct kvm_vcpu_events {
664 KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
665 interrupt.shadow contains a valid state. Otherwise, this field is undefined.
667 4.30 KVM_SET_VCPU_EVENTS
669 Capability: KVM_CAP_VCPU_EVENTS
670 Extended by: KVM_CAP_INTR_SHADOW
673 Parameters: struct kvm_vcpu_event (in)
674 Returns: 0 on success, -1 on error
676 Set pending exceptions, interrupts, and NMIs as well as related states of the
679 See KVM_GET_VCPU_EVENTS for the data structure.
681 Fields that may be modified asynchronously by running VCPUs can be excluded
682 from the update. These fields are nmi.pending and sipi_vector. Keep the
683 corresponding bits in the flags field cleared to suppress overwriting the
684 current in-kernel state. The bits are:
686 KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
687 KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
689 If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
690 the flags field to signal that interrupt.shadow contains a valid state and
691 shall be written into the VCPU.
693 4.32 KVM_GET_DEBUGREGS
695 Capability: KVM_CAP_DEBUGREGS
698 Parameters: struct kvm_debugregs (out)
699 Returns: 0 on success, -1 on error
701 Reads debug registers from the vcpu.
703 struct kvm_debugregs {
711 4.33 KVM_SET_DEBUGREGS
713 Capability: KVM_CAP_DEBUGREGS
716 Parameters: struct kvm_debugregs (in)
717 Returns: 0 on success, -1 on error
719 Writes debug registers into the vcpu.
721 See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
722 yet and must be cleared on entry.
724 4.34 KVM_SET_USER_MEMORY_REGION
726 Capability: KVM_CAP_USER_MEM
729 Parameters: struct kvm_userspace_memory_region (in)
730 Returns: 0 on success, -1 on error
732 struct kvm_userspace_memory_region {
735 __u64 guest_phys_addr;
736 __u64 memory_size; /* bytes */
737 __u64 userspace_addr; /* start of the userspace allocated memory */
740 /* for kvm_memory_region::flags */
741 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
743 This ioctl allows the user to create or modify a guest physical memory
744 slot. When changing an existing slot, it may be moved in the guest
745 physical memory space, or its flags may be modified. It may not be
746 resized. Slots may not overlap in guest physical address space.
748 Memory for the region is taken starting at the address denoted by the
749 field userspace_addr, which must point at user addressable memory for
750 the entire memory slot size. Any object may back this memory, including
751 anonymous memory, ordinary files, and hugetlbfs.
753 It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
754 be identical. This allows large pages in the guest to be backed by large
757 The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
758 instructs kvm to keep track of writes to memory within the slot. See
759 the KVM_GET_DIRTY_LOG ioctl.
761 When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
762 region are automatically reflected into the guest. For example, an mmap()
763 that affects the region will be made visible immediately. Another example
764 is madvise(MADV_DROP).
766 It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
767 The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
768 allocation and is deprecated.
770 4.35 KVM_SET_TSS_ADDR
772 Capability: KVM_CAP_SET_TSS_ADDR
775 Parameters: unsigned long tss_address (in)
776 Returns: 0 on success, -1 on error
778 This ioctl defines the physical address of a three-page region in the guest
779 physical address space. The region must be within the first 4GB of the
780 guest physical address space and must not conflict with any memory slot
781 or any mmio address. The guest may malfunction if it accesses this memory
784 This ioctl is required on Intel-based hosts. This is needed on Intel hardware
785 because of a quirk in the virtualization implementation (see the internals
786 documentation when it pops into existence).
790 Capability: KVM_CAP_ENABLE_CAP
793 Parameters: struct kvm_enable_cap (in)
794 Returns: 0 on success; -1 on error
796 +Not all extensions are enabled by default. Using this ioctl the application
797 can enable an extension, making it available to the guest.
799 On systems that do not support this ioctl, it always fails. On systems that
800 do support it, it only works for extensions that are supported for enablement.
802 To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
805 struct kvm_enable_cap {
809 The capability that is supposed to get enabled.
813 A bitfield indicating future enhancements. Has to be 0 for now.
817 Arguments for enabling a feature. If a feature needs initial values to
818 function properly, this is the place to put them.
823 4.37 KVM_GET_MP_STATE
825 Capability: KVM_CAP_MP_STATE
826 Architectures: x86, ia64
828 Parameters: struct kvm_mp_state (out)
829 Returns: 0 on success; -1 on error
831 struct kvm_mp_state {
835 Returns the vcpu's current "multiprocessing state" (though also valid on
836 uniprocessor guests).
840 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
841 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
842 which has not yet received an INIT signal
843 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
845 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
846 is waiting for an interrupt
847 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
848 accesible via KVM_GET_VCPU_EVENTS)
850 This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
851 irqchip, the multiprocessing state must be maintained by userspace.
853 4.38 KVM_SET_MP_STATE
855 Capability: KVM_CAP_MP_STATE
856 Architectures: x86, ia64
858 Parameters: struct kvm_mp_state (in)
859 Returns: 0 on success; -1 on error
861 Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
864 This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
865 irqchip, the multiprocessing state must be maintained by userspace.
867 4.39 KVM_SET_IDENTITY_MAP_ADDR
869 Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
872 Parameters: unsigned long identity (in)
873 Returns: 0 on success, -1 on error
875 This ioctl defines the physical address of a one-page region in the guest
876 physical address space. The region must be within the first 4GB of the
877 guest physical address space and must not conflict with any memory slot
878 or any mmio address. The guest may malfunction if it accesses this memory
881 This ioctl is required on Intel-based hosts. This is needed on Intel hardware
882 because of a quirk in the virtualization implementation (see the internals
883 documentation when it pops into existence).
885 4.40 KVM_SET_BOOT_CPU_ID
887 Capability: KVM_CAP_SET_BOOT_CPU_ID
888 Architectures: x86, ia64
890 Parameters: unsigned long vcpu_id
891 Returns: 0 on success, -1 on error
893 Define which vcpu is the Bootstrap Processor (BSP). Values are the same
894 as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
899 Capability: KVM_CAP_XSAVE
902 Parameters: struct kvm_xsave (out)
903 Returns: 0 on success, -1 on error
909 This ioctl would copy current vcpu's xsave struct to the userspace.
913 Capability: KVM_CAP_XSAVE
916 Parameters: struct kvm_xsave (in)
917 Returns: 0 on success, -1 on error
923 This ioctl would copy userspace's xsave struct to the kernel.
927 Capability: KVM_CAP_XCRS
930 Parameters: struct kvm_xcrs (out)
931 Returns: 0 on success, -1 on error
942 struct kvm_xcr xcrs[KVM_MAX_XCRS];
946 This ioctl would copy current vcpu's xcrs to the userspace.
950 Capability: KVM_CAP_XCRS
953 Parameters: struct kvm_xcrs (in)
954 Returns: 0 on success, -1 on error
965 struct kvm_xcr xcrs[KVM_MAX_XCRS];
969 This ioctl would set vcpu's xcr to the value userspace specified.
971 4.45 KVM_GET_SUPPORTED_CPUID
973 Capability: KVM_CAP_EXT_CPUID
976 Parameters: struct kvm_cpuid2 (in/out)
977 Returns: 0 on success, -1 on error
982 struct kvm_cpuid_entry2 entries[0];
985 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
986 #define KVM_CPUID_FLAG_STATEFUL_FUNC 2
987 #define KVM_CPUID_FLAG_STATE_READ_NEXT 4
989 struct kvm_cpuid_entry2 {
1000 This ioctl returns x86 cpuid features which are supported by both the hardware
1001 and kvm. Userspace can use the information returned by this ioctl to
1002 construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1003 hardware, kernel, and userspace capabilities, and with user requirements (for
1004 example, the user may wish to constrain cpuid to emulate older hardware,
1005 or for feature consistency across a cluster).
1007 Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1008 with the 'nent' field indicating the number of entries in the variable-size
1009 array 'entries'. If the number of entries is too low to describe the cpu
1010 capabilities, an error (E2BIG) is returned. If the number is too high,
1011 the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1012 number is just right, the 'nent' field is adjusted to the number of valid
1013 entries in the 'entries' array, which is then filled.
1015 The entries returned are the host cpuid as returned by the cpuid instruction,
1016 with unknown or unsupported features masked out. The fields in each entry
1017 are defined as follows:
1019 function: the eax value used to obtain the entry
1020 index: the ecx value used to obtain the entry (for entries that are
1022 flags: an OR of zero or more of the following:
1023 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1024 if the index field is valid
1025 KVM_CPUID_FLAG_STATEFUL_FUNC:
1026 if cpuid for this function returns different values for successive
1027 invocations; there will be several entries with the same function,
1028 all with this flag set
1029 KVM_CPUID_FLAG_STATE_READ_NEXT:
1030 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1031 the first entry to be read by a cpu
1032 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1033 this function/index combination
1035 5. The kvm_run structure
1037 Application code obtains a pointer to the kvm_run structure by
1038 mmap()ing a vcpu fd. From that point, application code can control
1039 execution by changing fields in kvm_run prior to calling the KVM_RUN
1040 ioctl, and obtain information about the reason KVM_RUN returned by
1041 looking up structure members.
1045 __u8 request_interrupt_window;
1047 Request that KVM_RUN return when it becomes possible to inject external
1048 interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1055 When KVM_RUN has returned successfully (return value 0), this informs
1056 application code why KVM_RUN has returned. Allowable values for this
1057 field are detailed below.
1059 __u8 ready_for_interrupt_injection;
1061 If request_interrupt_window has been specified, this field indicates
1062 an interrupt can be injected now with KVM_INTERRUPT.
1066 The value of the current interrupt flag. Only valid if in-kernel
1067 local APIC is not used.
1071 /* in (pre_kvm_run), out (post_kvm_run) */
1074 The value of the cr8 register. Only valid if in-kernel local APIC is
1075 not used. Both input and output.
1079 The value of the APIC BASE msr. Only valid if in-kernel local
1080 APIC is not used. Both input and output.
1083 /* KVM_EXIT_UNKNOWN */
1085 __u64 hardware_exit_reason;
1088 If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1089 reasons. Further architecture-specific information is available in
1090 hardware_exit_reason.
1092 /* KVM_EXIT_FAIL_ENTRY */
1094 __u64 hardware_entry_failure_reason;
1097 If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1098 to unknown reasons. Further architecture-specific information is
1099 available in hardware_entry_failure_reason.
1101 /* KVM_EXIT_EXCEPTION */
1111 #define KVM_EXIT_IO_IN 0
1112 #define KVM_EXIT_IO_OUT 1
1114 __u8 size; /* bytes */
1117 __u64 data_offset; /* relative to kvm_run start */
1120 If exit_reason is KVM_EXIT_IO, then the vcpu has
1121 executed a port I/O instruction which could not be satisfied by kvm.
1122 data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1123 where kvm expects application code to place the data for the next
1124 KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
1127 struct kvm_debug_exit_arch arch;
1140 If exit_reason is KVM_EXIT_MMIO, then the vcpu has
1141 executed a memory-mapped I/O instruction which could not be satisfied
1142 by kvm. The 'data' member contains the written data if 'is_write' is
1143 true, and should be filled by application code otherwise.
1145 NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1146 operations are complete (and guest state is consistent) only after userspace
1147 has re-entered the kernel with KVM_RUN. The kernel side will first finish
1148 incomplete operations and then check for pending signals. Userspace
1149 can re-enter the guest with an unmasked signal pending to complete
1152 /* KVM_EXIT_HYPERCALL */
1161 Unused. This was once used for 'hypercall to userspace'. To implement
1162 such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1163 Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
1165 /* KVM_EXIT_TPR_ACCESS */
1172 To be documented (KVM_TPR_ACCESS_REPORTING).
1174 /* KVM_EXIT_S390_SIEIC */
1177 __u64 mask; /* psw upper half */
1178 __u64 addr; /* psw lower half */
1185 /* KVM_EXIT_S390_RESET */
1186 #define KVM_S390_RESET_POR 1
1187 #define KVM_S390_RESET_CLEAR 2
1188 #define KVM_S390_RESET_SUBSYSTEM 4
1189 #define KVM_S390_RESET_CPU_INIT 8
1190 #define KVM_S390_RESET_IPL 16
1191 __u64 s390_reset_flags;
1209 MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1210 hypercalls and exit with this exit struct that contains all the guest gprs.
1212 If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1213 Userspace can now handle the hypercall and when it's done modify the gprs as
1214 necessary. Upon guest entry all guest GPRs will then be replaced by the values
1217 /* Fix the size of the union. */