blob: 158805532083f160f8b8b0d752faca5d20f38c4f [file] [log] [blame]
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001The Definitive KVM (Kernel-based Virtual Machine) API Documentation
2===================================================================
3
41. General description
Jan Kiszka414fa982012-04-24 16:40:15 +02005----------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +03006
7The kvm API is a set of ioctls that are issued to control various aspects
Sean Christopherson5e124902019-02-15 12:48:38 -08008of a virtual machine. The ioctls belong to three classes:
Avi Kivity9c1b96e2009-06-09 12:37:58 +03009
10 - System ioctls: These query and set global attributes which affect the
11 whole kvm subsystem. In addition a system ioctl is used to create
Sean Christopherson5e124902019-02-15 12:48:38 -080012 virtual machines.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030013
14 - VM ioctls: These query and set attributes that affect an entire virtual
15 machine, for example memory layout. In addition a VM ioctl is used to
16 create virtual cpus (vcpus).
17
Sean Christopherson5e124902019-02-15 12:48:38 -080018 VM ioctls must be issued from the same process (address space) that was
19 used to create the VM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030020
21 - vcpu ioctls: These query and set attributes that control the operation
22 of a single virtual cpu.
23
Sean Christopherson5e124902019-02-15 12:48:38 -080024 vcpu ioctls should be issued from the same thread that was used to create
25 the vcpu, except for asynchronous vcpu ioctl that are marked as such in
26 the documentation. Otherwise, the first ioctl after switching threads
27 could see a performance impact.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030028
Jan Kiszka414fa982012-04-24 16:40:15 +020029
Wu Fengguang2044892d2009-12-24 09:04:16 +0800302. File descriptors
Jan Kiszka414fa982012-04-24 16:40:15 +020031-------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030032
33The kvm API is centered around file descriptors. An initial
34open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
35can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
Wu Fengguang2044892d2009-12-24 09:04:16 +080036handle will create a VM file descriptor which can be used to issue VM
Avi Kivity9c1b96e2009-06-09 12:37:58 +030037ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
38and return a file descriptor pointing to it. Finally, ioctls on a vcpu
39fd can be used to control the vcpu, including the important task of
40actually running guest code.
41
42In general file descriptors can be migrated among processes by means
43of fork() and the SCM_RIGHTS facility of unix domain socket. These
44kinds of tricks are explicitly not supported by kvm. While they will
45not cause harm to the host, their actual behavior is not guaranteed by
Sean Christopherson5e124902019-02-15 12:48:38 -080046the API. See "General description" for details on the ioctl usage
47model that is supported by KVM.
Jan Kiszka414fa982012-04-24 16:40:15 +020048
Sean Christophersoneca6be52019-02-15 12:48:40 -080049It is important to note that althought VM ioctls may only be issued from
50the process that created the VM, a VM's lifecycle is associated with its
51file descriptor, not its creator (process). In other words, the VM and
52its resources, *including the associated address space*, are not freed
53until the last reference to the VM's file descriptor has been released.
54For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
55not be freed until both the parent (original) process and its child have
56put their references to the VM's file descriptor.
57
58Because a VM's resources are not freed until the last reference to its
59file descriptor is released, creating additional references to a VM via
60via fork(), dup(), etc... without careful consideration is strongly
61discouraged and may have unwanted side effects, e.g. memory allocated
62by and on behalf of the VM's process may not be freed/unaccounted when
63the VM is shut down.
64
65
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300663. Extensions
Jan Kiszka414fa982012-04-24 16:40:15 +020067-------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030068
69As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
70incompatible change are allowed. However, there is an extension
71facility that allows backward-compatible extensions to the API to be
72queried and used.
73
Masanari Iidac9f3f2d2013-07-18 01:29:12 +090074The extension mechanism is not based on the Linux version number.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030075Instead, kvm defines extension identifiers and a facility to query
76whether a particular extension identifier is available. If it is, a
77set of ioctls is available for application use.
78
Jan Kiszka414fa982012-04-24 16:40:15 +020079
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300804. API description
Jan Kiszka414fa982012-04-24 16:40:15 +020081------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030082
83This section describes ioctls that can be used to control kvm guests.
84For each ioctl, the following information is provided along with a
85description:
86
87 Capability: which KVM extension provides this ioctl. Can be 'basic',
88 which means that is will be provided by any kernel that supports
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030089 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
Avi Kivity9c1b96e2009-06-09 12:37:58 +030090 means availability needs to be checked with KVM_CHECK_EXTENSION
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030091 (see section 4.4), or 'none' which means that while not all kernels
92 support this ioctl, there's no capability bit to check its
93 availability: for kernels that don't support the ioctl,
94 the ioctl returns -ENOTTY.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030095
96 Architectures: which instruction set architectures provide this ioctl.
97 x86 includes both i386 and x86_64.
98
99 Type: system, vm, or vcpu.
100
101 Parameters: what parameters are accepted by the ioctl.
102
103 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
104 are not detailed, but errors with specific meanings are.
105
Jan Kiszka414fa982012-04-24 16:40:15 +0200106
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001074.1 KVM_GET_API_VERSION
108
109Capability: basic
110Architectures: all
111Type: system ioctl
112Parameters: none
113Returns: the constant KVM_API_VERSION (=12)
114
115This identifies the API version as the stable kvm API. It is not
116expected that this number will change. However, Linux 2.6.20 and
1172.6.21 report earlier versions; these are not documented and not
118supported. Applications should refuse to run if KVM_GET_API_VERSION
119returns a value other than 12. If this check passes, all ioctls
120described as 'basic' will be available.
121
Jan Kiszka414fa982012-04-24 16:40:15 +0200122
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001234.2 KVM_CREATE_VM
124
125Capability: basic
126Architectures: all
127Type: system ioctl
Carsten Ottee08b9632012-01-04 10:25:20 +0100128Parameters: machine type identifier (KVM_VM_*)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300129Returns: a VM fd that can be used to control the new virtual machine.
130
Jann Hornbcb85c82017-04-24 11:16:49 +0200131The new VM has no virtual cpus and no memory.
James Hogana8a3c422017-03-14 10:15:19 +0000132You probably want to use 0 as machine type.
Carsten Ottee08b9632012-01-04 10:25:20 +0100133
134In order to create user controlled virtual machines on S390, check
135KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
136privileged user (CAP_SYS_ADMIN).
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300137
James Hogana8a3c422017-03-14 10:15:19 +0000138To use hardware assisted virtualization on MIPS (VZ ASE) rather than
139the default trap & emulate implementation (which changes the virtual
140memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the
141flag KVM_VM_MIPS_VZ.
142
Jan Kiszka414fa982012-04-24 16:40:15 +0200143
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100144On arm64, the physical address size for a VM (IPA Size limit) is limited
145to 40bits by default. The limit can be configured if the host supports the
146extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use
147KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type
148identifier, where IPA_Bits is the maximum width of any physical
149address used by the VM. The IPA_Bits is encoded in bits[7-0] of the
150machine type identifier.
151
152e.g, to configure a guest to use 48bit physical address size :
153
154 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48));
155
156The requested size (IPA_Bits) must be :
157 0 - Implies default size, 40bits (for backward compatibility)
158
159 or
160
161 N - Implies N bits, where N is a positive integer such that,
162 32 <= N <= Host_IPA_Limit
163
164Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and
165is dependent on the CPU capability and the kernel configuration. The limit can
166be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
167ioctl() at run-time.
168
169Please note that configuring the IPA size does not affect the capability
170exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
171size of the address translated by the stage2 level (guest physical to
172host physical address translations).
173
174
Tom Lendacky801e4592018-02-21 13:39:51 -06001754.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300176
Tom Lendacky801e4592018-02-21 13:39:51 -0600177Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300178Architectures: x86
Tom Lendacky801e4592018-02-21 13:39:51 -0600179Type: system ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300180Parameters: struct kvm_msr_list (in/out)
181Returns: 0 on success; -1 on error
182Errors:
Tom Lendacky801e4592018-02-21 13:39:51 -0600183 EFAULT: the msr index list cannot be read from or written to
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300184 E2BIG: the msr index list is to be to fit in the array specified by
185 the user.
186
187struct kvm_msr_list {
188 __u32 nmsrs; /* number of msrs in entries */
189 __u32 indices[0];
190};
191
Tom Lendacky801e4592018-02-21 13:39:51 -0600192The user fills in the size of the indices array in nmsrs, and in return
193kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
194indices array with their numbers.
195
196KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
197varies by kvm version and host processor, but does not change otherwise.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300198
Avi Kivity2e2602c2010-07-07 14:09:39 +0300199Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
200not returned in the MSR list, as different vcpus can have a different number
201of banks, as set via the KVM_X86_SETUP_MCE ioctl.
202
Tom Lendacky801e4592018-02-21 13:39:51 -0600203KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
204to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
205and processor features that are exposed via MSRs (e.g., VMX capabilities).
206This list also varies by kvm version and host processor, but does not change
207otherwise.
208
Jan Kiszka414fa982012-04-24 16:40:15 +0200209
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002104.4 KVM_CHECK_EXTENSION
211
Alexander Graf92b591a2014-07-14 18:33:08 +0200212Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300213Architectures: all
Alexander Graf92b591a2014-07-14 18:33:08 +0200214Type: system ioctl, vm ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300215Parameters: extension identifier (KVM_CAP_*)
216Returns: 0 if unsupported; 1 (or some other positive integer) if supported
217
218The API allows the application to query about extensions to the core
219kvm API. Userspace passes an extension identifier (an integer) and
220receives an integer that describes the extension availability.
221Generally 0 means no and 1 means yes, but some extensions may report
222additional information in the integer return value.
223
Alexander Graf92b591a2014-07-14 18:33:08 +0200224Based on their initialization different VMs may have different capabilities.
225It is thus encouraged to use the vm ioctl to query for capabilities (available
226with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
Jan Kiszka414fa982012-04-24 16:40:15 +0200227
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002284.5 KVM_GET_VCPU_MMAP_SIZE
229
230Capability: basic
231Architectures: all
232Type: system ioctl
233Parameters: none
234Returns: size of vcpu mmap area, in bytes
235
236The KVM_RUN ioctl (cf.) communicates with userspace via a shared
237memory region. This ioctl returns the size of that region. See the
238KVM_RUN documentation for details.
239
Jan Kiszka414fa982012-04-24 16:40:15 +0200240
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002414.6 KVM_SET_MEMORY_REGION
242
243Capability: basic
244Architectures: all
245Type: vm ioctl
246Parameters: struct kvm_memory_region (in)
247Returns: 0 on success, -1 on error
248
Avi Kivityb74a07b2010-06-21 11:48:05 +0300249This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300250
Jan Kiszka414fa982012-04-24 16:40:15 +0200251
Paul Bolle68ba6972011-02-15 00:05:59 +01002524.7 KVM_CREATE_VCPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300253
254Capability: basic
255Architectures: all
256Type: vm ioctl
257Parameters: vcpu id (apic id on x86)
258Returns: vcpu fd on success, -1 on error
259
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200260This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
261The vcpu id is an integer in the range [0, max_vcpu_id).
Sasha Levin8c3ba332011-07-18 17:17:15 +0300262
263The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
264the KVM_CHECK_EXTENSION ioctl() at run-time.
265The maximum possible value for max_vcpus can be retrieved using the
266KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
267
Pekka Enberg76d25402011-05-09 22:48:54 +0300268If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
269cpus max.
Sasha Levin8c3ba332011-07-18 17:17:15 +0300270If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
271same as the value returned from KVM_CAP_NR_VCPUS.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300272
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200273The maximum possible value for max_vcpu_id can be retrieved using the
274KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
275
276If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
277is the same as the value returned from KVM_CAP_MAX_VCPUS.
278
Paul Mackerras371fefd2011-06-29 00:23:08 +0000279On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
280threads in one or more virtual CPU cores. (This is because the
281hardware requires all the hardware threads in a CPU core to be in the
282same partition.) The KVM_CAP_PPC_SMT capability indicates the number
283of vcpus per virtual core (vcore). The vcore id is obtained by
284dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
285given vcore will always be in the same physical core as each other
286(though that might be a different physical core from time to time).
287Userspace can control the threading (SMT) mode of the guest by its
288allocation of vcpu ids. For example, if userspace wants
289single-threaded guest vcpus, it should make all vcpu ids be a multiple
290of the number of vcpus per vcore.
291
Carsten Otte5b1c1492012-01-04 10:25:23 +0100292For virtual cpus that have been created with S390 user controlled virtual
293machines, the resulting vcpu fd can be memory mapped at page offset
294KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
295cpu's hardware control block.
296
Jan Kiszka414fa982012-04-24 16:40:15 +0200297
Paul Bolle68ba6972011-02-15 00:05:59 +01002984.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300299
300Capability: basic
301Architectures: x86
302Type: vm ioctl
303Parameters: struct kvm_dirty_log (in/out)
304Returns: 0 on success, -1 on error
305
306/* for KVM_GET_DIRTY_LOG */
307struct kvm_dirty_log {
308 __u32 slot;
309 __u32 padding;
310 union {
311 void __user *dirty_bitmap; /* one bit per page */
312 __u64 padding;
313 };
314};
315
316Given a memory slot, return a bitmap containing any pages dirtied
317since the last call to this ioctl. Bit 0 is the first page in the
318memory slot. Ensure the entire structure is cleared to avoid padding
319issues.
320
Paolo Bonzinif481b062015-05-17 17:30:37 +0200321If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies
322the address space for which you want to return the dirty bitmap.
323They must be less than the value that KVM_CHECK_EXTENSION returns for
324the KVM_CAP_MULTI_ADDRESS_SPACE capability.
325
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +0200326The bits in the dirty bitmap are cleared before the ioctl returns, unless
327KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is enabled. For more information,
328see the description of the capability.
Jan Kiszka414fa982012-04-24 16:40:15 +0200329
Paul Bolle68ba6972011-02-15 00:05:59 +01003304.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300331
332Capability: basic
333Architectures: x86
334Type: vm ioctl
335Parameters: struct kvm_memory_alias (in)
336Returns: 0 (success), -1 (error)
337
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300338This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300339
Jan Kiszka414fa982012-04-24 16:40:15 +0200340
Paul Bolle68ba6972011-02-15 00:05:59 +01003414.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300342
343Capability: basic
344Architectures: all
345Type: vcpu ioctl
346Parameters: none
347Returns: 0 on success, -1 on error
348Errors:
349 EINTR: an unmasked signal is pending
350
351This ioctl is used to run a guest virtual cpu. While there are no
352explicit parameters, there is an implicit parameter block that can be
353obtained by mmap()ing the vcpu fd at offset 0, with the size given by
354KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
355kvm_run' (see below).
356
Jan Kiszka414fa982012-04-24 16:40:15 +0200357
Paul Bolle68ba6972011-02-15 00:05:59 +01003584.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300359
360Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +0100361Architectures: all except ARM, arm64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300362Type: vcpu ioctl
363Parameters: struct kvm_regs (out)
364Returns: 0 on success, -1 on error
365
366Reads the general purpose registers from the vcpu.
367
368/* x86 */
369struct kvm_regs {
370 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
371 __u64 rax, rbx, rcx, rdx;
372 __u64 rsi, rdi, rsp, rbp;
373 __u64 r8, r9, r10, r11;
374 __u64 r12, r13, r14, r15;
375 __u64 rip, rflags;
376};
377
James Hoganc2d2c212014-07-04 15:11:35 +0100378/* mips */
379struct kvm_regs {
380 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
381 __u64 gpr[32];
382 __u64 hi;
383 __u64 lo;
384 __u64 pc;
385};
386
Jan Kiszka414fa982012-04-24 16:40:15 +0200387
Paul Bolle68ba6972011-02-15 00:05:59 +01003884.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300389
390Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +0100391Architectures: all except ARM, arm64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300392Type: vcpu ioctl
393Parameters: struct kvm_regs (in)
394Returns: 0 on success, -1 on error
395
396Writes the general purpose registers into the vcpu.
397
398See KVM_GET_REGS for the data structure.
399
Jan Kiszka414fa982012-04-24 16:40:15 +0200400
Paul Bolle68ba6972011-02-15 00:05:59 +01004014.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300402
403Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500404Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300405Type: vcpu ioctl
406Parameters: struct kvm_sregs (out)
407Returns: 0 on success, -1 on error
408
409Reads special registers from the vcpu.
410
411/* x86 */
412struct kvm_sregs {
413 struct kvm_segment cs, ds, es, fs, gs, ss;
414 struct kvm_segment tr, ldt;
415 struct kvm_dtable gdt, idt;
416 __u64 cr0, cr2, cr3, cr4, cr8;
417 __u64 efer;
418 __u64 apic_base;
419 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
420};
421
Mihai Caraman68e2ffe2012-12-11 03:38:23 +0000422/* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
Scott Wood5ce941e2011-04-27 17:24:21 -0500423
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300424interrupt_bitmap is a bitmap of pending external interrupts. At most
425one bit may be set. This interrupt has been acknowledged by the APIC
426but not yet injected into the cpu core.
427
Jan Kiszka414fa982012-04-24 16:40:15 +0200428
Paul Bolle68ba6972011-02-15 00:05:59 +01004294.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300430
431Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500432Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300433Type: vcpu ioctl
434Parameters: struct kvm_sregs (in)
435Returns: 0 on success, -1 on error
436
437Writes special registers into the vcpu. See KVM_GET_SREGS for the
438data structures.
439
Jan Kiszka414fa982012-04-24 16:40:15 +0200440
Paul Bolle68ba6972011-02-15 00:05:59 +01004414.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300442
443Capability: basic
444Architectures: x86
445Type: vcpu ioctl
446Parameters: struct kvm_translation (in/out)
447Returns: 0 on success, -1 on error
448
449Translates a virtual address according to the vcpu's current address
450translation mode.
451
452struct kvm_translation {
453 /* in */
454 __u64 linear_address;
455
456 /* out */
457 __u64 physical_address;
458 __u8 valid;
459 __u8 writeable;
460 __u8 usermode;
461 __u8 pad[5];
462};
463
Jan Kiszka414fa982012-04-24 16:40:15 +0200464
Paul Bolle68ba6972011-02-15 00:05:59 +01004654.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300466
467Capability: basic
James Hoganc2d2c212014-07-04 15:11:35 +0100468Architectures: x86, ppc, mips
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300469Type: vcpu ioctl
470Parameters: struct kvm_interrupt (in)
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200471Returns: 0 on success, negative on failure.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300472
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200473Queues a hardware interrupt vector to be injected.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300474
475/* for KVM_INTERRUPT */
476struct kvm_interrupt {
477 /* in */
478 __u32 irq;
479};
480
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200481X86:
482
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200483Returns: 0 on success,
484 -EEXIST if an interrupt is already enqueued
485 -EINVAL the the irq number is invalid
486 -ENXIO if the PIC is in the kernel
487 -EFAULT if the pointer is invalid
488
489Note 'irq' is an interrupt vector, not an interrupt pin or line. This
490ioctl is useful if the in-kernel PIC is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300491
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200492PPC:
493
494Queues an external interrupt to be injected. This ioctl is overleaded
495with 3 different irq values:
496
497a) KVM_INTERRUPT_SET
498
499 This injects an edge type external interrupt into the guest once it's ready
500 to receive interrupts. When injected, the interrupt is done.
501
502b) KVM_INTERRUPT_UNSET
503
504 This unsets any pending interrupt.
505
506 Only available with KVM_CAP_PPC_UNSET_IRQ.
507
508c) KVM_INTERRUPT_SET_LEVEL
509
510 This injects a level type external interrupt into the guest context. The
511 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
512 is triggered.
513
514 Only available with KVM_CAP_PPC_IRQ_LEVEL.
515
516Note that any value for 'irq' other than the ones stated above is invalid
517and incurs unexpected behavior.
518
Sean Christopherson5e124902019-02-15 12:48:38 -0800519This is an asynchronous vcpu ioctl and can be invoked from any thread.
520
James Hoganc2d2c212014-07-04 15:11:35 +0100521MIPS:
522
523Queues an external interrupt to be injected into the virtual CPU. A negative
524interrupt number dequeues the interrupt.
525
Sean Christopherson5e124902019-02-15 12:48:38 -0800526This is an asynchronous vcpu ioctl and can be invoked from any thread.
527
Jan Kiszka414fa982012-04-24 16:40:15 +0200528
Paul Bolle68ba6972011-02-15 00:05:59 +01005294.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300530
531Capability: basic
532Architectures: none
533Type: vcpu ioctl
534Parameters: none)
535Returns: -1 on error
536
537Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
538
Jan Kiszka414fa982012-04-24 16:40:15 +0200539
Paul Bolle68ba6972011-02-15 00:05:59 +01005404.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300541
Tom Lendacky801e4592018-02-21 13:39:51 -0600542Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300543Architectures: x86
Tom Lendacky801e4592018-02-21 13:39:51 -0600544Type: system ioctl, vcpu ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300545Parameters: struct kvm_msrs (in/out)
Tom Lendacky801e4592018-02-21 13:39:51 -0600546Returns: number of msrs successfully returned;
547 -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300548
Tom Lendacky801e4592018-02-21 13:39:51 -0600549When used as a system ioctl:
550Reads the values of MSR-based features that are available for the VM. This
551is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
552The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
553in a system ioctl.
554
555When used as a vcpu ioctl:
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300556Reads model-specific registers from the vcpu. Supported msr indices can
Tom Lendacky801e4592018-02-21 13:39:51 -0600557be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300558
559struct kvm_msrs {
560 __u32 nmsrs; /* number of msrs in entries */
561 __u32 pad;
562
563 struct kvm_msr_entry entries[0];
564};
565
566struct kvm_msr_entry {
567 __u32 index;
568 __u32 reserved;
569 __u64 data;
570};
571
572Application code should set the 'nmsrs' member (which indicates the
573size of the entries array) and the 'index' member of each array entry.
574kvm will fill in the 'data' member.
575
Jan Kiszka414fa982012-04-24 16:40:15 +0200576
Paul Bolle68ba6972011-02-15 00:05:59 +01005774.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300578
579Capability: basic
580Architectures: x86
581Type: vcpu ioctl
582Parameters: struct kvm_msrs (in)
583Returns: 0 on success, -1 on error
584
585Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
586data structures.
587
588Application code should set the 'nmsrs' member (which indicates the
589size of the entries array), and the 'index' and 'data' members of each
590array entry.
591
Jan Kiszka414fa982012-04-24 16:40:15 +0200592
Paul Bolle68ba6972011-02-15 00:05:59 +01005934.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300594
595Capability: basic
596Architectures: x86
597Type: vcpu ioctl
598Parameters: struct kvm_cpuid (in)
599Returns: 0 on success, -1 on error
600
601Defines the vcpu responses to the cpuid instruction. Applications
602should use the KVM_SET_CPUID2 ioctl if available.
603
604
605struct kvm_cpuid_entry {
606 __u32 function;
607 __u32 eax;
608 __u32 ebx;
609 __u32 ecx;
610 __u32 edx;
611 __u32 padding;
612};
613
614/* for KVM_SET_CPUID */
615struct kvm_cpuid {
616 __u32 nent;
617 __u32 padding;
618 struct kvm_cpuid_entry entries[0];
619};
620
Jan Kiszka414fa982012-04-24 16:40:15 +0200621
Paul Bolle68ba6972011-02-15 00:05:59 +01006224.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300623
624Capability: basic
James Hogan572e0922014-07-04 15:11:33 +0100625Architectures: all
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300626Type: vcpu ioctl
627Parameters: struct kvm_signal_mask (in)
628Returns: 0 on success, -1 on error
629
630Defines which signals are blocked during execution of KVM_RUN. This
631signal mask temporarily overrides the threads signal mask. Any
632unblocked signal received (except SIGKILL and SIGSTOP, which retain
633their traditional behaviour) will cause KVM_RUN to return with -EINTR.
634
635Note the signal will only be delivered if not blocked by the original
636signal mask.
637
638/* for KVM_SET_SIGNAL_MASK */
639struct kvm_signal_mask {
640 __u32 len;
641 __u8 sigset[0];
642};
643
Jan Kiszka414fa982012-04-24 16:40:15 +0200644
Paul Bolle68ba6972011-02-15 00:05:59 +01006454.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300646
647Capability: basic
648Architectures: x86
649Type: vcpu ioctl
650Parameters: struct kvm_fpu (out)
651Returns: 0 on success, -1 on error
652
653Reads the floating point state from the vcpu.
654
655/* for KVM_GET_FPU and KVM_SET_FPU */
656struct kvm_fpu {
657 __u8 fpr[8][16];
658 __u16 fcw;
659 __u16 fsw;
660 __u8 ftwx; /* in fxsave format */
661 __u8 pad1;
662 __u16 last_opcode;
663 __u64 last_ip;
664 __u64 last_dp;
665 __u8 xmm[16][16];
666 __u32 mxcsr;
667 __u32 pad2;
668};
669
Jan Kiszka414fa982012-04-24 16:40:15 +0200670
Paul Bolle68ba6972011-02-15 00:05:59 +01006714.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300672
673Capability: basic
674Architectures: x86
675Type: vcpu ioctl
676Parameters: struct kvm_fpu (in)
677Returns: 0 on success, -1 on error
678
679Writes the floating point state to the vcpu.
680
681/* for KVM_GET_FPU and KVM_SET_FPU */
682struct kvm_fpu {
683 __u8 fpr[8][16];
684 __u16 fcw;
685 __u16 fsw;
686 __u8 ftwx; /* in fxsave format */
687 __u8 pad1;
688 __u16 last_opcode;
689 __u64 last_ip;
690 __u64 last_dp;
691 __u8 xmm[16][16];
692 __u32 mxcsr;
693 __u32 pad2;
694};
695
Jan Kiszka414fa982012-04-24 16:40:15 +0200696
Paul Bolle68ba6972011-02-15 00:05:59 +01006974.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300698
Cornelia Huck84223592013-07-15 13:36:01 +0200699Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
Tiejun Chenc32a4272014-11-20 11:07:18 +0100700Architectures: x86, ARM, arm64, s390
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300701Type: vm ioctl
702Parameters: none
703Returns: 0 on success, -1 on error
704
Andre Przywaraac3d3732014-06-03 10:26:30 +0200705Creates an interrupt controller model in the kernel.
706On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
707future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
708PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
709On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of
710KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
711KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
712On s390, a dummy irq routing table is created.
Cornelia Huck84223592013-07-15 13:36:01 +0200713
714Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
715before KVM_CREATE_IRQCHIP can be used.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300716
Jan Kiszka414fa982012-04-24 16:40:15 +0200717
Paul Bolle68ba6972011-02-15 00:05:59 +01007184.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300719
720Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100721Architectures: x86, arm, arm64
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300722Type: vm ioctl
723Parameters: struct kvm_irq_level
724Returns: 0 on success, -1 on error
725
726Sets the level of a GSI input to the interrupt controller model in the kernel.
Christoffer Dall86ce8532013-01-20 18:28:08 -0500727On some architectures it is required that an interrupt controller model has
728been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
729interrupts require the level to be set to 1 and then back to 0.
730
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500731On real hardware, interrupt pins can be active-low or active-high. This
732does not matter for the level field of struct kvm_irq_level: 1 always
733means active (asserted), 0 means inactive (deasserted).
734
735x86 allows the operating system to program the interrupt polarity
736(active-low/active-high) for level-triggered interrupts, and KVM used
737to consider the polarity. However, due to bitrot in the handling of
738active-low interrupts, the above convention is now valid on x86 too.
739This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
740should not present interrupts to the guest as active-low unless this
741capability is present (or unless it is not using the in-kernel irqchip,
742of course).
743
744
Marc Zyngier379e04c72013-04-02 17:46:31 +0100745ARM/arm64 can signal an interrupt either at the CPU level, or at the
746in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
747use PPIs designated for specific cpus. The irq field is interpreted
748like this:
Christoffer Dall86ce8532013-01-20 18:28:08 -0500749
750  bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 |
751 field: | irq_type | vcpu_index | irq_id |
752
753The irq_type field has the following values:
754- irq_type[0]: out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
755- irq_type[1]: in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
756 (the vcpu_index field is ignored)
757- irq_type[2]: in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
758
759(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
760
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500761In both cases, level is used to assert/deassert the line.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300762
763struct kvm_irq_level {
764 union {
765 __u32 irq; /* GSI */
766 __s32 status; /* not used for KVM_IRQ_LEVEL */
767 };
768 __u32 level; /* 0 or 1 */
769};
770
Jan Kiszka414fa982012-04-24 16:40:15 +0200771
Paul Bolle68ba6972011-02-15 00:05:59 +01007724.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300773
774Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100775Architectures: x86
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300776Type: vm ioctl
777Parameters: struct kvm_irqchip (in/out)
778Returns: 0 on success, -1 on error
779
780Reads the state of a kernel interrupt controller created with
781KVM_CREATE_IRQCHIP into a buffer provided by the caller.
782
783struct kvm_irqchip {
784 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
785 __u32 pad;
786 union {
787 char dummy[512]; /* reserving space */
788 struct kvm_pic_state pic;
789 struct kvm_ioapic_state ioapic;
790 } chip;
791};
792
Jan Kiszka414fa982012-04-24 16:40:15 +0200793
Paul Bolle68ba6972011-02-15 00:05:59 +01007944.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300795
796Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100797Architectures: x86
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300798Type: vm ioctl
799Parameters: struct kvm_irqchip (in)
800Returns: 0 on success, -1 on error
801
802Sets the state of a kernel interrupt controller created with
803KVM_CREATE_IRQCHIP from a buffer provided by the caller.
804
805struct kvm_irqchip {
806 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
807 __u32 pad;
808 union {
809 char dummy[512]; /* reserving space */
810 struct kvm_pic_state pic;
811 struct kvm_ioapic_state ioapic;
812 } chip;
813};
814
Jan Kiszka414fa982012-04-24 16:40:15 +0200815
Paul Bolle68ba6972011-02-15 00:05:59 +01008164.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700817
818Capability: KVM_CAP_XEN_HVM
819Architectures: x86
820Type: vm ioctl
821Parameters: struct kvm_xen_hvm_config (in)
822Returns: 0 on success, -1 on error
823
824Sets the MSR that the Xen HVM guest uses to initialize its hypercall
825page, and provides the starting address and size of the hypercall
826blobs in userspace. When the guest writes the MSR, kvm copies one
827page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
828memory.
829
830struct kvm_xen_hvm_config {
831 __u32 flags;
832 __u32 msr;
833 __u64 blob_addr_32;
834 __u64 blob_addr_64;
835 __u8 blob_size_32;
836 __u8 blob_size_64;
837 __u8 pad2[30];
838};
839
Jan Kiszka414fa982012-04-24 16:40:15 +0200840
Paul Bolle68ba6972011-02-15 00:05:59 +01008414.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400842
843Capability: KVM_CAP_ADJUST_CLOCK
844Architectures: x86
845Type: vm ioctl
846Parameters: struct kvm_clock_data (out)
847Returns: 0 on success, -1 on error
848
849Gets the current timestamp of kvmclock as seen by the current guest. In
850conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
851such as migration.
852
Paolo Bonzinie3fd9a92016-11-09 17:48:15 +0100853When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
854set of bits that KVM can return in struct kvm_clock_data's flag member.
855
856The only flag defined now is KVM_CLOCK_TSC_STABLE. If set, the returned
857value is the exact kvmclock value seen by all VCPUs at the instant
858when KVM_GET_CLOCK was called. If clear, the returned value is simply
859CLOCK_MONOTONIC plus a constant offset; the offset can be modified
860with KVM_SET_CLOCK. KVM will try to make all VCPUs follow this clock,
861but the exact value read by each VCPU could differ, because the host
862TSC is not stable.
863
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400864struct kvm_clock_data {
865 __u64 clock; /* kvmclock current value */
866 __u32 flags;
867 __u32 pad[9];
868};
869
Jan Kiszka414fa982012-04-24 16:40:15 +0200870
Paul Bolle68ba6972011-02-15 00:05:59 +01008714.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400872
873Capability: KVM_CAP_ADJUST_CLOCK
874Architectures: x86
875Type: vm ioctl
876Parameters: struct kvm_clock_data (in)
877Returns: 0 on success, -1 on error
878
Wu Fengguang2044892d2009-12-24 09:04:16 +0800879Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400880In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
881such as migration.
882
883struct kvm_clock_data {
884 __u64 clock; /* kvmclock current value */
885 __u32 flags;
886 __u32 pad[9];
887};
888
Jan Kiszka414fa982012-04-24 16:40:15 +0200889
Paul Bolle68ba6972011-02-15 00:05:59 +01008904.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100891
892Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100893Extended by: KVM_CAP_INTR_SHADOW
James Morseb0960b92018-07-19 16:24:25 +0100894Architectures: x86, arm, arm64
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100895Type: vcpu ioctl
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100896Parameters: struct kvm_vcpu_event (out)
897Returns: 0 on success, -1 on error
898
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100899X86:
900
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100901Gets currently pending exceptions, interrupts, and NMIs as well as related
902states of the vcpu.
903
904struct kvm_vcpu_events {
905 struct {
906 __u8 injected;
907 __u8 nr;
908 __u8 has_error_code;
Jim Mattson59073aa2018-10-16 14:29:20 -0700909 __u8 pending;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100910 __u32 error_code;
911 } exception;
912 struct {
913 __u8 injected;
914 __u8 nr;
915 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100916 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100917 } interrupt;
918 struct {
919 __u8 injected;
920 __u8 pending;
921 __u8 masked;
922 __u8 pad;
923 } nmi;
924 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100925 __u32 flags;
Paolo Bonzinif0778252015-04-01 15:06:40 +0200926 struct {
927 __u8 smm;
928 __u8 pending;
929 __u8 smm_inside_nmi;
930 __u8 latched_init;
931 } smi;
Jim Mattson59073aa2018-10-16 14:29:20 -0700932 __u8 reserved[27];
933 __u8 exception_has_payload;
934 __u64 exception_payload;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100935};
936
Jim Mattson59073aa2018-10-16 14:29:20 -0700937The following bits are defined in the flags field:
Jan Kiszka48005f62010-02-19 19:38:07 +0100938
Jim Mattson59073aa2018-10-16 14:29:20 -0700939- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that
Paolo Bonzinif0778252015-04-01 15:06:40 +0200940 interrupt.shadow contains a valid state.
941
Jim Mattson59073aa2018-10-16 14:29:20 -0700942- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a
943 valid state.
944
945- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the
946 exception_has_payload, exception_payload, and exception.pending
947 fields contain a valid state. This bit will be set whenever
948 KVM_CAP_EXCEPTION_PAYLOAD is enabled.
Jan Kiszka414fa982012-04-24 16:40:15 +0200949
James Morseb0960b92018-07-19 16:24:25 +0100950ARM/ARM64:
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100951
952If the guest accesses a device that is being emulated by the host kernel in
953such a way that a real device would generate a physical SError, KVM may make
954a virtual SError pending for that VCPU. This system error interrupt remains
955pending until the guest takes the exception by unmasking PSTATE.A.
956
957Running the VCPU may cause it to take a pending SError, or make an access that
958causes an SError to become pending. The event's description is only valid while
959the VPCU is not running.
960
961This API provides a way to read and write the pending 'event' state that is not
962visible to the guest. To save, restore or migrate a VCPU the struct representing
963the state can be read then written using this GET/SET API, along with the other
964guest-visible registers. It is not possible to 'cancel' an SError that has been
965made pending.
966
967A device being emulated in user-space may also wish to generate an SError. To do
968this the events structure can be populated by user-space. The current state
969should be read first, to ensure no existing SError is pending. If an existing
970SError is pending, the architecture's 'Multiple SError interrupts' rules should
971be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
972Serviceability (RAS) Specification").
973
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +0100974SError exceptions always have an ESR value. Some CPUs have the ability to
975specify what the virtual SError's ESR value should be. These systems will
Dongjiu Geng688e0582018-08-20 17:39:25 -0400976advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +0100977always have a non-zero value when read, and the agent making an SError pending
978should specify the ISS field in the lower 24 bits of exception.serror_esr. If
Dongjiu Geng688e0582018-08-20 17:39:25 -0400979the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +0100980with exception.has_esr as zero, KVM will choose an ESR.
981
982Specifying exception.has_esr on a system that does not support it will return
983-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
984will return -EINVAL.
985
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100986struct kvm_vcpu_events {
987 struct {
988 __u8 serror_pending;
989 __u8 serror_has_esr;
990 /* Align it to 8 bytes */
991 __u8 pad[6];
992 __u64 serror_esr;
993 } exception;
994 __u32 reserved[12];
995};
996
Paul Bolle68ba6972011-02-15 00:05:59 +01009974.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100998
999Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +01001000Extended by: KVM_CAP_INTR_SHADOW
James Morseb0960b92018-07-19 16:24:25 +01001001Architectures: x86, arm, arm64
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001002Type: vcpu ioctl
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001003Parameters: struct kvm_vcpu_event (in)
1004Returns: 0 on success, -1 on error
1005
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001006X86:
1007
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001008Set pending exceptions, interrupts, and NMIs as well as related states of the
1009vcpu.
1010
1011See KVM_GET_VCPU_EVENTS for the data structure.
1012
Jan Kiszkadab4b912009-12-06 18:24:15 +01001013Fields that may be modified asynchronously by running VCPUs can be excluded
Paolo Bonzinif0778252015-04-01 15:06:40 +02001014from the update. These fields are nmi.pending, sipi_vector, smi.smm,
1015smi.pending. Keep the corresponding bits in the flags field cleared to
1016suppress overwriting the current in-kernel state. The bits are:
Jan Kiszkadab4b912009-12-06 18:24:15 +01001017
1018KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
1019KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
Paolo Bonzinif0778252015-04-01 15:06:40 +02001020KVM_VCPUEVENT_VALID_SMM - transfer the smi sub-struct.
Jan Kiszkadab4b912009-12-06 18:24:15 +01001021
Jan Kiszka48005f62010-02-19 19:38:07 +01001022If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
1023the flags field to signal that interrupt.shadow contains a valid state and
1024shall be written into the VCPU.
1025
Paolo Bonzinif0778252015-04-01 15:06:40 +02001026KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
1027
Jim Mattson59073aa2018-10-16 14:29:20 -07001028If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD
1029can be set in the flags field to signal that the
1030exception_has_payload, exception_payload, and exception.pending fields
1031contain a valid state and shall be written into the VCPU.
1032
James Morseb0960b92018-07-19 16:24:25 +01001033ARM/ARM64:
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001034
1035Set the pending SError exception state for this VCPU. It is not possible to
1036'cancel' an Serror that has been made pending.
1037
1038See KVM_GET_VCPU_EVENTS for the data structure.
1039
Jan Kiszka414fa982012-04-24 16:40:15 +02001040
Paul Bolle68ba6972011-02-15 00:05:59 +010010414.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001042
1043Capability: KVM_CAP_DEBUGREGS
1044Architectures: x86
1045Type: vm ioctl
1046Parameters: struct kvm_debugregs (out)
1047Returns: 0 on success, -1 on error
1048
1049Reads debug registers from the vcpu.
1050
1051struct kvm_debugregs {
1052 __u64 db[4];
1053 __u64 dr6;
1054 __u64 dr7;
1055 __u64 flags;
1056 __u64 reserved[9];
1057};
1058
Jan Kiszka414fa982012-04-24 16:40:15 +02001059
Paul Bolle68ba6972011-02-15 00:05:59 +010010604.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001061
1062Capability: KVM_CAP_DEBUGREGS
1063Architectures: x86
1064Type: vm ioctl
1065Parameters: struct kvm_debugregs (in)
1066Returns: 0 on success, -1 on error
1067
1068Writes debug registers into the vcpu.
1069
1070See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
1071yet and must be cleared on entry.
1072
Jan Kiszka414fa982012-04-24 16:40:15 +02001073
Paul Bolle68ba6972011-02-15 00:05:59 +010010744.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001075
1076Capability: KVM_CAP_USER_MEM
1077Architectures: all
1078Type: vm ioctl
1079Parameters: struct kvm_userspace_memory_region (in)
1080Returns: 0 on success, -1 on error
1081
1082struct kvm_userspace_memory_region {
1083 __u32 slot;
1084 __u32 flags;
1085 __u64 guest_phys_addr;
1086 __u64 memory_size; /* bytes */
1087 __u64 userspace_addr; /* start of the userspace allocated memory */
1088};
1089
1090/* for kvm_memory_region::flags */
Xiao Guangrong4d8b81a2012-08-21 11:02:51 +08001091#define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
1092#define KVM_MEM_READONLY (1UL << 1)
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001093
1094This ioctl allows the user to create or modify a guest physical memory
1095slot. When changing an existing slot, it may be moved in the guest
1096physical memory space, or its flags may be modified. It may not be
1097resized. Slots may not overlap in guest physical address space.
Linu Cheriana677e702017-03-08 11:38:32 +05301098Bits 0-15 of "slot" specifies the slot id and this value should be
1099less than the maximum number of user memory slots supported per VM.
1100The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS,
1101if this capability is supported by the architecture.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001102
Paolo Bonzinif481b062015-05-17 17:30:37 +02001103If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1104specifies the address space which is being modified. They must be
1105less than the value that KVM_CHECK_EXTENSION returns for the
1106KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
1107are unrelated; the restriction on overlapping slots only applies within
1108each address space.
1109
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001110Memory for the region is taken starting at the address denoted by the
1111field userspace_addr, which must point at user addressable memory for
1112the entire memory slot size. Any object may back this memory, including
1113anonymous memory, ordinary files, and hugetlbfs.
1114
1115It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1116be identical. This allows large pages in the guest to be backed by large
1117pages in the host.
1118
Takuya Yoshikawa75d61fb2013-01-30 19:40:41 +09001119The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1120KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
1121writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
1122use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1123to make a new slot read-only. In this case, writes to this memory will be
1124posted to userspace as KVM_EXIT_MMIO exits.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001125
Jan Kiszka7efd8fa2012-09-07 13:17:47 +02001126When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1127the memory region are automatically reflected into the guest. For example, an
1128mmap() that affects the region will be made visible immediately. Another
1129example is madvise(MADV_DROP).
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001130
1131It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
1132The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
1133allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001134
Jan Kiszka414fa982012-04-24 16:40:15 +02001135
Paul Bolle68ba6972011-02-15 00:05:59 +010011364.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +02001137
1138Capability: KVM_CAP_SET_TSS_ADDR
1139Architectures: x86
1140Type: vm ioctl
1141Parameters: unsigned long tss_address (in)
1142Returns: 0 on success, -1 on error
1143
1144This ioctl defines the physical address of a three-page region in the guest
1145physical address space. The region must be within the first 4GB of the
1146guest physical address space and must not conflict with any memory slot
1147or any mmio address. The guest may malfunction if it accesses this memory
1148region.
1149
1150This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1151because of a quirk in the virtualization implementation (see the internals
1152documentation when it pops into existence).
1153
Jan Kiszka414fa982012-04-24 16:40:15 +02001154
Paul Bolle68ba6972011-02-15 00:05:59 +010011554.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +01001156
Paolo Bonzinie5d83c72017-02-16 10:40:56 +01001157Capability: KVM_CAP_ENABLE_CAP
1158Architectures: mips, ppc, s390
1159Type: vcpu ioctl
1160Parameters: struct kvm_enable_cap (in)
1161Returns: 0 on success; -1 on error
1162
1163Capability: KVM_CAP_ENABLE_CAP_VM
1164Architectures: all
1165Type: vcpu ioctl
Alexander Graf71fbfd52010-03-24 21:48:29 +01001166Parameters: struct kvm_enable_cap (in)
1167Returns: 0 on success; -1 on error
1168
1169+Not all extensions are enabled by default. Using this ioctl the application
1170can enable an extension, making it available to the guest.
1171
1172On systems that do not support this ioctl, it always fails. On systems that
1173do support it, it only works for extensions that are supported for enablement.
1174
1175To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1176be used.
1177
1178struct kvm_enable_cap {
1179 /* in */
1180 __u32 cap;
1181
1182The capability that is supposed to get enabled.
1183
1184 __u32 flags;
1185
1186A bitfield indicating future enhancements. Has to be 0 for now.
1187
1188 __u64 args[4];
1189
1190Arguments for enabling a feature. If a feature needs initial values to
1191function properly, this is the place to put them.
1192
1193 __u8 pad[64];
1194};
1195
Cornelia Huckd938dc52013-10-23 18:26:34 +02001196The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1197for vm-wide capabilities.
Jan Kiszka414fa982012-04-24 16:40:15 +02001198
Paul Bolle68ba6972011-02-15 00:05:59 +010011994.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +03001200
1201Capability: KVM_CAP_MP_STATE
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001202Architectures: x86, s390, arm, arm64
Avi Kivityb843f062010-04-25 15:51:46 +03001203Type: vcpu ioctl
1204Parameters: struct kvm_mp_state (out)
1205Returns: 0 on success; -1 on error
1206
1207struct kvm_mp_state {
1208 __u32 mp_state;
1209};
1210
1211Returns the vcpu's current "multiprocessing state" (though also valid on
1212uniprocessor guests).
1213
1214Possible values are:
1215
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001216 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running [x86,arm/arm64]
Avi Kivityb843f062010-04-25 15:51:46 +03001217 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
Tiejun Chenc32a4272014-11-20 11:07:18 +01001218 which has not yet received an INIT signal [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001219 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
Tiejun Chenc32a4272014-11-20 11:07:18 +01001220 now ready for a SIPI [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001221 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
Tiejun Chenc32a4272014-11-20 11:07:18 +01001222 is waiting for an interrupt [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001223 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Tiejun Chenc32a4272014-11-20 11:07:18 +01001224 accessible via KVM_GET_VCPU_EVENTS) [x86]
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001225 - KVM_MP_STATE_STOPPED: the vcpu is stopped [s390,arm/arm64]
David Hildenbrand6352e4d2014-04-10 17:35:00 +02001226 - KVM_MP_STATE_CHECK_STOP: the vcpu is in a special error state [s390]
1227 - KVM_MP_STATE_OPERATING: the vcpu is operating (running or halted)
1228 [s390]
1229 - KVM_MP_STATE_LOAD: the vcpu is in a special load/startup state
1230 [s390]
Avi Kivityb843f062010-04-25 15:51:46 +03001231
Tiejun Chenc32a4272014-11-20 11:07:18 +01001232On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001233in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1234these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001235
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001236For arm/arm64:
1237
1238The only states that are valid are KVM_MP_STATE_STOPPED and
1239KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001240
Paul Bolle68ba6972011-02-15 00:05:59 +010012414.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +03001242
1243Capability: KVM_CAP_MP_STATE
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001244Architectures: x86, s390, arm, arm64
Avi Kivityb843f062010-04-25 15:51:46 +03001245Type: vcpu ioctl
1246Parameters: struct kvm_mp_state (in)
1247Returns: 0 on success; -1 on error
1248
1249Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1250arguments.
1251
Tiejun Chenc32a4272014-11-20 11:07:18 +01001252On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001253in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1254these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001255
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001256For arm/arm64:
1257
1258The only states that are valid are KVM_MP_STATE_STOPPED and
1259KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001260
Paul Bolle68ba6972011-02-15 00:05:59 +010012614.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +03001262
1263Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1264Architectures: x86
1265Type: vm ioctl
1266Parameters: unsigned long identity (in)
1267Returns: 0 on success, -1 on error
1268
1269This ioctl defines the physical address of a one-page region in the guest
1270physical address space. The region must be within the first 4GB of the
1271guest physical address space and must not conflict with any memory slot
1272or any mmio address. The guest may malfunction if it accesses this memory
1273region.
1274
David Hildenbrand726b99c2017-08-24 20:51:35 +02001275Setting the address to 0 will result in resetting the address to its default
1276(0xfffbc000).
1277
Avi Kivity47dbb842010-04-29 12:08:56 +03001278This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1279because of a quirk in the virtualization implementation (see the internals
1280documentation when it pops into existence).
1281
David Hildenbrand1af1ac92017-08-24 20:51:36 +02001282Fails if any VCPU has already been created.
Jan Kiszka414fa982012-04-24 16:40:15 +02001283
Paul Bolle68ba6972011-02-15 00:05:59 +010012844.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +03001285
1286Capability: KVM_CAP_SET_BOOT_CPU_ID
Tiejun Chenc32a4272014-11-20 11:07:18 +01001287Architectures: x86
Avi Kivity57bc24c2010-04-29 12:12:57 +03001288Type: vm ioctl
1289Parameters: unsigned long vcpu_id
1290Returns: 0 on success, -1 on error
1291
1292Define which vcpu is the Bootstrap Processor (BSP). Values are the same
1293as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
1294is vcpu 0.
1295
Jan Kiszka414fa982012-04-24 16:40:15 +02001296
Paul Bolle68ba6972011-02-15 00:05:59 +010012974.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001298
1299Capability: KVM_CAP_XSAVE
1300Architectures: x86
1301Type: vcpu ioctl
1302Parameters: struct kvm_xsave (out)
1303Returns: 0 on success, -1 on error
1304
1305struct kvm_xsave {
1306 __u32 region[1024];
1307};
1308
1309This ioctl would copy current vcpu's xsave struct to the userspace.
1310
Jan Kiszka414fa982012-04-24 16:40:15 +02001311
Paul Bolle68ba6972011-02-15 00:05:59 +010013124.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001313
1314Capability: KVM_CAP_XSAVE
1315Architectures: x86
1316Type: vcpu ioctl
1317Parameters: struct kvm_xsave (in)
1318Returns: 0 on success, -1 on error
1319
1320struct kvm_xsave {
1321 __u32 region[1024];
1322};
1323
1324This ioctl would copy userspace's xsave struct to the kernel.
1325
Jan Kiszka414fa982012-04-24 16:40:15 +02001326
Paul Bolle68ba6972011-02-15 00:05:59 +010013274.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001328
1329Capability: KVM_CAP_XCRS
1330Architectures: x86
1331Type: vcpu ioctl
1332Parameters: struct kvm_xcrs (out)
1333Returns: 0 on success, -1 on error
1334
1335struct kvm_xcr {
1336 __u32 xcr;
1337 __u32 reserved;
1338 __u64 value;
1339};
1340
1341struct kvm_xcrs {
1342 __u32 nr_xcrs;
1343 __u32 flags;
1344 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1345 __u64 padding[16];
1346};
1347
1348This ioctl would copy current vcpu's xcrs to the userspace.
1349
Jan Kiszka414fa982012-04-24 16:40:15 +02001350
Paul Bolle68ba6972011-02-15 00:05:59 +010013514.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001352
1353Capability: KVM_CAP_XCRS
1354Architectures: x86
1355Type: vcpu ioctl
1356Parameters: struct kvm_xcrs (in)
1357Returns: 0 on success, -1 on error
1358
1359struct kvm_xcr {
1360 __u32 xcr;
1361 __u32 reserved;
1362 __u64 value;
1363};
1364
1365struct kvm_xcrs {
1366 __u32 nr_xcrs;
1367 __u32 flags;
1368 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1369 __u64 padding[16];
1370};
1371
1372This ioctl would set vcpu's xcr to the value userspace specified.
1373
Jan Kiszka414fa982012-04-24 16:40:15 +02001374
Paul Bolle68ba6972011-02-15 00:05:59 +010013754.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001376
1377Capability: KVM_CAP_EXT_CPUID
1378Architectures: x86
1379Type: system ioctl
1380Parameters: struct kvm_cpuid2 (in/out)
1381Returns: 0 on success, -1 on error
1382
1383struct kvm_cpuid2 {
1384 __u32 nent;
1385 __u32 padding;
1386 struct kvm_cpuid_entry2 entries[0];
1387};
1388
Borislav Petkov9c15bb12013-09-22 16:44:50 +02001389#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
1390#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
1391#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
Avi Kivityd1535132010-07-14 09:45:21 +03001392
1393struct kvm_cpuid_entry2 {
1394 __u32 function;
1395 __u32 index;
1396 __u32 flags;
1397 __u32 eax;
1398 __u32 ebx;
1399 __u32 ecx;
1400 __u32 edx;
1401 __u32 padding[3];
1402};
1403
Jim Mattsondf9cb9c2018-05-24 11:59:54 -07001404This ioctl returns x86 cpuid features which are supported by both the
1405hardware and kvm in its default configuration. Userspace can use the
1406information returned by this ioctl to construct cpuid information (for
1407KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1408userspace capabilities, and with user requirements (for example, the
1409user may wish to constrain cpuid to emulate older hardware, or for
1410feature consistency across a cluster).
1411
1412Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1413expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1414its default configuration. If userspace enables such capabilities, it
1415is responsible for modifying the results of this ioctl appropriately.
Avi Kivityd1535132010-07-14 09:45:21 +03001416
1417Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1418with the 'nent' field indicating the number of entries in the variable-size
1419array 'entries'. If the number of entries is too low to describe the cpu
1420capabilities, an error (E2BIG) is returned. If the number is too high,
1421the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1422number is just right, the 'nent' field is adjusted to the number of valid
1423entries in the 'entries' array, which is then filled.
1424
1425The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001426with unknown or unsupported features masked out. Some features (for example,
1427x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1428emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001429
1430 function: the eax value used to obtain the entry
1431 index: the ecx value used to obtain the entry (for entries that are
1432 affected by ecx)
1433 flags: an OR of zero or more of the following:
1434 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1435 if the index field is valid
1436 KVM_CPUID_FLAG_STATEFUL_FUNC:
1437 if cpuid for this function returns different values for successive
1438 invocations; there will be several entries with the same function,
1439 all with this flag set
1440 KVM_CPUID_FLAG_STATE_READ_NEXT:
1441 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1442 the first entry to be read by a cpu
1443 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1444 this function/index combination
1445
Jan Kiszka4d25a0662011-12-21 12:28:29 +01001446The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1447as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1448support. Instead it is reported via
1449
1450 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1451
1452if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1453feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1454
Jan Kiszka414fa982012-04-24 16:40:15 +02001455
Paul Bolle68ba6972011-02-15 00:05:59 +010014564.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001457
1458Capability: KVM_CAP_PPC_GET_PVINFO
1459Architectures: ppc
1460Type: vm ioctl
1461Parameters: struct kvm_ppc_pvinfo (out)
1462Returns: 0 on success, !0 on error
1463
1464struct kvm_ppc_pvinfo {
1465 __u32 flags;
1466 __u32 hcall[4];
1467 __u8 pad[108];
1468};
1469
1470This ioctl fetches PV specific information that need to be passed to the guest
1471using the device tree or other means from vm context.
1472
Liu Yu-B132019202e072012-07-03 05:48:52 +00001473The hcall array defines 4 instructions that make up a hypercall.
Alexander Graf15711e92010-07-29 14:48:08 +02001474
1475If any additional field gets added to this structure later on, a bit for that
1476additional piece of information will be set in the flags bitmap.
1477
Liu Yu-B132019202e072012-07-03 05:48:52 +00001478The flags bitmap is defined as:
1479
1480 /* the host supports the ePAPR idle hcall
1481 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
Jan Kiszka414fa982012-04-24 16:40:15 +02001482
Paul Bolle68ba6972011-02-15 00:05:59 +010014834.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001484
1485Capability: KVM_CAP_IRQ_ROUTING
Eric Auger180ae7b2016-07-22 16:20:41 +00001486Architectures: x86 s390 arm arm64
Jan Kiszka49f48172010-11-16 22:30:07 +01001487Type: vm ioctl
1488Parameters: struct kvm_irq_routing (in)
1489Returns: 0 on success, -1 on error
1490
1491Sets the GSI routing table entries, overwriting any previously set entries.
1492
Eric Auger180ae7b2016-07-22 16:20:41 +00001493On arm/arm64, GSI routing has the following limitation:
1494- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1495
Jan Kiszka49f48172010-11-16 22:30:07 +01001496struct kvm_irq_routing {
1497 __u32 nr;
1498 __u32 flags;
1499 struct kvm_irq_routing_entry entries[0];
1500};
1501
1502No flags are specified so far, the corresponding field must be set to zero.
1503
1504struct kvm_irq_routing_entry {
1505 __u32 gsi;
1506 __u32 type;
1507 __u32 flags;
1508 __u32 pad;
1509 union {
1510 struct kvm_irq_routing_irqchip irqchip;
1511 struct kvm_irq_routing_msi msi;
Cornelia Huck84223592013-07-15 13:36:01 +02001512 struct kvm_irq_routing_s390_adapter adapter;
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001513 struct kvm_irq_routing_hv_sint hv_sint;
Jan Kiszka49f48172010-11-16 22:30:07 +01001514 __u32 pad[8];
1515 } u;
1516};
1517
1518/* gsi routing entry types */
1519#define KVM_IRQ_ROUTING_IRQCHIP 1
1520#define KVM_IRQ_ROUTING_MSI 2
Cornelia Huck84223592013-07-15 13:36:01 +02001521#define KVM_IRQ_ROUTING_S390_ADAPTER 3
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001522#define KVM_IRQ_ROUTING_HV_SINT 4
Jan Kiszka49f48172010-11-16 22:30:07 +01001523
Eric Auger76a10b82016-07-22 16:20:37 +00001524flags:
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001525- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1526 type, specifies that the devid field contains a valid value. The per-VM
1527 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1528 the device ID. If this capability is not available, userspace should
1529 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Eric Auger76a10b82016-07-22 16:20:37 +00001530- zero otherwise
Jan Kiszka49f48172010-11-16 22:30:07 +01001531
1532struct kvm_irq_routing_irqchip {
1533 __u32 irqchip;
1534 __u32 pin;
1535};
1536
1537struct kvm_irq_routing_msi {
1538 __u32 address_lo;
1539 __u32 address_hi;
1540 __u32 data;
Eric Auger76a10b82016-07-22 16:20:37 +00001541 union {
1542 __u32 pad;
1543 __u32 devid;
1544 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001545};
1546
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001547If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1548for the device that wrote the MSI message. For PCI, this is usually a
1549BFD identifier in the lower 16 bits.
Eric Auger76a10b82016-07-22 16:20:37 +00001550
Radim Krčmář371313132016-07-12 22:09:27 +02001551On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1552feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
1553address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
1554address_hi must be zero.
1555
Cornelia Huck84223592013-07-15 13:36:01 +02001556struct kvm_irq_routing_s390_adapter {
1557 __u64 ind_addr;
1558 __u64 summary_addr;
1559 __u64 ind_offset;
1560 __u32 summary_offset;
1561 __u32 adapter_id;
1562};
1563
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001564struct kvm_irq_routing_hv_sint {
1565 __u32 vcpu;
1566 __u32 sint;
1567};
Jan Kiszka414fa982012-04-24 16:40:15 +02001568
Jan Kiszka414fa982012-04-24 16:40:15 +02001569
15704.55 KVM_SET_TSC_KHZ
Joerg Roedel92a1f122011-03-25 09:44:51 +01001571
1572Capability: KVM_CAP_TSC_CONTROL
1573Architectures: x86
1574Type: vcpu ioctl
1575Parameters: virtual tsc_khz
1576Returns: 0 on success, -1 on error
1577
1578Specifies the tsc frequency for the virtual machine. The unit of the
1579frequency is KHz.
1580
Jan Kiszka414fa982012-04-24 16:40:15 +02001581
15824.56 KVM_GET_TSC_KHZ
Joerg Roedel92a1f122011-03-25 09:44:51 +01001583
1584Capability: KVM_CAP_GET_TSC_KHZ
1585Architectures: x86
1586Type: vcpu ioctl
1587Parameters: none
1588Returns: virtual tsc-khz on success, negative value on error
1589
1590Returns the tsc frequency of the guest. The unit of the return value is
1591KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1592error.
1593
Jan Kiszka414fa982012-04-24 16:40:15 +02001594
15954.57 KVM_GET_LAPIC
Avi Kivitye7677932011-05-11 08:30:51 -04001596
1597Capability: KVM_CAP_IRQCHIP
1598Architectures: x86
1599Type: vcpu ioctl
1600Parameters: struct kvm_lapic_state (out)
1601Returns: 0 on success, -1 on error
1602
1603#define KVM_APIC_REG_SIZE 0x400
1604struct kvm_lapic_state {
1605 char regs[KVM_APIC_REG_SIZE];
1606};
1607
1608Reads the Local APIC registers and copies them into the input argument. The
1609data format and layout are the same as documented in the architecture manual.
1610
Radim Krčmář371313132016-07-12 22:09:27 +02001611If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
1612enabled, then the format of APIC_ID register depends on the APIC mode
1613(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in
1614the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID
1615which is stored in bits 31-24 of the APIC register, or equivalently in
1616byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then
1617be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
1618
1619If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
1620always uses xAPIC format.
1621
Jan Kiszka414fa982012-04-24 16:40:15 +02001622
16234.58 KVM_SET_LAPIC
Avi Kivitye7677932011-05-11 08:30:51 -04001624
1625Capability: KVM_CAP_IRQCHIP
1626Architectures: x86
1627Type: vcpu ioctl
1628Parameters: struct kvm_lapic_state (in)
1629Returns: 0 on success, -1 on error
1630
1631#define KVM_APIC_REG_SIZE 0x400
1632struct kvm_lapic_state {
1633 char regs[KVM_APIC_REG_SIZE];
1634};
1635
Masanari Iidadf5cbb22014-03-21 10:04:30 +09001636Copies the input argument into the Local APIC registers. The data format
Avi Kivitye7677932011-05-11 08:30:51 -04001637and layout are the same as documented in the architecture manual.
1638
Radim Krčmář371313132016-07-12 22:09:27 +02001639The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
1640regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
1641See the note in KVM_GET_LAPIC.
1642
Jan Kiszka414fa982012-04-24 16:40:15 +02001643
16444.59 KVM_IOEVENTFD
Sasha Levin55399a02011-05-28 14:12:30 +03001645
1646Capability: KVM_CAP_IOEVENTFD
1647Architectures: all
1648Type: vm ioctl
1649Parameters: struct kvm_ioeventfd (in)
1650Returns: 0 on success, !0 on error
1651
1652This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1653within the guest. A guest write in the registered address will signal the
1654provided event instead of triggering an exit.
1655
1656struct kvm_ioeventfd {
1657 __u64 datamatch;
1658 __u64 addr; /* legal pio/mmio address */
Jason Wange9ea5062015-09-15 14:41:59 +08001659 __u32 len; /* 0, 1, 2, 4, or 8 bytes */
Sasha Levin55399a02011-05-28 14:12:30 +03001660 __s32 fd;
1661 __u32 flags;
1662 __u8 pad[36];
1663};
1664
Cornelia Huck2b834512013-02-28 12:33:20 +01001665For the special case of virtio-ccw devices on s390, the ioevent is matched
1666to a subchannel/virtqueue tuple instead.
1667
Sasha Levin55399a02011-05-28 14:12:30 +03001668The following flags are defined:
1669
1670#define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1671#define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1672#define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
Cornelia Huck2b834512013-02-28 12:33:20 +01001673#define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
1674 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
Sasha Levin55399a02011-05-28 14:12:30 +03001675
1676If datamatch flag is set, the event will be signaled only if the written value
1677to the registered address is equal to datamatch in struct kvm_ioeventfd.
1678
Cornelia Huck2b834512013-02-28 12:33:20 +01001679For virtio-ccw devices, addr contains the subchannel id and datamatch the
1680virtqueue index.
1681
Jason Wange9ea5062015-09-15 14:41:59 +08001682With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
1683the kernel will ignore the length of guest write and may get a faster vmexit.
1684The speedup may only apply to specific architectures, but the ioeventfd will
1685work anyway.
Jan Kiszka414fa982012-04-24 16:40:15 +02001686
16874.60 KVM_DIRTY_TLB
Scott Wooddc83b8b2011-08-18 15:25:21 -05001688
1689Capability: KVM_CAP_SW_TLB
1690Architectures: ppc
1691Type: vcpu ioctl
1692Parameters: struct kvm_dirty_tlb (in)
1693Returns: 0 on success, -1 on error
1694
1695struct kvm_dirty_tlb {
1696 __u64 bitmap;
1697 __u32 num_dirty;
1698};
1699
1700This must be called whenever userspace has changed an entry in the shared
1701TLB, prior to calling KVM_RUN on the associated vcpu.
1702
1703The "bitmap" field is the userspace address of an array. This array
1704consists of a number of bits, equal to the total number of TLB entries as
1705determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
1706nearest multiple of 64.
1707
1708Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
1709array.
1710
1711The array is little-endian: the bit 0 is the least significant bit of the
1712first byte, bit 8 is the least significant bit of the second byte, etc.
1713This avoids any complications with differing word sizes.
1714
1715The "num_dirty" field is a performance hint for KVM to determine whether it
1716should skip processing the bitmap and just invalidate everything. It must
1717be set to the number of set bits in the bitmap.
1718
Jan Kiszka414fa982012-04-24 16:40:15 +02001719
David Gibson54738c02011-06-29 00:22:41 +000017204.62 KVM_CREATE_SPAPR_TCE
1721
1722Capability: KVM_CAP_SPAPR_TCE
1723Architectures: powerpc
1724Type: vm ioctl
1725Parameters: struct kvm_create_spapr_tce (in)
1726Returns: file descriptor for manipulating the created TCE table
1727
1728This creates a virtual TCE (translation control entry) table, which
1729is an IOMMU for PAPR-style virtual I/O. It is used to translate
1730logical addresses used in virtual I/O into guest physical addresses,
1731and provides a scatter/gather capability for PAPR virtual I/O.
1732
1733/* for KVM_CAP_SPAPR_TCE */
1734struct kvm_create_spapr_tce {
1735 __u64 liobn;
1736 __u32 window_size;
1737};
1738
1739The liobn field gives the logical IO bus number for which to create a
1740TCE table. The window_size field specifies the size of the DMA window
1741which this TCE table will translate - the table will contain one 64
1742bit TCE entry for every 4kiB of the DMA window.
1743
1744When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1745table has been created using this ioctl(), the kernel will handle it
1746in real mode, updating the TCE table. H_PUT_TCE calls for other
1747liobns will cause a vm exit and must be handled by userspace.
1748
1749The return value is a file descriptor which can be passed to mmap(2)
1750to map the created TCE table into userspace. This lets userspace read
1751the entries written by kernel-handled H_PUT_TCE calls, and also lets
1752userspace update the TCE table directly which is useful in some
1753circumstances.
1754
Jan Kiszka414fa982012-04-24 16:40:15 +02001755
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +000017564.63 KVM_ALLOCATE_RMA
1757
1758Capability: KVM_CAP_PPC_RMA
1759Architectures: powerpc
1760Type: vm ioctl
1761Parameters: struct kvm_allocate_rma (out)
1762Returns: file descriptor for mapping the allocated RMA
1763
1764This allocates a Real Mode Area (RMA) from the pool allocated at boot
1765time by the kernel. An RMA is a physically-contiguous, aligned region
1766of memory used on older POWER processors to provide the memory which
1767will be accessed by real-mode (MMU off) accesses in a KVM guest.
1768POWER processors support a set of sizes for the RMA that usually
1769includes 64MB, 128MB, 256MB and some larger powers of two.
1770
1771/* for KVM_ALLOCATE_RMA */
1772struct kvm_allocate_rma {
1773 __u64 rma_size;
1774};
1775
1776The return value is a file descriptor which can be passed to mmap(2)
1777to map the allocated RMA into userspace. The mapped area can then be
1778passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1779RMA for a virtual machine. The size of the RMA in bytes (which is
1780fixed at host kernel boot time) is returned in the rma_size field of
1781the argument structure.
1782
1783The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1784is supported; 2 if the processor requires all virtual machines to have
1785an RMA, or 1 if the processor can use an RMA but doesn't require it,
1786because it supports the Virtual RMA (VRMA) facility.
1787
Jan Kiszka414fa982012-04-24 16:40:15 +02001788
Avi Kivity3f745f12011-12-07 12:42:47 +020017894.64 KVM_NMI
1790
1791Capability: KVM_CAP_USER_NMI
1792Architectures: x86
1793Type: vcpu ioctl
1794Parameters: none
1795Returns: 0 on success, -1 on error
1796
1797Queues an NMI on the thread's vcpu. Note this is well defined only
1798when KVM_CREATE_IRQCHIP has not been called, since this is an interface
1799between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
1800has been called, this interface is completely emulated within the kernel.
1801
1802To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
1803following algorithm:
1804
Masanari Iida5d4f6f32015-10-04 00:46:21 +09001805 - pause the vcpu
Avi Kivity3f745f12011-12-07 12:42:47 +02001806 - read the local APIC's state (KVM_GET_LAPIC)
1807 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
1808 - if so, issue KVM_NMI
1809 - resume the vcpu
1810
1811Some guests configure the LINT1 NMI input to cause a panic, aiding in
1812debugging.
1813
Jan Kiszka414fa982012-04-24 16:40:15 +02001814
Alexander Grafe24ed812011-09-14 10:02:41 +020018154.65 KVM_S390_UCAS_MAP
Carsten Otte27e03932012-01-04 10:25:21 +01001816
1817Capability: KVM_CAP_S390_UCONTROL
1818Architectures: s390
1819Type: vcpu ioctl
1820Parameters: struct kvm_s390_ucas_mapping (in)
1821Returns: 0 in case of success
1822
1823The parameter is defined like this:
1824 struct kvm_s390_ucas_mapping {
1825 __u64 user_addr;
1826 __u64 vcpu_addr;
1827 __u64 length;
1828 };
1829
1830This ioctl maps the memory at "user_addr" with the length "length" to
1831the vcpu's address space starting at "vcpu_addr". All parameters need to
Anatol Pomozovf884ab12013-05-08 16:56:16 -07001832be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01001833
Jan Kiszka414fa982012-04-24 16:40:15 +02001834
Alexander Grafe24ed812011-09-14 10:02:41 +020018354.66 KVM_S390_UCAS_UNMAP
Carsten Otte27e03932012-01-04 10:25:21 +01001836
1837Capability: KVM_CAP_S390_UCONTROL
1838Architectures: s390
1839Type: vcpu ioctl
1840Parameters: struct kvm_s390_ucas_mapping (in)
1841Returns: 0 in case of success
1842
1843The parameter is defined like this:
1844 struct kvm_s390_ucas_mapping {
1845 __u64 user_addr;
1846 __u64 vcpu_addr;
1847 __u64 length;
1848 };
1849
1850This ioctl unmaps the memory in the vcpu's address space starting at
1851"vcpu_addr" with the length "length". The field "user_addr" is ignored.
Anatol Pomozovf884ab12013-05-08 16:56:16 -07001852All parameters need to be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01001853
Jan Kiszka414fa982012-04-24 16:40:15 +02001854
Alexander Grafe24ed812011-09-14 10:02:41 +020018554.67 KVM_S390_VCPU_FAULT
Carsten Otteccc79102012-01-04 10:25:26 +01001856
1857Capability: KVM_CAP_S390_UCONTROL
1858Architectures: s390
1859Type: vcpu ioctl
1860Parameters: vcpu absolute address (in)
1861Returns: 0 in case of success
1862
1863This call creates a page table entry on the virtual cpu's address space
1864(for user controlled virtual machines) or the virtual machine's address
1865space (for regular virtual machines). This only works for minor faults,
1866thus it's recommended to access subject memory page via the user page
1867table upfront. This is useful to handle validity intercepts for user
1868controlled virtual machines to fault in the virtual cpu's lowcore pages
1869prior to calling the KVM_RUN ioctl.
1870
Jan Kiszka414fa982012-04-24 16:40:15 +02001871
Alexander Grafe24ed812011-09-14 10:02:41 +020018724.68 KVM_SET_ONE_REG
1873
1874Capability: KVM_CAP_ONE_REG
1875Architectures: all
1876Type: vcpu ioctl
1877Parameters: struct kvm_one_reg (in)
1878Returns: 0 on success, negative value on failure
1879
1880struct kvm_one_reg {
1881 __u64 id;
1882 __u64 addr;
1883};
1884
1885Using this ioctl, a single vcpu register can be set to a specific value
1886defined by user space with the passed in struct kvm_one_reg, where id
1887refers to the register identifier as described below and addr is a pointer
1888to a variable with the respective size. There can be architecture agnostic
1889and architecture specific registers. Each have their own range of operation
1890and their own constants and width. To keep track of the implemented
1891registers, find a list below:
1892
James Hoganbf5590f2014-07-04 15:11:34 +01001893 Arch | Register | Width (bits)
1894 | |
1895 PPC | KVM_REG_PPC_HIOR | 64
1896 PPC | KVM_REG_PPC_IAC1 | 64
1897 PPC | KVM_REG_PPC_IAC2 | 64
1898 PPC | KVM_REG_PPC_IAC3 | 64
1899 PPC | KVM_REG_PPC_IAC4 | 64
1900 PPC | KVM_REG_PPC_DAC1 | 64
1901 PPC | KVM_REG_PPC_DAC2 | 64
1902 PPC | KVM_REG_PPC_DABR | 64
1903 PPC | KVM_REG_PPC_DSCR | 64
1904 PPC | KVM_REG_PPC_PURR | 64
1905 PPC | KVM_REG_PPC_SPURR | 64
1906 PPC | KVM_REG_PPC_DAR | 64
1907 PPC | KVM_REG_PPC_DSISR | 32
1908 PPC | KVM_REG_PPC_AMR | 64
1909 PPC | KVM_REG_PPC_UAMOR | 64
1910 PPC | KVM_REG_PPC_MMCR0 | 64
1911 PPC | KVM_REG_PPC_MMCR1 | 64
1912 PPC | KVM_REG_PPC_MMCRA | 64
1913 PPC | KVM_REG_PPC_MMCR2 | 64
1914 PPC | KVM_REG_PPC_MMCRS | 64
1915 PPC | KVM_REG_PPC_SIAR | 64
1916 PPC | KVM_REG_PPC_SDAR | 64
1917 PPC | KVM_REG_PPC_SIER | 64
1918 PPC | KVM_REG_PPC_PMC1 | 32
1919 PPC | KVM_REG_PPC_PMC2 | 32
1920 PPC | KVM_REG_PPC_PMC3 | 32
1921 PPC | KVM_REG_PPC_PMC4 | 32
1922 PPC | KVM_REG_PPC_PMC5 | 32
1923 PPC | KVM_REG_PPC_PMC6 | 32
1924 PPC | KVM_REG_PPC_PMC7 | 32
1925 PPC | KVM_REG_PPC_PMC8 | 32
1926 PPC | KVM_REG_PPC_FPR0 | 64
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001927 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001928 PPC | KVM_REG_PPC_FPR31 | 64
1929 PPC | KVM_REG_PPC_VR0 | 128
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001930 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001931 PPC | KVM_REG_PPC_VR31 | 128
1932 PPC | KVM_REG_PPC_VSR0 | 128
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001933 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001934 PPC | KVM_REG_PPC_VSR31 | 128
1935 PPC | KVM_REG_PPC_FPSCR | 64
1936 PPC | KVM_REG_PPC_VSCR | 32
1937 PPC | KVM_REG_PPC_VPA_ADDR | 64
1938 PPC | KVM_REG_PPC_VPA_SLB | 128
1939 PPC | KVM_REG_PPC_VPA_DTL | 128
1940 PPC | KVM_REG_PPC_EPCR | 32
1941 PPC | KVM_REG_PPC_EPR | 32
1942 PPC | KVM_REG_PPC_TCR | 32
1943 PPC | KVM_REG_PPC_TSR | 32
1944 PPC | KVM_REG_PPC_OR_TSR | 32
1945 PPC | KVM_REG_PPC_CLEAR_TSR | 32
1946 PPC | KVM_REG_PPC_MAS0 | 32
1947 PPC | KVM_REG_PPC_MAS1 | 32
1948 PPC | KVM_REG_PPC_MAS2 | 64
1949 PPC | KVM_REG_PPC_MAS7_3 | 64
1950 PPC | KVM_REG_PPC_MAS4 | 32
1951 PPC | KVM_REG_PPC_MAS6 | 32
1952 PPC | KVM_REG_PPC_MMUCFG | 32
1953 PPC | KVM_REG_PPC_TLB0CFG | 32
1954 PPC | KVM_REG_PPC_TLB1CFG | 32
1955 PPC | KVM_REG_PPC_TLB2CFG | 32
1956 PPC | KVM_REG_PPC_TLB3CFG | 32
1957 PPC | KVM_REG_PPC_TLB0PS | 32
1958 PPC | KVM_REG_PPC_TLB1PS | 32
1959 PPC | KVM_REG_PPC_TLB2PS | 32
1960 PPC | KVM_REG_PPC_TLB3PS | 32
1961 PPC | KVM_REG_PPC_EPTCFG | 32
1962 PPC | KVM_REG_PPC_ICP_STATE | 64
1963 PPC | KVM_REG_PPC_TB_OFFSET | 64
1964 PPC | KVM_REG_PPC_SPMC1 | 32
1965 PPC | KVM_REG_PPC_SPMC2 | 32
1966 PPC | KVM_REG_PPC_IAMR | 64
1967 PPC | KVM_REG_PPC_TFHAR | 64
1968 PPC | KVM_REG_PPC_TFIAR | 64
1969 PPC | KVM_REG_PPC_TEXASR | 64
1970 PPC | KVM_REG_PPC_FSCR | 64
1971 PPC | KVM_REG_PPC_PSPB | 32
1972 PPC | KVM_REG_PPC_EBBHR | 64
1973 PPC | KVM_REG_PPC_EBBRR | 64
1974 PPC | KVM_REG_PPC_BESCR | 64
1975 PPC | KVM_REG_PPC_TAR | 64
1976 PPC | KVM_REG_PPC_DPDES | 64
1977 PPC | KVM_REG_PPC_DAWR | 64
1978 PPC | KVM_REG_PPC_DAWRX | 64
1979 PPC | KVM_REG_PPC_CIABR | 64
1980 PPC | KVM_REG_PPC_IC | 64
1981 PPC | KVM_REG_PPC_VTB | 64
1982 PPC | KVM_REG_PPC_CSIGR | 64
1983 PPC | KVM_REG_PPC_TACR | 64
1984 PPC | KVM_REG_PPC_TCSCR | 64
1985 PPC | KVM_REG_PPC_PID | 64
1986 PPC | KVM_REG_PPC_ACOP | 64
1987 PPC | KVM_REG_PPC_VRSAVE | 32
Paolo Bonzinicc568ea2014-08-05 09:55:22 +02001988 PPC | KVM_REG_PPC_LPCR | 32
1989 PPC | KVM_REG_PPC_LPCR_64 | 64
James Hoganbf5590f2014-07-04 15:11:34 +01001990 PPC | KVM_REG_PPC_PPR | 64
1991 PPC | KVM_REG_PPC_ARCH_COMPAT | 32
1992 PPC | KVM_REG_PPC_DABRX | 32
1993 PPC | KVM_REG_PPC_WORT | 64
Bharat Bhushanbc8a4e52014-08-13 14:40:06 +05301994 PPC | KVM_REG_PPC_SPRG9 | 64
1995 PPC | KVM_REG_PPC_DBSR | 32
Paul Mackerrase9cf1e02016-11-18 13:11:42 +11001996 PPC | KVM_REG_PPC_TIDR | 64
1997 PPC | KVM_REG_PPC_PSSCR | 64
Paul Mackerras58555642018-01-12 20:55:20 +11001998 PPC | KVM_REG_PPC_DEC_EXPIRY | 64
Paul Mackerras30323412018-10-08 16:31:13 +11001999 PPC | KVM_REG_PPC_PTCR | 64
James Hoganbf5590f2014-07-04 15:11:34 +01002000 PPC | KVM_REG_PPC_TM_GPR0 | 64
Michael Neuling3b783472013-09-03 11:13:12 +10002001 ...
James Hoganbf5590f2014-07-04 15:11:34 +01002002 PPC | KVM_REG_PPC_TM_GPR31 | 64
2003 PPC | KVM_REG_PPC_TM_VSR0 | 128
Michael Neuling3b783472013-09-03 11:13:12 +10002004 ...
James Hoganbf5590f2014-07-04 15:11:34 +01002005 PPC | KVM_REG_PPC_TM_VSR63 | 128
2006 PPC | KVM_REG_PPC_TM_CR | 64
2007 PPC | KVM_REG_PPC_TM_LR | 64
2008 PPC | KVM_REG_PPC_TM_CTR | 64
2009 PPC | KVM_REG_PPC_TM_FPSCR | 64
2010 PPC | KVM_REG_PPC_TM_AMR | 64
2011 PPC | KVM_REG_PPC_TM_PPR | 64
2012 PPC | KVM_REG_PPC_TM_VRSAVE | 64
2013 PPC | KVM_REG_PPC_TM_VSCR | 32
2014 PPC | KVM_REG_PPC_TM_DSCR | 64
2015 PPC | KVM_REG_PPC_TM_TAR | 64
Paul Mackerras0d808df2016-11-07 15:09:58 +11002016 PPC | KVM_REG_PPC_TM_XER | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002017 | |
2018 MIPS | KVM_REG_MIPS_R0 | 64
2019 ...
2020 MIPS | KVM_REG_MIPS_R31 | 64
2021 MIPS | KVM_REG_MIPS_HI | 64
2022 MIPS | KVM_REG_MIPS_LO | 64
2023 MIPS | KVM_REG_MIPS_PC | 64
2024 MIPS | KVM_REG_MIPS_CP0_INDEX | 32
James Hogan013044c2016-12-07 17:16:37 +00002025 MIPS | KVM_REG_MIPS_CP0_ENTRYLO0 | 64
2026 MIPS | KVM_REG_MIPS_CP0_ENTRYLO1 | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002027 MIPS | KVM_REG_MIPS_CP0_CONTEXT | 64
James Hogandffe0422017-03-14 10:15:34 +00002028 MIPS | KVM_REG_MIPS_CP0_CONTEXTCONFIG| 32
James Hoganc2d2c212014-07-04 15:11:35 +01002029 MIPS | KVM_REG_MIPS_CP0_USERLOCAL | 64
James Hogandffe0422017-03-14 10:15:34 +00002030 MIPS | KVM_REG_MIPS_CP0_XCONTEXTCONFIG| 64
James Hoganc2d2c212014-07-04 15:11:35 +01002031 MIPS | KVM_REG_MIPS_CP0_PAGEMASK | 32
James Hoganc992a4f2017-03-14 10:15:31 +00002032 MIPS | KVM_REG_MIPS_CP0_PAGEGRAIN | 32
James Hogan4b7de022017-03-14 10:15:35 +00002033 MIPS | KVM_REG_MIPS_CP0_SEGCTL0 | 64
2034 MIPS | KVM_REG_MIPS_CP0_SEGCTL1 | 64
2035 MIPS | KVM_REG_MIPS_CP0_SEGCTL2 | 64
James Hogan5a2f3522017-03-14 10:15:36 +00002036 MIPS | KVM_REG_MIPS_CP0_PWBASE | 64
2037 MIPS | KVM_REG_MIPS_CP0_PWFIELD | 64
2038 MIPS | KVM_REG_MIPS_CP0_PWSIZE | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002039 MIPS | KVM_REG_MIPS_CP0_WIRED | 32
James Hogan5a2f3522017-03-14 10:15:36 +00002040 MIPS | KVM_REG_MIPS_CP0_PWCTL | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002041 MIPS | KVM_REG_MIPS_CP0_HWRENA | 32
2042 MIPS | KVM_REG_MIPS_CP0_BADVADDR | 64
James Hoganedc89262017-03-14 10:15:33 +00002043 MIPS | KVM_REG_MIPS_CP0_BADINSTR | 32
2044 MIPS | KVM_REG_MIPS_CP0_BADINSTRP | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002045 MIPS | KVM_REG_MIPS_CP0_COUNT | 32
2046 MIPS | KVM_REG_MIPS_CP0_ENTRYHI | 64
2047 MIPS | KVM_REG_MIPS_CP0_COMPARE | 32
2048 MIPS | KVM_REG_MIPS_CP0_STATUS | 32
James Hoganad58d4d2015-02-02 22:55:17 +00002049 MIPS | KVM_REG_MIPS_CP0_INTCTL | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002050 MIPS | KVM_REG_MIPS_CP0_CAUSE | 32
2051 MIPS | KVM_REG_MIPS_CP0_EPC | 64
James Hogan1068eaa2014-06-26 13:56:52 +01002052 MIPS | KVM_REG_MIPS_CP0_PRID | 32
James Hogan7801bbe2016-11-14 23:59:27 +00002053 MIPS | KVM_REG_MIPS_CP0_EBASE | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002054 MIPS | KVM_REG_MIPS_CP0_CONFIG | 32
2055 MIPS | KVM_REG_MIPS_CP0_CONFIG1 | 32
2056 MIPS | KVM_REG_MIPS_CP0_CONFIG2 | 32
2057 MIPS | KVM_REG_MIPS_CP0_CONFIG3 | 32
James Hoganc7716072014-06-26 15:11:29 +01002058 MIPS | KVM_REG_MIPS_CP0_CONFIG4 | 32
2059 MIPS | KVM_REG_MIPS_CP0_CONFIG5 | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002060 MIPS | KVM_REG_MIPS_CP0_CONFIG7 | 32
James Hoganc992a4f2017-03-14 10:15:31 +00002061 MIPS | KVM_REG_MIPS_CP0_XCONTEXT | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002062 MIPS | KVM_REG_MIPS_CP0_ERROREPC | 64
James Hogan05108702016-06-15 19:29:56 +01002063 MIPS | KVM_REG_MIPS_CP0_KSCRATCH1 | 64
2064 MIPS | KVM_REG_MIPS_CP0_KSCRATCH2 | 64
2065 MIPS | KVM_REG_MIPS_CP0_KSCRATCH3 | 64
2066 MIPS | KVM_REG_MIPS_CP0_KSCRATCH4 | 64
2067 MIPS | KVM_REG_MIPS_CP0_KSCRATCH5 | 64
2068 MIPS | KVM_REG_MIPS_CP0_KSCRATCH6 | 64
James Hogand42a0082017-03-14 10:15:38 +00002069 MIPS | KVM_REG_MIPS_CP0_MAAR(0..63) | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002070 MIPS | KVM_REG_MIPS_COUNT_CTL | 64
2071 MIPS | KVM_REG_MIPS_COUNT_RESUME | 64
2072 MIPS | KVM_REG_MIPS_COUNT_HZ | 64
James Hogan379245c2014-12-02 15:48:24 +00002073 MIPS | KVM_REG_MIPS_FPR_32(0..31) | 32
2074 MIPS | KVM_REG_MIPS_FPR_64(0..31) | 64
James Hoganab86bd62014-12-02 15:48:24 +00002075 MIPS | KVM_REG_MIPS_VEC_128(0..31) | 128
James Hogan379245c2014-12-02 15:48:24 +00002076 MIPS | KVM_REG_MIPS_FCR_IR | 32
2077 MIPS | KVM_REG_MIPS_FCR_CSR | 32
James Hoganab86bd62014-12-02 15:48:24 +00002078 MIPS | KVM_REG_MIPS_MSA_IR | 32
2079 MIPS | KVM_REG_MIPS_MSA_CSR | 32
Jan Kiszka414fa982012-04-24 16:40:15 +02002080
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002081ARM registers are mapped using the lower 32 bits. The upper 16 of that
2082is the register group type, or coprocessor number:
2083
2084ARM core registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002085 0x4020 0000 0010 <index into the kvm_regs struct:16>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002086
Christoffer Dall11382452013-01-20 18:28:10 -05002087ARM 32-bit CP15 registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002088 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
Christoffer Dall11382452013-01-20 18:28:10 -05002089
2090ARM 64-bit CP15 registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002091 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002092
Christoffer Dallc27581e2013-01-20 18:28:10 -05002093ARM CCSIDR registers are demultiplexed by CSSELR value:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002094 0x4020 0000 0011 00 <csselr:8>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002095
Rusty Russell4fe21e42013-01-20 18:28:11 -05002096ARM 32-bit VFP control registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002097 0x4020 0000 0012 1 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002098
2099ARM 64-bit FP registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002100 0x4030 0000 0012 0 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002101
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002102ARM firmware pseudo-registers have the following bit pattern:
2103 0x4030 0000 0014 <regno:16>
2104
Marc Zyngier379e04c72013-04-02 17:46:31 +01002105
2106arm64 registers are mapped using the lower 32 bits. The upper 16 of
2107that is the register group type, or coprocessor number:
2108
2109arm64 core/FP-SIMD registers have the following id bit patterns. Note
2110that the size of the access is variable, as the kvm_regs structure
2111contains elements ranging from 32 to 128 bits. The index is a 32bit
2112value in the kvm_regs structure seen as a 32bit array.
2113 0x60x0 0000 0010 <index into the kvm_regs struct:16>
2114
2115arm64 CCSIDR registers are demultiplexed by CSSELR value:
2116 0x6020 0000 0011 00 <csselr:8>
2117
2118arm64 system registers have the following id bit patterns:
2119 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2120
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002121arm64 firmware pseudo-registers have the following bit pattern:
2122 0x6030 0000 0014 <regno:16>
2123
James Hoganc2d2c212014-07-04 15:11:35 +01002124
2125MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
2126the register group type:
2127
2128MIPS core registers (see above) have the following id bit patterns:
2129 0x7030 0000 0000 <reg:16>
2130
2131MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
2132patterns depending on whether they're 32-bit or 64-bit registers:
2133 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
2134 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2135
James Hogan013044c2016-12-07 17:16:37 +00002136Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2137versions of the EntryLo registers regardless of the word size of the host
2138hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2139with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2140the PFNX field starting at bit 30.
2141
James Hogand42a0082017-03-14 10:15:38 +00002142MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
2143patterns:
2144 0x7030 0000 0001 01 <reg:8>
2145
James Hoganc2d2c212014-07-04 15:11:35 +01002146MIPS KVM control registers (see above) have the following id bit patterns:
2147 0x7030 0000 0002 <reg:16>
2148
James Hogan379245c2014-12-02 15:48:24 +00002149MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2150id bit patterns depending on the size of the register being accessed. They are
2151always accessed according to the current guest FPU mode (Status.FR and
2152Config5.FRE), i.e. as the guest would see them, and they become unpredictable
James Hoganab86bd62014-12-02 15:48:24 +00002153if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2154registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
2155overlap the FPU registers:
James Hogan379245c2014-12-02 15:48:24 +00002156 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2157 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
James Hoganab86bd62014-12-02 15:48:24 +00002158 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
James Hogan379245c2014-12-02 15:48:24 +00002159
2160MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
2161following id bit patterns:
2162 0x7020 0000 0003 01 <0:3> <reg:5>
2163
James Hoganab86bd62014-12-02 15:48:24 +00002164MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
2165following id bit patterns:
2166 0x7020 0000 0003 02 <0:3> <reg:5>
2167
James Hoganc2d2c212014-07-04 15:11:35 +01002168
Alexander Grafe24ed812011-09-14 10:02:41 +020021694.69 KVM_GET_ONE_REG
2170
2171Capability: KVM_CAP_ONE_REG
2172Architectures: all
2173Type: vcpu ioctl
2174Parameters: struct kvm_one_reg (in and out)
2175Returns: 0 on success, negative value on failure
2176
2177This ioctl allows to receive the value of a single register implemented
2178in a vcpu. The register to read is indicated by the "id" field of the
2179kvm_one_reg struct passed in. On success, the register value can be found
2180at the memory location pointed to by "addr".
2181
2182The list of registers accessible using this interface is identical to the
Bharat Bhushan2e232702012-08-15 17:37:13 +00002183list in 4.68.
Alexander Grafe24ed812011-09-14 10:02:41 +02002184
Jan Kiszka414fa982012-04-24 16:40:15 +02002185
Eric B Munson1c0b28c2012-03-10 14:37:27 -050021864.70 KVM_KVMCLOCK_CTRL
2187
2188Capability: KVM_CAP_KVMCLOCK_CTRL
2189Architectures: Any that implement pvclocks (currently x86 only)
2190Type: vcpu ioctl
2191Parameters: None
2192Returns: 0 on success, -1 on error
2193
2194This signals to the host kernel that the specified guest is being paused by
2195userspace. The host will set a flag in the pvclock structure that is checked
2196from the soft lockup watchdog. The flag is part of the pvclock structure that
2197is shared between guest and host, specifically the second bit of the flags
2198field of the pvclock_vcpu_time_info structure. It will be set exclusively by
2199the host and read/cleared exclusively by the guest. The guest operation of
2200checking and clearing the flag must an atomic operation so
2201load-link/store-conditional, or equivalent must be used. There are two cases
2202where the guest will clear the flag: when the soft lockup watchdog timer resets
2203itself or when a soft lockup is detected. This ioctl can be called any time
2204after pausing the vcpu, but before it is resumed.
2205
Jan Kiszka414fa982012-04-24 16:40:15 +02002206
Jan Kiszka07975ad2012-03-29 21:14:12 +020022074.71 KVM_SIGNAL_MSI
2208
2209Capability: KVM_CAP_SIGNAL_MSI
Vladimir Murzin29885092016-11-02 11:55:34 +00002210Architectures: x86 arm arm64
Jan Kiszka07975ad2012-03-29 21:14:12 +02002211Type: vm ioctl
2212Parameters: struct kvm_msi (in)
2213Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
2214
2215Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2216MSI messages.
2217
2218struct kvm_msi {
2219 __u32 address_lo;
2220 __u32 address_hi;
2221 __u32 data;
2222 __u32 flags;
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002223 __u32 devid;
2224 __u8 pad[12];
Jan Kiszka07975ad2012-03-29 21:14:12 +02002225};
2226
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002227flags: KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM
2228 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2229 the device ID. If this capability is not available, userspace
2230 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002231
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002232If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2233for the device that wrote the MSI message. For PCI, this is usually a
2234BFD identifier in the lower 16 bits.
Jan Kiszka07975ad2012-03-29 21:14:12 +02002235
Paolo Bonzini055b6ae2016-08-04 14:01:05 +02002236On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2237feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
2238address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
2239address_hi must be zero.
Radim Krčmář371313132016-07-12 22:09:27 +02002240
Jan Kiszka414fa982012-04-24 16:40:15 +02002241
Jan Kiszka0589ff62012-04-24 16:40:16 +020022424.71 KVM_CREATE_PIT2
2243
2244Capability: KVM_CAP_PIT2
2245Architectures: x86
2246Type: vm ioctl
2247Parameters: struct kvm_pit_config (in)
2248Returns: 0 on success, -1 on error
2249
2250Creates an in-kernel device model for the i8254 PIT. This call is only valid
2251after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
2252parameters have to be passed:
2253
2254struct kvm_pit_config {
2255 __u32 flags;
2256 __u32 pad[15];
2257};
2258
2259Valid flags are:
2260
2261#define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
2262
Jan Kiszkab6ddf052012-04-24 16:40:17 +02002263PIT timer interrupts may use a per-VM kernel thread for injection. If it
2264exists, this thread will have a name of the following pattern:
2265
2266kvm-pit/<owner-process-pid>
2267
2268When running a guest with elevated priorities, the scheduling parameters of
2269this thread may have to be adjusted accordingly.
2270
Jan Kiszka0589ff62012-04-24 16:40:16 +02002271This IOCTL replaces the obsolete KVM_CREATE_PIT.
2272
2273
22744.72 KVM_GET_PIT2
2275
2276Capability: KVM_CAP_PIT_STATE2
2277Architectures: x86
2278Type: vm ioctl
2279Parameters: struct kvm_pit_state2 (out)
2280Returns: 0 on success, -1 on error
2281
2282Retrieves the state of the in-kernel PIT model. Only valid after
2283KVM_CREATE_PIT2. The state is returned in the following structure:
2284
2285struct kvm_pit_state2 {
2286 struct kvm_pit_channel_state channels[3];
2287 __u32 flags;
2288 __u32 reserved[9];
2289};
2290
2291Valid flags are:
2292
2293/* disable PIT in HPET legacy mode */
2294#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
2295
2296This IOCTL replaces the obsolete KVM_GET_PIT.
2297
2298
22994.73 KVM_SET_PIT2
2300
2301Capability: KVM_CAP_PIT_STATE2
2302Architectures: x86
2303Type: vm ioctl
2304Parameters: struct kvm_pit_state2 (in)
2305Returns: 0 on success, -1 on error
2306
2307Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
2308See KVM_GET_PIT2 for details on struct kvm_pit_state2.
2309
2310This IOCTL replaces the obsolete KVM_SET_PIT.
2311
2312
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000023134.74 KVM_PPC_GET_SMMU_INFO
2314
2315Capability: KVM_CAP_PPC_GET_SMMU_INFO
2316Architectures: powerpc
2317Type: vm ioctl
2318Parameters: None
2319Returns: 0 on success, -1 on error
2320
2321This populates and returns a structure describing the features of
2322the "Server" class MMU emulation supported by KVM.
Stefan Hubercc22c352013-06-05 12:24:37 +02002323This can in turn be used by userspace to generate the appropriate
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002324device-tree properties for the guest operating system.
2325
Carlos Garciac98be0c2014-04-04 22:31:00 -04002326The structure contains some global information, followed by an
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002327array of supported segment page sizes:
2328
2329 struct kvm_ppc_smmu_info {
2330 __u64 flags;
2331 __u32 slb_size;
2332 __u32 pad;
2333 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
2334 };
2335
2336The supported flags are:
2337
2338 - KVM_PPC_PAGE_SIZES_REAL:
2339 When that flag is set, guest page sizes must "fit" the backing
2340 store page sizes. When not set, any page size in the list can
2341 be used regardless of how they are backed by userspace.
2342
2343 - KVM_PPC_1T_SEGMENTS
2344 The emulated MMU supports 1T segments in addition to the
2345 standard 256M ones.
2346
Paul Mackerras901f8c32018-10-08 14:24:30 +11002347 - KVM_PPC_NO_HASH
2348 This flag indicates that HPT guests are not supported by KVM,
2349 thus all guests must use radix MMU mode.
2350
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002351The "slb_size" field indicates how many SLB entries are supported
2352
2353The "sps" array contains 8 entries indicating the supported base
2354page sizes for a segment in increasing order. Each entry is defined
2355as follow:
2356
2357 struct kvm_ppc_one_seg_page_size {
2358 __u32 page_shift; /* Base page shift of segment (or 0) */
2359 __u32 slb_enc; /* SLB encoding for BookS */
2360 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
2361 };
2362
2363An entry with a "page_shift" of 0 is unused. Because the array is
2364organized in increasing order, a lookup can stop when encoutering
2365such an entry.
2366
2367The "slb_enc" field provides the encoding to use in the SLB for the
2368page size. The bits are in positions such as the value can directly
2369be OR'ed into the "vsid" argument of the slbmte instruction.
2370
2371The "enc" array is a list which for each of those segment base page
2372size provides the list of supported actual page sizes (which can be
2373only larger or equal to the base page size), along with the
Anatol Pomozovf884ab12013-05-08 16:56:16 -07002374corresponding encoding in the hash PTE. Similarly, the array is
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000023758 entries sorted by increasing sizes and an entry with a "0" shift
2376is an empty entry and a terminator:
2377
2378 struct kvm_ppc_one_page_size {
2379 __u32 page_shift; /* Page shift (or 0) */
2380 __u32 pte_enc; /* Encoding in the HPTE (>>12) */
2381 };
2382
2383The "pte_enc" field provides a value that can OR'ed into the hash
2384PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
2385into the hash PTE second double word).
2386
Alex Williamsonf36992e2012-06-29 09:56:16 -060023874.75 KVM_IRQFD
2388
2389Capability: KVM_CAP_IRQFD
Eric Auger174178f2015-03-04 11:14:36 +01002390Architectures: x86 s390 arm arm64
Alex Williamsonf36992e2012-06-29 09:56:16 -06002391Type: vm ioctl
2392Parameters: struct kvm_irqfd (in)
2393Returns: 0 on success, -1 on error
2394
2395Allows setting an eventfd to directly trigger a guest interrupt.
2396kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
2397kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
Masanari Iida17180032013-12-22 01:21:23 +09002398an event is triggered on the eventfd, an interrupt is injected into
Alex Williamsonf36992e2012-06-29 09:56:16 -06002399the guest using the specified gsi pin. The irqfd is removed using
2400the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
2401and kvm_irqfd.gsi.
2402
Alex Williamson7a844282012-09-21 11:58:03 -06002403With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
2404mechanism allowing emulation of level-triggered, irqfd-based
2405interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
2406additional eventfd in the kvm_irqfd.resamplefd field. When operating
2407in resample mode, posting of an interrupt through kvm_irq.fd asserts
2408the specified gsi in the irqchip. When the irqchip is resampled, such
Masanari Iida17180032013-12-22 01:21:23 +09002409as from an EOI, the gsi is de-asserted and the user is notified via
Alex Williamson7a844282012-09-21 11:58:03 -06002410kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
2411the interrupt if the device making use of it still requires service.
2412Note that closing the resamplefd is not sufficient to disable the
2413irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
2414and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
2415
Eric Auger180ae7b2016-07-22 16:20:41 +00002416On arm/arm64, gsi routing being supported, the following can happen:
2417- in case no routing entry is associated to this gsi, injection fails
2418- in case the gsi is associated to an irqchip routing entry,
2419 irqchip.pin + 32 corresponds to the injected SPI ID.
Eric Auger995a0ee2016-07-22 16:20:42 +00002420- in case the gsi is associated to an MSI routing entry, the MSI
2421 message and device ID are translated into an LPI (support restricted
2422 to GICv3 ITS in-kernel emulation).
Eric Auger174178f2015-03-04 11:14:36 +01002423
Linus Torvalds5fecc9d2012-07-24 12:01:20 -070024244.76 KVM_PPC_ALLOCATE_HTAB
Paul Mackerras32fad282012-05-04 02:32:53 +00002425
2426Capability: KVM_CAP_PPC_ALLOC_HTAB
2427Architectures: powerpc
2428Type: vm ioctl
2429Parameters: Pointer to u32 containing hash table order (in/out)
2430Returns: 0 on success, -1 on error
2431
2432This requests the host kernel to allocate an MMU hash table for a
2433guest using the PAPR paravirtualization interface. This only does
2434anything if the kernel is configured to use the Book 3S HV style of
2435virtualization. Otherwise the capability doesn't exist and the ioctl
2436returns an ENOTTY error. The rest of this description assumes Book 3S
2437HV.
2438
2439There must be no vcpus running when this ioctl is called; if there
2440are, it will do nothing and return an EBUSY error.
2441
2442The parameter is a pointer to a 32-bit unsigned integer variable
2443containing the order (log base 2) of the desired size of the hash
2444table, which must be between 18 and 46. On successful return from the
David Gibsonf98a8bf2016-12-20 16:49:03 +11002445ioctl, the value will not be changed by the kernel.
Paul Mackerras32fad282012-05-04 02:32:53 +00002446
2447If no hash table has been allocated when any vcpu is asked to run
2448(with the KVM_RUN ioctl), the host kernel will allocate a
2449default-sized hash table (16 MB).
2450
2451If this ioctl is called when a hash table has already been allocated,
David Gibsonf98a8bf2016-12-20 16:49:03 +11002452with a different order from the existing hash table, the existing hash
2453table will be freed and a new one allocated. If this is ioctl is
2454called when a hash table has already been allocated of the same order
2455as specified, the kernel will clear out the existing hash table (zero
2456all HPTEs). In either case, if the guest is using the virtualized
2457real-mode area (VRMA) facility, the kernel will re-create the VMRA
2458HPTEs on the next KVM_RUN of any vcpu.
Paul Mackerras32fad282012-05-04 02:32:53 +00002459
Cornelia Huck416ad652012-10-02 16:25:37 +020024604.77 KVM_S390_INTERRUPT
2461
2462Capability: basic
2463Architectures: s390
2464Type: vm ioctl, vcpu ioctl
2465Parameters: struct kvm_s390_interrupt (in)
2466Returns: 0 on success, -1 on error
2467
2468Allows to inject an interrupt to the guest. Interrupts can be floating
2469(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
2470
2471Interrupt parameters are passed via kvm_s390_interrupt:
2472
2473struct kvm_s390_interrupt {
2474 __u32 type;
2475 __u32 parm;
2476 __u64 parm64;
2477};
2478
2479type can be one of the following:
2480
David Hildenbrand28225452014-10-15 16:48:16 +02002481KVM_S390_SIGP_STOP (vcpu) - sigp stop; optional flags in parm
Cornelia Huck416ad652012-10-02 16:25:37 +02002482KVM_S390_PROGRAM_INT (vcpu) - program check; code in parm
2483KVM_S390_SIGP_SET_PREFIX (vcpu) - sigp set prefix; prefix address in parm
2484KVM_S390_RESTART (vcpu) - restart
Thomas Huthe029ae52014-03-26 16:11:54 +01002485KVM_S390_INT_CLOCK_COMP (vcpu) - clock comparator interrupt
2486KVM_S390_INT_CPU_TIMER (vcpu) - CPU timer interrupt
Cornelia Huck416ad652012-10-02 16:25:37 +02002487KVM_S390_INT_VIRTIO (vm) - virtio external interrupt; external interrupt
2488 parameters in parm and parm64
2489KVM_S390_INT_SERVICE (vm) - sclp external interrupt; sclp parameter in parm
2490KVM_S390_INT_EMERGENCY (vcpu) - sigp emergency; source cpu in parm
2491KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
Cornelia Huckd8346b72012-12-20 15:32:08 +01002492KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) - compound value to indicate an
2493 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
2494 I/O interruption parameters in parm (subchannel) and parm64 (intparm,
2495 interruption subclass)
Cornelia Huck48a3e952012-12-20 15:32:09 +01002496KVM_S390_MCHK (vm, vcpu) - machine check interrupt; cr 14 bits in parm,
2497 machine check interrupt code in parm64 (note that
2498 machine checks needing further payload are not
2499 supported by this ioctl)
Cornelia Huck416ad652012-10-02 16:25:37 +02002500
Sean Christopherson5e124902019-02-15 12:48:38 -08002501This is an asynchronous vcpu ioctl and can be invoked from any thread.
Cornelia Huck416ad652012-10-02 16:25:37 +02002502
Paul Mackerrasa2932922012-11-19 22:57:20 +000025034.78 KVM_PPC_GET_HTAB_FD
2504
2505Capability: KVM_CAP_PPC_HTAB_FD
2506Architectures: powerpc
2507Type: vm ioctl
2508Parameters: Pointer to struct kvm_get_htab_fd (in)
2509Returns: file descriptor number (>= 0) on success, -1 on error
2510
2511This returns a file descriptor that can be used either to read out the
2512entries in the guest's hashed page table (HPT), or to write entries to
2513initialize the HPT. The returned fd can only be written to if the
2514KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
2515can only be read if that bit is clear. The argument struct looks like
2516this:
2517
2518/* For KVM_PPC_GET_HTAB_FD */
2519struct kvm_get_htab_fd {
2520 __u64 flags;
2521 __u64 start_index;
2522 __u64 reserved[2];
2523};
2524
2525/* Values for kvm_get_htab_fd.flags */
2526#define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
2527#define KVM_GET_HTAB_WRITE ((__u64)0x2)
2528
2529The `start_index' field gives the index in the HPT of the entry at
2530which to start reading. It is ignored when writing.
2531
2532Reads on the fd will initially supply information about all
2533"interesting" HPT entries. Interesting entries are those with the
2534bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
2535all entries. When the end of the HPT is reached, the read() will
2536return. If read() is called again on the fd, it will start again from
2537the beginning of the HPT, but will only return HPT entries that have
2538changed since they were last read.
2539
2540Data read or written is structured as a header (8 bytes) followed by a
2541series of valid HPT entries (16 bytes) each. The header indicates how
2542many valid HPT entries there are and how many invalid entries follow
2543the valid entries. The invalid entries are not represented explicitly
2544in the stream. The header format is:
2545
2546struct kvm_get_htab_header {
2547 __u32 index;
2548 __u16 n_valid;
2549 __u16 n_invalid;
2550};
2551
2552Writes to the fd create HPT entries starting at the index given in the
2553header; first `n_valid' valid entries with contents from the data
2554written, then `n_invalid' invalid entries, invalidating any previously
2555valid entries found.
2556
Scott Wood852b6d52013-04-12 14:08:42 +000025574.79 KVM_CREATE_DEVICE
2558
2559Capability: KVM_CAP_DEVICE_CTRL
2560Type: vm ioctl
2561Parameters: struct kvm_create_device (in/out)
2562Returns: 0 on success, -1 on error
2563Errors:
2564 ENODEV: The device type is unknown or unsupported
2565 EEXIST: Device already created, and this type of device may not
2566 be instantiated multiple times
2567
2568 Other error conditions may be defined by individual device types or
2569 have their standard meanings.
2570
2571Creates an emulated device in the kernel. The file descriptor returned
2572in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
2573
2574If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
2575device type is supported (not necessarily whether it can be created
2576in the current vm).
2577
2578Individual devices should not define flags. Attributes should be used
2579for specifying any behavior that is not implied by the device type
2580number.
2581
2582struct kvm_create_device {
2583 __u32 type; /* in: KVM_DEV_TYPE_xxx */
2584 __u32 fd; /* out: device handle */
2585 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
2586};
2587
25884.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
2589
Shannon Zhaof577f6c2016-01-11 20:56:17 +08002590Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
2591 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
2592Type: device ioctl, vm ioctl, vcpu ioctl
Scott Wood852b6d52013-04-12 14:08:42 +00002593Parameters: struct kvm_device_attr
2594Returns: 0 on success, -1 on error
2595Errors:
2596 ENXIO: The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01002597 or hardware support is missing.
Scott Wood852b6d52013-04-12 14:08:42 +00002598 EPERM: The attribute cannot (currently) be accessed this way
2599 (e.g. read-only attribute, or attribute that only makes
2600 sense when the device is in a different state)
2601
2602 Other error conditions may be defined by individual device types.
2603
2604Gets/sets a specified piece of device configuration and/or state. The
2605semantics are device-specific. See individual device documentation in
2606the "devices" directory. As with ONE_REG, the size of the data
2607transferred is defined by the particular attribute.
2608
2609struct kvm_device_attr {
2610 __u32 flags; /* no flags currently defined */
2611 __u32 group; /* device-defined */
2612 __u64 attr; /* group-defined */
2613 __u64 addr; /* userspace address of attr data */
2614};
2615
26164.81 KVM_HAS_DEVICE_ATTR
2617
Shannon Zhaof577f6c2016-01-11 20:56:17 +08002618Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
2619 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
2620Type: device ioctl, vm ioctl, vcpu ioctl
Scott Wood852b6d52013-04-12 14:08:42 +00002621Parameters: struct kvm_device_attr
2622Returns: 0 on success, -1 on error
2623Errors:
2624 ENXIO: The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01002625 or hardware support is missing.
Scott Wood852b6d52013-04-12 14:08:42 +00002626
2627Tests whether a device supports a particular attribute. A successful
2628return indicates the attribute is implemented. It does not necessarily
2629indicate that the attribute can be read or written in the device's
2630current state. "addr" is ignored.
Alex Williamsonf36992e2012-06-29 09:56:16 -06002631
Alexey Kardashevskiyd8968f12013-06-19 11:42:07 +100026324.82 KVM_ARM_VCPU_INIT
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002633
2634Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +01002635Architectures: arm, arm64
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002636Type: vcpu ioctl
Anup Patelbeb11fc2013-12-12 21:42:24 +05302637Parameters: struct kvm_vcpu_init (in)
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002638Returns: 0 on success; -1 on error
2639Errors:
2640  EINVAL:    the target is unknown, or the combination of features is invalid.
2641  ENOENT:    a features bit specified is unknown.
2642
2643This tells KVM what type of CPU to present to the guest, and what
2644optional features it should have.  This will cause a reset of the cpu
2645registers to their initial values.  If this is not called, KVM_RUN will
2646return ENOEXEC for that vcpu.
2647
2648Note that because some registers reflect machine topology, all vcpus
2649should be created before this ioctl is invoked.
2650
Christoffer Dallf7fa034d2014-10-16 16:40:53 +02002651Userspace can call this function multiple times for a given vcpu, including
2652after the vcpu has been run. This will reset the vcpu to its initial
2653state. All calls to this function after the initial call must use the same
2654target and same set of feature flags, otherwise EINVAL will be returned.
2655
Marc Zyngieraa024c22013-01-20 18:28:13 -05002656Possible features:
2657 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
Christoffer Dall3ad8b3d2014-10-16 16:14:43 +02002658 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
2659 and execute guest code when KVM_RUN is called.
Marc Zyngier379e04c72013-04-02 17:46:31 +01002660 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
2661 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002662 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
2663 backward compatible with v0.2) for the CPU.
Anup Patel50bb0c92014-04-29 11:24:17 +05302664 Depends on KVM_CAP_ARM_PSCI_0_2.
Shannon Zhao808e7382016-01-11 22:46:15 +08002665 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
2666 Depends on KVM_CAP_ARM_PMU_V3.
Marc Zyngieraa024c22013-01-20 18:28:13 -05002667
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002668
Anup Patel740edfc2013-09-30 14:20:08 +053026694.83 KVM_ARM_PREFERRED_TARGET
2670
2671Capability: basic
2672Architectures: arm, arm64
2673Type: vm ioctl
2674Parameters: struct struct kvm_vcpu_init (out)
2675Returns: 0 on success; -1 on error
2676Errors:
Christoffer Dalla7265fb2013-10-15 17:43:00 -07002677 ENODEV: no preferred target available for the host
Anup Patel740edfc2013-09-30 14:20:08 +05302678
2679This queries KVM for preferred CPU target type which can be emulated
2680by KVM on underlying host.
2681
2682The ioctl returns struct kvm_vcpu_init instance containing information
2683about preferred CPU target type and recommended features for it. The
2684kvm_vcpu_init->features bitmap returned will have feature bits set if
2685the preferred target recommends setting these features, but this is
2686not mandatory.
2687
2688The information returned by this ioctl can be used to prepare an instance
2689of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
2690in VCPU matching underlying host.
2691
2692
26934.84 KVM_GET_REG_LIST
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002694
2695Capability: basic
James Hoganc2d2c212014-07-04 15:11:35 +01002696Architectures: arm, arm64, mips
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002697Type: vcpu ioctl
2698Parameters: struct kvm_reg_list (in/out)
2699Returns: 0 on success; -1 on error
2700Errors:
2701  E2BIG:     the reg index list is too big to fit in the array specified by
2702             the user (the number required will be written into n).
2703
2704struct kvm_reg_list {
2705 __u64 n; /* number of registers in reg[] */
2706 __u64 reg[0];
2707};
2708
2709This ioctl returns the guest registers that are supported for the
2710KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
2711
Christoffer Dallce01e4e2013-09-23 14:55:56 -07002712
27134.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
Christoffer Dall3401d5462013-01-23 13:18:04 -05002714
2715Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
Marc Zyngier379e04c72013-04-02 17:46:31 +01002716Architectures: arm, arm64
Christoffer Dall3401d5462013-01-23 13:18:04 -05002717Type: vm ioctl
2718Parameters: struct kvm_arm_device_address (in)
2719Returns: 0 on success, -1 on error
2720Errors:
2721 ENODEV: The device id is unknown
2722 ENXIO: Device not supported on current system
2723 EEXIST: Address already set
2724 E2BIG: Address outside guest physical address space
Christoffer Dall330690c2013-01-21 19:36:13 -05002725 EBUSY: Address overlaps with other device range
Christoffer Dall3401d5462013-01-23 13:18:04 -05002726
2727struct kvm_arm_device_addr {
2728 __u64 id;
2729 __u64 addr;
2730};
2731
2732Specify a device address in the guest's physical address space where guests
2733can access emulated or directly exposed devices, which the host kernel needs
2734to know about. The id field is an architecture specific identifier for a
2735specific device.
2736
Marc Zyngier379e04c72013-04-02 17:46:31 +01002737ARM/arm64 divides the id field into two parts, a device id and an
2738address type id specific to the individual device.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002739
2740  bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
2741 field: | 0x00000000 | device id | addr type id |
2742
Marc Zyngier379e04c72013-04-02 17:46:31 +01002743ARM/arm64 currently only require this when using the in-kernel GIC
2744support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
2745as the device id. When setting the base address for the guest's
2746mapping of the VGIC virtual CPU and distributor interface, the ioctl
2747must be called after calling KVM_CREATE_IRQCHIP, but before calling
2748KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
2749base addresses will return -EEXIST.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002750
Christoffer Dallce01e4e2013-09-23 14:55:56 -07002751Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
2752should be used instead.
2753
2754
Anup Patel740edfc2013-09-30 14:20:08 +053027554.86 KVM_PPC_RTAS_DEFINE_TOKEN
Michael Ellerman8e591cb2013-04-17 20:30:00 +00002756
2757Capability: KVM_CAP_PPC_RTAS
2758Architectures: ppc
2759Type: vm ioctl
2760Parameters: struct kvm_rtas_token_args
2761Returns: 0 on success, -1 on error
2762
2763Defines a token value for a RTAS (Run Time Abstraction Services)
2764service in order to allow it to be handled in the kernel. The
2765argument struct gives the name of the service, which must be the name
2766of a service that has a kernel-side implementation. If the token
2767value is non-zero, it will be associated with that service, and
2768subsequent RTAS calls by the guest specifying that token will be
2769handled by the kernel. If the token value is 0, then any token
2770associated with the service will be forgotten, and subsequent RTAS
2771calls by the guest for that service will be passed to userspace to be
2772handled.
2773
Alex Bennée4bd9d342014-09-09 17:27:18 +010027744.87 KVM_SET_GUEST_DEBUG
2775
2776Capability: KVM_CAP_SET_GUEST_DEBUG
Alex Bennée0e6f07f2015-07-07 17:29:55 +01002777Architectures: x86, s390, ppc, arm64
Alex Bennée4bd9d342014-09-09 17:27:18 +01002778Type: vcpu ioctl
2779Parameters: struct kvm_guest_debug (in)
2780Returns: 0 on success; -1 on error
2781
2782struct kvm_guest_debug {
2783 __u32 control;
2784 __u32 pad;
2785 struct kvm_guest_debug_arch arch;
2786};
2787
2788Set up the processor specific debug registers and configure vcpu for
2789handling guest debug events. There are two parts to the structure, the
2790first a control bitfield indicates the type of debug events to handle
2791when running. Common control bits are:
2792
2793 - KVM_GUESTDBG_ENABLE: guest debugging is enabled
2794 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
2795
2796The top 16 bits of the control field are architecture specific control
2797flags which can include the following:
2798
Alex Bennée4bd611c2015-07-07 17:29:57 +01002799 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
Alex Bennée834bf882015-07-07 17:30:02 +01002800 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390, arm64]
Alex Bennée4bd9d342014-09-09 17:27:18 +01002801 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
2802 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
2803 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
2804
2805For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
2806are enabled in memory so we need to ensure breakpoint exceptions are
2807correctly trapped and the KVM run loop exits at the breakpoint and not
2808running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
2809we need to ensure the guest vCPUs architecture specific registers are
2810updated to the correct (supplied) values.
2811
2812The second part of the structure is architecture specific and
2813typically contains a set of debug registers.
2814
Alex Bennée834bf882015-07-07 17:30:02 +01002815For arm64 the number of debug registers is implementation defined and
2816can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
2817KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
2818indicating the number of supported registers.
2819
Alex Bennée4bd9d342014-09-09 17:27:18 +01002820When debug events exit the main run loop with the reason
2821KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
2822structure containing architecture specific debug information.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002823
Alex Bennée209cf192014-09-09 17:27:19 +010028244.88 KVM_GET_EMULATED_CPUID
2825
2826Capability: KVM_CAP_EXT_EMUL_CPUID
2827Architectures: x86
2828Type: system ioctl
2829Parameters: struct kvm_cpuid2 (in/out)
2830Returns: 0 on success, -1 on error
2831
2832struct kvm_cpuid2 {
2833 __u32 nent;
2834 __u32 flags;
2835 struct kvm_cpuid_entry2 entries[0];
2836};
2837
2838The member 'flags' is used for passing flags from userspace.
2839
2840#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
2841#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
2842#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
2843
2844struct kvm_cpuid_entry2 {
2845 __u32 function;
2846 __u32 index;
2847 __u32 flags;
2848 __u32 eax;
2849 __u32 ebx;
2850 __u32 ecx;
2851 __u32 edx;
2852 __u32 padding[3];
2853};
2854
2855This ioctl returns x86 cpuid features which are emulated by
2856kvm.Userspace can use the information returned by this ioctl to query
2857which features are emulated by kvm instead of being present natively.
2858
2859Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
2860structure with the 'nent' field indicating the number of entries in
2861the variable-size array 'entries'. If the number of entries is too low
2862to describe the cpu capabilities, an error (E2BIG) is returned. If the
2863number is too high, the 'nent' field is adjusted and an error (ENOMEM)
2864is returned. If the number is just right, the 'nent' field is adjusted
2865to the number of valid entries in the 'entries' array, which is then
2866filled.
2867
2868The entries returned are the set CPUID bits of the respective features
2869which kvm emulates, as returned by the CPUID instruction, with unknown
2870or unsupported feature bits cleared.
2871
2872Features like x2apic, for example, may not be present in the host cpu
2873but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
2874emulated efficiently and thus not included here.
2875
2876The fields in each entry are defined as follows:
2877
2878 function: the eax value used to obtain the entry
2879 index: the ecx value used to obtain the entry (for entries that are
2880 affected by ecx)
2881 flags: an OR of zero or more of the following:
2882 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
2883 if the index field is valid
2884 KVM_CPUID_FLAG_STATEFUL_FUNC:
2885 if cpuid for this function returns different values for successive
2886 invocations; there will be several entries with the same function,
2887 all with this flag set
2888 KVM_CPUID_FLAG_STATE_READ_NEXT:
2889 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
2890 the first entry to be read by a cpu
2891 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
2892 this function/index combination
2893
Thomas Huth41408c282015-02-06 15:01:21 +010028944.89 KVM_S390_MEM_OP
2895
2896Capability: KVM_CAP_S390_MEM_OP
2897Architectures: s390
2898Type: vcpu ioctl
2899Parameters: struct kvm_s390_mem_op (in)
2900Returns: = 0 on success,
2901 < 0 on generic error (e.g. -EFAULT or -ENOMEM),
2902 > 0 if an exception occurred while walking the page tables
2903
Masanari Iida5d4f6f32015-10-04 00:46:21 +09002904Read or write data from/to the logical (virtual) memory of a VCPU.
Thomas Huth41408c282015-02-06 15:01:21 +01002905
2906Parameters are specified via the following structure:
2907
2908struct kvm_s390_mem_op {
2909 __u64 gaddr; /* the guest address */
2910 __u64 flags; /* flags */
2911 __u32 size; /* amount of bytes */
2912 __u32 op; /* type of operation */
2913 __u64 buf; /* buffer in userspace */
2914 __u8 ar; /* the access register number */
2915 __u8 reserved[31]; /* should be set to 0 */
2916};
2917
2918The type of operation is specified in the "op" field. It is either
2919KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or
2920KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The
2921KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check
2922whether the corresponding memory access would create an access exception
2923(without touching the data in the memory at the destination). In case an
2924access exception occurred while walking the MMU tables of the guest, the
2925ioctl returns a positive error number to indicate the type of exception.
2926This exception is also raised directly at the corresponding VCPU if the
2927flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field.
2928
2929The start address of the memory region has to be specified in the "gaddr"
2930field, and the length of the region in the "size" field. "buf" is the buffer
2931supplied by the userspace application where the read data should be written
2932to for KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written
2933is stored for a KVM_S390_MEMOP_LOGICAL_WRITE. "buf" is unused and can be NULL
2934when KVM_S390_MEMOP_F_CHECK_ONLY is specified. "ar" designates the access
2935register number to be used.
2936
2937The "reserved" field is meant for future extensions. It is not used by
2938KVM with the currently defined set of flags.
2939
Jason J. Herne30ee2a92014-09-23 09:23:01 -040029404.90 KVM_S390_GET_SKEYS
2941
2942Capability: KVM_CAP_S390_SKEYS
2943Architectures: s390
2944Type: vm ioctl
2945Parameters: struct kvm_s390_skeys
2946Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
2947 keys, negative value on error
2948
2949This ioctl is used to get guest storage key values on the s390
2950architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
2951
2952struct kvm_s390_skeys {
2953 __u64 start_gfn;
2954 __u64 count;
2955 __u64 skeydata_addr;
2956 __u32 flags;
2957 __u32 reserved[9];
2958};
2959
2960The start_gfn field is the number of the first guest frame whose storage keys
2961you want to get.
2962
2963The count field is the number of consecutive frames (starting from start_gfn)
2964whose storage keys to get. The count field must be at least 1 and the maximum
2965allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
2966will cause the ioctl to return -EINVAL.
2967
2968The skeydata_addr field is the address to a buffer large enough to hold count
2969bytes. This buffer will be filled with storage key data by the ioctl.
2970
29714.91 KVM_S390_SET_SKEYS
2972
2973Capability: KVM_CAP_S390_SKEYS
2974Architectures: s390
2975Type: vm ioctl
2976Parameters: struct kvm_s390_skeys
2977Returns: 0 on success, negative value on error
2978
2979This ioctl is used to set guest storage key values on the s390
2980architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
2981See section on KVM_S390_GET_SKEYS for struct definition.
2982
2983The start_gfn field is the number of the first guest frame whose storage keys
2984you want to set.
2985
2986The count field is the number of consecutive frames (starting from start_gfn)
2987whose storage keys to get. The count field must be at least 1 and the maximum
2988allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
2989will cause the ioctl to return -EINVAL.
2990
2991The skeydata_addr field is the address to a buffer containing count bytes of
2992storage keys. Each byte in the buffer will be set as the storage key for a
2993single frame starting at start_gfn for count frames.
2994
2995Note: If any architecturally invalid key value is found in the given data then
2996the ioctl will return -EINVAL.
2997
Jens Freimann47b43c52014-11-11 20:57:06 +010029984.92 KVM_S390_IRQ
2999
3000Capability: KVM_CAP_S390_INJECT_IRQ
3001Architectures: s390
3002Type: vcpu ioctl
3003Parameters: struct kvm_s390_irq (in)
3004Returns: 0 on success, -1 on error
3005Errors:
3006 EINVAL: interrupt type is invalid
3007 type is KVM_S390_SIGP_STOP and flag parameter is invalid value
3008 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
3009 than the maximum of VCPUs
3010 EBUSY: type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped
3011 type is KVM_S390_SIGP_STOP and a stop irq is already pending
3012 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
3013 is already pending
3014
3015Allows to inject an interrupt to the guest.
3016
3017Using struct kvm_s390_irq as a parameter allows
3018to inject additional payload which is not
3019possible via KVM_S390_INTERRUPT.
3020
3021Interrupt parameters are passed via kvm_s390_irq:
3022
3023struct kvm_s390_irq {
3024 __u64 type;
3025 union {
3026 struct kvm_s390_io_info io;
3027 struct kvm_s390_ext_info ext;
3028 struct kvm_s390_pgm_info pgm;
3029 struct kvm_s390_emerg_info emerg;
3030 struct kvm_s390_extcall_info extcall;
3031 struct kvm_s390_prefix_info prefix;
3032 struct kvm_s390_stop_info stop;
3033 struct kvm_s390_mchk_info mchk;
3034 char reserved[64];
3035 } u;
3036};
3037
3038type can be one of the following:
3039
3040KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
3041KVM_S390_PROGRAM_INT - program check; parameters in .pgm
3042KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
3043KVM_S390_RESTART - restart; no parameters
3044KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
3045KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
3046KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
3047KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
3048KVM_S390_MCHK - machine check interrupt; parameters in .mchk
3049
Sean Christopherson5e124902019-02-15 12:48:38 -08003050This is an asynchronous vcpu ioctl and can be invoked from any thread.
Jens Freimann47b43c52014-11-11 20:57:06 +01003051
Jens Freimann816c7662014-11-24 17:13:46 +010030524.94 KVM_S390_GET_IRQ_STATE
3053
3054Capability: KVM_CAP_S390_IRQ_STATE
3055Architectures: s390
3056Type: vcpu ioctl
3057Parameters: struct kvm_s390_irq_state (out)
3058Returns: >= number of bytes copied into buffer,
3059 -EINVAL if buffer size is 0,
3060 -ENOBUFS if buffer size is too small to fit all pending interrupts,
3061 -EFAULT if the buffer address was invalid
3062
3063This ioctl allows userspace to retrieve the complete state of all currently
3064pending interrupts in a single buffer. Use cases include migration
3065and introspection. The parameter structure contains the address of a
3066userspace buffer and its length:
3067
3068struct kvm_s390_irq_state {
3069 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003070 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003071 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003072 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003073};
3074
3075Userspace passes in the above struct and for each pending interrupt a
3076struct kvm_s390_irq is copied to the provided buffer.
3077
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003078The structure contains a flags and a reserved field for future extensions. As
3079the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
3080reserved, these fields can not be used in the future without breaking
3081compatibility.
3082
Jens Freimann816c7662014-11-24 17:13:46 +01003083If -ENOBUFS is returned the buffer provided was too small and userspace
3084may retry with a bigger buffer.
3085
30864.95 KVM_S390_SET_IRQ_STATE
3087
3088Capability: KVM_CAP_S390_IRQ_STATE
3089Architectures: s390
3090Type: vcpu ioctl
3091Parameters: struct kvm_s390_irq_state (in)
3092Returns: 0 on success,
3093 -EFAULT if the buffer address was invalid,
3094 -EINVAL for an invalid buffer length (see below),
3095 -EBUSY if there were already interrupts pending,
3096 errors occurring when actually injecting the
3097 interrupt. See KVM_S390_IRQ.
3098
3099This ioctl allows userspace to set the complete state of all cpu-local
3100interrupts currently pending for the vcpu. It is intended for restoring
3101interrupt state after a migration. The input parameter is a userspace buffer
3102containing a struct kvm_s390_irq_state:
3103
3104struct kvm_s390_irq_state {
3105 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003106 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003107 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003108 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003109};
3110
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003111The restrictions for flags and reserved apply as well.
3112(see KVM_S390_GET_IRQ_STATE)
3113
Jens Freimann816c7662014-11-24 17:13:46 +01003114The userspace memory referenced by buf contains a struct kvm_s390_irq
3115for each interrupt to be injected into the guest.
3116If one of the interrupts could not be injected for some reason the
3117ioctl aborts.
3118
3119len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
3120and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
3121which is the maximum number of possibly pending cpu-local interrupts.
Jens Freimann47b43c52014-11-11 20:57:06 +01003122
Alexey Kardashevskiyed8e5a22016-01-19 16:12:28 +110031234.96 KVM_SMI
Paolo Bonzinif0778252015-04-01 15:06:40 +02003124
3125Capability: KVM_CAP_X86_SMM
3126Architectures: x86
3127Type: vcpu ioctl
3128Parameters: none
3129Returns: 0 on success, -1 on error
3130
3131Queues an SMI on the thread's vcpu.
3132
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +110031334.97 KVM_CAP_PPC_MULTITCE
3134
3135Capability: KVM_CAP_PPC_MULTITCE
3136Architectures: ppc
3137Type: vm
3138
3139This capability means the kernel is capable of handling hypercalls
3140H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
3141space. This significantly accelerates DMA operations for PPC KVM guests.
3142User space should expect that its handlers for these hypercalls
3143are not going to be called if user space previously registered LIOBN
3144in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
3145
3146In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
3147user space might have to advertise it for the guest. For example,
3148IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
3149present in the "ibm,hypertas-functions" device-tree property.
3150
3151The hypercalls mentioned above may or may not be processed successfully
3152in the kernel based fast path. If they can not be handled by the kernel,
3153they will get passed on to user space. So user space still has to have
3154an implementation for these despite the in kernel acceleration.
3155
3156This capability is always enabled.
3157
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +110031584.98 KVM_CREATE_SPAPR_TCE_64
3159
3160Capability: KVM_CAP_SPAPR_TCE_64
3161Architectures: powerpc
3162Type: vm ioctl
3163Parameters: struct kvm_create_spapr_tce_64 (in)
3164Returns: file descriptor for manipulating the created TCE table
3165
3166This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
3167windows, described in 4.62 KVM_CREATE_SPAPR_TCE
3168
3169This capability uses extended struct in ioctl interface:
3170
3171/* for KVM_CAP_SPAPR_TCE_64 */
3172struct kvm_create_spapr_tce_64 {
3173 __u64 liobn;
3174 __u32 page_shift;
3175 __u32 flags;
3176 __u64 offset; /* in pages */
3177 __u64 size; /* in pages */
3178};
3179
3180The aim of extension is to support an additional bigger DMA window with
3181a variable page size.
3182KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
3183a bus offset of the corresponding DMA window, @size and @offset are numbers
3184of IOMMU pages.
3185
3186@flags are not used at the moment.
3187
3188The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
3189
David Gibsonccc4df42016-12-20 16:48:57 +110031904.99 KVM_REINJECT_CONTROL
Radim Krčmář107d44a22016-03-02 22:56:53 +01003191
3192Capability: KVM_CAP_REINJECT_CONTROL
3193Architectures: x86
3194Type: vm ioctl
3195Parameters: struct kvm_reinject_control (in)
3196Returns: 0 on success,
3197 -EFAULT if struct kvm_reinject_control cannot be read,
3198 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
3199
3200i8254 (PIT) has two modes, reinject and !reinject. The default is reinject,
3201where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
3202vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its
3203interrupt whenever there isn't a pending interrupt from i8254.
3204!reinject mode injects an interrupt as soon as a tick arrives.
3205
3206struct kvm_reinject_control {
3207 __u8 pit_reinject;
3208 __u8 reserved[31];
3209};
3210
3211pit_reinject = 0 (!reinject mode) is recommended, unless running an old
3212operating system that uses the PIT for timing (e.g. Linux 2.4.x).
3213
David Gibsonccc4df42016-12-20 16:48:57 +110032144.100 KVM_PPC_CONFIGURE_V3_MMU
Paul Mackerrasc9270132017-01-30 21:21:41 +11003215
3216Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
3217Architectures: ppc
3218Type: vm ioctl
3219Parameters: struct kvm_ppc_mmuv3_cfg (in)
3220Returns: 0 on success,
3221 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
3222 -EINVAL if the configuration is invalid
3223
3224This ioctl controls whether the guest will use radix or HPT (hashed
3225page table) translation, and sets the pointer to the process table for
3226the guest.
3227
3228struct kvm_ppc_mmuv3_cfg {
3229 __u64 flags;
3230 __u64 process_table;
3231};
3232
3233There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
3234KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest
3235to use radix tree translation, and if clear, to use HPT translation.
3236KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
3237to be able to use the global TLB and SLB invalidation instructions;
3238if clear, the guest may not use these instructions.
3239
3240The process_table field specifies the address and size of the guest
3241process table, which is in the guest's space. This field is formatted
3242as the second doubleword of the partition table entry, as defined in
3243the Power ISA V3.00, Book III section 5.7.6.1.
3244
David Gibsonccc4df42016-12-20 16:48:57 +110032454.101 KVM_PPC_GET_RMMU_INFO
Paul Mackerrasc9270132017-01-30 21:21:41 +11003246
3247Capability: KVM_CAP_PPC_RADIX_MMU
3248Architectures: ppc
3249Type: vm ioctl
3250Parameters: struct kvm_ppc_rmmu_info (out)
3251Returns: 0 on success,
3252 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
3253 -EINVAL if no useful information can be returned
3254
3255This ioctl returns a structure containing two things: (a) a list
3256containing supported radix tree geometries, and (b) a list that maps
3257page sizes to put in the "AP" (actual page size) field for the tlbie
3258(TLB invalidate entry) instruction.
3259
3260struct kvm_ppc_rmmu_info {
3261 struct kvm_ppc_radix_geom {
3262 __u8 page_shift;
3263 __u8 level_bits[4];
3264 __u8 pad[3];
3265 } geometries[8];
3266 __u32 ap_encodings[8];
3267};
3268
3269The geometries[] field gives up to 8 supported geometries for the
3270radix page table, in terms of the log base 2 of the smallest page
3271size, and the number of bits indexed at each level of the tree, from
3272the PTE level up to the PGD level in that order. Any unused entries
3273will have 0 in the page_shift field.
3274
3275The ap_encodings gives the supported page sizes and their AP field
3276encodings, encoded with the AP value in the top 3 bits and the log
3277base 2 of the page size in the bottom 6 bits.
3278
David Gibsonef1ead02016-12-20 16:48:58 +110032794.102 KVM_PPC_RESIZE_HPT_PREPARE
3280
3281Capability: KVM_CAP_SPAPR_RESIZE_HPT
3282Architectures: powerpc
3283Type: vm ioctl
3284Parameters: struct kvm_ppc_resize_hpt (in)
3285Returns: 0 on successful completion,
3286 >0 if a new HPT is being prepared, the value is an estimated
3287 number of milliseconds until preparation is complete
3288 -EFAULT if struct kvm_reinject_control cannot be read,
3289 -EINVAL if the supplied shift or flags are invalid
3290 -ENOMEM if unable to allocate the new HPT
3291 -ENOSPC if there was a hash collision when moving existing
3292 HPT entries to the new HPT
3293 -EIO on other error conditions
3294
3295Used to implement the PAPR extension for runtime resizing of a guest's
3296Hashed Page Table (HPT). Specifically this starts, stops or monitors
3297the preparation of a new potential HPT for the guest, essentially
3298implementing the H_RESIZE_HPT_PREPARE hypercall.
3299
3300If called with shift > 0 when there is no pending HPT for the guest,
3301this begins preparation of a new pending HPT of size 2^(shift) bytes.
3302It then returns a positive integer with the estimated number of
3303milliseconds until preparation is complete.
3304
3305If called when there is a pending HPT whose size does not match that
3306requested in the parameters, discards the existing pending HPT and
3307creates a new one as above.
3308
3309If called when there is a pending HPT of the size requested, will:
3310 * If preparation of the pending HPT is already complete, return 0
3311 * If preparation of the pending HPT has failed, return an error
3312 code, then discard the pending HPT.
3313 * If preparation of the pending HPT is still in progress, return an
3314 estimated number of milliseconds until preparation is complete.
3315
3316If called with shift == 0, discards any currently pending HPT and
3317returns 0 (i.e. cancels any in-progress preparation).
3318
3319flags is reserved for future expansion, currently setting any bits in
3320flags will result in an -EINVAL.
3321
3322Normally this will be called repeatedly with the same parameters until
3323it returns <= 0. The first call will initiate preparation, subsequent
3324ones will monitor preparation until it completes or fails.
3325
3326struct kvm_ppc_resize_hpt {
3327 __u64 flags;
3328 __u32 shift;
3329 __u32 pad;
3330};
3331
33324.103 KVM_PPC_RESIZE_HPT_COMMIT
3333
3334Capability: KVM_CAP_SPAPR_RESIZE_HPT
3335Architectures: powerpc
3336Type: vm ioctl
3337Parameters: struct kvm_ppc_resize_hpt (in)
3338Returns: 0 on successful completion,
3339 -EFAULT if struct kvm_reinject_control cannot be read,
3340 -EINVAL if the supplied shift or flags are invalid
3341 -ENXIO is there is no pending HPT, or the pending HPT doesn't
3342 have the requested size
3343 -EBUSY if the pending HPT is not fully prepared
3344 -ENOSPC if there was a hash collision when moving existing
3345 HPT entries to the new HPT
3346 -EIO on other error conditions
3347
3348Used to implement the PAPR extension for runtime resizing of a guest's
3349Hashed Page Table (HPT). Specifically this requests that the guest be
3350transferred to working with the new HPT, essentially implementing the
3351H_RESIZE_HPT_COMMIT hypercall.
3352
3353This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
3354returned 0 with the same parameters. In other cases
3355KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
3356-EBUSY, though others may be possible if the preparation was started,
3357but failed).
3358
3359This will have undefined effects on the guest if it has not already
3360placed itself in a quiescent state where no vcpu will make MMU enabled
3361memory accesses.
3362
3363On succsful completion, the pending HPT will become the guest's active
3364HPT and the previous HPT will be discarded.
3365
3366On failure, the guest will still be operating on its previous HPT.
3367
3368struct kvm_ppc_resize_hpt {
3369 __u64 flags;
3370 __u32 shift;
3371 __u32 pad;
3372};
3373
Luiz Capitulino3aa53852017-03-13 09:08:20 -040033744.104 KVM_X86_GET_MCE_CAP_SUPPORTED
3375
3376Capability: KVM_CAP_MCE
3377Architectures: x86
3378Type: system ioctl
3379Parameters: u64 mce_cap (out)
3380Returns: 0 on success, -1 on error
3381
3382Returns supported MCE capabilities. The u64 mce_cap parameter
3383has the same format as the MSR_IA32_MCG_CAP register. Supported
3384capabilities will have the corresponding bits set.
3385
33864.105 KVM_X86_SETUP_MCE
3387
3388Capability: KVM_CAP_MCE
3389Architectures: x86
3390Type: vcpu ioctl
3391Parameters: u64 mcg_cap (in)
3392Returns: 0 on success,
3393 -EFAULT if u64 mcg_cap cannot be read,
3394 -EINVAL if the requested number of banks is invalid,
3395 -EINVAL if requested MCE capability is not supported.
3396
3397Initializes MCE support for use. The u64 mcg_cap parameter
3398has the same format as the MSR_IA32_MCG_CAP register and
3399specifies which capabilities should be enabled. The maximum
3400supported number of error-reporting banks can be retrieved when
3401checking for KVM_CAP_MCE. The supported capabilities can be
3402retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
3403
34044.106 KVM_X86_SET_MCE
3405
3406Capability: KVM_CAP_MCE
3407Architectures: x86
3408Type: vcpu ioctl
3409Parameters: struct kvm_x86_mce (in)
3410Returns: 0 on success,
3411 -EFAULT if struct kvm_x86_mce cannot be read,
3412 -EINVAL if the bank number is invalid,
3413 -EINVAL if VAL bit is not set in status field.
3414
3415Inject a machine check error (MCE) into the guest. The input
3416parameter is:
3417
3418struct kvm_x86_mce {
3419 __u64 status;
3420 __u64 addr;
3421 __u64 misc;
3422 __u64 mcg_status;
3423 __u8 bank;
3424 __u8 pad1[7];
3425 __u64 pad2[3];
3426};
3427
3428If the MCE being reported is an uncorrected error, KVM will
3429inject it as an MCE exception into the guest. If the guest
3430MCG_STATUS register reports that an MCE is in progress, KVM
3431causes an KVM_EXIT_SHUTDOWN vmexit.
3432
3433Otherwise, if the MCE is a corrected error, KVM will just
3434store it in the corresponding bank (provided this bank is
3435not holding a previously reported uncorrected error).
3436
Claudio Imbrenda4036e382016-08-04 17:58:47 +020034374.107 KVM_S390_GET_CMMA_BITS
3438
3439Capability: KVM_CAP_S390_CMMA_MIGRATION
3440Architectures: s390
3441Type: vm ioctl
3442Parameters: struct kvm_s390_cmma_log (in, out)
3443Returns: 0 on success, a negative value on error
3444
3445This ioctl is used to get the values of the CMMA bits on the s390
3446architecture. It is meant to be used in two scenarios:
3447- During live migration to save the CMMA values. Live migration needs
3448 to be enabled via the KVM_REQ_START_MIGRATION VM property.
3449- To non-destructively peek at the CMMA values, with the flag
3450 KVM_S390_CMMA_PEEK set.
3451
3452The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
3453values are written to a buffer whose location is indicated via the "values"
3454member in the kvm_s390_cmma_log struct. The values in the input struct are
3455also updated as needed.
3456Each CMMA value takes up one byte.
3457
3458struct kvm_s390_cmma_log {
3459 __u64 start_gfn;
3460 __u32 count;
3461 __u32 flags;
3462 union {
3463 __u64 remaining;
3464 __u64 mask;
3465 };
3466 __u64 values;
3467};
3468
3469start_gfn is the number of the first guest frame whose CMMA values are
3470to be retrieved,
3471
3472count is the length of the buffer in bytes,
3473
3474values points to the buffer where the result will be written to.
3475
3476If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
3477KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
3478other ioctls.
3479
3480The result is written in the buffer pointed to by the field values, and
3481the values of the input parameter are updated as follows.
3482
3483Depending on the flags, different actions are performed. The only
3484supported flag so far is KVM_S390_CMMA_PEEK.
3485
3486The default behaviour if KVM_S390_CMMA_PEEK is not set is:
3487start_gfn will indicate the first page frame whose CMMA bits were dirty.
3488It is not necessarily the same as the one passed as input, as clean pages
3489are skipped.
3490
3491count will indicate the number of bytes actually written in the buffer.
3492It can (and very often will) be smaller than the input value, since the
3493buffer is only filled until 16 bytes of clean values are found (which
3494are then not copied in the buffer). Since a CMMA migration block needs
3495the base address and the length, for a total of 16 bytes, we will send
3496back some clean data if there is some dirty data afterwards, as long as
3497the size of the clean data does not exceed the size of the header. This
3498allows to minimize the amount of data to be saved or transferred over
3499the network at the expense of more roundtrips to userspace. The next
3500invocation of the ioctl will skip over all the clean values, saving
3501potentially more than just the 16 bytes we found.
3502
3503If KVM_S390_CMMA_PEEK is set:
3504the existing storage attributes are read even when not in migration
3505mode, and no other action is performed;
3506
3507the output start_gfn will be equal to the input start_gfn,
3508
3509the output count will be equal to the input count, except if the end of
3510memory has been reached.
3511
3512In both cases:
3513the field "remaining" will indicate the total number of dirty CMMA values
3514still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
3515not enabled.
3516
3517mask is unused.
3518
3519values points to the userspace buffer where the result will be stored.
3520
3521This ioctl can fail with -ENOMEM if not enough memory can be allocated to
3522complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
3523KVM_S390_CMMA_PEEK is not set but migration mode was not enabled, with
3524-EFAULT if the userspace address is invalid or if no page table is
3525present for the addresses (e.g. when using hugepages).
3526
35274.108 KVM_S390_SET_CMMA_BITS
3528
3529Capability: KVM_CAP_S390_CMMA_MIGRATION
3530Architectures: s390
3531Type: vm ioctl
3532Parameters: struct kvm_s390_cmma_log (in)
3533Returns: 0 on success, a negative value on error
3534
3535This ioctl is used to set the values of the CMMA bits on the s390
3536architecture. It is meant to be used during live migration to restore
3537the CMMA values, but there are no restrictions on its use.
3538The ioctl takes parameters via the kvm_s390_cmma_values struct.
3539Each CMMA value takes up one byte.
3540
3541struct kvm_s390_cmma_log {
3542 __u64 start_gfn;
3543 __u32 count;
3544 __u32 flags;
3545 union {
3546 __u64 remaining;
3547 __u64 mask;
3548 };
3549 __u64 values;
3550};
3551
3552start_gfn indicates the starting guest frame number,
3553
3554count indicates how many values are to be considered in the buffer,
3555
3556flags is not used and must be 0.
3557
3558mask indicates which PGSTE bits are to be considered.
3559
3560remaining is not used.
3561
3562values points to the buffer in userspace where to store the values.
3563
3564This ioctl can fail with -ENOMEM if not enough memory can be allocated to
3565complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
3566the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
3567if the flags field was not 0, with -EFAULT if the userspace address is
3568invalid, if invalid pages are written to (e.g. after the end of memory)
3569or if no page table is present for the addresses (e.g. when using
3570hugepages).
3571
Radim Krčmář7bf14c22018-02-01 15:04:17 +010035724.109 KVM_PPC_GET_CPU_CHAR
Paul Mackerras3214d012018-01-15 16:06:47 +11003573
3574Capability: KVM_CAP_PPC_GET_CPU_CHAR
3575Architectures: powerpc
3576Type: vm ioctl
3577Parameters: struct kvm_ppc_cpu_char (out)
3578Returns: 0 on successful completion
3579 -EFAULT if struct kvm_ppc_cpu_char cannot be written
3580
3581This ioctl gives userspace information about certain characteristics
3582of the CPU relating to speculative execution of instructions and
3583possible information leakage resulting from speculative execution (see
3584CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is
3585returned in struct kvm_ppc_cpu_char, which looks like this:
3586
3587struct kvm_ppc_cpu_char {
3588 __u64 character; /* characteristics of the CPU */
3589 __u64 behaviour; /* recommended software behaviour */
3590 __u64 character_mask; /* valid bits in character */
3591 __u64 behaviour_mask; /* valid bits in behaviour */
3592};
3593
3594For extensibility, the character_mask and behaviour_mask fields
3595indicate which bits of character and behaviour have been filled in by
3596the kernel. If the set of defined bits is extended in future then
3597userspace will be able to tell whether it is running on a kernel that
3598knows about the new bits.
3599
3600The character field describes attributes of the CPU which can help
3601with preventing inadvertent information disclosure - specifically,
3602whether there is an instruction to flash-invalidate the L1 data cache
3603(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
3604to a mode where entries can only be used by the thread that created
3605them, whether the bcctr[l] instruction prevents speculation, and
3606whether a speculation barrier instruction (ori 31,31,0) is provided.
3607
3608The behaviour field describes actions that software should take to
3609prevent inadvertent information disclosure, and thus describes which
3610vulnerabilities the hardware is subject to; specifically whether the
3611L1 data cache should be flushed when returning to user mode from the
3612kernel, and whether a speculation barrier should be placed between an
3613array bounds check and the array access.
3614
3615These fields use the same bit definitions as the new
3616H_GET_CPU_CHARACTERISTICS hypercall.
3617
Radim Krčmář7bf14c22018-02-01 15:04:17 +010036184.110 KVM_MEMORY_ENCRYPT_OP
Brijesh Singh5acc5c02017-12-04 10:57:26 -06003619
3620Capability: basic
3621Architectures: x86
3622Type: system
3623Parameters: an opaque platform specific structure (in/out)
3624Returns: 0 on success; -1 on error
3625
3626If the platform supports creating encrypted VMs then this ioctl can be used
3627for issuing platform-specific memory encryption commands to manage those
3628encrypted VMs.
3629
3630Currently, this ioctl is used for issuing Secure Encrypted Virtualization
3631(SEV) commands on AMD Processors. The SEV commands are defined in
Andrew Jones21e94ac2018-03-26 14:38:02 +02003632Documentation/virtual/kvm/amd-memory-encryption.rst.
Brijesh Singh5acc5c02017-12-04 10:57:26 -06003633
Radim Krčmář7bf14c22018-02-01 15:04:17 +010036344.111 KVM_MEMORY_ENCRYPT_REG_REGION
Brijesh Singh69eaede2017-12-04 10:57:26 -06003635
3636Capability: basic
3637Architectures: x86
3638Type: system
3639Parameters: struct kvm_enc_region (in)
3640Returns: 0 on success; -1 on error
3641
3642This ioctl can be used to register a guest memory region which may
3643contain encrypted data (e.g. guest RAM, SMRAM etc).
3644
3645It is used in the SEV-enabled guest. When encryption is enabled, a guest
3646memory region may contain encrypted data. The SEV memory encryption
3647engine uses a tweak such that two identical plaintext pages, each at
3648different locations will have differing ciphertexts. So swapping or
3649moving ciphertext of those pages will not result in plaintext being
3650swapped. So relocating (or migrating) physical backing pages for the SEV
3651guest will require some additional steps.
3652
3653Note: The current SEV key management spec does not provide commands to
3654swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
3655memory region registered with the ioctl.
3656
Radim Krčmář7bf14c22018-02-01 15:04:17 +010036574.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
Brijesh Singh69eaede2017-12-04 10:57:26 -06003658
3659Capability: basic
3660Architectures: x86
3661Type: system
3662Parameters: struct kvm_enc_region (in)
3663Returns: 0 on success; -1 on error
3664
3665This ioctl can be used to unregister the guest memory region registered
3666with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
3667
Roman Kaganfaeb7832018-02-01 16:48:32 +030036684.113 KVM_HYPERV_EVENTFD
3669
3670Capability: KVM_CAP_HYPERV_EVENTFD
3671Architectures: x86
3672Type: vm ioctl
3673Parameters: struct kvm_hyperv_eventfd (in)
3674
3675This ioctl (un)registers an eventfd to receive notifications from the guest on
3676the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
3677causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
3678(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
3679
3680struct kvm_hyperv_eventfd {
3681 __u32 conn_id;
3682 __s32 fd;
3683 __u32 flags;
3684 __u32 padding[3];
3685};
3686
3687The conn_id field should fit within 24 bits:
3688
3689#define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
3690
3691The acceptable values for the flags field are:
3692
3693#define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
3694
3695Returns: 0 on success,
3696 -EINVAL if conn_id or flags is outside the allowed range
3697 -ENOENT on deassign if the conn_id isn't registered
3698 -EEXIST on assign if the conn_id is already registered
3699
Jim Mattson8fcc4b52018-07-10 11:27:20 +020037004.114 KVM_GET_NESTED_STATE
3701
3702Capability: KVM_CAP_NESTED_STATE
3703Architectures: x86
3704Type: vcpu ioctl
3705Parameters: struct kvm_nested_state (in/out)
3706Returns: 0 on success, -1 on error
3707Errors:
3708 E2BIG: the total state size (including the fixed-size part of struct
3709 kvm_nested_state) exceeds the value of 'size' specified by
3710 the user; the size required will be written into size.
3711
3712struct kvm_nested_state {
3713 __u16 flags;
3714 __u16 format;
3715 __u32 size;
3716 union {
3717 struct kvm_vmx_nested_state vmx;
3718 struct kvm_svm_nested_state svm;
3719 __u8 pad[120];
3720 };
3721 __u8 data[0];
3722};
3723
3724#define KVM_STATE_NESTED_GUEST_MODE 0x00000001
3725#define KVM_STATE_NESTED_RUN_PENDING 0x00000002
3726
3727#define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001
3728#define KVM_STATE_NESTED_SMM_VMXON 0x00000002
3729
3730struct kvm_vmx_nested_state {
3731 __u64 vmxon_pa;
3732 __u64 vmcs_pa;
3733
3734 struct {
3735 __u16 flags;
3736 } smm;
3737};
3738
3739This ioctl copies the vcpu's nested virtualization state from the kernel to
3740userspace.
3741
3742The maximum size of the state, including the fixed-size part of struct
3743kvm_nested_state, can be retrieved by passing KVM_CAP_NESTED_STATE to
3744the KVM_CHECK_EXTENSION ioctl().
3745
37464.115 KVM_SET_NESTED_STATE
3747
3748Capability: KVM_CAP_NESTED_STATE
3749Architectures: x86
3750Type: vcpu ioctl
3751Parameters: struct kvm_nested_state (in)
3752Returns: 0 on success, -1 on error
3753
3754This copies the vcpu's kvm_nested_state struct from userspace to the kernel. For
3755the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
Radim Krčmář7bf14c22018-02-01 15:04:17 +01003756
Peng Hao99434502018-10-14 07:09:56 +080037574.116 KVM_(UN)REGISTER_COALESCED_MMIO
3758
Peng Hao0804c842018-10-14 07:09:55 +08003759Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio)
3760 KVM_CAP_COALESCED_PIO (for coalesced pio)
Peng Hao99434502018-10-14 07:09:56 +08003761Architectures: all
3762Type: vm ioctl
3763Parameters: struct kvm_coalesced_mmio_zone
3764Returns: 0 on success, < 0 on error
3765
Peng Hao0804c842018-10-14 07:09:55 +08003766Coalesced I/O is a performance optimization that defers hardware
Peng Hao99434502018-10-14 07:09:56 +08003767register write emulation so that userspace exits are avoided. It is
3768typically used to reduce the overhead of emulating frequently accessed
3769hardware registers.
3770
Peng Hao0804c842018-10-14 07:09:55 +08003771When a hardware register is configured for coalesced I/O, write accesses
Peng Hao99434502018-10-14 07:09:56 +08003772do not exit to userspace and their value is recorded in a ring buffer
3773that is shared between kernel and userspace.
3774
Peng Hao0804c842018-10-14 07:09:55 +08003775Coalesced I/O is used if one or more write accesses to a hardware
Peng Hao99434502018-10-14 07:09:56 +08003776register can be deferred until a read or a write to another hardware
3777register on the same device. This last access will cause a vmexit and
3778userspace will process accesses from the ring buffer before emulating
Peng Hao0804c842018-10-14 07:09:55 +08003779it. That will avoid exiting to userspace on repeated writes.
3780
3781Coalesced pio is based on coalesced mmio. There is little difference
3782between coalesced mmio and pio except that coalesced pio records accesses
3783to I/O ports.
Peng Hao99434502018-10-14 07:09:56 +08003784
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020037854.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
3786
3787Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
3788Architectures: x86
3789Type: vm ioctl
3790Parameters: struct kvm_dirty_log (in)
3791Returns: 0 on success, -1 on error
3792
3793/* for KVM_CLEAR_DIRTY_LOG */
3794struct kvm_clear_dirty_log {
3795 __u32 slot;
3796 __u32 num_pages;
3797 __u64 first_page;
3798 union {
3799 void __user *dirty_bitmap; /* one bit per page */
3800 __u64 padding;
3801 };
3802};
3803
3804The ioctl clears the dirty status of pages in a memory slot, according to
3805the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap
3806field. Bit 0 of the bitmap corresponds to page "first_page" in the
3807memory slot, and num_pages is the size in bits of the input bitmap.
3808Both first_page and num_pages must be a multiple of 64. For each bit
3809that is set in the input bitmap, the corresponding page is marked "clean"
3810in KVM's dirty bitmap, and dirty tracking is re-enabled for that page
3811(for example via write-protection, or by clearing the dirty bit in
3812a page table entry).
3813
3814If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies
3815the address space for which you want to return the dirty bitmap.
3816They must be less than the value that KVM_CHECK_EXTENSION returns for
3817the KVM_CAP_MULTI_ADDRESS_SPACE capability.
3818
3819This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
3820is enabled; for more information, see the description of the capability.
3821However, it can always be used as long as KVM_CHECK_EXTENSION confirms
3822that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is present.
3823
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +010038244.118 KVM_GET_SUPPORTED_HV_CPUID
3825
3826Capability: KVM_CAP_HYPERV_CPUID
3827Architectures: x86
3828Type: vcpu ioctl
3829Parameters: struct kvm_cpuid2 (in/out)
3830Returns: 0 on success, -1 on error
3831
3832struct kvm_cpuid2 {
3833 __u32 nent;
3834 __u32 padding;
3835 struct kvm_cpuid_entry2 entries[0];
3836};
3837
3838struct kvm_cpuid_entry2 {
3839 __u32 function;
3840 __u32 index;
3841 __u32 flags;
3842 __u32 eax;
3843 __u32 ebx;
3844 __u32 ecx;
3845 __u32 edx;
3846 __u32 padding[3];
3847};
3848
3849This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in
3850KVM. Userspace can use the information returned by this ioctl to construct
3851cpuid information presented to guests consuming Hyper-V enlightenments (e.g.
3852Windows or Hyper-V guests).
3853
3854CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level
3855Functional Specification (TLFS). These leaves can't be obtained with
3856KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature
3857leaves (0x40000000, 0x40000001).
3858
3859Currently, the following list of CPUID leaves are returned:
3860 HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS
3861 HYPERV_CPUID_INTERFACE
3862 HYPERV_CPUID_VERSION
3863 HYPERV_CPUID_FEATURES
3864 HYPERV_CPUID_ENLIGHTMENT_INFO
3865 HYPERV_CPUID_IMPLEMENT_LIMITS
3866 HYPERV_CPUID_NESTED_FEATURES
3867
3868HYPERV_CPUID_NESTED_FEATURES leaf is only exposed when Enlightened VMCS was
3869enabled on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
3870
3871Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
3872with the 'nent' field indicating the number of entries in the variable-size
3873array 'entries'. If the number of entries is too low to describe all Hyper-V
3874feature leaves, an error (E2BIG) is returned. If the number is more or equal
3875to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the
3876number of valid entries in the 'entries' array, which is then filled.
3877
3878'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved,
3879userspace should not expect to get any particular value there.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02003880
Avi Kivity9c1b96e2009-06-09 12:37:58 +030038815. The kvm_run structure
Jan Kiszka414fa982012-04-24 16:40:15 +02003882------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003883
3884Application code obtains a pointer to the kvm_run structure by
3885mmap()ing a vcpu fd. From that point, application code can control
3886execution by changing fields in kvm_run prior to calling the KVM_RUN
3887ioctl, and obtain information about the reason KVM_RUN returned by
3888looking up structure members.
3889
3890struct kvm_run {
3891 /* in */
3892 __u8 request_interrupt_window;
3893
3894Request that KVM_RUN return when it becomes possible to inject external
3895interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
3896
Paolo Bonzini460df4c2017-02-08 11:50:15 +01003897 __u8 immediate_exit;
3898
3899This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
3900exits immediately, returning -EINTR. In the common scenario where a
3901signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
3902to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
3903Rather than blocking the signal outside KVM_RUN, userspace can set up
3904a signal handler that sets run->immediate_exit to a non-zero value.
3905
3906This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
3907
3908 __u8 padding1[6];
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003909
3910 /* out */
3911 __u32 exit_reason;
3912
3913When KVM_RUN has returned successfully (return value 0), this informs
3914application code why KVM_RUN has returned. Allowable values for this
3915field are detailed below.
3916
3917 __u8 ready_for_interrupt_injection;
3918
3919If request_interrupt_window has been specified, this field indicates
3920an interrupt can be injected now with KVM_INTERRUPT.
3921
3922 __u8 if_flag;
3923
3924The value of the current interrupt flag. Only valid if in-kernel
3925local APIC is not used.
3926
Paolo Bonzinif0778252015-04-01 15:06:40 +02003927 __u16 flags;
3928
3929More architecture-specific flags detailing state of the VCPU that may
3930affect the device's behavior. The only currently defined flag is
3931KVM_RUN_X86_SMM, which is valid on x86 machines and is set if the
3932VCPU is in system management mode.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003933
3934 /* in (pre_kvm_run), out (post_kvm_run) */
3935 __u64 cr8;
3936
3937The value of the cr8 register. Only valid if in-kernel local APIC is
3938not used. Both input and output.
3939
3940 __u64 apic_base;
3941
3942The value of the APIC BASE msr. Only valid if in-kernel local
3943APIC is not used. Both input and output.
3944
3945 union {
3946 /* KVM_EXIT_UNKNOWN */
3947 struct {
3948 __u64 hardware_exit_reason;
3949 } hw;
3950
3951If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
3952reasons. Further architecture-specific information is available in
3953hardware_exit_reason.
3954
3955 /* KVM_EXIT_FAIL_ENTRY */
3956 struct {
3957 __u64 hardware_entry_failure_reason;
3958 } fail_entry;
3959
3960If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
3961to unknown reasons. Further architecture-specific information is
3962available in hardware_entry_failure_reason.
3963
3964 /* KVM_EXIT_EXCEPTION */
3965 struct {
3966 __u32 exception;
3967 __u32 error_code;
3968 } ex;
3969
3970Unused.
3971
3972 /* KVM_EXIT_IO */
3973 struct {
3974#define KVM_EXIT_IO_IN 0
3975#define KVM_EXIT_IO_OUT 1
3976 __u8 direction;
3977 __u8 size; /* bytes */
3978 __u16 port;
3979 __u32 count;
3980 __u64 data_offset; /* relative to kvm_run start */
3981 } io;
3982
Wu Fengguang2044892d2009-12-24 09:04:16 +08003983If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003984executed a port I/O instruction which could not be satisfied by kvm.
3985data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
3986where kvm expects application code to place the data for the next
Wu Fengguang2044892d2009-12-24 09:04:16 +08003987KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003988
Alex Bennée8ab30c12015-07-07 17:29:53 +01003989 /* KVM_EXIT_DEBUG */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003990 struct {
3991 struct kvm_debug_exit_arch arch;
3992 } debug;
3993
Alex Bennée8ab30c12015-07-07 17:29:53 +01003994If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
3995for which architecture specific information is returned.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003996
3997 /* KVM_EXIT_MMIO */
3998 struct {
3999 __u64 phys_addr;
4000 __u8 data[8];
4001 __u32 len;
4002 __u8 is_write;
4003 } mmio;
4004
Wu Fengguang2044892d2009-12-24 09:04:16 +08004005If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004006executed a memory-mapped I/O instruction which could not be satisfied
4007by kvm. The 'data' member contains the written data if 'is_write' is
4008true, and should be filled by application code otherwise.
4009
Christoffer Dall6acdb162014-01-28 08:28:42 -08004010The 'data' member contains, in its first 'len' bytes, the value as it would
4011appear if the VCPU performed a load or store of the appropriate width directly
4012to the byte array.
4013
Paolo Bonzinicc568ea2014-08-05 09:55:22 +02004014NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR and
Alexander Grafce91ddc2014-07-28 19:29:13 +02004015 KVM_EXIT_EPR the corresponding
Alexander Grafad0a0482010-03-24 21:48:30 +01004016operations are complete (and guest state is consistent) only after userspace
4017has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02004018incomplete operations and then check for pending signals. Userspace
4019can re-enter the guest with an unmasked signal pending to complete
4020pending operations.
4021
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004022 /* KVM_EXIT_HYPERCALL */
4023 struct {
4024 __u64 nr;
4025 __u64 args[6];
4026 __u64 ret;
4027 __u32 longmode;
4028 __u32 pad;
4029 } hypercall;
4030
Avi Kivity647dc492010-04-01 14:39:21 +03004031Unused. This was once used for 'hypercall to userspace'. To implement
4032such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
4033Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004034
4035 /* KVM_EXIT_TPR_ACCESS */
4036 struct {
4037 __u64 rip;
4038 __u32 is_write;
4039 __u32 pad;
4040 } tpr_access;
4041
4042To be documented (KVM_TPR_ACCESS_REPORTING).
4043
4044 /* KVM_EXIT_S390_SIEIC */
4045 struct {
4046 __u8 icptcode;
4047 __u64 mask; /* psw upper half */
4048 __u64 addr; /* psw lower half */
4049 __u16 ipa;
4050 __u32 ipb;
4051 } s390_sieic;
4052
4053s390 specific.
4054
4055 /* KVM_EXIT_S390_RESET */
4056#define KVM_S390_RESET_POR 1
4057#define KVM_S390_RESET_CLEAR 2
4058#define KVM_S390_RESET_SUBSYSTEM 4
4059#define KVM_S390_RESET_CPU_INIT 8
4060#define KVM_S390_RESET_IPL 16
4061 __u64 s390_reset_flags;
4062
4063s390 specific.
4064
Carsten Ottee168bf82012-01-04 10:25:22 +01004065 /* KVM_EXIT_S390_UCONTROL */
4066 struct {
4067 __u64 trans_exc_code;
4068 __u32 pgm_code;
4069 } s390_ucontrol;
4070
4071s390 specific. A page fault has occurred for a user controlled virtual
4072machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
4073resolved by the kernel.
4074The program code and the translation exception code that were placed
4075in the cpu's lowcore are presented here as defined by the z Architecture
4076Principles of Operation Book in the Chapter for Dynamic Address Translation
4077(DAT)
4078
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004079 /* KVM_EXIT_DCR */
4080 struct {
4081 __u32 dcrn;
4082 __u32 data;
4083 __u8 is_write;
4084 } dcr;
4085
Alexander Grafce91ddc2014-07-28 19:29:13 +02004086Deprecated - was used for 440 KVM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004087
Alexander Grafad0a0482010-03-24 21:48:30 +01004088 /* KVM_EXIT_OSI */
4089 struct {
4090 __u64 gprs[32];
4091 } osi;
4092
4093MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
4094hypercalls and exit with this exit struct that contains all the guest gprs.
4095
4096If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
4097Userspace can now handle the hypercall and when it's done modify the gprs as
4098necessary. Upon guest entry all guest GPRs will then be replaced by the values
4099in this struct.
4100
Paul Mackerrasde56a942011-06-29 00:21:34 +00004101 /* KVM_EXIT_PAPR_HCALL */
4102 struct {
4103 __u64 nr;
4104 __u64 ret;
4105 __u64 args[9];
4106 } papr_hcall;
4107
4108This is used on 64-bit PowerPC when emulating a pSeries partition,
4109e.g. with the 'pseries' machine type in qemu. It occurs when the
4110guest does a hypercall using the 'sc 1' instruction. The 'nr' field
4111contains the hypercall number (from the guest R3), and 'args' contains
4112the arguments (from the guest R4 - R12). Userspace should put the
4113return code in 'ret' and any extra returned values in args[].
4114The possible hypercalls are defined in the Power Architecture Platform
4115Requirements (PAPR) document available from www.power.org (free
4116developer registration required to access it).
4117
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004118 /* KVM_EXIT_S390_TSCH */
4119 struct {
4120 __u16 subchannel_id;
4121 __u16 subchannel_nr;
4122 __u32 io_int_parm;
4123 __u32 io_int_word;
4124 __u32 ipb;
4125 __u8 dequeued;
4126 } s390_tsch;
4127
4128s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
4129and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
4130interrupt for the target subchannel has been dequeued and subchannel_id,
4131subchannel_nr, io_int_parm and io_int_word contain the parameters for that
4132interrupt. ipb is needed for instruction parameter decoding.
4133
Alexander Graf1c810632013-01-04 18:12:48 +01004134 /* KVM_EXIT_EPR */
4135 struct {
4136 __u32 epr;
4137 } epr;
4138
4139On FSL BookE PowerPC chips, the interrupt controller has a fast patch
4140interrupt acknowledge path to the core. When the core successfully
4141delivers an interrupt, it automatically populates the EPR register with
4142the interrupt vector number and acknowledges the interrupt inside
4143the interrupt controller.
4144
4145In case the interrupt controller lives in user space, we need to do
4146the interrupt acknowledge cycle through it to fetch the next to be
4147delivered interrupt vector using this exit.
4148
4149It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
4150external interrupt has just been delivered into the guest. User space
4151should put the acknowledged interrupt vector into the 'epr' field.
4152
Anup Patel8ad6b632014-04-29 11:24:19 +05304153 /* KVM_EXIT_SYSTEM_EVENT */
4154 struct {
4155#define KVM_SYSTEM_EVENT_SHUTDOWN 1
4156#define KVM_SYSTEM_EVENT_RESET 2
Andrey Smetanin2ce79182015-07-03 15:01:41 +03004157#define KVM_SYSTEM_EVENT_CRASH 3
Anup Patel8ad6b632014-04-29 11:24:19 +05304158 __u32 type;
4159 __u64 flags;
4160 } system_event;
4161
4162If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
4163a system-level event using some architecture specific mechanism (hypercall
4164or some special instruction). In case of ARM/ARM64, this is triggered using
4165HVC instruction based PSCI call from the vcpu. The 'type' field describes
4166the system-level event type. The 'flags' field describes architecture
4167specific flags for the system-level event.
4168
Christoffer Dallcf5d31882014-10-16 17:00:18 +02004169Valid values for 'type' are:
4170 KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
4171 VM. Userspace is not obliged to honour this, and if it does honour
4172 this does not need to destroy the VM synchronously (ie it may call
4173 KVM_RUN again before shutdown finally occurs).
4174 KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
4175 As with SHUTDOWN, userspace can choose to ignore the request, or
4176 to schedule the reset to occur in the future and may call KVM_RUN again.
Andrey Smetanin2ce79182015-07-03 15:01:41 +03004177 KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
4178 has requested a crash condition maintenance. Userspace can choose
4179 to ignore the request, or to gather VM memory core dump and/or
4180 reset/shutdown of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02004181
Steve Rutherford7543a632015-07-29 23:21:41 -07004182 /* KVM_EXIT_IOAPIC_EOI */
4183 struct {
4184 __u8 vector;
4185 } eoi;
4186
4187Indicates that the VCPU's in-kernel local APIC received an EOI for a
4188level-triggered IOAPIC interrupt. This exit only triggers when the
4189IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
4190the userspace IOAPIC should process the EOI and retrigger the interrupt if
4191it is still asserted. Vector is the LAPIC interrupt vector for which the
4192EOI was received.
4193
Andrey Smetanindb3975712015-11-10 15:36:35 +03004194 struct kvm_hyperv_exit {
4195#define KVM_EXIT_HYPERV_SYNIC 1
Andrey Smetanin83326e42016-02-11 16:45:01 +03004196#define KVM_EXIT_HYPERV_HCALL 2
Andrey Smetanindb3975712015-11-10 15:36:35 +03004197 __u32 type;
4198 union {
4199 struct {
4200 __u32 msr;
4201 __u64 control;
4202 __u64 evt_page;
4203 __u64 msg_page;
4204 } synic;
Andrey Smetanin83326e42016-02-11 16:45:01 +03004205 struct {
4206 __u64 input;
4207 __u64 result;
4208 __u64 params[2];
4209 } hcall;
Andrey Smetanindb3975712015-11-10 15:36:35 +03004210 } u;
4211 };
4212 /* KVM_EXIT_HYPERV */
4213 struct kvm_hyperv_exit hyperv;
4214Indicates that the VCPU exits into userspace to process some tasks
4215related to Hyper-V emulation.
4216Valid values for 'type' are:
4217 KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
4218Hyper-V SynIC state change. Notification is used to remap SynIC
4219event/message pages and to enable/disable SynIC messages/events processing
4220in userspace.
4221
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004222 /* Fix the size of the union. */
4223 char padding[256];
4224 };
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01004225
4226 /*
4227 * shared registers between kvm and userspace.
4228 * kvm_valid_regs specifies the register classes set by the host
4229 * kvm_dirty_regs specified the register classes dirtied by userspace
4230 * struct kvm_sync_regs is architecture specific, as well as the
4231 * bits for kvm_valid_regs and kvm_dirty_regs
4232 */
4233 __u64 kvm_valid_regs;
4234 __u64 kvm_dirty_regs;
4235 union {
4236 struct kvm_sync_regs regs;
Ken Hofsass7b7e3952018-01-31 16:03:35 -08004237 char padding[SYNC_REGS_SIZE_BYTES];
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01004238 } s;
4239
4240If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
4241certain guest registers without having to call SET/GET_*REGS. Thus we can
4242avoid some system call overhead if userspace has to handle the exit.
4243Userspace can query the validity of the structure by checking
4244kvm_valid_regs for specific bits. These bits are architecture specific
4245and usually define the validity of a groups of registers. (e.g. one bit
4246 for general purpose registers)
4247
David Hildenbrandd8482c02014-07-29 08:19:26 +02004248Please note that the kernel is allowed to use the kvm_run structure as the
4249primary storage for certain register types. Therefore, the kernel may use the
4250values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
4251
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004252};
Alexander Graf821246a2011-08-31 10:58:55 +02004253
Jan Kiszka414fa982012-04-24 16:40:15 +02004254
Borislav Petkov9c15bb12013-09-22 16:44:50 +02004255
Paul Mackerras699a0ea2014-06-02 11:02:59 +100042566. Capabilities that can be enabled on vCPUs
4257--------------------------------------------
Alexander Graf821246a2011-08-31 10:58:55 +02004258
Cornelia Huck0907c852014-06-27 09:29:26 +02004259There are certain capabilities that change the behavior of the virtual CPU or
4260the virtual machine when enabled. To enable them, please see section 4.37.
4261Below you can find a list of capabilities and what their effect on the vCPU or
4262the virtual machine is when enabling them.
Alexander Graf821246a2011-08-31 10:58:55 +02004263
4264The following information is provided along with the description:
4265
4266 Architectures: which instruction set architectures provide this ioctl.
4267 x86 includes both i386 and x86_64.
4268
Cornelia Huck0907c852014-06-27 09:29:26 +02004269 Target: whether this is a per-vcpu or per-vm capability.
4270
Alexander Graf821246a2011-08-31 10:58:55 +02004271 Parameters: what parameters are accepted by the capability.
4272
4273 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
4274 are not detailed, but errors with specific meanings are.
4275
Jan Kiszka414fa982012-04-24 16:40:15 +02004276
Alexander Graf821246a2011-08-31 10:58:55 +020042776.1 KVM_CAP_PPC_OSI
4278
4279Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004280Target: vcpu
Alexander Graf821246a2011-08-31 10:58:55 +02004281Parameters: none
4282Returns: 0 on success; -1 on error
4283
4284This capability enables interception of OSI hypercalls that otherwise would
4285be treated as normal system calls to be injected into the guest. OSI hypercalls
4286were invented by Mac-on-Linux to have a standardized communication mechanism
4287between the guest and the host.
4288
4289When this capability is enabled, KVM_EXIT_OSI can occur.
4290
Jan Kiszka414fa982012-04-24 16:40:15 +02004291
Alexander Graf821246a2011-08-31 10:58:55 +020042926.2 KVM_CAP_PPC_PAPR
4293
4294Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004295Target: vcpu
Alexander Graf821246a2011-08-31 10:58:55 +02004296Parameters: none
4297Returns: 0 on success; -1 on error
4298
4299This capability enables interception of PAPR hypercalls. PAPR hypercalls are
4300done using the hypercall instruction "sc 1".
4301
4302It also sets the guest privilege level to "supervisor" mode. Usually the guest
4303runs in "hypervisor" privilege mode with a few missing features.
4304
4305In addition to the above, it changes the semantics of SDR1. In this mode, the
4306HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
4307HTAB invisible to the guest.
4308
4309When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
Scott Wooddc83b8b2011-08-18 15:25:21 -05004310
Jan Kiszka414fa982012-04-24 16:40:15 +02004311
Scott Wooddc83b8b2011-08-18 15:25:21 -050043126.3 KVM_CAP_SW_TLB
4313
4314Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004315Target: vcpu
Scott Wooddc83b8b2011-08-18 15:25:21 -05004316Parameters: args[0] is the address of a struct kvm_config_tlb
4317Returns: 0 on success; -1 on error
4318
4319struct kvm_config_tlb {
4320 __u64 params;
4321 __u64 array;
4322 __u32 mmu_type;
4323 __u32 array_len;
4324};
4325
4326Configures the virtual CPU's TLB array, establishing a shared memory area
4327between userspace and KVM. The "params" and "array" fields are userspace
4328addresses of mmu-type-specific data structures. The "array_len" field is an
4329safety mechanism, and should be set to the size in bytes of the memory that
4330userspace has reserved for the array. It must be at least the size dictated
4331by "mmu_type" and "params".
4332
4333While KVM_RUN is active, the shared region is under control of KVM. Its
4334contents are undefined, and any modification by userspace results in
4335boundedly undefined behavior.
4336
4337On return from KVM_RUN, the shared region will reflect the current state of
4338the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
4339to tell KVM which entries have been changed, prior to calling KVM_RUN again
4340on this vcpu.
4341
4342For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
4343 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
4344 - The "array" field points to an array of type "struct
4345 kvm_book3e_206_tlb_entry".
4346 - The array consists of all entries in the first TLB, followed by all
4347 entries in the second TLB.
4348 - Within a TLB, entries are ordered first by increasing set number. Within a
4349 set, entries are ordered by way (increasing ESEL).
4350 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
4351 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
4352 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
4353 hardware ignores this value for TLB0.
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004354
43556.4 KVM_CAP_S390_CSS_SUPPORT
4356
4357Architectures: s390
Cornelia Huck0907c852014-06-27 09:29:26 +02004358Target: vcpu
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004359Parameters: none
4360Returns: 0 on success; -1 on error
4361
4362This capability enables support for handling of channel I/O instructions.
4363
4364TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
4365handled in-kernel, while the other I/O instructions are passed to userspace.
4366
4367When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
4368SUBCHANNEL intercepts.
Alexander Graf1c810632013-01-04 18:12:48 +01004369
Cornelia Huck0907c852014-06-27 09:29:26 +02004370Note that even though this capability is enabled per-vcpu, the complete
4371virtual machine is affected.
4372
Alexander Graf1c810632013-01-04 18:12:48 +010043736.5 KVM_CAP_PPC_EPR
4374
4375Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004376Target: vcpu
Alexander Graf1c810632013-01-04 18:12:48 +01004377Parameters: args[0] defines whether the proxy facility is active
4378Returns: 0 on success; -1 on error
4379
4380This capability enables or disables the delivery of interrupts through the
4381external proxy facility.
4382
4383When enabled (args[0] != 0), every time the guest gets an external interrupt
4384delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
4385to receive the topmost interrupt vector.
4386
4387When disabled (args[0] == 0), behavior is as if this facility is unsupported.
4388
4389When this capability is enabled, KVM_EXIT_EPR can occur.
Scott Woodeb1e4f42013-04-12 14:08:47 +00004390
43916.6 KVM_CAP_IRQ_MPIC
4392
4393Architectures: ppc
4394Parameters: args[0] is the MPIC device fd
4395 args[1] is the MPIC CPU number for this vcpu
4396
4397This capability connects the vcpu to an in-kernel MPIC device.
Paul Mackerras5975a2e2013-04-27 00:28:37 +00004398
43996.7 KVM_CAP_IRQ_XICS
4400
4401Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004402Target: vcpu
Paul Mackerras5975a2e2013-04-27 00:28:37 +00004403Parameters: args[0] is the XICS device fd
4404 args[1] is the XICS CPU number (server ID) for this vcpu
4405
4406This capability connects the vcpu to an in-kernel XICS device.
Cornelia Huck8a366a42014-06-27 11:06:25 +02004407
44086.8 KVM_CAP_S390_IRQCHIP
4409
4410Architectures: s390
4411Target: vm
4412Parameters: none
4413
4414This capability enables the in-kernel irqchip for s390. Please refer to
4415"4.24 KVM_CREATE_IRQCHIP" for details.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10004416
James Hogan5fafd8742014-12-08 23:07:56 +000044176.9 KVM_CAP_MIPS_FPU
4418
4419Architectures: mips
4420Target: vcpu
4421Parameters: args[0] is reserved for future use (should be 0).
4422
4423This capability allows the use of the host Floating Point Unit by the guest. It
4424allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
4425done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed
4426(depending on the current guest FPU register mode), and the Status.FR,
4427Config5.FRE bits are accessible via the KVM API and also from the guest,
4428depending on them being supported by the FPU.
4429
James Hogand952bd02014-12-08 23:07:56 +000044306.10 KVM_CAP_MIPS_MSA
4431
4432Architectures: mips
4433Target: vcpu
4434Parameters: args[0] is reserved for future use (should be 0).
4435
4436This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
4437It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
4438Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be
4439accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from
4440the guest.
4441
Ken Hofsass01643c52018-01-31 16:03:36 -080044426.74 KVM_CAP_SYNC_REGS
4443Architectures: s390, x86
4444Target: s390: always enabled, x86: vcpu
4445Parameters: none
4446Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
4447sets are supported (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
4448
4449As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
4450KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
4451without having to call SET/GET_*REGS". This reduces overhead by eliminating
4452repeated ioctl calls for setting and/or getting register values. This is
4453particularly important when userspace is making synchronous guest state
4454modifications, e.g. when emulating and/or intercepting instructions in
4455userspace.
4456
4457For s390 specifics, please refer to the source code.
4458
4459For x86:
4460- the register sets to be copied out to kvm_run are selectable
4461 by userspace (rather that all sets being copied out for every exit).
4462- vcpu_events are available in addition to regs and sregs.
4463
4464For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
4465function as an input bit-array field set by userspace to indicate the
4466specific register sets to be copied out on the next exit.
4467
4468To indicate when userspace has modified values that should be copied into
4469the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
4470This is done using the same bitflags as for the 'kvm_valid_regs' field.
4471If the dirty bit is not set, then the register set values will not be copied
4472into the vCPU even if they've been modified.
4473
4474Unused bitfields in the bitarrays must be set to zero.
4475
4476struct kvm_sync_regs {
4477 struct kvm_regs regs;
4478 struct kvm_sregs sregs;
4479 struct kvm_vcpu_events events;
4480};
4481
Paul Mackerras699a0ea2014-06-02 11:02:59 +100044827. Capabilities that can be enabled on VMs
4483------------------------------------------
4484
4485There are certain capabilities that change the behavior of the virtual
4486machine when enabled. To enable them, please see section 4.37. Below
4487you can find a list of capabilities and what their effect on the VM
4488is when enabling them.
4489
4490The following information is provided along with the description:
4491
4492 Architectures: which instruction set architectures provide this ioctl.
4493 x86 includes both i386 and x86_64.
4494
4495 Parameters: what parameters are accepted by the capability.
4496
4497 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
4498 are not detailed, but errors with specific meanings are.
4499
4500
45017.1 KVM_CAP_PPC_ENABLE_HCALL
4502
4503Architectures: ppc
4504Parameters: args[0] is the sPAPR hcall number
4505 args[1] is 0 to disable, 1 to enable in-kernel handling
4506
4507This capability controls whether individual sPAPR hypercalls (hcalls)
4508get handled by the kernel or not. Enabling or disabling in-kernel
4509handling of an hcall is effective across the VM. On creation, an
4510initial set of hcalls are enabled for in-kernel handling, which
4511consists of those hcalls for which in-kernel handlers were implemented
4512before this capability was implemented. If disabled, the kernel will
4513not to attempt to handle the hcall, but will always exit to userspace
4514to handle it. Note that it may not make sense to enable some and
4515disable others of a group of related hcalls, but KVM does not prevent
4516userspace from doing that.
Paul Mackerrasae2113a2014-06-02 11:03:00 +10004517
4518If the hcall number specified is not one that has an in-kernel
4519implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
4520error.
David Hildenbrand2444b352014-10-09 14:10:13 +02004521
45227.2 KVM_CAP_S390_USER_SIGP
4523
4524Architectures: s390
4525Parameters: none
4526
4527This capability controls which SIGP orders will be handled completely in user
4528space. With this capability enabled, all fast orders will be handled completely
4529in the kernel:
4530- SENSE
4531- SENSE RUNNING
4532- EXTERNAL CALL
4533- EMERGENCY SIGNAL
4534- CONDITIONAL EMERGENCY SIGNAL
4535
4536All other orders will be handled completely in user space.
4537
4538Only privileged operation exceptions will be checked for in the kernel (or even
4539in the hardware prior to interception). If this capability is not enabled, the
4540old way of handling SIGP orders is used (partially in kernel and user space).
Eric Farman68c55752014-06-09 10:57:26 -04004541
45427.3 KVM_CAP_S390_VECTOR_REGISTERS
4543
4544Architectures: s390
4545Parameters: none
4546Returns: 0 on success, negative value on error
4547
4548Allows use of the vector registers introduced with z13 processor, and
4549provides for the synchronization between host and user space. Will
4550return -EINVAL if the machine does not support vectors.
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01004551
45527.4 KVM_CAP_S390_USER_STSI
4553
4554Architectures: s390
4555Parameters: none
4556
4557This capability allows post-handlers for the STSI instruction. After
4558initial handling in the kernel, KVM exits to user space with
4559KVM_EXIT_S390_STSI to allow user space to insert further data.
4560
4561Before exiting to userspace, kvm handlers should fill in s390_stsi field of
4562vcpu->run:
4563struct {
4564 __u64 addr;
4565 __u8 ar;
4566 __u8 reserved;
4567 __u8 fc;
4568 __u8 sel1;
4569 __u16 sel2;
4570} s390_stsi;
4571
4572@addr - guest address of STSI SYSIB
4573@fc - function code
4574@sel1 - selector 1
4575@sel2 - selector 2
4576@ar - access register number
4577
4578KVM handlers should exit to userspace with rc = -EREMOTE.
Michael Ellermane928e9c2015-03-20 20:39:41 +11004579
Steve Rutherford49df6392015-07-29 23:21:40 -070045807.5 KVM_CAP_SPLIT_IRQCHIP
4581
4582Architectures: x86
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07004583Parameters: args[0] - number of routes reserved for userspace IOAPICs
Steve Rutherford49df6392015-07-29 23:21:40 -07004584Returns: 0 on success, -1 on error
4585
4586Create a local apic for each processor in the kernel. This can be used
4587instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
4588IOAPIC and PIC (and also the PIT, even though this has to be enabled
4589separately).
4590
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07004591This capability also enables in kernel routing of interrupt requests;
4592when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
4593used in the IRQ routing table. The first args[0] MSI routes are reserved
4594for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
4595a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
Steve Rutherford49df6392015-07-29 23:21:40 -07004596
4597Fails if VCPU has already been created, or if the irqchip is already in the
4598kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
4599
David Hildenbrand051c87f2016-04-19 13:13:40 +020046007.6 KVM_CAP_S390_RI
4601
4602Architectures: s390
4603Parameters: none
4604
4605Allows use of runtime-instrumentation introduced with zEC12 processor.
4606Will return -EINVAL if the machine does not support runtime-instrumentation.
4607Will return -EBUSY if a VCPU has already been created.
Michael Ellermane928e9c2015-03-20 20:39:41 +11004608
Radim Krčmář371313132016-07-12 22:09:27 +020046097.7 KVM_CAP_X2APIC_API
4610
4611Architectures: x86
4612Parameters: args[0] - features that should be enabled
4613Returns: 0 on success, -EINVAL when args[0] contains invalid features
4614
4615Valid feature flags in args[0] are
4616
4617#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
Radim Krčmářc5192652016-07-12 22:09:28 +02004618#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
Radim Krčmář371313132016-07-12 22:09:27 +02004619
4620Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
4621KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
4622allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
4623respective sections.
4624
Radim Krčmářc5192652016-07-12 22:09:28 +02004625KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
4626in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
4627as a broadcast even in x2APIC mode in order to support physical x2APIC
4628without interrupt remapping. This is undesirable in logical mode,
4629where 0xff represents CPUs 0-7 in cluster 0.
Radim Krčmář371313132016-07-12 22:09:27 +02004630
David Hildenbrand6502a342016-06-21 14:19:51 +020046317.8 KVM_CAP_S390_USER_INSTR0
4632
4633Architectures: s390
4634Parameters: none
4635
4636With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
4637be intercepted and forwarded to user space. User space can use this
4638mechanism e.g. to realize 2-byte software breakpoints. The kernel will
4639not inject an operating exception for these instructions, user space has
4640to take care of that.
4641
4642This capability can be enabled dynamically even if VCPUs were already
4643created and are running.
Radim Krčmář371313132016-07-12 22:09:27 +02004644
Fan Zhang4e0b1ab2016-11-29 07:17:55 +010046457.9 KVM_CAP_S390_GS
4646
4647Architectures: s390
4648Parameters: none
4649Returns: 0 on success; -EINVAL if the machine does not support
4650 guarded storage; -EBUSY if a VCPU has already been created.
4651
4652Allows use of guarded storage for the KVM guest.
4653
Yi Min Zhao47a46932017-03-10 09:29:38 +010046547.10 KVM_CAP_S390_AIS
4655
4656Architectures: s390
4657Parameters: none
4658
4659Allow use of adapter-interruption suppression.
4660Returns: 0 on success; -EBUSY if a VCPU has already been created.
4661
Paul Mackerras3c313522017-02-06 13:24:41 +110046627.11 KVM_CAP_PPC_SMT
4663
4664Architectures: ppc
4665Parameters: vsmt_mode, flags
4666
4667Enabling this capability on a VM provides userspace with a way to set
4668the desired virtual SMT mode (i.e. the number of virtual CPUs per
4669virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
4670between 1 and 8. On POWER8, vsmt_mode must also be no greater than
4671the number of threads per subcore for the host. Currently flags must
4672be 0. A successful call to enable this capability will result in
4673vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
4674subsequently queried for the VM. This capability is only supported by
4675HV KVM, and can only be set before any VCPUs have been created.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10004676The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
4677modes are available.
Paul Mackerras3c313522017-02-06 13:24:41 +11004678
Aravinda Prasad134764e2017-05-11 16:32:48 +053046797.12 KVM_CAP_PPC_FWNMI
4680
4681Architectures: ppc
4682Parameters: none
4683
4684With this capability a machine check exception in the guest address
4685space will cause KVM to exit the guest with NMI exit reason. This
4686enables QEMU to build error log and branch to guest kernel registered
4687machine check handling routine. Without this capability KVM will
4688branch to guests' 0x200 interrupt vector.
4689
Wanpeng Li4d5422c2018-03-12 04:53:02 -070046907.13 KVM_CAP_X86_DISABLE_EXITS
4691
4692Architectures: x86
4693Parameters: args[0] defines which exits are disabled
4694Returns: 0 on success, -EINVAL when args[0] contains invalid exits
4695
4696Valid bits in args[0] are
4697
4698#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
Wanpeng Licaa057a2018-03-12 04:53:03 -07004699#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
Wanpeng Li4d5422c2018-03-12 04:53:02 -07004700
4701Enabling this capability on a VM provides userspace with a way to no
4702longer intercept some instructions for improved latency in some
4703workloads, and is suggested when vCPUs are associated to dedicated
4704physical CPUs. More bits can be added in the future; userspace can
4705just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
4706all such vmexits.
4707
Wanpeng Licaa057a2018-03-12 04:53:03 -07004708Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
Wanpeng Li4d5422c2018-03-12 04:53:02 -07004709
Janosch Franka4499382018-07-13 11:28:31 +010047107.14 KVM_CAP_S390_HPAGE_1M
4711
4712Architectures: s390
4713Parameters: none
4714Returns: 0 on success, -EINVAL if hpage module parameter was not set
Janosch Frank40ebdb82018-08-01 11:48:28 +01004715 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
4716 flag set
Janosch Franka4499382018-07-13 11:28:31 +01004717
4718With this capability the KVM support for memory backing with 1m pages
4719through hugetlbfs can be enabled for a VM. After the capability is
4720enabled, cmma can't be enabled anymore and pfmfi and the storage key
4721interpretation are disabled. If cmma has already been enabled or the
4722hpage module parameter is not set to 1, -EINVAL is returned.
4723
4724While it is generally possible to create a huge page backed VM without
4725this capability, the VM will not be able to run.
4726
Jim Mattsonc4f55192018-10-16 14:29:24 -070047277.15 KVM_CAP_MSR_PLATFORM_INFO
Drew Schmitt6fbbde92018-08-20 10:32:15 -07004728
4729Architectures: x86
4730Parameters: args[0] whether feature should be enabled or not
4731
4732With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
4733a #GP would be raised when the guest tries to access. Currently, this
4734capability does not enable write permissions of this MSR for the guest.
4735
Paul Mackerrasaa069a92018-09-21 20:02:01 +100047367.16 KVM_CAP_PPC_NESTED_HV
4737
4738Architectures: ppc
4739Parameters: none
4740Returns: 0 on success, -EINVAL when the implementation doesn't support
4741 nested-HV virtualization.
4742
4743HV-KVM on POWER9 and later systems allows for "nested-HV"
4744virtualization, which provides a way for a guest VM to run guests that
4745can run using the CPU's supervisor mode (privileged non-hypervisor
4746state). Enabling this capability on a VM depends on the CPU having
4747the necessary functionality and on the facility being enabled with a
4748kvm-hv module parameter.
4749
Jim Mattsonc4f55192018-10-16 14:29:24 -070047507.17 KVM_CAP_EXCEPTION_PAYLOAD
4751
4752Architectures: x86
4753Parameters: args[0] whether feature should be enabled or not
4754
4755With this capability enabled, CR2 will not be modified prior to the
4756emulated VM-exit when L1 intercepts a #PF exception that occurs in
4757L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
4758the emulated VM-exit when L1 intercepts a #DB exception that occurs in
4759L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
4760#DB) exception for L2, exception.has_payload will be set and the
4761faulting address (or the new DR6 bits*) will be reported in the
4762exception_payload field. Similarly, when userspace injects a #PF (or
4763#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
4764exception.has_payload and to put the faulting address (or the new DR6
4765bits*) in the exception_payload field.
4766
4767This capability also enables exception.pending in struct
4768kvm_vcpu_events, which allows userspace to distinguish between pending
4769and injected exceptions.
4770
4771
4772* For the new DR6 bits, note that bit 16 is set iff the #DB exception
4773 will clear DR6.RTM.
4774
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020047757.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
4776
4777Architectures: all
4778Parameters: args[0] whether feature should be enabled or not
4779
4780With this capability enabled, KVM_GET_DIRTY_LOG will not automatically
4781clear and write-protect all pages that are returned as dirty.
4782Rather, userspace will have to do this operation separately using
4783KVM_CLEAR_DIRTY_LOG.
4784
4785At the cost of a slightly more complicated operation, this provides better
4786scalability and responsiveness for two reasons. First,
4787KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
4788than requiring to sync a full memslot; this ensures that KVM does not
4789take spinlocks for an extended period of time. Second, in some cases a
4790large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
4791userspace actually using the data in the page. Pages can be modified
4792during this time, which is inefficint for both the guest and userspace:
4793the guest will incur a higher penalty due to write protection faults,
4794while userspace can see false reports of dirty pages. Manual reprotection
4795helps reducing this time, improving guest performance and reducing the
4796number of dirty log false positives.
4797
4798
Michael Ellermane928e9c2015-03-20 20:39:41 +110047998. Other capabilities.
4800----------------------
4801
4802This section lists capabilities that give information about other
4803features of the KVM implementation.
4804
48058.1 KVM_CAP_PPC_HWRNG
4806
4807Architectures: ppc
4808
4809This capability, if KVM_CHECK_EXTENSION indicates that it is
4810available, means that that the kernel has an implementation of the
4811H_RANDOM hypercall backed by a hardware random-number generator.
4812If present, the kernel H_RANDOM handler can be enabled for guest use
4813with the KVM_CAP_PPC_ENABLE_HCALL capability.
Andrey Smetanin5c9194122015-11-10 15:36:34 +03004814
48158.2 KVM_CAP_HYPERV_SYNIC
4816
4817Architectures: x86
4818This capability, if KVM_CHECK_EXTENSION indicates that it is
4819available, means that that the kernel has an implementation of the
4820Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
4821used to support Windows Hyper-V based guest paravirt drivers(VMBus).
4822
4823In order to use SynIC, it has to be activated by setting this
4824capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
4825will disable the use of APIC hardware virtualization even if supported
4826by the CPU, as it's incompatible with SynIC auto-EOI behavior.
Paul Mackerrasc9270132017-01-30 21:21:41 +11004827
48288.3 KVM_CAP_PPC_RADIX_MMU
4829
4830Architectures: ppc
4831
4832This capability, if KVM_CHECK_EXTENSION indicates that it is
4833available, means that that the kernel can support guests using the
4834radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
4835processor).
4836
48378.4 KVM_CAP_PPC_HASH_MMU_V3
4838
4839Architectures: ppc
4840
4841This capability, if KVM_CHECK_EXTENSION indicates that it is
4842available, means that that the kernel can support guests using the
4843hashed page table MMU defined in Power ISA V3.00 (as implemented in
4844the POWER9 processor), including in-memory segment tables.
James Hogana8a3c422017-03-14 10:15:19 +00004845
48468.5 KVM_CAP_MIPS_VZ
4847
4848Architectures: mips
4849
4850This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
4851it is available, means that full hardware assisted virtualization capabilities
4852of the hardware are available for use through KVM. An appropriate
4853KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
4854utilises it.
4855
4856If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
4857available, it means that the VM is using full hardware assisted virtualization
4858capabilities of the hardware. This is useful to check after creating a VM with
4859KVM_VM_MIPS_DEFAULT.
4860
4861The value returned by KVM_CHECK_EXTENSION should be compared against known
4862values (see below). All other values are reserved. This is to allow for the
4863possibility of other hardware assisted virtualization implementations which
4864may be incompatible with the MIPS VZ ASE.
4865
4866 0: The trap & emulate implementation is in use to run guest code in user
4867 mode. Guest virtual memory segments are rearranged to fit the guest in the
4868 user mode address space.
4869
4870 1: The MIPS VZ ASE is in use, providing full hardware assisted
4871 virtualization, including standard guest virtual memory segments.
4872
48738.6 KVM_CAP_MIPS_TE
4874
4875Architectures: mips
4876
4877This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
4878it is available, means that the trap & emulate implementation is available to
4879run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
4880assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
4881to KVM_CREATE_VM to create a VM which utilises it.
4882
4883If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
4884available, it means that the VM is using trap & emulate.
James Hogan578fd612017-03-14 10:15:20 +00004885
48868.7 KVM_CAP_MIPS_64BIT
4887
4888Architectures: mips
4889
4890This capability indicates the supported architecture type of the guest, i.e. the
4891supported register and address width.
4892
4893The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
4894kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
4895be checked specifically against known values (see below). All other values are
4896reserved.
4897
4898 0: MIPS32 or microMIPS32.
4899 Both registers and addresses are 32-bits wide.
4900 It will only be possible to run 32-bit guest code.
4901
4902 1: MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
4903 Registers are 64-bits wide, but addresses are 32-bits wide.
4904 64-bit guest code may run but cannot access MIPS64 memory segments.
4905 It will also be possible to run 32-bit guest code.
4906
4907 2: MIPS64 or microMIPS64 with access to all address segments.
4908 Both registers and addresses are 64-bits wide.
4909 It will be possible to run 64-bit or 32-bit guest code.
Michael S. Tsirkin668fffa2017-04-21 12:27:17 +02004910
Paolo Bonzinic24a7be2017-04-27 17:33:14 +020049118.9 KVM_CAP_ARM_USER_IRQ
Alexander Graf3fe17e62016-09-27 21:08:05 +02004912
4913Architectures: arm, arm64
4914This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
4915that if userspace creates a VM without an in-kernel interrupt controller, it
4916will be notified of changes to the output level of in-kernel emulated devices,
4917which can generate virtual interrupts, presented to the VM.
4918For such VMs, on every return to userspace, the kernel
4919updates the vcpu's run->s.regs.device_irq_level field to represent the actual
4920output level of the device.
4921
4922Whenever kvm detects a change in the device output level, kvm guarantees at
4923least one return to userspace before running the VM. This exit could either
4924be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
4925userspace can always sample the device output level and re-compute the state of
4926the userspace interrupt controller. Userspace should always check the state
4927of run->s.regs.device_irq_level on every kvm exit.
4928The value in run->s.regs.device_irq_level can represent both level and edge
4929triggered interrupt signals, depending on the device. Edge triggered interrupt
4930signals will exit to userspace with the bit in run->s.regs.device_irq_level
4931set exactly once per edge signal.
4932
4933The field run->s.regs.device_irq_level is available independent of
4934run->kvm_valid_regs or run->kvm_dirty_regs bits.
4935
4936If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
4937number larger than 0 indicating the version of this capability is implemented
4938and thereby which bits in in run->s.regs.device_irq_level can signal values.
4939
4940Currently the following bits are defined for the device_irq_level bitmap:
4941
4942 KVM_CAP_ARM_USER_IRQ >= 1:
4943
4944 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
4945 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
4946 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
4947
4948Future versions of kvm may implement additional events. These will get
4949indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
4950listed above.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10004951
49528.10 KVM_CAP_PPC_SMT_POSSIBLE
4953
4954Architectures: ppc
4955
4956Querying this capability returns a bitmap indicating the possible
4957virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
4958(counting from the right) is set, then a virtual SMT mode of 2^N is
4959available.
Roman Kaganefc479e2017-06-22 16:51:01 +03004960
49618.11 KVM_CAP_HYPERV_SYNIC2
4962
4963Architectures: x86
4964
4965This capability enables a newer version of Hyper-V Synthetic interrupt
4966controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
4967doesn't clear SynIC message and event flags pages when they are enabled by
4968writing to the respective MSRs.
Roman Kagand3457c82017-07-14 17:13:20 +03004969
49708.12 KVM_CAP_HYPERV_VP_INDEX
4971
4972Architectures: x86
4973
4974This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
4975value is used to denote the target vcpu for a SynIC interrupt. For
4976compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this
4977capability is absent, userspace can still query this msr's value.
Christian Borntraegerda9a1442017-11-09 10:00:45 +01004978
49798.13 KVM_CAP_S390_AIS_MIGRATION
4980
4981Architectures: s390
4982Parameters: none
4983
4984This capability indicates if the flic device will be able to get/set the
4985AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
4986to discover this without having to create a flic device.
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00004987
49888.14 KVM_CAP_S390_PSW
4989
4990Architectures: s390
4991
4992This capability indicates that the PSW is exposed via the kvm_run structure.
4993
49948.15 KVM_CAP_S390_GMAP
4995
4996Architectures: s390
4997
4998This capability indicates that the user space memory used as guest mapping can
4999be anywhere in the user memory address space, as long as the memory slots are
5000aligned and sized to a segment (1MB) boundary.
5001
50028.16 KVM_CAP_S390_COW
5003
5004Architectures: s390
5005
5006This capability indicates that the user space memory used as guest mapping can
5007use copy-on-write semantics as well as dirty pages tracking via read-only page
5008tables.
5009
50108.17 KVM_CAP_S390_BPB
5011
5012Architectures: s390
5013
5014This capability indicates that kvm will implement the interfaces to handle
5015reset, migration and nested KVM for branch prediction blocking. The stfle
5016facility 82 should not be provided to the guest without this capability.
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02005017
Vitaly Kuznetsov2ddc6492018-06-22 16:56:14 +020050188.18 KVM_CAP_HYPERV_TLBFLUSH
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02005019
5020Architectures: x86
5021
5022This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
5023hypercalls:
5024HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
5025HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01005026
Dongjiu Geng688e0582018-08-20 17:39:25 -040050278.19 KVM_CAP_ARM_INJECT_SERROR_ESR
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01005028
5029Architectures: arm, arm64
5030
5031This capability indicates that userspace can specify (via the
5032KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
5033takes a virtual SError interrupt exception.
5034If KVM advertises this capability, userspace can only specify the ISS field for
5035the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
5036CPU when the exception is taken. If this virtual SError is taken to EL1 using
5037AArch64, this value will be reported in the ISS field of ESR_ELx.
5038
5039See KVM_CAP_VCPU_EVENTS for more details.
Vitaly Kuznetsov214ff832018-09-26 19:02:59 +020050408.20 KVM_CAP_HYPERV_SEND_IPI
5041
5042Architectures: x86
5043
5044This capability indicates that KVM supports paravirtualized Hyper-V IPI send
5045hypercalls:
5046HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.