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.
98 Parameters: machine type identifier (KVM_VM_*)
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
106 You most certainly want to use 0 as machine type.
108 In order to create user controlled virtual machines on S390, check
109 KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
110 privileged user (CAP_SYS_ADMIN).
112 4.3 KVM_GET_MSR_INDEX_LIST
117 Parameters: struct kvm_msr_list (in/out)
118 Returns: 0 on success; -1 on error
120 E2BIG: the msr index list is to be to fit in the array specified by
123 struct kvm_msr_list {
124 __u32 nmsrs; /* number of msrs in entries */
128 This ioctl returns the guest msrs that are supported. The list varies
129 by kvm version and host processor, but does not change otherwise. The
130 user fills in the size of the indices array in nmsrs, and in return
131 kvm adjusts nmsrs to reflect the actual number of msrs and fills in
132 the indices array with their numbers.
134 Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
135 not returned in the MSR list, as different vcpus can have a different number
136 of banks, as set via the KVM_X86_SETUP_MCE ioctl.
138 4.4 KVM_CHECK_EXTENSION
143 Parameters: extension identifier (KVM_CAP_*)
144 Returns: 0 if unsupported; 1 (or some other positive integer) if supported
146 The API allows the application to query about extensions to the core
147 kvm API. Userspace passes an extension identifier (an integer) and
148 receives an integer that describes the extension availability.
149 Generally 0 means no and 1 means yes, but some extensions may report
150 additional information in the integer return value.
152 4.5 KVM_GET_VCPU_MMAP_SIZE
158 Returns: size of vcpu mmap area, in bytes
160 The KVM_RUN ioctl (cf.) communicates with userspace via a shared
161 memory region. This ioctl returns the size of that region. See the
162 KVM_RUN documentation for details.
164 4.6 KVM_SET_MEMORY_REGION
169 Parameters: struct kvm_memory_region (in)
170 Returns: 0 on success, -1 on error
172 This ioctl is obsolete and has been removed.
179 Parameters: vcpu id (apic id on x86)
180 Returns: vcpu fd on success, -1 on error
182 This API adds a vcpu to a virtual machine. The vcpu id is a small integer
183 in the range [0, max_vcpus).
185 The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
186 the KVM_CHECK_EXTENSION ioctl() at run-time.
187 The maximum possible value for max_vcpus can be retrieved using the
188 KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
190 If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
192 If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
193 same as the value returned from KVM_CAP_NR_VCPUS.
195 On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
196 threads in one or more virtual CPU cores. (This is because the
197 hardware requires all the hardware threads in a CPU core to be in the
198 same partition.) The KVM_CAP_PPC_SMT capability indicates the number
199 of vcpus per virtual core (vcore). The vcore id is obtained by
200 dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
201 given vcore will always be in the same physical core as each other
202 (though that might be a different physical core from time to time).
203 Userspace can control the threading (SMT) mode of the guest by its
204 allocation of vcpu ids. For example, if userspace wants
205 single-threaded guest vcpus, it should make all vcpu ids be a multiple
206 of the number of vcpus per vcore.
208 On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
209 threads in one or more virtual CPU cores. (This is because the
210 hardware requires all the hardware threads in a CPU core to be in the
211 same partition.) The KVM_CAP_PPC_SMT capability indicates the number
212 of vcpus per virtual core (vcore). The vcore id is obtained by
213 dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
214 given vcore will always be in the same physical core as each other
215 (though that might be a different physical core from time to time).
216 Userspace can control the threading (SMT) mode of the guest by its
217 allocation of vcpu ids. For example, if userspace wants
218 single-threaded guest vcpus, it should make all vcpu ids be a multiple
219 of the number of vcpus per vcore.
221 For virtual cpus that have been created with S390 user controlled virtual
222 machines, the resulting vcpu fd can be memory mapped at page offset
223 KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
224 cpu's hardware control block.
226 4.8 KVM_GET_DIRTY_LOG (vm ioctl)
231 Parameters: struct kvm_dirty_log (in/out)
232 Returns: 0 on success, -1 on error
234 /* for KVM_GET_DIRTY_LOG */
235 struct kvm_dirty_log {
239 void __user *dirty_bitmap; /* one bit per page */
244 Given a memory slot, return a bitmap containing any pages dirtied
245 since the last call to this ioctl. Bit 0 is the first page in the
246 memory slot. Ensure the entire structure is cleared to avoid padding
249 4.9 KVM_SET_MEMORY_ALIAS
254 Parameters: struct kvm_memory_alias (in)
255 Returns: 0 (success), -1 (error)
257 This ioctl is obsolete and has been removed.
265 Returns: 0 on success, -1 on error
267 EINTR: an unmasked signal is pending
269 This ioctl is used to run a guest virtual cpu. While there are no
270 explicit parameters, there is an implicit parameter block that can be
271 obtained by mmap()ing the vcpu fd at offset 0, with the size given by
272 KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
273 kvm_run' (see below).
280 Parameters: struct kvm_regs (out)
281 Returns: 0 on success, -1 on error
283 Reads the general purpose registers from the vcpu.
287 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
288 __u64 rax, rbx, rcx, rdx;
289 __u64 rsi, rdi, rsp, rbp;
290 __u64 r8, r9, r10, r11;
291 __u64 r12, r13, r14, r15;
300 Parameters: struct kvm_regs (in)
301 Returns: 0 on success, -1 on error
303 Writes the general purpose registers into the vcpu.
305 See KVM_GET_REGS for the data structure.
310 Architectures: x86, ppc
312 Parameters: struct kvm_sregs (out)
313 Returns: 0 on success, -1 on error
315 Reads special registers from the vcpu.
319 struct kvm_segment cs, ds, es, fs, gs, ss;
320 struct kvm_segment tr, ldt;
321 struct kvm_dtable gdt, idt;
322 __u64 cr0, cr2, cr3, cr4, cr8;
325 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
328 /* ppc -- see arch/powerpc/include/asm/kvm.h */
330 interrupt_bitmap is a bitmap of pending external interrupts. At most
331 one bit may be set. This interrupt has been acknowledged by the APIC
332 but not yet injected into the cpu core.
337 Architectures: x86, ppc
339 Parameters: struct kvm_sregs (in)
340 Returns: 0 on success, -1 on error
342 Writes special registers into the vcpu. See KVM_GET_SREGS for the
350 Parameters: struct kvm_translation (in/out)
351 Returns: 0 on success, -1 on error
353 Translates a virtual address according to the vcpu's current address
356 struct kvm_translation {
358 __u64 linear_address;
361 __u64 physical_address;
371 Architectures: x86, ppc
373 Parameters: struct kvm_interrupt (in)
374 Returns: 0 on success, -1 on error
376 Queues a hardware interrupt vector to be injected. This is only
377 useful if in-kernel local APIC or equivalent is not used.
379 /* for KVM_INTERRUPT */
380 struct kvm_interrupt {
387 Note 'irq' is an interrupt vector, not an interrupt pin or line.
391 Queues an external interrupt to be injected. This ioctl is overleaded
392 with 3 different irq values:
396 This injects an edge type external interrupt into the guest once it's ready
397 to receive interrupts. When injected, the interrupt is done.
399 b) KVM_INTERRUPT_UNSET
401 This unsets any pending interrupt.
403 Only available with KVM_CAP_PPC_UNSET_IRQ.
405 c) KVM_INTERRUPT_SET_LEVEL
407 This injects a level type external interrupt into the guest context. The
408 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
411 Only available with KVM_CAP_PPC_IRQ_LEVEL.
413 Note that any value for 'irq' other than the ones stated above is invalid
414 and incurs unexpected behavior.
424 Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
431 Parameters: struct kvm_msrs (in/out)
432 Returns: 0 on success, -1 on error
434 Reads model-specific registers from the vcpu. Supported msr indices can
435 be obtained using KVM_GET_MSR_INDEX_LIST.
438 __u32 nmsrs; /* number of msrs in entries */
441 struct kvm_msr_entry entries[0];
444 struct kvm_msr_entry {
450 Application code should set the 'nmsrs' member (which indicates the
451 size of the entries array) and the 'index' member of each array entry.
452 kvm will fill in the 'data' member.
459 Parameters: struct kvm_msrs (in)
460 Returns: 0 on success, -1 on error
462 Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
465 Application code should set the 'nmsrs' member (which indicates the
466 size of the entries array), and the 'index' and 'data' members of each
474 Parameters: struct kvm_cpuid (in)
475 Returns: 0 on success, -1 on error
477 Defines the vcpu responses to the cpuid instruction. Applications
478 should use the KVM_SET_CPUID2 ioctl if available.
481 struct kvm_cpuid_entry {
490 /* for KVM_SET_CPUID */
494 struct kvm_cpuid_entry entries[0];
497 4.21 KVM_SET_SIGNAL_MASK
502 Parameters: struct kvm_signal_mask (in)
503 Returns: 0 on success, -1 on error
505 Defines which signals are blocked during execution of KVM_RUN. This
506 signal mask temporarily overrides the threads signal mask. Any
507 unblocked signal received (except SIGKILL and SIGSTOP, which retain
508 their traditional behaviour) will cause KVM_RUN to return with -EINTR.
510 Note the signal will only be delivered if not blocked by the original
513 /* for KVM_SET_SIGNAL_MASK */
514 struct kvm_signal_mask {
524 Parameters: struct kvm_fpu (out)
525 Returns: 0 on success, -1 on error
527 Reads the floating point state from the vcpu.
529 /* for KVM_GET_FPU and KVM_SET_FPU */
534 __u8 ftwx; /* in fxsave format */
549 Parameters: struct kvm_fpu (in)
550 Returns: 0 on success, -1 on error
552 Writes the floating point state to the vcpu.
554 /* for KVM_GET_FPU and KVM_SET_FPU */
559 __u8 ftwx; /* in fxsave format */
569 4.24 KVM_CREATE_IRQCHIP
571 Capability: KVM_CAP_IRQCHIP
572 Architectures: x86, ia64
575 Returns: 0 on success, -1 on error
577 Creates an interrupt controller model in the kernel. On x86, creates a virtual
578 ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
579 local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
580 only go to the IOAPIC. On ia64, a IOSAPIC is created.
584 Capability: KVM_CAP_IRQCHIP
585 Architectures: x86, ia64
587 Parameters: struct kvm_irq_level
588 Returns: 0 on success, -1 on error
590 Sets the level of a GSI input to the interrupt controller model in the kernel.
591 Requires that an interrupt controller model has been previously created with
592 KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
593 to be set to 1 and then back to 0.
595 struct kvm_irq_level {
598 __s32 status; /* not used for KVM_IRQ_LEVEL */
600 __u32 level; /* 0 or 1 */
605 Capability: KVM_CAP_IRQCHIP
606 Architectures: x86, ia64
608 Parameters: struct kvm_irqchip (in/out)
609 Returns: 0 on success, -1 on error
611 Reads the state of a kernel interrupt controller created with
612 KVM_CREATE_IRQCHIP into a buffer provided by the caller.
615 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
618 char dummy[512]; /* reserving space */
619 struct kvm_pic_state pic;
620 struct kvm_ioapic_state ioapic;
626 Capability: KVM_CAP_IRQCHIP
627 Architectures: x86, ia64
629 Parameters: struct kvm_irqchip (in)
630 Returns: 0 on success, -1 on error
632 Sets the state of a kernel interrupt controller created with
633 KVM_CREATE_IRQCHIP from a buffer provided by the caller.
636 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
639 char dummy[512]; /* reserving space */
640 struct kvm_pic_state pic;
641 struct kvm_ioapic_state ioapic;
645 4.28 KVM_XEN_HVM_CONFIG
647 Capability: KVM_CAP_XEN_HVM
650 Parameters: struct kvm_xen_hvm_config (in)
651 Returns: 0 on success, -1 on error
653 Sets the MSR that the Xen HVM guest uses to initialize its hypercall
654 page, and provides the starting address and size of the hypercall
655 blobs in userspace. When the guest writes the MSR, kvm copies one
656 page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
659 struct kvm_xen_hvm_config {
671 Capability: KVM_CAP_ADJUST_CLOCK
674 Parameters: struct kvm_clock_data (out)
675 Returns: 0 on success, -1 on error
677 Gets the current timestamp of kvmclock as seen by the current guest. In
678 conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
681 struct kvm_clock_data {
682 __u64 clock; /* kvmclock current value */
689 Capability: KVM_CAP_ADJUST_CLOCK
692 Parameters: struct kvm_clock_data (in)
693 Returns: 0 on success, -1 on error
695 Sets the current timestamp of kvmclock to the value specified in its parameter.
696 In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
699 struct kvm_clock_data {
700 __u64 clock; /* kvmclock current value */
705 4.31 KVM_GET_VCPU_EVENTS
707 Capability: KVM_CAP_VCPU_EVENTS
708 Extended by: KVM_CAP_INTR_SHADOW
711 Parameters: struct kvm_vcpu_event (out)
712 Returns: 0 on success, -1 on error
714 Gets currently pending exceptions, interrupts, and NMIs as well as related
717 struct kvm_vcpu_events {
741 KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
742 interrupt.shadow contains a valid state. Otherwise, this field is undefined.
744 4.32 KVM_SET_VCPU_EVENTS
746 Capability: KVM_CAP_VCPU_EVENTS
747 Extended by: KVM_CAP_INTR_SHADOW
750 Parameters: struct kvm_vcpu_event (in)
751 Returns: 0 on success, -1 on error
753 Set pending exceptions, interrupts, and NMIs as well as related states of the
756 See KVM_GET_VCPU_EVENTS for the data structure.
758 Fields that may be modified asynchronously by running VCPUs can be excluded
759 from the update. These fields are nmi.pending and sipi_vector. Keep the
760 corresponding bits in the flags field cleared to suppress overwriting the
761 current in-kernel state. The bits are:
763 KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
764 KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
766 If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
767 the flags field to signal that interrupt.shadow contains a valid state and
768 shall be written into the VCPU.
770 4.33 KVM_GET_DEBUGREGS
772 Capability: KVM_CAP_DEBUGREGS
775 Parameters: struct kvm_debugregs (out)
776 Returns: 0 on success, -1 on error
778 Reads debug registers from the vcpu.
780 struct kvm_debugregs {
788 4.34 KVM_SET_DEBUGREGS
790 Capability: KVM_CAP_DEBUGREGS
793 Parameters: struct kvm_debugregs (in)
794 Returns: 0 on success, -1 on error
796 Writes debug registers into the vcpu.
798 See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
799 yet and must be cleared on entry.
801 4.35 KVM_SET_USER_MEMORY_REGION
803 Capability: KVM_CAP_USER_MEM
806 Parameters: struct kvm_userspace_memory_region (in)
807 Returns: 0 on success, -1 on error
809 struct kvm_userspace_memory_region {
812 __u64 guest_phys_addr;
813 __u64 memory_size; /* bytes */
814 __u64 userspace_addr; /* start of the userspace allocated memory */
817 /* for kvm_memory_region::flags */
818 #define KVM_MEM_LOG_DIRTY_PAGES 1UL
820 This ioctl allows the user to create or modify a guest physical memory
821 slot. When changing an existing slot, it may be moved in the guest
822 physical memory space, or its flags may be modified. It may not be
823 resized. Slots may not overlap in guest physical address space.
825 Memory for the region is taken starting at the address denoted by the
826 field userspace_addr, which must point at user addressable memory for
827 the entire memory slot size. Any object may back this memory, including
828 anonymous memory, ordinary files, and hugetlbfs.
830 It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
831 be identical. This allows large pages in the guest to be backed by large
834 The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
835 instructs kvm to keep track of writes to memory within the slot. See
836 the KVM_GET_DIRTY_LOG ioctl.
838 When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
839 region are automatically reflected into the guest. For example, an mmap()
840 that affects the region will be made visible immediately. Another example
841 is madvise(MADV_DROP).
843 It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
844 The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
845 allocation and is deprecated.
847 4.36 KVM_SET_TSS_ADDR
849 Capability: KVM_CAP_SET_TSS_ADDR
852 Parameters: unsigned long tss_address (in)
853 Returns: 0 on success, -1 on error
855 This ioctl defines the physical address of a three-page region in the guest
856 physical address space. The region must be within the first 4GB of the
857 guest physical address space and must not conflict with any memory slot
858 or any mmio address. The guest may malfunction if it accesses this memory
861 This ioctl is required on Intel-based hosts. This is needed on Intel hardware
862 because of a quirk in the virtualization implementation (see the internals
863 documentation when it pops into existence).
867 Capability: KVM_CAP_ENABLE_CAP
870 Parameters: struct kvm_enable_cap (in)
871 Returns: 0 on success; -1 on error
873 +Not all extensions are enabled by default. Using this ioctl the application
874 can enable an extension, making it available to the guest.
876 On systems that do not support this ioctl, it always fails. On systems that
877 do support it, it only works for extensions that are supported for enablement.
879 To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
882 struct kvm_enable_cap {
886 The capability that is supposed to get enabled.
890 A bitfield indicating future enhancements. Has to be 0 for now.
894 Arguments for enabling a feature. If a feature needs initial values to
895 function properly, this is the place to put them.
900 4.38 KVM_GET_MP_STATE
902 Capability: KVM_CAP_MP_STATE
903 Architectures: x86, ia64
905 Parameters: struct kvm_mp_state (out)
906 Returns: 0 on success; -1 on error
908 struct kvm_mp_state {
912 Returns the vcpu's current "multiprocessing state" (though also valid on
913 uniprocessor guests).
917 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
918 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
919 which has not yet received an INIT signal
920 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
922 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
923 is waiting for an interrupt
924 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
925 accessible via KVM_GET_VCPU_EVENTS)
927 This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
928 irqchip, the multiprocessing state must be maintained by userspace.
930 4.39 KVM_SET_MP_STATE
932 Capability: KVM_CAP_MP_STATE
933 Architectures: x86, ia64
935 Parameters: struct kvm_mp_state (in)
936 Returns: 0 on success; -1 on error
938 Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
941 This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
942 irqchip, the multiprocessing state must be maintained by userspace.
944 4.40 KVM_SET_IDENTITY_MAP_ADDR
946 Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
949 Parameters: unsigned long identity (in)
950 Returns: 0 on success, -1 on error
952 This ioctl defines the physical address of a one-page region in the guest
953 physical address space. The region must be within the first 4GB of the
954 guest physical address space and must not conflict with any memory slot
955 or any mmio address. The guest may malfunction if it accesses this memory
958 This ioctl is required on Intel-based hosts. This is needed on Intel hardware
959 because of a quirk in the virtualization implementation (see the internals
960 documentation when it pops into existence).
962 4.41 KVM_SET_BOOT_CPU_ID
964 Capability: KVM_CAP_SET_BOOT_CPU_ID
965 Architectures: x86, ia64
967 Parameters: unsigned long vcpu_id
968 Returns: 0 on success, -1 on error
970 Define which vcpu is the Bootstrap Processor (BSP). Values are the same
971 as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
976 Capability: KVM_CAP_XSAVE
979 Parameters: struct kvm_xsave (out)
980 Returns: 0 on success, -1 on error
986 This ioctl would copy current vcpu's xsave struct to the userspace.
990 Capability: KVM_CAP_XSAVE
993 Parameters: struct kvm_xsave (in)
994 Returns: 0 on success, -1 on error
1000 This ioctl would copy userspace's xsave struct to the kernel.
1004 Capability: KVM_CAP_XCRS
1007 Parameters: struct kvm_xcrs (out)
1008 Returns: 0 on success, -1 on error
1019 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1023 This ioctl would copy current vcpu's xcrs to the userspace.
1027 Capability: KVM_CAP_XCRS
1030 Parameters: struct kvm_xcrs (in)
1031 Returns: 0 on success, -1 on error
1042 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1046 This ioctl would set vcpu's xcr to the value userspace specified.
1048 4.46 KVM_GET_SUPPORTED_CPUID
1050 Capability: KVM_CAP_EXT_CPUID
1053 Parameters: struct kvm_cpuid2 (in/out)
1054 Returns: 0 on success, -1 on error
1059 struct kvm_cpuid_entry2 entries[0];
1062 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
1063 #define KVM_CPUID_FLAG_STATEFUL_FUNC 2
1064 #define KVM_CPUID_FLAG_STATE_READ_NEXT 4
1066 struct kvm_cpuid_entry2 {
1077 This ioctl returns x86 cpuid features which are supported by both the hardware
1078 and kvm. Userspace can use the information returned by this ioctl to
1079 construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1080 hardware, kernel, and userspace capabilities, and with user requirements (for
1081 example, the user may wish to constrain cpuid to emulate older hardware,
1082 or for feature consistency across a cluster).
1084 Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1085 with the 'nent' field indicating the number of entries in the variable-size
1086 array 'entries'. If the number of entries is too low to describe the cpu
1087 capabilities, an error (E2BIG) is returned. If the number is too high,
1088 the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1089 number is just right, the 'nent' field is adjusted to the number of valid
1090 entries in the 'entries' array, which is then filled.
1092 The entries returned are the host cpuid as returned by the cpuid instruction,
1093 with unknown or unsupported features masked out. Some features (for example,
1094 x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1095 emulate them efficiently. The fields in each entry are defined as follows:
1097 function: the eax value used to obtain the entry
1098 index: the ecx value used to obtain the entry (for entries that are
1100 flags: an OR of zero or more of the following:
1101 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1102 if the index field is valid
1103 KVM_CPUID_FLAG_STATEFUL_FUNC:
1104 if cpuid for this function returns different values for successive
1105 invocations; there will be several entries with the same function,
1106 all with this flag set
1107 KVM_CPUID_FLAG_STATE_READ_NEXT:
1108 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1109 the first entry to be read by a cpu
1110 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1111 this function/index combination
1113 The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1114 as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1115 support. Instead it is reported via
1117 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1119 if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1120 feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1122 4.47 KVM_PPC_GET_PVINFO
1124 Capability: KVM_CAP_PPC_GET_PVINFO
1127 Parameters: struct kvm_ppc_pvinfo (out)
1128 Returns: 0 on success, !0 on error
1130 struct kvm_ppc_pvinfo {
1136 This ioctl fetches PV specific information that need to be passed to the guest
1137 using the device tree or other means from vm context.
1139 For now the only implemented piece of information distributed here is an array
1140 of 4 instructions that make up a hypercall.
1142 If any additional field gets added to this structure later on, a bit for that
1143 additional piece of information will be set in the flags bitmap.
1145 4.48 KVM_ASSIGN_PCI_DEVICE
1147 Capability: KVM_CAP_DEVICE_ASSIGNMENT
1148 Architectures: x86 ia64
1150 Parameters: struct kvm_assigned_pci_dev (in)
1151 Returns: 0 on success, -1 on error
1153 Assigns a host PCI device to the VM.
1155 struct kvm_assigned_pci_dev {
1156 __u32 assigned_dev_id;
1166 The PCI device is specified by the triple segnr, busnr, and devfn.
1167 Identification in succeeding service requests is done via assigned_dev_id. The
1168 following flags are specified:
1170 /* Depends on KVM_CAP_IOMMU */
1171 #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1173 The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
1174 isolation of the device. Usages not specifying this flag are deprecated.
1176 Only PCI header type 0 devices with PCI BAR resources are supported by
1177 device assignment. The user requesting this ioctl must have read/write
1178 access to the PCI sysfs resource files associated with the device.
1180 4.49 KVM_DEASSIGN_PCI_DEVICE
1182 Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1183 Architectures: x86 ia64
1185 Parameters: struct kvm_assigned_pci_dev (in)
1186 Returns: 0 on success, -1 on error
1188 Ends PCI device assignment, releasing all associated resources.
1190 See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1191 used in kvm_assigned_pci_dev to identify the device.
1193 4.50 KVM_ASSIGN_DEV_IRQ
1195 Capability: KVM_CAP_ASSIGN_DEV_IRQ
1196 Architectures: x86 ia64
1198 Parameters: struct kvm_assigned_irq (in)
1199 Returns: 0 on success, -1 on error
1201 Assigns an IRQ to a passed-through device.
1203 struct kvm_assigned_irq {
1204 __u32 assigned_dev_id;
1205 __u32 host_irq; /* ignored (legacy field) */
1213 The following flags are defined:
1215 #define KVM_DEV_IRQ_HOST_INTX (1 << 0)
1216 #define KVM_DEV_IRQ_HOST_MSI (1 << 1)
1217 #define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
1219 #define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
1220 #define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
1221 #define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
1223 It is not valid to specify multiple types per host or guest IRQ. However, the
1224 IRQ type of host and guest can differ or can even be null.
1226 4.51 KVM_DEASSIGN_DEV_IRQ
1228 Capability: KVM_CAP_ASSIGN_DEV_IRQ
1229 Architectures: x86 ia64
1231 Parameters: struct kvm_assigned_irq (in)
1232 Returns: 0 on success, -1 on error
1234 Ends an IRQ assignment to a passed-through device.
1236 See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1237 by assigned_dev_id, flags must correspond to the IRQ type specified on
1238 KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1240 4.52 KVM_SET_GSI_ROUTING
1242 Capability: KVM_CAP_IRQ_ROUTING
1243 Architectures: x86 ia64
1245 Parameters: struct kvm_irq_routing (in)
1246 Returns: 0 on success, -1 on error
1248 Sets the GSI routing table entries, overwriting any previously set entries.
1250 struct kvm_irq_routing {
1253 struct kvm_irq_routing_entry entries[0];
1256 No flags are specified so far, the corresponding field must be set to zero.
1258 struct kvm_irq_routing_entry {
1264 struct kvm_irq_routing_irqchip irqchip;
1265 struct kvm_irq_routing_msi msi;
1270 /* gsi routing entry types */
1271 #define KVM_IRQ_ROUTING_IRQCHIP 1
1272 #define KVM_IRQ_ROUTING_MSI 2
1274 No flags are specified so far, the corresponding field must be set to zero.
1276 struct kvm_irq_routing_irqchip {
1281 struct kvm_irq_routing_msi {
1288 4.53 KVM_ASSIGN_SET_MSIX_NR
1290 Capability: KVM_CAP_DEVICE_MSIX
1291 Architectures: x86 ia64
1293 Parameters: struct kvm_assigned_msix_nr (in)
1294 Returns: 0 on success, -1 on error
1296 Set the number of MSI-X interrupts for an assigned device. The number is
1297 reset again by terminating the MSI-X assignment of the device via
1298 KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
1301 struct kvm_assigned_msix_nr {
1302 __u32 assigned_dev_id;
1307 #define KVM_MAX_MSIX_PER_DEV 256
1309 4.54 KVM_ASSIGN_SET_MSIX_ENTRY
1311 Capability: KVM_CAP_DEVICE_MSIX
1312 Architectures: x86 ia64
1314 Parameters: struct kvm_assigned_msix_entry (in)
1315 Returns: 0 on success, -1 on error
1317 Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1318 the GSI vector to zero means disabling the interrupt.
1320 struct kvm_assigned_msix_entry {
1321 __u32 assigned_dev_id;
1323 __u16 entry; /* The index of entry in the MSI-X table */
1327 4.54 KVM_SET_TSC_KHZ
1329 Capability: KVM_CAP_TSC_CONTROL
1332 Parameters: virtual tsc_khz
1333 Returns: 0 on success, -1 on error
1335 Specifies the tsc frequency for the virtual machine. The unit of the
1338 4.55 KVM_GET_TSC_KHZ
1340 Capability: KVM_CAP_GET_TSC_KHZ
1344 Returns: virtual tsc-khz on success, negative value on error
1346 Returns the tsc frequency of the guest. The unit of the return value is
1347 KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1352 Capability: KVM_CAP_IRQCHIP
1355 Parameters: struct kvm_lapic_state (out)
1356 Returns: 0 on success, -1 on error
1358 #define KVM_APIC_REG_SIZE 0x400
1359 struct kvm_lapic_state {
1360 char regs[KVM_APIC_REG_SIZE];
1363 Reads the Local APIC registers and copies them into the input argument. The
1364 data format and layout are the same as documented in the architecture manual.
1368 Capability: KVM_CAP_IRQCHIP
1371 Parameters: struct kvm_lapic_state (in)
1372 Returns: 0 on success, -1 on error
1374 #define KVM_APIC_REG_SIZE 0x400
1375 struct kvm_lapic_state {
1376 char regs[KVM_APIC_REG_SIZE];
1379 Copies the input argument into the the Local APIC registers. The data format
1380 and layout are the same as documented in the architecture manual.
1384 Capability: KVM_CAP_IOEVENTFD
1387 Parameters: struct kvm_ioeventfd (in)
1388 Returns: 0 on success, !0 on error
1390 This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1391 within the guest. A guest write in the registered address will signal the
1392 provided event instead of triggering an exit.
1394 struct kvm_ioeventfd {
1396 __u64 addr; /* legal pio/mmio address */
1397 __u32 len; /* 1, 2, 4, or 8 bytes */
1403 The following flags are defined:
1405 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1406 #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1407 #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
1409 If datamatch flag is set, the event will be signaled only if the written value
1410 to the registered address is equal to datamatch in struct kvm_ioeventfd.
1414 Capability: KVM_CAP_SW_TLB
1417 Parameters: struct kvm_dirty_tlb (in)
1418 Returns: 0 on success, -1 on error
1420 struct kvm_dirty_tlb {
1425 This must be called whenever userspace has changed an entry in the shared
1426 TLB, prior to calling KVM_RUN on the associated vcpu.
1428 The "bitmap" field is the userspace address of an array. This array
1429 consists of a number of bits, equal to the total number of TLB entries as
1430 determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
1431 nearest multiple of 64.
1433 Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
1436 The array is little-endian: the bit 0 is the least significant bit of the
1437 first byte, bit 8 is the least significant bit of the second byte, etc.
1438 This avoids any complications with differing word sizes.
1440 The "num_dirty" field is a performance hint for KVM to determine whether it
1441 should skip processing the bitmap and just invalidate everything. It must
1442 be set to the number of set bits in the bitmap.
1444 4.62 KVM_CREATE_SPAPR_TCE
1446 Capability: KVM_CAP_SPAPR_TCE
1447 Architectures: powerpc
1449 Parameters: struct kvm_create_spapr_tce (in)
1450 Returns: file descriptor for manipulating the created TCE table
1452 This creates a virtual TCE (translation control entry) table, which
1453 is an IOMMU for PAPR-style virtual I/O. It is used to translate
1454 logical addresses used in virtual I/O into guest physical addresses,
1455 and provides a scatter/gather capability for PAPR virtual I/O.
1457 /* for KVM_CAP_SPAPR_TCE */
1458 struct kvm_create_spapr_tce {
1463 The liobn field gives the logical IO bus number for which to create a
1464 TCE table. The window_size field specifies the size of the DMA window
1465 which this TCE table will translate - the table will contain one 64
1466 bit TCE entry for every 4kiB of the DMA window.
1468 When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1469 table has been created using this ioctl(), the kernel will handle it
1470 in real mode, updating the TCE table. H_PUT_TCE calls for other
1471 liobns will cause a vm exit and must be handled by userspace.
1473 The return value is a file descriptor which can be passed to mmap(2)
1474 to map the created TCE table into userspace. This lets userspace read
1475 the entries written by kernel-handled H_PUT_TCE calls, and also lets
1476 userspace update the TCE table directly which is useful in some
1479 4.63 KVM_ALLOCATE_RMA
1481 Capability: KVM_CAP_PPC_RMA
1482 Architectures: powerpc
1484 Parameters: struct kvm_allocate_rma (out)
1485 Returns: file descriptor for mapping the allocated RMA
1487 This allocates a Real Mode Area (RMA) from the pool allocated at boot
1488 time by the kernel. An RMA is a physically-contiguous, aligned region
1489 of memory used on older POWER processors to provide the memory which
1490 will be accessed by real-mode (MMU off) accesses in a KVM guest.
1491 POWER processors support a set of sizes for the RMA that usually
1492 includes 64MB, 128MB, 256MB and some larger powers of two.
1494 /* for KVM_ALLOCATE_RMA */
1495 struct kvm_allocate_rma {
1499 The return value is a file descriptor which can be passed to mmap(2)
1500 to map the allocated RMA into userspace. The mapped area can then be
1501 passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1502 RMA for a virtual machine. The size of the RMA in bytes (which is
1503 fixed at host kernel boot time) is returned in the rma_size field of
1504 the argument structure.
1506 The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1507 is supported; 2 if the processor requires all virtual machines to have
1508 an RMA, or 1 if the processor can use an RMA but doesn't require it,
1509 because it supports the Virtual RMA (VRMA) facility.
1513 Capability: KVM_CAP_USER_NMI
1517 Returns: 0 on success, -1 on error
1519 Queues an NMI on the thread's vcpu. Note this is well defined only
1520 when KVM_CREATE_IRQCHIP has not been called, since this is an interface
1521 between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
1522 has been called, this interface is completely emulated within the kernel.
1524 To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
1525 following algorithm:
1528 - read the local APIC's state (KVM_GET_LAPIC)
1529 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
1530 - if so, issue KVM_NMI
1533 Some guests configure the LINT1 NMI input to cause a panic, aiding in
1536 4.64 KVM_S390_UCAS_MAP
1538 Capability: KVM_CAP_S390_UCONTROL
1541 Parameters: struct kvm_s390_ucas_mapping (in)
1542 Returns: 0 in case of success
1544 The parameter is defined like this:
1545 struct kvm_s390_ucas_mapping {
1551 This ioctl maps the memory at "user_addr" with the length "length" to
1552 the vcpu's address space starting at "vcpu_addr". All parameters need to
1553 be alligned by 1 megabyte.
1555 4.65 KVM_S390_UCAS_UNMAP
1557 Capability: KVM_CAP_S390_UCONTROL
1560 Parameters: struct kvm_s390_ucas_mapping (in)
1561 Returns: 0 in case of success
1563 The parameter is defined like this:
1564 struct kvm_s390_ucas_mapping {
1570 This ioctl unmaps the memory in the vcpu's address space starting at
1571 "vcpu_addr" with the length "length". The field "user_addr" is ignored.
1572 All parameters need to be alligned by 1 megabyte.
1574 4.66 KVM_S390_VCPU_FAULT
1576 Capability: KVM_CAP_S390_UCONTROL
1579 Parameters: vcpu absolute address (in)
1580 Returns: 0 in case of success
1582 This call creates a page table entry on the virtual cpu's address space
1583 (for user controlled virtual machines) or the virtual machine's address
1584 space (for regular virtual machines). This only works for minor faults,
1585 thus it's recommended to access subject memory page via the user page
1586 table upfront. This is useful to handle validity intercepts for user
1587 controlled virtual machines to fault in the virtual cpu's lowcore pages
1588 prior to calling the KVM_RUN ioctl.
1590 5. The kvm_run structure
1592 Application code obtains a pointer to the kvm_run structure by
1593 mmap()ing a vcpu fd. From that point, application code can control
1594 execution by changing fields in kvm_run prior to calling the KVM_RUN
1595 ioctl, and obtain information about the reason KVM_RUN returned by
1596 looking up structure members.
1600 __u8 request_interrupt_window;
1602 Request that KVM_RUN return when it becomes possible to inject external
1603 interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1610 When KVM_RUN has returned successfully (return value 0), this informs
1611 application code why KVM_RUN has returned. Allowable values for this
1612 field are detailed below.
1614 __u8 ready_for_interrupt_injection;
1616 If request_interrupt_window has been specified, this field indicates
1617 an interrupt can be injected now with KVM_INTERRUPT.
1621 The value of the current interrupt flag. Only valid if in-kernel
1622 local APIC is not used.
1626 /* in (pre_kvm_run), out (post_kvm_run) */
1629 The value of the cr8 register. Only valid if in-kernel local APIC is
1630 not used. Both input and output.
1634 The value of the APIC BASE msr. Only valid if in-kernel local
1635 APIC is not used. Both input and output.
1638 /* KVM_EXIT_UNKNOWN */
1640 __u64 hardware_exit_reason;
1643 If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1644 reasons. Further architecture-specific information is available in
1645 hardware_exit_reason.
1647 /* KVM_EXIT_FAIL_ENTRY */
1649 __u64 hardware_entry_failure_reason;
1652 If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1653 to unknown reasons. Further architecture-specific information is
1654 available in hardware_entry_failure_reason.
1656 /* KVM_EXIT_EXCEPTION */
1666 #define KVM_EXIT_IO_IN 0
1667 #define KVM_EXIT_IO_OUT 1
1669 __u8 size; /* bytes */
1672 __u64 data_offset; /* relative to kvm_run start */
1675 If exit_reason is KVM_EXIT_IO, then the vcpu has
1676 executed a port I/O instruction which could not be satisfied by kvm.
1677 data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1678 where kvm expects application code to place the data for the next
1679 KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
1682 struct kvm_debug_exit_arch arch;
1695 If exit_reason is KVM_EXIT_MMIO, then the vcpu has
1696 executed a memory-mapped I/O instruction which could not be satisfied
1697 by kvm. The 'data' member contains the written data if 'is_write' is
1698 true, and should be filled by application code otherwise.
1700 NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1701 operations are complete (and guest state is consistent) only after userspace
1702 has re-entered the kernel with KVM_RUN. The kernel side will first finish
1703 incomplete operations and then check for pending signals. Userspace
1704 can re-enter the guest with an unmasked signal pending to complete
1707 /* KVM_EXIT_HYPERCALL */
1716 Unused. This was once used for 'hypercall to userspace'. To implement
1717 such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1718 Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
1720 /* KVM_EXIT_TPR_ACCESS */
1727 To be documented (KVM_TPR_ACCESS_REPORTING).
1729 /* KVM_EXIT_S390_SIEIC */
1732 __u64 mask; /* psw upper half */
1733 __u64 addr; /* psw lower half */
1740 /* KVM_EXIT_S390_RESET */
1741 #define KVM_S390_RESET_POR 1
1742 #define KVM_S390_RESET_CLEAR 2
1743 #define KVM_S390_RESET_SUBSYSTEM 4
1744 #define KVM_S390_RESET_CPU_INIT 8
1745 #define KVM_S390_RESET_IPL 16
1746 __u64 s390_reset_flags;
1750 /* KVM_EXIT_S390_UCONTROL */
1752 __u64 trans_exc_code;
1756 s390 specific. A page fault has occurred for a user controlled virtual
1757 machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
1758 resolved by the kernel.
1759 The program code and the translation exception code that were placed
1760 in the cpu's lowcore are presented here as defined by the z Architecture
1761 Principles of Operation Book in the Chapter for Dynamic Address Translation
1778 MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1779 hypercalls and exit with this exit struct that contains all the guest gprs.
1781 If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1782 Userspace can now handle the hypercall and when it's done modify the gprs as
1783 necessary. Upon guest entry all guest GPRs will then be replaced by the values
1786 /* KVM_EXIT_PAPR_HCALL */
1793 This is used on 64-bit PowerPC when emulating a pSeries partition,
1794 e.g. with the 'pseries' machine type in qemu. It occurs when the
1795 guest does a hypercall using the 'sc 1' instruction. The 'nr' field
1796 contains the hypercall number (from the guest R3), and 'args' contains
1797 the arguments (from the guest R4 - R12). Userspace should put the
1798 return code in 'ret' and any extra returned values in args[].
1799 The possible hypercalls are defined in the Power Architecture Platform
1800 Requirements (PAPR) document available from www.power.org (free
1801 developer registration required to access it).
1803 /* Fix the size of the union. */
1808 * shared registers between kvm and userspace.
1809 * kvm_valid_regs specifies the register classes set by the host
1810 * kvm_dirty_regs specified the register classes dirtied by userspace
1811 * struct kvm_sync_regs is architecture specific, as well as the
1812 * bits for kvm_valid_regs and kvm_dirty_regs
1814 __u64 kvm_valid_regs;
1815 __u64 kvm_dirty_regs;
1817 struct kvm_sync_regs regs;
1821 If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
1822 certain guest registers without having to call SET/GET_*REGS. Thus we can
1823 avoid some system call overhead if userspace has to handle the exit.
1824 Userspace can query the validity of the structure by checking
1825 kvm_valid_regs for specific bits. These bits are architecture specific
1826 and usually define the validity of a groups of registers. (e.g. one bit
1827 for general purpose registers)
1831 6. Capabilities that can be enabled
1833 There are certain capabilities that change the behavior of the virtual CPU when
1834 enabled. To enable them, please see section 4.37. Below you can find a list of
1835 capabilities and what their effect on the vCPU is when enabling them.
1837 The following information is provided along with the description:
1839 Architectures: which instruction set architectures provide this ioctl.
1840 x86 includes both i386 and x86_64.
1842 Parameters: what parameters are accepted by the capability.
1844 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
1845 are not detailed, but errors with specific meanings are.
1851 Returns: 0 on success; -1 on error
1853 This capability enables interception of OSI hypercalls that otherwise would
1854 be treated as normal system calls to be injected into the guest. OSI hypercalls
1855 were invented by Mac-on-Linux to have a standardized communication mechanism
1856 between the guest and the host.
1858 When this capability is enabled, KVM_EXIT_OSI can occur.
1860 6.2 KVM_CAP_PPC_PAPR
1864 Returns: 0 on success; -1 on error
1866 This capability enables interception of PAPR hypercalls. PAPR hypercalls are
1867 done using the hypercall instruction "sc 1".
1869 It also sets the guest privilege level to "supervisor" mode. Usually the guest
1870 runs in "hypervisor" privilege mode with a few missing features.
1872 In addition to the above, it changes the semantics of SDR1. In this mode, the
1873 HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
1874 HTAB invisible to the guest.
1876 When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
1881 Parameters: args[0] is the address of a struct kvm_config_tlb
1882 Returns: 0 on success; -1 on error
1884 struct kvm_config_tlb {
1891 Configures the virtual CPU's TLB array, establishing a shared memory area
1892 between userspace and KVM. The "params" and "array" fields are userspace
1893 addresses of mmu-type-specific data structures. The "array_len" field is an
1894 safety mechanism, and should be set to the size in bytes of the memory that
1895 userspace has reserved for the array. It must be at least the size dictated
1896 by "mmu_type" and "params".
1898 While KVM_RUN is active, the shared region is under control of KVM. Its
1899 contents are undefined, and any modification by userspace results in
1900 boundedly undefined behavior.
1902 On return from KVM_RUN, the shared region will reflect the current state of
1903 the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
1904 to tell KVM which entries have been changed, prior to calling KVM_RUN again
1907 For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
1908 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
1909 - The "array" field points to an array of type "struct
1910 kvm_book3e_206_tlb_entry".
1911 - The array consists of all entries in the first TLB, followed by all
1912 entries in the second TLB.
1913 - Within a TLB, entries are ordered first by increasing set number. Within a
1914 set, entries are ordered by way (increasing ESEL).
1915 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
1916 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
1917 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
1918 hardware ignores this value for TLB0.