blob: 6386f8c0482eaa578f68dfe850e559691e9de95d [file] [log] [blame]
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001The Definitive KVM (Kernel-based Virtual Machine) API Documentation
2===================================================================
3
41. General description
5
6The kvm API is a set of ioctls that are issued to control various aspects
7of a virtual machine. The ioctls belong to three classes
8
9 - System ioctls: These query and set global attributes which affect the
10 whole kvm subsystem. In addition a system ioctl is used to create
11 virtual machines
12
13 - VM ioctls: These query and set attributes that affect an entire virtual
14 machine, for example memory layout. In addition a VM ioctl is used to
15 create virtual cpus (vcpus).
16
17 Only run VM ioctls from the same process (address space) that was used
18 to create the VM.
19
20 - vcpu ioctls: These query and set attributes that control the operation
21 of a single virtual cpu.
22
23 Only run vcpu ioctls from the same thread that was used to create the
24 vcpu.
25
Wu Fengguang20448922009-12-24 09:04:16 +0800262. File descriptors
Avi Kivity9c1b96e2009-06-09 12:37:58 +030027
28The kvm API is centered around file descriptors. An initial
29open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
30can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
Wu Fengguang20448922009-12-24 09:04:16 +080031handle will create a VM file descriptor which can be used to issue VM
Avi Kivity9c1b96e2009-06-09 12:37:58 +030032ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
33and return a file descriptor pointing to it. Finally, ioctls on a vcpu
34fd can be used to control the vcpu, including the important task of
35actually running guest code.
36
37In general file descriptors can be migrated among processes by means
38of fork() and the SCM_RIGHTS facility of unix domain socket. These
39kinds of tricks are explicitly not supported by kvm. While they will
40not cause harm to the host, their actual behavior is not guaranteed by
41the API. The only supported use is one virtual machine per process,
42and one vcpu per thread.
43
443. Extensions
45
46As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
47incompatible change are allowed. However, there is an extension
48facility that allows backward-compatible extensions to the API to be
49queried and used.
50
51The extension mechanism is not based on on the Linux version number.
52Instead, kvm defines extension identifiers and a facility to query
53whether a particular extension identifier is available. If it is, a
54set of ioctls is available for application use.
55
564. API description
57
58This section describes ioctls that can be used to control kvm guests.
59For each ioctl, the following information is provided along with a
60description:
61
62 Capability: which KVM extension provides this ioctl. Can be 'basic',
63 which means that is will be provided by any kernel that supports
64 API version 12 (see section 4.1), or a KVM_CAP_xyz constant, which
65 means availability needs to be checked with KVM_CHECK_EXTENSION
66 (see section 4.4).
67
68 Architectures: which instruction set architectures provide this ioctl.
69 x86 includes both i386 and x86_64.
70
71 Type: system, vm, or vcpu.
72
73 Parameters: what parameters are accepted by the ioctl.
74
75 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
76 are not detailed, but errors with specific meanings are.
77
784.1 KVM_GET_API_VERSION
79
80Capability: basic
81Architectures: all
82Type: system ioctl
83Parameters: none
84Returns: the constant KVM_API_VERSION (=12)
85
86This identifies the API version as the stable kvm API. It is not
87expected that this number will change. However, Linux 2.6.20 and
882.6.21 report earlier versions; these are not documented and not
89supported. Applications should refuse to run if KVM_GET_API_VERSION
90returns a value other than 12. If this check passes, all ioctls
91described as 'basic' will be available.
92
934.2 KVM_CREATE_VM
94
95Capability: basic
96Architectures: all
97Type: system ioctl
Carsten Ottee08b9632012-01-04 10:25:20 +010098Parameters: machine type identifier (KVM_VM_*)
Avi Kivity9c1b96e2009-06-09 12:37:58 +030099Returns: a VM fd that can be used to control the new virtual machine.
100
101The new VM has no virtual cpus and no memory. An mmap() of a VM fd
102will access the virtual machine's physical address space; offset zero
103corresponds to guest physical address zero. Use of mmap() on a VM fd
104is discouraged if userspace memory allocation (KVM_CAP_USER_MEMORY) is
105available.
Carsten Ottee08b9632012-01-04 10:25:20 +0100106You most certainly want to use 0 as machine type.
107
108In order to create user controlled virtual machines on S390, check
109KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
110privileged user (CAP_SYS_ADMIN).
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300111
1124.3 KVM_GET_MSR_INDEX_LIST
113
114Capability: basic
115Architectures: x86
116Type: system
117Parameters: struct kvm_msr_list (in/out)
118Returns: 0 on success; -1 on error
119Errors:
120 E2BIG: the msr index list is to be to fit in the array specified by
121 the user.
122
123struct kvm_msr_list {
124 __u32 nmsrs; /* number of msrs in entries */
125 __u32 indices[0];
126};
127
128This ioctl returns the guest msrs that are supported. The list varies
129by kvm version and host processor, but does not change otherwise. The
130user fills in the size of the indices array in nmsrs, and in return
131kvm adjusts nmsrs to reflect the actual number of msrs and fills in
132the indices array with their numbers.
133
Avi Kivity2e2602c2010-07-07 14:09:39 +0300134Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
135not returned in the MSR list, as different vcpus can have a different number
136of banks, as set via the KVM_X86_SETUP_MCE ioctl.
137
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001384.4 KVM_CHECK_EXTENSION
139
140Capability: basic
141Architectures: all
142Type: system ioctl
143Parameters: extension identifier (KVM_CAP_*)
144Returns: 0 if unsupported; 1 (or some other positive integer) if supported
145
146The API allows the application to query about extensions to the core
147kvm API. Userspace passes an extension identifier (an integer) and
148receives an integer that describes the extension availability.
149Generally 0 means no and 1 means yes, but some extensions may report
150additional information in the integer return value.
151
1524.5 KVM_GET_VCPU_MMAP_SIZE
153
154Capability: basic
155Architectures: all
156Type: system ioctl
157Parameters: none
158Returns: size of vcpu mmap area, in bytes
159
160The KVM_RUN ioctl (cf.) communicates with userspace via a shared
161memory region. This ioctl returns the size of that region. See the
162KVM_RUN documentation for details.
163
1644.6 KVM_SET_MEMORY_REGION
165
166Capability: basic
167Architectures: all
168Type: vm ioctl
169Parameters: struct kvm_memory_region (in)
170Returns: 0 on success, -1 on error
171
Avi Kivityb74a07b2010-06-21 11:48:05 +0300172This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300173
Paul Bolle68ba6972011-02-15 00:05:59 +01001744.7 KVM_CREATE_VCPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300175
176Capability: basic
177Architectures: all
178Type: vm ioctl
179Parameters: vcpu id (apic id on x86)
180Returns: vcpu fd on success, -1 on error
181
182This API adds a vcpu to a virtual machine. The vcpu id is a small integer
Sasha Levin8c3ba332011-07-18 17:17:15 +0300183in the range [0, max_vcpus).
184
185The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
186the KVM_CHECK_EXTENSION ioctl() at run-time.
187The maximum possible value for max_vcpus can be retrieved using the
188KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
189
Pekka Enberg76d25402011-05-09 22:48:54 +0300190If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
191cpus max.
Sasha Levin8c3ba332011-07-18 17:17:15 +0300192If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
193same as the value returned from KVM_CAP_NR_VCPUS.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300194
Paul Mackerras371fefd2011-06-29 00:23:08 +0000195On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
196threads in one or more virtual CPU cores. (This is because the
197hardware requires all the hardware threads in a CPU core to be in the
198same partition.) The KVM_CAP_PPC_SMT capability indicates the number
199of vcpus per virtual core (vcore). The vcore id is obtained by
200dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
201given vcore will always be in the same physical core as each other
202(though that might be a different physical core from time to time).
203Userspace can control the threading (SMT) mode of the guest by its
204allocation of vcpu ids. For example, if userspace wants
205single-threaded guest vcpus, it should make all vcpu ids be a multiple
206of the number of vcpus per vcore.
207
Avi Kivity36442682011-08-29 16:27:08 +0300208On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
209threads in one or more virtual CPU cores. (This is because the
210hardware requires all the hardware threads in a CPU core to be in the
211same partition.) The KVM_CAP_PPC_SMT capability indicates the number
212of vcpus per virtual core (vcore). The vcore id is obtained by
213dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
214given vcore will always be in the same physical core as each other
215(though that might be a different physical core from time to time).
216Userspace can control the threading (SMT) mode of the guest by its
217allocation of vcpu ids. For example, if userspace wants
218single-threaded guest vcpus, it should make all vcpu ids be a multiple
219of the number of vcpus per vcore.
220
Carsten Otte5b1c1492012-01-04 10:25:23 +0100221For virtual cpus that have been created with S390 user controlled virtual
222machines, the resulting vcpu fd can be memory mapped at page offset
223KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
224cpu's hardware control block.
225
Paul Bolle68ba6972011-02-15 00:05:59 +01002264.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300227
228Capability: basic
229Architectures: x86
230Type: vm ioctl
231Parameters: struct kvm_dirty_log (in/out)
232Returns: 0 on success, -1 on error
233
234/* for KVM_GET_DIRTY_LOG */
235struct kvm_dirty_log {
236 __u32 slot;
237 __u32 padding;
238 union {
239 void __user *dirty_bitmap; /* one bit per page */
240 __u64 padding;
241 };
242};
243
244Given a memory slot, return a bitmap containing any pages dirtied
245since the last call to this ioctl. Bit 0 is the first page in the
246memory slot. Ensure the entire structure is cleared to avoid padding
247issues.
248
Paul Bolle68ba6972011-02-15 00:05:59 +01002494.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300250
251Capability: basic
252Architectures: x86
253Type: vm ioctl
254Parameters: struct kvm_memory_alias (in)
255Returns: 0 (success), -1 (error)
256
Avi Kivitya1f4d392010-06-21 11:44:20 +0300257This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300258
Paul Bolle68ba6972011-02-15 00:05:59 +01002594.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300260
261Capability: basic
262Architectures: all
263Type: vcpu ioctl
264Parameters: none
265Returns: 0 on success, -1 on error
266Errors:
267 EINTR: an unmasked signal is pending
268
269This ioctl is used to run a guest virtual cpu. While there are no
270explicit parameters, there is an implicit parameter block that can be
271obtained by mmap()ing the vcpu fd at offset 0, with the size given by
272KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
273kvm_run' (see below).
274
Paul Bolle68ba6972011-02-15 00:05:59 +01002754.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300276
277Capability: basic
278Architectures: all
279Type: vcpu ioctl
280Parameters: struct kvm_regs (out)
281Returns: 0 on success, -1 on error
282
283Reads the general purpose registers from the vcpu.
284
285/* x86 */
286struct kvm_regs {
287 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
288 __u64 rax, rbx, rcx, rdx;
289 __u64 rsi, rdi, rsp, rbp;
290 __u64 r8, r9, r10, r11;
291 __u64 r12, r13, r14, r15;
292 __u64 rip, rflags;
293};
294
Paul Bolle68ba6972011-02-15 00:05:59 +01002954.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300296
297Capability: basic
298Architectures: all
299Type: vcpu ioctl
300Parameters: struct kvm_regs (in)
301Returns: 0 on success, -1 on error
302
303Writes the general purpose registers into the vcpu.
304
305See KVM_GET_REGS for the data structure.
306
Paul Bolle68ba6972011-02-15 00:05:59 +01003074.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300308
309Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500310Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300311Type: vcpu ioctl
312Parameters: struct kvm_sregs (out)
313Returns: 0 on success, -1 on error
314
315Reads special registers from the vcpu.
316
317/* x86 */
318struct kvm_sregs {
319 struct kvm_segment cs, ds, es, fs, gs, ss;
320 struct kvm_segment tr, ldt;
321 struct kvm_dtable gdt, idt;
322 __u64 cr0, cr2, cr3, cr4, cr8;
323 __u64 efer;
324 __u64 apic_base;
325 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
326};
327
Scott Wood5ce941e2011-04-27 17:24:21 -0500328/* ppc -- see arch/powerpc/include/asm/kvm.h */
329
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300330interrupt_bitmap is a bitmap of pending external interrupts. At most
331one bit may be set. This interrupt has been acknowledged by the APIC
332but not yet injected into the cpu core.
333
Paul Bolle68ba6972011-02-15 00:05:59 +01003344.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300335
336Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500337Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300338Type: vcpu ioctl
339Parameters: struct kvm_sregs (in)
340Returns: 0 on success, -1 on error
341
342Writes special registers into the vcpu. See KVM_GET_SREGS for the
343data structures.
344
Paul Bolle68ba6972011-02-15 00:05:59 +01003454.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300346
347Capability: basic
348Architectures: x86
349Type: vcpu ioctl
350Parameters: struct kvm_translation (in/out)
351Returns: 0 on success, -1 on error
352
353Translates a virtual address according to the vcpu's current address
354translation mode.
355
356struct kvm_translation {
357 /* in */
358 __u64 linear_address;
359
360 /* out */
361 __u64 physical_address;
362 __u8 valid;
363 __u8 writeable;
364 __u8 usermode;
365 __u8 pad[5];
366};
367
Paul Bolle68ba6972011-02-15 00:05:59 +01003684.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300369
370Capability: basic
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200371Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300372Type: vcpu ioctl
373Parameters: struct kvm_interrupt (in)
374Returns: 0 on success, -1 on error
375
376Queues a hardware interrupt vector to be injected. This is only
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200377useful if in-kernel local APIC or equivalent is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300378
379/* for KVM_INTERRUPT */
380struct kvm_interrupt {
381 /* in */
382 __u32 irq;
383};
384
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200385X86:
386
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300387Note 'irq' is an interrupt vector, not an interrupt pin or line.
388
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200389PPC:
390
391Queues an external interrupt to be injected. This ioctl is overleaded
392with 3 different irq values:
393
394a) KVM_INTERRUPT_SET
395
396 This injects an edge type external interrupt into the guest once it's ready
397 to receive interrupts. When injected, the interrupt is done.
398
399b) KVM_INTERRUPT_UNSET
400
401 This unsets any pending interrupt.
402
403 Only available with KVM_CAP_PPC_UNSET_IRQ.
404
405c) KVM_INTERRUPT_SET_LEVEL
406
407 This injects a level type external interrupt into the guest context. The
408 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
409 is triggered.
410
411 Only available with KVM_CAP_PPC_IRQ_LEVEL.
412
413Note that any value for 'irq' other than the ones stated above is invalid
414and incurs unexpected behavior.
415
Paul Bolle68ba6972011-02-15 00:05:59 +01004164.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300417
418Capability: basic
419Architectures: none
420Type: vcpu ioctl
421Parameters: none)
422Returns: -1 on error
423
424Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
425
Paul Bolle68ba6972011-02-15 00:05:59 +01004264.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300427
428Capability: basic
429Architectures: x86
430Type: vcpu ioctl
431Parameters: struct kvm_msrs (in/out)
432Returns: 0 on success, -1 on error
433
434Reads model-specific registers from the vcpu. Supported msr indices can
435be obtained using KVM_GET_MSR_INDEX_LIST.
436
437struct kvm_msrs {
438 __u32 nmsrs; /* number of msrs in entries */
439 __u32 pad;
440
441 struct kvm_msr_entry entries[0];
442};
443
444struct kvm_msr_entry {
445 __u32 index;
446 __u32 reserved;
447 __u64 data;
448};
449
450Application code should set the 'nmsrs' member (which indicates the
451size of the entries array) and the 'index' member of each array entry.
452kvm will fill in the 'data' member.
453
Paul Bolle68ba6972011-02-15 00:05:59 +01004544.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300455
456Capability: basic
457Architectures: x86
458Type: vcpu ioctl
459Parameters: struct kvm_msrs (in)
460Returns: 0 on success, -1 on error
461
462Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
463data structures.
464
465Application code should set the 'nmsrs' member (which indicates the
466size of the entries array), and the 'index' and 'data' members of each
467array entry.
468
Paul Bolle68ba6972011-02-15 00:05:59 +01004694.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300470
471Capability: basic
472Architectures: x86
473Type: vcpu ioctl
474Parameters: struct kvm_cpuid (in)
475Returns: 0 on success, -1 on error
476
477Defines the vcpu responses to the cpuid instruction. Applications
478should use the KVM_SET_CPUID2 ioctl if available.
479
480
481struct kvm_cpuid_entry {
482 __u32 function;
483 __u32 eax;
484 __u32 ebx;
485 __u32 ecx;
486 __u32 edx;
487 __u32 padding;
488};
489
490/* for KVM_SET_CPUID */
491struct kvm_cpuid {
492 __u32 nent;
493 __u32 padding;
494 struct kvm_cpuid_entry entries[0];
495};
496
Paul Bolle68ba6972011-02-15 00:05:59 +01004974.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300498
499Capability: basic
500Architectures: x86
501Type: vcpu ioctl
502Parameters: struct kvm_signal_mask (in)
503Returns: 0 on success, -1 on error
504
505Defines which signals are blocked during execution of KVM_RUN. This
506signal mask temporarily overrides the threads signal mask. Any
507unblocked signal received (except SIGKILL and SIGSTOP, which retain
508their traditional behaviour) will cause KVM_RUN to return with -EINTR.
509
510Note the signal will only be delivered if not blocked by the original
511signal mask.
512
513/* for KVM_SET_SIGNAL_MASK */
514struct kvm_signal_mask {
515 __u32 len;
516 __u8 sigset[0];
517};
518
Paul Bolle68ba6972011-02-15 00:05:59 +01005194.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300520
521Capability: basic
522Architectures: x86
523Type: vcpu ioctl
524Parameters: struct kvm_fpu (out)
525Returns: 0 on success, -1 on error
526
527Reads the floating point state from the vcpu.
528
529/* for KVM_GET_FPU and KVM_SET_FPU */
530struct kvm_fpu {
531 __u8 fpr[8][16];
532 __u16 fcw;
533 __u16 fsw;
534 __u8 ftwx; /* in fxsave format */
535 __u8 pad1;
536 __u16 last_opcode;
537 __u64 last_ip;
538 __u64 last_dp;
539 __u8 xmm[16][16];
540 __u32 mxcsr;
541 __u32 pad2;
542};
543
Paul Bolle68ba6972011-02-15 00:05:59 +01005444.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300545
546Capability: basic
547Architectures: x86
548Type: vcpu ioctl
549Parameters: struct kvm_fpu (in)
550Returns: 0 on success, -1 on error
551
552Writes the floating point state to the vcpu.
553
554/* for KVM_GET_FPU and KVM_SET_FPU */
555struct kvm_fpu {
556 __u8 fpr[8][16];
557 __u16 fcw;
558 __u16 fsw;
559 __u8 ftwx; /* in fxsave format */
560 __u8 pad1;
561 __u16 last_opcode;
562 __u64 last_ip;
563 __u64 last_dp;
564 __u8 xmm[16][16];
565 __u32 mxcsr;
566 __u32 pad2;
567};
568
Paul Bolle68ba6972011-02-15 00:05:59 +01005694.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300570
571Capability: KVM_CAP_IRQCHIP
572Architectures: x86, ia64
573Type: vm ioctl
574Parameters: none
575Returns: 0 on success, -1 on error
576
577Creates an interrupt controller model in the kernel. On x86, creates a virtual
578ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
579local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
580only go to the IOAPIC. On ia64, a IOSAPIC is created.
581
Paul Bolle68ba6972011-02-15 00:05:59 +01005824.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300583
584Capability: KVM_CAP_IRQCHIP
585Architectures: x86, ia64
586Type: vm ioctl
587Parameters: struct kvm_irq_level
588Returns: 0 on success, -1 on error
589
590Sets the level of a GSI input to the interrupt controller model in the kernel.
591Requires that an interrupt controller model has been previously created with
592KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
593to be set to 1 and then back to 0.
594
595struct kvm_irq_level {
596 union {
597 __u32 irq; /* GSI */
598 __s32 status; /* not used for KVM_IRQ_LEVEL */
599 };
600 __u32 level; /* 0 or 1 */
601};
602
Paul Bolle68ba6972011-02-15 00:05:59 +01006034.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300604
605Capability: KVM_CAP_IRQCHIP
606Architectures: x86, ia64
607Type: vm ioctl
608Parameters: struct kvm_irqchip (in/out)
609Returns: 0 on success, -1 on error
610
611Reads the state of a kernel interrupt controller created with
612KVM_CREATE_IRQCHIP into a buffer provided by the caller.
613
614struct kvm_irqchip {
615 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
616 __u32 pad;
617 union {
618 char dummy[512]; /* reserving space */
619 struct kvm_pic_state pic;
620 struct kvm_ioapic_state ioapic;
621 } chip;
622};
623
Paul Bolle68ba6972011-02-15 00:05:59 +01006244.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300625
626Capability: KVM_CAP_IRQCHIP
627Architectures: x86, ia64
628Type: vm ioctl
629Parameters: struct kvm_irqchip (in)
630Returns: 0 on success, -1 on error
631
632Sets the state of a kernel interrupt controller created with
633KVM_CREATE_IRQCHIP from a buffer provided by the caller.
634
635struct kvm_irqchip {
636 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
637 __u32 pad;
638 union {
639 char dummy[512]; /* reserving space */
640 struct kvm_pic_state pic;
641 struct kvm_ioapic_state ioapic;
642 } chip;
643};
644
Paul Bolle68ba6972011-02-15 00:05:59 +01006454.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700646
647Capability: KVM_CAP_XEN_HVM
648Architectures: x86
649Type: vm ioctl
650Parameters: struct kvm_xen_hvm_config (in)
651Returns: 0 on success, -1 on error
652
653Sets the MSR that the Xen HVM guest uses to initialize its hypercall
654page, and provides the starting address and size of the hypercall
655blobs in userspace. When the guest writes the MSR, kvm copies one
656page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
657memory.
658
659struct kvm_xen_hvm_config {
660 __u32 flags;
661 __u32 msr;
662 __u64 blob_addr_32;
663 __u64 blob_addr_64;
664 __u8 blob_size_32;
665 __u8 blob_size_64;
666 __u8 pad2[30];
667};
668
Paul Bolle68ba6972011-02-15 00:05:59 +01006694.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400670
671Capability: KVM_CAP_ADJUST_CLOCK
672Architectures: x86
673Type: vm ioctl
674Parameters: struct kvm_clock_data (out)
675Returns: 0 on success, -1 on error
676
677Gets the current timestamp of kvmclock as seen by the current guest. In
678conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
679such as migration.
680
681struct kvm_clock_data {
682 __u64 clock; /* kvmclock current value */
683 __u32 flags;
684 __u32 pad[9];
685};
686
Paul Bolle68ba6972011-02-15 00:05:59 +01006874.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400688
689Capability: KVM_CAP_ADJUST_CLOCK
690Architectures: x86
691Type: vm ioctl
692Parameters: struct kvm_clock_data (in)
693Returns: 0 on success, -1 on error
694
Wu Fengguang20448922009-12-24 09:04:16 +0800695Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400696In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
697such as migration.
698
699struct kvm_clock_data {
700 __u64 clock; /* kvmclock current value */
701 __u32 flags;
702 __u32 pad[9];
703};
704
Paul Bolle68ba6972011-02-15 00:05:59 +01007054.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100706
707Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100708Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100709Architectures: x86
710Type: vm ioctl
711Parameters: struct kvm_vcpu_event (out)
712Returns: 0 on success, -1 on error
713
714Gets currently pending exceptions, interrupts, and NMIs as well as related
715states of the vcpu.
716
717struct kvm_vcpu_events {
718 struct {
719 __u8 injected;
720 __u8 nr;
721 __u8 has_error_code;
722 __u8 pad;
723 __u32 error_code;
724 } exception;
725 struct {
726 __u8 injected;
727 __u8 nr;
728 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100729 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100730 } interrupt;
731 struct {
732 __u8 injected;
733 __u8 pending;
734 __u8 masked;
735 __u8 pad;
736 } nmi;
737 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100738 __u32 flags;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100739};
740
Jan Kiszka48005f62010-02-19 19:38:07 +0100741KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
742interrupt.shadow contains a valid state. Otherwise, this field is undefined.
743
Paul Bolle68ba6972011-02-15 00:05:59 +01007444.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100745
746Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100747Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100748Architectures: x86
749Type: vm ioctl
750Parameters: struct kvm_vcpu_event (in)
751Returns: 0 on success, -1 on error
752
753Set pending exceptions, interrupts, and NMIs as well as related states of the
754vcpu.
755
756See KVM_GET_VCPU_EVENTS for the data structure.
757
Jan Kiszkadab4b912009-12-06 18:24:15 +0100758Fields that may be modified asynchronously by running VCPUs can be excluded
759from the update. These fields are nmi.pending and sipi_vector. Keep the
760corresponding bits in the flags field cleared to suppress overwriting the
761current in-kernel state. The bits are:
762
763KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
764KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
765
Jan Kiszka48005f62010-02-19 19:38:07 +0100766If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
767the flags field to signal that interrupt.shadow contains a valid state and
768shall be written into the VCPU.
769
Paul Bolle68ba6972011-02-15 00:05:59 +01007704.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100771
772Capability: KVM_CAP_DEBUGREGS
773Architectures: x86
774Type: vm ioctl
775Parameters: struct kvm_debugregs (out)
776Returns: 0 on success, -1 on error
777
778Reads debug registers from the vcpu.
779
780struct kvm_debugregs {
781 __u64 db[4];
782 __u64 dr6;
783 __u64 dr7;
784 __u64 flags;
785 __u64 reserved[9];
786};
787
Paul Bolle68ba6972011-02-15 00:05:59 +01007884.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100789
790Capability: KVM_CAP_DEBUGREGS
791Architectures: x86
792Type: vm ioctl
793Parameters: struct kvm_debugregs (in)
794Returns: 0 on success, -1 on error
795
796Writes debug registers into the vcpu.
797
798See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
799yet and must be cleared on entry.
800
Paul Bolle68ba6972011-02-15 00:05:59 +01008014.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +0200802
803Capability: KVM_CAP_USER_MEM
804Architectures: all
805Type: vm ioctl
806Parameters: struct kvm_userspace_memory_region (in)
807Returns: 0 on success, -1 on error
808
809struct kvm_userspace_memory_region {
810 __u32 slot;
811 __u32 flags;
812 __u64 guest_phys_addr;
813 __u64 memory_size; /* bytes */
814 __u64 userspace_addr; /* start of the userspace allocated memory */
815};
816
817/* for kvm_memory_region::flags */
818#define KVM_MEM_LOG_DIRTY_PAGES 1UL
819
820This ioctl allows the user to create or modify a guest physical memory
821slot. When changing an existing slot, it may be moved in the guest
822physical memory space, or its flags may be modified. It may not be
823resized. Slots may not overlap in guest physical address space.
824
825Memory for the region is taken starting at the address denoted by the
826field userspace_addr, which must point at user addressable memory for
827the entire memory slot size. Any object may back this memory, including
828anonymous memory, ordinary files, and hugetlbfs.
829
830It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
831be identical. This allows large pages in the guest to be backed by large
832pages in the host.
833
834The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
835instructs kvm to keep track of writes to memory within the slot. See
836the KVM_GET_DIRTY_LOG ioctl.
837
838When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
839region are automatically reflected into the guest. For example, an mmap()
840that affects the region will be made visible immediately. Another example
841is madvise(MADV_DROP).
842
843It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
844The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
845allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100846
Paul Bolle68ba6972011-02-15 00:05:59 +01008474.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +0200848
849Capability: KVM_CAP_SET_TSS_ADDR
850Architectures: x86
851Type: vm ioctl
852Parameters: unsigned long tss_address (in)
853Returns: 0 on success, -1 on error
854
855This ioctl defines the physical address of a three-page region in the guest
856physical address space. The region must be within the first 4GB of the
857guest physical address space and must not conflict with any memory slot
858or any mmio address. The guest may malfunction if it accesses this memory
859region.
860
861This ioctl is required on Intel-based hosts. This is needed on Intel hardware
862because of a quirk in the virtualization implementation (see the internals
863documentation when it pops into existence).
864
Paul Bolle68ba6972011-02-15 00:05:59 +01008654.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +0100866
867Capability: KVM_CAP_ENABLE_CAP
868Architectures: ppc
869Type: vcpu ioctl
870Parameters: struct kvm_enable_cap (in)
871Returns: 0 on success; -1 on error
872
873+Not all extensions are enabled by default. Using this ioctl the application
874can enable an extension, making it available to the guest.
875
876On systems that do not support this ioctl, it always fails. On systems that
877do support it, it only works for extensions that are supported for enablement.
878
879To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
880be used.
881
882struct kvm_enable_cap {
883 /* in */
884 __u32 cap;
885
886The capability that is supposed to get enabled.
887
888 __u32 flags;
889
890A bitfield indicating future enhancements. Has to be 0 for now.
891
892 __u64 args[4];
893
894Arguments for enabling a feature. If a feature needs initial values to
895function properly, this is the place to put them.
896
897 __u8 pad[64];
898};
899
Paul Bolle68ba6972011-02-15 00:05:59 +01009004.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300901
902Capability: KVM_CAP_MP_STATE
903Architectures: x86, ia64
904Type: vcpu ioctl
905Parameters: struct kvm_mp_state (out)
906Returns: 0 on success; -1 on error
907
908struct kvm_mp_state {
909 __u32 mp_state;
910};
911
912Returns the vcpu's current "multiprocessing state" (though also valid on
913uniprocessor guests).
914
915Possible values are:
916
917 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
918 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
919 which has not yet received an INIT signal
920 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
921 now ready for a SIPI
922 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
923 is waiting for an interrupt
924 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400925 accessible via KVM_GET_VCPU_EVENTS)
Avi Kivityb843f062010-04-25 15:51:46 +0300926
927This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
928irqchip, the multiprocessing state must be maintained by userspace.
929
Paul Bolle68ba6972011-02-15 00:05:59 +01009304.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300931
932Capability: KVM_CAP_MP_STATE
933Architectures: x86, ia64
934Type: vcpu ioctl
935Parameters: struct kvm_mp_state (in)
936Returns: 0 on success; -1 on error
937
938Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
939arguments.
940
941This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
942irqchip, the multiprocessing state must be maintained by userspace.
943
Paul Bolle68ba6972011-02-15 00:05:59 +01009444.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +0300945
946Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
947Architectures: x86
948Type: vm ioctl
949Parameters: unsigned long identity (in)
950Returns: 0 on success, -1 on error
951
952This ioctl defines the physical address of a one-page region in the guest
953physical address space. The region must be within the first 4GB of the
954guest physical address space and must not conflict with any memory slot
955or any mmio address. The guest may malfunction if it accesses this memory
956region.
957
958This ioctl is required on Intel-based hosts. This is needed on Intel hardware
959because of a quirk in the virtualization implementation (see the internals
960documentation when it pops into existence).
961
Paul Bolle68ba6972011-02-15 00:05:59 +01009624.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +0300963
964Capability: KVM_CAP_SET_BOOT_CPU_ID
965Architectures: x86, ia64
966Type: vm ioctl
967Parameters: unsigned long vcpu_id
968Returns: 0 on success, -1 on error
969
970Define which vcpu is the Bootstrap Processor (BSP). Values are the same
971as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
972is vcpu 0.
973
Paul Bolle68ba6972011-02-15 00:05:59 +01009744.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800975
976Capability: KVM_CAP_XSAVE
977Architectures: x86
978Type: vcpu ioctl
979Parameters: struct kvm_xsave (out)
980Returns: 0 on success, -1 on error
981
982struct kvm_xsave {
983 __u32 region[1024];
984};
985
986This ioctl would copy current vcpu's xsave struct to the userspace.
987
Paul Bolle68ba6972011-02-15 00:05:59 +01009884.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800989
990Capability: KVM_CAP_XSAVE
991Architectures: x86
992Type: vcpu ioctl
993Parameters: struct kvm_xsave (in)
994Returns: 0 on success, -1 on error
995
996struct kvm_xsave {
997 __u32 region[1024];
998};
999
1000This ioctl would copy userspace's xsave struct to the kernel.
1001
Paul Bolle68ba6972011-02-15 00:05:59 +010010024.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001003
1004Capability: KVM_CAP_XCRS
1005Architectures: x86
1006Type: vcpu ioctl
1007Parameters: struct kvm_xcrs (out)
1008Returns: 0 on success, -1 on error
1009
1010struct kvm_xcr {
1011 __u32 xcr;
1012 __u32 reserved;
1013 __u64 value;
1014};
1015
1016struct kvm_xcrs {
1017 __u32 nr_xcrs;
1018 __u32 flags;
1019 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1020 __u64 padding[16];
1021};
1022
1023This ioctl would copy current vcpu's xcrs to the userspace.
1024
Paul Bolle68ba6972011-02-15 00:05:59 +010010254.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001026
1027Capability: KVM_CAP_XCRS
1028Architectures: x86
1029Type: vcpu ioctl
1030Parameters: struct kvm_xcrs (in)
1031Returns: 0 on success, -1 on error
1032
1033struct kvm_xcr {
1034 __u32 xcr;
1035 __u32 reserved;
1036 __u64 value;
1037};
1038
1039struct kvm_xcrs {
1040 __u32 nr_xcrs;
1041 __u32 flags;
1042 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1043 __u64 padding[16];
1044};
1045
1046This ioctl would set vcpu's xcr to the value userspace specified.
1047
Paul Bolle68ba6972011-02-15 00:05:59 +010010484.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001049
1050Capability: KVM_CAP_EXT_CPUID
1051Architectures: x86
1052Type: system ioctl
1053Parameters: struct kvm_cpuid2 (in/out)
1054Returns: 0 on success, -1 on error
1055
1056struct kvm_cpuid2 {
1057 __u32 nent;
1058 __u32 padding;
1059 struct kvm_cpuid_entry2 entries[0];
1060};
1061
1062#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
1063#define KVM_CPUID_FLAG_STATEFUL_FUNC 2
1064#define KVM_CPUID_FLAG_STATE_READ_NEXT 4
1065
1066struct kvm_cpuid_entry2 {
1067 __u32 function;
1068 __u32 index;
1069 __u32 flags;
1070 __u32 eax;
1071 __u32 ebx;
1072 __u32 ecx;
1073 __u32 edx;
1074 __u32 padding[3];
1075};
1076
1077This ioctl returns x86 cpuid features which are supported by both the hardware
1078and kvm. Userspace can use the information returned by this ioctl to
1079construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1080hardware, kernel, and userspace capabilities, and with user requirements (for
1081example, the user may wish to constrain cpuid to emulate older hardware,
1082or for feature consistency across a cluster).
1083
1084Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1085with the 'nent' field indicating the number of entries in the variable-size
1086array 'entries'. If the number of entries is too low to describe the cpu
1087capabilities, an error (E2BIG) is returned. If the number is too high,
1088the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1089number is just right, the 'nent' field is adjusted to the number of valid
1090entries in the 'entries' array, which is then filled.
1091
1092The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001093with unknown or unsupported features masked out. Some features (for example,
1094x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1095emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001096
1097 function: the eax value used to obtain the entry
1098 index: the ecx value used to obtain the entry (for entries that are
1099 affected by ecx)
1100 flags: an OR of zero or more of the following:
1101 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1102 if the index field is valid
1103 KVM_CPUID_FLAG_STATEFUL_FUNC:
1104 if cpuid for this function returns different values for successive
1105 invocations; there will be several entries with the same function,
1106 all with this flag set
1107 KVM_CPUID_FLAG_STATE_READ_NEXT:
1108 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1109 the first entry to be read by a cpu
1110 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1111 this function/index combination
1112
Jan Kiszka4d25a062011-12-21 12:28:29 +01001113The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1114as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1115support. Instead it is reported via
1116
1117 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1118
1119if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1120feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1121
Paul Bolle68ba6972011-02-15 00:05:59 +010011224.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001123
1124Capability: KVM_CAP_PPC_GET_PVINFO
1125Architectures: ppc
1126Type: vm ioctl
1127Parameters: struct kvm_ppc_pvinfo (out)
1128Returns: 0 on success, !0 on error
1129
1130struct kvm_ppc_pvinfo {
1131 __u32 flags;
1132 __u32 hcall[4];
1133 __u8 pad[108];
1134};
1135
1136This ioctl fetches PV specific information that need to be passed to the guest
1137using the device tree or other means from vm context.
1138
1139For now the only implemented piece of information distributed here is an array
1140of 4 instructions that make up a hypercall.
1141
1142If any additional field gets added to this structure later on, a bit for that
1143additional piece of information will be set in the flags bitmap.
1144
Paul Bolle68ba6972011-02-15 00:05:59 +010011454.48 KVM_ASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001146
1147Capability: KVM_CAP_DEVICE_ASSIGNMENT
1148Architectures: x86 ia64
1149Type: vm ioctl
1150Parameters: struct kvm_assigned_pci_dev (in)
1151Returns: 0 on success, -1 on error
1152
1153Assigns a host PCI device to the VM.
1154
1155struct kvm_assigned_pci_dev {
1156 __u32 assigned_dev_id;
1157 __u32 busnr;
1158 __u32 devfn;
1159 __u32 flags;
1160 __u32 segnr;
1161 union {
1162 __u32 reserved[11];
1163 };
1164};
1165
1166The PCI device is specified by the triple segnr, busnr, and devfn.
1167Identification in succeeding service requests is done via assigned_dev_id. The
1168following flags are specified:
1169
1170/* Depends on KVM_CAP_IOMMU */
1171#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
Jan Kiszka07700a92012-02-28 14:19:54 +01001172/* The following two depend on KVM_CAP_PCI_2_3 */
1173#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
1174#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
1175
1176If KVM_DEV_ASSIGN_PCI_2_3 is set, the kernel will manage legacy INTx interrupts
1177via the PCI-2.3-compliant device-level mask, thus enable IRQ sharing with other
1178assigned devices or host devices. KVM_DEV_ASSIGN_MASK_INTX specifies the
1179guest's view on the INTx mask, see KVM_ASSIGN_SET_INTX_MASK for details.
Jan Kiszka49f48172010-11-16 22:30:07 +01001180
Alex Williamson42387372011-12-20 21:59:03 -07001181The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
1182isolation of the device. Usages not specifying this flag are deprecated.
1183
Alex Williamson3d27e232011-12-20 21:59:09 -07001184Only PCI header type 0 devices with PCI BAR resources are supported by
1185device assignment. The user requesting this ioctl must have read/write
1186access to the PCI sysfs resource files associated with the device.
1187
Paul Bolle68ba6972011-02-15 00:05:59 +010011884.49 KVM_DEASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001189
1190Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1191Architectures: x86 ia64
1192Type: vm ioctl
1193Parameters: struct kvm_assigned_pci_dev (in)
1194Returns: 0 on success, -1 on error
1195
1196Ends PCI device assignment, releasing all associated resources.
1197
1198See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1199used in kvm_assigned_pci_dev to identify the device.
1200
Paul Bolle68ba6972011-02-15 00:05:59 +010012014.50 KVM_ASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001202
1203Capability: KVM_CAP_ASSIGN_DEV_IRQ
1204Architectures: x86 ia64
1205Type: vm ioctl
1206Parameters: struct kvm_assigned_irq (in)
1207Returns: 0 on success, -1 on error
1208
1209Assigns an IRQ to a passed-through device.
1210
1211struct kvm_assigned_irq {
1212 __u32 assigned_dev_id;
Jan Kiszka91e3d712011-06-03 08:51:05 +02001213 __u32 host_irq; /* ignored (legacy field) */
Jan Kiszka49f48172010-11-16 22:30:07 +01001214 __u32 guest_irq;
1215 __u32 flags;
1216 union {
Jan Kiszka49f48172010-11-16 22:30:07 +01001217 __u32 reserved[12];
1218 };
1219};
1220
1221The following flags are defined:
1222
1223#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
1224#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
1225#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
1226
1227#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
1228#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
1229#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
1230
1231It is not valid to specify multiple types per host or guest IRQ. However, the
1232IRQ type of host and guest can differ or can even be null.
1233
Paul Bolle68ba6972011-02-15 00:05:59 +010012344.51 KVM_DEASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001235
1236Capability: KVM_CAP_ASSIGN_DEV_IRQ
1237Architectures: x86 ia64
1238Type: vm ioctl
1239Parameters: struct kvm_assigned_irq (in)
1240Returns: 0 on success, -1 on error
1241
1242Ends an IRQ assignment to a passed-through device.
1243
1244See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1245by assigned_dev_id, flags must correspond to the IRQ type specified on
1246KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1247
Paul Bolle68ba6972011-02-15 00:05:59 +010012484.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001249
1250Capability: KVM_CAP_IRQ_ROUTING
1251Architectures: x86 ia64
1252Type: vm ioctl
1253Parameters: struct kvm_irq_routing (in)
1254Returns: 0 on success, -1 on error
1255
1256Sets the GSI routing table entries, overwriting any previously set entries.
1257
1258struct kvm_irq_routing {
1259 __u32 nr;
1260 __u32 flags;
1261 struct kvm_irq_routing_entry entries[0];
1262};
1263
1264No flags are specified so far, the corresponding field must be set to zero.
1265
1266struct kvm_irq_routing_entry {
1267 __u32 gsi;
1268 __u32 type;
1269 __u32 flags;
1270 __u32 pad;
1271 union {
1272 struct kvm_irq_routing_irqchip irqchip;
1273 struct kvm_irq_routing_msi msi;
1274 __u32 pad[8];
1275 } u;
1276};
1277
1278/* gsi routing entry types */
1279#define KVM_IRQ_ROUTING_IRQCHIP 1
1280#define KVM_IRQ_ROUTING_MSI 2
1281
1282No flags are specified so far, the corresponding field must be set to zero.
1283
1284struct kvm_irq_routing_irqchip {
1285 __u32 irqchip;
1286 __u32 pin;
1287};
1288
1289struct kvm_irq_routing_msi {
1290 __u32 address_lo;
1291 __u32 address_hi;
1292 __u32 data;
1293 __u32 pad;
1294};
1295
Paul Bolle68ba6972011-02-15 00:05:59 +010012964.53 KVM_ASSIGN_SET_MSIX_NR
Jan Kiszka49f48172010-11-16 22:30:07 +01001297
1298Capability: KVM_CAP_DEVICE_MSIX
1299Architectures: x86 ia64
1300Type: vm ioctl
1301Parameters: struct kvm_assigned_msix_nr (in)
1302Returns: 0 on success, -1 on error
1303
Jan Kiszka58f09642011-06-11 12:24:24 +02001304Set the number of MSI-X interrupts for an assigned device. The number is
1305reset again by terminating the MSI-X assignment of the device via
1306KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
1307point will fail.
Jan Kiszka49f48172010-11-16 22:30:07 +01001308
1309struct kvm_assigned_msix_nr {
1310 __u32 assigned_dev_id;
1311 __u16 entry_nr;
1312 __u16 padding;
1313};
1314
1315#define KVM_MAX_MSIX_PER_DEV 256
1316
Paul Bolle68ba6972011-02-15 00:05:59 +010013174.54 KVM_ASSIGN_SET_MSIX_ENTRY
Jan Kiszka49f48172010-11-16 22:30:07 +01001318
1319Capability: KVM_CAP_DEVICE_MSIX
1320Architectures: x86 ia64
1321Type: vm ioctl
1322Parameters: struct kvm_assigned_msix_entry (in)
1323Returns: 0 on success, -1 on error
1324
1325Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1326the GSI vector to zero means disabling the interrupt.
1327
1328struct kvm_assigned_msix_entry {
1329 __u32 assigned_dev_id;
1330 __u32 gsi;
1331 __u16 entry; /* The index of entry in the MSI-X table */
1332 __u16 padding[3];
1333};
1334
Joerg Roedel92a1f122011-03-25 09:44:51 +010013354.54 KVM_SET_TSC_KHZ
1336
1337Capability: KVM_CAP_TSC_CONTROL
1338Architectures: x86
1339Type: vcpu ioctl
1340Parameters: virtual tsc_khz
1341Returns: 0 on success, -1 on error
1342
1343Specifies the tsc frequency for the virtual machine. The unit of the
1344frequency is KHz.
1345
13464.55 KVM_GET_TSC_KHZ
1347
1348Capability: KVM_CAP_GET_TSC_KHZ
1349Architectures: x86
1350Type: vcpu ioctl
1351Parameters: none
1352Returns: virtual tsc-khz on success, negative value on error
1353
1354Returns the tsc frequency of the guest. The unit of the return value is
1355KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1356error.
1357
Avi Kivitye7677932011-05-11 08:30:51 -040013584.56 KVM_GET_LAPIC
1359
1360Capability: KVM_CAP_IRQCHIP
1361Architectures: x86
1362Type: vcpu ioctl
1363Parameters: struct kvm_lapic_state (out)
1364Returns: 0 on success, -1 on error
1365
1366#define KVM_APIC_REG_SIZE 0x400
1367struct kvm_lapic_state {
1368 char regs[KVM_APIC_REG_SIZE];
1369};
1370
1371Reads the Local APIC registers and copies them into the input argument. The
1372data format and layout are the same as documented in the architecture manual.
1373
13744.57 KVM_SET_LAPIC
1375
1376Capability: KVM_CAP_IRQCHIP
1377Architectures: x86
1378Type: vcpu ioctl
1379Parameters: struct kvm_lapic_state (in)
1380Returns: 0 on success, -1 on error
1381
1382#define KVM_APIC_REG_SIZE 0x400
1383struct kvm_lapic_state {
1384 char regs[KVM_APIC_REG_SIZE];
1385};
1386
1387Copies the input argument into the the Local APIC registers. The data format
1388and layout are the same as documented in the architecture manual.
1389
Jan Kiszka7f4382e2011-06-02 16:16:20 +020013904.58 KVM_IOEVENTFD
Sasha Levin55399a02011-05-28 14:12:30 +03001391
1392Capability: KVM_CAP_IOEVENTFD
1393Architectures: all
1394Type: vm ioctl
1395Parameters: struct kvm_ioeventfd (in)
1396Returns: 0 on success, !0 on error
1397
1398This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1399within the guest. A guest write in the registered address will signal the
1400provided event instead of triggering an exit.
1401
1402struct kvm_ioeventfd {
1403 __u64 datamatch;
1404 __u64 addr; /* legal pio/mmio address */
1405 __u32 len; /* 1, 2, 4, or 8 bytes */
1406 __s32 fd;
1407 __u32 flags;
1408 __u8 pad[36];
1409};
1410
1411The following flags are defined:
1412
1413#define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1414#define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1415#define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
1416
1417If datamatch flag is set, the event will be signaled only if the written value
1418to the registered address is equal to datamatch in struct kvm_ioeventfd.
1419
Scott Wooddc83b8b2011-08-18 15:25:21 -050014204.59 KVM_DIRTY_TLB
1421
1422Capability: KVM_CAP_SW_TLB
1423Architectures: ppc
1424Type: vcpu ioctl
1425Parameters: struct kvm_dirty_tlb (in)
1426Returns: 0 on success, -1 on error
1427
1428struct kvm_dirty_tlb {
1429 __u64 bitmap;
1430 __u32 num_dirty;
1431};
1432
1433This must be called whenever userspace has changed an entry in the shared
1434TLB, prior to calling KVM_RUN on the associated vcpu.
1435
1436The "bitmap" field is the userspace address of an array. This array
1437consists of a number of bits, equal to the total number of TLB entries as
1438determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
1439nearest multiple of 64.
1440
1441Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
1442array.
1443
1444The array is little-endian: the bit 0 is the least significant bit of the
1445first byte, bit 8 is the least significant bit of the second byte, etc.
1446This avoids any complications with differing word sizes.
1447
1448The "num_dirty" field is a performance hint for KVM to determine whether it
1449should skip processing the bitmap and just invalidate everything. It must
1450be set to the number of set bits in the bitmap.
1451
Jan Kiszka07700a92012-02-28 14:19:54 +010014524.60 KVM_ASSIGN_SET_INTX_MASK
1453
1454Capability: KVM_CAP_PCI_2_3
1455Architectures: x86
1456Type: vm ioctl
1457Parameters: struct kvm_assigned_pci_dev (in)
1458Returns: 0 on success, -1 on error
1459
1460Allows userspace to mask PCI INTx interrupts from the assigned device. The
1461kernel will not deliver INTx interrupts to the guest between setting and
1462clearing of KVM_ASSIGN_SET_INTX_MASK via this interface. This enables use of
1463and emulation of PCI 2.3 INTx disable command register behavior.
1464
1465This may be used for both PCI 2.3 devices supporting INTx disable natively and
1466older devices lacking this support. Userspace is responsible for emulating the
1467read value of the INTx disable bit in the guest visible PCI command register.
1468When modifying the INTx disable state, userspace should precede updating the
1469physical device command register by calling this ioctl to inform the kernel of
1470the new intended INTx mask state.
1471
1472Note that the kernel uses the device INTx disable bit to internally manage the
1473device interrupt state for PCI 2.3 devices. Reads of this register may
1474therefore not match the expected value. Writes should always use the guest
1475intended INTx disable value rather than attempting to read-copy-update the
1476current physical device state. Races between user and kernel updates to the
1477INTx disable bit are handled lazily in the kernel. It's possible the device
1478may generate unintended interrupts, but they will not be injected into the
1479guest.
1480
1481See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1482by assigned_dev_id. In the flags field, only KVM_DEV_ASSIGN_MASK_INTX is
1483evaluated.
1484
David Gibson54738c02011-06-29 00:22:41 +000014854.62 KVM_CREATE_SPAPR_TCE
1486
1487Capability: KVM_CAP_SPAPR_TCE
1488Architectures: powerpc
1489Type: vm ioctl
1490Parameters: struct kvm_create_spapr_tce (in)
1491Returns: file descriptor for manipulating the created TCE table
1492
1493This creates a virtual TCE (translation control entry) table, which
1494is an IOMMU for PAPR-style virtual I/O. It is used to translate
1495logical addresses used in virtual I/O into guest physical addresses,
1496and provides a scatter/gather capability for PAPR virtual I/O.
1497
1498/* for KVM_CAP_SPAPR_TCE */
1499struct kvm_create_spapr_tce {
1500 __u64 liobn;
1501 __u32 window_size;
1502};
1503
1504The liobn field gives the logical IO bus number for which to create a
1505TCE table. The window_size field specifies the size of the DMA window
1506which this TCE table will translate - the table will contain one 64
1507bit TCE entry for every 4kiB of the DMA window.
1508
1509When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1510table has been created using this ioctl(), the kernel will handle it
1511in real mode, updating the TCE table. H_PUT_TCE calls for other
1512liobns will cause a vm exit and must be handled by userspace.
1513
1514The return value is a file descriptor which can be passed to mmap(2)
1515to map the created TCE table into userspace. This lets userspace read
1516the entries written by kernel-handled H_PUT_TCE calls, and also lets
1517userspace update the TCE table directly which is useful in some
1518circumstances.
1519
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +000015204.63 KVM_ALLOCATE_RMA
1521
1522Capability: KVM_CAP_PPC_RMA
1523Architectures: powerpc
1524Type: vm ioctl
1525Parameters: struct kvm_allocate_rma (out)
1526Returns: file descriptor for mapping the allocated RMA
1527
1528This allocates a Real Mode Area (RMA) from the pool allocated at boot
1529time by the kernel. An RMA is a physically-contiguous, aligned region
1530of memory used on older POWER processors to provide the memory which
1531will be accessed by real-mode (MMU off) accesses in a KVM guest.
1532POWER processors support a set of sizes for the RMA that usually
1533includes 64MB, 128MB, 256MB and some larger powers of two.
1534
1535/* for KVM_ALLOCATE_RMA */
1536struct kvm_allocate_rma {
1537 __u64 rma_size;
1538};
1539
1540The return value is a file descriptor which can be passed to mmap(2)
1541to map the allocated RMA into userspace. The mapped area can then be
1542passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1543RMA for a virtual machine. The size of the RMA in bytes (which is
1544fixed at host kernel boot time) is returned in the rma_size field of
1545the argument structure.
1546
1547The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1548is supported; 2 if the processor requires all virtual machines to have
1549an RMA, or 1 if the processor can use an RMA but doesn't require it,
1550because it supports the Virtual RMA (VRMA) facility.
1551
Avi Kivity3f745f12011-12-07 12:42:47 +020015524.64 KVM_NMI
1553
1554Capability: KVM_CAP_USER_NMI
1555Architectures: x86
1556Type: vcpu ioctl
1557Parameters: none
1558Returns: 0 on success, -1 on error
1559
1560Queues an NMI on the thread's vcpu. Note this is well defined only
1561when KVM_CREATE_IRQCHIP has not been called, since this is an interface
1562between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
1563has been called, this interface is completely emulated within the kernel.
1564
1565To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
1566following algorithm:
1567
1568 - pause the vpcu
1569 - read the local APIC's state (KVM_GET_LAPIC)
1570 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
1571 - if so, issue KVM_NMI
1572 - resume the vcpu
1573
1574Some guests configure the LINT1 NMI input to cause a panic, aiding in
1575debugging.
1576
Alexander Grafe24ed812011-09-14 10:02:41 +020015774.65 KVM_S390_UCAS_MAP
Carsten Otte27e03932012-01-04 10:25:21 +01001578
1579Capability: KVM_CAP_S390_UCONTROL
1580Architectures: s390
1581Type: vcpu ioctl
1582Parameters: struct kvm_s390_ucas_mapping (in)
1583Returns: 0 in case of success
1584
1585The parameter is defined like this:
1586 struct kvm_s390_ucas_mapping {
1587 __u64 user_addr;
1588 __u64 vcpu_addr;
1589 __u64 length;
1590 };
1591
1592This ioctl maps the memory at "user_addr" with the length "length" to
1593the vcpu's address space starting at "vcpu_addr". All parameters need to
1594be alligned by 1 megabyte.
1595
Alexander Grafe24ed812011-09-14 10:02:41 +020015964.66 KVM_S390_UCAS_UNMAP
Carsten Otte27e03932012-01-04 10:25:21 +01001597
1598Capability: KVM_CAP_S390_UCONTROL
1599Architectures: s390
1600Type: vcpu ioctl
1601Parameters: struct kvm_s390_ucas_mapping (in)
1602Returns: 0 in case of success
1603
1604The parameter is defined like this:
1605 struct kvm_s390_ucas_mapping {
1606 __u64 user_addr;
1607 __u64 vcpu_addr;
1608 __u64 length;
1609 };
1610
1611This ioctl unmaps the memory in the vcpu's address space starting at
1612"vcpu_addr" with the length "length". The field "user_addr" is ignored.
1613All parameters need to be alligned by 1 megabyte.
1614
Alexander Grafe24ed812011-09-14 10:02:41 +020016154.67 KVM_S390_VCPU_FAULT
Carsten Otteccc79102012-01-04 10:25:26 +01001616
1617Capability: KVM_CAP_S390_UCONTROL
1618Architectures: s390
1619Type: vcpu ioctl
1620Parameters: vcpu absolute address (in)
1621Returns: 0 in case of success
1622
1623This call creates a page table entry on the virtual cpu's address space
1624(for user controlled virtual machines) or the virtual machine's address
1625space (for regular virtual machines). This only works for minor faults,
1626thus it's recommended to access subject memory page via the user page
1627table upfront. This is useful to handle validity intercepts for user
1628controlled virtual machines to fault in the virtual cpu's lowcore pages
1629prior to calling the KVM_RUN ioctl.
1630
Alexander Grafe24ed812011-09-14 10:02:41 +020016314.68 KVM_SET_ONE_REG
1632
1633Capability: KVM_CAP_ONE_REG
1634Architectures: all
1635Type: vcpu ioctl
1636Parameters: struct kvm_one_reg (in)
1637Returns: 0 on success, negative value on failure
1638
1639struct kvm_one_reg {
1640 __u64 id;
1641 __u64 addr;
1642};
1643
1644Using this ioctl, a single vcpu register can be set to a specific value
1645defined by user space with the passed in struct kvm_one_reg, where id
1646refers to the register identifier as described below and addr is a pointer
1647to a variable with the respective size. There can be architecture agnostic
1648and architecture specific registers. Each have their own range of operation
1649and their own constants and width. To keep track of the implemented
1650registers, find a list below:
1651
1652 Arch | Register | Width (bits)
1653 | |
Alexander Graf1022fc32011-09-14 21:45:23 +02001654 PPC | KVM_REG_PPC_HIOR | 64
Alexander Grafe24ed812011-09-14 10:02:41 +02001655
16564.69 KVM_GET_ONE_REG
1657
1658Capability: KVM_CAP_ONE_REG
1659Architectures: all
1660Type: vcpu ioctl
1661Parameters: struct kvm_one_reg (in and out)
1662Returns: 0 on success, negative value on failure
1663
1664This ioctl allows to receive the value of a single register implemented
1665in a vcpu. The register to read is indicated by the "id" field of the
1666kvm_one_reg struct passed in. On success, the register value can be found
1667at the memory location pointed to by "addr".
1668
1669The list of registers accessible using this interface is identical to the
1670list in 4.64.
1671
Avi Kivity9c1b96e2009-06-09 12:37:58 +030016725. The kvm_run structure
1673
1674Application code obtains a pointer to the kvm_run structure by
1675mmap()ing a vcpu fd. From that point, application code can control
1676execution by changing fields in kvm_run prior to calling the KVM_RUN
1677ioctl, and obtain information about the reason KVM_RUN returned by
1678looking up structure members.
1679
1680struct kvm_run {
1681 /* in */
1682 __u8 request_interrupt_window;
1683
1684Request that KVM_RUN return when it becomes possible to inject external
1685interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1686
1687 __u8 padding1[7];
1688
1689 /* out */
1690 __u32 exit_reason;
1691
1692When KVM_RUN has returned successfully (return value 0), this informs
1693application code why KVM_RUN has returned. Allowable values for this
1694field are detailed below.
1695
1696 __u8 ready_for_interrupt_injection;
1697
1698If request_interrupt_window has been specified, this field indicates
1699an interrupt can be injected now with KVM_INTERRUPT.
1700
1701 __u8 if_flag;
1702
1703The value of the current interrupt flag. Only valid if in-kernel
1704local APIC is not used.
1705
1706 __u8 padding2[2];
1707
1708 /* in (pre_kvm_run), out (post_kvm_run) */
1709 __u64 cr8;
1710
1711The value of the cr8 register. Only valid if in-kernel local APIC is
1712not used. Both input and output.
1713
1714 __u64 apic_base;
1715
1716The value of the APIC BASE msr. Only valid if in-kernel local
1717APIC is not used. Both input and output.
1718
1719 union {
1720 /* KVM_EXIT_UNKNOWN */
1721 struct {
1722 __u64 hardware_exit_reason;
1723 } hw;
1724
1725If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1726reasons. Further architecture-specific information is available in
1727hardware_exit_reason.
1728
1729 /* KVM_EXIT_FAIL_ENTRY */
1730 struct {
1731 __u64 hardware_entry_failure_reason;
1732 } fail_entry;
1733
1734If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1735to unknown reasons. Further architecture-specific information is
1736available in hardware_entry_failure_reason.
1737
1738 /* KVM_EXIT_EXCEPTION */
1739 struct {
1740 __u32 exception;
1741 __u32 error_code;
1742 } ex;
1743
1744Unused.
1745
1746 /* KVM_EXIT_IO */
1747 struct {
1748#define KVM_EXIT_IO_IN 0
1749#define KVM_EXIT_IO_OUT 1
1750 __u8 direction;
1751 __u8 size; /* bytes */
1752 __u16 port;
1753 __u32 count;
1754 __u64 data_offset; /* relative to kvm_run start */
1755 } io;
1756
Wu Fengguang20448922009-12-24 09:04:16 +08001757If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001758executed a port I/O instruction which could not be satisfied by kvm.
1759data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1760where kvm expects application code to place the data for the next
Wu Fengguang20448922009-12-24 09:04:16 +08001761KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001762
1763 struct {
1764 struct kvm_debug_exit_arch arch;
1765 } debug;
1766
1767Unused.
1768
1769 /* KVM_EXIT_MMIO */
1770 struct {
1771 __u64 phys_addr;
1772 __u8 data[8];
1773 __u32 len;
1774 __u8 is_write;
1775 } mmio;
1776
Wu Fengguang20448922009-12-24 09:04:16 +08001777If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001778executed a memory-mapped I/O instruction which could not be satisfied
1779by kvm. The 'data' member contains the written data if 'is_write' is
1780true, and should be filled by application code otherwise.
1781
Alexander Grafad0a0482010-03-24 21:48:30 +01001782NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1783operations are complete (and guest state is consistent) only after userspace
1784has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02001785incomplete operations and then check for pending signals. Userspace
1786can re-enter the guest with an unmasked signal pending to complete
1787pending operations.
1788
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001789 /* KVM_EXIT_HYPERCALL */
1790 struct {
1791 __u64 nr;
1792 __u64 args[6];
1793 __u64 ret;
1794 __u32 longmode;
1795 __u32 pad;
1796 } hypercall;
1797
Avi Kivity647dc492010-04-01 14:39:21 +03001798Unused. This was once used for 'hypercall to userspace'. To implement
1799such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1800Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001801
1802 /* KVM_EXIT_TPR_ACCESS */
1803 struct {
1804 __u64 rip;
1805 __u32 is_write;
1806 __u32 pad;
1807 } tpr_access;
1808
1809To be documented (KVM_TPR_ACCESS_REPORTING).
1810
1811 /* KVM_EXIT_S390_SIEIC */
1812 struct {
1813 __u8 icptcode;
1814 __u64 mask; /* psw upper half */
1815 __u64 addr; /* psw lower half */
1816 __u16 ipa;
1817 __u32 ipb;
1818 } s390_sieic;
1819
1820s390 specific.
1821
1822 /* KVM_EXIT_S390_RESET */
1823#define KVM_S390_RESET_POR 1
1824#define KVM_S390_RESET_CLEAR 2
1825#define KVM_S390_RESET_SUBSYSTEM 4
1826#define KVM_S390_RESET_CPU_INIT 8
1827#define KVM_S390_RESET_IPL 16
1828 __u64 s390_reset_flags;
1829
1830s390 specific.
1831
Carsten Ottee168bf82012-01-04 10:25:22 +01001832 /* KVM_EXIT_S390_UCONTROL */
1833 struct {
1834 __u64 trans_exc_code;
1835 __u32 pgm_code;
1836 } s390_ucontrol;
1837
1838s390 specific. A page fault has occurred for a user controlled virtual
1839machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
1840resolved by the kernel.
1841The program code and the translation exception code that were placed
1842in the cpu's lowcore are presented here as defined by the z Architecture
1843Principles of Operation Book in the Chapter for Dynamic Address Translation
1844(DAT)
1845
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001846 /* KVM_EXIT_DCR */
1847 struct {
1848 __u32 dcrn;
1849 __u32 data;
1850 __u8 is_write;
1851 } dcr;
1852
1853powerpc specific.
1854
Alexander Grafad0a0482010-03-24 21:48:30 +01001855 /* KVM_EXIT_OSI */
1856 struct {
1857 __u64 gprs[32];
1858 } osi;
1859
1860MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1861hypercalls and exit with this exit struct that contains all the guest gprs.
1862
1863If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1864Userspace can now handle the hypercall and when it's done modify the gprs as
1865necessary. Upon guest entry all guest GPRs will then be replaced by the values
1866in this struct.
1867
Paul Mackerrasde56a942011-06-29 00:21:34 +00001868 /* KVM_EXIT_PAPR_HCALL */
1869 struct {
1870 __u64 nr;
1871 __u64 ret;
1872 __u64 args[9];
1873 } papr_hcall;
1874
1875This is used on 64-bit PowerPC when emulating a pSeries partition,
1876e.g. with the 'pseries' machine type in qemu. It occurs when the
1877guest does a hypercall using the 'sc 1' instruction. The 'nr' field
1878contains the hypercall number (from the guest R3), and 'args' contains
1879the arguments (from the guest R4 - R12). Userspace should put the
1880return code in 'ret' and any extra returned values in args[].
1881The possible hypercalls are defined in the Power Architecture Platform
1882Requirements (PAPR) document available from www.power.org (free
1883developer registration required to access it).
1884
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001885 /* Fix the size of the union. */
1886 char padding[256];
1887 };
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01001888
1889 /*
1890 * shared registers between kvm and userspace.
1891 * kvm_valid_regs specifies the register classes set by the host
1892 * kvm_dirty_regs specified the register classes dirtied by userspace
1893 * struct kvm_sync_regs is architecture specific, as well as the
1894 * bits for kvm_valid_regs and kvm_dirty_regs
1895 */
1896 __u64 kvm_valid_regs;
1897 __u64 kvm_dirty_regs;
1898 union {
1899 struct kvm_sync_regs regs;
1900 char padding[1024];
1901 } s;
1902
1903If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
1904certain guest registers without having to call SET/GET_*REGS. Thus we can
1905avoid some system call overhead if userspace has to handle the exit.
1906Userspace can query the validity of the structure by checking
1907kvm_valid_regs for specific bits. These bits are architecture specific
1908and usually define the validity of a groups of registers. (e.g. one bit
1909 for general purpose registers)
1910
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001911};
Alexander Graf821246a2011-08-31 10:58:55 +02001912
19136. Capabilities that can be enabled
1914
1915There are certain capabilities that change the behavior of the virtual CPU when
1916enabled. To enable them, please see section 4.37. Below you can find a list of
1917capabilities and what their effect on the vCPU is when enabling them.
1918
1919The following information is provided along with the description:
1920
1921 Architectures: which instruction set architectures provide this ioctl.
1922 x86 includes both i386 and x86_64.
1923
1924 Parameters: what parameters are accepted by the capability.
1925
1926 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
1927 are not detailed, but errors with specific meanings are.
1928
19296.1 KVM_CAP_PPC_OSI
1930
1931Architectures: ppc
1932Parameters: none
1933Returns: 0 on success; -1 on error
1934
1935This capability enables interception of OSI hypercalls that otherwise would
1936be treated as normal system calls to be injected into the guest. OSI hypercalls
1937were invented by Mac-on-Linux to have a standardized communication mechanism
1938between the guest and the host.
1939
1940When this capability is enabled, KVM_EXIT_OSI can occur.
1941
19426.2 KVM_CAP_PPC_PAPR
1943
1944Architectures: ppc
1945Parameters: none
1946Returns: 0 on success; -1 on error
1947
1948This capability enables interception of PAPR hypercalls. PAPR hypercalls are
1949done using the hypercall instruction "sc 1".
1950
1951It also sets the guest privilege level to "supervisor" mode. Usually the guest
1952runs in "hypervisor" privilege mode with a few missing features.
1953
1954In addition to the above, it changes the semantics of SDR1. In this mode, the
1955HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
1956HTAB invisible to the guest.
1957
1958When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
Scott Wooddc83b8b2011-08-18 15:25:21 -05001959
19606.3 KVM_CAP_SW_TLB
1961
1962Architectures: ppc
1963Parameters: args[0] is the address of a struct kvm_config_tlb
1964Returns: 0 on success; -1 on error
1965
1966struct kvm_config_tlb {
1967 __u64 params;
1968 __u64 array;
1969 __u32 mmu_type;
1970 __u32 array_len;
1971};
1972
1973Configures the virtual CPU's TLB array, establishing a shared memory area
1974between userspace and KVM. The "params" and "array" fields are userspace
1975addresses of mmu-type-specific data structures. The "array_len" field is an
1976safety mechanism, and should be set to the size in bytes of the memory that
1977userspace has reserved for the array. It must be at least the size dictated
1978by "mmu_type" and "params".
1979
1980While KVM_RUN is active, the shared region is under control of KVM. Its
1981contents are undefined, and any modification by userspace results in
1982boundedly undefined behavior.
1983
1984On return from KVM_RUN, the shared region will reflect the current state of
1985the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
1986to tell KVM which entries have been changed, prior to calling KVM_RUN again
1987on this vcpu.
1988
1989For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
1990 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
1991 - The "array" field points to an array of type "struct
1992 kvm_book3e_206_tlb_entry".
1993 - The array consists of all entries in the first TLB, followed by all
1994 entries in the second TLB.
1995 - Within a TLB, entries are ordered first by increasing set number. Within a
1996 set, entries are ordered by way (increasing ESEL).
1997 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
1998 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
1999 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
2000 hardware ignores this value for TLB0.