1 .. SPDX-License-Identifier: GPL-2.0
3 ===================================================================
4 The Definitive KVM (Kernel-based Virtual Machine) API Documentation
5 ===================================================================
10 The kvm API is a set of ioctls that are issued to control various aspects
11 of a virtual machine. The ioctls belong to the following classes:
13 - System ioctls: These query and set global attributes which affect the
14 whole kvm subsystem. In addition a system ioctl is used to create
17 - VM ioctls: These query and set attributes that affect an entire virtual
18 machine, for example memory layout. In addition a VM ioctl is used to
19 create virtual cpus (vcpus) and devices.
21 VM ioctls must be issued from the same process (address space) that was
22 used to create the VM.
24 - vcpu ioctls: These query and set attributes that control the operation
25 of a single virtual cpu.
27 vcpu ioctls should be issued from the same thread that was used to create
28 the vcpu, except for asynchronous vcpu ioctl that are marked as such in
29 the documentation. Otherwise, the first ioctl after switching threads
30 could see a performance impact.
32 - device ioctls: These query and set attributes that control the operation
35 device ioctls must be issued from the same process (address space) that
36 was used to create the VM.
41 The kvm API is centered around file descriptors. An initial
42 open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
43 can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
44 handle will create a VM file descriptor which can be used to issue VM
45 ioctls. A KVM_CREATE_VCPU or KVM_CREATE_DEVICE ioctl on a VM fd will
46 create a virtual cpu or device and return a file descriptor pointing to
47 the new resource. Finally, ioctls on a vcpu or device fd can be used
48 to control the vcpu or device. For vcpus, this includes the important
49 task of actually running guest code.
51 In general file descriptors can be migrated among processes by means
52 of fork() and the SCM_RIGHTS facility of unix domain socket. These
53 kinds of tricks are explicitly not supported by kvm. While they will
54 not cause harm to the host, their actual behavior is not guaranteed by
55 the API. See "General description" for details on the ioctl usage
56 model that is supported by KVM.
58 It is important to note that although VM ioctls may only be issued from
59 the process that created the VM, a VM's lifecycle is associated with its
60 file descriptor, not its creator (process). In other words, the VM and
61 its resources, *including the associated address space*, are not freed
62 until the last reference to the VM's file descriptor has been released.
63 For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
64 not be freed until both the parent (original) process and its child have
65 put their references to the VM's file descriptor.
67 Because a VM's resources are not freed until the last reference to its
68 file descriptor is released, creating additional references to a VM
69 via fork(), dup(), etc... without careful consideration is strongly
70 discouraged and may have unwanted side effects, e.g. memory allocated
71 by and on behalf of the VM's process may not be freed/unaccounted when
78 As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
79 incompatible change are allowed. However, there is an extension
80 facility that allows backward-compatible extensions to the API to be
83 The extension mechanism is not based on the Linux version number.
84 Instead, kvm defines extension identifiers and a facility to query
85 whether a particular extension identifier is available. If it is, a
86 set of ioctls is available for application use.
92 This section describes ioctls that can be used to control kvm guests.
93 For each ioctl, the following information is provided along with a
97 which KVM extension provides this ioctl. Can be 'basic',
98 which means that is will be provided by any kernel that supports
99 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
100 means availability needs to be checked with KVM_CHECK_EXTENSION
101 (see section 4.4), or 'none' which means that while not all kernels
102 support this ioctl, there's no capability bit to check its
103 availability: for kernels that don't support the ioctl,
104 the ioctl returns -ENOTTY.
107 which instruction set architectures provide this ioctl.
108 x86 includes both i386 and x86_64.
114 what parameters are accepted by the ioctl.
117 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
118 are not detailed, but errors with specific meanings are.
121 4.1 KVM_GET_API_VERSION
122 -----------------------
128 :Returns: the constant KVM_API_VERSION (=12)
130 This identifies the API version as the stable kvm API. It is not
131 expected that this number will change. However, Linux 2.6.20 and
132 2.6.21 report earlier versions; these are not documented and not
133 supported. Applications should refuse to run if KVM_GET_API_VERSION
134 returns a value other than 12. If this check passes, all ioctls
135 described as 'basic' will be available.
144 :Parameters: machine type identifier (KVM_VM_*)
145 :Returns: a VM fd that can be used to control the new virtual machine.
147 The new VM has no virtual cpus and no memory.
148 You probably want to use 0 as machine type.
150 In order to create user controlled virtual machines on S390, check
151 KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
152 privileged user (CAP_SYS_ADMIN).
154 On arm64, the physical address size for a VM (IPA Size limit) is limited
155 to 40bits by default. The limit can be configured if the host supports the
156 extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use
157 KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type
158 identifier, where IPA_Bits is the maximum width of any physical
159 address used by the VM. The IPA_Bits is encoded in bits[7-0] of the
160 machine type identifier.
162 e.g, to configure a guest to use 48bit physical address size::
164 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48));
166 The requested size (IPA_Bits) must be:
168 == =========================================================
169 0 Implies default size, 40bits (for backward compatibility)
170 N Implies N bits, where N is a positive integer such that,
171 32 <= N <= Host_IPA_Limit
172 == =========================================================
174 Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and
175 is dependent on the CPU capability and the kernel configuration. The limit can
176 be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
179 Creation of the VM will fail if the requested IPA size (whether it is
180 implicit or explicit) is unsupported on the host.
182 Please note that configuring the IPA size does not affect the capability
183 exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
184 size of the address translated by the stage2 level (guest physical to
185 host physical address translations).
188 4.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
189 ----------------------------------------------------------
191 :Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
194 :Parameters: struct kvm_msr_list (in/out)
195 :Returns: 0 on success; -1 on error
199 ====== ============================================================
200 EFAULT the msr index list cannot be read from or written to
201 E2BIG the msr index list is too big to fit in the array specified by
203 ====== ============================================================
207 struct kvm_msr_list {
208 __u32 nmsrs; /* number of msrs in entries */
212 The user fills in the size of the indices array in nmsrs, and in return
213 kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
214 indices array with their numbers.
216 KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
217 varies by kvm version and host processor, but does not change otherwise.
219 Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
220 not returned in the MSR list, as different vcpus can have a different number
221 of banks, as set via the KVM_X86_SETUP_MCE ioctl.
223 KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
224 to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
225 and processor features that are exposed via MSRs (e.g., VMX capabilities).
226 This list also varies by kvm version and host processor, but does not change
230 4.4 KVM_CHECK_EXTENSION
231 -----------------------
233 :Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
235 :Type: system ioctl, vm ioctl
236 :Parameters: extension identifier (KVM_CAP_*)
237 :Returns: 0 if unsupported; 1 (or some other positive integer) if supported
239 The API allows the application to query about extensions to the core
240 kvm API. Userspace passes an extension identifier (an integer) and
241 receives an integer that describes the extension availability.
242 Generally 0 means no and 1 means yes, but some extensions may report
243 additional information in the integer return value.
245 Based on their initialization different VMs may have different capabilities.
246 It is thus encouraged to use the vm ioctl to query for capabilities (available
247 with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
249 4.5 KVM_GET_VCPU_MMAP_SIZE
250 --------------------------
256 :Returns: size of vcpu mmap area, in bytes
258 The KVM_RUN ioctl (cf.) communicates with userspace via a shared
259 memory region. This ioctl returns the size of that region. See the
260 KVM_RUN documentation for details.
262 Besides the size of the KVM_RUN communication region, other areas of
263 the VCPU file descriptor can be mmap-ed, including:
265 - if KVM_CAP_COALESCED_MMIO is available, a page at
266 KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons,
267 this page is included in the result of KVM_GET_VCPU_MMAP_SIZE.
268 KVM_CAP_COALESCED_MMIO is not documented yet.
270 - if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at
271 KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE. For more information on
272 KVM_CAP_DIRTY_LOG_RING, see section 8.3.
281 :Parameters: vcpu id (apic id on x86)
282 :Returns: vcpu fd on success, -1 on error
284 This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
285 The vcpu id is an integer in the range [0, max_vcpu_id).
287 The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
288 the KVM_CHECK_EXTENSION ioctl() at run-time.
289 The maximum possible value for max_vcpus can be retrieved using the
290 KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
292 If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
294 If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
295 same as the value returned from KVM_CAP_NR_VCPUS.
297 The maximum possible value for max_vcpu_id can be retrieved using the
298 KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
300 If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
301 is the same as the value returned from KVM_CAP_MAX_VCPUS.
303 On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
304 threads in one or more virtual CPU cores. (This is because the
305 hardware requires all the hardware threads in a CPU core to be in the
306 same partition.) The KVM_CAP_PPC_SMT capability indicates the number
307 of vcpus per virtual core (vcore). The vcore id is obtained by
308 dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
309 given vcore will always be in the same physical core as each other
310 (though that might be a different physical core from time to time).
311 Userspace can control the threading (SMT) mode of the guest by its
312 allocation of vcpu ids. For example, if userspace wants
313 single-threaded guest vcpus, it should make all vcpu ids be a multiple
314 of the number of vcpus per vcore.
316 For virtual cpus that have been created with S390 user controlled virtual
317 machines, the resulting vcpu fd can be memory mapped at page offset
318 KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
319 cpu's hardware control block.
322 4.8 KVM_GET_DIRTY_LOG (vm ioctl)
323 --------------------------------
328 :Parameters: struct kvm_dirty_log (in/out)
329 :Returns: 0 on success, -1 on error
333 /* for KVM_GET_DIRTY_LOG */
334 struct kvm_dirty_log {
338 void __user *dirty_bitmap; /* one bit per page */
343 Given a memory slot, return a bitmap containing any pages dirtied
344 since the last call to this ioctl. Bit 0 is the first page in the
345 memory slot. Ensure the entire structure is cleared to avoid padding
348 If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
349 the address space for which you want to return the dirty bitmap. See
350 KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
352 The bits in the dirty bitmap are cleared before the ioctl returns, unless
353 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information,
354 see the description of the capability.
356 Note that the Xen shared info page, if configured, shall always be assumed
357 to be dirty. KVM will not explicitly mark it such.
367 :Returns: 0 on success, -1 on error
371 ======= ==============================================================
372 EINTR an unmasked signal is pending
373 ENOEXEC the vcpu hasn't been initialized or the guest tried to execute
374 instructions from device memory (arm64)
375 ENOSYS data abort outside memslots with no syndrome info and
376 KVM_CAP_ARM_NISV_TO_USER not enabled (arm64)
377 EPERM SVE feature set but not finalized (arm64)
378 ======= ==============================================================
380 This ioctl is used to run a guest virtual cpu. While there are no
381 explicit parameters, there is an implicit parameter block that can be
382 obtained by mmap()ing the vcpu fd at offset 0, with the size given by
383 KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
384 kvm_run' (see below).
391 :Architectures: all except arm64
393 :Parameters: struct kvm_regs (out)
394 :Returns: 0 on success, -1 on error
396 Reads the general purpose registers from the vcpu.
402 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
403 __u64 rax, rbx, rcx, rdx;
404 __u64 rsi, rdi, rsp, rbp;
405 __u64 r8, r9, r10, r11;
406 __u64 r12, r13, r14, r15;
412 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
421 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
422 unsigned long gpr[32];
431 :Architectures: all except arm64
433 :Parameters: struct kvm_regs (in)
434 :Returns: 0 on success, -1 on error
436 Writes the general purpose registers into the vcpu.
438 See KVM_GET_REGS for the data structure.
445 :Architectures: x86, ppc
447 :Parameters: struct kvm_sregs (out)
448 :Returns: 0 on success, -1 on error
450 Reads special registers from the vcpu.
456 struct kvm_segment cs, ds, es, fs, gs, ss;
457 struct kvm_segment tr, ldt;
458 struct kvm_dtable gdt, idt;
459 __u64 cr0, cr2, cr3, cr4, cr8;
462 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
465 /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
467 interrupt_bitmap is a bitmap of pending external interrupts. At most
468 one bit may be set. This interrupt has been acknowledged by the APIC
469 but not yet injected into the cpu core.
476 :Architectures: x86, ppc
478 :Parameters: struct kvm_sregs (in)
479 :Returns: 0 on success, -1 on error
481 Writes special registers into the vcpu. See KVM_GET_SREGS for the
491 :Parameters: struct kvm_translation (in/out)
492 :Returns: 0 on success, -1 on error
494 Translates a virtual address according to the vcpu's current address
499 struct kvm_translation {
501 __u64 linear_address;
504 __u64 physical_address;
516 :Architectures: x86, ppc, mips, riscv, loongarch
518 :Parameters: struct kvm_interrupt (in)
519 :Returns: 0 on success, negative on failure.
521 Queues a hardware interrupt vector to be injected.
525 /* for KVM_INTERRUPT */
526 struct kvm_interrupt {
536 ========= ===================================
538 -EEXIST if an interrupt is already enqueued
539 -EINVAL the irq number is invalid
540 -ENXIO if the PIC is in the kernel
541 -EFAULT if the pointer is invalid
542 ========= ===================================
544 Note 'irq' is an interrupt vector, not an interrupt pin or line. This
545 ioctl is useful if the in-kernel PIC is not used.
550 Queues an external interrupt to be injected. This ioctl is overloaded
551 with 3 different irq values:
555 This injects an edge type external interrupt into the guest once it's ready
556 to receive interrupts. When injected, the interrupt is done.
558 b) KVM_INTERRUPT_UNSET
560 This unsets any pending interrupt.
562 Only available with KVM_CAP_PPC_UNSET_IRQ.
564 c) KVM_INTERRUPT_SET_LEVEL
566 This injects a level type external interrupt into the guest context. The
567 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
570 Only available with KVM_CAP_PPC_IRQ_LEVEL.
572 Note that any value for 'irq' other than the ones stated above is invalid
573 and incurs unexpected behavior.
575 This is an asynchronous vcpu ioctl and can be invoked from any thread.
580 Queues an external interrupt to be injected into the virtual CPU. A negative
581 interrupt number dequeues the interrupt.
583 This is an asynchronous vcpu ioctl and can be invoked from any thread.
588 Queues an external interrupt to be injected into the virtual CPU. This ioctl
589 is overloaded with 2 different irq values:
593 This sets external interrupt for a virtual CPU and it will receive
596 b) KVM_INTERRUPT_UNSET
598 This clears pending external interrupt for a virtual CPU.
600 This is an asynchronous vcpu ioctl and can be invoked from any thread.
605 Queues an external interrupt to be injected into the virtual CPU. A negative
606 interrupt number dequeues the interrupt.
608 This is an asynchronous vcpu ioctl and can be invoked from any thread.
618 :Returns: -1 on error
620 Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
626 :Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
628 :Type: system ioctl, vcpu ioctl
629 :Parameters: struct kvm_msrs (in/out)
630 :Returns: number of msrs successfully returned;
633 When used as a system ioctl:
634 Reads the values of MSR-based features that are available for the VM. This
635 is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
636 The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
639 When used as a vcpu ioctl:
640 Reads model-specific registers from the vcpu. Supported msr indices can
641 be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
646 __u32 nmsrs; /* number of msrs in entries */
649 struct kvm_msr_entry entries[0];
652 struct kvm_msr_entry {
658 Application code should set the 'nmsrs' member (which indicates the
659 size of the entries array) and the 'index' member of each array entry.
660 kvm will fill in the 'data' member.
669 :Parameters: struct kvm_msrs (in)
670 :Returns: number of msrs successfully set (see below), -1 on error
672 Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
675 Application code should set the 'nmsrs' member (which indicates the
676 size of the entries array), and the 'index' and 'data' members of each
679 It tries to set the MSRs in array entries[] one by one. If setting an MSR
680 fails, e.g., due to setting reserved bits, the MSR isn't supported/emulated
681 by KVM, etc..., it stops processing the MSR list and returns the number of
682 MSRs that have been set successfully.
691 :Parameters: struct kvm_cpuid (in)
692 :Returns: 0 on success, -1 on error
694 Defines the vcpu responses to the cpuid instruction. Applications
695 should use the KVM_SET_CPUID2 ioctl if available.
698 - If this IOCTL fails, KVM gives no guarantees that previous valid CPUID
699 configuration (if there is) is not corrupted. Userspace can get a copy
700 of the resulting CPUID configuration through KVM_GET_CPUID2 in case.
701 - Using KVM_SET_CPUID{,2} after KVM_RUN, i.e. changing the guest vCPU model
702 after running the guest, may cause guest instability.
703 - Using heterogeneous CPUID configurations, modulo APIC IDs, topology, etc...
704 may cause guest instability.
708 struct kvm_cpuid_entry {
717 /* for KVM_SET_CPUID */
721 struct kvm_cpuid_entry entries[0];
725 4.21 KVM_SET_SIGNAL_MASK
726 ------------------------
731 :Parameters: struct kvm_signal_mask (in)
732 :Returns: 0 on success, -1 on error
734 Defines which signals are blocked during execution of KVM_RUN. This
735 signal mask temporarily overrides the threads signal mask. Any
736 unblocked signal received (except SIGKILL and SIGSTOP, which retain
737 their traditional behaviour) will cause KVM_RUN to return with -EINTR.
739 Note the signal will only be delivered if not blocked by the original
744 /* for KVM_SET_SIGNAL_MASK */
745 struct kvm_signal_mask {
755 :Architectures: x86, loongarch
757 :Parameters: struct kvm_fpu (out)
758 :Returns: 0 on success, -1 on error
760 Reads the floating point state from the vcpu.
764 /* x86: for KVM_GET_FPU and KVM_SET_FPU */
769 __u8 ftwx; /* in fxsave format */
779 /* LoongArch: for KVM_GET_FPU and KVM_SET_FPU */
793 :Architectures: x86, loongarch
795 :Parameters: struct kvm_fpu (in)
796 :Returns: 0 on success, -1 on error
798 Writes the floating point state to the vcpu.
802 /* x86: for KVM_GET_FPU and KVM_SET_FPU */
807 __u8 ftwx; /* in fxsave format */
817 /* LoongArch: for KVM_GET_FPU and KVM_SET_FPU */
827 4.24 KVM_CREATE_IRQCHIP
828 -----------------------
830 :Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
831 :Architectures: x86, arm64, s390
834 :Returns: 0 on success, -1 on error
836 Creates an interrupt controller model in the kernel.
837 On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
838 future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
839 PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
840 On arm64, a GICv2 is created. Any other GIC versions require the usage of
841 KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
842 KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
843 On s390, a dummy irq routing table is created.
845 Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
846 before KVM_CREATE_IRQCHIP can be used.
852 :Capability: KVM_CAP_IRQCHIP
853 :Architectures: x86, arm64
855 :Parameters: struct kvm_irq_level
856 :Returns: 0 on success, -1 on error
858 Sets the level of a GSI input to the interrupt controller model in the kernel.
859 On some architectures it is required that an interrupt controller model has
860 been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
861 interrupts require the level to be set to 1 and then back to 0.
863 On real hardware, interrupt pins can be active-low or active-high. This
864 does not matter for the level field of struct kvm_irq_level: 1 always
865 means active (asserted), 0 means inactive (deasserted).
867 x86 allows the operating system to program the interrupt polarity
868 (active-low/active-high) for level-triggered interrupts, and KVM used
869 to consider the polarity. However, due to bitrot in the handling of
870 active-low interrupts, the above convention is now valid on x86 too.
871 This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
872 should not present interrupts to the guest as active-low unless this
873 capability is present (or unless it is not using the in-kernel irqchip,
877 arm64 can signal an interrupt either at the CPU level, or at the
878 in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
879 use PPIs designated for specific cpus. The irq field is interpreted
882 bits: | 31 ... 28 | 27 ... 24 | 23 ... 16 | 15 ... 0 |
883 field: | vcpu2_index | irq_type | vcpu_index | irq_id |
885 The irq_type field has the following values:
888 out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
890 in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
891 (the vcpu_index field is ignored)
893 in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
895 (The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
897 In both cases, level is used to assert/deassert the line.
899 When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is
900 identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index
903 Note that on arm64, the KVM_CAP_IRQCHIP capability only conditions
904 injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always
905 be used for a userspace interrupt controller.
909 struct kvm_irq_level {
912 __s32 status; /* not used for KVM_IRQ_LEVEL */
914 __u32 level; /* 0 or 1 */
921 :Capability: KVM_CAP_IRQCHIP
924 :Parameters: struct kvm_irqchip (in/out)
925 :Returns: 0 on success, -1 on error
927 Reads the state of a kernel interrupt controller created with
928 KVM_CREATE_IRQCHIP into a buffer provided by the caller.
933 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
936 char dummy[512]; /* reserving space */
937 struct kvm_pic_state pic;
938 struct kvm_ioapic_state ioapic;
946 :Capability: KVM_CAP_IRQCHIP
949 :Parameters: struct kvm_irqchip (in)
950 :Returns: 0 on success, -1 on error
952 Sets the state of a kernel interrupt controller created with
953 KVM_CREATE_IRQCHIP from a buffer provided by the caller.
958 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
961 char dummy[512]; /* reserving space */
962 struct kvm_pic_state pic;
963 struct kvm_ioapic_state ioapic;
968 4.28 KVM_XEN_HVM_CONFIG
969 -----------------------
971 :Capability: KVM_CAP_XEN_HVM
974 :Parameters: struct kvm_xen_hvm_config (in)
975 :Returns: 0 on success, -1 on error
977 Sets the MSR that the Xen HVM guest uses to initialize its hypercall
978 page, and provides the starting address and size of the hypercall
979 blobs in userspace. When the guest writes the MSR, kvm copies one
980 page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
985 struct kvm_xen_hvm_config {
995 If certain flags are returned from the KVM_CAP_XEN_HVM check, they may
996 be set in the flags field of this ioctl:
998 The KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag requests KVM to generate
999 the contents of the hypercall page automatically; hypercalls will be
1000 intercepted and passed to userspace through KVM_EXIT_XEN. In this
1001 case, all of the blob size and address fields must be zero.
1003 The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates to KVM that userspace
1004 will always use the KVM_XEN_HVM_EVTCHN_SEND ioctl to deliver event
1005 channel interrupts rather than manipulating the guest's shared_info
1006 structures directly. This, in turn, may allow KVM to enable features
1007 such as intercepting the SCHEDOP_poll hypercall to accelerate PV
1008 spinlock operation for the guest. Userspace may still use the ioctl
1009 to deliver events if it was advertised, even if userspace does not
1010 send this indication that it will always do so
1012 No other flags are currently valid in the struct kvm_xen_hvm_config.
1017 :Capability: KVM_CAP_ADJUST_CLOCK
1020 :Parameters: struct kvm_clock_data (out)
1021 :Returns: 0 on success, -1 on error
1023 Gets the current timestamp of kvmclock as seen by the current guest. In
1024 conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
1027 When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
1028 set of bits that KVM can return in struct kvm_clock_data's flag member.
1030 The following flags are defined:
1032 KVM_CLOCK_TSC_STABLE
1033 If set, the returned value is the exact kvmclock
1034 value seen by all VCPUs at the instant when KVM_GET_CLOCK was called.
1035 If clear, the returned value is simply CLOCK_MONOTONIC plus a constant
1036 offset; the offset can be modified with KVM_SET_CLOCK. KVM will try
1037 to make all VCPUs follow this clock, but the exact value read by each
1038 VCPU could differ, because the host TSC is not stable.
1041 If set, the `realtime` field in the kvm_clock_data
1042 structure is populated with the value of the host's real time
1043 clocksource at the instant when KVM_GET_CLOCK was called. If clear,
1044 the `realtime` field does not contain a value.
1047 If set, the `host_tsc` field in the kvm_clock_data
1048 structure is populated with the value of the host's timestamp counter (TSC)
1049 at the instant when KVM_GET_CLOCK was called. If clear, the `host_tsc` field
1050 does not contain a value.
1054 struct kvm_clock_data {
1055 __u64 clock; /* kvmclock current value */
1067 :Capability: KVM_CAP_ADJUST_CLOCK
1070 :Parameters: struct kvm_clock_data (in)
1071 :Returns: 0 on success, -1 on error
1073 Sets the current timestamp of kvmclock to the value specified in its parameter.
1074 In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
1077 The following flags can be passed:
1080 If set, KVM will compare the value of the `realtime` field
1081 with the value of the host's real time clocksource at the instant when
1082 KVM_SET_CLOCK was called. The difference in elapsed time is added to the final
1083 kvmclock value that will be provided to guests.
1085 Other flags returned by ``KVM_GET_CLOCK`` are accepted but ignored.
1089 struct kvm_clock_data {
1090 __u64 clock; /* kvmclock current value */
1099 4.31 KVM_GET_VCPU_EVENTS
1100 ------------------------
1102 :Capability: KVM_CAP_VCPU_EVENTS
1103 :Extended by: KVM_CAP_INTR_SHADOW
1104 :Architectures: x86, arm64
1106 :Parameters: struct kvm_vcpu_events (out)
1107 :Returns: 0 on success, -1 on error
1112 Gets currently pending exceptions, interrupts, and NMIs as well as related
1117 struct kvm_vcpu_events {
1121 __u8 has_error_code;
1142 __u8 smm_inside_nmi;
1146 __u8 exception_has_payload;
1147 __u64 exception_payload;
1150 The following bits are defined in the flags field:
1152 - KVM_VCPUEVENT_VALID_SHADOW may be set to signal that
1153 interrupt.shadow contains a valid state.
1155 - KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a
1158 - KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the
1159 exception_has_payload, exception_payload, and exception.pending
1160 fields contain a valid state. This bit will be set whenever
1161 KVM_CAP_EXCEPTION_PAYLOAD is enabled.
1163 - KVM_VCPUEVENT_VALID_TRIPLE_FAULT may be set to signal that the
1164 triple_fault_pending field contains a valid state. This bit will
1165 be set whenever KVM_CAP_X86_TRIPLE_FAULT_EVENT is enabled.
1170 If the guest accesses a device that is being emulated by the host kernel in
1171 such a way that a real device would generate a physical SError, KVM may make
1172 a virtual SError pending for that VCPU. This system error interrupt remains
1173 pending until the guest takes the exception by unmasking PSTATE.A.
1175 Running the VCPU may cause it to take a pending SError, or make an access that
1176 causes an SError to become pending. The event's description is only valid while
1177 the VPCU is not running.
1179 This API provides a way to read and write the pending 'event' state that is not
1180 visible to the guest. To save, restore or migrate a VCPU the struct representing
1181 the state can be read then written using this GET/SET API, along with the other
1182 guest-visible registers. It is not possible to 'cancel' an SError that has been
1185 A device being emulated in user-space may also wish to generate an SError. To do
1186 this the events structure can be populated by user-space. The current state
1187 should be read first, to ensure no existing SError is pending. If an existing
1188 SError is pending, the architecture's 'Multiple SError interrupts' rules should
1189 be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
1190 Serviceability (RAS) Specification").
1192 SError exceptions always have an ESR value. Some CPUs have the ability to
1193 specify what the virtual SError's ESR value should be. These systems will
1194 advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will
1195 always have a non-zero value when read, and the agent making an SError pending
1196 should specify the ISS field in the lower 24 bits of exception.serror_esr. If
1197 the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events
1198 with exception.has_esr as zero, KVM will choose an ESR.
1200 Specifying exception.has_esr on a system that does not support it will return
1201 -EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
1202 will return -EINVAL.
1204 It is not possible to read back a pending external abort (injected via
1205 KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered
1206 directly to the virtual CPU).
1210 struct kvm_vcpu_events {
1212 __u8 serror_pending;
1213 __u8 serror_has_esr;
1214 __u8 ext_dabt_pending;
1215 /* Align it to 8 bytes */
1222 4.32 KVM_SET_VCPU_EVENTS
1223 ------------------------
1225 :Capability: KVM_CAP_VCPU_EVENTS
1226 :Extended by: KVM_CAP_INTR_SHADOW
1227 :Architectures: x86, arm64
1229 :Parameters: struct kvm_vcpu_events (in)
1230 :Returns: 0 on success, -1 on error
1235 Set pending exceptions, interrupts, and NMIs as well as related states of the
1238 See KVM_GET_VCPU_EVENTS for the data structure.
1240 Fields that may be modified asynchronously by running VCPUs can be excluded
1241 from the update. These fields are nmi.pending, sipi_vector, smi.smm,
1242 smi.pending. Keep the corresponding bits in the flags field cleared to
1243 suppress overwriting the current in-kernel state. The bits are:
1245 =============================== ==================================
1246 KVM_VCPUEVENT_VALID_NMI_PENDING transfer nmi.pending to the kernel
1247 KVM_VCPUEVENT_VALID_SIPI_VECTOR transfer sipi_vector
1248 KVM_VCPUEVENT_VALID_SMM transfer the smi sub-struct.
1249 =============================== ==================================
1251 If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
1252 the flags field to signal that interrupt.shadow contains a valid state and
1253 shall be written into the VCPU.
1255 KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
1257 If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD
1258 can be set in the flags field to signal that the
1259 exception_has_payload, exception_payload, and exception.pending fields
1260 contain a valid state and shall be written into the VCPU.
1262 If KVM_CAP_X86_TRIPLE_FAULT_EVENT is enabled, KVM_VCPUEVENT_VALID_TRIPLE_FAULT
1263 can be set in flags field to signal that the triple_fault field contains
1264 a valid state and shall be written into the VCPU.
1269 User space may need to inject several types of events to the guest.
1271 Set the pending SError exception state for this VCPU. It is not possible to
1272 'cancel' an Serror that has been made pending.
1274 If the guest performed an access to I/O memory which could not be handled by
1275 userspace, for example because of missing instruction syndrome decode
1276 information or because there is no device mapped at the accessed IPA, then
1277 userspace can ask the kernel to inject an external abort using the address
1278 from the exiting fault on the VCPU. It is a programming error to set
1279 ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or
1280 KVM_EXIT_ARM_NISV. This feature is only available if the system supports
1281 KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in
1282 how userspace reports accesses for the above cases to guests, across different
1283 userspace implementations. Nevertheless, userspace can still emulate all Arm
1284 exceptions by manipulating individual registers using the KVM_SET_ONE_REG API.
1286 See KVM_GET_VCPU_EVENTS for the data structure.
1289 4.33 KVM_GET_DEBUGREGS
1290 ----------------------
1292 :Capability: KVM_CAP_DEBUGREGS
1295 :Parameters: struct kvm_debugregs (out)
1296 :Returns: 0 on success, -1 on error
1298 Reads debug registers from the vcpu.
1302 struct kvm_debugregs {
1311 4.34 KVM_SET_DEBUGREGS
1312 ----------------------
1314 :Capability: KVM_CAP_DEBUGREGS
1317 :Parameters: struct kvm_debugregs (in)
1318 :Returns: 0 on success, -1 on error
1320 Writes debug registers into the vcpu.
1322 See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
1323 yet and must be cleared on entry.
1326 4.35 KVM_SET_USER_MEMORY_REGION
1327 -------------------------------
1329 :Capability: KVM_CAP_USER_MEMORY
1332 :Parameters: struct kvm_userspace_memory_region (in)
1333 :Returns: 0 on success, -1 on error
1337 struct kvm_userspace_memory_region {
1340 __u64 guest_phys_addr;
1341 __u64 memory_size; /* bytes */
1342 __u64 userspace_addr; /* start of the userspace allocated memory */
1345 /* for kvm_userspace_memory_region::flags */
1346 #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
1347 #define KVM_MEM_READONLY (1UL << 1)
1349 This ioctl allows the user to create, modify or delete a guest physical
1350 memory slot. Bits 0-15 of "slot" specify the slot id and this value
1351 should be less than the maximum number of user memory slots supported per
1352 VM. The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS.
1353 Slots may not overlap in guest physical address space.
1355 If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1356 specifies the address space which is being modified. They must be
1357 less than the value that KVM_CHECK_EXTENSION returns for the
1358 KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
1359 are unrelated; the restriction on overlapping slots only applies within
1362 Deleting a slot is done by passing zero for memory_size. When changing
1363 an existing slot, it may be moved in the guest physical memory space,
1364 or its flags may be modified, but it may not be resized.
1366 Memory for the region is taken starting at the address denoted by the
1367 field userspace_addr, which must point at user addressable memory for
1368 the entire memory slot size. Any object may back this memory, including
1369 anonymous memory, ordinary files, and hugetlbfs.
1371 On architectures that support a form of address tagging, userspace_addr must
1372 be an untagged address.
1374 It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1375 be identical. This allows large pages in the guest to be backed by large
1378 The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1379 KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
1380 writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
1381 use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1382 to make a new slot read-only. In this case, writes to this memory will be
1383 posted to userspace as KVM_EXIT_MMIO exits.
1385 When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1386 the memory region are automatically reflected into the guest. For example, an
1387 mmap() that affects the region will be made visible immediately. Another
1388 example is madvise(MADV_DROP).
1390 Note: On arm64, a write generated by the page-table walker (to update
1391 the Access and Dirty flags, for example) never results in a
1392 KVM_EXIT_MMIO exit when the slot has the KVM_MEM_READONLY flag. This
1393 is because KVM cannot provide the data that would be written by the
1394 page-table walker, making it impossible to emulate the access.
1395 Instead, an abort (data abort if the cause of the page-table update
1396 was a load or a store, instruction abort if it was an instruction
1397 fetch) is injected in the guest.
1399 4.36 KVM_SET_TSS_ADDR
1400 ---------------------
1402 :Capability: KVM_CAP_SET_TSS_ADDR
1405 :Parameters: unsigned long tss_address (in)
1406 :Returns: 0 on success, -1 on error
1408 This ioctl defines the physical address of a three-page region in the guest
1409 physical address space. The region must be within the first 4GB of the
1410 guest physical address space and must not conflict with any memory slot
1411 or any mmio address. The guest may malfunction if it accesses this memory
1414 This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1415 because of a quirk in the virtualization implementation (see the internals
1416 documentation when it pops into existence).
1422 :Capability: KVM_CAP_ENABLE_CAP
1423 :Architectures: mips, ppc, s390, x86, loongarch
1425 :Parameters: struct kvm_enable_cap (in)
1426 :Returns: 0 on success; -1 on error
1428 :Capability: KVM_CAP_ENABLE_CAP_VM
1431 :Parameters: struct kvm_enable_cap (in)
1432 :Returns: 0 on success; -1 on error
1436 Not all extensions are enabled by default. Using this ioctl the application
1437 can enable an extension, making it available to the guest.
1439 On systems that do not support this ioctl, it always fails. On systems that
1440 do support it, it only works for extensions that are supported for enablement.
1442 To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1447 struct kvm_enable_cap {
1451 The capability that is supposed to get enabled.
1457 A bitfield indicating future enhancements. Has to be 0 for now.
1463 Arguments for enabling a feature. If a feature needs initial values to
1464 function properly, this is the place to put them.
1471 The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1472 for vm-wide capabilities.
1474 4.38 KVM_GET_MP_STATE
1475 ---------------------
1477 :Capability: KVM_CAP_MP_STATE
1478 :Architectures: x86, s390, arm64, riscv, loongarch
1480 :Parameters: struct kvm_mp_state (out)
1481 :Returns: 0 on success; -1 on error
1485 struct kvm_mp_state {
1489 Returns the vcpu's current "multiprocessing state" (though also valid on
1490 uniprocessor guests).
1492 Possible values are:
1494 ========================== ===============================================
1495 KVM_MP_STATE_RUNNABLE the vcpu is currently running
1496 [x86,arm64,riscv,loongarch]
1497 KVM_MP_STATE_UNINITIALIZED the vcpu is an application processor (AP)
1498 which has not yet received an INIT signal [x86]
1499 KVM_MP_STATE_INIT_RECEIVED the vcpu has received an INIT signal, and is
1500 now ready for a SIPI [x86]
1501 KVM_MP_STATE_HALTED the vcpu has executed a HLT instruction and
1502 is waiting for an interrupt [x86]
1503 KVM_MP_STATE_SIPI_RECEIVED the vcpu has just received a SIPI (vector
1504 accessible via KVM_GET_VCPU_EVENTS) [x86]
1505 KVM_MP_STATE_STOPPED the vcpu is stopped [s390,arm64,riscv]
1506 KVM_MP_STATE_CHECK_STOP the vcpu is in a special error state [s390]
1507 KVM_MP_STATE_OPERATING the vcpu is operating (running or halted)
1509 KVM_MP_STATE_LOAD the vcpu is in a special load/startup state
1511 KVM_MP_STATE_SUSPENDED the vcpu is in a suspend state and is waiting
1512 for a wakeup event [arm64]
1513 ========================== ===============================================
1515 On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
1516 in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1517 these architectures.
1522 If a vCPU is in the KVM_MP_STATE_SUSPENDED state, KVM will emulate the
1523 architectural execution of a WFI instruction.
1525 If a wakeup event is recognized, KVM will exit to userspace with a
1526 KVM_SYSTEM_EVENT exit, where the event type is KVM_SYSTEM_EVENT_WAKEUP. If
1527 userspace wants to honor the wakeup, it must set the vCPU's MP state to
1528 KVM_MP_STATE_RUNNABLE. If it does not, KVM will continue to await a wakeup
1529 event in subsequent calls to KVM_RUN.
1533 If userspace intends to keep the vCPU in a SUSPENDED state, it is
1534 strongly recommended that userspace take action to suppress the
1535 wakeup event (such as masking an interrupt). Otherwise, subsequent
1536 calls to KVM_RUN will immediately exit with a KVM_SYSTEM_EVENT_WAKEUP
1537 event and inadvertently waste CPU cycles.
1539 Additionally, if userspace takes action to suppress a wakeup event,
1540 it is strongly recommended that it also restores the vCPU to its
1541 original state when the vCPU is made RUNNABLE again. For example,
1542 if userspace masked a pending interrupt to suppress the wakeup,
1543 the interrupt should be unmasked before returning control to the
1549 The only states that are valid are KVM_MP_STATE_STOPPED and
1550 KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
1552 On LoongArch, only the KVM_MP_STATE_RUNNABLE state is used to reflect
1553 whether the vcpu is runnable.
1555 4.39 KVM_SET_MP_STATE
1556 ---------------------
1558 :Capability: KVM_CAP_MP_STATE
1559 :Architectures: x86, s390, arm64, riscv, loongarch
1561 :Parameters: struct kvm_mp_state (in)
1562 :Returns: 0 on success; -1 on error
1564 Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1567 On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
1568 in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1569 these architectures.
1574 The only states that are valid are KVM_MP_STATE_STOPPED and
1575 KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
1577 On LoongArch, only the KVM_MP_STATE_RUNNABLE state is used to reflect
1578 whether the vcpu is runnable.
1580 4.40 KVM_SET_IDENTITY_MAP_ADDR
1581 ------------------------------
1583 :Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1586 :Parameters: unsigned long identity (in)
1587 :Returns: 0 on success, -1 on error
1589 This ioctl defines the physical address of a one-page region in the guest
1590 physical address space. The region must be within the first 4GB of the
1591 guest physical address space and must not conflict with any memory slot
1592 or any mmio address. The guest may malfunction if it accesses this memory
1595 Setting the address to 0 will result in resetting the address to its default
1598 This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1599 because of a quirk in the virtualization implementation (see the internals
1600 documentation when it pops into existence).
1602 Fails if any VCPU has already been created.
1604 4.41 KVM_SET_BOOT_CPU_ID
1605 ------------------------
1607 :Capability: KVM_CAP_SET_BOOT_CPU_ID
1610 :Parameters: unsigned long vcpu_id
1611 :Returns: 0 on success, -1 on error
1613 Define which vcpu is the Bootstrap Processor (BSP). Values are the same
1614 as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
1615 is vcpu 0. This ioctl has to be called before vcpu creation,
1616 otherwise it will return EBUSY error.
1622 :Capability: KVM_CAP_XSAVE
1625 :Parameters: struct kvm_xsave (out)
1626 :Returns: 0 on success, -1 on error
1636 This ioctl would copy current vcpu's xsave struct to the userspace.
1642 :Capability: KVM_CAP_XSAVE and KVM_CAP_XSAVE2
1645 :Parameters: struct kvm_xsave (in)
1646 :Returns: 0 on success, -1 on error
1656 This ioctl would copy userspace's xsave struct to the kernel. It copies
1657 as many bytes as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2),
1658 when invoked on the vm file descriptor. The size value returned by
1659 KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) will always be at least 4096.
1660 Currently, it is only greater than 4096 if a dynamic feature has been
1661 enabled with ``arch_prctl()``, but this may change in the future.
1663 The offsets of the state save areas in struct kvm_xsave follow the
1664 contents of CPUID leaf 0xD on the host.
1670 :Capability: KVM_CAP_XCRS
1673 :Parameters: struct kvm_xcrs (out)
1674 :Returns: 0 on success, -1 on error
1687 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1691 This ioctl would copy current vcpu's xcrs to the userspace.
1697 :Capability: KVM_CAP_XCRS
1700 :Parameters: struct kvm_xcrs (in)
1701 :Returns: 0 on success, -1 on error
1714 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1718 This ioctl would set vcpu's xcr to the value userspace specified.
1721 4.46 KVM_GET_SUPPORTED_CPUID
1722 ----------------------------
1724 :Capability: KVM_CAP_EXT_CPUID
1727 :Parameters: struct kvm_cpuid2 (in/out)
1728 :Returns: 0 on success, -1 on error
1735 struct kvm_cpuid_entry2 entries[0];
1738 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
1739 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */
1740 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */
1742 struct kvm_cpuid_entry2 {
1753 This ioctl returns x86 cpuid features which are supported by both the
1754 hardware and kvm in its default configuration. Userspace can use the
1755 information returned by this ioctl to construct cpuid information (for
1756 KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1757 userspace capabilities, and with user requirements (for example, the
1758 user may wish to constrain cpuid to emulate older hardware, or for
1759 feature consistency across a cluster).
1761 Dynamically-enabled feature bits need to be requested with
1762 ``arch_prctl()`` before calling this ioctl. Feature bits that have not
1763 been requested are excluded from the result.
1765 Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1766 expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1767 its default configuration. If userspace enables such capabilities, it
1768 is responsible for modifying the results of this ioctl appropriately.
1770 Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1771 with the 'nent' field indicating the number of entries in the variable-size
1772 array 'entries'. If the number of entries is too low to describe the cpu
1773 capabilities, an error (E2BIG) is returned. If the number is too high,
1774 the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1775 number is just right, the 'nent' field is adjusted to the number of valid
1776 entries in the 'entries' array, which is then filled.
1778 The entries returned are the host cpuid as returned by the cpuid instruction,
1779 with unknown or unsupported features masked out. Some features (for example,
1780 x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1781 emulate them efficiently. The fields in each entry are defined as follows:
1784 the eax value used to obtain the entry
1787 the ecx value used to obtain the entry (for entries that are
1791 an OR of zero or more of the following:
1793 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1794 if the index field is valid
1797 the values returned by the cpuid instruction for
1798 this function/index combination
1800 The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1801 as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1802 support. Instead it is reported via::
1804 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1806 if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1807 feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1810 4.47 KVM_PPC_GET_PVINFO
1811 -----------------------
1813 :Capability: KVM_CAP_PPC_GET_PVINFO
1816 :Parameters: struct kvm_ppc_pvinfo (out)
1817 :Returns: 0 on success, !0 on error
1821 struct kvm_ppc_pvinfo {
1827 This ioctl fetches PV specific information that need to be passed to the guest
1828 using the device tree or other means from vm context.
1830 The hcall array defines 4 instructions that make up a hypercall.
1832 If any additional field gets added to this structure later on, a bit for that
1833 additional piece of information will be set in the flags bitmap.
1835 The flags bitmap is defined as::
1837 /* the host supports the ePAPR idle hcall
1838 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
1840 4.52 KVM_SET_GSI_ROUTING
1841 ------------------------
1843 :Capability: KVM_CAP_IRQ_ROUTING
1844 :Architectures: x86 s390 arm64
1846 :Parameters: struct kvm_irq_routing (in)
1847 :Returns: 0 on success, -1 on error
1849 Sets the GSI routing table entries, overwriting any previously set entries.
1851 On arm64, GSI routing has the following limitation:
1853 - GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1857 struct kvm_irq_routing {
1860 struct kvm_irq_routing_entry entries[0];
1863 No flags are specified so far, the corresponding field must be set to zero.
1867 struct kvm_irq_routing_entry {
1873 struct kvm_irq_routing_irqchip irqchip;
1874 struct kvm_irq_routing_msi msi;
1875 struct kvm_irq_routing_s390_adapter adapter;
1876 struct kvm_irq_routing_hv_sint hv_sint;
1877 struct kvm_irq_routing_xen_evtchn xen_evtchn;
1882 /* gsi routing entry types */
1883 #define KVM_IRQ_ROUTING_IRQCHIP 1
1884 #define KVM_IRQ_ROUTING_MSI 2
1885 #define KVM_IRQ_ROUTING_S390_ADAPTER 3
1886 #define KVM_IRQ_ROUTING_HV_SINT 4
1887 #define KVM_IRQ_ROUTING_XEN_EVTCHN 5
1891 - KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1892 type, specifies that the devid field contains a valid value. The per-VM
1893 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1894 the device ID. If this capability is not available, userspace should
1895 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
1900 struct kvm_irq_routing_irqchip {
1905 struct kvm_irq_routing_msi {
1915 If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1916 for the device that wrote the MSI message. For PCI, this is usually a
1917 BFD identifier in the lower 16 bits.
1919 On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1920 feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
1921 address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
1922 address_hi must be zero.
1926 struct kvm_irq_routing_s390_adapter {
1930 __u32 summary_offset;
1934 struct kvm_irq_routing_hv_sint {
1939 struct kvm_irq_routing_xen_evtchn {
1946 When KVM_CAP_XEN_HVM includes the KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL bit
1947 in its indication of supported features, routing to Xen event channels
1948 is supported. Although the priority field is present, only the value
1949 KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL is supported, which means delivery by
1950 2 level event channels. FIFO event channel support may be added in
1954 4.55 KVM_SET_TSC_KHZ
1955 --------------------
1957 :Capability: KVM_CAP_TSC_CONTROL / KVM_CAP_VM_TSC_CONTROL
1959 :Type: vcpu ioctl / vm ioctl
1960 :Parameters: virtual tsc_khz
1961 :Returns: 0 on success, -1 on error
1963 Specifies the tsc frequency for the virtual machine. The unit of the
1966 If the KVM_CAP_VM_TSC_CONTROL capability is advertised, this can also
1967 be used as a vm ioctl to set the initial tsc frequency of subsequently
1970 4.56 KVM_GET_TSC_KHZ
1971 --------------------
1973 :Capability: KVM_CAP_GET_TSC_KHZ / KVM_CAP_VM_TSC_CONTROL
1975 :Type: vcpu ioctl / vm ioctl
1977 :Returns: virtual tsc-khz on success, negative value on error
1979 Returns the tsc frequency of the guest. The unit of the return value is
1980 KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1987 :Capability: KVM_CAP_IRQCHIP
1990 :Parameters: struct kvm_lapic_state (out)
1991 :Returns: 0 on success, -1 on error
1995 #define KVM_APIC_REG_SIZE 0x400
1996 struct kvm_lapic_state {
1997 char regs[KVM_APIC_REG_SIZE];
2000 Reads the Local APIC registers and copies them into the input argument. The
2001 data format and layout are the same as documented in the architecture manual.
2003 If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
2004 enabled, then the format of APIC_ID register depends on the APIC mode
2005 (reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in
2006 the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID
2007 which is stored in bits 31-24 of the APIC register, or equivalently in
2008 byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then
2009 be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
2011 If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
2012 always uses xAPIC format.
2018 :Capability: KVM_CAP_IRQCHIP
2021 :Parameters: struct kvm_lapic_state (in)
2022 :Returns: 0 on success, -1 on error
2026 #define KVM_APIC_REG_SIZE 0x400
2027 struct kvm_lapic_state {
2028 char regs[KVM_APIC_REG_SIZE];
2031 Copies the input argument into the Local APIC registers. The data format
2032 and layout are the same as documented in the architecture manual.
2034 The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
2035 regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
2036 See the note in KVM_GET_LAPIC.
2042 :Capability: KVM_CAP_IOEVENTFD
2045 :Parameters: struct kvm_ioeventfd (in)
2046 :Returns: 0 on success, !0 on error
2048 This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
2049 within the guest. A guest write in the registered address will signal the
2050 provided event instead of triggering an exit.
2054 struct kvm_ioeventfd {
2056 __u64 addr; /* legal pio/mmio address */
2057 __u32 len; /* 0, 1, 2, 4, or 8 bytes */
2063 For the special case of virtio-ccw devices on s390, the ioevent is matched
2064 to a subchannel/virtqueue tuple instead.
2066 The following flags are defined::
2068 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
2069 #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
2070 #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
2071 #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
2072 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
2074 If datamatch flag is set, the event will be signaled only if the written value
2075 to the registered address is equal to datamatch in struct kvm_ioeventfd.
2077 For virtio-ccw devices, addr contains the subchannel id and datamatch the
2080 With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
2081 the kernel will ignore the length of guest write and may get a faster vmexit.
2082 The speedup may only apply to specific architectures, but the ioeventfd will
2088 :Capability: KVM_CAP_SW_TLB
2091 :Parameters: struct kvm_dirty_tlb (in)
2092 :Returns: 0 on success, -1 on error
2096 struct kvm_dirty_tlb {
2101 This must be called whenever userspace has changed an entry in the shared
2102 TLB, prior to calling KVM_RUN on the associated vcpu.
2104 The "bitmap" field is the userspace address of an array. This array
2105 consists of a number of bits, equal to the total number of TLB entries as
2106 determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
2107 nearest multiple of 64.
2109 Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
2112 The array is little-endian: the bit 0 is the least significant bit of the
2113 first byte, bit 8 is the least significant bit of the second byte, etc.
2114 This avoids any complications with differing word sizes.
2116 The "num_dirty" field is a performance hint for KVM to determine whether it
2117 should skip processing the bitmap and just invalidate everything. It must
2118 be set to the number of set bits in the bitmap.
2121 4.62 KVM_CREATE_SPAPR_TCE
2122 -------------------------
2124 :Capability: KVM_CAP_SPAPR_TCE
2125 :Architectures: powerpc
2127 :Parameters: struct kvm_create_spapr_tce (in)
2128 :Returns: file descriptor for manipulating the created TCE table
2130 This creates a virtual TCE (translation control entry) table, which
2131 is an IOMMU for PAPR-style virtual I/O. It is used to translate
2132 logical addresses used in virtual I/O into guest physical addresses,
2133 and provides a scatter/gather capability for PAPR virtual I/O.
2137 /* for KVM_CAP_SPAPR_TCE */
2138 struct kvm_create_spapr_tce {
2143 The liobn field gives the logical IO bus number for which to create a
2144 TCE table. The window_size field specifies the size of the DMA window
2145 which this TCE table will translate - the table will contain one 64
2146 bit TCE entry for every 4kiB of the DMA window.
2148 When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
2149 table has been created using this ioctl(), the kernel will handle it
2150 in real mode, updating the TCE table. H_PUT_TCE calls for other
2151 liobns will cause a vm exit and must be handled by userspace.
2153 The return value is a file descriptor which can be passed to mmap(2)
2154 to map the created TCE table into userspace. This lets userspace read
2155 the entries written by kernel-handled H_PUT_TCE calls, and also lets
2156 userspace update the TCE table directly which is useful in some
2160 4.63 KVM_ALLOCATE_RMA
2161 ---------------------
2163 :Capability: KVM_CAP_PPC_RMA
2164 :Architectures: powerpc
2166 :Parameters: struct kvm_allocate_rma (out)
2167 :Returns: file descriptor for mapping the allocated RMA
2169 This allocates a Real Mode Area (RMA) from the pool allocated at boot
2170 time by the kernel. An RMA is a physically-contiguous, aligned region
2171 of memory used on older POWER processors to provide the memory which
2172 will be accessed by real-mode (MMU off) accesses in a KVM guest.
2173 POWER processors support a set of sizes for the RMA that usually
2174 includes 64MB, 128MB, 256MB and some larger powers of two.
2178 /* for KVM_ALLOCATE_RMA */
2179 struct kvm_allocate_rma {
2183 The return value is a file descriptor which can be passed to mmap(2)
2184 to map the allocated RMA into userspace. The mapped area can then be
2185 passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
2186 RMA for a virtual machine. The size of the RMA in bytes (which is
2187 fixed at host kernel boot time) is returned in the rma_size field of
2188 the argument structure.
2190 The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
2191 is supported; 2 if the processor requires all virtual machines to have
2192 an RMA, or 1 if the processor can use an RMA but doesn't require it,
2193 because it supports the Virtual RMA (VRMA) facility.
2199 :Capability: KVM_CAP_USER_NMI
2203 :Returns: 0 on success, -1 on error
2205 Queues an NMI on the thread's vcpu. Note this is well defined only
2206 when KVM_CREATE_IRQCHIP has not been called, since this is an interface
2207 between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
2208 has been called, this interface is completely emulated within the kernel.
2210 To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
2211 following algorithm:
2214 - read the local APIC's state (KVM_GET_LAPIC)
2215 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
2216 - if so, issue KVM_NMI
2219 Some guests configure the LINT1 NMI input to cause a panic, aiding in
2223 4.65 KVM_S390_UCAS_MAP
2224 ----------------------
2226 :Capability: KVM_CAP_S390_UCONTROL
2227 :Architectures: s390
2229 :Parameters: struct kvm_s390_ucas_mapping (in)
2230 :Returns: 0 in case of success
2232 The parameter is defined like this::
2234 struct kvm_s390_ucas_mapping {
2240 This ioctl maps the memory at "user_addr" with the length "length" to
2241 the vcpu's address space starting at "vcpu_addr". All parameters need to
2242 be aligned by 1 megabyte.
2245 4.66 KVM_S390_UCAS_UNMAP
2246 ------------------------
2248 :Capability: KVM_CAP_S390_UCONTROL
2249 :Architectures: s390
2251 :Parameters: struct kvm_s390_ucas_mapping (in)
2252 :Returns: 0 in case of success
2254 The parameter is defined like this::
2256 struct kvm_s390_ucas_mapping {
2262 This ioctl unmaps the memory in the vcpu's address space starting at
2263 "vcpu_addr" with the length "length". The field "user_addr" is ignored.
2264 All parameters need to be aligned by 1 megabyte.
2267 4.67 KVM_S390_VCPU_FAULT
2268 ------------------------
2270 :Capability: KVM_CAP_S390_UCONTROL
2271 :Architectures: s390
2273 :Parameters: vcpu absolute address (in)
2274 :Returns: 0 in case of success
2276 This call creates a page table entry on the virtual cpu's address space
2277 (for user controlled virtual machines) or the virtual machine's address
2278 space (for regular virtual machines). This only works for minor faults,
2279 thus it's recommended to access subject memory page via the user page
2280 table upfront. This is useful to handle validity intercepts for user
2281 controlled virtual machines to fault in the virtual cpu's lowcore pages
2282 prior to calling the KVM_RUN ioctl.
2285 4.68 KVM_SET_ONE_REG
2286 --------------------
2288 :Capability: KVM_CAP_ONE_REG
2291 :Parameters: struct kvm_one_reg (in)
2292 :Returns: 0 on success, negative value on failure
2296 ====== ============================================================
2297 ENOENT no such register
2298 EINVAL invalid register ID, or no such register or used with VMs in
2299 protected virtualization mode on s390
2300 EPERM (arm64) register access not allowed before vcpu finalization
2301 EBUSY (riscv) changing register value not allowed after the vcpu
2302 has run at least once
2303 ====== ============================================================
2305 (These error codes are indicative only: do not rely on a specific error
2306 code being returned in a specific situation.)
2310 struct kvm_one_reg {
2315 Using this ioctl, a single vcpu register can be set to a specific value
2316 defined by user space with the passed in struct kvm_one_reg, where id
2317 refers to the register identifier as described below and addr is a pointer
2318 to a variable with the respective size. There can be architecture agnostic
2319 and architecture specific registers. Each have their own range of operation
2320 and their own constants and width. To keep track of the implemented
2321 registers, find a list below:
2323 ======= =============================== ============
2324 Arch Register Width (bits)
2325 ======= =============================== ============
2326 PPC KVM_REG_PPC_HIOR 64
2327 PPC KVM_REG_PPC_IAC1 64
2328 PPC KVM_REG_PPC_IAC2 64
2329 PPC KVM_REG_PPC_IAC3 64
2330 PPC KVM_REG_PPC_IAC4 64
2331 PPC KVM_REG_PPC_DAC1 64
2332 PPC KVM_REG_PPC_DAC2 64
2333 PPC KVM_REG_PPC_DABR 64
2334 PPC KVM_REG_PPC_DSCR 64
2335 PPC KVM_REG_PPC_PURR 64
2336 PPC KVM_REG_PPC_SPURR 64
2337 PPC KVM_REG_PPC_DAR 64
2338 PPC KVM_REG_PPC_DSISR 32
2339 PPC KVM_REG_PPC_AMR 64
2340 PPC KVM_REG_PPC_UAMOR 64
2341 PPC KVM_REG_PPC_MMCR0 64
2342 PPC KVM_REG_PPC_MMCR1 64
2343 PPC KVM_REG_PPC_MMCRA 64
2344 PPC KVM_REG_PPC_MMCR2 64
2345 PPC KVM_REG_PPC_MMCRS 64
2346 PPC KVM_REG_PPC_MMCR3 64
2347 PPC KVM_REG_PPC_SIAR 64
2348 PPC KVM_REG_PPC_SDAR 64
2349 PPC KVM_REG_PPC_SIER 64
2350 PPC KVM_REG_PPC_SIER2 64
2351 PPC KVM_REG_PPC_SIER3 64
2352 PPC KVM_REG_PPC_PMC1 32
2353 PPC KVM_REG_PPC_PMC2 32
2354 PPC KVM_REG_PPC_PMC3 32
2355 PPC KVM_REG_PPC_PMC4 32
2356 PPC KVM_REG_PPC_PMC5 32
2357 PPC KVM_REG_PPC_PMC6 32
2358 PPC KVM_REG_PPC_PMC7 32
2359 PPC KVM_REG_PPC_PMC8 32
2360 PPC KVM_REG_PPC_FPR0 64
2362 PPC KVM_REG_PPC_FPR31 64
2363 PPC KVM_REG_PPC_VR0 128
2365 PPC KVM_REG_PPC_VR31 128
2366 PPC KVM_REG_PPC_VSR0 128
2368 PPC KVM_REG_PPC_VSR31 128
2369 PPC KVM_REG_PPC_FPSCR 64
2370 PPC KVM_REG_PPC_VSCR 32
2371 PPC KVM_REG_PPC_VPA_ADDR 64
2372 PPC KVM_REG_PPC_VPA_SLB 128
2373 PPC KVM_REG_PPC_VPA_DTL 128
2374 PPC KVM_REG_PPC_EPCR 32
2375 PPC KVM_REG_PPC_EPR 32
2376 PPC KVM_REG_PPC_TCR 32
2377 PPC KVM_REG_PPC_TSR 32
2378 PPC KVM_REG_PPC_OR_TSR 32
2379 PPC KVM_REG_PPC_CLEAR_TSR 32
2380 PPC KVM_REG_PPC_MAS0 32
2381 PPC KVM_REG_PPC_MAS1 32
2382 PPC KVM_REG_PPC_MAS2 64
2383 PPC KVM_REG_PPC_MAS7_3 64
2384 PPC KVM_REG_PPC_MAS4 32
2385 PPC KVM_REG_PPC_MAS6 32
2386 PPC KVM_REG_PPC_MMUCFG 32
2387 PPC KVM_REG_PPC_TLB0CFG 32
2388 PPC KVM_REG_PPC_TLB1CFG 32
2389 PPC KVM_REG_PPC_TLB2CFG 32
2390 PPC KVM_REG_PPC_TLB3CFG 32
2391 PPC KVM_REG_PPC_TLB0PS 32
2392 PPC KVM_REG_PPC_TLB1PS 32
2393 PPC KVM_REG_PPC_TLB2PS 32
2394 PPC KVM_REG_PPC_TLB3PS 32
2395 PPC KVM_REG_PPC_EPTCFG 32
2396 PPC KVM_REG_PPC_ICP_STATE 64
2397 PPC KVM_REG_PPC_VP_STATE 128
2398 PPC KVM_REG_PPC_TB_OFFSET 64
2399 PPC KVM_REG_PPC_SPMC1 32
2400 PPC KVM_REG_PPC_SPMC2 32
2401 PPC KVM_REG_PPC_IAMR 64
2402 PPC KVM_REG_PPC_TFHAR 64
2403 PPC KVM_REG_PPC_TFIAR 64
2404 PPC KVM_REG_PPC_TEXASR 64
2405 PPC KVM_REG_PPC_FSCR 64
2406 PPC KVM_REG_PPC_PSPB 32
2407 PPC KVM_REG_PPC_EBBHR 64
2408 PPC KVM_REG_PPC_EBBRR 64
2409 PPC KVM_REG_PPC_BESCR 64
2410 PPC KVM_REG_PPC_TAR 64
2411 PPC KVM_REG_PPC_DPDES 64
2412 PPC KVM_REG_PPC_DAWR 64
2413 PPC KVM_REG_PPC_DAWRX 64
2414 PPC KVM_REG_PPC_CIABR 64
2415 PPC KVM_REG_PPC_IC 64
2416 PPC KVM_REG_PPC_VTB 64
2417 PPC KVM_REG_PPC_CSIGR 64
2418 PPC KVM_REG_PPC_TACR 64
2419 PPC KVM_REG_PPC_TCSCR 64
2420 PPC KVM_REG_PPC_PID 64
2421 PPC KVM_REG_PPC_ACOP 64
2422 PPC KVM_REG_PPC_VRSAVE 32
2423 PPC KVM_REG_PPC_LPCR 32
2424 PPC KVM_REG_PPC_LPCR_64 64
2425 PPC KVM_REG_PPC_PPR 64
2426 PPC KVM_REG_PPC_ARCH_COMPAT 32
2427 PPC KVM_REG_PPC_DABRX 32
2428 PPC KVM_REG_PPC_WORT 64
2429 PPC KVM_REG_PPC_SPRG9 64
2430 PPC KVM_REG_PPC_DBSR 32
2431 PPC KVM_REG_PPC_TIDR 64
2432 PPC KVM_REG_PPC_PSSCR 64
2433 PPC KVM_REG_PPC_DEC_EXPIRY 64
2434 PPC KVM_REG_PPC_PTCR 64
2435 PPC KVM_REG_PPC_DAWR1 64
2436 PPC KVM_REG_PPC_DAWRX1 64
2437 PPC KVM_REG_PPC_TM_GPR0 64
2439 PPC KVM_REG_PPC_TM_GPR31 64
2440 PPC KVM_REG_PPC_TM_VSR0 128
2442 PPC KVM_REG_PPC_TM_VSR63 128
2443 PPC KVM_REG_PPC_TM_CR 64
2444 PPC KVM_REG_PPC_TM_LR 64
2445 PPC KVM_REG_PPC_TM_CTR 64
2446 PPC KVM_REG_PPC_TM_FPSCR 64
2447 PPC KVM_REG_PPC_TM_AMR 64
2448 PPC KVM_REG_PPC_TM_PPR 64
2449 PPC KVM_REG_PPC_TM_VRSAVE 64
2450 PPC KVM_REG_PPC_TM_VSCR 32
2451 PPC KVM_REG_PPC_TM_DSCR 64
2452 PPC KVM_REG_PPC_TM_TAR 64
2453 PPC KVM_REG_PPC_TM_XER 64
2455 MIPS KVM_REG_MIPS_R0 64
2457 MIPS KVM_REG_MIPS_R31 64
2458 MIPS KVM_REG_MIPS_HI 64
2459 MIPS KVM_REG_MIPS_LO 64
2460 MIPS KVM_REG_MIPS_PC 64
2461 MIPS KVM_REG_MIPS_CP0_INDEX 32
2462 MIPS KVM_REG_MIPS_CP0_ENTRYLO0 64
2463 MIPS KVM_REG_MIPS_CP0_ENTRYLO1 64
2464 MIPS KVM_REG_MIPS_CP0_CONTEXT 64
2465 MIPS KVM_REG_MIPS_CP0_CONTEXTCONFIG 32
2466 MIPS KVM_REG_MIPS_CP0_USERLOCAL 64
2467 MIPS KVM_REG_MIPS_CP0_XCONTEXTCONFIG 64
2468 MIPS KVM_REG_MIPS_CP0_PAGEMASK 32
2469 MIPS KVM_REG_MIPS_CP0_PAGEGRAIN 32
2470 MIPS KVM_REG_MIPS_CP0_SEGCTL0 64
2471 MIPS KVM_REG_MIPS_CP0_SEGCTL1 64
2472 MIPS KVM_REG_MIPS_CP0_SEGCTL2 64
2473 MIPS KVM_REG_MIPS_CP0_PWBASE 64
2474 MIPS KVM_REG_MIPS_CP0_PWFIELD 64
2475 MIPS KVM_REG_MIPS_CP0_PWSIZE 64
2476 MIPS KVM_REG_MIPS_CP0_WIRED 32
2477 MIPS KVM_REG_MIPS_CP0_PWCTL 32
2478 MIPS KVM_REG_MIPS_CP0_HWRENA 32
2479 MIPS KVM_REG_MIPS_CP0_BADVADDR 64
2480 MIPS KVM_REG_MIPS_CP0_BADINSTR 32
2481 MIPS KVM_REG_MIPS_CP0_BADINSTRP 32
2482 MIPS KVM_REG_MIPS_CP0_COUNT 32
2483 MIPS KVM_REG_MIPS_CP0_ENTRYHI 64
2484 MIPS KVM_REG_MIPS_CP0_COMPARE 32
2485 MIPS KVM_REG_MIPS_CP0_STATUS 32
2486 MIPS KVM_REG_MIPS_CP0_INTCTL 32
2487 MIPS KVM_REG_MIPS_CP0_CAUSE 32
2488 MIPS KVM_REG_MIPS_CP0_EPC 64
2489 MIPS KVM_REG_MIPS_CP0_PRID 32
2490 MIPS KVM_REG_MIPS_CP0_EBASE 64
2491 MIPS KVM_REG_MIPS_CP0_CONFIG 32
2492 MIPS KVM_REG_MIPS_CP0_CONFIG1 32
2493 MIPS KVM_REG_MIPS_CP0_CONFIG2 32
2494 MIPS KVM_REG_MIPS_CP0_CONFIG3 32
2495 MIPS KVM_REG_MIPS_CP0_CONFIG4 32
2496 MIPS KVM_REG_MIPS_CP0_CONFIG5 32
2497 MIPS KVM_REG_MIPS_CP0_CONFIG7 32
2498 MIPS KVM_REG_MIPS_CP0_XCONTEXT 64
2499 MIPS KVM_REG_MIPS_CP0_ERROREPC 64
2500 MIPS KVM_REG_MIPS_CP0_KSCRATCH1 64
2501 MIPS KVM_REG_MIPS_CP0_KSCRATCH2 64
2502 MIPS KVM_REG_MIPS_CP0_KSCRATCH3 64
2503 MIPS KVM_REG_MIPS_CP0_KSCRATCH4 64
2504 MIPS KVM_REG_MIPS_CP0_KSCRATCH5 64
2505 MIPS KVM_REG_MIPS_CP0_KSCRATCH6 64
2506 MIPS KVM_REG_MIPS_CP0_MAAR(0..63) 64
2507 MIPS KVM_REG_MIPS_COUNT_CTL 64
2508 MIPS KVM_REG_MIPS_COUNT_RESUME 64
2509 MIPS KVM_REG_MIPS_COUNT_HZ 64
2510 MIPS KVM_REG_MIPS_FPR_32(0..31) 32
2511 MIPS KVM_REG_MIPS_FPR_64(0..31) 64
2512 MIPS KVM_REG_MIPS_VEC_128(0..31) 128
2513 MIPS KVM_REG_MIPS_FCR_IR 32
2514 MIPS KVM_REG_MIPS_FCR_CSR 32
2515 MIPS KVM_REG_MIPS_MSA_IR 32
2516 MIPS KVM_REG_MIPS_MSA_CSR 32
2517 ======= =============================== ============
2519 ARM registers are mapped using the lower 32 bits. The upper 16 of that
2520 is the register group type, or coprocessor number:
2522 ARM core registers have the following id bit patterns::
2524 0x4020 0000 0010 <index into the kvm_regs struct:16>
2526 ARM 32-bit CP15 registers have the following id bit patterns::
2528 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
2530 ARM 64-bit CP15 registers have the following id bit patterns::
2532 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
2534 ARM CCSIDR registers are demultiplexed by CSSELR value::
2536 0x4020 0000 0011 00 <csselr:8>
2538 ARM 32-bit VFP control registers have the following id bit patterns::
2540 0x4020 0000 0012 1 <regno:12>
2542 ARM 64-bit FP registers have the following id bit patterns::
2544 0x4030 0000 0012 0 <regno:12>
2546 ARM firmware pseudo-registers have the following bit pattern::
2548 0x4030 0000 0014 <regno:16>
2551 arm64 registers are mapped using the lower 32 bits. The upper 16 of
2552 that is the register group type, or coprocessor number:
2554 arm64 core/FP-SIMD registers have the following id bit patterns. Note
2555 that the size of the access is variable, as the kvm_regs structure
2556 contains elements ranging from 32 to 128 bits. The index is a 32bit
2557 value in the kvm_regs structure seen as a 32bit array::
2559 0x60x0 0000 0010 <index into the kvm_regs struct:16>
2563 ======================= ========= ===== =======================================
2564 Encoding Register Bits kvm_regs member
2565 ======================= ========= ===== =======================================
2566 0x6030 0000 0010 0000 X0 64 regs.regs[0]
2567 0x6030 0000 0010 0002 X1 64 regs.regs[1]
2569 0x6030 0000 0010 003c X30 64 regs.regs[30]
2570 0x6030 0000 0010 003e SP 64 regs.sp
2571 0x6030 0000 0010 0040 PC 64 regs.pc
2572 0x6030 0000 0010 0042 PSTATE 64 regs.pstate
2573 0x6030 0000 0010 0044 SP_EL1 64 sp_el1
2574 0x6030 0000 0010 0046 ELR_EL1 64 elr_el1
2575 0x6030 0000 0010 0048 SPSR_EL1 64 spsr[KVM_SPSR_EL1] (alias SPSR_SVC)
2576 0x6030 0000 0010 004a SPSR_ABT 64 spsr[KVM_SPSR_ABT]
2577 0x6030 0000 0010 004c SPSR_UND 64 spsr[KVM_SPSR_UND]
2578 0x6030 0000 0010 004e SPSR_IRQ 64 spsr[KVM_SPSR_IRQ]
2579 0x6060 0000 0010 0050 SPSR_FIQ 64 spsr[KVM_SPSR_FIQ]
2580 0x6040 0000 0010 0054 V0 128 fp_regs.vregs[0] [1]_
2581 0x6040 0000 0010 0058 V1 128 fp_regs.vregs[1] [1]_
2583 0x6040 0000 0010 00d0 V31 128 fp_regs.vregs[31] [1]_
2584 0x6020 0000 0010 00d4 FPSR 32 fp_regs.fpsr
2585 0x6020 0000 0010 00d5 FPCR 32 fp_regs.fpcr
2586 ======================= ========= ===== =======================================
2588 .. [1] These encodings are not accepted for SVE-enabled vcpus. See
2591 The equivalent register content can be accessed via bits [127:0] of
2592 the corresponding SVE Zn registers instead for vcpus that have SVE
2593 enabled (see below).
2595 arm64 CCSIDR registers are demultiplexed by CSSELR value::
2597 0x6020 0000 0011 00 <csselr:8>
2599 arm64 system registers have the following id bit patterns::
2601 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2605 Two system register IDs do not follow the specified pattern. These
2606 are KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT, which map to
2607 system registers CNTV_CVAL_EL0 and CNTVCT_EL0 respectively. These
2608 two had their values accidentally swapped, which means TIMER_CVAL is
2609 derived from the register encoding for CNTVCT_EL0 and TIMER_CNT is
2610 derived from the register encoding for CNTV_CVAL_EL0. As this is
2611 API, it must remain this way.
2613 arm64 firmware pseudo-registers have the following bit pattern::
2615 0x6030 0000 0014 <regno:16>
2617 arm64 SVE registers have the following bit patterns::
2619 0x6080 0000 0015 00 <n:5> <slice:5> Zn bits[2048*slice + 2047 : 2048*slice]
2620 0x6050 0000 0015 04 <n:4> <slice:5> Pn bits[256*slice + 255 : 256*slice]
2621 0x6050 0000 0015 060 <slice:5> FFR bits[256*slice + 255 : 256*slice]
2622 0x6060 0000 0015 ffff KVM_REG_ARM64_SVE_VLS pseudo-register
2624 Access to register IDs where 2048 * slice >= 128 * max_vq will fail with
2625 ENOENT. max_vq is the vcpu's maximum supported vector length in 128-bit
2626 quadwords: see [2]_ below.
2628 These registers are only accessible on vcpus for which SVE is enabled.
2629 See KVM_ARM_VCPU_INIT for details.
2631 In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not
2632 accessible until the vcpu's SVE configuration has been finalized
2633 using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). See KVM_ARM_VCPU_INIT
2634 and KVM_ARM_VCPU_FINALIZE for more information about this procedure.
2636 KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector
2637 lengths supported by the vcpu to be discovered and configured by
2638 userspace. When transferred to or from user memory via KVM_GET_ONE_REG
2639 or KVM_SET_ONE_REG, the value of this register is of type
2640 __u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as
2643 __u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS];
2645 if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX &&
2646 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >>
2647 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1))
2648 /* Vector length vq * 16 bytes supported */
2650 /* Vector length vq * 16 bytes not supported */
2652 .. [2] The maximum value vq for which the above condition is true is
2653 max_vq. This is the maximum vector length available to the guest on
2654 this vcpu, and determines which register slices are visible through
2655 this ioctl interface.
2657 (See Documentation/arch/arm64/sve.rst for an explanation of the "vq"
2660 KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT.
2661 KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that
2664 Userspace may subsequently modify it if desired until the vcpu's SVE
2665 configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE).
2667 Apart from simply removing all vector lengths from the host set that
2668 exceed some value, support for arbitrarily chosen sets of vector lengths
2669 is hardware-dependent and may not be available. Attempting to configure
2670 an invalid set of vector lengths via KVM_SET_ONE_REG will fail with
2673 After the vcpu's SVE configuration is finalized, further attempts to
2674 write this register will fail with EPERM.
2676 arm64 bitmap feature firmware pseudo-registers have the following bit pattern::
2678 0x6030 0000 0016 <regno:16>
2680 The bitmap feature firmware registers exposes the hypercall services that
2681 are available for userspace to configure. The set bits corresponds to the
2682 services that are available for the guests to access. By default, KVM
2683 sets all the supported bits during VM initialization. The userspace can
2684 discover the available services via KVM_GET_ONE_REG, and write back the
2685 bitmap corresponding to the features that it wishes guests to see via
2688 Note: These registers are immutable once any of the vCPUs of the VM has
2689 run at least once. A KVM_SET_ONE_REG in such a scenario will return
2690 a -EBUSY to userspace.
2692 (See Documentation/virt/kvm/arm/hypercalls.rst for more details.)
2695 MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
2696 the register group type:
2698 MIPS core registers (see above) have the following id bit patterns::
2700 0x7030 0000 0000 <reg:16>
2702 MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
2703 patterns depending on whether they're 32-bit or 64-bit registers::
2705 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
2706 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2708 Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2709 versions of the EntryLo registers regardless of the word size of the host
2710 hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2711 with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2712 the PFNX field starting at bit 30.
2714 MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
2717 0x7030 0000 0001 01 <reg:8>
2719 MIPS KVM control registers (see above) have the following id bit patterns::
2721 0x7030 0000 0002 <reg:16>
2723 MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2724 id bit patterns depending on the size of the register being accessed. They are
2725 always accessed according to the current guest FPU mode (Status.FR and
2726 Config5.FRE), i.e. as the guest would see them, and they become unpredictable
2727 if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2728 registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
2729 overlap the FPU registers::
2731 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2732 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
2733 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
2735 MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
2736 following id bit patterns::
2738 0x7020 0000 0003 01 <0:3> <reg:5>
2740 MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
2741 following id bit patterns::
2743 0x7020 0000 0003 02 <0:3> <reg:5>
2745 RISC-V registers are mapped using the lower 32 bits. The upper 8 bits of
2746 that is the register group type.
2748 RISC-V config registers are meant for configuring a Guest VCPU and it has
2749 the following id bit patterns::
2751 0x8020 0000 01 <index into the kvm_riscv_config struct:24> (32bit Host)
2752 0x8030 0000 01 <index into the kvm_riscv_config struct:24> (64bit Host)
2754 Following are the RISC-V config registers:
2756 ======================= ========= =============================================
2757 Encoding Register Description
2758 ======================= ========= =============================================
2759 0x80x0 0000 0100 0000 isa ISA feature bitmap of Guest VCPU
2760 ======================= ========= =============================================
2762 The isa config register can be read anytime but can only be written before
2763 a Guest VCPU runs. It will have ISA feature bits matching underlying host
2766 RISC-V core registers represent the general execution state of a Guest VCPU
2767 and it has the following id bit patterns::
2769 0x8020 0000 02 <index into the kvm_riscv_core struct:24> (32bit Host)
2770 0x8030 0000 02 <index into the kvm_riscv_core struct:24> (64bit Host)
2772 Following are the RISC-V core registers:
2774 ======================= ========= =============================================
2775 Encoding Register Description
2776 ======================= ========= =============================================
2777 0x80x0 0000 0200 0000 regs.pc Program counter
2778 0x80x0 0000 0200 0001 regs.ra Return address
2779 0x80x0 0000 0200 0002 regs.sp Stack pointer
2780 0x80x0 0000 0200 0003 regs.gp Global pointer
2781 0x80x0 0000 0200 0004 regs.tp Task pointer
2782 0x80x0 0000 0200 0005 regs.t0 Caller saved register 0
2783 0x80x0 0000 0200 0006 regs.t1 Caller saved register 1
2784 0x80x0 0000 0200 0007 regs.t2 Caller saved register 2
2785 0x80x0 0000 0200 0008 regs.s0 Callee saved register 0
2786 0x80x0 0000 0200 0009 regs.s1 Callee saved register 1
2787 0x80x0 0000 0200 000a regs.a0 Function argument (or return value) 0
2788 0x80x0 0000 0200 000b regs.a1 Function argument (or return value) 1
2789 0x80x0 0000 0200 000c regs.a2 Function argument 2
2790 0x80x0 0000 0200 000d regs.a3 Function argument 3
2791 0x80x0 0000 0200 000e regs.a4 Function argument 4
2792 0x80x0 0000 0200 000f regs.a5 Function argument 5
2793 0x80x0 0000 0200 0010 regs.a6 Function argument 6
2794 0x80x0 0000 0200 0011 regs.a7 Function argument 7
2795 0x80x0 0000 0200 0012 regs.s2 Callee saved register 2
2796 0x80x0 0000 0200 0013 regs.s3 Callee saved register 3
2797 0x80x0 0000 0200 0014 regs.s4 Callee saved register 4
2798 0x80x0 0000 0200 0015 regs.s5 Callee saved register 5
2799 0x80x0 0000 0200 0016 regs.s6 Callee saved register 6
2800 0x80x0 0000 0200 0017 regs.s7 Callee saved register 7
2801 0x80x0 0000 0200 0018 regs.s8 Callee saved register 8
2802 0x80x0 0000 0200 0019 regs.s9 Callee saved register 9
2803 0x80x0 0000 0200 001a regs.s10 Callee saved register 10
2804 0x80x0 0000 0200 001b regs.s11 Callee saved register 11
2805 0x80x0 0000 0200 001c regs.t3 Caller saved register 3
2806 0x80x0 0000 0200 001d regs.t4 Caller saved register 4
2807 0x80x0 0000 0200 001e regs.t5 Caller saved register 5
2808 0x80x0 0000 0200 001f regs.t6 Caller saved register 6
2809 0x80x0 0000 0200 0020 mode Privilege mode (1 = S-mode or 0 = U-mode)
2810 ======================= ========= =============================================
2812 RISC-V csr registers represent the supervisor mode control/status registers
2813 of a Guest VCPU and it has the following id bit patterns::
2815 0x8020 0000 03 <index into the kvm_riscv_csr struct:24> (32bit Host)
2816 0x8030 0000 03 <index into the kvm_riscv_csr struct:24> (64bit Host)
2818 Following are the RISC-V csr registers:
2820 ======================= ========= =============================================
2821 Encoding Register Description
2822 ======================= ========= =============================================
2823 0x80x0 0000 0300 0000 sstatus Supervisor status
2824 0x80x0 0000 0300 0001 sie Supervisor interrupt enable
2825 0x80x0 0000 0300 0002 stvec Supervisor trap vector base
2826 0x80x0 0000 0300 0003 sscratch Supervisor scratch register
2827 0x80x0 0000 0300 0004 sepc Supervisor exception program counter
2828 0x80x0 0000 0300 0005 scause Supervisor trap cause
2829 0x80x0 0000 0300 0006 stval Supervisor bad address or instruction
2830 0x80x0 0000 0300 0007 sip Supervisor interrupt pending
2831 0x80x0 0000 0300 0008 satp Supervisor address translation and protection
2832 ======================= ========= =============================================
2834 RISC-V timer registers represent the timer state of a Guest VCPU and it has
2835 the following id bit patterns::
2837 0x8030 0000 04 <index into the kvm_riscv_timer struct:24>
2839 Following are the RISC-V timer registers:
2841 ======================= ========= =============================================
2842 Encoding Register Description
2843 ======================= ========= =============================================
2844 0x8030 0000 0400 0000 frequency Time base frequency (read-only)
2845 0x8030 0000 0400 0001 time Time value visible to Guest
2846 0x8030 0000 0400 0002 compare Time compare programmed by Guest
2847 0x8030 0000 0400 0003 state Time compare state (1 = ON or 0 = OFF)
2848 ======================= ========= =============================================
2850 RISC-V F-extension registers represent the single precision floating point
2851 state of a Guest VCPU and it has the following id bit patterns::
2853 0x8020 0000 05 <index into the __riscv_f_ext_state struct:24>
2855 Following are the RISC-V F-extension registers:
2857 ======================= ========= =============================================
2858 Encoding Register Description
2859 ======================= ========= =============================================
2860 0x8020 0000 0500 0000 f[0] Floating point register 0
2862 0x8020 0000 0500 001f f[31] Floating point register 31
2863 0x8020 0000 0500 0020 fcsr Floating point control and status register
2864 ======================= ========= =============================================
2866 RISC-V D-extension registers represent the double precision floating point
2867 state of a Guest VCPU and it has the following id bit patterns::
2869 0x8020 0000 06 <index into the __riscv_d_ext_state struct:24> (fcsr)
2870 0x8030 0000 06 <index into the __riscv_d_ext_state struct:24> (non-fcsr)
2872 Following are the RISC-V D-extension registers:
2874 ======================= ========= =============================================
2875 Encoding Register Description
2876 ======================= ========= =============================================
2877 0x8030 0000 0600 0000 f[0] Floating point register 0
2879 0x8030 0000 0600 001f f[31] Floating point register 31
2880 0x8020 0000 0600 0020 fcsr Floating point control and status register
2881 ======================= ========= =============================================
2883 LoongArch registers are mapped using the lower 32 bits. The upper 16 bits of
2884 that is the register group type.
2886 LoongArch csr registers are used to control guest cpu or get status of guest
2887 cpu, and they have the following id bit patterns::
2889 0x9030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2891 LoongArch KVM control registers are used to implement some new defined functions
2892 such as set vcpu counter or reset vcpu, and they have the following id bit patterns::
2894 0x9030 0000 0002 <reg:16>
2897 4.69 KVM_GET_ONE_REG
2898 --------------------
2900 :Capability: KVM_CAP_ONE_REG
2903 :Parameters: struct kvm_one_reg (in and out)
2904 :Returns: 0 on success, negative value on failure
2908 ======== ============================================================
2909 ENOENT no such register
2910 EINVAL invalid register ID, or no such register or used with VMs in
2911 protected virtualization mode on s390
2912 EPERM (arm64) register access not allowed before vcpu finalization
2913 ======== ============================================================
2915 (These error codes are indicative only: do not rely on a specific error
2916 code being returned in a specific situation.)
2918 This ioctl allows to receive the value of a single register implemented
2919 in a vcpu. The register to read is indicated by the "id" field of the
2920 kvm_one_reg struct passed in. On success, the register value can be found
2921 at the memory location pointed to by "addr".
2923 The list of registers accessible using this interface is identical to the
2927 4.70 KVM_KVMCLOCK_CTRL
2928 ----------------------
2930 :Capability: KVM_CAP_KVMCLOCK_CTRL
2931 :Architectures: Any that implement pvclocks (currently x86 only)
2934 :Returns: 0 on success, -1 on error
2936 This ioctl sets a flag accessible to the guest indicating that the specified
2937 vCPU has been paused by the host userspace.
2939 The host will set a flag in the pvclock structure that is checked from the
2940 soft lockup watchdog. The flag is part of the pvclock structure that is
2941 shared between guest and host, specifically the second bit of the flags
2942 field of the pvclock_vcpu_time_info structure. It will be set exclusively by
2943 the host and read/cleared exclusively by the guest. The guest operation of
2944 checking and clearing the flag must be an atomic operation so
2945 load-link/store-conditional, or equivalent must be used. There are two cases
2946 where the guest will clear the flag: when the soft lockup watchdog timer resets
2947 itself or when a soft lockup is detected. This ioctl can be called any time
2948 after pausing the vcpu, but before it is resumed.
2954 :Capability: KVM_CAP_SIGNAL_MSI
2955 :Architectures: x86 arm64
2957 :Parameters: struct kvm_msi (in)
2958 :Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
2960 Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2975 KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM
2976 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2977 the device ID. If this capability is not available, userspace
2978 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
2980 If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2981 for the device that wrote the MSI message. For PCI, this is usually a
2982 BFD identifier in the lower 16 bits.
2984 On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2985 feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
2986 address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
2987 address_hi must be zero.
2990 4.71 KVM_CREATE_PIT2
2991 --------------------
2993 :Capability: KVM_CAP_PIT2
2996 :Parameters: struct kvm_pit_config (in)
2997 :Returns: 0 on success, -1 on error
2999 Creates an in-kernel device model for the i8254 PIT. This call is only valid
3000 after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
3001 parameters have to be passed::
3003 struct kvm_pit_config {
3010 #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
3012 PIT timer interrupts may use a per-VM kernel thread for injection. If it
3013 exists, this thread will have a name of the following pattern::
3015 kvm-pit/<owner-process-pid>
3017 When running a guest with elevated priorities, the scheduling parameters of
3018 this thread may have to be adjusted accordingly.
3020 This IOCTL replaces the obsolete KVM_CREATE_PIT.
3026 :Capability: KVM_CAP_PIT_STATE2
3029 :Parameters: struct kvm_pit_state2 (out)
3030 :Returns: 0 on success, -1 on error
3032 Retrieves the state of the in-kernel PIT model. Only valid after
3033 KVM_CREATE_PIT2. The state is returned in the following structure::
3035 struct kvm_pit_state2 {
3036 struct kvm_pit_channel_state channels[3];
3043 /* disable PIT in HPET legacy mode */
3044 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
3045 /* speaker port data bit enabled */
3046 #define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
3048 This IOCTL replaces the obsolete KVM_GET_PIT.
3054 :Capability: KVM_CAP_PIT_STATE2
3057 :Parameters: struct kvm_pit_state2 (in)
3058 :Returns: 0 on success, -1 on error
3060 Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
3061 See KVM_GET_PIT2 for details on struct kvm_pit_state2.
3063 This IOCTL replaces the obsolete KVM_SET_PIT.
3066 4.74 KVM_PPC_GET_SMMU_INFO
3067 --------------------------
3069 :Capability: KVM_CAP_PPC_GET_SMMU_INFO
3070 :Architectures: powerpc
3073 :Returns: 0 on success, -1 on error
3075 This populates and returns a structure describing the features of
3076 the "Server" class MMU emulation supported by KVM.
3077 This can in turn be used by userspace to generate the appropriate
3078 device-tree properties for the guest operating system.
3080 The structure contains some global information, followed by an
3081 array of supported segment page sizes::
3083 struct kvm_ppc_smmu_info {
3087 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
3090 The supported flags are:
3092 - KVM_PPC_PAGE_SIZES_REAL:
3093 When that flag is set, guest page sizes must "fit" the backing
3094 store page sizes. When not set, any page size in the list can
3095 be used regardless of how they are backed by userspace.
3097 - KVM_PPC_1T_SEGMENTS
3098 The emulated MMU supports 1T segments in addition to the
3102 This flag indicates that HPT guests are not supported by KVM,
3103 thus all guests must use radix MMU mode.
3105 The "slb_size" field indicates how many SLB entries are supported
3107 The "sps" array contains 8 entries indicating the supported base
3108 page sizes for a segment in increasing order. Each entry is defined
3111 struct kvm_ppc_one_seg_page_size {
3112 __u32 page_shift; /* Base page shift of segment (or 0) */
3113 __u32 slb_enc; /* SLB encoding for BookS */
3114 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
3117 An entry with a "page_shift" of 0 is unused. Because the array is
3118 organized in increasing order, a lookup can stop when encountering
3121 The "slb_enc" field provides the encoding to use in the SLB for the
3122 page size. The bits are in positions such as the value can directly
3123 be OR'ed into the "vsid" argument of the slbmte instruction.
3125 The "enc" array is a list which for each of those segment base page
3126 size provides the list of supported actual page sizes (which can be
3127 only larger or equal to the base page size), along with the
3128 corresponding encoding in the hash PTE. Similarly, the array is
3129 8 entries sorted by increasing sizes and an entry with a "0" shift
3130 is an empty entry and a terminator::
3132 struct kvm_ppc_one_page_size {
3133 __u32 page_shift; /* Page shift (or 0) */
3134 __u32 pte_enc; /* Encoding in the HPTE (>>12) */
3137 The "pte_enc" field provides a value that can OR'ed into the hash
3138 PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
3139 into the hash PTE second double word).
3144 :Capability: KVM_CAP_IRQFD
3145 :Architectures: x86 s390 arm64
3147 :Parameters: struct kvm_irqfd (in)
3148 :Returns: 0 on success, -1 on error
3150 Allows setting an eventfd to directly trigger a guest interrupt.
3151 kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
3152 kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
3153 an event is triggered on the eventfd, an interrupt is injected into
3154 the guest using the specified gsi pin. The irqfd is removed using
3155 the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
3158 With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
3159 mechanism allowing emulation of level-triggered, irqfd-based
3160 interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
3161 additional eventfd in the kvm_irqfd.resamplefd field. When operating
3162 in resample mode, posting of an interrupt through kvm_irq.fd asserts
3163 the specified gsi in the irqchip. When the irqchip is resampled, such
3164 as from an EOI, the gsi is de-asserted and the user is notified via
3165 kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
3166 the interrupt if the device making use of it still requires service.
3167 Note that closing the resamplefd is not sufficient to disable the
3168 irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
3169 and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
3171 On arm64, gsi routing being supported, the following can happen:
3173 - in case no routing entry is associated to this gsi, injection fails
3174 - in case the gsi is associated to an irqchip routing entry,
3175 irqchip.pin + 32 corresponds to the injected SPI ID.
3176 - in case the gsi is associated to an MSI routing entry, the MSI
3177 message and device ID are translated into an LPI (support restricted
3178 to GICv3 ITS in-kernel emulation).
3180 4.76 KVM_PPC_ALLOCATE_HTAB
3181 --------------------------
3183 :Capability: KVM_CAP_PPC_ALLOC_HTAB
3184 :Architectures: powerpc
3186 :Parameters: Pointer to u32 containing hash table order (in/out)
3187 :Returns: 0 on success, -1 on error
3189 This requests the host kernel to allocate an MMU hash table for a
3190 guest using the PAPR paravirtualization interface. This only does
3191 anything if the kernel is configured to use the Book 3S HV style of
3192 virtualization. Otherwise the capability doesn't exist and the ioctl
3193 returns an ENOTTY error. The rest of this description assumes Book 3S
3196 There must be no vcpus running when this ioctl is called; if there
3197 are, it will do nothing and return an EBUSY error.
3199 The parameter is a pointer to a 32-bit unsigned integer variable
3200 containing the order (log base 2) of the desired size of the hash
3201 table, which must be between 18 and 46. On successful return from the
3202 ioctl, the value will not be changed by the kernel.
3204 If no hash table has been allocated when any vcpu is asked to run
3205 (with the KVM_RUN ioctl), the host kernel will allocate a
3206 default-sized hash table (16 MB).
3208 If this ioctl is called when a hash table has already been allocated,
3209 with a different order from the existing hash table, the existing hash
3210 table will be freed and a new one allocated. If this is ioctl is
3211 called when a hash table has already been allocated of the same order
3212 as specified, the kernel will clear out the existing hash table (zero
3213 all HPTEs). In either case, if the guest is using the virtualized
3214 real-mode area (VRMA) facility, the kernel will re-create the VMRA
3215 HPTEs on the next KVM_RUN of any vcpu.
3217 4.77 KVM_S390_INTERRUPT
3218 -----------------------
3221 :Architectures: s390
3222 :Type: vm ioctl, vcpu ioctl
3223 :Parameters: struct kvm_s390_interrupt (in)
3224 :Returns: 0 on success, -1 on error
3226 Allows to inject an interrupt to the guest. Interrupts can be floating
3227 (vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
3229 Interrupt parameters are passed via kvm_s390_interrupt::
3231 struct kvm_s390_interrupt {
3237 type can be one of the following:
3239 KVM_S390_SIGP_STOP (vcpu)
3240 - sigp stop; optional flags in parm
3241 KVM_S390_PROGRAM_INT (vcpu)
3242 - program check; code in parm
3243 KVM_S390_SIGP_SET_PREFIX (vcpu)
3244 - sigp set prefix; prefix address in parm
3245 KVM_S390_RESTART (vcpu)
3247 KVM_S390_INT_CLOCK_COMP (vcpu)
3248 - clock comparator interrupt
3249 KVM_S390_INT_CPU_TIMER (vcpu)
3250 - CPU timer interrupt
3251 KVM_S390_INT_VIRTIO (vm)
3252 - virtio external interrupt; external interrupt
3253 parameters in parm and parm64
3254 KVM_S390_INT_SERVICE (vm)
3255 - sclp external interrupt; sclp parameter in parm
3256 KVM_S390_INT_EMERGENCY (vcpu)
3257 - sigp emergency; source cpu in parm
3258 KVM_S390_INT_EXTERNAL_CALL (vcpu)
3259 - sigp external call; source cpu in parm
3260 KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm)
3261 - compound value to indicate an
3262 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
3263 I/O interruption parameters in parm (subchannel) and parm64 (intparm,
3264 interruption subclass)
3265 KVM_S390_MCHK (vm, vcpu)
3266 - machine check interrupt; cr 14 bits in parm, machine check interrupt
3267 code in parm64 (note that machine checks needing further payload are not
3268 supported by this ioctl)
3270 This is an asynchronous vcpu ioctl and can be invoked from any thread.
3272 4.78 KVM_PPC_GET_HTAB_FD
3273 ------------------------
3275 :Capability: KVM_CAP_PPC_HTAB_FD
3276 :Architectures: powerpc
3278 :Parameters: Pointer to struct kvm_get_htab_fd (in)
3279 :Returns: file descriptor number (>= 0) on success, -1 on error
3281 This returns a file descriptor that can be used either to read out the
3282 entries in the guest's hashed page table (HPT), or to write entries to
3283 initialize the HPT. The returned fd can only be written to if the
3284 KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
3285 can only be read if that bit is clear. The argument struct looks like
3288 /* For KVM_PPC_GET_HTAB_FD */
3289 struct kvm_get_htab_fd {
3295 /* Values for kvm_get_htab_fd.flags */
3296 #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
3297 #define KVM_GET_HTAB_WRITE ((__u64)0x2)
3299 The 'start_index' field gives the index in the HPT of the entry at
3300 which to start reading. It is ignored when writing.
3302 Reads on the fd will initially supply information about all
3303 "interesting" HPT entries. Interesting entries are those with the
3304 bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
3305 all entries. When the end of the HPT is reached, the read() will
3306 return. If read() is called again on the fd, it will start again from
3307 the beginning of the HPT, but will only return HPT entries that have
3308 changed since they were last read.
3310 Data read or written is structured as a header (8 bytes) followed by a
3311 series of valid HPT entries (16 bytes) each. The header indicates how
3312 many valid HPT entries there are and how many invalid entries follow
3313 the valid entries. The invalid entries are not represented explicitly
3314 in the stream. The header format is::
3316 struct kvm_get_htab_header {
3322 Writes to the fd create HPT entries starting at the index given in the
3323 header; first 'n_valid' valid entries with contents from the data
3324 written, then 'n_invalid' invalid entries, invalidating any previously
3325 valid entries found.
3327 4.79 KVM_CREATE_DEVICE
3328 ----------------------
3330 :Capability: KVM_CAP_DEVICE_CTRL
3333 :Parameters: struct kvm_create_device (in/out)
3334 :Returns: 0 on success, -1 on error
3338 ====== =======================================================
3339 ENODEV The device type is unknown or unsupported
3340 EEXIST Device already created, and this type of device may not
3341 be instantiated multiple times
3342 ====== =======================================================
3344 Other error conditions may be defined by individual device types or
3345 have their standard meanings.
3347 Creates an emulated device in the kernel. The file descriptor returned
3348 in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
3350 If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
3351 device type is supported (not necessarily whether it can be created
3354 Individual devices should not define flags. Attributes should be used
3355 for specifying any behavior that is not implied by the device type
3360 struct kvm_create_device {
3361 __u32 type; /* in: KVM_DEV_TYPE_xxx */
3362 __u32 fd; /* out: device handle */
3363 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
3366 4.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
3367 --------------------------------------------
3369 :Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3370 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3371 KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device (no set)
3372 :Architectures: x86, arm64, s390
3373 :Type: device ioctl, vm ioctl, vcpu ioctl
3374 :Parameters: struct kvm_device_attr
3375 :Returns: 0 on success, -1 on error
3379 ===== =============================================================
3380 ENXIO The group or attribute is unknown/unsupported for this device
3381 or hardware support is missing.
3382 EPERM The attribute cannot (currently) be accessed this way
3383 (e.g. read-only attribute, or attribute that only makes
3384 sense when the device is in a different state)
3385 ===== =============================================================
3387 Other error conditions may be defined by individual device types.
3389 Gets/sets a specified piece of device configuration and/or state. The
3390 semantics are device-specific. See individual device documentation in
3391 the "devices" directory. As with ONE_REG, the size of the data
3392 transferred is defined by the particular attribute.
3396 struct kvm_device_attr {
3397 __u32 flags; /* no flags currently defined */
3398 __u32 group; /* device-defined */
3399 __u64 attr; /* group-defined */
3400 __u64 addr; /* userspace address of attr data */
3403 4.81 KVM_HAS_DEVICE_ATTR
3404 ------------------------
3406 :Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3407 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3408 KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device
3409 :Type: device ioctl, vm ioctl, vcpu ioctl
3410 :Parameters: struct kvm_device_attr
3411 :Returns: 0 on success, -1 on error
3415 ===== =============================================================
3416 ENXIO The group or attribute is unknown/unsupported for this device
3417 or hardware support is missing.
3418 ===== =============================================================
3420 Tests whether a device supports a particular attribute. A successful
3421 return indicates the attribute is implemented. It does not necessarily
3422 indicate that the attribute can be read or written in the device's
3423 current state. "addr" is ignored.
3425 .. _KVM_ARM_VCPU_INIT:
3427 4.82 KVM_ARM_VCPU_INIT
3428 ----------------------
3431 :Architectures: arm64
3433 :Parameters: struct kvm_vcpu_init (in)
3434 :Returns: 0 on success; -1 on error
3438 ====== =================================================================
3439 EINVAL the target is unknown, or the combination of features is invalid.
3440 ENOENT a features bit specified is unknown.
3441 ====== =================================================================
3443 This tells KVM what type of CPU to present to the guest, and what
3444 optional features it should have. This will cause a reset of the cpu
3445 registers to their initial values. If this is not called, KVM_RUN will
3446 return ENOEXEC for that vcpu.
3448 The initial values are defined as:
3450 * AArch64: EL1h, D, A, I and F bits set. All other bits
3452 * AArch32: SVC, A, I and F bits set. All other bits are
3454 - General Purpose registers, including PC and SP: set to 0
3455 - FPSIMD/NEON registers: set to 0
3456 - SVE registers: set to 0
3457 - System registers: Reset to their architecturally defined
3458 values as for a warm reset to EL1 (resp. SVC)
3460 Note that because some registers reflect machine topology, all vcpus
3461 should be created before this ioctl is invoked.
3463 Userspace can call this function multiple times for a given vcpu, including
3464 after the vcpu has been run. This will reset the vcpu to its initial
3465 state. All calls to this function after the initial call must use the same
3466 target and same set of feature flags, otherwise EINVAL will be returned.
3470 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
3471 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
3472 and execute guest code when KVM_RUN is called.
3473 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
3474 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
3475 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
3476 backward compatible with v0.2) for the CPU.
3477 Depends on KVM_CAP_ARM_PSCI_0_2.
3478 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
3479 Depends on KVM_CAP_ARM_PMU_V3.
3481 - KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication
3483 Depends on KVM_CAP_ARM_PTRAUTH_ADDRESS.
3484 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3485 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3486 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3489 - KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication
3491 Depends on KVM_CAP_ARM_PTRAUTH_GENERIC.
3492 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3493 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3494 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3497 - KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only).
3498 Depends on KVM_CAP_ARM_SVE.
3499 Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3501 * After KVM_ARM_VCPU_INIT:
3503 - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the
3504 initial value of this pseudo-register indicates the best set of
3505 vector lengths possible for a vcpu on this host.
3507 * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3509 - KVM_RUN and KVM_GET_REG_LIST are not available;
3511 - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access
3512 the scalable architectural SVE registers
3513 KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or
3514 KVM_REG_ARM64_SVE_FFR;
3516 - KVM_REG_ARM64_SVE_VLS may optionally be written using
3517 KVM_SET_ONE_REG, to modify the set of vector lengths available
3520 * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3522 - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can
3523 no longer be written using KVM_SET_ONE_REG.
3525 4.83 KVM_ARM_PREFERRED_TARGET
3526 -----------------------------
3529 :Architectures: arm64
3531 :Parameters: struct kvm_vcpu_init (out)
3532 :Returns: 0 on success; -1 on error
3536 ====== ==========================================
3537 ENODEV no preferred target available for the host
3538 ====== ==========================================
3540 This queries KVM for preferred CPU target type which can be emulated
3541 by KVM on underlying host.
3543 The ioctl returns struct kvm_vcpu_init instance containing information
3544 about preferred CPU target type and recommended features for it. The
3545 kvm_vcpu_init->features bitmap returned will have feature bits set if
3546 the preferred target recommends setting these features, but this is
3549 The information returned by this ioctl can be used to prepare an instance
3550 of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
3551 VCPU matching underlying host.
3554 4.84 KVM_GET_REG_LIST
3555 ---------------------
3558 :Architectures: arm64, mips, riscv
3560 :Parameters: struct kvm_reg_list (in/out)
3561 :Returns: 0 on success; -1 on error
3565 ===== ==============================================================
3566 E2BIG the reg index list is too big to fit in the array specified by
3567 the user (the number required will be written into n).
3568 ===== ==============================================================
3572 struct kvm_reg_list {
3573 __u64 n; /* number of registers in reg[] */
3577 This ioctl returns the guest registers that are supported for the
3578 KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
3581 4.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
3582 -----------------------------------------
3584 :Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
3585 :Architectures: arm64
3587 :Parameters: struct kvm_arm_device_address (in)
3588 :Returns: 0 on success, -1 on error
3592 ====== ============================================
3593 ENODEV The device id is unknown
3594 ENXIO Device not supported on current system
3595 EEXIST Address already set
3596 E2BIG Address outside guest physical address space
3597 EBUSY Address overlaps with other device range
3598 ====== ============================================
3602 struct kvm_arm_device_addr {
3607 Specify a device address in the guest's physical address space where guests
3608 can access emulated or directly exposed devices, which the host kernel needs
3609 to know about. The id field is an architecture specific identifier for a
3612 arm64 divides the id field into two parts, a device id and an
3613 address type id specific to the individual device::
3615 bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
3616 field: | 0x00000000 | device id | addr type id |
3618 arm64 currently only require this when using the in-kernel GIC
3619 support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
3620 as the device id. When setting the base address for the guest's
3621 mapping of the VGIC virtual CPU and distributor interface, the ioctl
3622 must be called after calling KVM_CREATE_IRQCHIP, but before calling
3623 KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
3624 base addresses will return -EEXIST.
3626 Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
3627 should be used instead.
3630 4.86 KVM_PPC_RTAS_DEFINE_TOKEN
3631 ------------------------------
3633 :Capability: KVM_CAP_PPC_RTAS
3636 :Parameters: struct kvm_rtas_token_args
3637 :Returns: 0 on success, -1 on error
3639 Defines a token value for a RTAS (Run Time Abstraction Services)
3640 service in order to allow it to be handled in the kernel. The
3641 argument struct gives the name of the service, which must be the name
3642 of a service that has a kernel-side implementation. If the token
3643 value is non-zero, it will be associated with that service, and
3644 subsequent RTAS calls by the guest specifying that token will be
3645 handled by the kernel. If the token value is 0, then any token
3646 associated with the service will be forgotten, and subsequent RTAS
3647 calls by the guest for that service will be passed to userspace to be
3650 4.87 KVM_SET_GUEST_DEBUG
3651 ------------------------
3653 :Capability: KVM_CAP_SET_GUEST_DEBUG
3654 :Architectures: x86, s390, ppc, arm64
3656 :Parameters: struct kvm_guest_debug (in)
3657 :Returns: 0 on success; -1 on error
3661 struct kvm_guest_debug {
3664 struct kvm_guest_debug_arch arch;
3667 Set up the processor specific debug registers and configure vcpu for
3668 handling guest debug events. There are two parts to the structure, the
3669 first a control bitfield indicates the type of debug events to handle
3670 when running. Common control bits are:
3672 - KVM_GUESTDBG_ENABLE: guest debugging is enabled
3673 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
3675 The top 16 bits of the control field are architecture specific control
3676 flags which can include the following:
3678 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
3679 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390]
3680 - KVM_GUESTDBG_USE_HW: using hardware debug events [arm64]
3681 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
3682 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
3683 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
3684 - KVM_GUESTDBG_BLOCKIRQ: avoid injecting interrupts/NMI/SMI [x86]
3686 For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
3687 are enabled in memory so we need to ensure breakpoint exceptions are
3688 correctly trapped and the KVM run loop exits at the breakpoint and not
3689 running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
3690 we need to ensure the guest vCPUs architecture specific registers are
3691 updated to the correct (supplied) values.
3693 The second part of the structure is architecture specific and
3694 typically contains a set of debug registers.
3696 For arm64 the number of debug registers is implementation defined and
3697 can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
3698 KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
3699 indicating the number of supported registers.
3701 For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether
3702 the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported.
3704 Also when supported, KVM_CAP_SET_GUEST_DEBUG2 capability indicates the
3705 supported KVM_GUESTDBG_* bits in the control field.
3707 When debug events exit the main run loop with the reason
3708 KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
3709 structure containing architecture specific debug information.
3711 4.88 KVM_GET_EMULATED_CPUID
3712 ---------------------------
3714 :Capability: KVM_CAP_EXT_EMUL_CPUID
3717 :Parameters: struct kvm_cpuid2 (in/out)
3718 :Returns: 0 on success, -1 on error
3725 struct kvm_cpuid_entry2 entries[0];
3728 The member 'flags' is used for passing flags from userspace.
3732 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
3733 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */
3734 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */
3736 struct kvm_cpuid_entry2 {
3747 This ioctl returns x86 cpuid features which are emulated by
3748 kvm.Userspace can use the information returned by this ioctl to query
3749 which features are emulated by kvm instead of being present natively.
3751 Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
3752 structure with the 'nent' field indicating the number of entries in
3753 the variable-size array 'entries'. If the number of entries is too low
3754 to describe the cpu capabilities, an error (E2BIG) is returned. If the
3755 number is too high, the 'nent' field is adjusted and an error (ENOMEM)
3756 is returned. If the number is just right, the 'nent' field is adjusted
3757 to the number of valid entries in the 'entries' array, which is then
3760 The entries returned are the set CPUID bits of the respective features
3761 which kvm emulates, as returned by the CPUID instruction, with unknown
3762 or unsupported feature bits cleared.
3764 Features like x2apic, for example, may not be present in the host cpu
3765 but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
3766 emulated efficiently and thus not included here.
3768 The fields in each entry are defined as follows:
3771 the eax value used to obtain the entry
3773 the ecx value used to obtain the entry (for entries that are
3776 an OR of zero or more of the following:
3778 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
3779 if the index field is valid
3783 the values returned by the cpuid instruction for
3784 this function/index combination
3786 4.89 KVM_S390_MEM_OP
3787 --------------------
3789 :Capability: KVM_CAP_S390_MEM_OP, KVM_CAP_S390_PROTECTED, KVM_CAP_S390_MEM_OP_EXTENSION
3790 :Architectures: s390
3791 :Type: vm ioctl, vcpu ioctl
3792 :Parameters: struct kvm_s390_mem_op (in)
3793 :Returns: = 0 on success,
3794 < 0 on generic error (e.g. -EFAULT or -ENOMEM),
3795 16 bit program exception code if the access causes such an exception
3797 Read or write data from/to the VM's memory.
3798 The KVM_CAP_S390_MEM_OP_EXTENSION capability specifies what functionality is
3801 Parameters are specified via the following structure::
3803 struct kvm_s390_mem_op {
3804 __u64 gaddr; /* the guest address */
3805 __u64 flags; /* flags */
3806 __u32 size; /* amount of bytes */
3807 __u32 op; /* type of operation */
3808 __u64 buf; /* buffer in userspace */
3811 __u8 ar; /* the access register number */
3812 __u8 key; /* access key, ignored if flag unset */
3813 __u8 pad1[6]; /* ignored */
3814 __u64 old_addr; /* ignored if flag unset */
3816 __u32 sida_offset; /* offset into the sida */
3817 __u8 reserved[32]; /* ignored */
3821 The start address of the memory region has to be specified in the "gaddr"
3822 field, and the length of the region in the "size" field (which must not
3823 be 0). The maximum value for "size" can be obtained by checking the
3824 KVM_CAP_S390_MEM_OP capability. "buf" is the buffer supplied by the
3825 userspace application where the read data should be written to for
3826 a read access, or where the data that should be written is stored for
3827 a write access. The "reserved" field is meant for future extensions.
3828 Reserved and unused values are ignored. Future extension that add members must
3829 introduce new flags.
3831 The type of operation is specified in the "op" field. Flags modifying
3832 their behavior can be set in the "flags" field. Undefined flag bits must
3835 Possible operations are:
3836 * ``KVM_S390_MEMOP_LOGICAL_READ``
3837 * ``KVM_S390_MEMOP_LOGICAL_WRITE``
3838 * ``KVM_S390_MEMOP_ABSOLUTE_READ``
3839 * ``KVM_S390_MEMOP_ABSOLUTE_WRITE``
3840 * ``KVM_S390_MEMOP_SIDA_READ``
3841 * ``KVM_S390_MEMOP_SIDA_WRITE``
3842 * ``KVM_S390_MEMOP_ABSOLUTE_CMPXCHG``
3847 Access logical memory, i.e. translate the given guest address to an absolute
3848 address given the state of the VCPU and use the absolute address as target of
3849 the access. "ar" designates the access register number to be used; the valid
3851 Logical accesses are permitted for the VCPU ioctl only.
3852 Logical accesses are permitted for non-protected guests only.
3855 * ``KVM_S390_MEMOP_F_CHECK_ONLY``
3856 * ``KVM_S390_MEMOP_F_INJECT_EXCEPTION``
3857 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION``
3859 The KVM_S390_MEMOP_F_CHECK_ONLY flag can be set to check whether the
3860 corresponding memory access would cause an access exception; however,
3861 no actual access to the data in memory at the destination is performed.
3862 In this case, "buf" is unused and can be NULL.
3864 In case an access exception occurred during the access (or would occur
3865 in case of KVM_S390_MEMOP_F_CHECK_ONLY), the ioctl returns a positive
3866 error number indicating the type of exception. This exception is also
3867 raised directly at the corresponding VCPU if the flag
3868 KVM_S390_MEMOP_F_INJECT_EXCEPTION is set.
3869 On protection exceptions, unless specified otherwise, the injected
3870 translation-exception identifier (TEID) indicates suppression.
3872 If the KVM_S390_MEMOP_F_SKEY_PROTECTION flag is set, storage key
3873 protection is also in effect and may cause exceptions if accesses are
3874 prohibited given the access key designated by "key"; the valid range is 0..15.
3875 KVM_S390_MEMOP_F_SKEY_PROTECTION is available if KVM_CAP_S390_MEM_OP_EXTENSION
3877 Since the accessed memory may span multiple pages and those pages might have
3878 different storage keys, it is possible that a protection exception occurs
3879 after memory has been modified. In this case, if the exception is injected,
3880 the TEID does not indicate suppression.
3882 Absolute read/write:
3883 ^^^^^^^^^^^^^^^^^^^^
3885 Access absolute memory. This operation is intended to be used with the
3886 KVM_S390_MEMOP_F_SKEY_PROTECTION flag, to allow accessing memory and performing
3887 the checks required for storage key protection as one operation (as opposed to
3888 user space getting the storage keys, performing the checks, and accessing
3889 memory thereafter, which could lead to a delay between check and access).
3890 Absolute accesses are permitted for the VM ioctl if KVM_CAP_S390_MEM_OP_EXTENSION
3891 has the KVM_S390_MEMOP_EXTENSION_CAP_BASE bit set.
3892 Currently absolute accesses are not permitted for VCPU ioctls.
3893 Absolute accesses are permitted for non-protected guests only.
3896 * ``KVM_S390_MEMOP_F_CHECK_ONLY``
3897 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION``
3899 The semantics of the flags common with logical accesses are as for logical
3905 Perform cmpxchg on absolute guest memory. Intended for use with the
3906 KVM_S390_MEMOP_F_SKEY_PROTECTION flag.
3907 Instead of doing an unconditional write, the access occurs only if the target
3908 location contains the value pointed to by "old_addr".
3909 This is performed as an atomic cmpxchg with the length specified by the "size"
3910 parameter. "size" must be a power of two up to and including 16.
3911 If the exchange did not take place because the target value doesn't match the
3912 old value, the value "old_addr" points to is replaced by the target value.
3913 User space can tell if an exchange took place by checking if this replacement
3914 occurred. The cmpxchg op is permitted for the VM ioctl if
3915 KVM_CAP_S390_MEM_OP_EXTENSION has flag KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG set.
3918 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION``
3923 Access the secure instruction data area which contains memory operands necessary
3924 for instruction emulation for protected guests.
3925 SIDA accesses are available if the KVM_CAP_S390_PROTECTED capability is available.
3926 SIDA accesses are permitted for the VCPU ioctl only.
3927 SIDA accesses are permitted for protected guests only.
3929 No flags are supported.
3931 4.90 KVM_S390_GET_SKEYS
3932 -----------------------
3934 :Capability: KVM_CAP_S390_SKEYS
3935 :Architectures: s390
3937 :Parameters: struct kvm_s390_skeys
3938 :Returns: 0 on success, KVM_S390_GET_SKEYS_NONE if guest is not using storage
3939 keys, negative value on error
3941 This ioctl is used to get guest storage key values on the s390
3942 architecture. The ioctl takes parameters via the kvm_s390_skeys struct::
3944 struct kvm_s390_skeys {
3947 __u64 skeydata_addr;
3952 The start_gfn field is the number of the first guest frame whose storage keys
3955 The count field is the number of consecutive frames (starting from start_gfn)
3956 whose storage keys to get. The count field must be at least 1 and the maximum
3957 allowed value is defined as KVM_S390_SKEYS_MAX. Values outside this range
3958 will cause the ioctl to return -EINVAL.
3960 The skeydata_addr field is the address to a buffer large enough to hold count
3961 bytes. This buffer will be filled with storage key data by the ioctl.
3963 4.91 KVM_S390_SET_SKEYS
3964 -----------------------
3966 :Capability: KVM_CAP_S390_SKEYS
3967 :Architectures: s390
3969 :Parameters: struct kvm_s390_skeys
3970 :Returns: 0 on success, negative value on error
3972 This ioctl is used to set guest storage key values on the s390
3973 architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
3974 See section on KVM_S390_GET_SKEYS for struct definition.
3976 The start_gfn field is the number of the first guest frame whose storage keys
3979 The count field is the number of consecutive frames (starting from start_gfn)
3980 whose storage keys to get. The count field must be at least 1 and the maximum
3981 allowed value is defined as KVM_S390_SKEYS_MAX. Values outside this range
3982 will cause the ioctl to return -EINVAL.
3984 The skeydata_addr field is the address to a buffer containing count bytes of
3985 storage keys. Each byte in the buffer will be set as the storage key for a
3986 single frame starting at start_gfn for count frames.
3988 Note: If any architecturally invalid key value is found in the given data then
3989 the ioctl will return -EINVAL.
3994 :Capability: KVM_CAP_S390_INJECT_IRQ
3995 :Architectures: s390
3997 :Parameters: struct kvm_s390_irq (in)
3998 :Returns: 0 on success, -1 on error
4003 ====== =================================================================
4004 EINVAL interrupt type is invalid
4005 type is KVM_S390_SIGP_STOP and flag parameter is invalid value,
4006 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
4007 than the maximum of VCPUs
4008 EBUSY type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped,
4009 type is KVM_S390_SIGP_STOP and a stop irq is already pending,
4010 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
4012 ====== =================================================================
4014 Allows to inject an interrupt to the guest.
4016 Using struct kvm_s390_irq as a parameter allows
4017 to inject additional payload which is not
4018 possible via KVM_S390_INTERRUPT.
4020 Interrupt parameters are passed via kvm_s390_irq::
4022 struct kvm_s390_irq {
4025 struct kvm_s390_io_info io;
4026 struct kvm_s390_ext_info ext;
4027 struct kvm_s390_pgm_info pgm;
4028 struct kvm_s390_emerg_info emerg;
4029 struct kvm_s390_extcall_info extcall;
4030 struct kvm_s390_prefix_info prefix;
4031 struct kvm_s390_stop_info stop;
4032 struct kvm_s390_mchk_info mchk;
4037 type can be one of the following:
4039 - KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
4040 - KVM_S390_PROGRAM_INT - program check; parameters in .pgm
4041 - KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
4042 - KVM_S390_RESTART - restart; no parameters
4043 - KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
4044 - KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
4045 - KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
4046 - KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
4047 - KVM_S390_MCHK - machine check interrupt; parameters in .mchk
4049 This is an asynchronous vcpu ioctl and can be invoked from any thread.
4051 4.94 KVM_S390_GET_IRQ_STATE
4052 ---------------------------
4054 :Capability: KVM_CAP_S390_IRQ_STATE
4055 :Architectures: s390
4057 :Parameters: struct kvm_s390_irq_state (out)
4058 :Returns: >= number of bytes copied into buffer,
4059 -EINVAL if buffer size is 0,
4060 -ENOBUFS if buffer size is too small to fit all pending interrupts,
4061 -EFAULT if the buffer address was invalid
4063 This ioctl allows userspace to retrieve the complete state of all currently
4064 pending interrupts in a single buffer. Use cases include migration
4065 and introspection. The parameter structure contains the address of a
4066 userspace buffer and its length::
4068 struct kvm_s390_irq_state {
4070 __u32 flags; /* will stay unused for compatibility reasons */
4072 __u32 reserved[4]; /* will stay unused for compatibility reasons */
4075 Userspace passes in the above struct and for each pending interrupt a
4076 struct kvm_s390_irq is copied to the provided buffer.
4078 The structure contains a flags and a reserved field for future extensions. As
4079 the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
4080 reserved, these fields can not be used in the future without breaking
4083 If -ENOBUFS is returned the buffer provided was too small and userspace
4084 may retry with a bigger buffer.
4086 4.95 KVM_S390_SET_IRQ_STATE
4087 ---------------------------
4089 :Capability: KVM_CAP_S390_IRQ_STATE
4090 :Architectures: s390
4092 :Parameters: struct kvm_s390_irq_state (in)
4093 :Returns: 0 on success,
4094 -EFAULT if the buffer address was invalid,
4095 -EINVAL for an invalid buffer length (see below),
4096 -EBUSY if there were already interrupts pending,
4097 errors occurring when actually injecting the
4098 interrupt. See KVM_S390_IRQ.
4100 This ioctl allows userspace to set the complete state of all cpu-local
4101 interrupts currently pending for the vcpu. It is intended for restoring
4102 interrupt state after a migration. The input parameter is a userspace buffer
4103 containing a struct kvm_s390_irq_state::
4105 struct kvm_s390_irq_state {
4107 __u32 flags; /* will stay unused for compatibility reasons */
4109 __u32 reserved[4]; /* will stay unused for compatibility reasons */
4112 The restrictions for flags and reserved apply as well.
4113 (see KVM_S390_GET_IRQ_STATE)
4115 The userspace memory referenced by buf contains a struct kvm_s390_irq
4116 for each interrupt to be injected into the guest.
4117 If one of the interrupts could not be injected for some reason the
4120 len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
4121 and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
4122 which is the maximum number of possibly pending cpu-local interrupts.
4127 :Capability: KVM_CAP_X86_SMM
4131 :Returns: 0 on success, -1 on error
4133 Queues an SMI on the thread's vcpu.
4135 4.97 KVM_X86_SET_MSR_FILTER
4136 ----------------------------
4138 :Capability: KVM_CAP_X86_MSR_FILTER
4141 :Parameters: struct kvm_msr_filter
4142 :Returns: 0 on success, < 0 on error
4146 struct kvm_msr_filter_range {
4147 #define KVM_MSR_FILTER_READ (1 << 0)
4148 #define KVM_MSR_FILTER_WRITE (1 << 1)
4150 __u32 nmsrs; /* number of msrs in bitmap */
4151 __u32 base; /* MSR index the bitmap starts at */
4152 __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
4155 #define KVM_MSR_FILTER_MAX_RANGES 16
4156 struct kvm_msr_filter {
4157 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
4158 #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0)
4160 struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
4163 flags values for ``struct kvm_msr_filter_range``:
4165 ``KVM_MSR_FILTER_READ``
4167 Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap
4168 indicates that read accesses should be denied, while a 1 indicates that
4169 a read for a particular MSR should be allowed regardless of the default
4172 ``KVM_MSR_FILTER_WRITE``
4174 Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap
4175 indicates that write accesses should be denied, while a 1 indicates that
4176 a write for a particular MSR should be allowed regardless of the default
4179 flags values for ``struct kvm_msr_filter``:
4181 ``KVM_MSR_FILTER_DEFAULT_ALLOW``
4183 If no filter range matches an MSR index that is getting accessed, KVM will
4184 allow accesses to all MSRs by default.
4186 ``KVM_MSR_FILTER_DEFAULT_DENY``
4188 If no filter range matches an MSR index that is getting accessed, KVM will
4189 deny accesses to all MSRs by default.
4191 This ioctl allows userspace to define up to 16 bitmaps of MSR ranges to deny
4192 guest MSR accesses that would normally be allowed by KVM. If an MSR is not
4193 covered by a specific range, the "default" filtering behavior applies. Each
4194 bitmap range covers MSRs from [base .. base+nmsrs).
4196 If an MSR access is denied by userspace, the resulting KVM behavior depends on
4197 whether or not KVM_CAP_X86_USER_SPACE_MSR's KVM_MSR_EXIT_REASON_FILTER is
4198 enabled. If KVM_MSR_EXIT_REASON_FILTER is enabled, KVM will exit to userspace
4199 on denied accesses, i.e. userspace effectively intercepts the MSR access. If
4200 KVM_MSR_EXIT_REASON_FILTER is not enabled, KVM will inject a #GP into the guest
4203 If an MSR access is allowed by userspace, KVM will emulate and/or virtualize
4204 the access in accordance with the vCPU model. Note, KVM may still ultimately
4205 inject a #GP if an access is allowed by userspace, e.g. if KVM doesn't support
4206 the MSR, or to follow architectural behavior for the MSR.
4208 By default, KVM operates in KVM_MSR_FILTER_DEFAULT_ALLOW mode with no MSR range
4211 Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR
4212 filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes
4216 MSR accesses as part of nested VM-Enter/VM-Exit are not filtered.
4217 This includes both writes to individual VMCS fields and reads/writes
4218 through the MSR lists pointed to by the VMCS.
4220 x2APIC MSR accesses cannot be filtered (KVM silently ignores filters that
4221 cover any x2APIC MSRs).
4223 Note, invoking this ioctl while a vCPU is running is inherently racy. However,
4224 KVM does guarantee that vCPUs will see either the previous filter or the new
4225 filter, e.g. MSRs with identical settings in both the old and new filter will
4226 have deterministic behavior.
4228 Similarly, if userspace wishes to intercept on denied accesses,
4229 KVM_MSR_EXIT_REASON_FILTER must be enabled before activating any filters, and
4230 left enabled until after all filters are deactivated. Failure to do so may
4231 result in KVM injecting a #GP instead of exiting to userspace.
4233 4.98 KVM_CREATE_SPAPR_TCE_64
4234 ----------------------------
4236 :Capability: KVM_CAP_SPAPR_TCE_64
4237 :Architectures: powerpc
4239 :Parameters: struct kvm_create_spapr_tce_64 (in)
4240 :Returns: file descriptor for manipulating the created TCE table
4242 This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
4243 windows, described in 4.62 KVM_CREATE_SPAPR_TCE
4245 This capability uses extended struct in ioctl interface::
4247 /* for KVM_CAP_SPAPR_TCE_64 */
4248 struct kvm_create_spapr_tce_64 {
4252 __u64 offset; /* in pages */
4253 __u64 size; /* in pages */
4256 The aim of extension is to support an additional bigger DMA window with
4257 a variable page size.
4258 KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
4259 a bus offset of the corresponding DMA window, @size and @offset are numbers
4262 @flags are not used at the moment.
4264 The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
4266 4.99 KVM_REINJECT_CONTROL
4267 -------------------------
4269 :Capability: KVM_CAP_REINJECT_CONTROL
4272 :Parameters: struct kvm_reinject_control (in)
4273 :Returns: 0 on success,
4274 -EFAULT if struct kvm_reinject_control cannot be read,
4275 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
4277 i8254 (PIT) has two modes, reinject and !reinject. The default is reinject,
4278 where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
4279 vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its
4280 interrupt whenever there isn't a pending interrupt from i8254.
4281 !reinject mode injects an interrupt as soon as a tick arrives.
4285 struct kvm_reinject_control {
4290 pit_reinject = 0 (!reinject mode) is recommended, unless running an old
4291 operating system that uses the PIT for timing (e.g. Linux 2.4.x).
4293 4.100 KVM_PPC_CONFIGURE_V3_MMU
4294 ------------------------------
4296 :Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
4299 :Parameters: struct kvm_ppc_mmuv3_cfg (in)
4300 :Returns: 0 on success,
4301 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
4302 -EINVAL if the configuration is invalid
4304 This ioctl controls whether the guest will use radix or HPT (hashed
4305 page table) translation, and sets the pointer to the process table for
4310 struct kvm_ppc_mmuv3_cfg {
4312 __u64 process_table;
4315 There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
4316 KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest
4317 to use radix tree translation, and if clear, to use HPT translation.
4318 KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
4319 to be able to use the global TLB and SLB invalidation instructions;
4320 if clear, the guest may not use these instructions.
4322 The process_table field specifies the address and size of the guest
4323 process table, which is in the guest's space. This field is formatted
4324 as the second doubleword of the partition table entry, as defined in
4325 the Power ISA V3.00, Book III section 5.7.6.1.
4327 4.101 KVM_PPC_GET_RMMU_INFO
4328 ---------------------------
4330 :Capability: KVM_CAP_PPC_RADIX_MMU
4333 :Parameters: struct kvm_ppc_rmmu_info (out)
4334 :Returns: 0 on success,
4335 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
4336 -EINVAL if no useful information can be returned
4338 This ioctl returns a structure containing two things: (a) a list
4339 containing supported radix tree geometries, and (b) a list that maps
4340 page sizes to put in the "AP" (actual page size) field for the tlbie
4341 (TLB invalidate entry) instruction.
4345 struct kvm_ppc_rmmu_info {
4346 struct kvm_ppc_radix_geom {
4351 __u32 ap_encodings[8];
4354 The geometries[] field gives up to 8 supported geometries for the
4355 radix page table, in terms of the log base 2 of the smallest page
4356 size, and the number of bits indexed at each level of the tree, from
4357 the PTE level up to the PGD level in that order. Any unused entries
4358 will have 0 in the page_shift field.
4360 The ap_encodings gives the supported page sizes and their AP field
4361 encodings, encoded with the AP value in the top 3 bits and the log
4362 base 2 of the page size in the bottom 6 bits.
4364 4.102 KVM_PPC_RESIZE_HPT_PREPARE
4365 --------------------------------
4367 :Capability: KVM_CAP_SPAPR_RESIZE_HPT
4368 :Architectures: powerpc
4370 :Parameters: struct kvm_ppc_resize_hpt (in)
4371 :Returns: 0 on successful completion,
4372 >0 if a new HPT is being prepared, the value is an estimated
4373 number of milliseconds until preparation is complete,
4374 -EFAULT if struct kvm_reinject_control cannot be read,
4375 -EINVAL if the supplied shift or flags are invalid,
4376 -ENOMEM if unable to allocate the new HPT,
4378 Used to implement the PAPR extension for runtime resizing of a guest's
4379 Hashed Page Table (HPT). Specifically this starts, stops or monitors
4380 the preparation of a new potential HPT for the guest, essentially
4381 implementing the H_RESIZE_HPT_PREPARE hypercall.
4385 struct kvm_ppc_resize_hpt {
4391 If called with shift > 0 when there is no pending HPT for the guest,
4392 this begins preparation of a new pending HPT of size 2^(shift) bytes.
4393 It then returns a positive integer with the estimated number of
4394 milliseconds until preparation is complete.
4396 If called when there is a pending HPT whose size does not match that
4397 requested in the parameters, discards the existing pending HPT and
4398 creates a new one as above.
4400 If called when there is a pending HPT of the size requested, will:
4402 * If preparation of the pending HPT is already complete, return 0
4403 * If preparation of the pending HPT has failed, return an error
4404 code, then discard the pending HPT.
4405 * If preparation of the pending HPT is still in progress, return an
4406 estimated number of milliseconds until preparation is complete.
4408 If called with shift == 0, discards any currently pending HPT and
4409 returns 0 (i.e. cancels any in-progress preparation).
4411 flags is reserved for future expansion, currently setting any bits in
4412 flags will result in an -EINVAL.
4414 Normally this will be called repeatedly with the same parameters until
4415 it returns <= 0. The first call will initiate preparation, subsequent
4416 ones will monitor preparation until it completes or fails.
4418 4.103 KVM_PPC_RESIZE_HPT_COMMIT
4419 -------------------------------
4421 :Capability: KVM_CAP_SPAPR_RESIZE_HPT
4422 :Architectures: powerpc
4424 :Parameters: struct kvm_ppc_resize_hpt (in)
4425 :Returns: 0 on successful completion,
4426 -EFAULT if struct kvm_reinject_control cannot be read,
4427 -EINVAL if the supplied shift or flags are invalid,
4428 -ENXIO is there is no pending HPT, or the pending HPT doesn't
4429 have the requested size,
4430 -EBUSY if the pending HPT is not fully prepared,
4431 -ENOSPC if there was a hash collision when moving existing
4432 HPT entries to the new HPT,
4433 -EIO on other error conditions
4435 Used to implement the PAPR extension for runtime resizing of a guest's
4436 Hashed Page Table (HPT). Specifically this requests that the guest be
4437 transferred to working with the new HPT, essentially implementing the
4438 H_RESIZE_HPT_COMMIT hypercall.
4442 struct kvm_ppc_resize_hpt {
4448 This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
4449 returned 0 with the same parameters. In other cases
4450 KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
4451 -EBUSY, though others may be possible if the preparation was started,
4454 This will have undefined effects on the guest if it has not already
4455 placed itself in a quiescent state where no vcpu will make MMU enabled
4458 On successful completion, the pending HPT will become the guest's active
4459 HPT and the previous HPT will be discarded.
4461 On failure, the guest will still be operating on its previous HPT.
4463 4.104 KVM_X86_GET_MCE_CAP_SUPPORTED
4464 -----------------------------------
4466 :Capability: KVM_CAP_MCE
4469 :Parameters: u64 mce_cap (out)
4470 :Returns: 0 on success, -1 on error
4472 Returns supported MCE capabilities. The u64 mce_cap parameter
4473 has the same format as the MSR_IA32_MCG_CAP register. Supported
4474 capabilities will have the corresponding bits set.
4476 4.105 KVM_X86_SETUP_MCE
4477 -----------------------
4479 :Capability: KVM_CAP_MCE
4482 :Parameters: u64 mcg_cap (in)
4483 :Returns: 0 on success,
4484 -EFAULT if u64 mcg_cap cannot be read,
4485 -EINVAL if the requested number of banks is invalid,
4486 -EINVAL if requested MCE capability is not supported.
4488 Initializes MCE support for use. The u64 mcg_cap parameter
4489 has the same format as the MSR_IA32_MCG_CAP register and
4490 specifies which capabilities should be enabled. The maximum
4491 supported number of error-reporting banks can be retrieved when
4492 checking for KVM_CAP_MCE. The supported capabilities can be
4493 retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
4495 4.106 KVM_X86_SET_MCE
4496 ---------------------
4498 :Capability: KVM_CAP_MCE
4501 :Parameters: struct kvm_x86_mce (in)
4502 :Returns: 0 on success,
4503 -EFAULT if struct kvm_x86_mce cannot be read,
4504 -EINVAL if the bank number is invalid,
4505 -EINVAL if VAL bit is not set in status field.
4507 Inject a machine check error (MCE) into the guest. The input
4510 struct kvm_x86_mce {
4520 If the MCE being reported is an uncorrected error, KVM will
4521 inject it as an MCE exception into the guest. If the guest
4522 MCG_STATUS register reports that an MCE is in progress, KVM
4523 causes an KVM_EXIT_SHUTDOWN vmexit.
4525 Otherwise, if the MCE is a corrected error, KVM will just
4526 store it in the corresponding bank (provided this bank is
4527 not holding a previously reported uncorrected error).
4529 4.107 KVM_S390_GET_CMMA_BITS
4530 ----------------------------
4532 :Capability: KVM_CAP_S390_CMMA_MIGRATION
4533 :Architectures: s390
4535 :Parameters: struct kvm_s390_cmma_log (in, out)
4536 :Returns: 0 on success, a negative value on error
4540 ====== =============================================================
4541 ENOMEM not enough memory can be allocated to complete the task
4542 ENXIO if CMMA is not enabled
4543 EINVAL if KVM_S390_CMMA_PEEK is not set but migration mode was not enabled
4544 EINVAL if KVM_S390_CMMA_PEEK is not set but dirty tracking has been
4545 disabled (and thus migration mode was automatically disabled)
4546 EFAULT if the userspace address is invalid or if no page table is
4547 present for the addresses (e.g. when using hugepages).
4548 ====== =============================================================
4550 This ioctl is used to get the values of the CMMA bits on the s390
4551 architecture. It is meant to be used in two scenarios:
4553 - During live migration to save the CMMA values. Live migration needs
4554 to be enabled via the KVM_REQ_START_MIGRATION VM property.
4555 - To non-destructively peek at the CMMA values, with the flag
4556 KVM_S390_CMMA_PEEK set.
4558 The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
4559 values are written to a buffer whose location is indicated via the "values"
4560 member in the kvm_s390_cmma_log struct. The values in the input struct are
4561 also updated as needed.
4563 Each CMMA value takes up one byte.
4567 struct kvm_s390_cmma_log {
4578 start_gfn is the number of the first guest frame whose CMMA values are
4581 count is the length of the buffer in bytes,
4583 values points to the buffer where the result will be written to.
4585 If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
4586 KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
4589 The result is written in the buffer pointed to by the field values, and
4590 the values of the input parameter are updated as follows.
4592 Depending on the flags, different actions are performed. The only
4593 supported flag so far is KVM_S390_CMMA_PEEK.
4595 The default behaviour if KVM_S390_CMMA_PEEK is not set is:
4596 start_gfn will indicate the first page frame whose CMMA bits were dirty.
4597 It is not necessarily the same as the one passed as input, as clean pages
4600 count will indicate the number of bytes actually written in the buffer.
4601 It can (and very often will) be smaller than the input value, since the
4602 buffer is only filled until 16 bytes of clean values are found (which
4603 are then not copied in the buffer). Since a CMMA migration block needs
4604 the base address and the length, for a total of 16 bytes, we will send
4605 back some clean data if there is some dirty data afterwards, as long as
4606 the size of the clean data does not exceed the size of the header. This
4607 allows to minimize the amount of data to be saved or transferred over
4608 the network at the expense of more roundtrips to userspace. The next
4609 invocation of the ioctl will skip over all the clean values, saving
4610 potentially more than just the 16 bytes we found.
4612 If KVM_S390_CMMA_PEEK is set:
4613 the existing storage attributes are read even when not in migration
4614 mode, and no other action is performed;
4616 the output start_gfn will be equal to the input start_gfn,
4618 the output count will be equal to the input count, except if the end of
4619 memory has been reached.
4622 the field "remaining" will indicate the total number of dirty CMMA values
4623 still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
4628 values points to the userspace buffer where the result will be stored.
4630 4.108 KVM_S390_SET_CMMA_BITS
4631 ----------------------------
4633 :Capability: KVM_CAP_S390_CMMA_MIGRATION
4634 :Architectures: s390
4636 :Parameters: struct kvm_s390_cmma_log (in)
4637 :Returns: 0 on success, a negative value on error
4639 This ioctl is used to set the values of the CMMA bits on the s390
4640 architecture. It is meant to be used during live migration to restore
4641 the CMMA values, but there are no restrictions on its use.
4642 The ioctl takes parameters via the kvm_s390_cmma_values struct.
4643 Each CMMA value takes up one byte.
4647 struct kvm_s390_cmma_log {
4658 start_gfn indicates the starting guest frame number,
4660 count indicates how many values are to be considered in the buffer,
4662 flags is not used and must be 0.
4664 mask indicates which PGSTE bits are to be considered.
4666 remaining is not used.
4668 values points to the buffer in userspace where to store the values.
4670 This ioctl can fail with -ENOMEM if not enough memory can be allocated to
4671 complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
4672 the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
4673 if the flags field was not 0, with -EFAULT if the userspace address is
4674 invalid, if invalid pages are written to (e.g. after the end of memory)
4675 or if no page table is present for the addresses (e.g. when using
4678 4.109 KVM_PPC_GET_CPU_CHAR
4679 --------------------------
4681 :Capability: KVM_CAP_PPC_GET_CPU_CHAR
4682 :Architectures: powerpc
4684 :Parameters: struct kvm_ppc_cpu_char (out)
4685 :Returns: 0 on successful completion,
4686 -EFAULT if struct kvm_ppc_cpu_char cannot be written
4688 This ioctl gives userspace information about certain characteristics
4689 of the CPU relating to speculative execution of instructions and
4690 possible information leakage resulting from speculative execution (see
4691 CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is
4692 returned in struct kvm_ppc_cpu_char, which looks like this::
4694 struct kvm_ppc_cpu_char {
4695 __u64 character; /* characteristics of the CPU */
4696 __u64 behaviour; /* recommended software behaviour */
4697 __u64 character_mask; /* valid bits in character */
4698 __u64 behaviour_mask; /* valid bits in behaviour */
4701 For extensibility, the character_mask and behaviour_mask fields
4702 indicate which bits of character and behaviour have been filled in by
4703 the kernel. If the set of defined bits is extended in future then
4704 userspace will be able to tell whether it is running on a kernel that
4705 knows about the new bits.
4707 The character field describes attributes of the CPU which can help
4708 with preventing inadvertent information disclosure - specifically,
4709 whether there is an instruction to flash-invalidate the L1 data cache
4710 (ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
4711 to a mode where entries can only be used by the thread that created
4712 them, whether the bcctr[l] instruction prevents speculation, and
4713 whether a speculation barrier instruction (ori 31,31,0) is provided.
4715 The behaviour field describes actions that software should take to
4716 prevent inadvertent information disclosure, and thus describes which
4717 vulnerabilities the hardware is subject to; specifically whether the
4718 L1 data cache should be flushed when returning to user mode from the
4719 kernel, and whether a speculation barrier should be placed between an
4720 array bounds check and the array access.
4722 These fields use the same bit definitions as the new
4723 H_GET_CPU_CHARACTERISTICS hypercall.
4725 4.110 KVM_MEMORY_ENCRYPT_OP
4726 ---------------------------
4731 :Parameters: an opaque platform specific structure (in/out)
4732 :Returns: 0 on success; -1 on error
4734 If the platform supports creating encrypted VMs then this ioctl can be used
4735 for issuing platform-specific memory encryption commands to manage those
4738 Currently, this ioctl is used for issuing Secure Encrypted Virtualization
4739 (SEV) commands on AMD Processors. The SEV commands are defined in
4740 Documentation/virt/kvm/x86/amd-memory-encryption.rst.
4742 4.111 KVM_MEMORY_ENCRYPT_REG_REGION
4743 -----------------------------------
4748 :Parameters: struct kvm_enc_region (in)
4749 :Returns: 0 on success; -1 on error
4751 This ioctl can be used to register a guest memory region which may
4752 contain encrypted data (e.g. guest RAM, SMRAM etc).
4754 It is used in the SEV-enabled guest. When encryption is enabled, a guest
4755 memory region may contain encrypted data. The SEV memory encryption
4756 engine uses a tweak such that two identical plaintext pages, each at
4757 different locations will have differing ciphertexts. So swapping or
4758 moving ciphertext of those pages will not result in plaintext being
4759 swapped. So relocating (or migrating) physical backing pages for the SEV
4760 guest will require some additional steps.
4762 Note: The current SEV key management spec does not provide commands to
4763 swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
4764 memory region registered with the ioctl.
4766 4.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
4767 -------------------------------------
4772 :Parameters: struct kvm_enc_region (in)
4773 :Returns: 0 on success; -1 on error
4775 This ioctl can be used to unregister the guest memory region registered
4776 with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
4778 4.113 KVM_HYPERV_EVENTFD
4779 ------------------------
4781 :Capability: KVM_CAP_HYPERV_EVENTFD
4784 :Parameters: struct kvm_hyperv_eventfd (in)
4786 This ioctl (un)registers an eventfd to receive notifications from the guest on
4787 the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
4788 causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
4789 (bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
4793 struct kvm_hyperv_eventfd {
4800 The conn_id field should fit within 24 bits::
4802 #define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
4804 The acceptable values for the flags field are::
4806 #define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
4808 :Returns: 0 on success,
4809 -EINVAL if conn_id or flags is outside the allowed range,
4810 -ENOENT on deassign if the conn_id isn't registered,
4811 -EEXIST on assign if the conn_id is already registered
4813 4.114 KVM_GET_NESTED_STATE
4814 --------------------------
4816 :Capability: KVM_CAP_NESTED_STATE
4819 :Parameters: struct kvm_nested_state (in/out)
4820 :Returns: 0 on success, -1 on error
4824 ===== =============================================================
4825 E2BIG the total state size exceeds the value of 'size' specified by
4826 the user; the size required will be written into size.
4827 ===== =============================================================
4831 struct kvm_nested_state {
4837 struct kvm_vmx_nested_state_hdr vmx;
4838 struct kvm_svm_nested_state_hdr svm;
4840 /* Pad the header to 128 bytes. */
4845 struct kvm_vmx_nested_state_data vmx[0];
4846 struct kvm_svm_nested_state_data svm[0];
4850 #define KVM_STATE_NESTED_GUEST_MODE 0x00000001
4851 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002
4852 #define KVM_STATE_NESTED_EVMCS 0x00000004
4854 #define KVM_STATE_NESTED_FORMAT_VMX 0
4855 #define KVM_STATE_NESTED_FORMAT_SVM 1
4857 #define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000
4859 #define KVM_STATE_NESTED_VMX_SMM_GUEST_MODE 0x00000001
4860 #define KVM_STATE_NESTED_VMX_SMM_VMXON 0x00000002
4862 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001
4864 struct kvm_vmx_nested_state_hdr {
4873 __u64 preemption_timer_deadline;
4876 struct kvm_vmx_nested_state_data {
4877 __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
4878 __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
4881 This ioctl copies the vcpu's nested virtualization state from the kernel to
4884 The maximum size of the state can be retrieved by passing KVM_CAP_NESTED_STATE
4885 to the KVM_CHECK_EXTENSION ioctl().
4887 4.115 KVM_SET_NESTED_STATE
4888 --------------------------
4890 :Capability: KVM_CAP_NESTED_STATE
4893 :Parameters: struct kvm_nested_state (in)
4894 :Returns: 0 on success, -1 on error
4896 This copies the vcpu's kvm_nested_state struct from userspace to the kernel.
4897 For the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
4899 4.116 KVM_(UN)REGISTER_COALESCED_MMIO
4900 -------------------------------------
4902 :Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio)
4903 KVM_CAP_COALESCED_PIO (for coalesced pio)
4906 :Parameters: struct kvm_coalesced_mmio_zone
4907 :Returns: 0 on success, < 0 on error
4909 Coalesced I/O is a performance optimization that defers hardware
4910 register write emulation so that userspace exits are avoided. It is
4911 typically used to reduce the overhead of emulating frequently accessed
4914 When a hardware register is configured for coalesced I/O, write accesses
4915 do not exit to userspace and their value is recorded in a ring buffer
4916 that is shared between kernel and userspace.
4918 Coalesced I/O is used if one or more write accesses to a hardware
4919 register can be deferred until a read or a write to another hardware
4920 register on the same device. This last access will cause a vmexit and
4921 userspace will process accesses from the ring buffer before emulating
4922 it. That will avoid exiting to userspace on repeated writes.
4924 Coalesced pio is based on coalesced mmio. There is little difference
4925 between coalesced mmio and pio except that coalesced pio records accesses
4928 4.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
4929 ------------------------------------
4931 :Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
4932 :Architectures: x86, arm64, mips
4934 :Parameters: struct kvm_clear_dirty_log (in)
4935 :Returns: 0 on success, -1 on error
4939 /* for KVM_CLEAR_DIRTY_LOG */
4940 struct kvm_clear_dirty_log {
4945 void __user *dirty_bitmap; /* one bit per page */
4950 The ioctl clears the dirty status of pages in a memory slot, according to
4951 the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap
4952 field. Bit 0 of the bitmap corresponds to page "first_page" in the
4953 memory slot, and num_pages is the size in bits of the input bitmap.
4954 first_page must be a multiple of 64; num_pages must also be a multiple of
4955 64 unless first_page + num_pages is the size of the memory slot. For each
4956 bit that is set in the input bitmap, the corresponding page is marked "clean"
4957 in KVM's dirty bitmap, and dirty tracking is re-enabled for that page
4958 (for example via write-protection, or by clearing the dirty bit in
4959 a page table entry).
4961 If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
4962 the address space for which you want to clear the dirty status. See
4963 KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
4965 This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
4966 is enabled; for more information, see the description of the capability.
4967 However, it can always be used as long as KVM_CHECK_EXTENSION confirms
4968 that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present.
4970 4.118 KVM_GET_SUPPORTED_HV_CPUID
4971 --------------------------------
4973 :Capability: KVM_CAP_HYPERV_CPUID (vcpu), KVM_CAP_SYS_HYPERV_CPUID (system)
4975 :Type: system ioctl, vcpu ioctl
4976 :Parameters: struct kvm_cpuid2 (in/out)
4977 :Returns: 0 on success, -1 on error
4984 struct kvm_cpuid_entry2 entries[0];
4987 struct kvm_cpuid_entry2 {
4998 This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in
4999 KVM. Userspace can use the information returned by this ioctl to construct
5000 cpuid information presented to guests consuming Hyper-V enlightenments (e.g.
5001 Windows or Hyper-V guests).
5003 CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level
5004 Functional Specification (TLFS). These leaves can't be obtained with
5005 KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature
5006 leaves (0x40000000, 0x40000001).
5008 Currently, the following list of CPUID leaves are returned:
5010 - HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS
5011 - HYPERV_CPUID_INTERFACE
5012 - HYPERV_CPUID_VERSION
5013 - HYPERV_CPUID_FEATURES
5014 - HYPERV_CPUID_ENLIGHTMENT_INFO
5015 - HYPERV_CPUID_IMPLEMENT_LIMITS
5016 - HYPERV_CPUID_NESTED_FEATURES
5017 - HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS
5018 - HYPERV_CPUID_SYNDBG_INTERFACE
5019 - HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES
5021 Userspace invokes KVM_GET_SUPPORTED_HV_CPUID by passing a kvm_cpuid2 structure
5022 with the 'nent' field indicating the number of entries in the variable-size
5023 array 'entries'. If the number of entries is too low to describe all Hyper-V
5024 feature leaves, an error (E2BIG) is returned. If the number is more or equal
5025 to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the
5026 number of valid entries in the 'entries' array, which is then filled.
5028 'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved,
5029 userspace should not expect to get any particular value there.
5031 Note, vcpu version of KVM_GET_SUPPORTED_HV_CPUID is currently deprecated. Unlike
5032 system ioctl which exposes all supported feature bits unconditionally, vcpu
5033 version has the following quirks:
5035 - HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED
5036 feature bit are only exposed when Enlightened VMCS was previously enabled
5037 on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
5038 - HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC.
5039 (presumes KVM_CREATE_IRQCHIP has already been called).
5041 4.119 KVM_ARM_VCPU_FINALIZE
5042 ---------------------------
5044 :Architectures: arm64
5046 :Parameters: int feature (in)
5047 :Returns: 0 on success, -1 on error
5051 ====== ==============================================================
5052 EPERM feature not enabled, needs configuration, or already finalized
5053 EINVAL feature unknown or not present
5054 ====== ==============================================================
5056 Recognised values for feature:
5058 ===== ===========================================
5059 arm64 KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE)
5060 ===== ===========================================
5062 Finalizes the configuration of the specified vcpu feature.
5064 The vcpu must already have been initialised, enabling the affected feature, by
5065 means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in
5068 For affected vcpu features, this is a mandatory step that must be performed
5069 before the vcpu is fully usable.
5071 Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be
5072 configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration
5073 that should be performed and how to do it are feature-dependent.
5075 Other calls that depend on a particular feature being finalized, such as
5076 KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with
5077 -EPERM unless the feature has already been finalized by means of a
5078 KVM_ARM_VCPU_FINALIZE call.
5080 See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization
5083 4.120 KVM_SET_PMU_EVENT_FILTER
5084 ------------------------------
5086 :Capability: KVM_CAP_PMU_EVENT_FILTER
5089 :Parameters: struct kvm_pmu_event_filter (in)
5090 :Returns: 0 on success, -1 on error
5094 ====== ============================================================
5095 EFAULT args[0] cannot be accessed
5096 EINVAL args[0] contains invalid data in the filter or filter events
5097 E2BIG nevents is too large
5098 EBUSY not enough memory to allocate the filter
5099 ====== ============================================================
5103 struct kvm_pmu_event_filter {
5106 __u32 fixed_counter_bitmap;
5112 This ioctl restricts the set of PMU events the guest can program by limiting
5113 which event select and unit mask combinations are permitted.
5115 The argument holds a list of filter events which will be allowed or denied.
5117 Filter events only control general purpose counters; fixed purpose counters
5118 are controlled by the fixed_counter_bitmap.
5120 Valid values for 'flags'::
5124 To use this mode, clear the 'flags' field.
5126 In this mode each event will contain an event select + unit mask.
5128 When the guest attempts to program the PMU the guest's event select +
5129 unit mask is compared against the filter events to determine whether the
5130 guest should have access.
5132 ``KVM_PMU_EVENT_FLAG_MASKED_EVENTS``
5133 :Capability: KVM_CAP_PMU_EVENT_MASKED_EVENTS
5135 In this mode each filter event will contain an event select, mask, match, and
5136 exclude value. To encode a masked event use::
5138 KVM_PMU_ENCODE_MASKED_ENTRY()
5140 An encoded event will follow this layout::
5144 7:0 event select (low bits)
5147 35:32 event select (high bits)
5152 When the guest attempts to program the PMU, these steps are followed in
5153 determining if the guest should have access:
5155 1. Match the event select from the guest against the filter events.
5156 2. If a match is found, match the guest's unit mask to the mask and match
5157 values of the included filter events.
5158 I.e. (unit mask & mask) == match && !exclude.
5159 3. If a match is found, match the guest's unit mask to the mask and match
5160 values of the excluded filter events.
5161 I.e. (unit mask & mask) == match && exclude.
5163 a. If an included match is found and an excluded match is not found, filter
5165 b. For everything else, do not filter the event.
5167 a. If the event is filtered and it's an allow list, allow the guest to
5169 b. If the event is filtered and it's a deny list, do not allow the guest to
5172 When setting a new pmu event filter, -EINVAL will be returned if any of the
5173 unused fields are set or if any of the high bits (35:32) in the event
5174 select are set when called on Intel.
5176 Valid values for 'action'::
5178 #define KVM_PMU_EVENT_ALLOW 0
5179 #define KVM_PMU_EVENT_DENY 1
5181 Via this API, KVM userspace can also control the behavior of the VM's fixed
5182 counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields.
5184 Specifically, KVM follows the following pseudo-code when determining whether to
5185 allow the guest FixCtr[i] to count its pre-defined fixed event::
5187 FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
5188 (action == DENY) && !(bitmap & BIT(i));
5189 FixCtr[i]_is_denied = !FixCtr[i]_is_allowed;
5191 KVM always consumes fixed_counter_bitmap, it's userspace's responsibility to
5192 ensure fixed_counter_bitmap is set correctly, e.g. if userspace wants to define
5193 a filter that only affects general purpose counters.
5195 Note, the "events" field also applies to fixed counters' hardcoded event_select
5196 and unit_mask values. "fixed_counter_bitmap" has higher priority than "events"
5197 if there is a contradiction between the two.
5199 4.121 KVM_PPC_SVM_OFF
5200 ---------------------
5203 :Architectures: powerpc
5206 :Returns: 0 on successful completion,
5210 ====== ================================================================
5211 EINVAL if ultravisor failed to terminate the secure guest
5212 ENOMEM if hypervisor failed to allocate new radix page tables for guest
5213 ====== ================================================================
5215 This ioctl is used to turn off the secure mode of the guest or transition
5216 the guest from secure mode to normal mode. This is invoked when the guest
5217 is reset. This has no effect if called for a normal guest.
5219 This ioctl issues an ultravisor call to terminate the secure guest,
5220 unpins the VPA pages and releases all the device pages that are used to
5221 track the secure pages by hypervisor.
5223 4.122 KVM_S390_NORMAL_RESET
5224 ---------------------------
5226 :Capability: KVM_CAP_S390_VCPU_RESETS
5227 :Architectures: s390
5232 This ioctl resets VCPU registers and control structures according to
5233 the cpu reset definition in the POP (Principles Of Operation).
5235 4.123 KVM_S390_INITIAL_RESET
5236 ----------------------------
5239 :Architectures: s390
5244 This ioctl resets VCPU registers and control structures according to
5245 the initial cpu reset definition in the POP. However, the cpu is not
5246 put into ESA mode. This reset is a superset of the normal reset.
5248 4.124 KVM_S390_CLEAR_RESET
5249 --------------------------
5251 :Capability: KVM_CAP_S390_VCPU_RESETS
5252 :Architectures: s390
5257 This ioctl resets VCPU registers and control structures according to
5258 the clear cpu reset definition in the POP. However, the cpu is not put
5259 into ESA mode. This reset is a superset of the initial reset.
5262 4.125 KVM_S390_PV_COMMAND
5263 -------------------------
5265 :Capability: KVM_CAP_S390_PROTECTED
5266 :Architectures: s390
5268 :Parameters: struct kvm_pv_cmd
5269 :Returns: 0 on success, < 0 on error
5274 __u32 cmd; /* Command to be executed */
5275 __u16 rc; /* Ultravisor return code */
5276 __u16 rrc; /* Ultravisor return reason code */
5277 __u64 data; /* Data or address */
5278 __u32 flags; /* flags for future extensions. Must be 0 for now */
5282 **Ultravisor return codes**
5283 The Ultravisor return (reason) codes are provided by the kernel if a
5284 Ultravisor call has been executed to achieve the results expected by
5285 the command. Therefore they are independent of the IOCTL return
5286 code. If KVM changes `rc`, its value will always be greater than 0
5287 hence setting it to 0 before issuing a PV command is advised to be
5288 able to detect a change of `rc`.
5293 Allocate memory and register the VM with the Ultravisor, thereby
5294 donating memory to the Ultravisor that will become inaccessible to
5295 KVM. All existing CPUs are converted to protected ones. After this
5296 command has succeeded, any CPU added via hotplug will become
5297 protected during its creation as well.
5301 ===== =============================
5302 EINTR an unmasked signal is pending
5303 ===== =============================
5306 Deregister the VM from the Ultravisor and reclaim the memory that had
5307 been donated to the Ultravisor, making it usable by the kernel again.
5308 All registered VCPUs are converted back to non-protected ones. If a
5309 previous protected VM had been prepared for asynchronous teardown with
5310 KVM_PV_ASYNC_CLEANUP_PREPARE and not subsequently torn down with
5311 KVM_PV_ASYNC_CLEANUP_PERFORM, it will be torn down in this call
5312 together with the current protected VM.
5314 KVM_PV_VM_SET_SEC_PARMS
5315 Pass the image header from VM memory to the Ultravisor in
5316 preparation of image unpacking and verification.
5319 Unpack (protect and decrypt) a page of the encrypted boot image.
5322 Verify the integrity of the unpacked image. Only if this succeeds,
5323 KVM is allowed to start protected VCPUs.
5326 :Capability: KVM_CAP_S390_PROTECTED_DUMP
5328 Presents an API that provides Ultravisor related data to userspace
5329 via subcommands. len_max is the size of the user space buffer,
5330 len_written is KVM's indication of how much bytes of that buffer
5331 were actually written to. len_written can be used to determine the
5332 valid fields if more response fields are added in the future.
5336 enum pv_cmd_info_id {
5341 struct kvm_s390_pv_info_header {
5348 struct kvm_s390_pv_info {
5349 struct kvm_s390_pv_info_header header;
5350 struct kvm_s390_pv_info_dump dump;
5351 struct kvm_s390_pv_info_vm vm;
5357 This subcommand provides basic Ultravisor information for PV
5358 hosts. These values are likely also exported as files in the sysfs
5359 firmware UV query interface but they are more easily available to
5360 programs in this API.
5362 The installed calls and feature_indication members provide the
5363 installed UV calls and the UV's other feature indications.
5365 The max_* members provide information about the maximum number of PV
5366 vcpus, PV guests and PV guest memory size.
5370 struct kvm_s390_pv_info_vm {
5371 __u64 inst_calls_list[4];
5374 __u64 max_guest_addr;
5375 __u64 feature_indication;
5380 This subcommand provides information related to dumping PV guests.
5384 struct kvm_s390_pv_info_dump {
5385 __u64 dump_cpu_buffer_len;
5386 __u64 dump_config_mem_buffer_per_1m;
5387 __u64 dump_config_finalize_len;
5391 :Capability: KVM_CAP_S390_PROTECTED_DUMP
5393 Presents an API that provides calls which facilitate dumping a
5398 struct kvm_s390_pv_dmp {
5402 __u64 gaddr; /* For dump storage state */
5408 Initializes the dump process of a protected VM. If this call does
5409 not succeed all other subcommands will fail with -EINVAL. This
5410 subcommand will return -EINVAL if a dump process has not yet been
5413 Not all PV vms can be dumped, the owner needs to set `dump
5414 allowed` PCF bit 34 in the SE header to allow dumping.
5416 KVM_PV_DUMP_CONFIG_STOR_STATE
5417 Stores `buff_len` bytes of tweak component values starting with
5418 the 1MB block specified by the absolute guest address
5419 (`gaddr`). `buff_len` needs to be `conf_dump_storage_state_len`
5420 aligned and at least >= the `conf_dump_storage_state_len` value
5421 provided by the dump uv_info data. buff_user might be written to
5422 even if an error rc is returned. For instance if we encounter a
5423 fault after writing the first page of data.
5425 KVM_PV_DUMP_COMPLETE
5426 If the subcommand succeeds it completes the dump process and lets
5427 KVM_PV_DUMP_INIT be called again.
5429 On success `conf_dump_finalize_len` bytes of completion data will be
5430 stored to the `buff_addr`. The completion data contains a key
5431 derivation seed, IV, tweak nonce and encryption keys as well as an
5432 authentication tag all of which are needed to decrypt the dump at a
5435 KVM_PV_ASYNC_CLEANUP_PREPARE
5436 :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE
5438 Prepare the current protected VM for asynchronous teardown. Most
5439 resources used by the current protected VM will be set aside for a
5440 subsequent asynchronous teardown. The current protected VM will then
5441 resume execution immediately as non-protected. There can be at most
5442 one protected VM prepared for asynchronous teardown at any time. If
5443 a protected VM had already been prepared for teardown without
5444 subsequently calling KVM_PV_ASYNC_CLEANUP_PERFORM, this call will
5445 fail. In that case, the userspace process should issue a normal
5446 KVM_PV_DISABLE. The resources set aside with this call will need to
5447 be cleaned up with a subsequent call to KVM_PV_ASYNC_CLEANUP_PERFORM
5448 or KVM_PV_DISABLE, otherwise they will be cleaned up when KVM
5449 terminates. KVM_PV_ASYNC_CLEANUP_PREPARE can be called again as soon
5450 as cleanup starts, i.e. before KVM_PV_ASYNC_CLEANUP_PERFORM finishes.
5452 KVM_PV_ASYNC_CLEANUP_PERFORM
5453 :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE
5455 Tear down the protected VM previously prepared for teardown with
5456 KVM_PV_ASYNC_CLEANUP_PREPARE. The resources that had been set aside
5457 will be freed during the execution of this command. This PV command
5458 should ideally be issued by userspace from a separate thread. If a
5459 fatal signal is received (or the process terminates naturally), the
5460 command will terminate immediately without completing, and the normal
5461 KVM shutdown procedure will take care of cleaning up all remaining
5462 protected VMs, including the ones whose teardown was interrupted by
5463 process termination.
5465 4.126 KVM_XEN_HVM_SET_ATTR
5466 --------------------------
5468 :Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5471 :Parameters: struct kvm_xen_hvm_attr
5472 :Returns: 0 on success, < 0 on error
5476 struct kvm_xen_hvm_attr {
5482 __u8 runstate_update_flag;
5488 __u32 type; /* EVTCHNSTAT_ipi / EVTCHNSTAT_interdomain */
5497 __u32 port; /* Zero for eventfd */
5510 KVM_XEN_ATTR_TYPE_LONG_MODE
5511 Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This
5512 determines the layout of the shared info pages exposed to the VM.
5514 KVM_XEN_ATTR_TYPE_SHARED_INFO
5515 Sets the guest physical frame number at which the Xen "shared info"
5516 page resides. Note that although Xen places vcpu_info for the first
5517 32 vCPUs in the shared_info page, KVM does not automatically do so
5518 and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
5519 explicitly even when the vcpu_info for a given vCPU resides at the
5520 "default" location in the shared_info page. This is because KVM may
5521 not be aware of the Xen CPU id which is used as the index into the
5522 vcpu_info[] array, so may know the correct default location.
5524 Note that the shared info page may be constantly written to by KVM;
5525 it contains the event channel bitmap used to deliver interrupts to
5526 a Xen guest, amongst other things. It is exempt from dirty tracking
5527 mechanisms — KVM will not explicitly mark the page as dirty each
5528 time an event channel interrupt is delivered to the guest! Thus,
5529 userspace should always assume that the designated GFN is dirty if
5530 any vCPU has been running or any event channel interrupts can be
5531 routed to the guest.
5533 Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared info
5536 KVM_XEN_ATTR_TYPE_UPCALL_VECTOR
5537 Sets the exception vector used to deliver Xen event channel upcalls.
5538 This is the HVM-wide vector injected directly by the hypervisor
5539 (not through the local APIC), typically configured by a guest via
5540 HVM_PARAM_CALLBACK_IRQ. This can be disabled again (e.g. for guest
5541 SHUTDOWN_soft_reset) by setting it to zero.
5543 KVM_XEN_ATTR_TYPE_EVTCHN
5544 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5545 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It configures
5546 an outbound port number for interception of EVTCHNOP_send requests
5547 from the guest. A given sending port number may be directed back to
5548 a specified vCPU (by APIC ID) / port / priority on the guest, or to
5549 trigger events on an eventfd. The vCPU and priority can be changed
5550 by setting KVM_XEN_EVTCHN_UPDATE in a subsequent call, but other
5551 fields cannot change for a given sending port. A port mapping is
5552 removed by using KVM_XEN_EVTCHN_DEASSIGN in the flags field. Passing
5553 KVM_XEN_EVTCHN_RESET in the flags field removes all interception of
5554 outbound event channels. The values of the flags field are mutually
5555 exclusive and cannot be combined as a bitmask.
5557 KVM_XEN_ATTR_TYPE_XEN_VERSION
5558 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5559 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It configures
5560 the 32-bit version code returned to the guest when it invokes the
5561 XENVER_version call; typically (XEN_MAJOR << 16 | XEN_MINOR). PV
5562 Xen guests will often use this to as a dummy hypercall to trigger
5563 event channel delivery, so responding within the kernel without
5564 exiting to userspace is beneficial.
5566 KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG
5567 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5568 support for KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG. It enables the
5569 XEN_RUNSTATE_UPDATE flag which allows guest vCPUs to safely read
5570 other vCPUs' vcpu_runstate_info. Xen guests enable this feature via
5571 the VMASST_TYPE_runstate_update_flag of the HYPERVISOR_vm_assist
5574 4.127 KVM_XEN_HVM_GET_ATTR
5575 --------------------------
5577 :Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5580 :Parameters: struct kvm_xen_hvm_attr
5581 :Returns: 0 on success, < 0 on error
5583 Allows Xen VM attributes to be read. For the structure and types,
5584 see KVM_XEN_HVM_SET_ATTR above. The KVM_XEN_ATTR_TYPE_EVTCHN
5585 attribute cannot be read.
5587 4.128 KVM_XEN_VCPU_SET_ATTR
5588 ---------------------------
5590 :Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5593 :Parameters: struct kvm_xen_vcpu_attr
5594 :Returns: 0 on success, < 0 on error
5598 struct kvm_xen_vcpu_attr {
5606 __u64 state_entry_time;
5608 __u64 time_runnable;
5624 KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
5625 Sets the guest physical address of the vcpu_info for a given vCPU.
5626 As with the shared_info page for the VM, the corresponding page may be
5627 dirtied at any time if event channel interrupt delivery is enabled, so
5628 userspace should always assume that the page is dirty without relying
5629 on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable
5632 KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
5633 Sets the guest physical address of an additional pvclock structure
5634 for a given vCPU. This is typically used for guest vsyscall support.
5635 Setting the gpa to KVM_XEN_INVALID_GPA will disable the structure.
5637 KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR
5638 Sets the guest physical address of the vcpu_runstate_info for a given
5639 vCPU. This is how a Xen guest tracks CPU state such as steal time.
5640 Setting the gpa to KVM_XEN_INVALID_GPA will disable the runstate area.
5642 KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT
5643 Sets the runstate (RUNSTATE_running/_runnable/_blocked/_offline) of
5644 the given vCPU from the .u.runstate.state member of the structure.
5645 KVM automatically accounts running and runnable time but blocked
5646 and offline states are only entered explicitly.
5648 KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA
5649 Sets all fields of the vCPU runstate data from the .u.runstate member
5650 of the structure, including the current runstate. The state_entry_time
5651 must equal the sum of the other four times.
5653 KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST
5654 This *adds* the contents of the .u.runstate members of the structure
5655 to the corresponding members of the given vCPU's runstate data, thus
5656 permitting atomic adjustments to the runstate times. The adjustment
5657 to the state_entry_time must equal the sum of the adjustments to the
5658 other four times. The state field must be set to -1, or to a valid
5659 runstate value (RUNSTATE_running, RUNSTATE_runnable, RUNSTATE_blocked
5660 or RUNSTATE_offline) to set the current accounted state as of the
5661 adjusted state_entry_time.
5663 KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID
5664 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5665 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the Xen
5666 vCPU ID of the given vCPU, to allow timer-related VCPU operations to
5667 be intercepted by KVM.
5669 KVM_XEN_VCPU_ATTR_TYPE_TIMER
5670 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5671 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the
5672 event channel port/priority for the VIRQ_TIMER of the vCPU, as well
5673 as allowing a pending timer to be saved/restored. Setting the timer
5674 port to zero disables kernel handling of the singleshot timer.
5676 KVM_XEN_VCPU_ATTR_TYPE_UPCALL_VECTOR
5677 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5678 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the
5679 per-vCPU local APIC upcall vector, configured by a Xen guest with
5680 the HVMOP_set_evtchn_upcall_vector hypercall. This is typically
5681 used by Windows guests, and is distinct from the HVM-wide upcall
5682 vector configured with HVM_PARAM_CALLBACK_IRQ. It is disabled by
5683 setting the vector to zero.
5686 4.129 KVM_XEN_VCPU_GET_ATTR
5687 ---------------------------
5689 :Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5692 :Parameters: struct kvm_xen_vcpu_attr
5693 :Returns: 0 on success, < 0 on error
5695 Allows Xen vCPU attributes to be read. For the structure and types,
5696 see KVM_XEN_VCPU_SET_ATTR above.
5698 The KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST type may not be used
5699 with the KVM_XEN_VCPU_GET_ATTR ioctl.
5701 4.130 KVM_ARM_MTE_COPY_TAGS
5702 ---------------------------
5704 :Capability: KVM_CAP_ARM_MTE
5705 :Architectures: arm64
5707 :Parameters: struct kvm_arm_copy_mte_tags
5708 :Returns: number of bytes copied, < 0 on error (-EINVAL for incorrect
5709 arguments, -EFAULT if memory cannot be accessed).
5713 struct kvm_arm_copy_mte_tags {
5721 Copies Memory Tagging Extension (MTE) tags to/from guest tag memory. The
5722 ``guest_ipa`` and ``length`` fields must be ``PAGE_SIZE`` aligned.
5723 ``length`` must not be bigger than 2^31 - PAGE_SIZE bytes. The ``addr``
5724 field must point to a buffer which the tags will be copied to or from.
5726 ``flags`` specifies the direction of copy, either ``KVM_ARM_TAGS_TO_GUEST`` or
5727 ``KVM_ARM_TAGS_FROM_GUEST``.
5729 The size of the buffer to store the tags is ``(length / 16)`` bytes
5730 (granules in MTE are 16 bytes long). Each byte contains a single tag
5731 value. This matches the format of ``PTRACE_PEEKMTETAGS`` and
5732 ``PTRACE_POKEMTETAGS``.
5734 If an error occurs before any data is copied then a negative error code is
5735 returned. If some tags have been copied before an error occurs then the number
5736 of bytes successfully copied is returned. If the call completes successfully
5737 then ``length`` is returned.
5739 4.131 KVM_GET_SREGS2
5740 --------------------
5742 :Capability: KVM_CAP_SREGS2
5745 :Parameters: struct kvm_sregs2 (out)
5746 :Returns: 0 on success, -1 on error
5748 Reads special registers from the vcpu.
5749 This ioctl (when supported) replaces the KVM_GET_SREGS.
5754 /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */
5755 struct kvm_segment cs, ds, es, fs, gs, ss;
5756 struct kvm_segment tr, ldt;
5757 struct kvm_dtable gdt, idt;
5758 __u64 cr0, cr2, cr3, cr4, cr8;
5765 flags values for ``kvm_sregs2``:
5767 ``KVM_SREGS2_FLAGS_PDPTRS_VALID``
5769 Indicates that the struct contains valid PDPTR values.
5772 4.132 KVM_SET_SREGS2
5773 --------------------
5775 :Capability: KVM_CAP_SREGS2
5778 :Parameters: struct kvm_sregs2 (in)
5779 :Returns: 0 on success, -1 on error
5781 Writes special registers into the vcpu.
5782 See KVM_GET_SREGS2 for the data structures.
5783 This ioctl (when supported) replaces the KVM_SET_SREGS.
5785 4.133 KVM_GET_STATS_FD
5786 ----------------------
5788 :Capability: KVM_CAP_STATS_BINARY_FD
5790 :Type: vm ioctl, vcpu ioctl
5792 :Returns: statistics file descriptor on success, < 0 on error
5796 ====== ======================================================
5797 ENOMEM if the fd could not be created due to lack of memory
5798 EMFILE if the number of opened files exceeds the limit
5799 ====== ======================================================
5801 The returned file descriptor can be used to read VM/vCPU statistics data in
5802 binary format. The data in the file descriptor consists of four blocks
5803 organized as follows:
5815 Apart from the header starting at offset 0, please be aware that it is
5816 not guaranteed that the four blocks are adjacent or in the above order;
5817 the offsets of the id, descriptors and data blocks are found in the
5818 header. However, all four blocks are aligned to 64 bit offsets in the
5819 file and they do not overlap.
5821 All blocks except the data block are immutable. Userspace can read them
5822 only one time after retrieving the file descriptor, and then use ``pread`` or
5823 ``lseek`` to read the statistics repeatedly.
5825 All data is in system endianness.
5827 The format of the header is as follows::
5829 struct kvm_stats_header {
5838 The ``flags`` field is not used at the moment. It is always read as 0.
5840 The ``name_size`` field is the size (in byte) of the statistics name string
5841 (including trailing '\0') which is contained in the "id string" block and
5842 appended at the end of every descriptor.
5844 The ``num_desc`` field is the number of descriptors that are included in the
5845 descriptor block. (The actual number of values in the data block may be
5846 larger, since each descriptor may comprise more than one value).
5848 The ``id_offset`` field is the offset of the id string from the start of the
5849 file indicated by the file descriptor. It is a multiple of 8.
5851 The ``desc_offset`` field is the offset of the Descriptors block from the start
5852 of the file indicated by the file descriptor. It is a multiple of 8.
5854 The ``data_offset`` field is the offset of the Stats Data block from the start
5855 of the file indicated by the file descriptor. It is a multiple of 8.
5857 The id string block contains a string which identifies the file descriptor on
5858 which KVM_GET_STATS_FD was invoked. The size of the block, including the
5859 trailing ``'\0'``, is indicated by the ``name_size`` field in the header.
5861 The descriptors block is only needed to be read once for the lifetime of the
5862 file descriptor contains a sequence of ``struct kvm_stats_desc``, each followed
5863 by a string of size ``name_size``.
5866 #define KVM_STATS_TYPE_SHIFT 0
5867 #define KVM_STATS_TYPE_MASK (0xF << KVM_STATS_TYPE_SHIFT)
5868 #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT)
5869 #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT)
5870 #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT)
5871 #define KVM_STATS_TYPE_LINEAR_HIST (0x3 << KVM_STATS_TYPE_SHIFT)
5872 #define KVM_STATS_TYPE_LOG_HIST (0x4 << KVM_STATS_TYPE_SHIFT)
5873 #define KVM_STATS_TYPE_MAX KVM_STATS_TYPE_LOG_HIST
5875 #define KVM_STATS_UNIT_SHIFT 4
5876 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT)
5877 #define KVM_STATS_UNIT_NONE (0x0 << KVM_STATS_UNIT_SHIFT)
5878 #define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT)
5879 #define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT)
5880 #define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT)
5881 #define KVM_STATS_UNIT_BOOLEAN (0x4 << KVM_STATS_UNIT_SHIFT)
5882 #define KVM_STATS_UNIT_MAX KVM_STATS_UNIT_BOOLEAN
5884 #define KVM_STATS_BASE_SHIFT 8
5885 #define KVM_STATS_BASE_MASK (0xF << KVM_STATS_BASE_SHIFT)
5886 #define KVM_STATS_BASE_POW10 (0x0 << KVM_STATS_BASE_SHIFT)
5887 #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT)
5888 #define KVM_STATS_BASE_MAX KVM_STATS_BASE_POW2
5890 struct kvm_stats_desc {
5899 The ``flags`` field contains the type and unit of the statistics data described
5900 by this descriptor. Its endianness is CPU native.
5901 The following flags are supported:
5903 Bits 0-3 of ``flags`` encode the type:
5905 * ``KVM_STATS_TYPE_CUMULATIVE``
5906 The statistics reports a cumulative count. The value of data can only be increased.
5907 Most of the counters used in KVM are of this type.
5908 The corresponding ``size`` field for this type is always 1.
5909 All cumulative statistics data are read/write.
5910 * ``KVM_STATS_TYPE_INSTANT``
5911 The statistics reports an instantaneous value. Its value can be increased or
5912 decreased. This type is usually used as a measurement of some resources,
5913 like the number of dirty pages, the number of large pages, etc.
5914 All instant statistics are read only.
5915 The corresponding ``size`` field for this type is always 1.
5916 * ``KVM_STATS_TYPE_PEAK``
5917 The statistics data reports a peak value, for example the maximum number
5918 of items in a hash table bucket, the longest time waited and so on.
5919 The value of data can only be increased.
5920 The corresponding ``size`` field for this type is always 1.
5921 * ``KVM_STATS_TYPE_LINEAR_HIST``
5922 The statistic is reported as a linear histogram. The number of
5923 buckets is specified by the ``size`` field. The size of buckets is specified
5924 by the ``hist_param`` field. The range of the Nth bucket (1 <= N < ``size``)
5925 is [``hist_param``*(N-1), ``hist_param``*N), while the range of the last
5926 bucket is [``hist_param``*(``size``-1), +INF). (+INF means positive infinity
5928 * ``KVM_STATS_TYPE_LOG_HIST``
5929 The statistic is reported as a logarithmic histogram. The number of
5930 buckets is specified by the ``size`` field. The range of the first bucket is
5931 [0, 1), while the range of the last bucket is [pow(2, ``size``-2), +INF).
5932 Otherwise, The Nth bucket (1 < N < ``size``) covers
5933 [pow(2, N-2), pow(2, N-1)).
5935 Bits 4-7 of ``flags`` encode the unit:
5937 * ``KVM_STATS_UNIT_NONE``
5938 There is no unit for the value of statistics data. This usually means that
5939 the value is a simple counter of an event.
5940 * ``KVM_STATS_UNIT_BYTES``
5941 It indicates that the statistics data is used to measure memory size, in the
5942 unit of Byte, KiByte, MiByte, GiByte, etc. The unit of the data is
5943 determined by the ``exponent`` field in the descriptor.
5944 * ``KVM_STATS_UNIT_SECONDS``
5945 It indicates that the statistics data is used to measure time or latency.
5946 * ``KVM_STATS_UNIT_CYCLES``
5947 It indicates that the statistics data is used to measure CPU clock cycles.
5948 * ``KVM_STATS_UNIT_BOOLEAN``
5949 It indicates that the statistic will always be either 0 or 1. Boolean
5950 statistics of "peak" type will never go back from 1 to 0. Boolean
5951 statistics can be linear histograms (with two buckets) but not logarithmic
5954 Note that, in the case of histograms, the unit applies to the bucket
5955 ranges, while the bucket value indicates how many samples fell in the
5958 Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the
5961 * ``KVM_STATS_BASE_POW10``
5962 The scale is based on power of 10. It is used for measurement of time and
5963 CPU clock cycles. For example, an exponent of -9 can be used with
5964 ``KVM_STATS_UNIT_SECONDS`` to express that the unit is nanoseconds.
5965 * ``KVM_STATS_BASE_POW2``
5966 The scale is based on power of 2. It is used for measurement of memory size.
5967 For example, an exponent of 20 can be used with ``KVM_STATS_UNIT_BYTES`` to
5968 express that the unit is MiB.
5970 The ``size`` field is the number of values of this statistics data. Its
5971 value is usually 1 for most of simple statistics. 1 means it contains an
5972 unsigned 64bit data.
5974 The ``offset`` field is the offset from the start of Data Block to the start of
5975 the corresponding statistics data.
5977 The ``bucket_size`` field is used as a parameter for histogram statistics data.
5978 It is only used by linear histogram statistics data, specifying the size of a
5979 bucket in the unit expressed by bits 4-11 of ``flags`` together with ``exponent``.
5981 The ``name`` field is the name string of the statistics data. The name string
5982 starts at the end of ``struct kvm_stats_desc``. The maximum length including
5983 the trailing ``'\0'``, is indicated by ``name_size`` in the header.
5985 The Stats Data block contains an array of 64-bit values in the same order
5986 as the descriptors in Descriptors block.
5988 4.134 KVM_GET_XSAVE2
5989 --------------------
5991 :Capability: KVM_CAP_XSAVE2
5994 :Parameters: struct kvm_xsave (out)
5995 :Returns: 0 on success, -1 on error
6005 This ioctl would copy current vcpu's xsave struct to the userspace. It
6006 copies as many bytes as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2)
6007 when invoked on the vm file descriptor. The size value returned by
6008 KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) will always be at least 4096.
6009 Currently, it is only greater than 4096 if a dynamic feature has been
6010 enabled with ``arch_prctl()``, but this may change in the future.
6012 The offsets of the state save areas in struct kvm_xsave follow the contents
6013 of CPUID leaf 0xD on the host.
6015 4.135 KVM_XEN_HVM_EVTCHN_SEND
6016 -----------------------------
6018 :Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND
6021 :Parameters: struct kvm_irq_routing_xen_evtchn
6022 :Returns: 0 on success, < 0 on error
6027 struct kvm_irq_routing_xen_evtchn {
6033 This ioctl injects an event channel interrupt directly to the guest vCPU.
6035 4.136 KVM_S390_PV_CPU_COMMAND
6036 -----------------------------
6038 :Capability: KVM_CAP_S390_PROTECTED_DUMP
6039 :Architectures: s390
6042 :Returns: 0 on success, < 0 on error
6044 This ioctl closely mirrors `KVM_S390_PV_COMMAND` but handles requests
6045 for vcpus. It re-uses the kvm_s390_pv_dmp struct and hence also shares
6051 Presents an API that provides calls which facilitate dumping a vcpu
6057 Provides encrypted dump data like register values.
6058 The length of the returned data is provided by uv_info.guest_cpu_stor_len.
6060 4.137 KVM_S390_ZPCI_OP
6061 ----------------------
6063 :Capability: KVM_CAP_S390_ZPCI_OP
6064 :Architectures: s390
6066 :Parameters: struct kvm_s390_zpci_op (in)
6067 :Returns: 0 on success, <0 on error
6069 Used to manage hardware-assisted virtualization features for zPCI devices.
6071 Parameters are specified via the following structure::
6073 struct kvm_s390_zpci_op {
6075 __u32 fh; /* target device */
6076 __u8 op; /* operation to perform */
6079 /* for KVM_S390_ZPCIOP_REG_AEN */
6081 __u64 ibv; /* Guest addr of interrupt bit vector */
6082 __u64 sb; /* Guest addr of summary bit */
6084 __u32 noi; /* Number of interrupts */
6085 __u8 isc; /* Guest interrupt subclass */
6086 __u8 sbo; /* Offset of guest summary bit vector */
6093 The type of operation is specified in the "op" field.
6094 KVM_S390_ZPCIOP_REG_AEN is used to register the VM for adapter event
6095 notification interpretation, which will allow firmware delivery of adapter
6096 events directly to the vm, with KVM providing a backup delivery mechanism;
6097 KVM_S390_ZPCIOP_DEREG_AEN is used to subsequently disable interpretation of
6098 adapter event notifications.
6100 The target zPCI function must also be specified via the "fh" field. For the
6101 KVM_S390_ZPCIOP_REG_AEN operation, additional information to establish firmware
6102 delivery must be provided via the "reg_aen" struct.
6104 The "pad" and "reserved" fields may be used for future extensions and should be
6105 set to 0s by userspace.
6107 4.138 KVM_ARM_SET_COUNTER_OFFSET
6108 --------------------------------
6110 :Capability: KVM_CAP_COUNTER_OFFSET
6111 :Architectures: arm64
6113 :Parameters: struct kvm_arm_counter_offset (in)
6114 :Returns: 0 on success, < 0 on error
6116 This capability indicates that userspace is able to apply a single VM-wide
6117 offset to both the virtual and physical counters as viewed by the guest
6118 using the KVM_ARM_SET_CNT_OFFSET ioctl and the following data structure:
6122 struct kvm_arm_counter_offset {
6123 __u64 counter_offset;
6127 The offset describes a number of counter cycles that are subtracted from
6128 both virtual and physical counter views (similar to the effects of the
6129 CNTVOFF_EL2 and CNTPOFF_EL2 system registers, but only global). The offset
6130 always applies to all vcpus (already created or created after this ioctl)
6133 It is userspace's responsibility to compute the offset based, for example,
6134 on previous values of the guest counters.
6136 Any value other than 0 for the "reserved" field may result in an error
6137 (-EINVAL) being returned. This ioctl can also return -EBUSY if any vcpu
6138 ioctl is issued concurrently.
6140 Note that using this ioctl results in KVM ignoring subsequent userspace
6141 writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG
6142 interface. No error will be returned, but the resulting offset will not be
6145 .. _KVM_ARM_GET_REG_WRITABLE_MASKS:
6147 4.139 KVM_ARM_GET_REG_WRITABLE_MASKS
6148 -------------------------------------------
6150 :Capability: KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES
6151 :Architectures: arm64
6153 :Parameters: struct reg_mask_range (in/out)
6154 :Returns: 0 on success, < 0 on error
6159 #define KVM_ARM_FEATURE_ID_RANGE 0
6160 #define KVM_ARM_FEATURE_ID_RANGE_SIZE (3 * 8 * 8)
6162 struct reg_mask_range {
6163 __u64 addr; /* Pointer to mask array */
6164 __u32 range; /* Requested range */
6168 This ioctl copies the writable masks for a selected range of registers to
6171 The ``addr`` field is a pointer to the destination array where KVM copies
6174 The ``range`` field indicates the requested range of registers.
6175 ``KVM_CHECK_EXTENSION`` for the ``KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES``
6176 capability returns the supported ranges, expressed as a set of flags. Each
6177 flag's bit index represents a possible value for the ``range`` field.
6178 All other values are reserved for future use and KVM may return an error.
6180 The ``reserved[13]`` array is reserved for future use and should be 0, or
6181 KVM may return an error.
6183 KVM_ARM_FEATURE_ID_RANGE (0)
6184 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6186 The Feature ID range is defined as the AArch64 System register space with
6187 op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.
6189 The mask returned array pointed to by ``addr`` is indexed by the macro
6190 ``ARM64_FEATURE_ID_RANGE_IDX(op0, op1, crn, crm, op2)``, allowing userspace
6191 to know what fields can be changed for the system register described by
6192 ``op0, op1, crn, crm, op2``. KVM rejects ID register values that describe a
6193 superset of the features supported by the system.
6195 5. The kvm_run structure
6196 ========================
6198 Application code obtains a pointer to the kvm_run structure by
6199 mmap()ing a vcpu fd. From that point, application code can control
6200 execution by changing fields in kvm_run prior to calling the KVM_RUN
6201 ioctl, and obtain information about the reason KVM_RUN returned by
6202 looking up structure members.
6208 __u8 request_interrupt_window;
6210 Request that KVM_RUN return when it becomes possible to inject external
6211 interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
6215 __u8 immediate_exit;
6217 This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
6218 exits immediately, returning -EINTR. In the common scenario where a
6219 signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
6220 to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
6221 Rather than blocking the signal outside KVM_RUN, userspace can set up
6222 a signal handler that sets run->immediate_exit to a non-zero value.
6224 This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
6233 When KVM_RUN has returned successfully (return value 0), this informs
6234 application code why KVM_RUN has returned. Allowable values for this
6235 field are detailed below.
6239 __u8 ready_for_interrupt_injection;
6241 If request_interrupt_window has been specified, this field indicates
6242 an interrupt can be injected now with KVM_INTERRUPT.
6248 The value of the current interrupt flag. Only valid if in-kernel
6249 local APIC is not used.
6255 More architecture-specific flags detailing state of the VCPU that may
6256 affect the device's behavior. Current defined flags::
6258 /* x86, set if the VCPU is in system management mode */
6259 #define KVM_RUN_X86_SMM (1 << 0)
6260 /* x86, set if bus lock detected in VM */
6261 #define KVM_RUN_BUS_LOCK (1 << 1)
6262 /* arm64, set for KVM_EXIT_DEBUG */
6263 #define KVM_DEBUG_ARCH_HSR_HIGH_VALID (1 << 0)
6267 /* in (pre_kvm_run), out (post_kvm_run) */
6270 The value of the cr8 register. Only valid if in-kernel local APIC is
6271 not used. Both input and output.
6277 The value of the APIC BASE msr. Only valid if in-kernel local
6278 APIC is not used. Both input and output.
6283 /* KVM_EXIT_UNKNOWN */
6285 __u64 hardware_exit_reason;
6288 If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
6289 reasons. Further architecture-specific information is available in
6290 hardware_exit_reason.
6294 /* KVM_EXIT_FAIL_ENTRY */
6296 __u64 hardware_entry_failure_reason;
6297 __u32 cpu; /* if KVM_LAST_CPU */
6300 If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
6301 to unknown reasons. Further architecture-specific information is
6302 available in hardware_entry_failure_reason.
6306 /* KVM_EXIT_EXCEPTION */
6318 #define KVM_EXIT_IO_IN 0
6319 #define KVM_EXIT_IO_OUT 1
6321 __u8 size; /* bytes */
6324 __u64 data_offset; /* relative to kvm_run start */
6327 If exit_reason is KVM_EXIT_IO, then the vcpu has
6328 executed a port I/O instruction which could not be satisfied by kvm.
6329 data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
6330 where kvm expects application code to place the data for the next
6331 KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
6335 /* KVM_EXIT_DEBUG */
6337 struct kvm_debug_exit_arch arch;
6340 If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
6341 for which architecture specific information is returned.
6353 If exit_reason is KVM_EXIT_MMIO, then the vcpu has
6354 executed a memory-mapped I/O instruction which could not be satisfied
6355 by kvm. The 'data' member contains the written data if 'is_write' is
6356 true, and should be filled by application code otherwise.
6358 The 'data' member contains, in its first 'len' bytes, the value as it would
6359 appear if the VCPU performed a load or store of the appropriate width directly
6364 For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN,
6365 KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding
6366 operations are complete (and guest state is consistent) only after userspace
6367 has re-entered the kernel with KVM_RUN. The kernel side will first finish
6368 incomplete operations and then check for pending signals.
6370 The pending state of the operation is not preserved in state which is
6371 visible to userspace, thus userspace should ensure that the operation is
6372 completed before performing a live migration. Userspace can re-enter the
6373 guest with an unmasked signal pending or with the immediate_exit field set
6374 to complete pending operations without allowing any further instructions
6379 /* KVM_EXIT_HYPERCALL */
6388 It is strongly recommended that userspace use ``KVM_EXIT_IO`` (x86) or
6389 ``KVM_EXIT_MMIO`` (all except s390) to implement functionality that
6390 requires a guest to interact with host userspace.
6392 .. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
6397 SMCCC exits can be enabled depending on the configuration of the SMCCC
6398 filter. See the Documentation/virt/kvm/devices/vm.rst
6399 ``KVM_ARM_SMCCC_FILTER`` for more details.
6401 ``nr`` contains the function ID of the guest's SMCCC call. Userspace is
6402 expected to use the ``KVM_GET_ONE_REG`` ioctl to retrieve the call
6403 parameters from the vCPU's GPRs.
6405 Definition of ``flags``:
6406 - ``KVM_HYPERCALL_EXIT_SMC``: Indicates that the guest used the SMC
6407 conduit to initiate the SMCCC call. If this bit is 0 then the guest
6408 used the HVC conduit for the SMCCC call.
6410 - ``KVM_HYPERCALL_EXIT_16BIT``: Indicates that the guest used a 16bit
6411 instruction to initiate the SMCCC call. If this bit is 0 then the
6412 guest used a 32bit instruction. An AArch64 guest always has this
6415 At the point of exit, PC points to the instruction immediately following
6416 the trapping instruction.
6420 /* KVM_EXIT_TPR_ACCESS */
6427 To be documented (KVM_TPR_ACCESS_REPORTING).
6431 /* KVM_EXIT_S390_SIEIC */
6434 __u64 mask; /* psw upper half */
6435 __u64 addr; /* psw lower half */
6444 /* KVM_EXIT_S390_RESET */
6445 #define KVM_S390_RESET_POR 1
6446 #define KVM_S390_RESET_CLEAR 2
6447 #define KVM_S390_RESET_SUBSYSTEM 4
6448 #define KVM_S390_RESET_CPU_INIT 8
6449 #define KVM_S390_RESET_IPL 16
6450 __u64 s390_reset_flags;
6456 /* KVM_EXIT_S390_UCONTROL */
6458 __u64 trans_exc_code;
6462 s390 specific. A page fault has occurred for a user controlled virtual
6463 machine (KVM_VM_S390_UNCONTROL) on its host page table that cannot be
6464 resolved by the kernel.
6465 The program code and the translation exception code that were placed
6466 in the cpu's lowcore are presented here as defined by the z Architecture
6467 Principles of Operation Book in the Chapter for Dynamic Address Translation
6479 Deprecated - was used for 440 KVM.
6488 MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
6489 hypercalls and exit with this exit struct that contains all the guest gprs.
6491 If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
6492 Userspace can now handle the hypercall and when it's done modify the gprs as
6493 necessary. Upon guest entry all guest GPRs will then be replaced by the values
6498 /* KVM_EXIT_PAPR_HCALL */
6505 This is used on 64-bit PowerPC when emulating a pSeries partition,
6506 e.g. with the 'pseries' machine type in qemu. It occurs when the
6507 guest does a hypercall using the 'sc 1' instruction. The 'nr' field
6508 contains the hypercall number (from the guest R3), and 'args' contains
6509 the arguments (from the guest R4 - R12). Userspace should put the
6510 return code in 'ret' and any extra returned values in args[].
6511 The possible hypercalls are defined in the Power Architecture Platform
6512 Requirements (PAPR) document available from www.power.org (free
6513 developer registration required to access it).
6517 /* KVM_EXIT_S390_TSCH */
6519 __u16 subchannel_id;
6520 __u16 subchannel_nr;
6527 s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
6528 and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
6529 interrupt for the target subchannel has been dequeued and subchannel_id,
6530 subchannel_nr, io_int_parm and io_int_word contain the parameters for that
6531 interrupt. ipb is needed for instruction parameter decoding.
6540 On FSL BookE PowerPC chips, the interrupt controller has a fast patch
6541 interrupt acknowledge path to the core. When the core successfully
6542 delivers an interrupt, it automatically populates the EPR register with
6543 the interrupt vector number and acknowledges the interrupt inside
6544 the interrupt controller.
6546 In case the interrupt controller lives in user space, we need to do
6547 the interrupt acknowledge cycle through it to fetch the next to be
6548 delivered interrupt vector using this exit.
6550 It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
6551 external interrupt has just been delivered into the guest. User space
6552 should put the acknowledged interrupt vector into the 'epr' field.
6556 /* KVM_EXIT_SYSTEM_EVENT */
6558 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
6559 #define KVM_SYSTEM_EVENT_RESET 2
6560 #define KVM_SYSTEM_EVENT_CRASH 3
6561 #define KVM_SYSTEM_EVENT_WAKEUP 4
6562 #define KVM_SYSTEM_EVENT_SUSPEND 5
6563 #define KVM_SYSTEM_EVENT_SEV_TERM 6
6569 If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
6570 a system-level event using some architecture specific mechanism (hypercall
6571 or some special instruction). In case of ARM64, this is triggered using
6572 HVC instruction based PSCI call from the vcpu.
6574 The 'type' field describes the system-level event type.
6575 Valid values for 'type' are:
6577 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
6578 VM. Userspace is not obliged to honour this, and if it does honour
6579 this does not need to destroy the VM synchronously (ie it may call
6580 KVM_RUN again before shutdown finally occurs).
6581 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
6582 As with SHUTDOWN, userspace can choose to ignore the request, or
6583 to schedule the reset to occur in the future and may call KVM_RUN again.
6584 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
6585 has requested a crash condition maintenance. Userspace can choose
6586 to ignore the request, or to gather VM memory core dump and/or
6587 reset/shutdown of the VM.
6588 - KVM_SYSTEM_EVENT_SEV_TERM -- an AMD SEV guest requested termination.
6589 The guest physical address of the guest's GHCB is stored in `data[0]`.
6590 - KVM_SYSTEM_EVENT_WAKEUP -- the exiting vCPU is in a suspended state and
6591 KVM has recognized a wakeup event. Userspace may honor this event by
6592 marking the exiting vCPU as runnable, or deny it and call KVM_RUN again.
6593 - KVM_SYSTEM_EVENT_SUSPEND -- the guest has requested a suspension of
6596 If KVM_CAP_SYSTEM_EVENT_DATA is present, the 'data' field can contain
6597 architecture specific information for the system-level event. Only
6598 the first `ndata` items (possibly zero) of the data array are valid.
6600 - for arm64, data[0] is set to KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 if
6601 the guest issued a SYSTEM_RESET2 call according to v1.1 of the PSCI
6604 - for RISC-V, data[0] is set to the value of the second argument of the
6605 ``sbi_system_reset`` call.
6607 Previous versions of Linux defined a `flags` member in this struct. The
6608 field is now aliased to `data[0]`. Userspace can assume that it is only
6609 written if ndata is greater than 0.
6614 KVM_SYSTEM_EVENT_SUSPEND exits are enabled with the
6615 KVM_CAP_ARM_SYSTEM_SUSPEND VM capability. If a guest invokes the PSCI
6616 SYSTEM_SUSPEND function, KVM will exit to userspace with this event
6619 It is the sole responsibility of userspace to implement the PSCI
6620 SYSTEM_SUSPEND call according to ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND".
6621 KVM does not change the vCPU's state before exiting to userspace, so
6622 the call parameters are left in-place in the vCPU registers.
6624 Userspace is _required_ to take action for such an exit. It must
6627 - Honor the guest request to suspend the VM. Userspace can request
6628 in-kernel emulation of suspension by setting the calling vCPU's
6629 state to KVM_MP_STATE_SUSPENDED. Userspace must configure the vCPU's
6630 state according to the parameters passed to the PSCI function when
6631 the calling vCPU is resumed. See ARM DEN0022D.b 5.19.1 "Intended use"
6632 for details on the function parameters.
6634 - Deny the guest request to suspend the VM. See ARM DEN0022D.b 5.19.2
6635 "Caller responsibilities" for possible return values.
6639 /* KVM_EXIT_IOAPIC_EOI */
6644 Indicates that the VCPU's in-kernel local APIC received an EOI for a
6645 level-triggered IOAPIC interrupt. This exit only triggers when the
6646 IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
6647 the userspace IOAPIC should process the EOI and retrigger the interrupt if
6648 it is still asserted. Vector is the LAPIC interrupt vector for which the
6653 struct kvm_hyperv_exit {
6654 #define KVM_EXIT_HYPERV_SYNIC 1
6655 #define KVM_EXIT_HYPERV_HCALL 2
6656 #define KVM_EXIT_HYPERV_SYNDBG 3
6683 /* KVM_EXIT_HYPERV */
6684 struct kvm_hyperv_exit hyperv;
6686 Indicates that the VCPU exits into userspace to process some tasks
6687 related to Hyper-V emulation.
6689 Valid values for 'type' are:
6691 - KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
6693 Hyper-V SynIC state change. Notification is used to remap SynIC
6694 event/message pages and to enable/disable SynIC messages/events processing
6697 - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about
6699 Hyper-V Synthetic debugger state change. Notification is used to either update
6700 the pending_page location or to send a control command (send the buffer located
6701 in send_page or recv a buffer to recv_page).
6705 /* KVM_EXIT_ARM_NISV */
6711 Used on arm64 systems. If a guest accesses memory not in a memslot,
6712 KVM will typically return to userspace and ask it to do MMIO emulation on its
6713 behalf. However, for certain classes of instructions, no instruction decode
6714 (direction, length of memory access) is provided, and fetching and decoding
6715 the instruction from the VM is overly complicated to live in the kernel.
6717 Historically, when this situation occurred, KVM would print a warning and kill
6718 the VM. KVM assumed that if the guest accessed non-memslot memory, it was
6719 trying to do I/O, which just couldn't be emulated, and the warning message was
6720 phrased accordingly. However, what happened more often was that a guest bug
6721 caused access outside the guest memory areas which should lead to a more
6722 meaningful warning message and an external abort in the guest, if the access
6723 did not fall within an I/O window.
6725 Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable
6726 this capability at VM creation. Once this is done, these types of errors will
6727 instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from
6728 the ESR_EL2 in the esr_iss field, and the faulting IPA in the fault_ipa field.
6729 Userspace can either fix up the access if it's actually an I/O access by
6730 decoding the instruction from guest memory (if it's very brave) and continue
6731 executing the guest, or it can decide to suspend, dump, or restart the guest.
6733 Note that KVM does not skip the faulting instruction as it does for
6734 KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state
6735 if it decides to decode and emulate the instruction.
6739 /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */
6741 __u8 error; /* user -> kernel */
6743 __u32 reason; /* kernel -> user */
6744 __u32 index; /* kernel -> user */
6745 __u64 data; /* kernel <-> user */
6748 Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is
6749 enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code
6750 may instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR
6753 The "reason" field specifies why the MSR interception occurred. Userspace will
6754 only receive MSR exits when a particular reason was requested during through
6755 ENABLE_CAP. Currently valid exit reasons are:
6757 ============================ ========================================
6758 KVM_MSR_EXIT_REASON_UNKNOWN access to MSR that is unknown to KVM
6759 KVM_MSR_EXIT_REASON_INVAL access to invalid MSRs or reserved bits
6760 KVM_MSR_EXIT_REASON_FILTER access blocked by KVM_X86_SET_MSR_FILTER
6761 ============================ ========================================
6763 For KVM_EXIT_X86_RDMSR, the "index" field tells userspace which MSR the guest
6764 wants to read. To respond to this request with a successful read, userspace
6765 writes the respective data into the "data" field and must continue guest
6766 execution to ensure the read data is transferred into guest register state.
6768 If the RDMSR request was unsuccessful, userspace indicates that with a "1" in
6769 the "error" field. This will inject a #GP into the guest when the VCPU is
6772 For KVM_EXIT_X86_WRMSR, the "index" field tells userspace which MSR the guest
6773 wants to write. Once finished processing the event, userspace must continue
6774 vCPU execution. If the MSR write was unsuccessful, userspace also sets the
6775 "error" field to "1".
6777 See KVM_X86_SET_MSR_FILTER for details on the interaction with MSR filtering.
6782 struct kvm_xen_exit {
6783 #define KVM_EXIT_XEN_HCALL 1
6796 struct kvm_hyperv_exit xen;
6798 Indicates that the VCPU exits into userspace to process some tasks
6799 related to Xen emulation.
6801 Valid values for 'type' are:
6803 - KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall.
6804 Userspace is expected to place the hypercall result into the appropriate
6805 field before invoking KVM_RUN again.
6809 /* KVM_EXIT_RISCV_SBI */
6811 unsigned long extension_id;
6812 unsigned long function_id;
6813 unsigned long args[6];
6814 unsigned long ret[2];
6817 If exit reason is KVM_EXIT_RISCV_SBI then it indicates that the VCPU has
6818 done a SBI call which is not handled by KVM RISC-V kernel module. The details
6819 of the SBI call are available in 'riscv_sbi' member of kvm_run structure. The
6820 'extension_id' field of 'riscv_sbi' represents SBI extension ID whereas the
6821 'function_id' field represents function ID of given SBI extension. The 'args'
6822 array field of 'riscv_sbi' represents parameters for the SBI call and 'ret'
6823 array field represents return values. The userspace should update the return
6824 values of SBI call before resuming the VCPU. For more details on RISC-V SBI
6825 spec refer, https://github.com/riscv/riscv-sbi-doc.
6829 /* KVM_EXIT_NOTIFY */
6831 #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0)
6835 Used on x86 systems. When the VM capability KVM_CAP_X86_NOTIFY_VMEXIT is
6836 enabled, a VM exit generated if no event window occurs in VM non-root mode
6837 for a specified amount of time. Once KVM_X86_NOTIFY_VMEXIT_USER is set when
6838 enabling the cap, it would exit to userspace with the exit reason
6839 KVM_EXIT_NOTIFY for further handling. The "flags" field contains more
6842 The valid value for 'flags' is:
6844 - KVM_NOTIFY_CONTEXT_INVALID -- the VM context is corrupted and not valid
6845 in VMCS. It would run into unknown result if resume the target VM.
6849 /* Fix the size of the union. */
6854 * shared registers between kvm and userspace.
6855 * kvm_valid_regs specifies the register classes set by the host
6856 * kvm_dirty_regs specified the register classes dirtied by userspace
6857 * struct kvm_sync_regs is architecture specific, as well as the
6858 * bits for kvm_valid_regs and kvm_dirty_regs
6860 __u64 kvm_valid_regs;
6861 __u64 kvm_dirty_regs;
6863 struct kvm_sync_regs regs;
6864 char padding[SYNC_REGS_SIZE_BYTES];
6867 If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
6868 certain guest registers without having to call SET/GET_*REGS. Thus we can
6869 avoid some system call overhead if userspace has to handle the exit.
6870 Userspace can query the validity of the structure by checking
6871 kvm_valid_regs for specific bits. These bits are architecture specific
6872 and usually define the validity of a groups of registers. (e.g. one bit
6873 for general purpose registers)
6875 Please note that the kernel is allowed to use the kvm_run structure as the
6876 primary storage for certain register types. Therefore, the kernel may use the
6877 values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
6880 6. Capabilities that can be enabled on vCPUs
6881 ============================================
6883 There are certain capabilities that change the behavior of the virtual CPU or
6884 the virtual machine when enabled. To enable them, please see section 4.37.
6885 Below you can find a list of capabilities and what their effect on the vCPU or
6886 the virtual machine is when enabling them.
6888 The following information is provided along with the description:
6891 which instruction set architectures provide this ioctl.
6892 x86 includes both i386 and x86_64.
6895 whether this is a per-vcpu or per-vm capability.
6898 what parameters are accepted by the capability.
6901 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
6902 are not detailed, but errors with specific meanings are.
6911 :Returns: 0 on success; -1 on error
6913 This capability enables interception of OSI hypercalls that otherwise would
6914 be treated as normal system calls to be injected into the guest. OSI hypercalls
6915 were invented by Mac-on-Linux to have a standardized communication mechanism
6916 between the guest and the host.
6918 When this capability is enabled, KVM_EXIT_OSI can occur.
6921 6.2 KVM_CAP_PPC_PAPR
6922 --------------------
6927 :Returns: 0 on success; -1 on error
6929 This capability enables interception of PAPR hypercalls. PAPR hypercalls are
6930 done using the hypercall instruction "sc 1".
6932 It also sets the guest privilege level to "supervisor" mode. Usually the guest
6933 runs in "hypervisor" privilege mode with a few missing features.
6935 In addition to the above, it changes the semantics of SDR1. In this mode, the
6936 HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
6937 HTAB invisible to the guest.
6939 When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
6947 :Parameters: args[0] is the address of a struct kvm_config_tlb
6948 :Returns: 0 on success; -1 on error
6952 struct kvm_config_tlb {
6959 Configures the virtual CPU's TLB array, establishing a shared memory area
6960 between userspace and KVM. The "params" and "array" fields are userspace
6961 addresses of mmu-type-specific data structures. The "array_len" field is an
6962 safety mechanism, and should be set to the size in bytes of the memory that
6963 userspace has reserved for the array. It must be at least the size dictated
6964 by "mmu_type" and "params".
6966 While KVM_RUN is active, the shared region is under control of KVM. Its
6967 contents are undefined, and any modification by userspace results in
6968 boundedly undefined behavior.
6970 On return from KVM_RUN, the shared region will reflect the current state of
6971 the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
6972 to tell KVM which entries have been changed, prior to calling KVM_RUN again
6975 For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
6977 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
6978 - The "array" field points to an array of type "struct
6979 kvm_book3e_206_tlb_entry".
6980 - The array consists of all entries in the first TLB, followed by all
6981 entries in the second TLB.
6982 - Within a TLB, entries are ordered first by increasing set number. Within a
6983 set, entries are ordered by way (increasing ESEL).
6984 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
6985 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
6986 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
6987 hardware ignores this value for TLB0.
6989 6.4 KVM_CAP_S390_CSS_SUPPORT
6990 ----------------------------
6992 :Architectures: s390
6995 :Returns: 0 on success; -1 on error
6997 This capability enables support for handling of channel I/O instructions.
6999 TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
7000 handled in-kernel, while the other I/O instructions are passed to userspace.
7002 When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
7003 SUBCHANNEL intercepts.
7005 Note that even though this capability is enabled per-vcpu, the complete
7006 virtual machine is affected.
7013 :Parameters: args[0] defines whether the proxy facility is active
7014 :Returns: 0 on success; -1 on error
7016 This capability enables or disables the delivery of interrupts through the
7017 external proxy facility.
7019 When enabled (args[0] != 0), every time the guest gets an external interrupt
7020 delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
7021 to receive the topmost interrupt vector.
7023 When disabled (args[0] == 0), behavior is as if this facility is unsupported.
7025 When this capability is enabled, KVM_EXIT_EPR can occur.
7027 6.6 KVM_CAP_IRQ_MPIC
7028 --------------------
7031 :Parameters: args[0] is the MPIC device fd;
7032 args[1] is the MPIC CPU number for this vcpu
7034 This capability connects the vcpu to an in-kernel MPIC device.
7036 6.7 KVM_CAP_IRQ_XICS
7037 --------------------
7041 :Parameters: args[0] is the XICS device fd;
7042 args[1] is the XICS CPU number (server ID) for this vcpu
7044 This capability connects the vcpu to an in-kernel XICS device.
7046 6.8 KVM_CAP_S390_IRQCHIP
7047 ------------------------
7049 :Architectures: s390
7053 This capability enables the in-kernel irqchip for s390. Please refer to
7054 "4.24 KVM_CREATE_IRQCHIP" for details.
7056 6.9 KVM_CAP_MIPS_FPU
7057 --------------------
7059 :Architectures: mips
7061 :Parameters: args[0] is reserved for future use (should be 0).
7063 This capability allows the use of the host Floating Point Unit by the guest. It
7064 allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
7065 done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be
7066 accessed (depending on the current guest FPU register mode), and the Status.FR,
7067 Config5.FRE bits are accessible via the KVM API and also from the guest,
7068 depending on them being supported by the FPU.
7070 6.10 KVM_CAP_MIPS_MSA
7071 ---------------------
7073 :Architectures: mips
7075 :Parameters: args[0] is reserved for future use (should be 0).
7077 This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
7078 It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
7079 Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*``
7080 registers can be accessed, and the Config5.MSAEn bit is accessible via the
7081 KVM API and also from the guest.
7083 6.74 KVM_CAP_SYNC_REGS
7084 ----------------------
7086 :Architectures: s390, x86
7087 :Target: s390: always enabled, x86: vcpu
7089 :Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
7091 (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
7093 As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
7094 KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
7095 without having to call SET/GET_*REGS". This reduces overhead by eliminating
7096 repeated ioctl calls for setting and/or getting register values. This is
7097 particularly important when userspace is making synchronous guest state
7098 modifications, e.g. when emulating and/or intercepting instructions in
7101 For s390 specifics, please refer to the source code.
7105 - the register sets to be copied out to kvm_run are selectable
7106 by userspace (rather that all sets being copied out for every exit).
7107 - vcpu_events are available in addition to regs and sregs.
7109 For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
7110 function as an input bit-array field set by userspace to indicate the
7111 specific register sets to be copied out on the next exit.
7113 To indicate when userspace has modified values that should be copied into
7114 the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
7115 This is done using the same bitflags as for the 'kvm_valid_regs' field.
7116 If the dirty bit is not set, then the register set values will not be copied
7117 into the vCPU even if they've been modified.
7119 Unused bitfields in the bitarrays must be set to zero.
7123 struct kvm_sync_regs {
7124 struct kvm_regs regs;
7125 struct kvm_sregs sregs;
7126 struct kvm_vcpu_events events;
7129 6.75 KVM_CAP_PPC_IRQ_XIVE
7130 -------------------------
7134 :Parameters: args[0] is the XIVE device fd;
7135 args[1] is the XIVE CPU number (server ID) for this vcpu
7137 This capability connects the vcpu to an in-kernel XIVE device.
7139 7. Capabilities that can be enabled on VMs
7140 ==========================================
7142 There are certain capabilities that change the behavior of the virtual
7143 machine when enabled. To enable them, please see section 4.37. Below
7144 you can find a list of capabilities and what their effect on the VM
7145 is when enabling them.
7147 The following information is provided along with the description:
7150 which instruction set architectures provide this ioctl.
7151 x86 includes both i386 and x86_64.
7154 what parameters are accepted by the capability.
7157 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
7158 are not detailed, but errors with specific meanings are.
7161 7.1 KVM_CAP_PPC_ENABLE_HCALL
7162 ----------------------------
7165 :Parameters: args[0] is the sPAPR hcall number;
7166 args[1] is 0 to disable, 1 to enable in-kernel handling
7168 This capability controls whether individual sPAPR hypercalls (hcalls)
7169 get handled by the kernel or not. Enabling or disabling in-kernel
7170 handling of an hcall is effective across the VM. On creation, an
7171 initial set of hcalls are enabled for in-kernel handling, which
7172 consists of those hcalls for which in-kernel handlers were implemented
7173 before this capability was implemented. If disabled, the kernel will
7174 not to attempt to handle the hcall, but will always exit to userspace
7175 to handle it. Note that it may not make sense to enable some and
7176 disable others of a group of related hcalls, but KVM does not prevent
7177 userspace from doing that.
7179 If the hcall number specified is not one that has an in-kernel
7180 implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
7183 7.2 KVM_CAP_S390_USER_SIGP
7184 --------------------------
7186 :Architectures: s390
7189 This capability controls which SIGP orders will be handled completely in user
7190 space. With this capability enabled, all fast orders will be handled completely
7197 - CONDITIONAL EMERGENCY SIGNAL
7199 All other orders will be handled completely in user space.
7201 Only privileged operation exceptions will be checked for in the kernel (or even
7202 in the hardware prior to interception). If this capability is not enabled, the
7203 old way of handling SIGP orders is used (partially in kernel and user space).
7205 7.3 KVM_CAP_S390_VECTOR_REGISTERS
7206 ---------------------------------
7208 :Architectures: s390
7210 :Returns: 0 on success, negative value on error
7212 Allows use of the vector registers introduced with z13 processor, and
7213 provides for the synchronization between host and user space. Will
7214 return -EINVAL if the machine does not support vectors.
7216 7.4 KVM_CAP_S390_USER_STSI
7217 --------------------------
7219 :Architectures: s390
7222 This capability allows post-handlers for the STSI instruction. After
7223 initial handling in the kernel, KVM exits to user space with
7224 KVM_EXIT_S390_STSI to allow user space to insert further data.
7226 Before exiting to userspace, kvm handlers should fill in s390_stsi field of
7238 @addr - guest address of STSI SYSIB
7242 @ar - access register number
7244 KVM handlers should exit to userspace with rc = -EREMOTE.
7246 7.5 KVM_CAP_SPLIT_IRQCHIP
7247 -------------------------
7250 :Parameters: args[0] - number of routes reserved for userspace IOAPICs
7251 :Returns: 0 on success, -1 on error
7253 Create a local apic for each processor in the kernel. This can be used
7254 instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
7255 IOAPIC and PIC (and also the PIT, even though this has to be enabled
7258 This capability also enables in kernel routing of interrupt requests;
7259 when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
7260 used in the IRQ routing table. The first args[0] MSI routes are reserved
7261 for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
7262 a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
7264 Fails if VCPU has already been created, or if the irqchip is already in the
7265 kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
7270 :Architectures: s390
7273 Allows use of runtime-instrumentation introduced with zEC12 processor.
7274 Will return -EINVAL if the machine does not support runtime-instrumentation.
7275 Will return -EBUSY if a VCPU has already been created.
7277 7.7 KVM_CAP_X2APIC_API
7278 ----------------------
7281 :Parameters: args[0] - features that should be enabled
7282 :Returns: 0 on success, -EINVAL when args[0] contains invalid features
7284 Valid feature flags in args[0] are::
7286 #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
7287 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
7289 Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
7290 KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
7291 allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
7292 respective sections.
7294 KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
7295 in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
7296 as a broadcast even in x2APIC mode in order to support physical x2APIC
7297 without interrupt remapping. This is undesirable in logical mode,
7298 where 0xff represents CPUs 0-7 in cluster 0.
7300 7.8 KVM_CAP_S390_USER_INSTR0
7301 ----------------------------
7303 :Architectures: s390
7306 With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
7307 be intercepted and forwarded to user space. User space can use this
7308 mechanism e.g. to realize 2-byte software breakpoints. The kernel will
7309 not inject an operating exception for these instructions, user space has
7310 to take care of that.
7312 This capability can be enabled dynamically even if VCPUs were already
7313 created and are running.
7318 :Architectures: s390
7320 :Returns: 0 on success; -EINVAL if the machine does not support
7321 guarded storage; -EBUSY if a VCPU has already been created.
7323 Allows use of guarded storage for the KVM guest.
7325 7.10 KVM_CAP_S390_AIS
7326 ---------------------
7328 :Architectures: s390
7331 Allow use of adapter-interruption suppression.
7332 :Returns: 0 on success; -EBUSY if a VCPU has already been created.
7334 7.11 KVM_CAP_PPC_SMT
7335 --------------------
7338 :Parameters: vsmt_mode, flags
7340 Enabling this capability on a VM provides userspace with a way to set
7341 the desired virtual SMT mode (i.e. the number of virtual CPUs per
7342 virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
7343 between 1 and 8. On POWER8, vsmt_mode must also be no greater than
7344 the number of threads per subcore for the host. Currently flags must
7345 be 0. A successful call to enable this capability will result in
7346 vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
7347 subsequently queried for the VM. This capability is only supported by
7348 HV KVM, and can only be set before any VCPUs have been created.
7349 The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
7350 modes are available.
7352 7.12 KVM_CAP_PPC_FWNMI
7353 ----------------------
7358 With this capability a machine check exception in the guest address
7359 space will cause KVM to exit the guest with NMI exit reason. This
7360 enables QEMU to build error log and branch to guest kernel registered
7361 machine check handling routine. Without this capability KVM will
7362 branch to guests' 0x200 interrupt vector.
7364 7.13 KVM_CAP_X86_DISABLE_EXITS
7365 ------------------------------
7368 :Parameters: args[0] defines which exits are disabled
7369 :Returns: 0 on success, -EINVAL when args[0] contains invalid exits
7371 Valid bits in args[0] are::
7373 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
7374 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
7375 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
7376 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
7378 Enabling this capability on a VM provides userspace with a way to no
7379 longer intercept some instructions for improved latency in some
7380 workloads, and is suggested when vCPUs are associated to dedicated
7381 physical CPUs. More bits can be added in the future; userspace can
7382 just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
7385 Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
7387 7.14 KVM_CAP_S390_HPAGE_1M
7388 --------------------------
7390 :Architectures: s390
7392 :Returns: 0 on success, -EINVAL if hpage module parameter was not set
7393 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
7396 With this capability the KVM support for memory backing with 1m pages
7397 through hugetlbfs can be enabled for a VM. After the capability is
7398 enabled, cmma can't be enabled anymore and pfmfi and the storage key
7399 interpretation are disabled. If cmma has already been enabled or the
7400 hpage module parameter is not set to 1, -EINVAL is returned.
7402 While it is generally possible to create a huge page backed VM without
7403 this capability, the VM will not be able to run.
7405 7.15 KVM_CAP_MSR_PLATFORM_INFO
7406 ------------------------------
7409 :Parameters: args[0] whether feature should be enabled or not
7411 With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
7412 a #GP would be raised when the guest tries to access. Currently, this
7413 capability does not enable write permissions of this MSR for the guest.
7415 7.16 KVM_CAP_PPC_NESTED_HV
7416 --------------------------
7420 :Returns: 0 on success, -EINVAL when the implementation doesn't support
7421 nested-HV virtualization.
7423 HV-KVM on POWER9 and later systems allows for "nested-HV"
7424 virtualization, which provides a way for a guest VM to run guests that
7425 can run using the CPU's supervisor mode (privileged non-hypervisor
7426 state). Enabling this capability on a VM depends on the CPU having
7427 the necessary functionality and on the facility being enabled with a
7428 kvm-hv module parameter.
7430 7.17 KVM_CAP_EXCEPTION_PAYLOAD
7431 ------------------------------
7434 :Parameters: args[0] whether feature should be enabled or not
7436 With this capability enabled, CR2 will not be modified prior to the
7437 emulated VM-exit when L1 intercepts a #PF exception that occurs in
7438 L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
7439 the emulated VM-exit when L1 intercepts a #DB exception that occurs in
7440 L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
7441 #DB) exception for L2, exception.has_payload will be set and the
7442 faulting address (or the new DR6 bits*) will be reported in the
7443 exception_payload field. Similarly, when userspace injects a #PF (or
7444 #DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
7445 exception.has_payload and to put the faulting address - or the new DR6
7446 bits\ [#]_ - in the exception_payload field.
7448 This capability also enables exception.pending in struct
7449 kvm_vcpu_events, which allows userspace to distinguish between pending
7450 and injected exceptions.
7453 .. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception
7456 7.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
7457 --------------------------------------
7459 :Architectures: x86, arm64, mips
7460 :Parameters: args[0] whether feature should be enabled or not
7464 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0)
7465 #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1)
7467 With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not
7468 automatically clear and write-protect all pages that are returned as dirty.
7469 Rather, userspace will have to do this operation separately using
7470 KVM_CLEAR_DIRTY_LOG.
7472 At the cost of a slightly more complicated operation, this provides better
7473 scalability and responsiveness for two reasons. First,
7474 KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
7475 than requiring to sync a full memslot; this ensures that KVM does not
7476 take spinlocks for an extended period of time. Second, in some cases a
7477 large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
7478 userspace actually using the data in the page. Pages can be modified
7479 during this time, which is inefficient for both the guest and userspace:
7480 the guest will incur a higher penalty due to write protection faults,
7481 while userspace can see false reports of dirty pages. Manual reprotection
7482 helps reducing this time, improving guest performance and reducing the
7483 number of dirty log false positives.
7485 With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap
7486 will be initialized to 1 when created. This also improves performance because
7487 dirty logging can be enabled gradually in small chunks on the first call
7488 to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on
7489 KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
7490 x86 and arm64 for now).
7492 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
7493 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make
7494 it hard or impossible to use it correctly. The availability of
7495 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed.
7496 Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
7498 7.19 KVM_CAP_PPC_SECURE_GUEST
7499 ------------------------------
7503 This capability indicates that KVM is running on a host that has
7504 ultravisor firmware and thus can support a secure guest. On such a
7505 system, a guest can ask the ultravisor to make it a secure guest,
7506 one whose memory is inaccessible to the host except for pages which
7507 are explicitly requested to be shared with the host. The ultravisor
7508 notifies KVM when a guest requests to become a secure guest, and KVM
7509 has the opportunity to veto the transition.
7511 If present, this capability can be enabled for a VM, meaning that KVM
7512 will allow the transition to secure guest mode. Otherwise KVM will
7513 veto the transition.
7515 7.20 KVM_CAP_HALT_POLL
7516 ----------------------
7520 :Parameters: args[0] is the maximum poll time in nanoseconds
7521 :Returns: 0 on success; -1 on error
7523 KVM_CAP_HALT_POLL overrides the kvm.halt_poll_ns module parameter to set the
7524 maximum halt-polling time for all vCPUs in the target VM. This capability can
7525 be invoked at any time and any number of times to dynamically change the
7526 maximum halt-polling time.
7528 See Documentation/virt/kvm/halt-polling.rst for more information on halt
7531 7.21 KVM_CAP_X86_USER_SPACE_MSR
7532 -------------------------------
7536 :Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report
7537 :Returns: 0 on success; -1 on error
7539 This capability allows userspace to intercept RDMSR and WRMSR instructions if
7540 access to an MSR is denied. By default, KVM injects #GP on denied accesses.
7542 When a guest requests to read or write an MSR, KVM may not implement all MSRs
7543 that are relevant to a respective system. It also does not differentiate by
7546 To allow more fine grained control over MSR handling, userspace may enable
7547 this capability. With it enabled, MSR accesses that match the mask specified in
7548 args[0] and would trigger a #GP inside the guest will instead trigger
7549 KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications. Userspace
7550 can then implement model specific MSR handling and/or user notifications
7551 to inform a user that an MSR was not emulated/virtualized by KVM.
7553 The valid mask flags are:
7555 ============================ ===============================================
7556 KVM_MSR_EXIT_REASON_UNKNOWN intercept accesses to unknown (to KVM) MSRs
7557 KVM_MSR_EXIT_REASON_INVAL intercept accesses that are architecturally
7558 invalid according to the vCPU model and/or mode
7559 KVM_MSR_EXIT_REASON_FILTER intercept accesses that are denied by userspace
7560 via KVM_X86_SET_MSR_FILTER
7561 ============================ ===============================================
7563 7.22 KVM_CAP_X86_BUS_LOCK_EXIT
7564 -------------------------------
7568 :Parameters: args[0] defines the policy used when bus locks detected in guest
7569 :Returns: 0 on success, -EINVAL when args[0] contains invalid bits
7571 Valid bits in args[0] are::
7573 #define KVM_BUS_LOCK_DETECTION_OFF (1 << 0)
7574 #define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1)
7576 Enabling this capability on a VM provides userspace with a way to select
7577 a policy to handle the bus locks detected in guest. Userspace can obtain
7578 the supported modes from the result of KVM_CHECK_EXTENSION and define it
7579 through the KVM_ENABLE_CAP.
7581 KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
7582 currently and mutually exclusive with each other. More bits can be added in
7585 With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
7586 so that no additional actions are needed. This is the default mode.
7588 With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
7589 in VM. KVM just exits to userspace when handling them. Userspace can enforce
7590 its own throttling or other policy based mitigations.
7592 This capability is aimed to address the thread that VM can exploit bus locks to
7593 degree the performance of the whole system. Once the userspace enable this
7594 capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
7595 KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
7596 the bus lock vm exit can be preempted by a higher priority VM exit, the exit
7597 notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
7598 KVM_RUN_BUS_LOCK flag is used to distinguish between them.
7600 7.23 KVM_CAP_PPC_DAWR1
7601 ----------------------
7605 :Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
7607 This capability can be used to check / enable 2nd DAWR feature provided
7608 by POWER10 processor.
7611 7.24 KVM_CAP_VM_COPY_ENC_CONTEXT_FROM
7612 -------------------------------------
7614 Architectures: x86 SEV enabled
7616 Parameters: args[0] is the fd of the source vm
7617 Returns: 0 on success; ENOTTY on error
7619 This capability enables userspace to copy encryption context from the vm
7620 indicated by the fd to the vm this is called on.
7622 This is intended to support in-guest workloads scheduled by the host. This
7623 allows the in-guest workload to maintain its own NPTs and keeps the two vms
7624 from accidentally clobbering each other with interrupts and the like (separate
7627 7.25 KVM_CAP_SGX_ATTRIBUTE
7628 --------------------------
7632 :Parameters: args[0] is a file handle of a SGX attribute file in securityfs
7633 :Returns: 0 on success, -EINVAL if the file handle is invalid or if a requested
7634 attribute is not supported by KVM.
7636 KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or
7637 more privileged enclave attributes. args[0] must hold a file handle to a valid
7638 SGX attribute file corresponding to an attribute that is supported/restricted
7639 by KVM (currently only PROVISIONKEY).
7641 The SGX subsystem restricts access to a subset of enclave attributes to provide
7642 additional security for an uncompromised kernel, e.g. use of the PROVISIONKEY
7643 is restricted to deter malware from using the PROVISIONKEY to obtain a stable
7644 system fingerprint. To prevent userspace from circumventing such restrictions
7645 by running an enclave in a VM, KVM prevents access to privileged attributes by
7648 See Documentation/arch/x86/sgx.rst for more details.
7650 7.26 KVM_CAP_PPC_RPT_INVALIDATE
7651 -------------------------------
7653 :Capability: KVM_CAP_PPC_RPT_INVALIDATE
7657 This capability indicates that the kernel is capable of handling
7658 H_RPT_INVALIDATE hcall.
7660 In order to enable the use of H_RPT_INVALIDATE in the guest,
7661 user space might have to advertise it for the guest. For example,
7662 IBM pSeries (sPAPR) guest starts using it if "hcall-rpt-invalidate" is
7663 present in the "ibm,hypertas-functions" device-tree property.
7665 This capability is enabled for hypervisors on platforms like POWER9
7666 that support radix MMU.
7668 7.27 KVM_CAP_EXIT_ON_EMULATION_FAILURE
7669 --------------------------------------
7672 :Parameters: args[0] whether the feature should be enabled or not
7674 When this capability is enabled, an emulation failure will result in an exit
7675 to userspace with KVM_INTERNAL_ERROR (except when the emulator was invoked
7676 to handle a VMware backdoor instruction). Furthermore, KVM will now provide up
7677 to 15 instruction bytes for any exit to userspace resulting from an emulation
7678 failure. When these exits to userspace occur use the emulation_failure struct
7679 instead of the internal struct. They both have the same layout, but the
7680 emulation_failure struct matches the content better. It also explicitly
7681 defines the 'flags' field which is used to describe the fields in the struct
7682 that are valid (ie: if KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES is
7683 set in the 'flags' field then both 'insn_size' and 'insn_bytes' have valid data
7686 7.28 KVM_CAP_ARM_MTE
7687 --------------------
7689 :Architectures: arm64
7692 This capability indicates that KVM (and the hardware) supports exposing the
7693 Memory Tagging Extensions (MTE) to the guest. It must also be enabled by the
7694 VMM before creating any VCPUs to allow the guest access. Note that MTE is only
7695 available to a guest running in AArch64 mode and enabling this capability will
7696 cause attempts to create AArch32 VCPUs to fail.
7698 When enabled the guest is able to access tags associated with any memory given
7699 to the guest. KVM will ensure that the tags are maintained during swap or
7700 hibernation of the host; however the VMM needs to manually save/restore the
7701 tags as appropriate if the VM is migrated.
7703 When this capability is enabled all memory in memslots must be mapped as
7704 ``MAP_ANONYMOUS`` or with a RAM-based file mapping (``tmpfs``, ``memfd``),
7705 attempts to create a memslot with an invalid mmap will result in an
7708 When enabled the VMM may make use of the ``KVM_ARM_MTE_COPY_TAGS`` ioctl to
7709 perform a bulk copy of tags to/from the guest.
7711 7.29 KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM
7712 -------------------------------------
7714 Architectures: x86 SEV enabled
7716 Parameters: args[0] is the fd of the source vm
7717 Returns: 0 on success
7719 This capability enables userspace to migrate the encryption context from the VM
7720 indicated by the fd to the VM this is called on.
7722 This is intended to support intra-host migration of VMs between userspace VMMs,
7723 upgrading the VMM process without interrupting the guest.
7725 7.30 KVM_CAP_PPC_AIL_MODE_3
7726 -------------------------------
7728 :Capability: KVM_CAP_PPC_AIL_MODE_3
7732 This capability indicates that the kernel supports the mode 3 setting for the
7733 "Address Translation Mode on Interrupt" aka "Alternate Interrupt Location"
7734 resource that is controlled with the H_SET_MODE hypercall.
7736 This capability allows a guest kernel to use a better-performance mode for
7737 handling interrupts and system calls.
7739 7.31 KVM_CAP_DISABLE_QUIRKS2
7740 ----------------------------
7742 :Capability: KVM_CAP_DISABLE_QUIRKS2
7743 :Parameters: args[0] - set of KVM quirks to disable
7747 This capability, if enabled, will cause KVM to disable some behavior
7750 Calling KVM_CHECK_EXTENSION for this capability returns a bitmask of
7751 quirks that can be disabled in KVM.
7753 The argument to KVM_ENABLE_CAP for this capability is a bitmask of
7754 quirks to disable, and must be a subset of the bitmask returned by
7755 KVM_CHECK_EXTENSION.
7757 The valid bits in cap.args[0] are:
7759 =================================== ============================================
7760 KVM_X86_QUIRK_LINT0_REENABLED By default, the reset value for the LVT
7761 LINT0 register is 0x700 (APIC_MODE_EXTINT).
7762 When this quirk is disabled, the reset value
7763 is 0x10000 (APIC_LVT_MASKED).
7765 KVM_X86_QUIRK_CD_NW_CLEARED By default, KVM clears CR0.CD and CR0.NW.
7766 When this quirk is disabled, KVM does not
7767 change the value of CR0.CD and CR0.NW.
7769 KVM_X86_QUIRK_LAPIC_MMIO_HOLE By default, the MMIO LAPIC interface is
7770 available even when configured for x2APIC
7771 mode. When this quirk is disabled, KVM
7772 disables the MMIO LAPIC interface if the
7773 LAPIC is in x2APIC mode.
7775 KVM_X86_QUIRK_OUT_7E_INC_RIP By default, KVM pre-increments %rip before
7776 exiting to userspace for an OUT instruction
7777 to port 0x7e. When this quirk is disabled,
7778 KVM does not pre-increment %rip before
7779 exiting to userspace.
7781 KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT When this quirk is disabled, KVM sets
7782 CPUID.01H:ECX[bit 3] (MONITOR/MWAIT) if
7783 IA32_MISC_ENABLE[bit 18] (MWAIT) is set.
7784 Additionally, when this quirk is disabled,
7785 KVM clears CPUID.01H:ECX[bit 3] if
7786 IA32_MISC_ENABLE[bit 18] is cleared.
7788 KVM_X86_QUIRK_FIX_HYPERCALL_INSN By default, KVM rewrites guest
7789 VMMCALL/VMCALL instructions to match the
7790 vendor's hypercall instruction for the
7791 system. When this quirk is disabled, KVM
7792 will no longer rewrite invalid guest
7793 hypercall instructions. Executing the
7794 incorrect hypercall instruction will
7795 generate a #UD within the guest.
7797 KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS By default, KVM emulates MONITOR/MWAIT (if
7798 they are intercepted) as NOPs regardless of
7799 whether or not MONITOR/MWAIT are supported
7800 according to guest CPUID. When this quirk
7801 is disabled and KVM_X86_DISABLE_EXITS_MWAIT
7802 is not set (MONITOR/MWAIT are intercepted),
7803 KVM will inject a #UD on MONITOR/MWAIT if
7804 they're unsupported per guest CPUID. Note,
7805 KVM will modify MONITOR/MWAIT support in
7806 guest CPUID on writes to MISC_ENABLE if
7807 KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT is
7809 =================================== ============================================
7811 7.32 KVM_CAP_MAX_VCPU_ID
7812 ------------------------
7816 :Parameters: args[0] - maximum APIC ID value set for current VM
7817 :Returns: 0 on success, -EINVAL if args[0] is beyond KVM_MAX_VCPU_IDS
7818 supported in KVM or if it has been set.
7820 This capability allows userspace to specify maximum possible APIC ID
7821 assigned for current VM session prior to the creation of vCPUs, saving
7822 memory for data structures indexed by the APIC ID. Userspace is able
7823 to calculate the limit to APIC ID values from designated
7826 The value can be changed only until KVM_ENABLE_CAP is set to a nonzero
7827 value or until a vCPU is created. Upon creation of the first vCPU,
7828 if the value was set to zero or KVM_ENABLE_CAP was not invoked, KVM
7829 uses the return value of KVM_CHECK_EXTENSION(KVM_CAP_MAX_VCPU_ID) as
7830 the maximum APIC ID.
7832 7.33 KVM_CAP_X86_NOTIFY_VMEXIT
7833 ------------------------------
7837 :Parameters: args[0] is the value of notify window as well as some flags
7838 :Returns: 0 on success, -EINVAL if args[0] contains invalid flags or notify
7839 VM exit is unsupported.
7841 Bits 63:32 of args[0] are used for notify window.
7842 Bits 31:0 of args[0] are for some flags. Valid bits are::
7844 #define KVM_X86_NOTIFY_VMEXIT_ENABLED (1 << 0)
7845 #define KVM_X86_NOTIFY_VMEXIT_USER (1 << 1)
7847 This capability allows userspace to configure the notify VM exit on/off
7848 in per-VM scope during VM creation. Notify VM exit is disabled by default.
7849 When userspace sets KVM_X86_NOTIFY_VMEXIT_ENABLED bit in args[0], VMM will
7850 enable this feature with the notify window provided, which will generate
7851 a VM exit if no event window occurs in VM non-root mode for a specified of
7852 time (notify window).
7854 If KVM_X86_NOTIFY_VMEXIT_USER is set in args[0], upon notify VM exits happen,
7855 KVM would exit to userspace for handling.
7857 This capability is aimed to mitigate the threat that malicious VMs can
7858 cause CPU stuck (due to event windows don't open up) and make the CPU
7859 unavailable to host or other VMs.
7861 8. Other capabilities.
7862 ======================
7864 This section lists capabilities that give information about other
7865 features of the KVM implementation.
7867 8.1 KVM_CAP_PPC_HWRNG
7868 ---------------------
7872 This capability, if KVM_CHECK_EXTENSION indicates that it is
7873 available, means that the kernel has an implementation of the
7874 H_RANDOM hypercall backed by a hardware random-number generator.
7875 If present, the kernel H_RANDOM handler can be enabled for guest use
7876 with the KVM_CAP_PPC_ENABLE_HCALL capability.
7878 8.2 KVM_CAP_HYPERV_SYNIC
7879 ------------------------
7883 This capability, if KVM_CHECK_EXTENSION indicates that it is
7884 available, means that the kernel has an implementation of the
7885 Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
7886 used to support Windows Hyper-V based guest paravirt drivers(VMBus).
7888 In order to use SynIC, it has to be activated by setting this
7889 capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
7890 will disable the use of APIC hardware virtualization even if supported
7891 by the CPU, as it's incompatible with SynIC auto-EOI behavior.
7893 8.3 KVM_CAP_PPC_RADIX_MMU
7894 -------------------------
7898 This capability, if KVM_CHECK_EXTENSION indicates that it is
7899 available, means that the kernel can support guests using the
7900 radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
7903 8.4 KVM_CAP_PPC_HASH_MMU_V3
7904 ---------------------------
7908 This capability, if KVM_CHECK_EXTENSION indicates that it is
7909 available, means that the kernel can support guests using the
7910 hashed page table MMU defined in Power ISA V3.00 (as implemented in
7911 the POWER9 processor), including in-memory segment tables.
7916 :Architectures: mips
7918 This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
7919 it is available, means that full hardware assisted virtualization capabilities
7920 of the hardware are available for use through KVM. An appropriate
7921 KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
7924 If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
7925 available, it means that the VM is using full hardware assisted virtualization
7926 capabilities of the hardware. This is useful to check after creating a VM with
7927 KVM_VM_MIPS_DEFAULT.
7929 The value returned by KVM_CHECK_EXTENSION should be compared against known
7930 values (see below). All other values are reserved. This is to allow for the
7931 possibility of other hardware assisted virtualization implementations which
7932 may be incompatible with the MIPS VZ ASE.
7934 == ==========================================================================
7935 0 The trap & emulate implementation is in use to run guest code in user
7936 mode. Guest virtual memory segments are rearranged to fit the guest in the
7937 user mode address space.
7939 1 The MIPS VZ ASE is in use, providing full hardware assisted
7940 virtualization, including standard guest virtual memory segments.
7941 == ==========================================================================
7946 :Architectures: mips
7948 This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
7949 it is available, means that the trap & emulate implementation is available to
7950 run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
7951 assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
7952 to KVM_CREATE_VM to create a VM which utilises it.
7954 If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
7955 available, it means that the VM is using trap & emulate.
7957 8.7 KVM_CAP_MIPS_64BIT
7958 ----------------------
7960 :Architectures: mips
7962 This capability indicates the supported architecture type of the guest, i.e. the
7963 supported register and address width.
7965 The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
7966 kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
7967 be checked specifically against known values (see below). All other values are
7970 == ========================================================================
7971 0 MIPS32 or microMIPS32.
7972 Both registers and addresses are 32-bits wide.
7973 It will only be possible to run 32-bit guest code.
7975 1 MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
7976 Registers are 64-bits wide, but addresses are 32-bits wide.
7977 64-bit guest code may run but cannot access MIPS64 memory segments.
7978 It will also be possible to run 32-bit guest code.
7980 2 MIPS64 or microMIPS64 with access to all address segments.
7981 Both registers and addresses are 64-bits wide.
7982 It will be possible to run 64-bit or 32-bit guest code.
7983 == ========================================================================
7985 8.9 KVM_CAP_ARM_USER_IRQ
7986 ------------------------
7988 :Architectures: arm64
7990 This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
7991 that if userspace creates a VM without an in-kernel interrupt controller, it
7992 will be notified of changes to the output level of in-kernel emulated devices,
7993 which can generate virtual interrupts, presented to the VM.
7994 For such VMs, on every return to userspace, the kernel
7995 updates the vcpu's run->s.regs.device_irq_level field to represent the actual
7996 output level of the device.
7998 Whenever kvm detects a change in the device output level, kvm guarantees at
7999 least one return to userspace before running the VM. This exit could either
8000 be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
8001 userspace can always sample the device output level and re-compute the state of
8002 the userspace interrupt controller. Userspace should always check the state
8003 of run->s.regs.device_irq_level on every kvm exit.
8004 The value in run->s.regs.device_irq_level can represent both level and edge
8005 triggered interrupt signals, depending on the device. Edge triggered interrupt
8006 signals will exit to userspace with the bit in run->s.regs.device_irq_level
8007 set exactly once per edge signal.
8009 The field run->s.regs.device_irq_level is available independent of
8010 run->kvm_valid_regs or run->kvm_dirty_regs bits.
8012 If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
8013 number larger than 0 indicating the version of this capability is implemented
8014 and thereby which bits in run->s.regs.device_irq_level can signal values.
8016 Currently the following bits are defined for the device_irq_level bitmap::
8018 KVM_CAP_ARM_USER_IRQ >= 1:
8020 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
8021 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
8022 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
8024 Future versions of kvm may implement additional events. These will get
8025 indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
8028 8.10 KVM_CAP_PPC_SMT_POSSIBLE
8029 -----------------------------
8033 Querying this capability returns a bitmap indicating the possible
8034 virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
8035 (counting from the right) is set, then a virtual SMT mode of 2^N is
8038 8.11 KVM_CAP_HYPERV_SYNIC2
8039 --------------------------
8043 This capability enables a newer version of Hyper-V Synthetic interrupt
8044 controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
8045 doesn't clear SynIC message and event flags pages when they are enabled by
8046 writing to the respective MSRs.
8048 8.12 KVM_CAP_HYPERV_VP_INDEX
8049 ----------------------------
8053 This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
8054 value is used to denote the target vcpu for a SynIC interrupt. For
8055 compatibility, KVM initializes this msr to KVM's internal vcpu index. When this
8056 capability is absent, userspace can still query this msr's value.
8058 8.13 KVM_CAP_S390_AIS_MIGRATION
8059 -------------------------------
8061 :Architectures: s390
8064 This capability indicates if the flic device will be able to get/set the
8065 AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
8066 to discover this without having to create a flic device.
8068 8.14 KVM_CAP_S390_PSW
8069 ---------------------
8071 :Architectures: s390
8073 This capability indicates that the PSW is exposed via the kvm_run structure.
8075 8.15 KVM_CAP_S390_GMAP
8076 ----------------------
8078 :Architectures: s390
8080 This capability indicates that the user space memory used as guest mapping can
8081 be anywhere in the user memory address space, as long as the memory slots are
8082 aligned and sized to a segment (1MB) boundary.
8084 8.16 KVM_CAP_S390_COW
8085 ---------------------
8087 :Architectures: s390
8089 This capability indicates that the user space memory used as guest mapping can
8090 use copy-on-write semantics as well as dirty pages tracking via read-only page
8093 8.17 KVM_CAP_S390_BPB
8094 ---------------------
8096 :Architectures: s390
8098 This capability indicates that kvm will implement the interfaces to handle
8099 reset, migration and nested KVM for branch prediction blocking. The stfle
8100 facility 82 should not be provided to the guest without this capability.
8102 8.18 KVM_CAP_HYPERV_TLBFLUSH
8103 ----------------------------
8107 This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
8109 HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
8110 HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
8112 8.19 KVM_CAP_ARM_INJECT_SERROR_ESR
8113 ----------------------------------
8115 :Architectures: arm64
8117 This capability indicates that userspace can specify (via the
8118 KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
8119 takes a virtual SError interrupt exception.
8120 If KVM advertises this capability, userspace can only specify the ISS field for
8121 the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
8122 CPU when the exception is taken. If this virtual SError is taken to EL1 using
8123 AArch64, this value will be reported in the ISS field of ESR_ELx.
8125 See KVM_CAP_VCPU_EVENTS for more details.
8127 8.20 KVM_CAP_HYPERV_SEND_IPI
8128 ----------------------------
8132 This capability indicates that KVM supports paravirtualized Hyper-V IPI send
8134 HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.
8136 8.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH
8137 -----------------------------------
8141 This capability indicates that KVM running on top of Hyper-V hypervisor
8142 enables Direct TLB flush for its guests meaning that TLB flush
8143 hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM.
8144 Due to the different ABI for hypercall parameters between Hyper-V and
8145 KVM, enabling this capability effectively disables all hypercall
8146 handling by KVM (as some KVM hypercall may be mistakenly treated as TLB
8147 flush hypercalls by Hyper-V) so userspace should disable KVM identification
8148 in CPUID and only exposes Hyper-V identification. In this case, guest
8149 thinks it's running on Hyper-V and only use Hyper-V hypercalls.
8151 8.22 KVM_CAP_S390_VCPU_RESETS
8152 -----------------------------
8154 :Architectures: s390
8156 This capability indicates that the KVM_S390_NORMAL_RESET and
8157 KVM_S390_CLEAR_RESET ioctls are available.
8159 8.23 KVM_CAP_S390_PROTECTED
8160 ---------------------------
8162 :Architectures: s390
8164 This capability indicates that the Ultravisor has been initialized and
8165 KVM can therefore start protected VMs.
8166 This capability governs the KVM_S390_PV_COMMAND ioctl and the
8167 KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
8168 guests when the state change is invalid.
8170 8.24 KVM_CAP_STEAL_TIME
8171 -----------------------
8173 :Architectures: arm64, x86
8175 This capability indicates that KVM supports steal time accounting.
8176 When steal time accounting is supported it may be enabled with
8177 architecture-specific interfaces. This capability and the architecture-
8178 specific interfaces must be consistent, i.e. if one says the feature
8179 is supported, than the other should as well and vice versa. For arm64
8180 see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
8181 For x86 see Documentation/virt/kvm/x86/msr.rst "MSR_KVM_STEAL_TIME".
8183 8.25 KVM_CAP_S390_DIAG318
8184 -------------------------
8186 :Architectures: s390
8188 This capability enables a guest to set information about its control program
8189 (i.e. guest kernel type and version). The information is helpful during
8190 system/firmware service events, providing additional data about the guest
8191 environments running on the machine.
8193 The information is associated with the DIAGNOSE 0x318 instruction, which sets
8194 an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and
8195 a 7-byte Control Program Version Code (CPVC). The CPNC determines what
8196 environment the control program is running in (e.g. Linux, z/VM...), and the
8197 CPVC is used for information specific to OS (e.g. Linux version, Linux
8200 If this capability is available, then the CPNC and CPVC can be synchronized
8201 between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318).
8203 8.26 KVM_CAP_X86_USER_SPACE_MSR
8204 -------------------------------
8208 This capability indicates that KVM supports deflection of MSR reads and
8209 writes to user space. It can be enabled on a VM level. If enabled, MSR
8210 accesses that would usually trigger a #GP by KVM into the guest will
8211 instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
8212 KVM_EXIT_X86_WRMSR exit notifications.
8214 8.27 KVM_CAP_X86_MSR_FILTER
8215 ---------------------------
8219 This capability indicates that KVM supports that accesses to user defined MSRs
8220 may be rejected. With this capability exposed, KVM exports new VM ioctl
8221 KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR
8222 ranges that KVM should deny access to.
8224 In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
8225 trap and emulate MSRs that are outside of the scope of KVM as well as
8226 limit the attack surface on KVM's MSR emulation code.
8228 8.28 KVM_CAP_ENFORCE_PV_FEATURE_CPUID
8229 -------------------------------------
8233 When enabled, KVM will disable paravirtual features provided to the
8234 guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
8235 (0x40000001). Otherwise, a guest may use the paravirtual features
8236 regardless of what has actually been exposed through the CPUID leaf.
8238 8.29 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL
8239 ----------------------------------------------------------
8241 :Architectures: x86, arm64
8242 :Parameters: args[0] - size of the dirty log ring
8244 KVM is capable of tracking dirty memory using ring buffers that are
8245 mmapped into userspace; there is one dirty ring per vcpu.
8247 The dirty ring is available to userspace as an array of
8248 ``struct kvm_dirty_gfn``. Each dirty entry is defined as::
8250 struct kvm_dirty_gfn {
8252 __u32 slot; /* as_id | slot_id */
8256 The following values are defined for the flags field to define the
8257 current state of the entry::
8259 #define KVM_DIRTY_GFN_F_DIRTY BIT(0)
8260 #define KVM_DIRTY_GFN_F_RESET BIT(1)
8261 #define KVM_DIRTY_GFN_F_MASK 0x3
8263 Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM
8264 ioctl to enable this capability for the new guest and set the size of
8265 the rings. Enabling the capability is only allowed before creating any
8266 vCPU, and the size of the ring must be a power of two. The larger the
8267 ring buffer, the less likely the ring is full and the VM is forced to
8268 exit to userspace. The optimal size depends on the workload, but it is
8269 recommended that it be at least 64 KiB (4096 entries).
8271 Just like for dirty page bitmaps, the buffer tracks writes to
8272 all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was
8273 set in KVM_SET_USER_MEMORY_REGION. Once a memory region is registered
8274 with the flag set, userspace can start harvesting dirty pages from the
8277 An entry in the ring buffer can be unused (flag bits ``00``),
8278 dirty (flag bits ``01``) or harvested (flag bits ``1X``). The
8279 state machine for the entry is as follows::
8281 dirtied harvested reset
8282 00 -----------> 01 -------------> 1X -------+
8285 +------------------------------------------+
8287 To harvest the dirty pages, userspace accesses the mmapped ring buffer
8288 to read the dirty GFNs. If the flags has the DIRTY bit set (at this stage
8289 the RESET bit must be cleared), then it means this GFN is a dirty GFN.
8290 The userspace should harvest this GFN and mark the flags from state
8291 ``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set
8292 to show that this GFN is harvested and waiting for a reset), and move
8293 on to the next GFN. The userspace should continue to do this until the
8294 flags of a GFN have the DIRTY bit cleared, meaning that it has harvested
8295 all the dirty GFNs that were available.
8297 Note that on weakly ordered architectures, userspace accesses to the
8298 ring buffer (and more specifically the 'flags' field) must be ordered,
8299 using load-acquire/store-release accessors when available, or any
8300 other memory barrier that will ensure this ordering.
8302 It's not necessary for userspace to harvest the all dirty GFNs at once.
8303 However it must collect the dirty GFNs in sequence, i.e., the userspace
8304 program cannot skip one dirty GFN to collect the one next to it.
8306 After processing one or more entries in the ring buffer, userspace
8307 calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about
8308 it, so that the kernel will reprotect those collected GFNs.
8309 Therefore, the ioctl must be called *before* reading the content of
8312 The dirty ring can get full. When it happens, the KVM_RUN of the
8313 vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL.
8315 The dirty ring interface has a major difference comparing to the
8316 KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from
8317 userspace, it's still possible that the kernel has not yet flushed the
8318 processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the
8319 flushing is done by the KVM_GET_DIRTY_LOG ioctl). To achieve that, one
8320 needs to kick the vcpu out of KVM_RUN using a signal. The resulting
8321 vmexit ensures that all dirty GFNs are flushed to the dirty rings.
8323 NOTE: KVM_CAP_DIRTY_LOG_RING_ACQ_REL is the only capability that
8324 should be exposed by weakly ordered architecture, in order to indicate
8325 the additional memory ordering requirements imposed on userspace when
8326 reading the state of an entry and mutating it from DIRTY to HARVESTED.
8327 Architecture with TSO-like ordering (such as x86) are allowed to
8328 expose both KVM_CAP_DIRTY_LOG_RING and KVM_CAP_DIRTY_LOG_RING_ACQ_REL
8331 After enabling the dirty rings, the userspace needs to detect the
8332 capability of KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP to see whether the
8333 ring structures can be backed by per-slot bitmaps. With this capability
8334 advertised, it means the architecture can dirty guest pages without
8335 vcpu/ring context, so that some of the dirty information will still be
8336 maintained in the bitmap structure. KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP
8337 can't be enabled if the capability of KVM_CAP_DIRTY_LOG_RING_ACQ_REL
8338 hasn't been enabled, or any memslot has been existing.
8340 Note that the bitmap here is only a backup of the ring structure. The
8341 use of the ring and bitmap combination is only beneficial if there is
8342 only a very small amount of memory that is dirtied out of vcpu/ring
8343 context. Otherwise, the stand-alone per-slot bitmap mechanism needs to
8346 To collect dirty bits in the backup bitmap, userspace can use the same
8347 KVM_GET_DIRTY_LOG ioctl. KVM_CLEAR_DIRTY_LOG isn't needed as long as all
8348 the generation of the dirty bits is done in a single pass. Collecting
8349 the dirty bitmap should be the very last thing that the VMM does before
8350 considering the state as complete. VMM needs to ensure that the dirty
8351 state is final and avoid missing dirty pages from another ioctl ordered
8352 after the bitmap collection.
8354 NOTE: Multiple examples of using the backup bitmap: (1) save vgic/its
8355 tables through command KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_SAVE_TABLES} on
8356 KVM device "kvm-arm-vgic-its". (2) restore vgic/its tables through
8357 command KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_RESTORE_TABLES} on KVM device
8358 "kvm-arm-vgic-its". VGICv3 LPI pending status is restored. (3) save
8359 vgic3 pending table through KVM_DEV_ARM_VGIC_{GRP_CTRL, SAVE_PENDING_TABLES}
8360 command on KVM device "kvm-arm-vgic-v3".
8362 8.30 KVM_CAP_XEN_HVM
8363 --------------------
8367 This capability indicates the features that Xen supports for hosting Xen
8368 PVHVM guests. Valid flags are::
8370 #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR (1 << 0)
8371 #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL (1 << 1)
8372 #define KVM_XEN_HVM_CONFIG_SHARED_INFO (1 << 2)
8373 #define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 3)
8374 #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)
8375 #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5)
8376 #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)
8378 The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
8379 ioctl is available, for the guest to set its hypercall page.
8381 If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be
8382 provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page
8383 contents, to request that KVM generate hypercall page content automatically
8384 and also enable interception of guest hypercalls with KVM_EXIT_XEN.
8386 The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the
8387 KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and
8388 KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors
8389 for event channel upcalls when the evtchn_upcall_pending field of a vcpu's
8392 The KVM_XEN_HVM_CONFIG_RUNSTATE flag indicates that the runstate-related
8393 features KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR/_CURRENT/_DATA/_ADJUST are
8394 supported by the KVM_XEN_VCPU_SET_ATTR/KVM_XEN_VCPU_GET_ATTR ioctls.
8396 The KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL flag indicates that IRQ routing entries
8397 of the type KVM_IRQ_ROUTING_XEN_EVTCHN are supported, with the priority
8398 field set to indicate 2 level event channel delivery.
8400 The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates that KVM supports
8401 injecting event channel events directly into the guest with the
8402 KVM_XEN_HVM_EVTCHN_SEND ioctl. It also indicates support for the
8403 KVM_XEN_ATTR_TYPE_EVTCHN/XEN_VERSION HVM attributes and the
8404 KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID/TIMER/UPCALL_VECTOR vCPU attributes.
8405 related to event channel delivery, timers, and the XENVER_version
8408 The KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG flag indicates that KVM supports
8409 the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute in the KVM_XEN_SET_ATTR
8410 and KVM_XEN_GET_ATTR ioctls. This controls whether KVM will set the
8411 XEN_RUNSTATE_UPDATE flag in guest memory mapped vcpu_runstate_info during
8412 updates of the runstate information. Note that versions of KVM which support
8413 the RUNSTATE feature above, but not the RUNSTATE_UPDATE_FLAG feature, will
8414 always set the XEN_RUNSTATE_UPDATE flag when updating the guest structure,
8415 which is perhaps counterintuitive. When this flag is advertised, KVM will
8416 behave more correctly, not using the XEN_RUNSTATE_UPDATE flag until/unless
8417 specifically enabled (by the guest making the hypercall, causing the VMM
8418 to enable the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute).
8420 8.31 KVM_CAP_PPC_MULTITCE
8421 -------------------------
8423 :Capability: KVM_CAP_PPC_MULTITCE
8427 This capability means the kernel is capable of handling hypercalls
8428 H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
8429 space. This significantly accelerates DMA operations for PPC KVM guests.
8430 User space should expect that its handlers for these hypercalls
8431 are not going to be called if user space previously registered LIOBN
8432 in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
8434 In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
8435 user space might have to advertise it for the guest. For example,
8436 IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
8437 present in the "ibm,hypertas-functions" device-tree property.
8439 The hypercalls mentioned above may or may not be processed successfully
8440 in the kernel based fast path. If they can not be handled by the kernel,
8441 they will get passed on to user space. So user space still has to have
8442 an implementation for these despite the in kernel acceleration.
8444 This capability is always enabled.
8446 8.32 KVM_CAP_PTP_KVM
8447 --------------------
8449 :Architectures: arm64
8451 This capability indicates that the KVM virtual PTP service is
8452 supported in the host. A VMM can check whether the service is
8453 available to the guest on migration.
8455 8.33 KVM_CAP_HYPERV_ENFORCE_CPUID
8456 ---------------------------------
8460 When enabled, KVM will disable emulated Hyper-V features provided to the
8461 guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all
8462 currently implemented Hyper-V features are provided unconditionally when
8463 Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001)
8466 8.34 KVM_CAP_EXIT_HYPERCALL
8467 ---------------------------
8469 :Capability: KVM_CAP_EXIT_HYPERCALL
8473 This capability, if enabled, will cause KVM to exit to userspace
8474 with KVM_EXIT_HYPERCALL exit reason to process some hypercalls.
8476 Calling KVM_CHECK_EXTENSION for this capability will return a bitmask
8477 of hypercalls that can be configured to exit to userspace.
8478 Right now, the only such hypercall is KVM_HC_MAP_GPA_RANGE.
8480 The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset
8481 of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace
8482 the hypercalls whose corresponding bit is in the argument, and return
8483 ENOSYS for the others.
8485 8.35 KVM_CAP_PMU_CAPABILITY
8486 ---------------------------
8488 :Capability: KVM_CAP_PMU_CAPABILITY
8491 :Parameters: arg[0] is bitmask of PMU virtualization capabilities.
8492 :Returns: 0 on success, -EINVAL when arg[0] contains invalid bits
8494 This capability alters PMU virtualization in KVM.
8496 Calling KVM_CHECK_EXTENSION for this capability returns a bitmask of
8497 PMU virtualization capabilities that can be adjusted on a VM.
8499 The argument to KVM_ENABLE_CAP is also a bitmask and selects specific
8500 PMU virtualization capabilities to be applied to the VM. This can
8501 only be invoked on a VM prior to the creation of VCPUs.
8503 At this time, KVM_PMU_CAP_DISABLE is the only capability. Setting
8504 this capability will disable PMU virtualization for that VM. Usermode
8505 should adjust CPUID leaf 0xA to reflect that the PMU is disabled.
8507 8.36 KVM_CAP_ARM_SYSTEM_SUSPEND
8508 -------------------------------
8510 :Capability: KVM_CAP_ARM_SYSTEM_SUSPEND
8511 :Architectures: arm64
8514 When enabled, KVM will exit to userspace with KVM_EXIT_SYSTEM_EVENT of
8515 type KVM_SYSTEM_EVENT_SUSPEND to process the guest suspend request.
8517 8.37 KVM_CAP_S390_PROTECTED_DUMP
8518 --------------------------------
8520 :Capability: KVM_CAP_S390_PROTECTED_DUMP
8521 :Architectures: s390
8524 This capability indicates that KVM and the Ultravisor support dumping
8525 PV guests. The `KVM_PV_DUMP` command is available for the
8526 `KVM_S390_PV_COMMAND` ioctl and the `KVM_PV_INFO` command provides
8527 dump related UV data. Also the vcpu ioctl `KVM_S390_PV_CPU_COMMAND` is
8528 available and supports the `KVM_PV_DUMP_CPU` subcommand.
8530 8.38 KVM_CAP_VM_DISABLE_NX_HUGE_PAGES
8531 -------------------------------------
8533 :Capability: KVM_CAP_VM_DISABLE_NX_HUGE_PAGES
8536 :Parameters: arg[0] must be 0.
8537 :Returns: 0 on success, -EPERM if the userspace process does not
8538 have CAP_SYS_BOOT, -EINVAL if args[0] is not 0 or any vCPUs have been
8541 This capability disables the NX huge pages mitigation for iTLB MULTIHIT.
8543 The capability has no effect if the nx_huge_pages module parameter is not set.
8545 This capability may only be set before any vCPUs are created.
8547 8.39 KVM_CAP_S390_CPU_TOPOLOGY
8548 ------------------------------
8550 :Capability: KVM_CAP_S390_CPU_TOPOLOGY
8551 :Architectures: s390
8554 This capability indicates that KVM will provide the S390 CPU Topology
8555 facility which consist of the interpretation of the PTF instruction for
8556 the function code 2 along with interception and forwarding of both the
8557 PTF instruction with function codes 0 or 1 and the STSI(15,1,x)
8558 instruction to the userland hypervisor.
8560 The stfle facility 11, CPU Topology facility, should not be indicated
8561 to the guest without this capability.
8563 When this capability is present, KVM provides a new attribute group
8564 on vm fd, KVM_S390_VM_CPU_TOPOLOGY.
8565 This new attribute allows to get, set or clear the Modified Change
8566 Topology Report (MTCR) bit of the SCA through the kvm_device_attr
8569 When getting the Modified Change Topology Report value, the attr->addr
8570 must point to a byte where the value will be stored or retrieved from.
8572 8.40 KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
8573 ---------------------------------------
8575 :Capability: KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
8576 :Architectures: arm64
8578 :Parameters: arg[0] is the new split chunk size.
8579 :Returns: 0 on success, -EINVAL if any memslot was already created.
8581 This capability sets the chunk size used in Eager Page Splitting.
8583 Eager Page Splitting improves the performance of dirty-logging (used
8584 in live migrations) when guest memory is backed by huge-pages. It
8585 avoids splitting huge-pages (into PAGE_SIZE pages) on fault, by doing
8586 it eagerly when enabling dirty logging (with the
8587 KVM_MEM_LOG_DIRTY_PAGES flag for a memory region), or when using
8588 KVM_CLEAR_DIRTY_LOG.
8590 The chunk size specifies how many pages to break at a time, using a
8591 single allocation for each chunk. Bigger the chunk size, more pages
8592 need to be allocated ahead of time.
8594 The chunk size needs to be a valid block size. The list of acceptable
8595 block sizes is exposed in KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES as a
8596 64-bit bitmap (each bit describing a block size). The default value is
8597 0, to disable the eager page splitting.
8599 9. Known KVM API problems
8600 =========================
8602 In some cases, KVM's API has some inconsistencies or common pitfalls
8603 that userspace need to be aware of. This section details some of
8606 Most of them are architecture specific, so the section is split by
8612 ``KVM_GET_SUPPORTED_CPUID`` issues
8613 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8615 In general, ``KVM_GET_SUPPORTED_CPUID`` is designed so that it is possible
8616 to take its result and pass it directly to ``KVM_SET_CPUID2``. This section
8617 documents some cases in which that requires some care.
8622 CPU[EAX=1]:ECX[21] (X2APIC) is reported by ``KVM_GET_SUPPORTED_CPUID``,
8623 but it can only be enabled if ``KVM_CREATE_IRQCHIP`` or
8624 ``KVM_ENABLE_CAP(KVM_CAP_IRQCHIP_SPLIT)`` are used to enable in-kernel emulation of
8627 The same is true for the ``KVM_FEATURE_PV_UNHALT`` paravirtualized feature.
8629 CPU[EAX=1]:ECX[24] (TSC_DEADLINE) is not reported by ``KVM_GET_SUPPORTED_CPUID``.
8630 It can be enabled if ``KVM_CAP_TSC_DEADLINE_TIMER`` is present and the kernel
8631 has enabled in-kernel emulation of the local APIC.
8636 Several CPUID values include topology information for the host CPU:
8637 0x0b and 0x1f for Intel systems, 0x8000001e for AMD systems. Different
8638 versions of KVM return different values for this information and userspace
8639 should not rely on it. Currently they return all zeroes.
8641 If userspace wishes to set up a guest topology, it should be careful that
8642 the values of these three leaves differ for each CPU. In particular,
8643 the APIC ID is found in EDX for all subleaves of 0x0b and 0x1f, and in EAX
8644 for 0x8000001e; the latter also encodes the core id and node id in bits
8645 7:0 of EBX and ECX respectively.
8647 Obsolete ioctls and capabilities
8648 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8650 KVM_CAP_DISABLE_QUIRKS does not let userspace know which quirks are actually
8651 available. Use ``KVM_CHECK_EXTENSION(KVM_CAP_DISABLE_QUIRKS2)`` instead if
8654 Ordering of KVM_GET_*/KVM_SET_* ioctls
8655 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^