blob: 284d36e72f284108559b6457baf6c1db8947e99d [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
8of a virtual machine. The ioctls belong to three classes
9
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
12 virtual machines
13
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
18 Only run VM ioctls from the same process (address space) that was used
19 to create the VM.
20
21 - vcpu ioctls: These query and set attributes that control the operation
22 of a single virtual cpu.
23
24 Only run vcpu ioctls from the same thread that was used to create the
25 vcpu.
26
Jan Kiszka414fa982012-04-24 16:40:15 +020027
Wu Fengguang2044892d2009-12-24 09:04:16 +0800282. File descriptors
Jan Kiszka414fa982012-04-24 16:40:15 +020029-------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030030
31The kvm API is centered around file descriptors. An initial
32open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
33can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
Wu Fengguang2044892d2009-12-24 09:04:16 +080034handle will create a VM file descriptor which can be used to issue VM
Avi Kivity9c1b96e2009-06-09 12:37:58 +030035ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
36and return a file descriptor pointing to it. Finally, ioctls on a vcpu
37fd can be used to control the vcpu, including the important task of
38actually running guest code.
39
40In general file descriptors can be migrated among processes by means
41of fork() and the SCM_RIGHTS facility of unix domain socket. These
42kinds of tricks are explicitly not supported by kvm. While they will
43not cause harm to the host, their actual behavior is not guaranteed by
44the API. The only supported use is one virtual machine per process,
45and one vcpu per thread.
46
Jan Kiszka414fa982012-04-24 16:40:15 +020047
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300483. Extensions
Jan Kiszka414fa982012-04-24 16:40:15 +020049-------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030050
51As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
52incompatible change are allowed. However, there is an extension
53facility that allows backward-compatible extensions to the API to be
54queried and used.
55
Masanari Iidac9f3f2d2013-07-18 01:29:12 +090056The extension mechanism is not based on the Linux version number.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030057Instead, kvm defines extension identifiers and a facility to query
58whether a particular extension identifier is available. If it is, a
59set of ioctls is available for application use.
60
Jan Kiszka414fa982012-04-24 16:40:15 +020061
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300624. API description
Jan Kiszka414fa982012-04-24 16:40:15 +020063------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030064
65This section describes ioctls that can be used to control kvm guests.
66For each ioctl, the following information is provided along with a
67description:
68
69 Capability: which KVM extension provides this ioctl. Can be 'basic',
70 which means that is will be provided by any kernel that supports
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030071 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
Avi Kivity9c1b96e2009-06-09 12:37:58 +030072 means availability needs to be checked with KVM_CHECK_EXTENSION
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030073 (see section 4.4), or 'none' which means that while not all kernels
74 support this ioctl, there's no capability bit to check its
75 availability: for kernels that don't support the ioctl,
76 the ioctl returns -ENOTTY.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030077
78 Architectures: which instruction set architectures provide this ioctl.
79 x86 includes both i386 and x86_64.
80
81 Type: system, vm, or vcpu.
82
83 Parameters: what parameters are accepted by the ioctl.
84
85 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
86 are not detailed, but errors with specific meanings are.
87
Jan Kiszka414fa982012-04-24 16:40:15 +020088
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300894.1 KVM_GET_API_VERSION
90
91Capability: basic
92Architectures: all
93Type: system ioctl
94Parameters: none
95Returns: the constant KVM_API_VERSION (=12)
96
97This identifies the API version as the stable kvm API. It is not
98expected that this number will change. However, Linux 2.6.20 and
992.6.21 report earlier versions; these are not documented and not
100supported. Applications should refuse to run if KVM_GET_API_VERSION
101returns a value other than 12. If this check passes, all ioctls
102described as 'basic' will be available.
103
Jan Kiszka414fa982012-04-24 16:40:15 +0200104
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001054.2 KVM_CREATE_VM
106
107Capability: basic
108Architectures: all
109Type: system ioctl
Carsten Ottee08b9632012-01-04 10:25:20 +0100110Parameters: machine type identifier (KVM_VM_*)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300111Returns: a VM fd that can be used to control the new virtual machine.
112
Jann Hornbcb85c82017-04-24 11:16:49 +0200113The new VM has no virtual cpus and no memory.
James Hogana8a3c422017-03-14 10:15:19 +0000114You probably want to use 0 as machine type.
Carsten Ottee08b9632012-01-04 10:25:20 +0100115
116In order to create user controlled virtual machines on S390, check
117KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
118privileged user (CAP_SYS_ADMIN).
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300119
James Hogana8a3c422017-03-14 10:15:19 +0000120To use hardware assisted virtualization on MIPS (VZ ASE) rather than
121the default trap & emulate implementation (which changes the virtual
122memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the
123flag KVM_VM_MIPS_VZ.
124
Jan Kiszka414fa982012-04-24 16:40:15 +0200125
Tom Lendacky801e4592018-02-21 13:39:51 -06001264.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300127
Tom Lendacky801e4592018-02-21 13:39:51 -0600128Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300129Architectures: x86
Tom Lendacky801e4592018-02-21 13:39:51 -0600130Type: system ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300131Parameters: struct kvm_msr_list (in/out)
132Returns: 0 on success; -1 on error
133Errors:
Tom Lendacky801e4592018-02-21 13:39:51 -0600134 EFAULT: the msr index list cannot be read from or written to
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300135 E2BIG: the msr index list is to be to fit in the array specified by
136 the user.
137
138struct kvm_msr_list {
139 __u32 nmsrs; /* number of msrs in entries */
140 __u32 indices[0];
141};
142
Tom Lendacky801e4592018-02-21 13:39:51 -0600143The user fills in the size of the indices array in nmsrs, and in return
144kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
145indices array with their numbers.
146
147KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
148varies by kvm version and host processor, but does not change otherwise.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300149
Avi Kivity2e2602c2010-07-07 14:09:39 +0300150Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
151not returned in the MSR list, as different vcpus can have a different number
152of banks, as set via the KVM_X86_SETUP_MCE ioctl.
153
Tom Lendacky801e4592018-02-21 13:39:51 -0600154KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
155to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
156and processor features that are exposed via MSRs (e.g., VMX capabilities).
157This list also varies by kvm version and host processor, but does not change
158otherwise.
159
Jan Kiszka414fa982012-04-24 16:40:15 +0200160
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001614.4 KVM_CHECK_EXTENSION
162
Alexander Graf92b591a2014-07-14 18:33:08 +0200163Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300164Architectures: all
Alexander Graf92b591a2014-07-14 18:33:08 +0200165Type: system ioctl, vm ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300166Parameters: extension identifier (KVM_CAP_*)
167Returns: 0 if unsupported; 1 (or some other positive integer) if supported
168
169The API allows the application to query about extensions to the core
170kvm API. Userspace passes an extension identifier (an integer) and
171receives an integer that describes the extension availability.
172Generally 0 means no and 1 means yes, but some extensions may report
173additional information in the integer return value.
174
Alexander Graf92b591a2014-07-14 18:33:08 +0200175Based on their initialization different VMs may have different capabilities.
176It is thus encouraged to use the vm ioctl to query for capabilities (available
177with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
Jan Kiszka414fa982012-04-24 16:40:15 +0200178
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001794.5 KVM_GET_VCPU_MMAP_SIZE
180
181Capability: basic
182Architectures: all
183Type: system ioctl
184Parameters: none
185Returns: size of vcpu mmap area, in bytes
186
187The KVM_RUN ioctl (cf.) communicates with userspace via a shared
188memory region. This ioctl returns the size of that region. See the
189KVM_RUN documentation for details.
190
Jan Kiszka414fa982012-04-24 16:40:15 +0200191
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001924.6 KVM_SET_MEMORY_REGION
193
194Capability: basic
195Architectures: all
196Type: vm ioctl
197Parameters: struct kvm_memory_region (in)
198Returns: 0 on success, -1 on error
199
Avi Kivityb74a07b2010-06-21 11:48:05 +0300200This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300201
Jan Kiszka414fa982012-04-24 16:40:15 +0200202
Paul Bolle68ba6972011-02-15 00:05:59 +01002034.7 KVM_CREATE_VCPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300204
205Capability: basic
206Architectures: all
207Type: vm ioctl
208Parameters: vcpu id (apic id on x86)
209Returns: vcpu fd on success, -1 on error
210
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200211This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
212The vcpu id is an integer in the range [0, max_vcpu_id).
Sasha Levin8c3ba332011-07-18 17:17:15 +0300213
214The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
215the KVM_CHECK_EXTENSION ioctl() at run-time.
216The maximum possible value for max_vcpus can be retrieved using the
217KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
218
Pekka Enberg76d25402011-05-09 22:48:54 +0300219If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
220cpus max.
Sasha Levin8c3ba332011-07-18 17:17:15 +0300221If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
222same as the value returned from KVM_CAP_NR_VCPUS.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300223
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200224The maximum possible value for max_vcpu_id can be retrieved using the
225KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
226
227If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
228is the same as the value returned from KVM_CAP_MAX_VCPUS.
229
Paul Mackerras371fefd2011-06-29 00:23:08 +0000230On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
231threads in one or more virtual CPU cores. (This is because the
232hardware requires all the hardware threads in a CPU core to be in the
233same partition.) The KVM_CAP_PPC_SMT capability indicates the number
234of vcpus per virtual core (vcore). The vcore id is obtained by
235dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
236given vcore will always be in the same physical core as each other
237(though that might be a different physical core from time to time).
238Userspace can control the threading (SMT) mode of the guest by its
239allocation of vcpu ids. For example, if userspace wants
240single-threaded guest vcpus, it should make all vcpu ids be a multiple
241of the number of vcpus per vcore.
242
Carsten Otte5b1c1492012-01-04 10:25:23 +0100243For virtual cpus that have been created with S390 user controlled virtual
244machines, the resulting vcpu fd can be memory mapped at page offset
245KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
246cpu's hardware control block.
247
Jan Kiszka414fa982012-04-24 16:40:15 +0200248
Paul Bolle68ba6972011-02-15 00:05:59 +01002494.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300250
251Capability: basic
252Architectures: x86
253Type: vm ioctl
254Parameters: struct kvm_dirty_log (in/out)
255Returns: 0 on success, -1 on error
256
257/* for KVM_GET_DIRTY_LOG */
258struct kvm_dirty_log {
259 __u32 slot;
260 __u32 padding;
261 union {
262 void __user *dirty_bitmap; /* one bit per page */
263 __u64 padding;
264 };
265};
266
267Given a memory slot, return a bitmap containing any pages dirtied
268since the last call to this ioctl. Bit 0 is the first page in the
269memory slot. Ensure the entire structure is cleared to avoid padding
270issues.
271
Paolo Bonzinif481b062015-05-17 17:30:37 +0200272If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies
273the address space for which you want to return the dirty bitmap.
274They must be less than the value that KVM_CHECK_EXTENSION returns for
275the KVM_CAP_MULTI_ADDRESS_SPACE capability.
276
Jan Kiszka414fa982012-04-24 16:40:15 +0200277
Paul Bolle68ba6972011-02-15 00:05:59 +01002784.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300279
280Capability: basic
281Architectures: x86
282Type: vm ioctl
283Parameters: struct kvm_memory_alias (in)
284Returns: 0 (success), -1 (error)
285
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300286This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300287
Jan Kiszka414fa982012-04-24 16:40:15 +0200288
Paul Bolle68ba6972011-02-15 00:05:59 +01002894.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300290
291Capability: basic
292Architectures: all
293Type: vcpu ioctl
294Parameters: none
295Returns: 0 on success, -1 on error
296Errors:
297 EINTR: an unmasked signal is pending
298
299This ioctl is used to run a guest virtual cpu. While there are no
300explicit parameters, there is an implicit parameter block that can be
301obtained by mmap()ing the vcpu fd at offset 0, with the size given by
302KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
303kvm_run' (see below).
304
Jan Kiszka414fa982012-04-24 16:40:15 +0200305
Paul Bolle68ba6972011-02-15 00:05:59 +01003064.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300307
308Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +0100309Architectures: all except ARM, arm64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300310Type: vcpu ioctl
311Parameters: struct kvm_regs (out)
312Returns: 0 on success, -1 on error
313
314Reads the general purpose registers from the vcpu.
315
316/* x86 */
317struct kvm_regs {
318 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
319 __u64 rax, rbx, rcx, rdx;
320 __u64 rsi, rdi, rsp, rbp;
321 __u64 r8, r9, r10, r11;
322 __u64 r12, r13, r14, r15;
323 __u64 rip, rflags;
324};
325
James Hoganc2d2c212014-07-04 15:11:35 +0100326/* mips */
327struct kvm_regs {
328 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
329 __u64 gpr[32];
330 __u64 hi;
331 __u64 lo;
332 __u64 pc;
333};
334
Jan Kiszka414fa982012-04-24 16:40:15 +0200335
Paul Bolle68ba6972011-02-15 00:05:59 +01003364.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300337
338Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +0100339Architectures: all except ARM, arm64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300340Type: vcpu ioctl
341Parameters: struct kvm_regs (in)
342Returns: 0 on success, -1 on error
343
344Writes the general purpose registers into the vcpu.
345
346See KVM_GET_REGS for the data structure.
347
Jan Kiszka414fa982012-04-24 16:40:15 +0200348
Paul Bolle68ba6972011-02-15 00:05:59 +01003494.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300350
351Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500352Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300353Type: vcpu ioctl
354Parameters: struct kvm_sregs (out)
355Returns: 0 on success, -1 on error
356
357Reads special registers from the vcpu.
358
359/* x86 */
360struct kvm_sregs {
361 struct kvm_segment cs, ds, es, fs, gs, ss;
362 struct kvm_segment tr, ldt;
363 struct kvm_dtable gdt, idt;
364 __u64 cr0, cr2, cr3, cr4, cr8;
365 __u64 efer;
366 __u64 apic_base;
367 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
368};
369
Mihai Caraman68e2ffe2012-12-11 03:38:23 +0000370/* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
Scott Wood5ce941e2011-04-27 17:24:21 -0500371
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300372interrupt_bitmap is a bitmap of pending external interrupts. At most
373one bit may be set. This interrupt has been acknowledged by the APIC
374but not yet injected into the cpu core.
375
Jan Kiszka414fa982012-04-24 16:40:15 +0200376
Paul Bolle68ba6972011-02-15 00:05:59 +01003774.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300378
379Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500380Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300381Type: vcpu ioctl
382Parameters: struct kvm_sregs (in)
383Returns: 0 on success, -1 on error
384
385Writes special registers into the vcpu. See KVM_GET_SREGS for the
386data structures.
387
Jan Kiszka414fa982012-04-24 16:40:15 +0200388
Paul Bolle68ba6972011-02-15 00:05:59 +01003894.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300390
391Capability: basic
392Architectures: x86
393Type: vcpu ioctl
394Parameters: struct kvm_translation (in/out)
395Returns: 0 on success, -1 on error
396
397Translates a virtual address according to the vcpu's current address
398translation mode.
399
400struct kvm_translation {
401 /* in */
402 __u64 linear_address;
403
404 /* out */
405 __u64 physical_address;
406 __u8 valid;
407 __u8 writeable;
408 __u8 usermode;
409 __u8 pad[5];
410};
411
Jan Kiszka414fa982012-04-24 16:40:15 +0200412
Paul Bolle68ba6972011-02-15 00:05:59 +01004134.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300414
415Capability: basic
James Hoganc2d2c212014-07-04 15:11:35 +0100416Architectures: x86, ppc, mips
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300417Type: vcpu ioctl
418Parameters: struct kvm_interrupt (in)
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200419Returns: 0 on success, negative on failure.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300420
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200421Queues a hardware interrupt vector to be injected.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300422
423/* for KVM_INTERRUPT */
424struct kvm_interrupt {
425 /* in */
426 __u32 irq;
427};
428
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200429X86:
430
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200431Returns: 0 on success,
432 -EEXIST if an interrupt is already enqueued
433 -EINVAL the the irq number is invalid
434 -ENXIO if the PIC is in the kernel
435 -EFAULT if the pointer is invalid
436
437Note 'irq' is an interrupt vector, not an interrupt pin or line. This
438ioctl is useful if the in-kernel PIC is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300439
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200440PPC:
441
442Queues an external interrupt to be injected. This ioctl is overleaded
443with 3 different irq values:
444
445a) KVM_INTERRUPT_SET
446
447 This injects an edge type external interrupt into the guest once it's ready
448 to receive interrupts. When injected, the interrupt is done.
449
450b) KVM_INTERRUPT_UNSET
451
452 This unsets any pending interrupt.
453
454 Only available with KVM_CAP_PPC_UNSET_IRQ.
455
456c) KVM_INTERRUPT_SET_LEVEL
457
458 This injects a level type external interrupt into the guest context. The
459 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
460 is triggered.
461
462 Only available with KVM_CAP_PPC_IRQ_LEVEL.
463
464Note that any value for 'irq' other than the ones stated above is invalid
465and incurs unexpected behavior.
466
James Hoganc2d2c212014-07-04 15:11:35 +0100467MIPS:
468
469Queues an external interrupt to be injected into the virtual CPU. A negative
470interrupt number dequeues the interrupt.
471
Jan Kiszka414fa982012-04-24 16:40:15 +0200472
Paul Bolle68ba6972011-02-15 00:05:59 +01004734.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300474
475Capability: basic
476Architectures: none
477Type: vcpu ioctl
478Parameters: none)
479Returns: -1 on error
480
481Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
482
Jan Kiszka414fa982012-04-24 16:40:15 +0200483
Paul Bolle68ba6972011-02-15 00:05:59 +01004844.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300485
Tom Lendacky801e4592018-02-21 13:39:51 -0600486Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300487Architectures: x86
Tom Lendacky801e4592018-02-21 13:39:51 -0600488Type: system ioctl, vcpu ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300489Parameters: struct kvm_msrs (in/out)
Tom Lendacky801e4592018-02-21 13:39:51 -0600490Returns: number of msrs successfully returned;
491 -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300492
Tom Lendacky801e4592018-02-21 13:39:51 -0600493When used as a system ioctl:
494Reads the values of MSR-based features that are available for the VM. This
495is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
496The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
497in a system ioctl.
498
499When used as a vcpu ioctl:
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300500Reads model-specific registers from the vcpu. Supported msr indices can
Tom Lendacky801e4592018-02-21 13:39:51 -0600501be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300502
503struct kvm_msrs {
504 __u32 nmsrs; /* number of msrs in entries */
505 __u32 pad;
506
507 struct kvm_msr_entry entries[0];
508};
509
510struct kvm_msr_entry {
511 __u32 index;
512 __u32 reserved;
513 __u64 data;
514};
515
516Application code should set the 'nmsrs' member (which indicates the
517size of the entries array) and the 'index' member of each array entry.
518kvm will fill in the 'data' member.
519
Jan Kiszka414fa982012-04-24 16:40:15 +0200520
Paul Bolle68ba6972011-02-15 00:05:59 +01005214.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300522
523Capability: basic
524Architectures: x86
525Type: vcpu ioctl
526Parameters: struct kvm_msrs (in)
527Returns: 0 on success, -1 on error
528
529Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
530data structures.
531
532Application code should set the 'nmsrs' member (which indicates the
533size of the entries array), and the 'index' and 'data' members of each
534array entry.
535
Jan Kiszka414fa982012-04-24 16:40:15 +0200536
Paul Bolle68ba6972011-02-15 00:05:59 +01005374.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300538
539Capability: basic
540Architectures: x86
541Type: vcpu ioctl
542Parameters: struct kvm_cpuid (in)
543Returns: 0 on success, -1 on error
544
545Defines the vcpu responses to the cpuid instruction. Applications
546should use the KVM_SET_CPUID2 ioctl if available.
547
548
549struct kvm_cpuid_entry {
550 __u32 function;
551 __u32 eax;
552 __u32 ebx;
553 __u32 ecx;
554 __u32 edx;
555 __u32 padding;
556};
557
558/* for KVM_SET_CPUID */
559struct kvm_cpuid {
560 __u32 nent;
561 __u32 padding;
562 struct kvm_cpuid_entry entries[0];
563};
564
Jan Kiszka414fa982012-04-24 16:40:15 +0200565
Paul Bolle68ba6972011-02-15 00:05:59 +01005664.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300567
568Capability: basic
James Hogan572e0922014-07-04 15:11:33 +0100569Architectures: all
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300570Type: vcpu ioctl
571Parameters: struct kvm_signal_mask (in)
572Returns: 0 on success, -1 on error
573
574Defines which signals are blocked during execution of KVM_RUN. This
575signal mask temporarily overrides the threads signal mask. Any
576unblocked signal received (except SIGKILL and SIGSTOP, which retain
577their traditional behaviour) will cause KVM_RUN to return with -EINTR.
578
579Note the signal will only be delivered if not blocked by the original
580signal mask.
581
582/* for KVM_SET_SIGNAL_MASK */
583struct kvm_signal_mask {
584 __u32 len;
585 __u8 sigset[0];
586};
587
Jan Kiszka414fa982012-04-24 16:40:15 +0200588
Paul Bolle68ba6972011-02-15 00:05:59 +01005894.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300590
591Capability: basic
592Architectures: x86
593Type: vcpu ioctl
594Parameters: struct kvm_fpu (out)
595Returns: 0 on success, -1 on error
596
597Reads the floating point state from the vcpu.
598
599/* for KVM_GET_FPU and KVM_SET_FPU */
600struct kvm_fpu {
601 __u8 fpr[8][16];
602 __u16 fcw;
603 __u16 fsw;
604 __u8 ftwx; /* in fxsave format */
605 __u8 pad1;
606 __u16 last_opcode;
607 __u64 last_ip;
608 __u64 last_dp;
609 __u8 xmm[16][16];
610 __u32 mxcsr;
611 __u32 pad2;
612};
613
Jan Kiszka414fa982012-04-24 16:40:15 +0200614
Paul Bolle68ba6972011-02-15 00:05:59 +01006154.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300616
617Capability: basic
618Architectures: x86
619Type: vcpu ioctl
620Parameters: struct kvm_fpu (in)
621Returns: 0 on success, -1 on error
622
623Writes the floating point state to the vcpu.
624
625/* for KVM_GET_FPU and KVM_SET_FPU */
626struct kvm_fpu {
627 __u8 fpr[8][16];
628 __u16 fcw;
629 __u16 fsw;
630 __u8 ftwx; /* in fxsave format */
631 __u8 pad1;
632 __u16 last_opcode;
633 __u64 last_ip;
634 __u64 last_dp;
635 __u8 xmm[16][16];
636 __u32 mxcsr;
637 __u32 pad2;
638};
639
Jan Kiszka414fa982012-04-24 16:40:15 +0200640
Paul Bolle68ba6972011-02-15 00:05:59 +01006414.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300642
Cornelia Huck84223592013-07-15 13:36:01 +0200643Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
Tiejun Chenc32a4272014-11-20 11:07:18 +0100644Architectures: x86, ARM, arm64, s390
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300645Type: vm ioctl
646Parameters: none
647Returns: 0 on success, -1 on error
648
Andre Przywaraac3d3732014-06-03 10:26:30 +0200649Creates an interrupt controller model in the kernel.
650On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
651future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
652PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
653On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of
654KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
655KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
656On s390, a dummy irq routing table is created.
Cornelia Huck84223592013-07-15 13:36:01 +0200657
658Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
659before KVM_CREATE_IRQCHIP can be used.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300660
Jan Kiszka414fa982012-04-24 16:40:15 +0200661
Paul Bolle68ba6972011-02-15 00:05:59 +01006624.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300663
664Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100665Architectures: x86, arm, arm64
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300666Type: vm ioctl
667Parameters: struct kvm_irq_level
668Returns: 0 on success, -1 on error
669
670Sets the level of a GSI input to the interrupt controller model in the kernel.
Christoffer Dall86ce8532013-01-20 18:28:08 -0500671On some architectures it is required that an interrupt controller model has
672been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
673interrupts require the level to be set to 1 and then back to 0.
674
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500675On real hardware, interrupt pins can be active-low or active-high. This
676does not matter for the level field of struct kvm_irq_level: 1 always
677means active (asserted), 0 means inactive (deasserted).
678
679x86 allows the operating system to program the interrupt polarity
680(active-low/active-high) for level-triggered interrupts, and KVM used
681to consider the polarity. However, due to bitrot in the handling of
682active-low interrupts, the above convention is now valid on x86 too.
683This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
684should not present interrupts to the guest as active-low unless this
685capability is present (or unless it is not using the in-kernel irqchip,
686of course).
687
688
Marc Zyngier379e04c72013-04-02 17:46:31 +0100689ARM/arm64 can signal an interrupt either at the CPU level, or at the
690in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
691use PPIs designated for specific cpus. The irq field is interpreted
692like this:
Christoffer Dall86ce8532013-01-20 18:28:08 -0500693
694  bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 |
695 field: | irq_type | vcpu_index | irq_id |
696
697The irq_type field has the following values:
698- irq_type[0]: out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
699- irq_type[1]: in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
700 (the vcpu_index field is ignored)
701- irq_type[2]: in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
702
703(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
704
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500705In both cases, level is used to assert/deassert the line.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300706
707struct kvm_irq_level {
708 union {
709 __u32 irq; /* GSI */
710 __s32 status; /* not used for KVM_IRQ_LEVEL */
711 };
712 __u32 level; /* 0 or 1 */
713};
714
Jan Kiszka414fa982012-04-24 16:40:15 +0200715
Paul Bolle68ba6972011-02-15 00:05:59 +01007164.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300717
718Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100719Architectures: x86
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300720Type: vm ioctl
721Parameters: struct kvm_irqchip (in/out)
722Returns: 0 on success, -1 on error
723
724Reads the state of a kernel interrupt controller created with
725KVM_CREATE_IRQCHIP into a buffer provided by the caller.
726
727struct kvm_irqchip {
728 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
729 __u32 pad;
730 union {
731 char dummy[512]; /* reserving space */
732 struct kvm_pic_state pic;
733 struct kvm_ioapic_state ioapic;
734 } chip;
735};
736
Jan Kiszka414fa982012-04-24 16:40:15 +0200737
Paul Bolle68ba6972011-02-15 00:05:59 +01007384.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300739
740Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100741Architectures: x86
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300742Type: vm ioctl
743Parameters: struct kvm_irqchip (in)
744Returns: 0 on success, -1 on error
745
746Sets the state of a kernel interrupt controller created with
747KVM_CREATE_IRQCHIP from a buffer provided by the caller.
748
749struct kvm_irqchip {
750 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
751 __u32 pad;
752 union {
753 char dummy[512]; /* reserving space */
754 struct kvm_pic_state pic;
755 struct kvm_ioapic_state ioapic;
756 } chip;
757};
758
Jan Kiszka414fa982012-04-24 16:40:15 +0200759
Paul Bolle68ba6972011-02-15 00:05:59 +01007604.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700761
762Capability: KVM_CAP_XEN_HVM
763Architectures: x86
764Type: vm ioctl
765Parameters: struct kvm_xen_hvm_config (in)
766Returns: 0 on success, -1 on error
767
768Sets the MSR that the Xen HVM guest uses to initialize its hypercall
769page, and provides the starting address and size of the hypercall
770blobs in userspace. When the guest writes the MSR, kvm copies one
771page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
772memory.
773
774struct kvm_xen_hvm_config {
775 __u32 flags;
776 __u32 msr;
777 __u64 blob_addr_32;
778 __u64 blob_addr_64;
779 __u8 blob_size_32;
780 __u8 blob_size_64;
781 __u8 pad2[30];
782};
783
Jan Kiszka414fa982012-04-24 16:40:15 +0200784
Paul Bolle68ba6972011-02-15 00:05:59 +01007854.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400786
787Capability: KVM_CAP_ADJUST_CLOCK
788Architectures: x86
789Type: vm ioctl
790Parameters: struct kvm_clock_data (out)
791Returns: 0 on success, -1 on error
792
793Gets the current timestamp of kvmclock as seen by the current guest. In
794conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
795such as migration.
796
Paolo Bonzinie3fd9a92016-11-09 17:48:15 +0100797When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
798set of bits that KVM can return in struct kvm_clock_data's flag member.
799
800The only flag defined now is KVM_CLOCK_TSC_STABLE. If set, the returned
801value is the exact kvmclock value seen by all VCPUs at the instant
802when KVM_GET_CLOCK was called. If clear, the returned value is simply
803CLOCK_MONOTONIC plus a constant offset; the offset can be modified
804with KVM_SET_CLOCK. KVM will try to make all VCPUs follow this clock,
805but the exact value read by each VCPU could differ, because the host
806TSC is not stable.
807
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400808struct kvm_clock_data {
809 __u64 clock; /* kvmclock current value */
810 __u32 flags;
811 __u32 pad[9];
812};
813
Jan Kiszka414fa982012-04-24 16:40:15 +0200814
Paul Bolle68ba6972011-02-15 00:05:59 +01008154.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400816
817Capability: KVM_CAP_ADJUST_CLOCK
818Architectures: x86
819Type: vm ioctl
820Parameters: struct kvm_clock_data (in)
821Returns: 0 on success, -1 on error
822
Wu Fengguang2044892d2009-12-24 09:04:16 +0800823Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400824In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
825such as migration.
826
827struct kvm_clock_data {
828 __u64 clock; /* kvmclock current value */
829 __u32 flags;
830 __u32 pad[9];
831};
832
Jan Kiszka414fa982012-04-24 16:40:15 +0200833
Paul Bolle68ba6972011-02-15 00:05:59 +01008344.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100835
836Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100837Extended by: KVM_CAP_INTR_SHADOW
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100838Architectures: x86, arm64
839Type: vcpu ioctl
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100840Parameters: struct kvm_vcpu_event (out)
841Returns: 0 on success, -1 on error
842
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100843X86:
844
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100845Gets currently pending exceptions, interrupts, and NMIs as well as related
846states of the vcpu.
847
848struct kvm_vcpu_events {
849 struct {
850 __u8 injected;
851 __u8 nr;
852 __u8 has_error_code;
853 __u8 pad;
854 __u32 error_code;
855 } exception;
856 struct {
857 __u8 injected;
858 __u8 nr;
859 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100860 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100861 } interrupt;
862 struct {
863 __u8 injected;
864 __u8 pending;
865 __u8 masked;
866 __u8 pad;
867 } nmi;
868 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100869 __u32 flags;
Paolo Bonzinif0778252015-04-01 15:06:40 +0200870 struct {
871 __u8 smm;
872 __u8 pending;
873 __u8 smm_inside_nmi;
874 __u8 latched_init;
875 } smi;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100876};
877
Paolo Bonzinif0778252015-04-01 15:06:40 +0200878Only two fields are defined in the flags field:
Jan Kiszka48005f62010-02-19 19:38:07 +0100879
Paolo Bonzinif0778252015-04-01 15:06:40 +0200880- KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
881 interrupt.shadow contains a valid state.
882
883- KVM_VCPUEVENT_VALID_SMM may be set in the flags field to signal that
884 smi contains a valid state.
Jan Kiszka414fa982012-04-24 16:40:15 +0200885
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100886ARM64:
887
888If the guest accesses a device that is being emulated by the host kernel in
889such a way that a real device would generate a physical SError, KVM may make
890a virtual SError pending for that VCPU. This system error interrupt remains
891pending until the guest takes the exception by unmasking PSTATE.A.
892
893Running the VCPU may cause it to take a pending SError, or make an access that
894causes an SError to become pending. The event's description is only valid while
895the VPCU is not running.
896
897This API provides a way to read and write the pending 'event' state that is not
898visible to the guest. To save, restore or migrate a VCPU the struct representing
899the state can be read then written using this GET/SET API, along with the other
900guest-visible registers. It is not possible to 'cancel' an SError that has been
901made pending.
902
903A device being emulated in user-space may also wish to generate an SError. To do
904this the events structure can be populated by user-space. The current state
905should be read first, to ensure no existing SError is pending. If an existing
906SError is pending, the architecture's 'Multiple SError interrupts' rules should
907be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
908Serviceability (RAS) Specification").
909
910struct kvm_vcpu_events {
911 struct {
912 __u8 serror_pending;
913 __u8 serror_has_esr;
914 /* Align it to 8 bytes */
915 __u8 pad[6];
916 __u64 serror_esr;
917 } exception;
918 __u32 reserved[12];
919};
920
Paul Bolle68ba6972011-02-15 00:05:59 +01009214.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100922
923Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100924Extended by: KVM_CAP_INTR_SHADOW
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100925Architectures: x86, arm64
926Type: vcpu ioctl
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100927Parameters: struct kvm_vcpu_event (in)
928Returns: 0 on success, -1 on error
929
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100930X86:
931
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100932Set pending exceptions, interrupts, and NMIs as well as related states of the
933vcpu.
934
935See KVM_GET_VCPU_EVENTS for the data structure.
936
Jan Kiszkadab4b912009-12-06 18:24:15 +0100937Fields that may be modified asynchronously by running VCPUs can be excluded
Paolo Bonzinif0778252015-04-01 15:06:40 +0200938from the update. These fields are nmi.pending, sipi_vector, smi.smm,
939smi.pending. Keep the corresponding bits in the flags field cleared to
940suppress overwriting the current in-kernel state. The bits are:
Jan Kiszkadab4b912009-12-06 18:24:15 +0100941
942KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
943KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
Paolo Bonzinif0778252015-04-01 15:06:40 +0200944KVM_VCPUEVENT_VALID_SMM - transfer the smi sub-struct.
Jan Kiszkadab4b912009-12-06 18:24:15 +0100945
Jan Kiszka48005f62010-02-19 19:38:07 +0100946If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
947the flags field to signal that interrupt.shadow contains a valid state and
948shall be written into the VCPU.
949
Paolo Bonzinif0778252015-04-01 15:06:40 +0200950KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
951
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100952ARM64:
953
954Set the pending SError exception state for this VCPU. It is not possible to
955'cancel' an Serror that has been made pending.
956
957See KVM_GET_VCPU_EVENTS for the data structure.
958
Jan Kiszka414fa982012-04-24 16:40:15 +0200959
Paul Bolle68ba6972011-02-15 00:05:59 +01009604.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100961
962Capability: KVM_CAP_DEBUGREGS
963Architectures: x86
964Type: vm ioctl
965Parameters: struct kvm_debugregs (out)
966Returns: 0 on success, -1 on error
967
968Reads debug registers from the vcpu.
969
970struct kvm_debugregs {
971 __u64 db[4];
972 __u64 dr6;
973 __u64 dr7;
974 __u64 flags;
975 __u64 reserved[9];
976};
977
Jan Kiszka414fa982012-04-24 16:40:15 +0200978
Paul Bolle68ba6972011-02-15 00:05:59 +01009794.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100980
981Capability: KVM_CAP_DEBUGREGS
982Architectures: x86
983Type: vm ioctl
984Parameters: struct kvm_debugregs (in)
985Returns: 0 on success, -1 on error
986
987Writes debug registers into the vcpu.
988
989See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
990yet and must be cleared on entry.
991
Jan Kiszka414fa982012-04-24 16:40:15 +0200992
Paul Bolle68ba6972011-02-15 00:05:59 +01009934.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +0200994
995Capability: KVM_CAP_USER_MEM
996Architectures: all
997Type: vm ioctl
998Parameters: struct kvm_userspace_memory_region (in)
999Returns: 0 on success, -1 on error
1000
1001struct kvm_userspace_memory_region {
1002 __u32 slot;
1003 __u32 flags;
1004 __u64 guest_phys_addr;
1005 __u64 memory_size; /* bytes */
1006 __u64 userspace_addr; /* start of the userspace allocated memory */
1007};
1008
1009/* for kvm_memory_region::flags */
Xiao Guangrong4d8b81a2012-08-21 11:02:51 +08001010#define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
1011#define KVM_MEM_READONLY (1UL << 1)
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001012
1013This ioctl allows the user to create or modify a guest physical memory
1014slot. When changing an existing slot, it may be moved in the guest
1015physical memory space, or its flags may be modified. It may not be
1016resized. Slots may not overlap in guest physical address space.
Linu Cheriana677e702017-03-08 11:38:32 +05301017Bits 0-15 of "slot" specifies the slot id and this value should be
1018less than the maximum number of user memory slots supported per VM.
1019The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS,
1020if this capability is supported by the architecture.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001021
Paolo Bonzinif481b062015-05-17 17:30:37 +02001022If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1023specifies the address space which is being modified. They must be
1024less than the value that KVM_CHECK_EXTENSION returns for the
1025KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
1026are unrelated; the restriction on overlapping slots only applies within
1027each address space.
1028
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001029Memory for the region is taken starting at the address denoted by the
1030field userspace_addr, which must point at user addressable memory for
1031the entire memory slot size. Any object may back this memory, including
1032anonymous memory, ordinary files, and hugetlbfs.
1033
1034It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1035be identical. This allows large pages in the guest to be backed by large
1036pages in the host.
1037
Takuya Yoshikawa75d61fb2013-01-30 19:40:41 +09001038The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1039KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
1040writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
1041use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1042to make a new slot read-only. In this case, writes to this memory will be
1043posted to userspace as KVM_EXIT_MMIO exits.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001044
Jan Kiszka7efd8fa2012-09-07 13:17:47 +02001045When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1046the memory region are automatically reflected into the guest. For example, an
1047mmap() that affects the region will be made visible immediately. Another
1048example is madvise(MADV_DROP).
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001049
1050It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
1051The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
1052allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001053
Jan Kiszka414fa982012-04-24 16:40:15 +02001054
Paul Bolle68ba6972011-02-15 00:05:59 +010010554.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +02001056
1057Capability: KVM_CAP_SET_TSS_ADDR
1058Architectures: x86
1059Type: vm ioctl
1060Parameters: unsigned long tss_address (in)
1061Returns: 0 on success, -1 on error
1062
1063This ioctl defines the physical address of a three-page region in the guest
1064physical address space. The region must be within the first 4GB of the
1065guest physical address space and must not conflict with any memory slot
1066or any mmio address. The guest may malfunction if it accesses this memory
1067region.
1068
1069This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1070because of a quirk in the virtualization implementation (see the internals
1071documentation when it pops into existence).
1072
Jan Kiszka414fa982012-04-24 16:40:15 +02001073
Paul Bolle68ba6972011-02-15 00:05:59 +010010744.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +01001075
Cornelia Huckd938dc52013-10-23 18:26:34 +02001076Capability: KVM_CAP_ENABLE_CAP, KVM_CAP_ENABLE_CAP_VM
Nadav Amit90de4a12015-04-13 01:53:41 +03001077Architectures: x86 (only KVM_CAP_ENABLE_CAP_VM),
1078 mips (only KVM_CAP_ENABLE_CAP), ppc, s390
Cornelia Huckd938dc52013-10-23 18:26:34 +02001079Type: vcpu ioctl, vm ioctl (with KVM_CAP_ENABLE_CAP_VM)
Alexander Graf71fbfd52010-03-24 21:48:29 +01001080Parameters: struct kvm_enable_cap (in)
1081Returns: 0 on success; -1 on error
1082
1083+Not all extensions are enabled by default. Using this ioctl the application
1084can enable an extension, making it available to the guest.
1085
1086On systems that do not support this ioctl, it always fails. On systems that
1087do support it, it only works for extensions that are supported for enablement.
1088
1089To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1090be used.
1091
1092struct kvm_enable_cap {
1093 /* in */
1094 __u32 cap;
1095
1096The capability that is supposed to get enabled.
1097
1098 __u32 flags;
1099
1100A bitfield indicating future enhancements. Has to be 0 for now.
1101
1102 __u64 args[4];
1103
1104Arguments for enabling a feature. If a feature needs initial values to
1105function properly, this is the place to put them.
1106
1107 __u8 pad[64];
1108};
1109
Cornelia Huckd938dc52013-10-23 18:26:34 +02001110The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1111for vm-wide capabilities.
Jan Kiszka414fa982012-04-24 16:40:15 +02001112
Paul Bolle68ba6972011-02-15 00:05:59 +010011134.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +03001114
1115Capability: KVM_CAP_MP_STATE
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001116Architectures: x86, s390, arm, arm64
Avi Kivityb843f062010-04-25 15:51:46 +03001117Type: vcpu ioctl
1118Parameters: struct kvm_mp_state (out)
1119Returns: 0 on success; -1 on error
1120
1121struct kvm_mp_state {
1122 __u32 mp_state;
1123};
1124
1125Returns the vcpu's current "multiprocessing state" (though also valid on
1126uniprocessor guests).
1127
1128Possible values are:
1129
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001130 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running [x86,arm/arm64]
Avi Kivityb843f062010-04-25 15:51:46 +03001131 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
Tiejun Chenc32a4272014-11-20 11:07:18 +01001132 which has not yet received an INIT signal [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001133 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
Tiejun Chenc32a4272014-11-20 11:07:18 +01001134 now ready for a SIPI [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001135 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
Tiejun Chenc32a4272014-11-20 11:07:18 +01001136 is waiting for an interrupt [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001137 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Tiejun Chenc32a4272014-11-20 11:07:18 +01001138 accessible via KVM_GET_VCPU_EVENTS) [x86]
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001139 - KVM_MP_STATE_STOPPED: the vcpu is stopped [s390,arm/arm64]
David Hildenbrand6352e4d2014-04-10 17:35:00 +02001140 - KVM_MP_STATE_CHECK_STOP: the vcpu is in a special error state [s390]
1141 - KVM_MP_STATE_OPERATING: the vcpu is operating (running or halted)
1142 [s390]
1143 - KVM_MP_STATE_LOAD: the vcpu is in a special load/startup state
1144 [s390]
Avi Kivityb843f062010-04-25 15:51:46 +03001145
Tiejun Chenc32a4272014-11-20 11:07:18 +01001146On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001147in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1148these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001149
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001150For arm/arm64:
1151
1152The only states that are valid are KVM_MP_STATE_STOPPED and
1153KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001154
Paul Bolle68ba6972011-02-15 00:05:59 +010011554.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +03001156
1157Capability: KVM_CAP_MP_STATE
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001158Architectures: x86, s390, arm, arm64
Avi Kivityb843f062010-04-25 15:51:46 +03001159Type: vcpu ioctl
1160Parameters: struct kvm_mp_state (in)
1161Returns: 0 on success; -1 on error
1162
1163Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1164arguments.
1165
Tiejun Chenc32a4272014-11-20 11:07:18 +01001166On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001167in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1168these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001169
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001170For arm/arm64:
1171
1172The only states that are valid are KVM_MP_STATE_STOPPED and
1173KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001174
Paul Bolle68ba6972011-02-15 00:05:59 +010011754.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +03001176
1177Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1178Architectures: x86
1179Type: vm ioctl
1180Parameters: unsigned long identity (in)
1181Returns: 0 on success, -1 on error
1182
1183This ioctl defines the physical address of a one-page region in the guest
1184physical address space. The region must be within the first 4GB of the
1185guest physical address space and must not conflict with any memory slot
1186or any mmio address. The guest may malfunction if it accesses this memory
1187region.
1188
David Hildenbrand726b99c2017-08-24 20:51:35 +02001189Setting the address to 0 will result in resetting the address to its default
1190(0xfffbc000).
1191
Avi Kivity47dbb842010-04-29 12:08:56 +03001192This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1193because of a quirk in the virtualization implementation (see the internals
1194documentation when it pops into existence).
1195
David Hildenbrand1af1ac92017-08-24 20:51:36 +02001196Fails if any VCPU has already been created.
Jan Kiszka414fa982012-04-24 16:40:15 +02001197
Paul Bolle68ba6972011-02-15 00:05:59 +010011984.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +03001199
1200Capability: KVM_CAP_SET_BOOT_CPU_ID
Tiejun Chenc32a4272014-11-20 11:07:18 +01001201Architectures: x86
Avi Kivity57bc24c2010-04-29 12:12:57 +03001202Type: vm ioctl
1203Parameters: unsigned long vcpu_id
1204Returns: 0 on success, -1 on error
1205
1206Define which vcpu is the Bootstrap Processor (BSP). Values are the same
1207as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
1208is vcpu 0.
1209
Jan Kiszka414fa982012-04-24 16:40:15 +02001210
Paul Bolle68ba6972011-02-15 00:05:59 +010012114.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001212
1213Capability: KVM_CAP_XSAVE
1214Architectures: x86
1215Type: vcpu ioctl
1216Parameters: struct kvm_xsave (out)
1217Returns: 0 on success, -1 on error
1218
1219struct kvm_xsave {
1220 __u32 region[1024];
1221};
1222
1223This ioctl would copy current vcpu's xsave struct to the userspace.
1224
Jan Kiszka414fa982012-04-24 16:40:15 +02001225
Paul Bolle68ba6972011-02-15 00:05:59 +010012264.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001227
1228Capability: KVM_CAP_XSAVE
1229Architectures: x86
1230Type: vcpu ioctl
1231Parameters: struct kvm_xsave (in)
1232Returns: 0 on success, -1 on error
1233
1234struct kvm_xsave {
1235 __u32 region[1024];
1236};
1237
1238This ioctl would copy userspace's xsave struct to the kernel.
1239
Jan Kiszka414fa982012-04-24 16:40:15 +02001240
Paul Bolle68ba6972011-02-15 00:05:59 +010012414.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001242
1243Capability: KVM_CAP_XCRS
1244Architectures: x86
1245Type: vcpu ioctl
1246Parameters: struct kvm_xcrs (out)
1247Returns: 0 on success, -1 on error
1248
1249struct kvm_xcr {
1250 __u32 xcr;
1251 __u32 reserved;
1252 __u64 value;
1253};
1254
1255struct kvm_xcrs {
1256 __u32 nr_xcrs;
1257 __u32 flags;
1258 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1259 __u64 padding[16];
1260};
1261
1262This ioctl would copy current vcpu's xcrs to the userspace.
1263
Jan Kiszka414fa982012-04-24 16:40:15 +02001264
Paul Bolle68ba6972011-02-15 00:05:59 +010012654.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001266
1267Capability: KVM_CAP_XCRS
1268Architectures: x86
1269Type: vcpu ioctl
1270Parameters: struct kvm_xcrs (in)
1271Returns: 0 on success, -1 on error
1272
1273struct kvm_xcr {
1274 __u32 xcr;
1275 __u32 reserved;
1276 __u64 value;
1277};
1278
1279struct kvm_xcrs {
1280 __u32 nr_xcrs;
1281 __u32 flags;
1282 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1283 __u64 padding[16];
1284};
1285
1286This ioctl would set vcpu's xcr to the value userspace specified.
1287
Jan Kiszka414fa982012-04-24 16:40:15 +02001288
Paul Bolle68ba6972011-02-15 00:05:59 +010012894.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001290
1291Capability: KVM_CAP_EXT_CPUID
1292Architectures: x86
1293Type: system ioctl
1294Parameters: struct kvm_cpuid2 (in/out)
1295Returns: 0 on success, -1 on error
1296
1297struct kvm_cpuid2 {
1298 __u32 nent;
1299 __u32 padding;
1300 struct kvm_cpuid_entry2 entries[0];
1301};
1302
Borislav Petkov9c15bb12013-09-22 16:44:50 +02001303#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
1304#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
1305#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
Avi Kivityd1535132010-07-14 09:45:21 +03001306
1307struct kvm_cpuid_entry2 {
1308 __u32 function;
1309 __u32 index;
1310 __u32 flags;
1311 __u32 eax;
1312 __u32 ebx;
1313 __u32 ecx;
1314 __u32 edx;
1315 __u32 padding[3];
1316};
1317
Jim Mattsondf9cb9c2018-05-24 11:59:54 -07001318This ioctl returns x86 cpuid features which are supported by both the
1319hardware and kvm in its default configuration. Userspace can use the
1320information returned by this ioctl to construct cpuid information (for
1321KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1322userspace capabilities, and with user requirements (for example, the
1323user may wish to constrain cpuid to emulate older hardware, or for
1324feature consistency across a cluster).
1325
1326Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1327expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1328its default configuration. If userspace enables such capabilities, it
1329is responsible for modifying the results of this ioctl appropriately.
Avi Kivityd1535132010-07-14 09:45:21 +03001330
1331Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1332with the 'nent' field indicating the number of entries in the variable-size
1333array 'entries'. If the number of entries is too low to describe the cpu
1334capabilities, an error (E2BIG) is returned. If the number is too high,
1335the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1336number is just right, the 'nent' field is adjusted to the number of valid
1337entries in the 'entries' array, which is then filled.
1338
1339The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001340with unknown or unsupported features masked out. Some features (for example,
1341x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1342emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001343
1344 function: the eax value used to obtain the entry
1345 index: the ecx value used to obtain the entry (for entries that are
1346 affected by ecx)
1347 flags: an OR of zero or more of the following:
1348 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1349 if the index field is valid
1350 KVM_CPUID_FLAG_STATEFUL_FUNC:
1351 if cpuid for this function returns different values for successive
1352 invocations; there will be several entries with the same function,
1353 all with this flag set
1354 KVM_CPUID_FLAG_STATE_READ_NEXT:
1355 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1356 the first entry to be read by a cpu
1357 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1358 this function/index combination
1359
Jan Kiszka4d25a0662011-12-21 12:28:29 +01001360The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1361as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1362support. Instead it is reported via
1363
1364 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1365
1366if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1367feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1368
Jan Kiszka414fa982012-04-24 16:40:15 +02001369
Paul Bolle68ba6972011-02-15 00:05:59 +010013704.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001371
1372Capability: KVM_CAP_PPC_GET_PVINFO
1373Architectures: ppc
1374Type: vm ioctl
1375Parameters: struct kvm_ppc_pvinfo (out)
1376Returns: 0 on success, !0 on error
1377
1378struct kvm_ppc_pvinfo {
1379 __u32 flags;
1380 __u32 hcall[4];
1381 __u8 pad[108];
1382};
1383
1384This ioctl fetches PV specific information that need to be passed to the guest
1385using the device tree or other means from vm context.
1386
Liu Yu-B132019202e072012-07-03 05:48:52 +00001387The hcall array defines 4 instructions that make up a hypercall.
Alexander Graf15711e92010-07-29 14:48:08 +02001388
1389If any additional field gets added to this structure later on, a bit for that
1390additional piece of information will be set in the flags bitmap.
1391
Liu Yu-B132019202e072012-07-03 05:48:52 +00001392The flags bitmap is defined as:
1393
1394 /* the host supports the ePAPR idle hcall
1395 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
Jan Kiszka414fa982012-04-24 16:40:15 +02001396
Paul Bolle68ba6972011-02-15 00:05:59 +010013974.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001398
1399Capability: KVM_CAP_IRQ_ROUTING
Eric Auger180ae7b2016-07-22 16:20:41 +00001400Architectures: x86 s390 arm arm64
Jan Kiszka49f48172010-11-16 22:30:07 +01001401Type: vm ioctl
1402Parameters: struct kvm_irq_routing (in)
1403Returns: 0 on success, -1 on error
1404
1405Sets the GSI routing table entries, overwriting any previously set entries.
1406
Eric Auger180ae7b2016-07-22 16:20:41 +00001407On arm/arm64, GSI routing has the following limitation:
1408- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1409
Jan Kiszka49f48172010-11-16 22:30:07 +01001410struct kvm_irq_routing {
1411 __u32 nr;
1412 __u32 flags;
1413 struct kvm_irq_routing_entry entries[0];
1414};
1415
1416No flags are specified so far, the corresponding field must be set to zero.
1417
1418struct kvm_irq_routing_entry {
1419 __u32 gsi;
1420 __u32 type;
1421 __u32 flags;
1422 __u32 pad;
1423 union {
1424 struct kvm_irq_routing_irqchip irqchip;
1425 struct kvm_irq_routing_msi msi;
Cornelia Huck84223592013-07-15 13:36:01 +02001426 struct kvm_irq_routing_s390_adapter adapter;
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001427 struct kvm_irq_routing_hv_sint hv_sint;
Jan Kiszka49f48172010-11-16 22:30:07 +01001428 __u32 pad[8];
1429 } u;
1430};
1431
1432/* gsi routing entry types */
1433#define KVM_IRQ_ROUTING_IRQCHIP 1
1434#define KVM_IRQ_ROUTING_MSI 2
Cornelia Huck84223592013-07-15 13:36:01 +02001435#define KVM_IRQ_ROUTING_S390_ADAPTER 3
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001436#define KVM_IRQ_ROUTING_HV_SINT 4
Jan Kiszka49f48172010-11-16 22:30:07 +01001437
Eric Auger76a10b82016-07-22 16:20:37 +00001438flags:
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001439- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1440 type, specifies that the devid field contains a valid value. The per-VM
1441 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1442 the device ID. If this capability is not available, userspace should
1443 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Eric Auger76a10b82016-07-22 16:20:37 +00001444- zero otherwise
Jan Kiszka49f48172010-11-16 22:30:07 +01001445
1446struct kvm_irq_routing_irqchip {
1447 __u32 irqchip;
1448 __u32 pin;
1449};
1450
1451struct kvm_irq_routing_msi {
1452 __u32 address_lo;
1453 __u32 address_hi;
1454 __u32 data;
Eric Auger76a10b82016-07-22 16:20:37 +00001455 union {
1456 __u32 pad;
1457 __u32 devid;
1458 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001459};
1460
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001461If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1462for the device that wrote the MSI message. For PCI, this is usually a
1463BFD identifier in the lower 16 bits.
Eric Auger76a10b82016-07-22 16:20:37 +00001464
Radim Krčmář371313132016-07-12 22:09:27 +02001465On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1466feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
1467address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
1468address_hi must be zero.
1469
Cornelia Huck84223592013-07-15 13:36:01 +02001470struct kvm_irq_routing_s390_adapter {
1471 __u64 ind_addr;
1472 __u64 summary_addr;
1473 __u64 ind_offset;
1474 __u32 summary_offset;
1475 __u32 adapter_id;
1476};
1477
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001478struct kvm_irq_routing_hv_sint {
1479 __u32 vcpu;
1480 __u32 sint;
1481};
Jan Kiszka414fa982012-04-24 16:40:15 +02001482
Jan Kiszka414fa982012-04-24 16:40:15 +02001483
14844.55 KVM_SET_TSC_KHZ
Joerg Roedel92a1f122011-03-25 09:44:51 +01001485
1486Capability: KVM_CAP_TSC_CONTROL
1487Architectures: x86
1488Type: vcpu ioctl
1489Parameters: virtual tsc_khz
1490Returns: 0 on success, -1 on error
1491
1492Specifies the tsc frequency for the virtual machine. The unit of the
1493frequency is KHz.
1494
Jan Kiszka414fa982012-04-24 16:40:15 +02001495
14964.56 KVM_GET_TSC_KHZ
Joerg Roedel92a1f122011-03-25 09:44:51 +01001497
1498Capability: KVM_CAP_GET_TSC_KHZ
1499Architectures: x86
1500Type: vcpu ioctl
1501Parameters: none
1502Returns: virtual tsc-khz on success, negative value on error
1503
1504Returns the tsc frequency of the guest. The unit of the return value is
1505KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1506error.
1507
Jan Kiszka414fa982012-04-24 16:40:15 +02001508
15094.57 KVM_GET_LAPIC
Avi Kivitye7677932011-05-11 08:30:51 -04001510
1511Capability: KVM_CAP_IRQCHIP
1512Architectures: x86
1513Type: vcpu ioctl
1514Parameters: struct kvm_lapic_state (out)
1515Returns: 0 on success, -1 on error
1516
1517#define KVM_APIC_REG_SIZE 0x400
1518struct kvm_lapic_state {
1519 char regs[KVM_APIC_REG_SIZE];
1520};
1521
1522Reads the Local APIC registers and copies them into the input argument. The
1523data format and layout are the same as documented in the architecture manual.
1524
Radim Krčmář371313132016-07-12 22:09:27 +02001525If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
1526enabled, then the format of APIC_ID register depends on the APIC mode
1527(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in
1528the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID
1529which is stored in bits 31-24 of the APIC register, or equivalently in
1530byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then
1531be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
1532
1533If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
1534always uses xAPIC format.
1535
Jan Kiszka414fa982012-04-24 16:40:15 +02001536
15374.58 KVM_SET_LAPIC
Avi Kivitye7677932011-05-11 08:30:51 -04001538
1539Capability: KVM_CAP_IRQCHIP
1540Architectures: x86
1541Type: vcpu ioctl
1542Parameters: struct kvm_lapic_state (in)
1543Returns: 0 on success, -1 on error
1544
1545#define KVM_APIC_REG_SIZE 0x400
1546struct kvm_lapic_state {
1547 char regs[KVM_APIC_REG_SIZE];
1548};
1549
Masanari Iidadf5cbb22014-03-21 10:04:30 +09001550Copies the input argument into the Local APIC registers. The data format
Avi Kivitye7677932011-05-11 08:30:51 -04001551and layout are the same as documented in the architecture manual.
1552
Radim Krčmář371313132016-07-12 22:09:27 +02001553The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
1554regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
1555See the note in KVM_GET_LAPIC.
1556
Jan Kiszka414fa982012-04-24 16:40:15 +02001557
15584.59 KVM_IOEVENTFD
Sasha Levin55399a02011-05-28 14:12:30 +03001559
1560Capability: KVM_CAP_IOEVENTFD
1561Architectures: all
1562Type: vm ioctl
1563Parameters: struct kvm_ioeventfd (in)
1564Returns: 0 on success, !0 on error
1565
1566This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1567within the guest. A guest write in the registered address will signal the
1568provided event instead of triggering an exit.
1569
1570struct kvm_ioeventfd {
1571 __u64 datamatch;
1572 __u64 addr; /* legal pio/mmio address */
Jason Wange9ea5062015-09-15 14:41:59 +08001573 __u32 len; /* 0, 1, 2, 4, or 8 bytes */
Sasha Levin55399a02011-05-28 14:12:30 +03001574 __s32 fd;
1575 __u32 flags;
1576 __u8 pad[36];
1577};
1578
Cornelia Huck2b834512013-02-28 12:33:20 +01001579For the special case of virtio-ccw devices on s390, the ioevent is matched
1580to a subchannel/virtqueue tuple instead.
1581
Sasha Levin55399a02011-05-28 14:12:30 +03001582The following flags are defined:
1583
1584#define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1585#define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1586#define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
Cornelia Huck2b834512013-02-28 12:33:20 +01001587#define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
1588 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
Sasha Levin55399a02011-05-28 14:12:30 +03001589
1590If datamatch flag is set, the event will be signaled only if the written value
1591to the registered address is equal to datamatch in struct kvm_ioeventfd.
1592
Cornelia Huck2b834512013-02-28 12:33:20 +01001593For virtio-ccw devices, addr contains the subchannel id and datamatch the
1594virtqueue index.
1595
Jason Wange9ea5062015-09-15 14:41:59 +08001596With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
1597the kernel will ignore the length of guest write and may get a faster vmexit.
1598The speedup may only apply to specific architectures, but the ioeventfd will
1599work anyway.
Jan Kiszka414fa982012-04-24 16:40:15 +02001600
16014.60 KVM_DIRTY_TLB
Scott Wooddc83b8b2011-08-18 15:25:21 -05001602
1603Capability: KVM_CAP_SW_TLB
1604Architectures: ppc
1605Type: vcpu ioctl
1606Parameters: struct kvm_dirty_tlb (in)
1607Returns: 0 on success, -1 on error
1608
1609struct kvm_dirty_tlb {
1610 __u64 bitmap;
1611 __u32 num_dirty;
1612};
1613
1614This must be called whenever userspace has changed an entry in the shared
1615TLB, prior to calling KVM_RUN on the associated vcpu.
1616
1617The "bitmap" field is the userspace address of an array. This array
1618consists of a number of bits, equal to the total number of TLB entries as
1619determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
1620nearest multiple of 64.
1621
1622Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
1623array.
1624
1625The array is little-endian: the bit 0 is the least significant bit of the
1626first byte, bit 8 is the least significant bit of the second byte, etc.
1627This avoids any complications with differing word sizes.
1628
1629The "num_dirty" field is a performance hint for KVM to determine whether it
1630should skip processing the bitmap and just invalidate everything. It must
1631be set to the number of set bits in the bitmap.
1632
Jan Kiszka414fa982012-04-24 16:40:15 +02001633
David Gibson54738c02011-06-29 00:22:41 +000016344.62 KVM_CREATE_SPAPR_TCE
1635
1636Capability: KVM_CAP_SPAPR_TCE
1637Architectures: powerpc
1638Type: vm ioctl
1639Parameters: struct kvm_create_spapr_tce (in)
1640Returns: file descriptor for manipulating the created TCE table
1641
1642This creates a virtual TCE (translation control entry) table, which
1643is an IOMMU for PAPR-style virtual I/O. It is used to translate
1644logical addresses used in virtual I/O into guest physical addresses,
1645and provides a scatter/gather capability for PAPR virtual I/O.
1646
1647/* for KVM_CAP_SPAPR_TCE */
1648struct kvm_create_spapr_tce {
1649 __u64 liobn;
1650 __u32 window_size;
1651};
1652
1653The liobn field gives the logical IO bus number for which to create a
1654TCE table. The window_size field specifies the size of the DMA window
1655which this TCE table will translate - the table will contain one 64
1656bit TCE entry for every 4kiB of the DMA window.
1657
1658When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1659table has been created using this ioctl(), the kernel will handle it
1660in real mode, updating the TCE table. H_PUT_TCE calls for other
1661liobns will cause a vm exit and must be handled by userspace.
1662
1663The return value is a file descriptor which can be passed to mmap(2)
1664to map the created TCE table into userspace. This lets userspace read
1665the entries written by kernel-handled H_PUT_TCE calls, and also lets
1666userspace update the TCE table directly which is useful in some
1667circumstances.
1668
Jan Kiszka414fa982012-04-24 16:40:15 +02001669
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +000016704.63 KVM_ALLOCATE_RMA
1671
1672Capability: KVM_CAP_PPC_RMA
1673Architectures: powerpc
1674Type: vm ioctl
1675Parameters: struct kvm_allocate_rma (out)
1676Returns: file descriptor for mapping the allocated RMA
1677
1678This allocates a Real Mode Area (RMA) from the pool allocated at boot
1679time by the kernel. An RMA is a physically-contiguous, aligned region
1680of memory used on older POWER processors to provide the memory which
1681will be accessed by real-mode (MMU off) accesses in a KVM guest.
1682POWER processors support a set of sizes for the RMA that usually
1683includes 64MB, 128MB, 256MB and some larger powers of two.
1684
1685/* for KVM_ALLOCATE_RMA */
1686struct kvm_allocate_rma {
1687 __u64 rma_size;
1688};
1689
1690The return value is a file descriptor which can be passed to mmap(2)
1691to map the allocated RMA into userspace. The mapped area can then be
1692passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1693RMA for a virtual machine. The size of the RMA in bytes (which is
1694fixed at host kernel boot time) is returned in the rma_size field of
1695the argument structure.
1696
1697The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1698is supported; 2 if the processor requires all virtual machines to have
1699an RMA, or 1 if the processor can use an RMA but doesn't require it,
1700because it supports the Virtual RMA (VRMA) facility.
1701
Jan Kiszka414fa982012-04-24 16:40:15 +02001702
Avi Kivity3f745f12011-12-07 12:42:47 +020017034.64 KVM_NMI
1704
1705Capability: KVM_CAP_USER_NMI
1706Architectures: x86
1707Type: vcpu ioctl
1708Parameters: none
1709Returns: 0 on success, -1 on error
1710
1711Queues an NMI on the thread's vcpu. Note this is well defined only
1712when KVM_CREATE_IRQCHIP has not been called, since this is an interface
1713between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
1714has been called, this interface is completely emulated within the kernel.
1715
1716To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
1717following algorithm:
1718
Masanari Iida5d4f6f32015-10-04 00:46:21 +09001719 - pause the vcpu
Avi Kivity3f745f12011-12-07 12:42:47 +02001720 - read the local APIC's state (KVM_GET_LAPIC)
1721 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
1722 - if so, issue KVM_NMI
1723 - resume the vcpu
1724
1725Some guests configure the LINT1 NMI input to cause a panic, aiding in
1726debugging.
1727
Jan Kiszka414fa982012-04-24 16:40:15 +02001728
Alexander Grafe24ed812011-09-14 10:02:41 +020017294.65 KVM_S390_UCAS_MAP
Carsten Otte27e03932012-01-04 10:25:21 +01001730
1731Capability: KVM_CAP_S390_UCONTROL
1732Architectures: s390
1733Type: vcpu ioctl
1734Parameters: struct kvm_s390_ucas_mapping (in)
1735Returns: 0 in case of success
1736
1737The parameter is defined like this:
1738 struct kvm_s390_ucas_mapping {
1739 __u64 user_addr;
1740 __u64 vcpu_addr;
1741 __u64 length;
1742 };
1743
1744This ioctl maps the memory at "user_addr" with the length "length" to
1745the vcpu's address space starting at "vcpu_addr". All parameters need to
Anatol Pomozovf884ab12013-05-08 16:56:16 -07001746be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01001747
Jan Kiszka414fa982012-04-24 16:40:15 +02001748
Alexander Grafe24ed812011-09-14 10:02:41 +020017494.66 KVM_S390_UCAS_UNMAP
Carsten Otte27e03932012-01-04 10:25:21 +01001750
1751Capability: KVM_CAP_S390_UCONTROL
1752Architectures: s390
1753Type: vcpu ioctl
1754Parameters: struct kvm_s390_ucas_mapping (in)
1755Returns: 0 in case of success
1756
1757The parameter is defined like this:
1758 struct kvm_s390_ucas_mapping {
1759 __u64 user_addr;
1760 __u64 vcpu_addr;
1761 __u64 length;
1762 };
1763
1764This ioctl unmaps the memory in the vcpu's address space starting at
1765"vcpu_addr" with the length "length". The field "user_addr" is ignored.
Anatol Pomozovf884ab12013-05-08 16:56:16 -07001766All parameters need to be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01001767
Jan Kiszka414fa982012-04-24 16:40:15 +02001768
Alexander Grafe24ed812011-09-14 10:02:41 +020017694.67 KVM_S390_VCPU_FAULT
Carsten Otteccc79102012-01-04 10:25:26 +01001770
1771Capability: KVM_CAP_S390_UCONTROL
1772Architectures: s390
1773Type: vcpu ioctl
1774Parameters: vcpu absolute address (in)
1775Returns: 0 in case of success
1776
1777This call creates a page table entry on the virtual cpu's address space
1778(for user controlled virtual machines) or the virtual machine's address
1779space (for regular virtual machines). This only works for minor faults,
1780thus it's recommended to access subject memory page via the user page
1781table upfront. This is useful to handle validity intercepts for user
1782controlled virtual machines to fault in the virtual cpu's lowcore pages
1783prior to calling the KVM_RUN ioctl.
1784
Jan Kiszka414fa982012-04-24 16:40:15 +02001785
Alexander Grafe24ed812011-09-14 10:02:41 +020017864.68 KVM_SET_ONE_REG
1787
1788Capability: KVM_CAP_ONE_REG
1789Architectures: all
1790Type: vcpu ioctl
1791Parameters: struct kvm_one_reg (in)
1792Returns: 0 on success, negative value on failure
1793
1794struct kvm_one_reg {
1795 __u64 id;
1796 __u64 addr;
1797};
1798
1799Using this ioctl, a single vcpu register can be set to a specific value
1800defined by user space with the passed in struct kvm_one_reg, where id
1801refers to the register identifier as described below and addr is a pointer
1802to a variable with the respective size. There can be architecture agnostic
1803and architecture specific registers. Each have their own range of operation
1804and their own constants and width. To keep track of the implemented
1805registers, find a list below:
1806
James Hoganbf5590f2014-07-04 15:11:34 +01001807 Arch | Register | Width (bits)
1808 | |
1809 PPC | KVM_REG_PPC_HIOR | 64
1810 PPC | KVM_REG_PPC_IAC1 | 64
1811 PPC | KVM_REG_PPC_IAC2 | 64
1812 PPC | KVM_REG_PPC_IAC3 | 64
1813 PPC | KVM_REG_PPC_IAC4 | 64
1814 PPC | KVM_REG_PPC_DAC1 | 64
1815 PPC | KVM_REG_PPC_DAC2 | 64
1816 PPC | KVM_REG_PPC_DABR | 64
1817 PPC | KVM_REG_PPC_DSCR | 64
1818 PPC | KVM_REG_PPC_PURR | 64
1819 PPC | KVM_REG_PPC_SPURR | 64
1820 PPC | KVM_REG_PPC_DAR | 64
1821 PPC | KVM_REG_PPC_DSISR | 32
1822 PPC | KVM_REG_PPC_AMR | 64
1823 PPC | KVM_REG_PPC_UAMOR | 64
1824 PPC | KVM_REG_PPC_MMCR0 | 64
1825 PPC | KVM_REG_PPC_MMCR1 | 64
1826 PPC | KVM_REG_PPC_MMCRA | 64
1827 PPC | KVM_REG_PPC_MMCR2 | 64
1828 PPC | KVM_REG_PPC_MMCRS | 64
1829 PPC | KVM_REG_PPC_SIAR | 64
1830 PPC | KVM_REG_PPC_SDAR | 64
1831 PPC | KVM_REG_PPC_SIER | 64
1832 PPC | KVM_REG_PPC_PMC1 | 32
1833 PPC | KVM_REG_PPC_PMC2 | 32
1834 PPC | KVM_REG_PPC_PMC3 | 32
1835 PPC | KVM_REG_PPC_PMC4 | 32
1836 PPC | KVM_REG_PPC_PMC5 | 32
1837 PPC | KVM_REG_PPC_PMC6 | 32
1838 PPC | KVM_REG_PPC_PMC7 | 32
1839 PPC | KVM_REG_PPC_PMC8 | 32
1840 PPC | KVM_REG_PPC_FPR0 | 64
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001841 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001842 PPC | KVM_REG_PPC_FPR31 | 64
1843 PPC | KVM_REG_PPC_VR0 | 128
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001844 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001845 PPC | KVM_REG_PPC_VR31 | 128
1846 PPC | KVM_REG_PPC_VSR0 | 128
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001847 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001848 PPC | KVM_REG_PPC_VSR31 | 128
1849 PPC | KVM_REG_PPC_FPSCR | 64
1850 PPC | KVM_REG_PPC_VSCR | 32
1851 PPC | KVM_REG_PPC_VPA_ADDR | 64
1852 PPC | KVM_REG_PPC_VPA_SLB | 128
1853 PPC | KVM_REG_PPC_VPA_DTL | 128
1854 PPC | KVM_REG_PPC_EPCR | 32
1855 PPC | KVM_REG_PPC_EPR | 32
1856 PPC | KVM_REG_PPC_TCR | 32
1857 PPC | KVM_REG_PPC_TSR | 32
1858 PPC | KVM_REG_PPC_OR_TSR | 32
1859 PPC | KVM_REG_PPC_CLEAR_TSR | 32
1860 PPC | KVM_REG_PPC_MAS0 | 32
1861 PPC | KVM_REG_PPC_MAS1 | 32
1862 PPC | KVM_REG_PPC_MAS2 | 64
1863 PPC | KVM_REG_PPC_MAS7_3 | 64
1864 PPC | KVM_REG_PPC_MAS4 | 32
1865 PPC | KVM_REG_PPC_MAS6 | 32
1866 PPC | KVM_REG_PPC_MMUCFG | 32
1867 PPC | KVM_REG_PPC_TLB0CFG | 32
1868 PPC | KVM_REG_PPC_TLB1CFG | 32
1869 PPC | KVM_REG_PPC_TLB2CFG | 32
1870 PPC | KVM_REG_PPC_TLB3CFG | 32
1871 PPC | KVM_REG_PPC_TLB0PS | 32
1872 PPC | KVM_REG_PPC_TLB1PS | 32
1873 PPC | KVM_REG_PPC_TLB2PS | 32
1874 PPC | KVM_REG_PPC_TLB3PS | 32
1875 PPC | KVM_REG_PPC_EPTCFG | 32
1876 PPC | KVM_REG_PPC_ICP_STATE | 64
1877 PPC | KVM_REG_PPC_TB_OFFSET | 64
1878 PPC | KVM_REG_PPC_SPMC1 | 32
1879 PPC | KVM_REG_PPC_SPMC2 | 32
1880 PPC | KVM_REG_PPC_IAMR | 64
1881 PPC | KVM_REG_PPC_TFHAR | 64
1882 PPC | KVM_REG_PPC_TFIAR | 64
1883 PPC | KVM_REG_PPC_TEXASR | 64
1884 PPC | KVM_REG_PPC_FSCR | 64
1885 PPC | KVM_REG_PPC_PSPB | 32
1886 PPC | KVM_REG_PPC_EBBHR | 64
1887 PPC | KVM_REG_PPC_EBBRR | 64
1888 PPC | KVM_REG_PPC_BESCR | 64
1889 PPC | KVM_REG_PPC_TAR | 64
1890 PPC | KVM_REG_PPC_DPDES | 64
1891 PPC | KVM_REG_PPC_DAWR | 64
1892 PPC | KVM_REG_PPC_DAWRX | 64
1893 PPC | KVM_REG_PPC_CIABR | 64
1894 PPC | KVM_REG_PPC_IC | 64
1895 PPC | KVM_REG_PPC_VTB | 64
1896 PPC | KVM_REG_PPC_CSIGR | 64
1897 PPC | KVM_REG_PPC_TACR | 64
1898 PPC | KVM_REG_PPC_TCSCR | 64
1899 PPC | KVM_REG_PPC_PID | 64
1900 PPC | KVM_REG_PPC_ACOP | 64
1901 PPC | KVM_REG_PPC_VRSAVE | 32
Paolo Bonzinicc568ea2014-08-05 09:55:22 +02001902 PPC | KVM_REG_PPC_LPCR | 32
1903 PPC | KVM_REG_PPC_LPCR_64 | 64
James Hoganbf5590f2014-07-04 15:11:34 +01001904 PPC | KVM_REG_PPC_PPR | 64
1905 PPC | KVM_REG_PPC_ARCH_COMPAT | 32
1906 PPC | KVM_REG_PPC_DABRX | 32
1907 PPC | KVM_REG_PPC_WORT | 64
Bharat Bhushanbc8a4e52014-08-13 14:40:06 +05301908 PPC | KVM_REG_PPC_SPRG9 | 64
1909 PPC | KVM_REG_PPC_DBSR | 32
Paul Mackerrase9cf1e02016-11-18 13:11:42 +11001910 PPC | KVM_REG_PPC_TIDR | 64
1911 PPC | KVM_REG_PPC_PSSCR | 64
Paul Mackerras58555642018-01-12 20:55:20 +11001912 PPC | KVM_REG_PPC_DEC_EXPIRY | 64
James Hoganbf5590f2014-07-04 15:11:34 +01001913 PPC | KVM_REG_PPC_TM_GPR0 | 64
Michael Neuling3b783472013-09-03 11:13:12 +10001914 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001915 PPC | KVM_REG_PPC_TM_GPR31 | 64
1916 PPC | KVM_REG_PPC_TM_VSR0 | 128
Michael Neuling3b783472013-09-03 11:13:12 +10001917 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001918 PPC | KVM_REG_PPC_TM_VSR63 | 128
1919 PPC | KVM_REG_PPC_TM_CR | 64
1920 PPC | KVM_REG_PPC_TM_LR | 64
1921 PPC | KVM_REG_PPC_TM_CTR | 64
1922 PPC | KVM_REG_PPC_TM_FPSCR | 64
1923 PPC | KVM_REG_PPC_TM_AMR | 64
1924 PPC | KVM_REG_PPC_TM_PPR | 64
1925 PPC | KVM_REG_PPC_TM_VRSAVE | 64
1926 PPC | KVM_REG_PPC_TM_VSCR | 32
1927 PPC | KVM_REG_PPC_TM_DSCR | 64
1928 PPC | KVM_REG_PPC_TM_TAR | 64
Paul Mackerras0d808df2016-11-07 15:09:58 +11001929 PPC | KVM_REG_PPC_TM_XER | 64
James Hoganc2d2c212014-07-04 15:11:35 +01001930 | |
1931 MIPS | KVM_REG_MIPS_R0 | 64
1932 ...
1933 MIPS | KVM_REG_MIPS_R31 | 64
1934 MIPS | KVM_REG_MIPS_HI | 64
1935 MIPS | KVM_REG_MIPS_LO | 64
1936 MIPS | KVM_REG_MIPS_PC | 64
1937 MIPS | KVM_REG_MIPS_CP0_INDEX | 32
James Hogan013044c2016-12-07 17:16:37 +00001938 MIPS | KVM_REG_MIPS_CP0_ENTRYLO0 | 64
1939 MIPS | KVM_REG_MIPS_CP0_ENTRYLO1 | 64
James Hoganc2d2c212014-07-04 15:11:35 +01001940 MIPS | KVM_REG_MIPS_CP0_CONTEXT | 64
James Hogandffe0422017-03-14 10:15:34 +00001941 MIPS | KVM_REG_MIPS_CP0_CONTEXTCONFIG| 32
James Hoganc2d2c212014-07-04 15:11:35 +01001942 MIPS | KVM_REG_MIPS_CP0_USERLOCAL | 64
James Hogandffe0422017-03-14 10:15:34 +00001943 MIPS | KVM_REG_MIPS_CP0_XCONTEXTCONFIG| 64
James Hoganc2d2c212014-07-04 15:11:35 +01001944 MIPS | KVM_REG_MIPS_CP0_PAGEMASK | 32
James Hoganc992a4f2017-03-14 10:15:31 +00001945 MIPS | KVM_REG_MIPS_CP0_PAGEGRAIN | 32
James Hogan4b7de022017-03-14 10:15:35 +00001946 MIPS | KVM_REG_MIPS_CP0_SEGCTL0 | 64
1947 MIPS | KVM_REG_MIPS_CP0_SEGCTL1 | 64
1948 MIPS | KVM_REG_MIPS_CP0_SEGCTL2 | 64
James Hogan5a2f3522017-03-14 10:15:36 +00001949 MIPS | KVM_REG_MIPS_CP0_PWBASE | 64
1950 MIPS | KVM_REG_MIPS_CP0_PWFIELD | 64
1951 MIPS | KVM_REG_MIPS_CP0_PWSIZE | 64
James Hoganc2d2c212014-07-04 15:11:35 +01001952 MIPS | KVM_REG_MIPS_CP0_WIRED | 32
James Hogan5a2f3522017-03-14 10:15:36 +00001953 MIPS | KVM_REG_MIPS_CP0_PWCTL | 32
James Hoganc2d2c212014-07-04 15:11:35 +01001954 MIPS | KVM_REG_MIPS_CP0_HWRENA | 32
1955 MIPS | KVM_REG_MIPS_CP0_BADVADDR | 64
James Hoganedc89262017-03-14 10:15:33 +00001956 MIPS | KVM_REG_MIPS_CP0_BADINSTR | 32
1957 MIPS | KVM_REG_MIPS_CP0_BADINSTRP | 32
James Hoganc2d2c212014-07-04 15:11:35 +01001958 MIPS | KVM_REG_MIPS_CP0_COUNT | 32
1959 MIPS | KVM_REG_MIPS_CP0_ENTRYHI | 64
1960 MIPS | KVM_REG_MIPS_CP0_COMPARE | 32
1961 MIPS | KVM_REG_MIPS_CP0_STATUS | 32
James Hoganad58d4d2015-02-02 22:55:17 +00001962 MIPS | KVM_REG_MIPS_CP0_INTCTL | 32
James Hoganc2d2c212014-07-04 15:11:35 +01001963 MIPS | KVM_REG_MIPS_CP0_CAUSE | 32
1964 MIPS | KVM_REG_MIPS_CP0_EPC | 64
James Hogan1068eaa2014-06-26 13:56:52 +01001965 MIPS | KVM_REG_MIPS_CP0_PRID | 32
James Hogan7801bbe2016-11-14 23:59:27 +00001966 MIPS | KVM_REG_MIPS_CP0_EBASE | 64
James Hoganc2d2c212014-07-04 15:11:35 +01001967 MIPS | KVM_REG_MIPS_CP0_CONFIG | 32
1968 MIPS | KVM_REG_MIPS_CP0_CONFIG1 | 32
1969 MIPS | KVM_REG_MIPS_CP0_CONFIG2 | 32
1970 MIPS | KVM_REG_MIPS_CP0_CONFIG3 | 32
James Hoganc7716072014-06-26 15:11:29 +01001971 MIPS | KVM_REG_MIPS_CP0_CONFIG4 | 32
1972 MIPS | KVM_REG_MIPS_CP0_CONFIG5 | 32
James Hoganc2d2c212014-07-04 15:11:35 +01001973 MIPS | KVM_REG_MIPS_CP0_CONFIG7 | 32
James Hoganc992a4f2017-03-14 10:15:31 +00001974 MIPS | KVM_REG_MIPS_CP0_XCONTEXT | 64
James Hoganc2d2c212014-07-04 15:11:35 +01001975 MIPS | KVM_REG_MIPS_CP0_ERROREPC | 64
James Hogan05108702016-06-15 19:29:56 +01001976 MIPS | KVM_REG_MIPS_CP0_KSCRATCH1 | 64
1977 MIPS | KVM_REG_MIPS_CP0_KSCRATCH2 | 64
1978 MIPS | KVM_REG_MIPS_CP0_KSCRATCH3 | 64
1979 MIPS | KVM_REG_MIPS_CP0_KSCRATCH4 | 64
1980 MIPS | KVM_REG_MIPS_CP0_KSCRATCH5 | 64
1981 MIPS | KVM_REG_MIPS_CP0_KSCRATCH6 | 64
James Hogand42a0082017-03-14 10:15:38 +00001982 MIPS | KVM_REG_MIPS_CP0_MAAR(0..63) | 64
James Hoganc2d2c212014-07-04 15:11:35 +01001983 MIPS | KVM_REG_MIPS_COUNT_CTL | 64
1984 MIPS | KVM_REG_MIPS_COUNT_RESUME | 64
1985 MIPS | KVM_REG_MIPS_COUNT_HZ | 64
James Hogan379245c2014-12-02 15:48:24 +00001986 MIPS | KVM_REG_MIPS_FPR_32(0..31) | 32
1987 MIPS | KVM_REG_MIPS_FPR_64(0..31) | 64
James Hoganab86bd62014-12-02 15:48:24 +00001988 MIPS | KVM_REG_MIPS_VEC_128(0..31) | 128
James Hogan379245c2014-12-02 15:48:24 +00001989 MIPS | KVM_REG_MIPS_FCR_IR | 32
1990 MIPS | KVM_REG_MIPS_FCR_CSR | 32
James Hoganab86bd62014-12-02 15:48:24 +00001991 MIPS | KVM_REG_MIPS_MSA_IR | 32
1992 MIPS | KVM_REG_MIPS_MSA_CSR | 32
Jan Kiszka414fa982012-04-24 16:40:15 +02001993
Christoffer Dall749cf76c2013-01-20 18:28:06 -05001994ARM registers are mapped using the lower 32 bits. The upper 16 of that
1995is the register group type, or coprocessor number:
1996
1997ARM core registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07001998 0x4020 0000 0010 <index into the kvm_regs struct:16>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05001999
Christoffer Dall11382452013-01-20 18:28:10 -05002000ARM 32-bit CP15 registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002001 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
Christoffer Dall11382452013-01-20 18:28:10 -05002002
2003ARM 64-bit CP15 registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002004 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002005
Christoffer Dallc27581e2013-01-20 18:28:10 -05002006ARM CCSIDR registers are demultiplexed by CSSELR value:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002007 0x4020 0000 0011 00 <csselr:8>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002008
Rusty Russell4fe21e42013-01-20 18:28:11 -05002009ARM 32-bit VFP control registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002010 0x4020 0000 0012 1 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002011
2012ARM 64-bit FP registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002013 0x4030 0000 0012 0 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002014
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002015ARM firmware pseudo-registers have the following bit pattern:
2016 0x4030 0000 0014 <regno:16>
2017
Marc Zyngier379e04c72013-04-02 17:46:31 +01002018
2019arm64 registers are mapped using the lower 32 bits. The upper 16 of
2020that is the register group type, or coprocessor number:
2021
2022arm64 core/FP-SIMD registers have the following id bit patterns. Note
2023that the size of the access is variable, as the kvm_regs structure
2024contains elements ranging from 32 to 128 bits. The index is a 32bit
2025value in the kvm_regs structure seen as a 32bit array.
2026 0x60x0 0000 0010 <index into the kvm_regs struct:16>
2027
2028arm64 CCSIDR registers are demultiplexed by CSSELR value:
2029 0x6020 0000 0011 00 <csselr:8>
2030
2031arm64 system registers have the following id bit patterns:
2032 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2033
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002034arm64 firmware pseudo-registers have the following bit pattern:
2035 0x6030 0000 0014 <regno:16>
2036
James Hoganc2d2c212014-07-04 15:11:35 +01002037
2038MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
2039the register group type:
2040
2041MIPS core registers (see above) have the following id bit patterns:
2042 0x7030 0000 0000 <reg:16>
2043
2044MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
2045patterns depending on whether they're 32-bit or 64-bit registers:
2046 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
2047 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2048
James Hogan013044c2016-12-07 17:16:37 +00002049Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2050versions of the EntryLo registers regardless of the word size of the host
2051hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2052with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2053the PFNX field starting at bit 30.
2054
James Hogand42a0082017-03-14 10:15:38 +00002055MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
2056patterns:
2057 0x7030 0000 0001 01 <reg:8>
2058
James Hoganc2d2c212014-07-04 15:11:35 +01002059MIPS KVM control registers (see above) have the following id bit patterns:
2060 0x7030 0000 0002 <reg:16>
2061
James Hogan379245c2014-12-02 15:48:24 +00002062MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2063id bit patterns depending on the size of the register being accessed. They are
2064always accessed according to the current guest FPU mode (Status.FR and
2065Config5.FRE), i.e. as the guest would see them, and they become unpredictable
James Hoganab86bd62014-12-02 15:48:24 +00002066if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2067registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
2068overlap the FPU registers:
James Hogan379245c2014-12-02 15:48:24 +00002069 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2070 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
James Hoganab86bd62014-12-02 15:48:24 +00002071 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
James Hogan379245c2014-12-02 15:48:24 +00002072
2073MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
2074following id bit patterns:
2075 0x7020 0000 0003 01 <0:3> <reg:5>
2076
James Hoganab86bd62014-12-02 15:48:24 +00002077MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
2078following id bit patterns:
2079 0x7020 0000 0003 02 <0:3> <reg:5>
2080
James Hoganc2d2c212014-07-04 15:11:35 +01002081
Alexander Grafe24ed812011-09-14 10:02:41 +020020824.69 KVM_GET_ONE_REG
2083
2084Capability: KVM_CAP_ONE_REG
2085Architectures: all
2086Type: vcpu ioctl
2087Parameters: struct kvm_one_reg (in and out)
2088Returns: 0 on success, negative value on failure
2089
2090This ioctl allows to receive the value of a single register implemented
2091in a vcpu. The register to read is indicated by the "id" field of the
2092kvm_one_reg struct passed in. On success, the register value can be found
2093at the memory location pointed to by "addr".
2094
2095The list of registers accessible using this interface is identical to the
Bharat Bhushan2e232702012-08-15 17:37:13 +00002096list in 4.68.
Alexander Grafe24ed812011-09-14 10:02:41 +02002097
Jan Kiszka414fa982012-04-24 16:40:15 +02002098
Eric B Munson1c0b28c2012-03-10 14:37:27 -050020994.70 KVM_KVMCLOCK_CTRL
2100
2101Capability: KVM_CAP_KVMCLOCK_CTRL
2102Architectures: Any that implement pvclocks (currently x86 only)
2103Type: vcpu ioctl
2104Parameters: None
2105Returns: 0 on success, -1 on error
2106
2107This signals to the host kernel that the specified guest is being paused by
2108userspace. The host will set a flag in the pvclock structure that is checked
2109from the soft lockup watchdog. The flag is part of the pvclock structure that
2110is shared between guest and host, specifically the second bit of the flags
2111field of the pvclock_vcpu_time_info structure. It will be set exclusively by
2112the host and read/cleared exclusively by the guest. The guest operation of
2113checking and clearing the flag must an atomic operation so
2114load-link/store-conditional, or equivalent must be used. There are two cases
2115where the guest will clear the flag: when the soft lockup watchdog timer resets
2116itself or when a soft lockup is detected. This ioctl can be called any time
2117after pausing the vcpu, but before it is resumed.
2118
Jan Kiszka414fa982012-04-24 16:40:15 +02002119
Jan Kiszka07975ad2012-03-29 21:14:12 +020021204.71 KVM_SIGNAL_MSI
2121
2122Capability: KVM_CAP_SIGNAL_MSI
Vladimir Murzin29885092016-11-02 11:55:34 +00002123Architectures: x86 arm arm64
Jan Kiszka07975ad2012-03-29 21:14:12 +02002124Type: vm ioctl
2125Parameters: struct kvm_msi (in)
2126Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
2127
2128Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2129MSI messages.
2130
2131struct kvm_msi {
2132 __u32 address_lo;
2133 __u32 address_hi;
2134 __u32 data;
2135 __u32 flags;
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002136 __u32 devid;
2137 __u8 pad[12];
Jan Kiszka07975ad2012-03-29 21:14:12 +02002138};
2139
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002140flags: KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM
2141 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2142 the device ID. If this capability is not available, userspace
2143 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002144
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002145If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2146for the device that wrote the MSI message. For PCI, this is usually a
2147BFD identifier in the lower 16 bits.
Jan Kiszka07975ad2012-03-29 21:14:12 +02002148
Paolo Bonzini055b6ae2016-08-04 14:01:05 +02002149On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2150feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
2151address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
2152address_hi must be zero.
Radim Krčmář371313132016-07-12 22:09:27 +02002153
Jan Kiszka414fa982012-04-24 16:40:15 +02002154
Jan Kiszka0589ff62012-04-24 16:40:16 +020021554.71 KVM_CREATE_PIT2
2156
2157Capability: KVM_CAP_PIT2
2158Architectures: x86
2159Type: vm ioctl
2160Parameters: struct kvm_pit_config (in)
2161Returns: 0 on success, -1 on error
2162
2163Creates an in-kernel device model for the i8254 PIT. This call is only valid
2164after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
2165parameters have to be passed:
2166
2167struct kvm_pit_config {
2168 __u32 flags;
2169 __u32 pad[15];
2170};
2171
2172Valid flags are:
2173
2174#define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
2175
Jan Kiszkab6ddf052012-04-24 16:40:17 +02002176PIT timer interrupts may use a per-VM kernel thread for injection. If it
2177exists, this thread will have a name of the following pattern:
2178
2179kvm-pit/<owner-process-pid>
2180
2181When running a guest with elevated priorities, the scheduling parameters of
2182this thread may have to be adjusted accordingly.
2183
Jan Kiszka0589ff62012-04-24 16:40:16 +02002184This IOCTL replaces the obsolete KVM_CREATE_PIT.
2185
2186
21874.72 KVM_GET_PIT2
2188
2189Capability: KVM_CAP_PIT_STATE2
2190Architectures: x86
2191Type: vm ioctl
2192Parameters: struct kvm_pit_state2 (out)
2193Returns: 0 on success, -1 on error
2194
2195Retrieves the state of the in-kernel PIT model. Only valid after
2196KVM_CREATE_PIT2. The state is returned in the following structure:
2197
2198struct kvm_pit_state2 {
2199 struct kvm_pit_channel_state channels[3];
2200 __u32 flags;
2201 __u32 reserved[9];
2202};
2203
2204Valid flags are:
2205
2206/* disable PIT in HPET legacy mode */
2207#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
2208
2209This IOCTL replaces the obsolete KVM_GET_PIT.
2210
2211
22124.73 KVM_SET_PIT2
2213
2214Capability: KVM_CAP_PIT_STATE2
2215Architectures: x86
2216Type: vm ioctl
2217Parameters: struct kvm_pit_state2 (in)
2218Returns: 0 on success, -1 on error
2219
2220Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
2221See KVM_GET_PIT2 for details on struct kvm_pit_state2.
2222
2223This IOCTL replaces the obsolete KVM_SET_PIT.
2224
2225
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000022264.74 KVM_PPC_GET_SMMU_INFO
2227
2228Capability: KVM_CAP_PPC_GET_SMMU_INFO
2229Architectures: powerpc
2230Type: vm ioctl
2231Parameters: None
2232Returns: 0 on success, -1 on error
2233
2234This populates and returns a structure describing the features of
2235the "Server" class MMU emulation supported by KVM.
Stefan Hubercc22c352013-06-05 12:24:37 +02002236This can in turn be used by userspace to generate the appropriate
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002237device-tree properties for the guest operating system.
2238
Carlos Garciac98be0c2014-04-04 22:31:00 -04002239The structure contains some global information, followed by an
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002240array of supported segment page sizes:
2241
2242 struct kvm_ppc_smmu_info {
2243 __u64 flags;
2244 __u32 slb_size;
2245 __u32 pad;
2246 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
2247 };
2248
2249The supported flags are:
2250
2251 - KVM_PPC_PAGE_SIZES_REAL:
2252 When that flag is set, guest page sizes must "fit" the backing
2253 store page sizes. When not set, any page size in the list can
2254 be used regardless of how they are backed by userspace.
2255
2256 - KVM_PPC_1T_SEGMENTS
2257 The emulated MMU supports 1T segments in addition to the
2258 standard 256M ones.
2259
2260The "slb_size" field indicates how many SLB entries are supported
2261
2262The "sps" array contains 8 entries indicating the supported base
2263page sizes for a segment in increasing order. Each entry is defined
2264as follow:
2265
2266 struct kvm_ppc_one_seg_page_size {
2267 __u32 page_shift; /* Base page shift of segment (or 0) */
2268 __u32 slb_enc; /* SLB encoding for BookS */
2269 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
2270 };
2271
2272An entry with a "page_shift" of 0 is unused. Because the array is
2273organized in increasing order, a lookup can stop when encoutering
2274such an entry.
2275
2276The "slb_enc" field provides the encoding to use in the SLB for the
2277page size. The bits are in positions such as the value can directly
2278be OR'ed into the "vsid" argument of the slbmte instruction.
2279
2280The "enc" array is a list which for each of those segment base page
2281size provides the list of supported actual page sizes (which can be
2282only larger or equal to the base page size), along with the
Anatol Pomozovf884ab12013-05-08 16:56:16 -07002283corresponding encoding in the hash PTE. Similarly, the array is
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000022848 entries sorted by increasing sizes and an entry with a "0" shift
2285is an empty entry and a terminator:
2286
2287 struct kvm_ppc_one_page_size {
2288 __u32 page_shift; /* Page shift (or 0) */
2289 __u32 pte_enc; /* Encoding in the HPTE (>>12) */
2290 };
2291
2292The "pte_enc" field provides a value that can OR'ed into the hash
2293PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
2294into the hash PTE second double word).
2295
Alex Williamsonf36992e2012-06-29 09:56:16 -060022964.75 KVM_IRQFD
2297
2298Capability: KVM_CAP_IRQFD
Eric Auger174178f2015-03-04 11:14:36 +01002299Architectures: x86 s390 arm arm64
Alex Williamsonf36992e2012-06-29 09:56:16 -06002300Type: vm ioctl
2301Parameters: struct kvm_irqfd (in)
2302Returns: 0 on success, -1 on error
2303
2304Allows setting an eventfd to directly trigger a guest interrupt.
2305kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
2306kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
Masanari Iida17180032013-12-22 01:21:23 +09002307an event is triggered on the eventfd, an interrupt is injected into
Alex Williamsonf36992e2012-06-29 09:56:16 -06002308the guest using the specified gsi pin. The irqfd is removed using
2309the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
2310and kvm_irqfd.gsi.
2311
Alex Williamson7a844282012-09-21 11:58:03 -06002312With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
2313mechanism allowing emulation of level-triggered, irqfd-based
2314interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
2315additional eventfd in the kvm_irqfd.resamplefd field. When operating
2316in resample mode, posting of an interrupt through kvm_irq.fd asserts
2317the specified gsi in the irqchip. When the irqchip is resampled, such
Masanari Iida17180032013-12-22 01:21:23 +09002318as from an EOI, the gsi is de-asserted and the user is notified via
Alex Williamson7a844282012-09-21 11:58:03 -06002319kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
2320the interrupt if the device making use of it still requires service.
2321Note that closing the resamplefd is not sufficient to disable the
2322irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
2323and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
2324
Eric Auger180ae7b2016-07-22 16:20:41 +00002325On arm/arm64, gsi routing being supported, the following can happen:
2326- in case no routing entry is associated to this gsi, injection fails
2327- in case the gsi is associated to an irqchip routing entry,
2328 irqchip.pin + 32 corresponds to the injected SPI ID.
Eric Auger995a0ee2016-07-22 16:20:42 +00002329- in case the gsi is associated to an MSI routing entry, the MSI
2330 message and device ID are translated into an LPI (support restricted
2331 to GICv3 ITS in-kernel emulation).
Eric Auger174178f2015-03-04 11:14:36 +01002332
Linus Torvalds5fecc9d2012-07-24 12:01:20 -070023334.76 KVM_PPC_ALLOCATE_HTAB
Paul Mackerras32fad282012-05-04 02:32:53 +00002334
2335Capability: KVM_CAP_PPC_ALLOC_HTAB
2336Architectures: powerpc
2337Type: vm ioctl
2338Parameters: Pointer to u32 containing hash table order (in/out)
2339Returns: 0 on success, -1 on error
2340
2341This requests the host kernel to allocate an MMU hash table for a
2342guest using the PAPR paravirtualization interface. This only does
2343anything if the kernel is configured to use the Book 3S HV style of
2344virtualization. Otherwise the capability doesn't exist and the ioctl
2345returns an ENOTTY error. The rest of this description assumes Book 3S
2346HV.
2347
2348There must be no vcpus running when this ioctl is called; if there
2349are, it will do nothing and return an EBUSY error.
2350
2351The parameter is a pointer to a 32-bit unsigned integer variable
2352containing the order (log base 2) of the desired size of the hash
2353table, which must be between 18 and 46. On successful return from the
David Gibsonf98a8bf2016-12-20 16:49:03 +11002354ioctl, the value will not be changed by the kernel.
Paul Mackerras32fad282012-05-04 02:32:53 +00002355
2356If no hash table has been allocated when any vcpu is asked to run
2357(with the KVM_RUN ioctl), the host kernel will allocate a
2358default-sized hash table (16 MB).
2359
2360If this ioctl is called when a hash table has already been allocated,
David Gibsonf98a8bf2016-12-20 16:49:03 +11002361with a different order from the existing hash table, the existing hash
2362table will be freed and a new one allocated. If this is ioctl is
2363called when a hash table has already been allocated of the same order
2364as specified, the kernel will clear out the existing hash table (zero
2365all HPTEs). In either case, if the guest is using the virtualized
2366real-mode area (VRMA) facility, the kernel will re-create the VMRA
2367HPTEs on the next KVM_RUN of any vcpu.
Paul Mackerras32fad282012-05-04 02:32:53 +00002368
Cornelia Huck416ad652012-10-02 16:25:37 +020023694.77 KVM_S390_INTERRUPT
2370
2371Capability: basic
2372Architectures: s390
2373Type: vm ioctl, vcpu ioctl
2374Parameters: struct kvm_s390_interrupt (in)
2375Returns: 0 on success, -1 on error
2376
2377Allows to inject an interrupt to the guest. Interrupts can be floating
2378(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
2379
2380Interrupt parameters are passed via kvm_s390_interrupt:
2381
2382struct kvm_s390_interrupt {
2383 __u32 type;
2384 __u32 parm;
2385 __u64 parm64;
2386};
2387
2388type can be one of the following:
2389
David Hildenbrand28225452014-10-15 16:48:16 +02002390KVM_S390_SIGP_STOP (vcpu) - sigp stop; optional flags in parm
Cornelia Huck416ad652012-10-02 16:25:37 +02002391KVM_S390_PROGRAM_INT (vcpu) - program check; code in parm
2392KVM_S390_SIGP_SET_PREFIX (vcpu) - sigp set prefix; prefix address in parm
2393KVM_S390_RESTART (vcpu) - restart
Thomas Huthe029ae52014-03-26 16:11:54 +01002394KVM_S390_INT_CLOCK_COMP (vcpu) - clock comparator interrupt
2395KVM_S390_INT_CPU_TIMER (vcpu) - CPU timer interrupt
Cornelia Huck416ad652012-10-02 16:25:37 +02002396KVM_S390_INT_VIRTIO (vm) - virtio external interrupt; external interrupt
2397 parameters in parm and parm64
2398KVM_S390_INT_SERVICE (vm) - sclp external interrupt; sclp parameter in parm
2399KVM_S390_INT_EMERGENCY (vcpu) - sigp emergency; source cpu in parm
2400KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
Cornelia Huckd8346b72012-12-20 15:32:08 +01002401KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) - compound value to indicate an
2402 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
2403 I/O interruption parameters in parm (subchannel) and parm64 (intparm,
2404 interruption subclass)
Cornelia Huck48a3e952012-12-20 15:32:09 +01002405KVM_S390_MCHK (vm, vcpu) - machine check interrupt; cr 14 bits in parm,
2406 machine check interrupt code in parm64 (note that
2407 machine checks needing further payload are not
2408 supported by this ioctl)
Cornelia Huck416ad652012-10-02 16:25:37 +02002409
2410Note that the vcpu ioctl is asynchronous to vcpu execution.
2411
Paul Mackerrasa2932922012-11-19 22:57:20 +000024124.78 KVM_PPC_GET_HTAB_FD
2413
2414Capability: KVM_CAP_PPC_HTAB_FD
2415Architectures: powerpc
2416Type: vm ioctl
2417Parameters: Pointer to struct kvm_get_htab_fd (in)
2418Returns: file descriptor number (>= 0) on success, -1 on error
2419
2420This returns a file descriptor that can be used either to read out the
2421entries in the guest's hashed page table (HPT), or to write entries to
2422initialize the HPT. The returned fd can only be written to if the
2423KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
2424can only be read if that bit is clear. The argument struct looks like
2425this:
2426
2427/* For KVM_PPC_GET_HTAB_FD */
2428struct kvm_get_htab_fd {
2429 __u64 flags;
2430 __u64 start_index;
2431 __u64 reserved[2];
2432};
2433
2434/* Values for kvm_get_htab_fd.flags */
2435#define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
2436#define KVM_GET_HTAB_WRITE ((__u64)0x2)
2437
2438The `start_index' field gives the index in the HPT of the entry at
2439which to start reading. It is ignored when writing.
2440
2441Reads on the fd will initially supply information about all
2442"interesting" HPT entries. Interesting entries are those with the
2443bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
2444all entries. When the end of the HPT is reached, the read() will
2445return. If read() is called again on the fd, it will start again from
2446the beginning of the HPT, but will only return HPT entries that have
2447changed since they were last read.
2448
2449Data read or written is structured as a header (8 bytes) followed by a
2450series of valid HPT entries (16 bytes) each. The header indicates how
2451many valid HPT entries there are and how many invalid entries follow
2452the valid entries. The invalid entries are not represented explicitly
2453in the stream. The header format is:
2454
2455struct kvm_get_htab_header {
2456 __u32 index;
2457 __u16 n_valid;
2458 __u16 n_invalid;
2459};
2460
2461Writes to the fd create HPT entries starting at the index given in the
2462header; first `n_valid' valid entries with contents from the data
2463written, then `n_invalid' invalid entries, invalidating any previously
2464valid entries found.
2465
Scott Wood852b6d52013-04-12 14:08:42 +000024664.79 KVM_CREATE_DEVICE
2467
2468Capability: KVM_CAP_DEVICE_CTRL
2469Type: vm ioctl
2470Parameters: struct kvm_create_device (in/out)
2471Returns: 0 on success, -1 on error
2472Errors:
2473 ENODEV: The device type is unknown or unsupported
2474 EEXIST: Device already created, and this type of device may not
2475 be instantiated multiple times
2476
2477 Other error conditions may be defined by individual device types or
2478 have their standard meanings.
2479
2480Creates an emulated device in the kernel. The file descriptor returned
2481in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
2482
2483If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
2484device type is supported (not necessarily whether it can be created
2485in the current vm).
2486
2487Individual devices should not define flags. Attributes should be used
2488for specifying any behavior that is not implied by the device type
2489number.
2490
2491struct kvm_create_device {
2492 __u32 type; /* in: KVM_DEV_TYPE_xxx */
2493 __u32 fd; /* out: device handle */
2494 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
2495};
2496
24974.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
2498
Shannon Zhaof577f6c2016-01-11 20:56:17 +08002499Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
2500 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
2501Type: device ioctl, vm ioctl, vcpu ioctl
Scott Wood852b6d52013-04-12 14:08:42 +00002502Parameters: struct kvm_device_attr
2503Returns: 0 on success, -1 on error
2504Errors:
2505 ENXIO: The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01002506 or hardware support is missing.
Scott Wood852b6d52013-04-12 14:08:42 +00002507 EPERM: The attribute cannot (currently) be accessed this way
2508 (e.g. read-only attribute, or attribute that only makes
2509 sense when the device is in a different state)
2510
2511 Other error conditions may be defined by individual device types.
2512
2513Gets/sets a specified piece of device configuration and/or state. The
2514semantics are device-specific. See individual device documentation in
2515the "devices" directory. As with ONE_REG, the size of the data
2516transferred is defined by the particular attribute.
2517
2518struct kvm_device_attr {
2519 __u32 flags; /* no flags currently defined */
2520 __u32 group; /* device-defined */
2521 __u64 attr; /* group-defined */
2522 __u64 addr; /* userspace address of attr data */
2523};
2524
25254.81 KVM_HAS_DEVICE_ATTR
2526
Shannon Zhaof577f6c2016-01-11 20:56:17 +08002527Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
2528 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
2529Type: device ioctl, vm ioctl, vcpu ioctl
Scott Wood852b6d52013-04-12 14:08:42 +00002530Parameters: struct kvm_device_attr
2531Returns: 0 on success, -1 on error
2532Errors:
2533 ENXIO: The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01002534 or hardware support is missing.
Scott Wood852b6d52013-04-12 14:08:42 +00002535
2536Tests whether a device supports a particular attribute. A successful
2537return indicates the attribute is implemented. It does not necessarily
2538indicate that the attribute can be read or written in the device's
2539current state. "addr" is ignored.
Alex Williamsonf36992e2012-06-29 09:56:16 -06002540
Alexey Kardashevskiyd8968f12013-06-19 11:42:07 +100025414.82 KVM_ARM_VCPU_INIT
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002542
2543Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +01002544Architectures: arm, arm64
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002545Type: vcpu ioctl
Anup Patelbeb11fc2013-12-12 21:42:24 +05302546Parameters: struct kvm_vcpu_init (in)
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002547Returns: 0 on success; -1 on error
2548Errors:
2549  EINVAL:    the target is unknown, or the combination of features is invalid.
2550  ENOENT:    a features bit specified is unknown.
2551
2552This tells KVM what type of CPU to present to the guest, and what
2553optional features it should have.  This will cause a reset of the cpu
2554registers to their initial values.  If this is not called, KVM_RUN will
2555return ENOEXEC for that vcpu.
2556
2557Note that because some registers reflect machine topology, all vcpus
2558should be created before this ioctl is invoked.
2559
Christoffer Dallf7fa034d2014-10-16 16:40:53 +02002560Userspace can call this function multiple times for a given vcpu, including
2561after the vcpu has been run. This will reset the vcpu to its initial
2562state. All calls to this function after the initial call must use the same
2563target and same set of feature flags, otherwise EINVAL will be returned.
2564
Marc Zyngieraa024c22013-01-20 18:28:13 -05002565Possible features:
2566 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
Christoffer Dall3ad8b3d2014-10-16 16:14:43 +02002567 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
2568 and execute guest code when KVM_RUN is called.
Marc Zyngier379e04c72013-04-02 17:46:31 +01002569 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
2570 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002571 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
2572 backward compatible with v0.2) for the CPU.
Anup Patel50bb0c92014-04-29 11:24:17 +05302573 Depends on KVM_CAP_ARM_PSCI_0_2.
Shannon Zhao808e7382016-01-11 22:46:15 +08002574 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
2575 Depends on KVM_CAP_ARM_PMU_V3.
Marc Zyngieraa024c22013-01-20 18:28:13 -05002576
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002577
Anup Patel740edfc2013-09-30 14:20:08 +053025784.83 KVM_ARM_PREFERRED_TARGET
2579
2580Capability: basic
2581Architectures: arm, arm64
2582Type: vm ioctl
2583Parameters: struct struct kvm_vcpu_init (out)
2584Returns: 0 on success; -1 on error
2585Errors:
Christoffer Dalla7265fb2013-10-15 17:43:00 -07002586 ENODEV: no preferred target available for the host
Anup Patel740edfc2013-09-30 14:20:08 +05302587
2588This queries KVM for preferred CPU target type which can be emulated
2589by KVM on underlying host.
2590
2591The ioctl returns struct kvm_vcpu_init instance containing information
2592about preferred CPU target type and recommended features for it. The
2593kvm_vcpu_init->features bitmap returned will have feature bits set if
2594the preferred target recommends setting these features, but this is
2595not mandatory.
2596
2597The information returned by this ioctl can be used to prepare an instance
2598of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
2599in VCPU matching underlying host.
2600
2601
26024.84 KVM_GET_REG_LIST
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002603
2604Capability: basic
James Hoganc2d2c212014-07-04 15:11:35 +01002605Architectures: arm, arm64, mips
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002606Type: vcpu ioctl
2607Parameters: struct kvm_reg_list (in/out)
2608Returns: 0 on success; -1 on error
2609Errors:
2610  E2BIG:     the reg index list is too big to fit in the array specified by
2611             the user (the number required will be written into n).
2612
2613struct kvm_reg_list {
2614 __u64 n; /* number of registers in reg[] */
2615 __u64 reg[0];
2616};
2617
2618This ioctl returns the guest registers that are supported for the
2619KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
2620
Christoffer Dallce01e4e2013-09-23 14:55:56 -07002621
26224.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
Christoffer Dall3401d5462013-01-23 13:18:04 -05002623
2624Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
Marc Zyngier379e04c72013-04-02 17:46:31 +01002625Architectures: arm, arm64
Christoffer Dall3401d5462013-01-23 13:18:04 -05002626Type: vm ioctl
2627Parameters: struct kvm_arm_device_address (in)
2628Returns: 0 on success, -1 on error
2629Errors:
2630 ENODEV: The device id is unknown
2631 ENXIO: Device not supported on current system
2632 EEXIST: Address already set
2633 E2BIG: Address outside guest physical address space
Christoffer Dall330690c2013-01-21 19:36:13 -05002634 EBUSY: Address overlaps with other device range
Christoffer Dall3401d5462013-01-23 13:18:04 -05002635
2636struct kvm_arm_device_addr {
2637 __u64 id;
2638 __u64 addr;
2639};
2640
2641Specify a device address in the guest's physical address space where guests
2642can access emulated or directly exposed devices, which the host kernel needs
2643to know about. The id field is an architecture specific identifier for a
2644specific device.
2645
Marc Zyngier379e04c72013-04-02 17:46:31 +01002646ARM/arm64 divides the id field into two parts, a device id and an
2647address type id specific to the individual device.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002648
2649  bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
2650 field: | 0x00000000 | device id | addr type id |
2651
Marc Zyngier379e04c72013-04-02 17:46:31 +01002652ARM/arm64 currently only require this when using the in-kernel GIC
2653support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
2654as the device id. When setting the base address for the guest's
2655mapping of the VGIC virtual CPU and distributor interface, the ioctl
2656must be called after calling KVM_CREATE_IRQCHIP, but before calling
2657KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
2658base addresses will return -EEXIST.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002659
Christoffer Dallce01e4e2013-09-23 14:55:56 -07002660Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
2661should be used instead.
2662
2663
Anup Patel740edfc2013-09-30 14:20:08 +053026644.86 KVM_PPC_RTAS_DEFINE_TOKEN
Michael Ellerman8e591cb2013-04-17 20:30:00 +00002665
2666Capability: KVM_CAP_PPC_RTAS
2667Architectures: ppc
2668Type: vm ioctl
2669Parameters: struct kvm_rtas_token_args
2670Returns: 0 on success, -1 on error
2671
2672Defines a token value for a RTAS (Run Time Abstraction Services)
2673service in order to allow it to be handled in the kernel. The
2674argument struct gives the name of the service, which must be the name
2675of a service that has a kernel-side implementation. If the token
2676value is non-zero, it will be associated with that service, and
2677subsequent RTAS calls by the guest specifying that token will be
2678handled by the kernel. If the token value is 0, then any token
2679associated with the service will be forgotten, and subsequent RTAS
2680calls by the guest for that service will be passed to userspace to be
2681handled.
2682
Alex Bennée4bd9d342014-09-09 17:27:18 +010026834.87 KVM_SET_GUEST_DEBUG
2684
2685Capability: KVM_CAP_SET_GUEST_DEBUG
Alex Bennée0e6f07f2015-07-07 17:29:55 +01002686Architectures: x86, s390, ppc, arm64
Alex Bennée4bd9d342014-09-09 17:27:18 +01002687Type: vcpu ioctl
2688Parameters: struct kvm_guest_debug (in)
2689Returns: 0 on success; -1 on error
2690
2691struct kvm_guest_debug {
2692 __u32 control;
2693 __u32 pad;
2694 struct kvm_guest_debug_arch arch;
2695};
2696
2697Set up the processor specific debug registers and configure vcpu for
2698handling guest debug events. There are two parts to the structure, the
2699first a control bitfield indicates the type of debug events to handle
2700when running. Common control bits are:
2701
2702 - KVM_GUESTDBG_ENABLE: guest debugging is enabled
2703 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
2704
2705The top 16 bits of the control field are architecture specific control
2706flags which can include the following:
2707
Alex Bennée4bd611c2015-07-07 17:29:57 +01002708 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
Alex Bennée834bf882015-07-07 17:30:02 +01002709 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390, arm64]
Alex Bennée4bd9d342014-09-09 17:27:18 +01002710 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
2711 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
2712 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
2713
2714For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
2715are enabled in memory so we need to ensure breakpoint exceptions are
2716correctly trapped and the KVM run loop exits at the breakpoint and not
2717running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
2718we need to ensure the guest vCPUs architecture specific registers are
2719updated to the correct (supplied) values.
2720
2721The second part of the structure is architecture specific and
2722typically contains a set of debug registers.
2723
Alex Bennée834bf882015-07-07 17:30:02 +01002724For arm64 the number of debug registers is implementation defined and
2725can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
2726KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
2727indicating the number of supported registers.
2728
Alex Bennée4bd9d342014-09-09 17:27:18 +01002729When debug events exit the main run loop with the reason
2730KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
2731structure containing architecture specific debug information.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002732
Alex Bennée209cf192014-09-09 17:27:19 +010027334.88 KVM_GET_EMULATED_CPUID
2734
2735Capability: KVM_CAP_EXT_EMUL_CPUID
2736Architectures: x86
2737Type: system ioctl
2738Parameters: struct kvm_cpuid2 (in/out)
2739Returns: 0 on success, -1 on error
2740
2741struct kvm_cpuid2 {
2742 __u32 nent;
2743 __u32 flags;
2744 struct kvm_cpuid_entry2 entries[0];
2745};
2746
2747The member 'flags' is used for passing flags from userspace.
2748
2749#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
2750#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
2751#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
2752
2753struct kvm_cpuid_entry2 {
2754 __u32 function;
2755 __u32 index;
2756 __u32 flags;
2757 __u32 eax;
2758 __u32 ebx;
2759 __u32 ecx;
2760 __u32 edx;
2761 __u32 padding[3];
2762};
2763
2764This ioctl returns x86 cpuid features which are emulated by
2765kvm.Userspace can use the information returned by this ioctl to query
2766which features are emulated by kvm instead of being present natively.
2767
2768Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
2769structure with the 'nent' field indicating the number of entries in
2770the variable-size array 'entries'. If the number of entries is too low
2771to describe the cpu capabilities, an error (E2BIG) is returned. If the
2772number is too high, the 'nent' field is adjusted and an error (ENOMEM)
2773is returned. If the number is just right, the 'nent' field is adjusted
2774to the number of valid entries in the 'entries' array, which is then
2775filled.
2776
2777The entries returned are the set CPUID bits of the respective features
2778which kvm emulates, as returned by the CPUID instruction, with unknown
2779or unsupported feature bits cleared.
2780
2781Features like x2apic, for example, may not be present in the host cpu
2782but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
2783emulated efficiently and thus not included here.
2784
2785The fields in each entry are defined as follows:
2786
2787 function: the eax value used to obtain the entry
2788 index: the ecx value used to obtain the entry (for entries that are
2789 affected by ecx)
2790 flags: an OR of zero or more of the following:
2791 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
2792 if the index field is valid
2793 KVM_CPUID_FLAG_STATEFUL_FUNC:
2794 if cpuid for this function returns different values for successive
2795 invocations; there will be several entries with the same function,
2796 all with this flag set
2797 KVM_CPUID_FLAG_STATE_READ_NEXT:
2798 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
2799 the first entry to be read by a cpu
2800 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
2801 this function/index combination
2802
Thomas Huth41408c282015-02-06 15:01:21 +010028034.89 KVM_S390_MEM_OP
2804
2805Capability: KVM_CAP_S390_MEM_OP
2806Architectures: s390
2807Type: vcpu ioctl
2808Parameters: struct kvm_s390_mem_op (in)
2809Returns: = 0 on success,
2810 < 0 on generic error (e.g. -EFAULT or -ENOMEM),
2811 > 0 if an exception occurred while walking the page tables
2812
Masanari Iida5d4f6f32015-10-04 00:46:21 +09002813Read or write data from/to the logical (virtual) memory of a VCPU.
Thomas Huth41408c282015-02-06 15:01:21 +01002814
2815Parameters are specified via the following structure:
2816
2817struct kvm_s390_mem_op {
2818 __u64 gaddr; /* the guest address */
2819 __u64 flags; /* flags */
2820 __u32 size; /* amount of bytes */
2821 __u32 op; /* type of operation */
2822 __u64 buf; /* buffer in userspace */
2823 __u8 ar; /* the access register number */
2824 __u8 reserved[31]; /* should be set to 0 */
2825};
2826
2827The type of operation is specified in the "op" field. It is either
2828KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or
2829KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The
2830KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check
2831whether the corresponding memory access would create an access exception
2832(without touching the data in the memory at the destination). In case an
2833access exception occurred while walking the MMU tables of the guest, the
2834ioctl returns a positive error number to indicate the type of exception.
2835This exception is also raised directly at the corresponding VCPU if the
2836flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field.
2837
2838The start address of the memory region has to be specified in the "gaddr"
2839field, and the length of the region in the "size" field. "buf" is the buffer
2840supplied by the userspace application where the read data should be written
2841to for KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written
2842is stored for a KVM_S390_MEMOP_LOGICAL_WRITE. "buf" is unused and can be NULL
2843when KVM_S390_MEMOP_F_CHECK_ONLY is specified. "ar" designates the access
2844register number to be used.
2845
2846The "reserved" field is meant for future extensions. It is not used by
2847KVM with the currently defined set of flags.
2848
Jason J. Herne30ee2a92014-09-23 09:23:01 -040028494.90 KVM_S390_GET_SKEYS
2850
2851Capability: KVM_CAP_S390_SKEYS
2852Architectures: s390
2853Type: vm ioctl
2854Parameters: struct kvm_s390_skeys
2855Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
2856 keys, negative value on error
2857
2858This ioctl is used to get guest storage key values on the s390
2859architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
2860
2861struct kvm_s390_skeys {
2862 __u64 start_gfn;
2863 __u64 count;
2864 __u64 skeydata_addr;
2865 __u32 flags;
2866 __u32 reserved[9];
2867};
2868
2869The start_gfn field is the number of the first guest frame whose storage keys
2870you want to get.
2871
2872The count field is the number of consecutive frames (starting from start_gfn)
2873whose storage keys to get. The count field must be at least 1 and the maximum
2874allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
2875will cause the ioctl to return -EINVAL.
2876
2877The skeydata_addr field is the address to a buffer large enough to hold count
2878bytes. This buffer will be filled with storage key data by the ioctl.
2879
28804.91 KVM_S390_SET_SKEYS
2881
2882Capability: KVM_CAP_S390_SKEYS
2883Architectures: s390
2884Type: vm ioctl
2885Parameters: struct kvm_s390_skeys
2886Returns: 0 on success, negative value on error
2887
2888This ioctl is used to set guest storage key values on the s390
2889architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
2890See section on KVM_S390_GET_SKEYS for struct definition.
2891
2892The start_gfn field is the number of the first guest frame whose storage keys
2893you want to set.
2894
2895The count field is the number of consecutive frames (starting from start_gfn)
2896whose storage keys to get. The count field must be at least 1 and the maximum
2897allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
2898will cause the ioctl to return -EINVAL.
2899
2900The skeydata_addr field is the address to a buffer containing count bytes of
2901storage keys. Each byte in the buffer will be set as the storage key for a
2902single frame starting at start_gfn for count frames.
2903
2904Note: If any architecturally invalid key value is found in the given data then
2905the ioctl will return -EINVAL.
2906
Jens Freimann47b43c52014-11-11 20:57:06 +010029074.92 KVM_S390_IRQ
2908
2909Capability: KVM_CAP_S390_INJECT_IRQ
2910Architectures: s390
2911Type: vcpu ioctl
2912Parameters: struct kvm_s390_irq (in)
2913Returns: 0 on success, -1 on error
2914Errors:
2915 EINVAL: interrupt type is invalid
2916 type is KVM_S390_SIGP_STOP and flag parameter is invalid value
2917 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
2918 than the maximum of VCPUs
2919 EBUSY: type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped
2920 type is KVM_S390_SIGP_STOP and a stop irq is already pending
2921 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
2922 is already pending
2923
2924Allows to inject an interrupt to the guest.
2925
2926Using struct kvm_s390_irq as a parameter allows
2927to inject additional payload which is not
2928possible via KVM_S390_INTERRUPT.
2929
2930Interrupt parameters are passed via kvm_s390_irq:
2931
2932struct kvm_s390_irq {
2933 __u64 type;
2934 union {
2935 struct kvm_s390_io_info io;
2936 struct kvm_s390_ext_info ext;
2937 struct kvm_s390_pgm_info pgm;
2938 struct kvm_s390_emerg_info emerg;
2939 struct kvm_s390_extcall_info extcall;
2940 struct kvm_s390_prefix_info prefix;
2941 struct kvm_s390_stop_info stop;
2942 struct kvm_s390_mchk_info mchk;
2943 char reserved[64];
2944 } u;
2945};
2946
2947type can be one of the following:
2948
2949KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
2950KVM_S390_PROGRAM_INT - program check; parameters in .pgm
2951KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
2952KVM_S390_RESTART - restart; no parameters
2953KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
2954KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
2955KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
2956KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
2957KVM_S390_MCHK - machine check interrupt; parameters in .mchk
2958
2959
2960Note that the vcpu ioctl is asynchronous to vcpu execution.
2961
Jens Freimann816c7662014-11-24 17:13:46 +010029624.94 KVM_S390_GET_IRQ_STATE
2963
2964Capability: KVM_CAP_S390_IRQ_STATE
2965Architectures: s390
2966Type: vcpu ioctl
2967Parameters: struct kvm_s390_irq_state (out)
2968Returns: >= number of bytes copied into buffer,
2969 -EINVAL if buffer size is 0,
2970 -ENOBUFS if buffer size is too small to fit all pending interrupts,
2971 -EFAULT if the buffer address was invalid
2972
2973This ioctl allows userspace to retrieve the complete state of all currently
2974pending interrupts in a single buffer. Use cases include migration
2975and introspection. The parameter structure contains the address of a
2976userspace buffer and its length:
2977
2978struct kvm_s390_irq_state {
2979 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01002980 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01002981 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01002982 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01002983};
2984
2985Userspace passes in the above struct and for each pending interrupt a
2986struct kvm_s390_irq is copied to the provided buffer.
2987
Christian Borntraegerbb64da92017-11-21 16:02:52 +01002988The structure contains a flags and a reserved field for future extensions. As
2989the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
2990reserved, these fields can not be used in the future without breaking
2991compatibility.
2992
Jens Freimann816c7662014-11-24 17:13:46 +01002993If -ENOBUFS is returned the buffer provided was too small and userspace
2994may retry with a bigger buffer.
2995
29964.95 KVM_S390_SET_IRQ_STATE
2997
2998Capability: KVM_CAP_S390_IRQ_STATE
2999Architectures: s390
3000Type: vcpu ioctl
3001Parameters: struct kvm_s390_irq_state (in)
3002Returns: 0 on success,
3003 -EFAULT if the buffer address was invalid,
3004 -EINVAL for an invalid buffer length (see below),
3005 -EBUSY if there were already interrupts pending,
3006 errors occurring when actually injecting the
3007 interrupt. See KVM_S390_IRQ.
3008
3009This ioctl allows userspace to set the complete state of all cpu-local
3010interrupts currently pending for the vcpu. It is intended for restoring
3011interrupt state after a migration. The input parameter is a userspace buffer
3012containing a struct kvm_s390_irq_state:
3013
3014struct kvm_s390_irq_state {
3015 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003016 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003017 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003018 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003019};
3020
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003021The restrictions for flags and reserved apply as well.
3022(see KVM_S390_GET_IRQ_STATE)
3023
Jens Freimann816c7662014-11-24 17:13:46 +01003024The userspace memory referenced by buf contains a struct kvm_s390_irq
3025for each interrupt to be injected into the guest.
3026If one of the interrupts could not be injected for some reason the
3027ioctl aborts.
3028
3029len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
3030and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
3031which is the maximum number of possibly pending cpu-local interrupts.
Jens Freimann47b43c52014-11-11 20:57:06 +01003032
Alexey Kardashevskiyed8e5a22016-01-19 16:12:28 +110030334.96 KVM_SMI
Paolo Bonzinif0778252015-04-01 15:06:40 +02003034
3035Capability: KVM_CAP_X86_SMM
3036Architectures: x86
3037Type: vcpu ioctl
3038Parameters: none
3039Returns: 0 on success, -1 on error
3040
3041Queues an SMI on the thread's vcpu.
3042
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +110030434.97 KVM_CAP_PPC_MULTITCE
3044
3045Capability: KVM_CAP_PPC_MULTITCE
3046Architectures: ppc
3047Type: vm
3048
3049This capability means the kernel is capable of handling hypercalls
3050H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
3051space. This significantly accelerates DMA operations for PPC KVM guests.
3052User space should expect that its handlers for these hypercalls
3053are not going to be called if user space previously registered LIOBN
3054in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
3055
3056In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
3057user space might have to advertise it for the guest. For example,
3058IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
3059present in the "ibm,hypertas-functions" device-tree property.
3060
3061The hypercalls mentioned above may or may not be processed successfully
3062in the kernel based fast path. If they can not be handled by the kernel,
3063they will get passed on to user space. So user space still has to have
3064an implementation for these despite the in kernel acceleration.
3065
3066This capability is always enabled.
3067
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +110030684.98 KVM_CREATE_SPAPR_TCE_64
3069
3070Capability: KVM_CAP_SPAPR_TCE_64
3071Architectures: powerpc
3072Type: vm ioctl
3073Parameters: struct kvm_create_spapr_tce_64 (in)
3074Returns: file descriptor for manipulating the created TCE table
3075
3076This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
3077windows, described in 4.62 KVM_CREATE_SPAPR_TCE
3078
3079This capability uses extended struct in ioctl interface:
3080
3081/* for KVM_CAP_SPAPR_TCE_64 */
3082struct kvm_create_spapr_tce_64 {
3083 __u64 liobn;
3084 __u32 page_shift;
3085 __u32 flags;
3086 __u64 offset; /* in pages */
3087 __u64 size; /* in pages */
3088};
3089
3090The aim of extension is to support an additional bigger DMA window with
3091a variable page size.
3092KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
3093a bus offset of the corresponding DMA window, @size and @offset are numbers
3094of IOMMU pages.
3095
3096@flags are not used at the moment.
3097
3098The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
3099
David Gibsonccc4df42016-12-20 16:48:57 +110031004.99 KVM_REINJECT_CONTROL
Radim Krčmář107d44a22016-03-02 22:56:53 +01003101
3102Capability: KVM_CAP_REINJECT_CONTROL
3103Architectures: x86
3104Type: vm ioctl
3105Parameters: struct kvm_reinject_control (in)
3106Returns: 0 on success,
3107 -EFAULT if struct kvm_reinject_control cannot be read,
3108 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
3109
3110i8254 (PIT) has two modes, reinject and !reinject. The default is reinject,
3111where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
3112vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its
3113interrupt whenever there isn't a pending interrupt from i8254.
3114!reinject mode injects an interrupt as soon as a tick arrives.
3115
3116struct kvm_reinject_control {
3117 __u8 pit_reinject;
3118 __u8 reserved[31];
3119};
3120
3121pit_reinject = 0 (!reinject mode) is recommended, unless running an old
3122operating system that uses the PIT for timing (e.g. Linux 2.4.x).
3123
David Gibsonccc4df42016-12-20 16:48:57 +110031244.100 KVM_PPC_CONFIGURE_V3_MMU
Paul Mackerrasc9270132017-01-30 21:21:41 +11003125
3126Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
3127Architectures: ppc
3128Type: vm ioctl
3129Parameters: struct kvm_ppc_mmuv3_cfg (in)
3130Returns: 0 on success,
3131 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
3132 -EINVAL if the configuration is invalid
3133
3134This ioctl controls whether the guest will use radix or HPT (hashed
3135page table) translation, and sets the pointer to the process table for
3136the guest.
3137
3138struct kvm_ppc_mmuv3_cfg {
3139 __u64 flags;
3140 __u64 process_table;
3141};
3142
3143There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
3144KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest
3145to use radix tree translation, and if clear, to use HPT translation.
3146KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
3147to be able to use the global TLB and SLB invalidation instructions;
3148if clear, the guest may not use these instructions.
3149
3150The process_table field specifies the address and size of the guest
3151process table, which is in the guest's space. This field is formatted
3152as the second doubleword of the partition table entry, as defined in
3153the Power ISA V3.00, Book III section 5.7.6.1.
3154
David Gibsonccc4df42016-12-20 16:48:57 +110031554.101 KVM_PPC_GET_RMMU_INFO
Paul Mackerrasc9270132017-01-30 21:21:41 +11003156
3157Capability: KVM_CAP_PPC_RADIX_MMU
3158Architectures: ppc
3159Type: vm ioctl
3160Parameters: struct kvm_ppc_rmmu_info (out)
3161Returns: 0 on success,
3162 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
3163 -EINVAL if no useful information can be returned
3164
3165This ioctl returns a structure containing two things: (a) a list
3166containing supported radix tree geometries, and (b) a list that maps
3167page sizes to put in the "AP" (actual page size) field for the tlbie
3168(TLB invalidate entry) instruction.
3169
3170struct kvm_ppc_rmmu_info {
3171 struct kvm_ppc_radix_geom {
3172 __u8 page_shift;
3173 __u8 level_bits[4];
3174 __u8 pad[3];
3175 } geometries[8];
3176 __u32 ap_encodings[8];
3177};
3178
3179The geometries[] field gives up to 8 supported geometries for the
3180radix page table, in terms of the log base 2 of the smallest page
3181size, and the number of bits indexed at each level of the tree, from
3182the PTE level up to the PGD level in that order. Any unused entries
3183will have 0 in the page_shift field.
3184
3185The ap_encodings gives the supported page sizes and their AP field
3186encodings, encoded with the AP value in the top 3 bits and the log
3187base 2 of the page size in the bottom 6 bits.
3188
David Gibsonef1ead02016-12-20 16:48:58 +110031894.102 KVM_PPC_RESIZE_HPT_PREPARE
3190
3191Capability: KVM_CAP_SPAPR_RESIZE_HPT
3192Architectures: powerpc
3193Type: vm ioctl
3194Parameters: struct kvm_ppc_resize_hpt (in)
3195Returns: 0 on successful completion,
3196 >0 if a new HPT is being prepared, the value is an estimated
3197 number of milliseconds until preparation is complete
3198 -EFAULT if struct kvm_reinject_control cannot be read,
3199 -EINVAL if the supplied shift or flags are invalid
3200 -ENOMEM if unable to allocate the new HPT
3201 -ENOSPC if there was a hash collision when moving existing
3202 HPT entries to the new HPT
3203 -EIO on other error conditions
3204
3205Used to implement the PAPR extension for runtime resizing of a guest's
3206Hashed Page Table (HPT). Specifically this starts, stops or monitors
3207the preparation of a new potential HPT for the guest, essentially
3208implementing the H_RESIZE_HPT_PREPARE hypercall.
3209
3210If called with shift > 0 when there is no pending HPT for the guest,
3211this begins preparation of a new pending HPT of size 2^(shift) bytes.
3212It then returns a positive integer with the estimated number of
3213milliseconds until preparation is complete.
3214
3215If called when there is a pending HPT whose size does not match that
3216requested in the parameters, discards the existing pending HPT and
3217creates a new one as above.
3218
3219If called when there is a pending HPT of the size requested, will:
3220 * If preparation of the pending HPT is already complete, return 0
3221 * If preparation of the pending HPT has failed, return an error
3222 code, then discard the pending HPT.
3223 * If preparation of the pending HPT is still in progress, return an
3224 estimated number of milliseconds until preparation is complete.
3225
3226If called with shift == 0, discards any currently pending HPT and
3227returns 0 (i.e. cancels any in-progress preparation).
3228
3229flags is reserved for future expansion, currently setting any bits in
3230flags will result in an -EINVAL.
3231
3232Normally this will be called repeatedly with the same parameters until
3233it returns <= 0. The first call will initiate preparation, subsequent
3234ones will monitor preparation until it completes or fails.
3235
3236struct kvm_ppc_resize_hpt {
3237 __u64 flags;
3238 __u32 shift;
3239 __u32 pad;
3240};
3241
32424.103 KVM_PPC_RESIZE_HPT_COMMIT
3243
3244Capability: KVM_CAP_SPAPR_RESIZE_HPT
3245Architectures: powerpc
3246Type: vm ioctl
3247Parameters: struct kvm_ppc_resize_hpt (in)
3248Returns: 0 on successful completion,
3249 -EFAULT if struct kvm_reinject_control cannot be read,
3250 -EINVAL if the supplied shift or flags are invalid
3251 -ENXIO is there is no pending HPT, or the pending HPT doesn't
3252 have the requested size
3253 -EBUSY if the pending HPT is not fully prepared
3254 -ENOSPC if there was a hash collision when moving existing
3255 HPT entries to the new HPT
3256 -EIO on other error conditions
3257
3258Used to implement the PAPR extension for runtime resizing of a guest's
3259Hashed Page Table (HPT). Specifically this requests that the guest be
3260transferred to working with the new HPT, essentially implementing the
3261H_RESIZE_HPT_COMMIT hypercall.
3262
3263This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
3264returned 0 with the same parameters. In other cases
3265KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
3266-EBUSY, though others may be possible if the preparation was started,
3267but failed).
3268
3269This will have undefined effects on the guest if it has not already
3270placed itself in a quiescent state where no vcpu will make MMU enabled
3271memory accesses.
3272
3273On succsful completion, the pending HPT will become the guest's active
3274HPT and the previous HPT will be discarded.
3275
3276On failure, the guest will still be operating on its previous HPT.
3277
3278struct kvm_ppc_resize_hpt {
3279 __u64 flags;
3280 __u32 shift;
3281 __u32 pad;
3282};
3283
Luiz Capitulino3aa53852017-03-13 09:08:20 -040032844.104 KVM_X86_GET_MCE_CAP_SUPPORTED
3285
3286Capability: KVM_CAP_MCE
3287Architectures: x86
3288Type: system ioctl
3289Parameters: u64 mce_cap (out)
3290Returns: 0 on success, -1 on error
3291
3292Returns supported MCE capabilities. The u64 mce_cap parameter
3293has the same format as the MSR_IA32_MCG_CAP register. Supported
3294capabilities will have the corresponding bits set.
3295
32964.105 KVM_X86_SETUP_MCE
3297
3298Capability: KVM_CAP_MCE
3299Architectures: x86
3300Type: vcpu ioctl
3301Parameters: u64 mcg_cap (in)
3302Returns: 0 on success,
3303 -EFAULT if u64 mcg_cap cannot be read,
3304 -EINVAL if the requested number of banks is invalid,
3305 -EINVAL if requested MCE capability is not supported.
3306
3307Initializes MCE support for use. The u64 mcg_cap parameter
3308has the same format as the MSR_IA32_MCG_CAP register and
3309specifies which capabilities should be enabled. The maximum
3310supported number of error-reporting banks can be retrieved when
3311checking for KVM_CAP_MCE. The supported capabilities can be
3312retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
3313
33144.106 KVM_X86_SET_MCE
3315
3316Capability: KVM_CAP_MCE
3317Architectures: x86
3318Type: vcpu ioctl
3319Parameters: struct kvm_x86_mce (in)
3320Returns: 0 on success,
3321 -EFAULT if struct kvm_x86_mce cannot be read,
3322 -EINVAL if the bank number is invalid,
3323 -EINVAL if VAL bit is not set in status field.
3324
3325Inject a machine check error (MCE) into the guest. The input
3326parameter is:
3327
3328struct kvm_x86_mce {
3329 __u64 status;
3330 __u64 addr;
3331 __u64 misc;
3332 __u64 mcg_status;
3333 __u8 bank;
3334 __u8 pad1[7];
3335 __u64 pad2[3];
3336};
3337
3338If the MCE being reported is an uncorrected error, KVM will
3339inject it as an MCE exception into the guest. If the guest
3340MCG_STATUS register reports that an MCE is in progress, KVM
3341causes an KVM_EXIT_SHUTDOWN vmexit.
3342
3343Otherwise, if the MCE is a corrected error, KVM will just
3344store it in the corresponding bank (provided this bank is
3345not holding a previously reported uncorrected error).
3346
Claudio Imbrenda4036e382016-08-04 17:58:47 +020033474.107 KVM_S390_GET_CMMA_BITS
3348
3349Capability: KVM_CAP_S390_CMMA_MIGRATION
3350Architectures: s390
3351Type: vm ioctl
3352Parameters: struct kvm_s390_cmma_log (in, out)
3353Returns: 0 on success, a negative value on error
3354
3355This ioctl is used to get the values of the CMMA bits on the s390
3356architecture. It is meant to be used in two scenarios:
3357- During live migration to save the CMMA values. Live migration needs
3358 to be enabled via the KVM_REQ_START_MIGRATION VM property.
3359- To non-destructively peek at the CMMA values, with the flag
3360 KVM_S390_CMMA_PEEK set.
3361
3362The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
3363values are written to a buffer whose location is indicated via the "values"
3364member in the kvm_s390_cmma_log struct. The values in the input struct are
3365also updated as needed.
3366Each CMMA value takes up one byte.
3367
3368struct kvm_s390_cmma_log {
3369 __u64 start_gfn;
3370 __u32 count;
3371 __u32 flags;
3372 union {
3373 __u64 remaining;
3374 __u64 mask;
3375 };
3376 __u64 values;
3377};
3378
3379start_gfn is the number of the first guest frame whose CMMA values are
3380to be retrieved,
3381
3382count is the length of the buffer in bytes,
3383
3384values points to the buffer where the result will be written to.
3385
3386If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
3387KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
3388other ioctls.
3389
3390The result is written in the buffer pointed to by the field values, and
3391the values of the input parameter are updated as follows.
3392
3393Depending on the flags, different actions are performed. The only
3394supported flag so far is KVM_S390_CMMA_PEEK.
3395
3396The default behaviour if KVM_S390_CMMA_PEEK is not set is:
3397start_gfn will indicate the first page frame whose CMMA bits were dirty.
3398It is not necessarily the same as the one passed as input, as clean pages
3399are skipped.
3400
3401count will indicate the number of bytes actually written in the buffer.
3402It can (and very often will) be smaller than the input value, since the
3403buffer is only filled until 16 bytes of clean values are found (which
3404are then not copied in the buffer). Since a CMMA migration block needs
3405the base address and the length, for a total of 16 bytes, we will send
3406back some clean data if there is some dirty data afterwards, as long as
3407the size of the clean data does not exceed the size of the header. This
3408allows to minimize the amount of data to be saved or transferred over
3409the network at the expense of more roundtrips to userspace. The next
3410invocation of the ioctl will skip over all the clean values, saving
3411potentially more than just the 16 bytes we found.
3412
3413If KVM_S390_CMMA_PEEK is set:
3414the existing storage attributes are read even when not in migration
3415mode, and no other action is performed;
3416
3417the output start_gfn will be equal to the input start_gfn,
3418
3419the output count will be equal to the input count, except if the end of
3420memory has been reached.
3421
3422In both cases:
3423the field "remaining" will indicate the total number of dirty CMMA values
3424still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
3425not enabled.
3426
3427mask is unused.
3428
3429values points to the userspace buffer where the result will be stored.
3430
3431This ioctl can fail with -ENOMEM if not enough memory can be allocated to
3432complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
3433KVM_S390_CMMA_PEEK is not set but migration mode was not enabled, with
3434-EFAULT if the userspace address is invalid or if no page table is
3435present for the addresses (e.g. when using hugepages).
3436
34374.108 KVM_S390_SET_CMMA_BITS
3438
3439Capability: KVM_CAP_S390_CMMA_MIGRATION
3440Architectures: s390
3441Type: vm ioctl
3442Parameters: struct kvm_s390_cmma_log (in)
3443Returns: 0 on success, a negative value on error
3444
3445This ioctl is used to set the values of the CMMA bits on the s390
3446architecture. It is meant to be used during live migration to restore
3447the CMMA values, but there are no restrictions on its use.
3448The ioctl takes parameters via the kvm_s390_cmma_values struct.
3449Each CMMA value takes up one byte.
3450
3451struct kvm_s390_cmma_log {
3452 __u64 start_gfn;
3453 __u32 count;
3454 __u32 flags;
3455 union {
3456 __u64 remaining;
3457 __u64 mask;
3458 };
3459 __u64 values;
3460};
3461
3462start_gfn indicates the starting guest frame number,
3463
3464count indicates how many values are to be considered in the buffer,
3465
3466flags is not used and must be 0.
3467
3468mask indicates which PGSTE bits are to be considered.
3469
3470remaining is not used.
3471
3472values points to the buffer in userspace where to store the values.
3473
3474This ioctl can fail with -ENOMEM if not enough memory can be allocated to
3475complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
3476the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
3477if the flags field was not 0, with -EFAULT if the userspace address is
3478invalid, if invalid pages are written to (e.g. after the end of memory)
3479or if no page table is present for the addresses (e.g. when using
3480hugepages).
3481
Radim Krčmář7bf14c22018-02-01 15:04:17 +010034824.109 KVM_PPC_GET_CPU_CHAR
Paul Mackerras3214d012018-01-15 16:06:47 +11003483
3484Capability: KVM_CAP_PPC_GET_CPU_CHAR
3485Architectures: powerpc
3486Type: vm ioctl
3487Parameters: struct kvm_ppc_cpu_char (out)
3488Returns: 0 on successful completion
3489 -EFAULT if struct kvm_ppc_cpu_char cannot be written
3490
3491This ioctl gives userspace information about certain characteristics
3492of the CPU relating to speculative execution of instructions and
3493possible information leakage resulting from speculative execution (see
3494CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is
3495returned in struct kvm_ppc_cpu_char, which looks like this:
3496
3497struct kvm_ppc_cpu_char {
3498 __u64 character; /* characteristics of the CPU */
3499 __u64 behaviour; /* recommended software behaviour */
3500 __u64 character_mask; /* valid bits in character */
3501 __u64 behaviour_mask; /* valid bits in behaviour */
3502};
3503
3504For extensibility, the character_mask and behaviour_mask fields
3505indicate which bits of character and behaviour have been filled in by
3506the kernel. If the set of defined bits is extended in future then
3507userspace will be able to tell whether it is running on a kernel that
3508knows about the new bits.
3509
3510The character field describes attributes of the CPU which can help
3511with preventing inadvertent information disclosure - specifically,
3512whether there is an instruction to flash-invalidate the L1 data cache
3513(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
3514to a mode where entries can only be used by the thread that created
3515them, whether the bcctr[l] instruction prevents speculation, and
3516whether a speculation barrier instruction (ori 31,31,0) is provided.
3517
3518The behaviour field describes actions that software should take to
3519prevent inadvertent information disclosure, and thus describes which
3520vulnerabilities the hardware is subject to; specifically whether the
3521L1 data cache should be flushed when returning to user mode from the
3522kernel, and whether a speculation barrier should be placed between an
3523array bounds check and the array access.
3524
3525These fields use the same bit definitions as the new
3526H_GET_CPU_CHARACTERISTICS hypercall.
3527
Radim Krčmář7bf14c22018-02-01 15:04:17 +010035284.110 KVM_MEMORY_ENCRYPT_OP
Brijesh Singh5acc5c02017-12-04 10:57:26 -06003529
3530Capability: basic
3531Architectures: x86
3532Type: system
3533Parameters: an opaque platform specific structure (in/out)
3534Returns: 0 on success; -1 on error
3535
3536If the platform supports creating encrypted VMs then this ioctl can be used
3537for issuing platform-specific memory encryption commands to manage those
3538encrypted VMs.
3539
3540Currently, this ioctl is used for issuing Secure Encrypted Virtualization
3541(SEV) commands on AMD Processors. The SEV commands are defined in
Andrew Jones21e94ac2018-03-26 14:38:02 +02003542Documentation/virtual/kvm/amd-memory-encryption.rst.
Brijesh Singh5acc5c02017-12-04 10:57:26 -06003543
Radim Krčmář7bf14c22018-02-01 15:04:17 +010035444.111 KVM_MEMORY_ENCRYPT_REG_REGION
Brijesh Singh69eaede2017-12-04 10:57:26 -06003545
3546Capability: basic
3547Architectures: x86
3548Type: system
3549Parameters: struct kvm_enc_region (in)
3550Returns: 0 on success; -1 on error
3551
3552This ioctl can be used to register a guest memory region which may
3553contain encrypted data (e.g. guest RAM, SMRAM etc).
3554
3555It is used in the SEV-enabled guest. When encryption is enabled, a guest
3556memory region may contain encrypted data. The SEV memory encryption
3557engine uses a tweak such that two identical plaintext pages, each at
3558different locations will have differing ciphertexts. So swapping or
3559moving ciphertext of those pages will not result in plaintext being
3560swapped. So relocating (or migrating) physical backing pages for the SEV
3561guest will require some additional steps.
3562
3563Note: The current SEV key management spec does not provide commands to
3564swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
3565memory region registered with the ioctl.
3566
Radim Krčmář7bf14c22018-02-01 15:04:17 +010035674.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
Brijesh Singh69eaede2017-12-04 10:57:26 -06003568
3569Capability: basic
3570Architectures: x86
3571Type: system
3572Parameters: struct kvm_enc_region (in)
3573Returns: 0 on success; -1 on error
3574
3575This ioctl can be used to unregister the guest memory region registered
3576with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
3577
Roman Kaganfaeb7832018-02-01 16:48:32 +030035784.113 KVM_HYPERV_EVENTFD
3579
3580Capability: KVM_CAP_HYPERV_EVENTFD
3581Architectures: x86
3582Type: vm ioctl
3583Parameters: struct kvm_hyperv_eventfd (in)
3584
3585This ioctl (un)registers an eventfd to receive notifications from the guest on
3586the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
3587causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
3588(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
3589
3590struct kvm_hyperv_eventfd {
3591 __u32 conn_id;
3592 __s32 fd;
3593 __u32 flags;
3594 __u32 padding[3];
3595};
3596
3597The conn_id field should fit within 24 bits:
3598
3599#define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
3600
3601The acceptable values for the flags field are:
3602
3603#define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
3604
3605Returns: 0 on success,
3606 -EINVAL if conn_id or flags is outside the allowed range
3607 -ENOENT on deassign if the conn_id isn't registered
3608 -EEXIST on assign if the conn_id is already registered
3609
Radim Krčmář7bf14c22018-02-01 15:04:17 +01003610
Avi Kivity9c1b96e2009-06-09 12:37:58 +030036115. The kvm_run structure
Jan Kiszka414fa982012-04-24 16:40:15 +02003612------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003613
3614Application code obtains a pointer to the kvm_run structure by
3615mmap()ing a vcpu fd. From that point, application code can control
3616execution by changing fields in kvm_run prior to calling the KVM_RUN
3617ioctl, and obtain information about the reason KVM_RUN returned by
3618looking up structure members.
3619
3620struct kvm_run {
3621 /* in */
3622 __u8 request_interrupt_window;
3623
3624Request that KVM_RUN return when it becomes possible to inject external
3625interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
3626
Paolo Bonzini460df4c2017-02-08 11:50:15 +01003627 __u8 immediate_exit;
3628
3629This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
3630exits immediately, returning -EINTR. In the common scenario where a
3631signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
3632to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
3633Rather than blocking the signal outside KVM_RUN, userspace can set up
3634a signal handler that sets run->immediate_exit to a non-zero value.
3635
3636This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
3637
3638 __u8 padding1[6];
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003639
3640 /* out */
3641 __u32 exit_reason;
3642
3643When KVM_RUN has returned successfully (return value 0), this informs
3644application code why KVM_RUN has returned. Allowable values for this
3645field are detailed below.
3646
3647 __u8 ready_for_interrupt_injection;
3648
3649If request_interrupt_window has been specified, this field indicates
3650an interrupt can be injected now with KVM_INTERRUPT.
3651
3652 __u8 if_flag;
3653
3654The value of the current interrupt flag. Only valid if in-kernel
3655local APIC is not used.
3656
Paolo Bonzinif0778252015-04-01 15:06:40 +02003657 __u16 flags;
3658
3659More architecture-specific flags detailing state of the VCPU that may
3660affect the device's behavior. The only currently defined flag is
3661KVM_RUN_X86_SMM, which is valid on x86 machines and is set if the
3662VCPU is in system management mode.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003663
3664 /* in (pre_kvm_run), out (post_kvm_run) */
3665 __u64 cr8;
3666
3667The value of the cr8 register. Only valid if in-kernel local APIC is
3668not used. Both input and output.
3669
3670 __u64 apic_base;
3671
3672The value of the APIC BASE msr. Only valid if in-kernel local
3673APIC is not used. Both input and output.
3674
3675 union {
3676 /* KVM_EXIT_UNKNOWN */
3677 struct {
3678 __u64 hardware_exit_reason;
3679 } hw;
3680
3681If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
3682reasons. Further architecture-specific information is available in
3683hardware_exit_reason.
3684
3685 /* KVM_EXIT_FAIL_ENTRY */
3686 struct {
3687 __u64 hardware_entry_failure_reason;
3688 } fail_entry;
3689
3690If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
3691to unknown reasons. Further architecture-specific information is
3692available in hardware_entry_failure_reason.
3693
3694 /* KVM_EXIT_EXCEPTION */
3695 struct {
3696 __u32 exception;
3697 __u32 error_code;
3698 } ex;
3699
3700Unused.
3701
3702 /* KVM_EXIT_IO */
3703 struct {
3704#define KVM_EXIT_IO_IN 0
3705#define KVM_EXIT_IO_OUT 1
3706 __u8 direction;
3707 __u8 size; /* bytes */
3708 __u16 port;
3709 __u32 count;
3710 __u64 data_offset; /* relative to kvm_run start */
3711 } io;
3712
Wu Fengguang2044892d2009-12-24 09:04:16 +08003713If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003714executed a port I/O instruction which could not be satisfied by kvm.
3715data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
3716where kvm expects application code to place the data for the next
Wu Fengguang2044892d2009-12-24 09:04:16 +08003717KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003718
Alex Bennée8ab30c12015-07-07 17:29:53 +01003719 /* KVM_EXIT_DEBUG */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003720 struct {
3721 struct kvm_debug_exit_arch arch;
3722 } debug;
3723
Alex Bennée8ab30c12015-07-07 17:29:53 +01003724If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
3725for which architecture specific information is returned.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003726
3727 /* KVM_EXIT_MMIO */
3728 struct {
3729 __u64 phys_addr;
3730 __u8 data[8];
3731 __u32 len;
3732 __u8 is_write;
3733 } mmio;
3734
Wu Fengguang2044892d2009-12-24 09:04:16 +08003735If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003736executed a memory-mapped I/O instruction which could not be satisfied
3737by kvm. The 'data' member contains the written data if 'is_write' is
3738true, and should be filled by application code otherwise.
3739
Christoffer Dall6acdb162014-01-28 08:28:42 -08003740The 'data' member contains, in its first 'len' bytes, the value as it would
3741appear if the VCPU performed a load or store of the appropriate width directly
3742to the byte array.
3743
Paolo Bonzinicc568ea2014-08-05 09:55:22 +02003744NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR and
Alexander Grafce91ddc2014-07-28 19:29:13 +02003745 KVM_EXIT_EPR the corresponding
Alexander Grafad0a0482010-03-24 21:48:30 +01003746operations are complete (and guest state is consistent) only after userspace
3747has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02003748incomplete operations and then check for pending signals. Userspace
3749can re-enter the guest with an unmasked signal pending to complete
3750pending operations.
3751
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003752 /* KVM_EXIT_HYPERCALL */
3753 struct {
3754 __u64 nr;
3755 __u64 args[6];
3756 __u64 ret;
3757 __u32 longmode;
3758 __u32 pad;
3759 } hypercall;
3760
Avi Kivity647dc492010-04-01 14:39:21 +03003761Unused. This was once used for 'hypercall to userspace'. To implement
3762such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
3763Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003764
3765 /* KVM_EXIT_TPR_ACCESS */
3766 struct {
3767 __u64 rip;
3768 __u32 is_write;
3769 __u32 pad;
3770 } tpr_access;
3771
3772To be documented (KVM_TPR_ACCESS_REPORTING).
3773
3774 /* KVM_EXIT_S390_SIEIC */
3775 struct {
3776 __u8 icptcode;
3777 __u64 mask; /* psw upper half */
3778 __u64 addr; /* psw lower half */
3779 __u16 ipa;
3780 __u32 ipb;
3781 } s390_sieic;
3782
3783s390 specific.
3784
3785 /* KVM_EXIT_S390_RESET */
3786#define KVM_S390_RESET_POR 1
3787#define KVM_S390_RESET_CLEAR 2
3788#define KVM_S390_RESET_SUBSYSTEM 4
3789#define KVM_S390_RESET_CPU_INIT 8
3790#define KVM_S390_RESET_IPL 16
3791 __u64 s390_reset_flags;
3792
3793s390 specific.
3794
Carsten Ottee168bf82012-01-04 10:25:22 +01003795 /* KVM_EXIT_S390_UCONTROL */
3796 struct {
3797 __u64 trans_exc_code;
3798 __u32 pgm_code;
3799 } s390_ucontrol;
3800
3801s390 specific. A page fault has occurred for a user controlled virtual
3802machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
3803resolved by the kernel.
3804The program code and the translation exception code that were placed
3805in the cpu's lowcore are presented here as defined by the z Architecture
3806Principles of Operation Book in the Chapter for Dynamic Address Translation
3807(DAT)
3808
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003809 /* KVM_EXIT_DCR */
3810 struct {
3811 __u32 dcrn;
3812 __u32 data;
3813 __u8 is_write;
3814 } dcr;
3815
Alexander Grafce91ddc2014-07-28 19:29:13 +02003816Deprecated - was used for 440 KVM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003817
Alexander Grafad0a0482010-03-24 21:48:30 +01003818 /* KVM_EXIT_OSI */
3819 struct {
3820 __u64 gprs[32];
3821 } osi;
3822
3823MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
3824hypercalls and exit with this exit struct that contains all the guest gprs.
3825
3826If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
3827Userspace can now handle the hypercall and when it's done modify the gprs as
3828necessary. Upon guest entry all guest GPRs will then be replaced by the values
3829in this struct.
3830
Paul Mackerrasde56a942011-06-29 00:21:34 +00003831 /* KVM_EXIT_PAPR_HCALL */
3832 struct {
3833 __u64 nr;
3834 __u64 ret;
3835 __u64 args[9];
3836 } papr_hcall;
3837
3838This is used on 64-bit PowerPC when emulating a pSeries partition,
3839e.g. with the 'pseries' machine type in qemu. It occurs when the
3840guest does a hypercall using the 'sc 1' instruction. The 'nr' field
3841contains the hypercall number (from the guest R3), and 'args' contains
3842the arguments (from the guest R4 - R12). Userspace should put the
3843return code in 'ret' and any extra returned values in args[].
3844The possible hypercalls are defined in the Power Architecture Platform
3845Requirements (PAPR) document available from www.power.org (free
3846developer registration required to access it).
3847
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01003848 /* KVM_EXIT_S390_TSCH */
3849 struct {
3850 __u16 subchannel_id;
3851 __u16 subchannel_nr;
3852 __u32 io_int_parm;
3853 __u32 io_int_word;
3854 __u32 ipb;
3855 __u8 dequeued;
3856 } s390_tsch;
3857
3858s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
3859and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
3860interrupt for the target subchannel has been dequeued and subchannel_id,
3861subchannel_nr, io_int_parm and io_int_word contain the parameters for that
3862interrupt. ipb is needed for instruction parameter decoding.
3863
Alexander Graf1c810632013-01-04 18:12:48 +01003864 /* KVM_EXIT_EPR */
3865 struct {
3866 __u32 epr;
3867 } epr;
3868
3869On FSL BookE PowerPC chips, the interrupt controller has a fast patch
3870interrupt acknowledge path to the core. When the core successfully
3871delivers an interrupt, it automatically populates the EPR register with
3872the interrupt vector number and acknowledges the interrupt inside
3873the interrupt controller.
3874
3875In case the interrupt controller lives in user space, we need to do
3876the interrupt acknowledge cycle through it to fetch the next to be
3877delivered interrupt vector using this exit.
3878
3879It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
3880external interrupt has just been delivered into the guest. User space
3881should put the acknowledged interrupt vector into the 'epr' field.
3882
Anup Patel8ad6b632014-04-29 11:24:19 +05303883 /* KVM_EXIT_SYSTEM_EVENT */
3884 struct {
3885#define KVM_SYSTEM_EVENT_SHUTDOWN 1
3886#define KVM_SYSTEM_EVENT_RESET 2
Andrey Smetanin2ce79182015-07-03 15:01:41 +03003887#define KVM_SYSTEM_EVENT_CRASH 3
Anup Patel8ad6b632014-04-29 11:24:19 +05303888 __u32 type;
3889 __u64 flags;
3890 } system_event;
3891
3892If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
3893a system-level event using some architecture specific mechanism (hypercall
3894or some special instruction). In case of ARM/ARM64, this is triggered using
3895HVC instruction based PSCI call from the vcpu. The 'type' field describes
3896the system-level event type. The 'flags' field describes architecture
3897specific flags for the system-level event.
3898
Christoffer Dallcf5d31882014-10-16 17:00:18 +02003899Valid values for 'type' are:
3900 KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
3901 VM. Userspace is not obliged to honour this, and if it does honour
3902 this does not need to destroy the VM synchronously (ie it may call
3903 KVM_RUN again before shutdown finally occurs).
3904 KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
3905 As with SHUTDOWN, userspace can choose to ignore the request, or
3906 to schedule the reset to occur in the future and may call KVM_RUN again.
Andrey Smetanin2ce79182015-07-03 15:01:41 +03003907 KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
3908 has requested a crash condition maintenance. Userspace can choose
3909 to ignore the request, or to gather VM memory core dump and/or
3910 reset/shutdown of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02003911
Steve Rutherford7543a632015-07-29 23:21:41 -07003912 /* KVM_EXIT_IOAPIC_EOI */
3913 struct {
3914 __u8 vector;
3915 } eoi;
3916
3917Indicates that the VCPU's in-kernel local APIC received an EOI for a
3918level-triggered IOAPIC interrupt. This exit only triggers when the
3919IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
3920the userspace IOAPIC should process the EOI and retrigger the interrupt if
3921it is still asserted. Vector is the LAPIC interrupt vector for which the
3922EOI was received.
3923
Andrey Smetanindb3975712015-11-10 15:36:35 +03003924 struct kvm_hyperv_exit {
3925#define KVM_EXIT_HYPERV_SYNIC 1
Andrey Smetanin83326e42016-02-11 16:45:01 +03003926#define KVM_EXIT_HYPERV_HCALL 2
Andrey Smetanindb3975712015-11-10 15:36:35 +03003927 __u32 type;
3928 union {
3929 struct {
3930 __u32 msr;
3931 __u64 control;
3932 __u64 evt_page;
3933 __u64 msg_page;
3934 } synic;
Andrey Smetanin83326e42016-02-11 16:45:01 +03003935 struct {
3936 __u64 input;
3937 __u64 result;
3938 __u64 params[2];
3939 } hcall;
Andrey Smetanindb3975712015-11-10 15:36:35 +03003940 } u;
3941 };
3942 /* KVM_EXIT_HYPERV */
3943 struct kvm_hyperv_exit hyperv;
3944Indicates that the VCPU exits into userspace to process some tasks
3945related to Hyper-V emulation.
3946Valid values for 'type' are:
3947 KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
3948Hyper-V SynIC state change. Notification is used to remap SynIC
3949event/message pages and to enable/disable SynIC messages/events processing
3950in userspace.
3951
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003952 /* Fix the size of the union. */
3953 char padding[256];
3954 };
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01003955
3956 /*
3957 * shared registers between kvm and userspace.
3958 * kvm_valid_regs specifies the register classes set by the host
3959 * kvm_dirty_regs specified the register classes dirtied by userspace
3960 * struct kvm_sync_regs is architecture specific, as well as the
3961 * bits for kvm_valid_regs and kvm_dirty_regs
3962 */
3963 __u64 kvm_valid_regs;
3964 __u64 kvm_dirty_regs;
3965 union {
3966 struct kvm_sync_regs regs;
Ken Hofsass7b7e3952018-01-31 16:03:35 -08003967 char padding[SYNC_REGS_SIZE_BYTES];
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01003968 } s;
3969
3970If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
3971certain guest registers without having to call SET/GET_*REGS. Thus we can
3972avoid some system call overhead if userspace has to handle the exit.
3973Userspace can query the validity of the structure by checking
3974kvm_valid_regs for specific bits. These bits are architecture specific
3975and usually define the validity of a groups of registers. (e.g. one bit
3976 for general purpose registers)
3977
David Hildenbrandd8482c02014-07-29 08:19:26 +02003978Please note that the kernel is allowed to use the kvm_run structure as the
3979primary storage for certain register types. Therefore, the kernel may use the
3980values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
3981
Avi Kivity9c1b96e2009-06-09 12:37:58 +03003982};
Alexander Graf821246a2011-08-31 10:58:55 +02003983
Jan Kiszka414fa982012-04-24 16:40:15 +02003984
Borislav Petkov9c15bb12013-09-22 16:44:50 +02003985
Paul Mackerras699a0ea2014-06-02 11:02:59 +100039866. Capabilities that can be enabled on vCPUs
3987--------------------------------------------
Alexander Graf821246a2011-08-31 10:58:55 +02003988
Cornelia Huck0907c852014-06-27 09:29:26 +02003989There are certain capabilities that change the behavior of the virtual CPU or
3990the virtual machine when enabled. To enable them, please see section 4.37.
3991Below you can find a list of capabilities and what their effect on the vCPU or
3992the virtual machine is when enabling them.
Alexander Graf821246a2011-08-31 10:58:55 +02003993
3994The following information is provided along with the description:
3995
3996 Architectures: which instruction set architectures provide this ioctl.
3997 x86 includes both i386 and x86_64.
3998
Cornelia Huck0907c852014-06-27 09:29:26 +02003999 Target: whether this is a per-vcpu or per-vm capability.
4000
Alexander Graf821246a2011-08-31 10:58:55 +02004001 Parameters: what parameters are accepted by the capability.
4002
4003 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
4004 are not detailed, but errors with specific meanings are.
4005
Jan Kiszka414fa982012-04-24 16:40:15 +02004006
Alexander Graf821246a2011-08-31 10:58:55 +020040076.1 KVM_CAP_PPC_OSI
4008
4009Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004010Target: vcpu
Alexander Graf821246a2011-08-31 10:58:55 +02004011Parameters: none
4012Returns: 0 on success; -1 on error
4013
4014This capability enables interception of OSI hypercalls that otherwise would
4015be treated as normal system calls to be injected into the guest. OSI hypercalls
4016were invented by Mac-on-Linux to have a standardized communication mechanism
4017between the guest and the host.
4018
4019When this capability is enabled, KVM_EXIT_OSI can occur.
4020
Jan Kiszka414fa982012-04-24 16:40:15 +02004021
Alexander Graf821246a2011-08-31 10:58:55 +020040226.2 KVM_CAP_PPC_PAPR
4023
4024Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004025Target: vcpu
Alexander Graf821246a2011-08-31 10:58:55 +02004026Parameters: none
4027Returns: 0 on success; -1 on error
4028
4029This capability enables interception of PAPR hypercalls. PAPR hypercalls are
4030done using the hypercall instruction "sc 1".
4031
4032It also sets the guest privilege level to "supervisor" mode. Usually the guest
4033runs in "hypervisor" privilege mode with a few missing features.
4034
4035In addition to the above, it changes the semantics of SDR1. In this mode, the
4036HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
4037HTAB invisible to the guest.
4038
4039When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
Scott Wooddc83b8b2011-08-18 15:25:21 -05004040
Jan Kiszka414fa982012-04-24 16:40:15 +02004041
Scott Wooddc83b8b2011-08-18 15:25:21 -050040426.3 KVM_CAP_SW_TLB
4043
4044Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004045Target: vcpu
Scott Wooddc83b8b2011-08-18 15:25:21 -05004046Parameters: args[0] is the address of a struct kvm_config_tlb
4047Returns: 0 on success; -1 on error
4048
4049struct kvm_config_tlb {
4050 __u64 params;
4051 __u64 array;
4052 __u32 mmu_type;
4053 __u32 array_len;
4054};
4055
4056Configures the virtual CPU's TLB array, establishing a shared memory area
4057between userspace and KVM. The "params" and "array" fields are userspace
4058addresses of mmu-type-specific data structures. The "array_len" field is an
4059safety mechanism, and should be set to the size in bytes of the memory that
4060userspace has reserved for the array. It must be at least the size dictated
4061by "mmu_type" and "params".
4062
4063While KVM_RUN is active, the shared region is under control of KVM. Its
4064contents are undefined, and any modification by userspace results in
4065boundedly undefined behavior.
4066
4067On return from KVM_RUN, the shared region will reflect the current state of
4068the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
4069to tell KVM which entries have been changed, prior to calling KVM_RUN again
4070on this vcpu.
4071
4072For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
4073 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
4074 - The "array" field points to an array of type "struct
4075 kvm_book3e_206_tlb_entry".
4076 - The array consists of all entries in the first TLB, followed by all
4077 entries in the second TLB.
4078 - Within a TLB, entries are ordered first by increasing set number. Within a
4079 set, entries are ordered by way (increasing ESEL).
4080 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
4081 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
4082 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
4083 hardware ignores this value for TLB0.
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004084
40856.4 KVM_CAP_S390_CSS_SUPPORT
4086
4087Architectures: s390
Cornelia Huck0907c852014-06-27 09:29:26 +02004088Target: vcpu
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004089Parameters: none
4090Returns: 0 on success; -1 on error
4091
4092This capability enables support for handling of channel I/O instructions.
4093
4094TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
4095handled in-kernel, while the other I/O instructions are passed to userspace.
4096
4097When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
4098SUBCHANNEL intercepts.
Alexander Graf1c810632013-01-04 18:12:48 +01004099
Cornelia Huck0907c852014-06-27 09:29:26 +02004100Note that even though this capability is enabled per-vcpu, the complete
4101virtual machine is affected.
4102
Alexander Graf1c810632013-01-04 18:12:48 +010041036.5 KVM_CAP_PPC_EPR
4104
4105Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004106Target: vcpu
Alexander Graf1c810632013-01-04 18:12:48 +01004107Parameters: args[0] defines whether the proxy facility is active
4108Returns: 0 on success; -1 on error
4109
4110This capability enables or disables the delivery of interrupts through the
4111external proxy facility.
4112
4113When enabled (args[0] != 0), every time the guest gets an external interrupt
4114delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
4115to receive the topmost interrupt vector.
4116
4117When disabled (args[0] == 0), behavior is as if this facility is unsupported.
4118
4119When this capability is enabled, KVM_EXIT_EPR can occur.
Scott Woodeb1e4f42013-04-12 14:08:47 +00004120
41216.6 KVM_CAP_IRQ_MPIC
4122
4123Architectures: ppc
4124Parameters: args[0] is the MPIC device fd
4125 args[1] is the MPIC CPU number for this vcpu
4126
4127This capability connects the vcpu to an in-kernel MPIC device.
Paul Mackerras5975a2e2013-04-27 00:28:37 +00004128
41296.7 KVM_CAP_IRQ_XICS
4130
4131Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004132Target: vcpu
Paul Mackerras5975a2e2013-04-27 00:28:37 +00004133Parameters: args[0] is the XICS device fd
4134 args[1] is the XICS CPU number (server ID) for this vcpu
4135
4136This capability connects the vcpu to an in-kernel XICS device.
Cornelia Huck8a366a42014-06-27 11:06:25 +02004137
41386.8 KVM_CAP_S390_IRQCHIP
4139
4140Architectures: s390
4141Target: vm
4142Parameters: none
4143
4144This capability enables the in-kernel irqchip for s390. Please refer to
4145"4.24 KVM_CREATE_IRQCHIP" for details.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10004146
James Hogan5fafd8742014-12-08 23:07:56 +000041476.9 KVM_CAP_MIPS_FPU
4148
4149Architectures: mips
4150Target: vcpu
4151Parameters: args[0] is reserved for future use (should be 0).
4152
4153This capability allows the use of the host Floating Point Unit by the guest. It
4154allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
4155done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed
4156(depending on the current guest FPU register mode), and the Status.FR,
4157Config5.FRE bits are accessible via the KVM API and also from the guest,
4158depending on them being supported by the FPU.
4159
James Hogand952bd02014-12-08 23:07:56 +000041606.10 KVM_CAP_MIPS_MSA
4161
4162Architectures: mips
4163Target: vcpu
4164Parameters: args[0] is reserved for future use (should be 0).
4165
4166This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
4167It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
4168Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be
4169accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from
4170the guest.
4171
Ken Hofsass01643c52018-01-31 16:03:36 -080041726.74 KVM_CAP_SYNC_REGS
4173Architectures: s390, x86
4174Target: s390: always enabled, x86: vcpu
4175Parameters: none
4176Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
4177sets are supported (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
4178
4179As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
4180KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
4181without having to call SET/GET_*REGS". This reduces overhead by eliminating
4182repeated ioctl calls for setting and/or getting register values. This is
4183particularly important when userspace is making synchronous guest state
4184modifications, e.g. when emulating and/or intercepting instructions in
4185userspace.
4186
4187For s390 specifics, please refer to the source code.
4188
4189For x86:
4190- the register sets to be copied out to kvm_run are selectable
4191 by userspace (rather that all sets being copied out for every exit).
4192- vcpu_events are available in addition to regs and sregs.
4193
4194For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
4195function as an input bit-array field set by userspace to indicate the
4196specific register sets to be copied out on the next exit.
4197
4198To indicate when userspace has modified values that should be copied into
4199the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
4200This is done using the same bitflags as for the 'kvm_valid_regs' field.
4201If the dirty bit is not set, then the register set values will not be copied
4202into the vCPU even if they've been modified.
4203
4204Unused bitfields in the bitarrays must be set to zero.
4205
4206struct kvm_sync_regs {
4207 struct kvm_regs regs;
4208 struct kvm_sregs sregs;
4209 struct kvm_vcpu_events events;
4210};
4211
Paul Mackerras699a0ea2014-06-02 11:02:59 +100042127. Capabilities that can be enabled on VMs
4213------------------------------------------
4214
4215There are certain capabilities that change the behavior of the virtual
4216machine when enabled. To enable them, please see section 4.37. Below
4217you can find a list of capabilities and what their effect on the VM
4218is when enabling them.
4219
4220The following information is provided along with the description:
4221
4222 Architectures: which instruction set architectures provide this ioctl.
4223 x86 includes both i386 and x86_64.
4224
4225 Parameters: what parameters are accepted by the capability.
4226
4227 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
4228 are not detailed, but errors with specific meanings are.
4229
4230
42317.1 KVM_CAP_PPC_ENABLE_HCALL
4232
4233Architectures: ppc
4234Parameters: args[0] is the sPAPR hcall number
4235 args[1] is 0 to disable, 1 to enable in-kernel handling
4236
4237This capability controls whether individual sPAPR hypercalls (hcalls)
4238get handled by the kernel or not. Enabling or disabling in-kernel
4239handling of an hcall is effective across the VM. On creation, an
4240initial set of hcalls are enabled for in-kernel handling, which
4241consists of those hcalls for which in-kernel handlers were implemented
4242before this capability was implemented. If disabled, the kernel will
4243not to attempt to handle the hcall, but will always exit to userspace
4244to handle it. Note that it may not make sense to enable some and
4245disable others of a group of related hcalls, but KVM does not prevent
4246userspace from doing that.
Paul Mackerrasae2113a2014-06-02 11:03:00 +10004247
4248If the hcall number specified is not one that has an in-kernel
4249implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
4250error.
David Hildenbrand2444b352014-10-09 14:10:13 +02004251
42527.2 KVM_CAP_S390_USER_SIGP
4253
4254Architectures: s390
4255Parameters: none
4256
4257This capability controls which SIGP orders will be handled completely in user
4258space. With this capability enabled, all fast orders will be handled completely
4259in the kernel:
4260- SENSE
4261- SENSE RUNNING
4262- EXTERNAL CALL
4263- EMERGENCY SIGNAL
4264- CONDITIONAL EMERGENCY SIGNAL
4265
4266All other orders will be handled completely in user space.
4267
4268Only privileged operation exceptions will be checked for in the kernel (or even
4269in the hardware prior to interception). If this capability is not enabled, the
4270old way of handling SIGP orders is used (partially in kernel and user space).
Eric Farman68c55752014-06-09 10:57:26 -04004271
42727.3 KVM_CAP_S390_VECTOR_REGISTERS
4273
4274Architectures: s390
4275Parameters: none
4276Returns: 0 on success, negative value on error
4277
4278Allows use of the vector registers introduced with z13 processor, and
4279provides for the synchronization between host and user space. Will
4280return -EINVAL if the machine does not support vectors.
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01004281
42827.4 KVM_CAP_S390_USER_STSI
4283
4284Architectures: s390
4285Parameters: none
4286
4287This capability allows post-handlers for the STSI instruction. After
4288initial handling in the kernel, KVM exits to user space with
4289KVM_EXIT_S390_STSI to allow user space to insert further data.
4290
4291Before exiting to userspace, kvm handlers should fill in s390_stsi field of
4292vcpu->run:
4293struct {
4294 __u64 addr;
4295 __u8 ar;
4296 __u8 reserved;
4297 __u8 fc;
4298 __u8 sel1;
4299 __u16 sel2;
4300} s390_stsi;
4301
4302@addr - guest address of STSI SYSIB
4303@fc - function code
4304@sel1 - selector 1
4305@sel2 - selector 2
4306@ar - access register number
4307
4308KVM handlers should exit to userspace with rc = -EREMOTE.
Michael Ellermane928e9c2015-03-20 20:39:41 +11004309
Steve Rutherford49df6392015-07-29 23:21:40 -070043107.5 KVM_CAP_SPLIT_IRQCHIP
4311
4312Architectures: x86
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07004313Parameters: args[0] - number of routes reserved for userspace IOAPICs
Steve Rutherford49df6392015-07-29 23:21:40 -07004314Returns: 0 on success, -1 on error
4315
4316Create a local apic for each processor in the kernel. This can be used
4317instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
4318IOAPIC and PIC (and also the PIT, even though this has to be enabled
4319separately).
4320
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07004321This capability also enables in kernel routing of interrupt requests;
4322when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
4323used in the IRQ routing table. The first args[0] MSI routes are reserved
4324for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
4325a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
Steve Rutherford49df6392015-07-29 23:21:40 -07004326
4327Fails if VCPU has already been created, or if the irqchip is already in the
4328kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
4329
David Hildenbrand051c87f2016-04-19 13:13:40 +020043307.6 KVM_CAP_S390_RI
4331
4332Architectures: s390
4333Parameters: none
4334
4335Allows use of runtime-instrumentation introduced with zEC12 processor.
4336Will return -EINVAL if the machine does not support runtime-instrumentation.
4337Will return -EBUSY if a VCPU has already been created.
Michael Ellermane928e9c2015-03-20 20:39:41 +11004338
Radim Krčmář371313132016-07-12 22:09:27 +020043397.7 KVM_CAP_X2APIC_API
4340
4341Architectures: x86
4342Parameters: args[0] - features that should be enabled
4343Returns: 0 on success, -EINVAL when args[0] contains invalid features
4344
4345Valid feature flags in args[0] are
4346
4347#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
Radim Krčmářc5192652016-07-12 22:09:28 +02004348#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
Radim Krčmář371313132016-07-12 22:09:27 +02004349
4350Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
4351KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
4352allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
4353respective sections.
4354
Radim Krčmářc5192652016-07-12 22:09:28 +02004355KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
4356in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
4357as a broadcast even in x2APIC mode in order to support physical x2APIC
4358without interrupt remapping. This is undesirable in logical mode,
4359where 0xff represents CPUs 0-7 in cluster 0.
Radim Krčmář371313132016-07-12 22:09:27 +02004360
David Hildenbrand6502a342016-06-21 14:19:51 +020043617.8 KVM_CAP_S390_USER_INSTR0
4362
4363Architectures: s390
4364Parameters: none
4365
4366With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
4367be intercepted and forwarded to user space. User space can use this
4368mechanism e.g. to realize 2-byte software breakpoints. The kernel will
4369not inject an operating exception for these instructions, user space has
4370to take care of that.
4371
4372This capability can be enabled dynamically even if VCPUs were already
4373created and are running.
Radim Krčmář371313132016-07-12 22:09:27 +02004374
Fan Zhang4e0b1ab2016-11-29 07:17:55 +010043757.9 KVM_CAP_S390_GS
4376
4377Architectures: s390
4378Parameters: none
4379Returns: 0 on success; -EINVAL if the machine does not support
4380 guarded storage; -EBUSY if a VCPU has already been created.
4381
4382Allows use of guarded storage for the KVM guest.
4383
Yi Min Zhao47a46932017-03-10 09:29:38 +010043847.10 KVM_CAP_S390_AIS
4385
4386Architectures: s390
4387Parameters: none
4388
4389Allow use of adapter-interruption suppression.
4390Returns: 0 on success; -EBUSY if a VCPU has already been created.
4391
Paul Mackerras3c313522017-02-06 13:24:41 +110043927.11 KVM_CAP_PPC_SMT
4393
4394Architectures: ppc
4395Parameters: vsmt_mode, flags
4396
4397Enabling this capability on a VM provides userspace with a way to set
4398the desired virtual SMT mode (i.e. the number of virtual CPUs per
4399virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
4400between 1 and 8. On POWER8, vsmt_mode must also be no greater than
4401the number of threads per subcore for the host. Currently flags must
4402be 0. A successful call to enable this capability will result in
4403vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
4404subsequently queried for the VM. This capability is only supported by
4405HV KVM, and can only be set before any VCPUs have been created.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10004406The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
4407modes are available.
Paul Mackerras3c313522017-02-06 13:24:41 +11004408
Aravinda Prasad134764e2017-05-11 16:32:48 +053044097.12 KVM_CAP_PPC_FWNMI
4410
4411Architectures: ppc
4412Parameters: none
4413
4414With this capability a machine check exception in the guest address
4415space will cause KVM to exit the guest with NMI exit reason. This
4416enables QEMU to build error log and branch to guest kernel registered
4417machine check handling routine. Without this capability KVM will
4418branch to guests' 0x200 interrupt vector.
4419
Wanpeng Li4d5422c2018-03-12 04:53:02 -070044207.13 KVM_CAP_X86_DISABLE_EXITS
4421
4422Architectures: x86
4423Parameters: args[0] defines which exits are disabled
4424Returns: 0 on success, -EINVAL when args[0] contains invalid exits
4425
4426Valid bits in args[0] are
4427
4428#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
Wanpeng Licaa057a2018-03-12 04:53:03 -07004429#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
Wanpeng Li4d5422c2018-03-12 04:53:02 -07004430
4431Enabling this capability on a VM provides userspace with a way to no
4432longer intercept some instructions for improved latency in some
4433workloads, and is suggested when vCPUs are associated to dedicated
4434physical CPUs. More bits can be added in the future; userspace can
4435just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
4436all such vmexits.
4437
Wanpeng Licaa057a2018-03-12 04:53:03 -07004438Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
Wanpeng Li4d5422c2018-03-12 04:53:02 -07004439
Michael Ellermane928e9c2015-03-20 20:39:41 +110044408. Other capabilities.
4441----------------------
4442
4443This section lists capabilities that give information about other
4444features of the KVM implementation.
4445
44468.1 KVM_CAP_PPC_HWRNG
4447
4448Architectures: ppc
4449
4450This capability, if KVM_CHECK_EXTENSION indicates that it is
4451available, means that that the kernel has an implementation of the
4452H_RANDOM hypercall backed by a hardware random-number generator.
4453If present, the kernel H_RANDOM handler can be enabled for guest use
4454with the KVM_CAP_PPC_ENABLE_HCALL capability.
Andrey Smetanin5c9194122015-11-10 15:36:34 +03004455
44568.2 KVM_CAP_HYPERV_SYNIC
4457
4458Architectures: x86
4459This capability, if KVM_CHECK_EXTENSION indicates that it is
4460available, means that that the kernel has an implementation of the
4461Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
4462used to support Windows Hyper-V based guest paravirt drivers(VMBus).
4463
4464In order to use SynIC, it has to be activated by setting this
4465capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
4466will disable the use of APIC hardware virtualization even if supported
4467by the CPU, as it's incompatible with SynIC auto-EOI behavior.
Paul Mackerrasc9270132017-01-30 21:21:41 +11004468
44698.3 KVM_CAP_PPC_RADIX_MMU
4470
4471Architectures: ppc
4472
4473This capability, if KVM_CHECK_EXTENSION indicates that it is
4474available, means that that the kernel can support guests using the
4475radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
4476processor).
4477
44788.4 KVM_CAP_PPC_HASH_MMU_V3
4479
4480Architectures: ppc
4481
4482This capability, if KVM_CHECK_EXTENSION indicates that it is
4483available, means that that the kernel can support guests using the
4484hashed page table MMU defined in Power ISA V3.00 (as implemented in
4485the POWER9 processor), including in-memory segment tables.
James Hogana8a3c422017-03-14 10:15:19 +00004486
44878.5 KVM_CAP_MIPS_VZ
4488
4489Architectures: mips
4490
4491This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
4492it is available, means that full hardware assisted virtualization capabilities
4493of the hardware are available for use through KVM. An appropriate
4494KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
4495utilises it.
4496
4497If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
4498available, it means that the VM is using full hardware assisted virtualization
4499capabilities of the hardware. This is useful to check after creating a VM with
4500KVM_VM_MIPS_DEFAULT.
4501
4502The value returned by KVM_CHECK_EXTENSION should be compared against known
4503values (see below). All other values are reserved. This is to allow for the
4504possibility of other hardware assisted virtualization implementations which
4505may be incompatible with the MIPS VZ ASE.
4506
4507 0: The trap & emulate implementation is in use to run guest code in user
4508 mode. Guest virtual memory segments are rearranged to fit the guest in the
4509 user mode address space.
4510
4511 1: The MIPS VZ ASE is in use, providing full hardware assisted
4512 virtualization, including standard guest virtual memory segments.
4513
45148.6 KVM_CAP_MIPS_TE
4515
4516Architectures: mips
4517
4518This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
4519it is available, means that the trap & emulate implementation is available to
4520run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
4521assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
4522to KVM_CREATE_VM to create a VM which utilises it.
4523
4524If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
4525available, it means that the VM is using trap & emulate.
James Hogan578fd612017-03-14 10:15:20 +00004526
45278.7 KVM_CAP_MIPS_64BIT
4528
4529Architectures: mips
4530
4531This capability indicates the supported architecture type of the guest, i.e. the
4532supported register and address width.
4533
4534The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
4535kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
4536be checked specifically against known values (see below). All other values are
4537reserved.
4538
4539 0: MIPS32 or microMIPS32.
4540 Both registers and addresses are 32-bits wide.
4541 It will only be possible to run 32-bit guest code.
4542
4543 1: MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
4544 Registers are 64-bits wide, but addresses are 32-bits wide.
4545 64-bit guest code may run but cannot access MIPS64 memory segments.
4546 It will also be possible to run 32-bit guest code.
4547
4548 2: MIPS64 or microMIPS64 with access to all address segments.
4549 Both registers and addresses are 64-bits wide.
4550 It will be possible to run 64-bit or 32-bit guest code.
Michael S. Tsirkin668fffa2017-04-21 12:27:17 +02004551
Paolo Bonzinic24a7be2017-04-27 17:33:14 +020045528.9 KVM_CAP_ARM_USER_IRQ
Alexander Graf3fe17e62016-09-27 21:08:05 +02004553
4554Architectures: arm, arm64
4555This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
4556that if userspace creates a VM without an in-kernel interrupt controller, it
4557will be notified of changes to the output level of in-kernel emulated devices,
4558which can generate virtual interrupts, presented to the VM.
4559For such VMs, on every return to userspace, the kernel
4560updates the vcpu's run->s.regs.device_irq_level field to represent the actual
4561output level of the device.
4562
4563Whenever kvm detects a change in the device output level, kvm guarantees at
4564least one return to userspace before running the VM. This exit could either
4565be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
4566userspace can always sample the device output level and re-compute the state of
4567the userspace interrupt controller. Userspace should always check the state
4568of run->s.regs.device_irq_level on every kvm exit.
4569The value in run->s.regs.device_irq_level can represent both level and edge
4570triggered interrupt signals, depending on the device. Edge triggered interrupt
4571signals will exit to userspace with the bit in run->s.regs.device_irq_level
4572set exactly once per edge signal.
4573
4574The field run->s.regs.device_irq_level is available independent of
4575run->kvm_valid_regs or run->kvm_dirty_regs bits.
4576
4577If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
4578number larger than 0 indicating the version of this capability is implemented
4579and thereby which bits in in run->s.regs.device_irq_level can signal values.
4580
4581Currently the following bits are defined for the device_irq_level bitmap:
4582
4583 KVM_CAP_ARM_USER_IRQ >= 1:
4584
4585 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
4586 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
4587 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
4588
4589Future versions of kvm may implement additional events. These will get
4590indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
4591listed above.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10004592
45938.10 KVM_CAP_PPC_SMT_POSSIBLE
4594
4595Architectures: ppc
4596
4597Querying this capability returns a bitmap indicating the possible
4598virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
4599(counting from the right) is set, then a virtual SMT mode of 2^N is
4600available.
Roman Kaganefc479e2017-06-22 16:51:01 +03004601
46028.11 KVM_CAP_HYPERV_SYNIC2
4603
4604Architectures: x86
4605
4606This capability enables a newer version of Hyper-V Synthetic interrupt
4607controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
4608doesn't clear SynIC message and event flags pages when they are enabled by
4609writing to the respective MSRs.
Roman Kagand3457c82017-07-14 17:13:20 +03004610
46118.12 KVM_CAP_HYPERV_VP_INDEX
4612
4613Architectures: x86
4614
4615This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
4616value is used to denote the target vcpu for a SynIC interrupt. For
4617compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this
4618capability is absent, userspace can still query this msr's value.
Christian Borntraegerda9a1442017-11-09 10:00:45 +01004619
46208.13 KVM_CAP_S390_AIS_MIGRATION
4621
4622Architectures: s390
4623Parameters: none
4624
4625This capability indicates if the flic device will be able to get/set the
4626AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
4627to discover this without having to create a flic device.
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00004628
46298.14 KVM_CAP_S390_PSW
4630
4631Architectures: s390
4632
4633This capability indicates that the PSW is exposed via the kvm_run structure.
4634
46358.15 KVM_CAP_S390_GMAP
4636
4637Architectures: s390
4638
4639This capability indicates that the user space memory used as guest mapping can
4640be anywhere in the user memory address space, as long as the memory slots are
4641aligned and sized to a segment (1MB) boundary.
4642
46438.16 KVM_CAP_S390_COW
4644
4645Architectures: s390
4646
4647This capability indicates that the user space memory used as guest mapping can
4648use copy-on-write semantics as well as dirty pages tracking via read-only page
4649tables.
4650
46518.17 KVM_CAP_S390_BPB
4652
4653Architectures: s390
4654
4655This capability indicates that kvm will implement the interfaces to handle
4656reset, migration and nested KVM for branch prediction blocking. The stfle
4657facility 82 should not be provided to the guest without this capability.
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02004658
Vitaly Kuznetsov2ddc6492018-06-22 16:56:14 +020046598.18 KVM_CAP_HYPERV_TLBFLUSH
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02004660
4661Architectures: x86
4662
4663This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
4664hypercalls:
4665HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
4666HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.