blob: 4df9af4f6132e46b09f1f78c3b00db5dbb8c5c38 [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
98Parameters: none
99Returns: 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.
106
1074.3 KVM_GET_MSR_INDEX_LIST
108
109Capability: basic
110Architectures: x86
111Type: system
112Parameters: struct kvm_msr_list (in/out)
113Returns: 0 on success; -1 on error
114Errors:
115 E2BIG: the msr index list is to be to fit in the array specified by
116 the user.
117
118struct kvm_msr_list {
119 __u32 nmsrs; /* number of msrs in entries */
120 __u32 indices[0];
121};
122
123This ioctl returns the guest msrs that are supported. The list varies
124by kvm version and host processor, but does not change otherwise. The
125user fills in the size of the indices array in nmsrs, and in return
126kvm adjusts nmsrs to reflect the actual number of msrs and fills in
127the indices array with their numbers.
128
Avi Kivity2e2602c2010-07-07 14:09:39 +0300129Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
130not returned in the MSR list, as different vcpus can have a different number
131of banks, as set via the KVM_X86_SETUP_MCE ioctl.
132
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001334.4 KVM_CHECK_EXTENSION
134
135Capability: basic
136Architectures: all
137Type: system ioctl
138Parameters: extension identifier (KVM_CAP_*)
139Returns: 0 if unsupported; 1 (or some other positive integer) if supported
140
141The API allows the application to query about extensions to the core
142kvm API. Userspace passes an extension identifier (an integer) and
143receives an integer that describes the extension availability.
144Generally 0 means no and 1 means yes, but some extensions may report
145additional information in the integer return value.
146
1474.5 KVM_GET_VCPU_MMAP_SIZE
148
149Capability: basic
150Architectures: all
151Type: system ioctl
152Parameters: none
153Returns: size of vcpu mmap area, in bytes
154
155The KVM_RUN ioctl (cf.) communicates with userspace via a shared
156memory region. This ioctl returns the size of that region. See the
157KVM_RUN documentation for details.
158
1594.6 KVM_SET_MEMORY_REGION
160
161Capability: basic
162Architectures: all
163Type: vm ioctl
164Parameters: struct kvm_memory_region (in)
165Returns: 0 on success, -1 on error
166
Avi Kivityb74a07b2010-06-21 11:48:05 +0300167This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300168
Paul Bolle68ba6972011-02-15 00:05:59 +01001694.7 KVM_CREATE_VCPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300170
171Capability: basic
172Architectures: all
173Type: vm ioctl
174Parameters: vcpu id (apic id on x86)
175Returns: vcpu fd on success, -1 on error
176
177This API adds a vcpu to a virtual machine. The vcpu id is a small integer
Sasha Levin8c3ba332011-07-18 17:17:15 +0300178in the range [0, max_vcpus).
179
180The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
181the KVM_CHECK_EXTENSION ioctl() at run-time.
182The maximum possible value for max_vcpus can be retrieved using the
183KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
184
Pekka Enberg76d25402011-05-09 22:48:54 +0300185If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
186cpus max.
Sasha Levin8c3ba332011-07-18 17:17:15 +0300187If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
188same as the value returned from KVM_CAP_NR_VCPUS.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300189
Paul Mackerras371fefd2011-06-29 00:23:08 +0000190On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
191threads in one or more virtual CPU cores. (This is because the
192hardware requires all the hardware threads in a CPU core to be in the
193same partition.) The KVM_CAP_PPC_SMT capability indicates the number
194of vcpus per virtual core (vcore). The vcore id is obtained by
195dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
196given vcore will always be in the same physical core as each other
197(though that might be a different physical core from time to time).
198Userspace can control the threading (SMT) mode of the guest by its
199allocation of vcpu ids. For example, if userspace wants
200single-threaded guest vcpus, it should make all vcpu ids be a multiple
201of the number of vcpus per vcore.
202
Avi Kivity36442682011-08-29 16:27:08 +0300203On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
204threads in one or more virtual CPU cores. (This is because the
205hardware requires all the hardware threads in a CPU core to be in the
206same partition.) The KVM_CAP_PPC_SMT capability indicates the number
207of vcpus per virtual core (vcore). The vcore id is obtained by
208dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
209given vcore will always be in the same physical core as each other
210(though that might be a different physical core from time to time).
211Userspace can control the threading (SMT) mode of the guest by its
212allocation of vcpu ids. For example, if userspace wants
213single-threaded guest vcpus, it should make all vcpu ids be a multiple
214of the number of vcpus per vcore.
215
Paul Bolle68ba6972011-02-15 00:05:59 +01002164.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300217
218Capability: basic
219Architectures: x86
220Type: vm ioctl
221Parameters: struct kvm_dirty_log (in/out)
222Returns: 0 on success, -1 on error
223
224/* for KVM_GET_DIRTY_LOG */
225struct kvm_dirty_log {
226 __u32 slot;
227 __u32 padding;
228 union {
229 void __user *dirty_bitmap; /* one bit per page */
230 __u64 padding;
231 };
232};
233
234Given a memory slot, return a bitmap containing any pages dirtied
235since the last call to this ioctl. Bit 0 is the first page in the
236memory slot. Ensure the entire structure is cleared to avoid padding
237issues.
238
Paul Bolle68ba6972011-02-15 00:05:59 +01002394.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300240
241Capability: basic
242Architectures: x86
243Type: vm ioctl
244Parameters: struct kvm_memory_alias (in)
245Returns: 0 (success), -1 (error)
246
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300247This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300248
Paul Bolle68ba6972011-02-15 00:05:59 +01002494.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300250
251Capability: basic
252Architectures: all
253Type: vcpu ioctl
254Parameters: none
255Returns: 0 on success, -1 on error
256Errors:
257 EINTR: an unmasked signal is pending
258
259This ioctl is used to run a guest virtual cpu. While there are no
260explicit parameters, there is an implicit parameter block that can be
261obtained by mmap()ing the vcpu fd at offset 0, with the size given by
262KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
263kvm_run' (see below).
264
Paul Bolle68ba6972011-02-15 00:05:59 +01002654.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300266
267Capability: basic
268Architectures: all
269Type: vcpu ioctl
270Parameters: struct kvm_regs (out)
271Returns: 0 on success, -1 on error
272
273Reads the general purpose registers from the vcpu.
274
275/* x86 */
276struct kvm_regs {
277 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
278 __u64 rax, rbx, rcx, rdx;
279 __u64 rsi, rdi, rsp, rbp;
280 __u64 r8, r9, r10, r11;
281 __u64 r12, r13, r14, r15;
282 __u64 rip, rflags;
283};
284
Paul Bolle68ba6972011-02-15 00:05:59 +01002854.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300286
287Capability: basic
288Architectures: all
289Type: vcpu ioctl
290Parameters: struct kvm_regs (in)
291Returns: 0 on success, -1 on error
292
293Writes the general purpose registers into the vcpu.
294
295See KVM_GET_REGS for the data structure.
296
Paul Bolle68ba6972011-02-15 00:05:59 +01002974.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300298
299Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500300Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300301Type: vcpu ioctl
302Parameters: struct kvm_sregs (out)
303Returns: 0 on success, -1 on error
304
305Reads special registers from the vcpu.
306
307/* x86 */
308struct kvm_sregs {
309 struct kvm_segment cs, ds, es, fs, gs, ss;
310 struct kvm_segment tr, ldt;
311 struct kvm_dtable gdt, idt;
312 __u64 cr0, cr2, cr3, cr4, cr8;
313 __u64 efer;
314 __u64 apic_base;
315 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
316};
317
Scott Wood5ce941e2011-04-27 17:24:21 -0500318/* ppc -- see arch/powerpc/include/asm/kvm.h */
319
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300320interrupt_bitmap is a bitmap of pending external interrupts. At most
321one bit may be set. This interrupt has been acknowledged by the APIC
322but not yet injected into the cpu core.
323
Paul Bolle68ba6972011-02-15 00:05:59 +01003244.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300325
326Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500327Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300328Type: vcpu ioctl
329Parameters: struct kvm_sregs (in)
330Returns: 0 on success, -1 on error
331
332Writes special registers into the vcpu. See KVM_GET_SREGS for the
333data structures.
334
Paul Bolle68ba6972011-02-15 00:05:59 +01003354.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300336
337Capability: basic
338Architectures: x86
339Type: vcpu ioctl
340Parameters: struct kvm_translation (in/out)
341Returns: 0 on success, -1 on error
342
343Translates a virtual address according to the vcpu's current address
344translation mode.
345
346struct kvm_translation {
347 /* in */
348 __u64 linear_address;
349
350 /* out */
351 __u64 physical_address;
352 __u8 valid;
353 __u8 writeable;
354 __u8 usermode;
355 __u8 pad[5];
356};
357
Paul Bolle68ba6972011-02-15 00:05:59 +01003584.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300359
360Capability: basic
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200361Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300362Type: vcpu ioctl
363Parameters: struct kvm_interrupt (in)
364Returns: 0 on success, -1 on error
365
366Queues a hardware interrupt vector to be injected. This is only
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200367useful if in-kernel local APIC or equivalent is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300368
369/* for KVM_INTERRUPT */
370struct kvm_interrupt {
371 /* in */
372 __u32 irq;
373};
374
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200375X86:
376
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300377Note 'irq' is an interrupt vector, not an interrupt pin or line.
378
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200379PPC:
380
381Queues an external interrupt to be injected. This ioctl is overleaded
382with 3 different irq values:
383
384a) KVM_INTERRUPT_SET
385
386 This injects an edge type external interrupt into the guest once it's ready
387 to receive interrupts. When injected, the interrupt is done.
388
389b) KVM_INTERRUPT_UNSET
390
391 This unsets any pending interrupt.
392
393 Only available with KVM_CAP_PPC_UNSET_IRQ.
394
395c) KVM_INTERRUPT_SET_LEVEL
396
397 This injects a level type external interrupt into the guest context. The
398 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
399 is triggered.
400
401 Only available with KVM_CAP_PPC_IRQ_LEVEL.
402
403Note that any value for 'irq' other than the ones stated above is invalid
404and incurs unexpected behavior.
405
Paul Bolle68ba6972011-02-15 00:05:59 +01004064.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300407
408Capability: basic
409Architectures: none
410Type: vcpu ioctl
411Parameters: none)
412Returns: -1 on error
413
414Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
415
Paul Bolle68ba6972011-02-15 00:05:59 +01004164.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300417
418Capability: basic
419Architectures: x86
420Type: vcpu ioctl
421Parameters: struct kvm_msrs (in/out)
422Returns: 0 on success, -1 on error
423
424Reads model-specific registers from the vcpu. Supported msr indices can
425be obtained using KVM_GET_MSR_INDEX_LIST.
426
427struct kvm_msrs {
428 __u32 nmsrs; /* number of msrs in entries */
429 __u32 pad;
430
431 struct kvm_msr_entry entries[0];
432};
433
434struct kvm_msr_entry {
435 __u32 index;
436 __u32 reserved;
437 __u64 data;
438};
439
440Application code should set the 'nmsrs' member (which indicates the
441size of the entries array) and the 'index' member of each array entry.
442kvm will fill in the 'data' member.
443
Paul Bolle68ba6972011-02-15 00:05:59 +01004444.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300445
446Capability: basic
447Architectures: x86
448Type: vcpu ioctl
449Parameters: struct kvm_msrs (in)
450Returns: 0 on success, -1 on error
451
452Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
453data structures.
454
455Application code should set the 'nmsrs' member (which indicates the
456size of the entries array), and the 'index' and 'data' members of each
457array entry.
458
Paul Bolle68ba6972011-02-15 00:05:59 +01004594.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300460
461Capability: basic
462Architectures: x86
463Type: vcpu ioctl
464Parameters: struct kvm_cpuid (in)
465Returns: 0 on success, -1 on error
466
467Defines the vcpu responses to the cpuid instruction. Applications
468should use the KVM_SET_CPUID2 ioctl if available.
469
470
471struct kvm_cpuid_entry {
472 __u32 function;
473 __u32 eax;
474 __u32 ebx;
475 __u32 ecx;
476 __u32 edx;
477 __u32 padding;
478};
479
480/* for KVM_SET_CPUID */
481struct kvm_cpuid {
482 __u32 nent;
483 __u32 padding;
484 struct kvm_cpuid_entry entries[0];
485};
486
Paul Bolle68ba6972011-02-15 00:05:59 +01004874.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300488
489Capability: basic
490Architectures: x86
491Type: vcpu ioctl
492Parameters: struct kvm_signal_mask (in)
493Returns: 0 on success, -1 on error
494
495Defines which signals are blocked during execution of KVM_RUN. This
496signal mask temporarily overrides the threads signal mask. Any
497unblocked signal received (except SIGKILL and SIGSTOP, which retain
498their traditional behaviour) will cause KVM_RUN to return with -EINTR.
499
500Note the signal will only be delivered if not blocked by the original
501signal mask.
502
503/* for KVM_SET_SIGNAL_MASK */
504struct kvm_signal_mask {
505 __u32 len;
506 __u8 sigset[0];
507};
508
Paul Bolle68ba6972011-02-15 00:05:59 +01005094.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300510
511Capability: basic
512Architectures: x86
513Type: vcpu ioctl
514Parameters: struct kvm_fpu (out)
515Returns: 0 on success, -1 on error
516
517Reads the floating point state from the vcpu.
518
519/* for KVM_GET_FPU and KVM_SET_FPU */
520struct kvm_fpu {
521 __u8 fpr[8][16];
522 __u16 fcw;
523 __u16 fsw;
524 __u8 ftwx; /* in fxsave format */
525 __u8 pad1;
526 __u16 last_opcode;
527 __u64 last_ip;
528 __u64 last_dp;
529 __u8 xmm[16][16];
530 __u32 mxcsr;
531 __u32 pad2;
532};
533
Paul Bolle68ba6972011-02-15 00:05:59 +01005344.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300535
536Capability: basic
537Architectures: x86
538Type: vcpu ioctl
539Parameters: struct kvm_fpu (in)
540Returns: 0 on success, -1 on error
541
542Writes the floating point state to the vcpu.
543
544/* for KVM_GET_FPU and KVM_SET_FPU */
545struct kvm_fpu {
546 __u8 fpr[8][16];
547 __u16 fcw;
548 __u16 fsw;
549 __u8 ftwx; /* in fxsave format */
550 __u8 pad1;
551 __u16 last_opcode;
552 __u64 last_ip;
553 __u64 last_dp;
554 __u8 xmm[16][16];
555 __u32 mxcsr;
556 __u32 pad2;
557};
558
Paul Bolle68ba6972011-02-15 00:05:59 +01005594.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300560
561Capability: KVM_CAP_IRQCHIP
562Architectures: x86, ia64
563Type: vm ioctl
564Parameters: none
565Returns: 0 on success, -1 on error
566
567Creates an interrupt controller model in the kernel. On x86, creates a virtual
568ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
569local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
570only go to the IOAPIC. On ia64, a IOSAPIC is created.
571
Paul Bolle68ba6972011-02-15 00:05:59 +01005724.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300573
574Capability: KVM_CAP_IRQCHIP
575Architectures: x86, ia64
576Type: vm ioctl
577Parameters: struct kvm_irq_level
578Returns: 0 on success, -1 on error
579
580Sets the level of a GSI input to the interrupt controller model in the kernel.
581Requires that an interrupt controller model has been previously created with
582KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
583to be set to 1 and then back to 0.
584
585struct kvm_irq_level {
586 union {
587 __u32 irq; /* GSI */
588 __s32 status; /* not used for KVM_IRQ_LEVEL */
589 };
590 __u32 level; /* 0 or 1 */
591};
592
Paul Bolle68ba6972011-02-15 00:05:59 +01005934.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300594
595Capability: KVM_CAP_IRQCHIP
596Architectures: x86, ia64
597Type: vm ioctl
598Parameters: struct kvm_irqchip (in/out)
599Returns: 0 on success, -1 on error
600
601Reads the state of a kernel interrupt controller created with
602KVM_CREATE_IRQCHIP into a buffer provided by the caller.
603
604struct kvm_irqchip {
605 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
606 __u32 pad;
607 union {
608 char dummy[512]; /* reserving space */
609 struct kvm_pic_state pic;
610 struct kvm_ioapic_state ioapic;
611 } chip;
612};
613
Paul Bolle68ba6972011-02-15 00:05:59 +01006144.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300615
616Capability: KVM_CAP_IRQCHIP
617Architectures: x86, ia64
618Type: vm ioctl
619Parameters: struct kvm_irqchip (in)
620Returns: 0 on success, -1 on error
621
622Sets the state of a kernel interrupt controller created with
623KVM_CREATE_IRQCHIP from a buffer provided by the caller.
624
625struct kvm_irqchip {
626 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
627 __u32 pad;
628 union {
629 char dummy[512]; /* reserving space */
630 struct kvm_pic_state pic;
631 struct kvm_ioapic_state ioapic;
632 } chip;
633};
634
Paul Bolle68ba6972011-02-15 00:05:59 +01006354.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700636
637Capability: KVM_CAP_XEN_HVM
638Architectures: x86
639Type: vm ioctl
640Parameters: struct kvm_xen_hvm_config (in)
641Returns: 0 on success, -1 on error
642
643Sets the MSR that the Xen HVM guest uses to initialize its hypercall
644page, and provides the starting address and size of the hypercall
645blobs in userspace. When the guest writes the MSR, kvm copies one
646page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
647memory.
648
649struct kvm_xen_hvm_config {
650 __u32 flags;
651 __u32 msr;
652 __u64 blob_addr_32;
653 __u64 blob_addr_64;
654 __u8 blob_size_32;
655 __u8 blob_size_64;
656 __u8 pad2[30];
657};
658
Paul Bolle68ba6972011-02-15 00:05:59 +01006594.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400660
661Capability: KVM_CAP_ADJUST_CLOCK
662Architectures: x86
663Type: vm ioctl
664Parameters: struct kvm_clock_data (out)
665Returns: 0 on success, -1 on error
666
667Gets the current timestamp of kvmclock as seen by the current guest. In
668conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
669such as migration.
670
671struct kvm_clock_data {
672 __u64 clock; /* kvmclock current value */
673 __u32 flags;
674 __u32 pad[9];
675};
676
Paul Bolle68ba6972011-02-15 00:05:59 +01006774.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400678
679Capability: KVM_CAP_ADJUST_CLOCK
680Architectures: x86
681Type: vm ioctl
682Parameters: struct kvm_clock_data (in)
683Returns: 0 on success, -1 on error
684
Wu Fengguang20448922009-12-24 09:04:16 +0800685Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400686In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
687such as migration.
688
689struct kvm_clock_data {
690 __u64 clock; /* kvmclock current value */
691 __u32 flags;
692 __u32 pad[9];
693};
694
Paul Bolle68ba6972011-02-15 00:05:59 +01006954.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100696
697Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100698Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100699Architectures: x86
700Type: vm ioctl
701Parameters: struct kvm_vcpu_event (out)
702Returns: 0 on success, -1 on error
703
704Gets currently pending exceptions, interrupts, and NMIs as well as related
705states of the vcpu.
706
707struct kvm_vcpu_events {
708 struct {
709 __u8 injected;
710 __u8 nr;
711 __u8 has_error_code;
712 __u8 pad;
713 __u32 error_code;
714 } exception;
715 struct {
716 __u8 injected;
717 __u8 nr;
718 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100719 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100720 } interrupt;
721 struct {
722 __u8 injected;
723 __u8 pending;
724 __u8 masked;
725 __u8 pad;
726 } nmi;
727 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100728 __u32 flags;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100729};
730
Jan Kiszka48005f62010-02-19 19:38:07 +0100731KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
732interrupt.shadow contains a valid state. Otherwise, this field is undefined.
733
Paul Bolle68ba6972011-02-15 00:05:59 +01007344.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100735
736Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100737Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100738Architectures: x86
739Type: vm ioctl
740Parameters: struct kvm_vcpu_event (in)
741Returns: 0 on success, -1 on error
742
743Set pending exceptions, interrupts, and NMIs as well as related states of the
744vcpu.
745
746See KVM_GET_VCPU_EVENTS for the data structure.
747
Jan Kiszkadab4b912009-12-06 18:24:15 +0100748Fields that may be modified asynchronously by running VCPUs can be excluded
749from the update. These fields are nmi.pending and sipi_vector. Keep the
750corresponding bits in the flags field cleared to suppress overwriting the
751current in-kernel state. The bits are:
752
753KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
754KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
755
Jan Kiszka48005f62010-02-19 19:38:07 +0100756If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
757the flags field to signal that interrupt.shadow contains a valid state and
758shall be written into the VCPU.
759
Paul Bolle68ba6972011-02-15 00:05:59 +01007604.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100761
762Capability: KVM_CAP_DEBUGREGS
763Architectures: x86
764Type: vm ioctl
765Parameters: struct kvm_debugregs (out)
766Returns: 0 on success, -1 on error
767
768Reads debug registers from the vcpu.
769
770struct kvm_debugregs {
771 __u64 db[4];
772 __u64 dr6;
773 __u64 dr7;
774 __u64 flags;
775 __u64 reserved[9];
776};
777
Paul Bolle68ba6972011-02-15 00:05:59 +01007784.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100779
780Capability: KVM_CAP_DEBUGREGS
781Architectures: x86
782Type: vm ioctl
783Parameters: struct kvm_debugregs (in)
784Returns: 0 on success, -1 on error
785
786Writes debug registers into the vcpu.
787
788See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
789yet and must be cleared on entry.
790
Paul Bolle68ba6972011-02-15 00:05:59 +01007914.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +0200792
793Capability: KVM_CAP_USER_MEM
794Architectures: all
795Type: vm ioctl
796Parameters: struct kvm_userspace_memory_region (in)
797Returns: 0 on success, -1 on error
798
799struct kvm_userspace_memory_region {
800 __u32 slot;
801 __u32 flags;
802 __u64 guest_phys_addr;
803 __u64 memory_size; /* bytes */
804 __u64 userspace_addr; /* start of the userspace allocated memory */
805};
806
807/* for kvm_memory_region::flags */
808#define KVM_MEM_LOG_DIRTY_PAGES 1UL
809
810This ioctl allows the user to create or modify a guest physical memory
811slot. When changing an existing slot, it may be moved in the guest
812physical memory space, or its flags may be modified. It may not be
813resized. Slots may not overlap in guest physical address space.
814
815Memory for the region is taken starting at the address denoted by the
816field userspace_addr, which must point at user addressable memory for
817the entire memory slot size. Any object may back this memory, including
818anonymous memory, ordinary files, and hugetlbfs.
819
820It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
821be identical. This allows large pages in the guest to be backed by large
822pages in the host.
823
824The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
825instructs kvm to keep track of writes to memory within the slot. See
826the KVM_GET_DIRTY_LOG ioctl.
827
828When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
829region are automatically reflected into the guest. For example, an mmap()
830that affects the region will be made visible immediately. Another example
831is madvise(MADV_DROP).
832
833It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
834The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
835allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100836
Paul Bolle68ba6972011-02-15 00:05:59 +01008374.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +0200838
839Capability: KVM_CAP_SET_TSS_ADDR
840Architectures: x86
841Type: vm ioctl
842Parameters: unsigned long tss_address (in)
843Returns: 0 on success, -1 on error
844
845This ioctl defines the physical address of a three-page region in the guest
846physical address space. The region must be within the first 4GB of the
847guest physical address space and must not conflict with any memory slot
848or any mmio address. The guest may malfunction if it accesses this memory
849region.
850
851This ioctl is required on Intel-based hosts. This is needed on Intel hardware
852because of a quirk in the virtualization implementation (see the internals
853documentation when it pops into existence).
854
Paul Bolle68ba6972011-02-15 00:05:59 +01008554.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +0100856
857Capability: KVM_CAP_ENABLE_CAP
858Architectures: ppc
859Type: vcpu ioctl
860Parameters: struct kvm_enable_cap (in)
861Returns: 0 on success; -1 on error
862
863+Not all extensions are enabled by default. Using this ioctl the application
864can enable an extension, making it available to the guest.
865
866On systems that do not support this ioctl, it always fails. On systems that
867do support it, it only works for extensions that are supported for enablement.
868
869To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
870be used.
871
872struct kvm_enable_cap {
873 /* in */
874 __u32 cap;
875
876The capability that is supposed to get enabled.
877
878 __u32 flags;
879
880A bitfield indicating future enhancements. Has to be 0 for now.
881
882 __u64 args[4];
883
884Arguments for enabling a feature. If a feature needs initial values to
885function properly, this is the place to put them.
886
887 __u8 pad[64];
888};
889
Paul Bolle68ba6972011-02-15 00:05:59 +01008904.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300891
892Capability: KVM_CAP_MP_STATE
893Architectures: x86, ia64
894Type: vcpu ioctl
895Parameters: struct kvm_mp_state (out)
896Returns: 0 on success; -1 on error
897
898struct kvm_mp_state {
899 __u32 mp_state;
900};
901
902Returns the vcpu's current "multiprocessing state" (though also valid on
903uniprocessor guests).
904
905Possible values are:
906
907 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
908 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
909 which has not yet received an INIT signal
910 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
911 now ready for a SIPI
912 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
913 is waiting for an interrupt
914 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400915 accessible via KVM_GET_VCPU_EVENTS)
Avi Kivityb843f062010-04-25 15:51:46 +0300916
917This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
918irqchip, the multiprocessing state must be maintained by userspace.
919
Paul Bolle68ba6972011-02-15 00:05:59 +01009204.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300921
922Capability: KVM_CAP_MP_STATE
923Architectures: x86, ia64
924Type: vcpu ioctl
925Parameters: struct kvm_mp_state (in)
926Returns: 0 on success; -1 on error
927
928Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
929arguments.
930
931This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
932irqchip, the multiprocessing state must be maintained by userspace.
933
Paul Bolle68ba6972011-02-15 00:05:59 +01009344.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +0300935
936Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
937Architectures: x86
938Type: vm ioctl
939Parameters: unsigned long identity (in)
940Returns: 0 on success, -1 on error
941
942This ioctl defines the physical address of a one-page region in the guest
943physical address space. The region must be within the first 4GB of the
944guest physical address space and must not conflict with any memory slot
945or any mmio address. The guest may malfunction if it accesses this memory
946region.
947
948This ioctl is required on Intel-based hosts. This is needed on Intel hardware
949because of a quirk in the virtualization implementation (see the internals
950documentation when it pops into existence).
951
Paul Bolle68ba6972011-02-15 00:05:59 +01009524.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +0300953
954Capability: KVM_CAP_SET_BOOT_CPU_ID
955Architectures: x86, ia64
956Type: vm ioctl
957Parameters: unsigned long vcpu_id
958Returns: 0 on success, -1 on error
959
960Define which vcpu is the Bootstrap Processor (BSP). Values are the same
961as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
962is vcpu 0.
963
Paul Bolle68ba6972011-02-15 00:05:59 +01009644.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800965
966Capability: KVM_CAP_XSAVE
967Architectures: x86
968Type: vcpu ioctl
969Parameters: struct kvm_xsave (out)
970Returns: 0 on success, -1 on error
971
972struct kvm_xsave {
973 __u32 region[1024];
974};
975
976This ioctl would copy current vcpu's xsave struct to the userspace.
977
Paul Bolle68ba6972011-02-15 00:05:59 +01009784.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800979
980Capability: KVM_CAP_XSAVE
981Architectures: x86
982Type: vcpu ioctl
983Parameters: struct kvm_xsave (in)
984Returns: 0 on success, -1 on error
985
986struct kvm_xsave {
987 __u32 region[1024];
988};
989
990This ioctl would copy userspace's xsave struct to the kernel.
991
Paul Bolle68ba6972011-02-15 00:05:59 +01009924.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800993
994Capability: KVM_CAP_XCRS
995Architectures: x86
996Type: vcpu ioctl
997Parameters: struct kvm_xcrs (out)
998Returns: 0 on success, -1 on error
999
1000struct kvm_xcr {
1001 __u32 xcr;
1002 __u32 reserved;
1003 __u64 value;
1004};
1005
1006struct kvm_xcrs {
1007 __u32 nr_xcrs;
1008 __u32 flags;
1009 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1010 __u64 padding[16];
1011};
1012
1013This ioctl would copy current vcpu's xcrs to the userspace.
1014
Paul Bolle68ba6972011-02-15 00:05:59 +010010154.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001016
1017Capability: KVM_CAP_XCRS
1018Architectures: x86
1019Type: vcpu ioctl
1020Parameters: struct kvm_xcrs (in)
1021Returns: 0 on success, -1 on error
1022
1023struct kvm_xcr {
1024 __u32 xcr;
1025 __u32 reserved;
1026 __u64 value;
1027};
1028
1029struct kvm_xcrs {
1030 __u32 nr_xcrs;
1031 __u32 flags;
1032 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1033 __u64 padding[16];
1034};
1035
1036This ioctl would set vcpu's xcr to the value userspace specified.
1037
Paul Bolle68ba6972011-02-15 00:05:59 +010010384.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001039
1040Capability: KVM_CAP_EXT_CPUID
1041Architectures: x86
1042Type: system ioctl
1043Parameters: struct kvm_cpuid2 (in/out)
1044Returns: 0 on success, -1 on error
1045
1046struct kvm_cpuid2 {
1047 __u32 nent;
1048 __u32 padding;
1049 struct kvm_cpuid_entry2 entries[0];
1050};
1051
1052#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
1053#define KVM_CPUID_FLAG_STATEFUL_FUNC 2
1054#define KVM_CPUID_FLAG_STATE_READ_NEXT 4
1055
1056struct kvm_cpuid_entry2 {
1057 __u32 function;
1058 __u32 index;
1059 __u32 flags;
1060 __u32 eax;
1061 __u32 ebx;
1062 __u32 ecx;
1063 __u32 edx;
1064 __u32 padding[3];
1065};
1066
1067This ioctl returns x86 cpuid features which are supported by both the hardware
1068and kvm. Userspace can use the information returned by this ioctl to
1069construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1070hardware, kernel, and userspace capabilities, and with user requirements (for
1071example, the user may wish to constrain cpuid to emulate older hardware,
1072or for feature consistency across a cluster).
1073
1074Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1075with the 'nent' field indicating the number of entries in the variable-size
1076array 'entries'. If the number of entries is too low to describe the cpu
1077capabilities, an error (E2BIG) is returned. If the number is too high,
1078the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1079number is just right, the 'nent' field is adjusted to the number of valid
1080entries in the 'entries' array, which is then filled.
1081
1082The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001083with unknown or unsupported features masked out. Some features (for example,
1084x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1085emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001086
1087 function: the eax value used to obtain the entry
1088 index: the ecx value used to obtain the entry (for entries that are
1089 affected by ecx)
1090 flags: an OR of zero or more of the following:
1091 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1092 if the index field is valid
1093 KVM_CPUID_FLAG_STATEFUL_FUNC:
1094 if cpuid for this function returns different values for successive
1095 invocations; there will be several entries with the same function,
1096 all with this flag set
1097 KVM_CPUID_FLAG_STATE_READ_NEXT:
1098 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1099 the first entry to be read by a cpu
1100 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1101 this function/index combination
1102
Paul Bolle68ba6972011-02-15 00:05:59 +010011034.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001104
1105Capability: KVM_CAP_PPC_GET_PVINFO
1106Architectures: ppc
1107Type: vm ioctl
1108Parameters: struct kvm_ppc_pvinfo (out)
1109Returns: 0 on success, !0 on error
1110
1111struct kvm_ppc_pvinfo {
1112 __u32 flags;
1113 __u32 hcall[4];
1114 __u8 pad[108];
1115};
1116
1117This ioctl fetches PV specific information that need to be passed to the guest
1118using the device tree or other means from vm context.
1119
1120For now the only implemented piece of information distributed here is an array
1121of 4 instructions that make up a hypercall.
1122
1123If any additional field gets added to this structure later on, a bit for that
1124additional piece of information will be set in the flags bitmap.
1125
Paul Bolle68ba6972011-02-15 00:05:59 +010011264.48 KVM_ASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001127
1128Capability: KVM_CAP_DEVICE_ASSIGNMENT
1129Architectures: x86 ia64
1130Type: vm ioctl
1131Parameters: struct kvm_assigned_pci_dev (in)
1132Returns: 0 on success, -1 on error
1133
1134Assigns a host PCI device to the VM.
1135
1136struct kvm_assigned_pci_dev {
1137 __u32 assigned_dev_id;
1138 __u32 busnr;
1139 __u32 devfn;
1140 __u32 flags;
1141 __u32 segnr;
1142 union {
1143 __u32 reserved[11];
1144 };
1145};
1146
1147The PCI device is specified by the triple segnr, busnr, and devfn.
1148Identification in succeeding service requests is done via assigned_dev_id. The
1149following flags are specified:
1150
1151/* Depends on KVM_CAP_IOMMU */
1152#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1153
Alex Williamson42387372011-12-20 21:59:03 -07001154The KVM_DEV_ASSIGN_ENABLE_IOMMU flag is a mandatory option to ensure
1155isolation of the device. Usages not specifying this flag are deprecated.
1156
Alex Williamson3d27e232011-12-20 21:59:09 -07001157Only PCI header type 0 devices with PCI BAR resources are supported by
1158device assignment. The user requesting this ioctl must have read/write
1159access to the PCI sysfs resource files associated with the device.
1160
Paul Bolle68ba6972011-02-15 00:05:59 +010011614.49 KVM_DEASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001162
1163Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1164Architectures: x86 ia64
1165Type: vm ioctl
1166Parameters: struct kvm_assigned_pci_dev (in)
1167Returns: 0 on success, -1 on error
1168
1169Ends PCI device assignment, releasing all associated resources.
1170
1171See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1172used in kvm_assigned_pci_dev to identify the device.
1173
Paul Bolle68ba6972011-02-15 00:05:59 +010011744.50 KVM_ASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001175
1176Capability: KVM_CAP_ASSIGN_DEV_IRQ
1177Architectures: x86 ia64
1178Type: vm ioctl
1179Parameters: struct kvm_assigned_irq (in)
1180Returns: 0 on success, -1 on error
1181
1182Assigns an IRQ to a passed-through device.
1183
1184struct kvm_assigned_irq {
1185 __u32 assigned_dev_id;
Jan Kiszka91e3d712011-06-03 08:51:05 +02001186 __u32 host_irq; /* ignored (legacy field) */
Jan Kiszka49f48172010-11-16 22:30:07 +01001187 __u32 guest_irq;
1188 __u32 flags;
1189 union {
Jan Kiszka49f48172010-11-16 22:30:07 +01001190 __u32 reserved[12];
1191 };
1192};
1193
1194The following flags are defined:
1195
1196#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
1197#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
1198#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
1199
1200#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
1201#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
1202#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
1203
1204It is not valid to specify multiple types per host or guest IRQ. However, the
1205IRQ type of host and guest can differ or can even be null.
1206
Paul Bolle68ba6972011-02-15 00:05:59 +010012074.51 KVM_DEASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001208
1209Capability: KVM_CAP_ASSIGN_DEV_IRQ
1210Architectures: x86 ia64
1211Type: vm ioctl
1212Parameters: struct kvm_assigned_irq (in)
1213Returns: 0 on success, -1 on error
1214
1215Ends an IRQ assignment to a passed-through device.
1216
1217See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1218by assigned_dev_id, flags must correspond to the IRQ type specified on
1219KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1220
Paul Bolle68ba6972011-02-15 00:05:59 +010012214.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001222
1223Capability: KVM_CAP_IRQ_ROUTING
1224Architectures: x86 ia64
1225Type: vm ioctl
1226Parameters: struct kvm_irq_routing (in)
1227Returns: 0 on success, -1 on error
1228
1229Sets the GSI routing table entries, overwriting any previously set entries.
1230
1231struct kvm_irq_routing {
1232 __u32 nr;
1233 __u32 flags;
1234 struct kvm_irq_routing_entry entries[0];
1235};
1236
1237No flags are specified so far, the corresponding field must be set to zero.
1238
1239struct kvm_irq_routing_entry {
1240 __u32 gsi;
1241 __u32 type;
1242 __u32 flags;
1243 __u32 pad;
1244 union {
1245 struct kvm_irq_routing_irqchip irqchip;
1246 struct kvm_irq_routing_msi msi;
1247 __u32 pad[8];
1248 } u;
1249};
1250
1251/* gsi routing entry types */
1252#define KVM_IRQ_ROUTING_IRQCHIP 1
1253#define KVM_IRQ_ROUTING_MSI 2
1254
1255No flags are specified so far, the corresponding field must be set to zero.
1256
1257struct kvm_irq_routing_irqchip {
1258 __u32 irqchip;
1259 __u32 pin;
1260};
1261
1262struct kvm_irq_routing_msi {
1263 __u32 address_lo;
1264 __u32 address_hi;
1265 __u32 data;
1266 __u32 pad;
1267};
1268
Paul Bolle68ba6972011-02-15 00:05:59 +010012694.53 KVM_ASSIGN_SET_MSIX_NR
Jan Kiszka49f48172010-11-16 22:30:07 +01001270
1271Capability: KVM_CAP_DEVICE_MSIX
1272Architectures: x86 ia64
1273Type: vm ioctl
1274Parameters: struct kvm_assigned_msix_nr (in)
1275Returns: 0 on success, -1 on error
1276
Jan Kiszka58f09642011-06-11 12:24:24 +02001277Set the number of MSI-X interrupts for an assigned device. The number is
1278reset again by terminating the MSI-X assignment of the device via
1279KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
1280point will fail.
Jan Kiszka49f48172010-11-16 22:30:07 +01001281
1282struct kvm_assigned_msix_nr {
1283 __u32 assigned_dev_id;
1284 __u16 entry_nr;
1285 __u16 padding;
1286};
1287
1288#define KVM_MAX_MSIX_PER_DEV 256
1289
Paul Bolle68ba6972011-02-15 00:05:59 +010012904.54 KVM_ASSIGN_SET_MSIX_ENTRY
Jan Kiszka49f48172010-11-16 22:30:07 +01001291
1292Capability: KVM_CAP_DEVICE_MSIX
1293Architectures: x86 ia64
1294Type: vm ioctl
1295Parameters: struct kvm_assigned_msix_entry (in)
1296Returns: 0 on success, -1 on error
1297
1298Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1299the GSI vector to zero means disabling the interrupt.
1300
1301struct kvm_assigned_msix_entry {
1302 __u32 assigned_dev_id;
1303 __u32 gsi;
1304 __u16 entry; /* The index of entry in the MSI-X table */
1305 __u16 padding[3];
1306};
1307
Joerg Roedel92a1f122011-03-25 09:44:51 +010013084.54 KVM_SET_TSC_KHZ
1309
1310Capability: KVM_CAP_TSC_CONTROL
1311Architectures: x86
1312Type: vcpu ioctl
1313Parameters: virtual tsc_khz
1314Returns: 0 on success, -1 on error
1315
1316Specifies the tsc frequency for the virtual machine. The unit of the
1317frequency is KHz.
1318
13194.55 KVM_GET_TSC_KHZ
1320
1321Capability: KVM_CAP_GET_TSC_KHZ
1322Architectures: x86
1323Type: vcpu ioctl
1324Parameters: none
1325Returns: virtual tsc-khz on success, negative value on error
1326
1327Returns the tsc frequency of the guest. The unit of the return value is
1328KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1329error.
1330
Avi Kivitye7677932011-05-11 08:30:51 -040013314.56 KVM_GET_LAPIC
1332
1333Capability: KVM_CAP_IRQCHIP
1334Architectures: x86
1335Type: vcpu ioctl
1336Parameters: struct kvm_lapic_state (out)
1337Returns: 0 on success, -1 on error
1338
1339#define KVM_APIC_REG_SIZE 0x400
1340struct kvm_lapic_state {
1341 char regs[KVM_APIC_REG_SIZE];
1342};
1343
1344Reads the Local APIC registers and copies them into the input argument. The
1345data format and layout are the same as documented in the architecture manual.
1346
13474.57 KVM_SET_LAPIC
1348
1349Capability: KVM_CAP_IRQCHIP
1350Architectures: x86
1351Type: vcpu ioctl
1352Parameters: struct kvm_lapic_state (in)
1353Returns: 0 on success, -1 on error
1354
1355#define KVM_APIC_REG_SIZE 0x400
1356struct kvm_lapic_state {
1357 char regs[KVM_APIC_REG_SIZE];
1358};
1359
1360Copies the input argument into the the Local APIC registers. The data format
1361and layout are the same as documented in the architecture manual.
1362
Jan Kiszka7f4382e2011-06-02 16:16:20 +020013634.58 KVM_IOEVENTFD
Sasha Levin55399a02011-05-28 14:12:30 +03001364
1365Capability: KVM_CAP_IOEVENTFD
1366Architectures: all
1367Type: vm ioctl
1368Parameters: struct kvm_ioeventfd (in)
1369Returns: 0 on success, !0 on error
1370
1371This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1372within the guest. A guest write in the registered address will signal the
1373provided event instead of triggering an exit.
1374
1375struct kvm_ioeventfd {
1376 __u64 datamatch;
1377 __u64 addr; /* legal pio/mmio address */
1378 __u32 len; /* 1, 2, 4, or 8 bytes */
1379 __s32 fd;
1380 __u32 flags;
1381 __u8 pad[36];
1382};
1383
1384The following flags are defined:
1385
1386#define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1387#define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1388#define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
1389
1390If datamatch flag is set, the event will be signaled only if the written value
1391to the registered address is equal to datamatch in struct kvm_ioeventfd.
1392
David Gibson54738c02011-06-29 00:22:41 +000013934.62 KVM_CREATE_SPAPR_TCE
1394
1395Capability: KVM_CAP_SPAPR_TCE
1396Architectures: powerpc
1397Type: vm ioctl
1398Parameters: struct kvm_create_spapr_tce (in)
1399Returns: file descriptor for manipulating the created TCE table
1400
1401This creates a virtual TCE (translation control entry) table, which
1402is an IOMMU for PAPR-style virtual I/O. It is used to translate
1403logical addresses used in virtual I/O into guest physical addresses,
1404and provides a scatter/gather capability for PAPR virtual I/O.
1405
1406/* for KVM_CAP_SPAPR_TCE */
1407struct kvm_create_spapr_tce {
1408 __u64 liobn;
1409 __u32 window_size;
1410};
1411
1412The liobn field gives the logical IO bus number for which to create a
1413TCE table. The window_size field specifies the size of the DMA window
1414which this TCE table will translate - the table will contain one 64
1415bit TCE entry for every 4kiB of the DMA window.
1416
1417When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1418table has been created using this ioctl(), the kernel will handle it
1419in real mode, updating the TCE table. H_PUT_TCE calls for other
1420liobns will cause a vm exit and must be handled by userspace.
1421
1422The return value is a file descriptor which can be passed to mmap(2)
1423to map the created TCE table into userspace. This lets userspace read
1424the entries written by kernel-handled H_PUT_TCE calls, and also lets
1425userspace update the TCE table directly which is useful in some
1426circumstances.
1427
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +000014284.63 KVM_ALLOCATE_RMA
1429
1430Capability: KVM_CAP_PPC_RMA
1431Architectures: powerpc
1432Type: vm ioctl
1433Parameters: struct kvm_allocate_rma (out)
1434Returns: file descriptor for mapping the allocated RMA
1435
1436This allocates a Real Mode Area (RMA) from the pool allocated at boot
1437time by the kernel. An RMA is a physically-contiguous, aligned region
1438of memory used on older POWER processors to provide the memory which
1439will be accessed by real-mode (MMU off) accesses in a KVM guest.
1440POWER processors support a set of sizes for the RMA that usually
1441includes 64MB, 128MB, 256MB and some larger powers of two.
1442
1443/* for KVM_ALLOCATE_RMA */
1444struct kvm_allocate_rma {
1445 __u64 rma_size;
1446};
1447
1448The return value is a file descriptor which can be passed to mmap(2)
1449to map the allocated RMA into userspace. The mapped area can then be
1450passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1451RMA for a virtual machine. The size of the RMA in bytes (which is
1452fixed at host kernel boot time) is returned in the rma_size field of
1453the argument structure.
1454
1455The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1456is supported; 2 if the processor requires all virtual machines to have
1457an RMA, or 1 if the processor can use an RMA but doesn't require it,
1458because it supports the Virtual RMA (VRMA) facility.
1459
Avi Kivity9c1b96e2009-06-09 12:37:58 +030014605. The kvm_run structure
1461
1462Application code obtains a pointer to the kvm_run structure by
1463mmap()ing a vcpu fd. From that point, application code can control
1464execution by changing fields in kvm_run prior to calling the KVM_RUN
1465ioctl, and obtain information about the reason KVM_RUN returned by
1466looking up structure members.
1467
1468struct kvm_run {
1469 /* in */
1470 __u8 request_interrupt_window;
1471
1472Request that KVM_RUN return when it becomes possible to inject external
1473interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1474
1475 __u8 padding1[7];
1476
1477 /* out */
1478 __u32 exit_reason;
1479
1480When KVM_RUN has returned successfully (return value 0), this informs
1481application code why KVM_RUN has returned. Allowable values for this
1482field are detailed below.
1483
1484 __u8 ready_for_interrupt_injection;
1485
1486If request_interrupt_window has been specified, this field indicates
1487an interrupt can be injected now with KVM_INTERRUPT.
1488
1489 __u8 if_flag;
1490
1491The value of the current interrupt flag. Only valid if in-kernel
1492local APIC is not used.
1493
1494 __u8 padding2[2];
1495
1496 /* in (pre_kvm_run), out (post_kvm_run) */
1497 __u64 cr8;
1498
1499The value of the cr8 register. Only valid if in-kernel local APIC is
1500not used. Both input and output.
1501
1502 __u64 apic_base;
1503
1504The value of the APIC BASE msr. Only valid if in-kernel local
1505APIC is not used. Both input and output.
1506
1507 union {
1508 /* KVM_EXIT_UNKNOWN */
1509 struct {
1510 __u64 hardware_exit_reason;
1511 } hw;
1512
1513If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1514reasons. Further architecture-specific information is available in
1515hardware_exit_reason.
1516
1517 /* KVM_EXIT_FAIL_ENTRY */
1518 struct {
1519 __u64 hardware_entry_failure_reason;
1520 } fail_entry;
1521
1522If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1523to unknown reasons. Further architecture-specific information is
1524available in hardware_entry_failure_reason.
1525
1526 /* KVM_EXIT_EXCEPTION */
1527 struct {
1528 __u32 exception;
1529 __u32 error_code;
1530 } ex;
1531
1532Unused.
1533
1534 /* KVM_EXIT_IO */
1535 struct {
1536#define KVM_EXIT_IO_IN 0
1537#define KVM_EXIT_IO_OUT 1
1538 __u8 direction;
1539 __u8 size; /* bytes */
1540 __u16 port;
1541 __u32 count;
1542 __u64 data_offset; /* relative to kvm_run start */
1543 } io;
1544
Wu Fengguang20448922009-12-24 09:04:16 +08001545If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001546executed a port I/O instruction which could not be satisfied by kvm.
1547data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1548where kvm expects application code to place the data for the next
Wu Fengguang20448922009-12-24 09:04:16 +08001549KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001550
1551 struct {
1552 struct kvm_debug_exit_arch arch;
1553 } debug;
1554
1555Unused.
1556
1557 /* KVM_EXIT_MMIO */
1558 struct {
1559 __u64 phys_addr;
1560 __u8 data[8];
1561 __u32 len;
1562 __u8 is_write;
1563 } mmio;
1564
Wu Fengguang20448922009-12-24 09:04:16 +08001565If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001566executed a memory-mapped I/O instruction which could not be satisfied
1567by kvm. The 'data' member contains the written data if 'is_write' is
1568true, and should be filled by application code otherwise.
1569
Alexander Grafad0a0482010-03-24 21:48:30 +01001570NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1571operations are complete (and guest state is consistent) only after userspace
1572has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02001573incomplete operations and then check for pending signals. Userspace
1574can re-enter the guest with an unmasked signal pending to complete
1575pending operations.
1576
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001577 /* KVM_EXIT_HYPERCALL */
1578 struct {
1579 __u64 nr;
1580 __u64 args[6];
1581 __u64 ret;
1582 __u32 longmode;
1583 __u32 pad;
1584 } hypercall;
1585
Avi Kivity647dc492010-04-01 14:39:21 +03001586Unused. This was once used for 'hypercall to userspace'. To implement
1587such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1588Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001589
1590 /* KVM_EXIT_TPR_ACCESS */
1591 struct {
1592 __u64 rip;
1593 __u32 is_write;
1594 __u32 pad;
1595 } tpr_access;
1596
1597To be documented (KVM_TPR_ACCESS_REPORTING).
1598
1599 /* KVM_EXIT_S390_SIEIC */
1600 struct {
1601 __u8 icptcode;
1602 __u64 mask; /* psw upper half */
1603 __u64 addr; /* psw lower half */
1604 __u16 ipa;
1605 __u32 ipb;
1606 } s390_sieic;
1607
1608s390 specific.
1609
1610 /* KVM_EXIT_S390_RESET */
1611#define KVM_S390_RESET_POR 1
1612#define KVM_S390_RESET_CLEAR 2
1613#define KVM_S390_RESET_SUBSYSTEM 4
1614#define KVM_S390_RESET_CPU_INIT 8
1615#define KVM_S390_RESET_IPL 16
1616 __u64 s390_reset_flags;
1617
1618s390 specific.
1619
1620 /* KVM_EXIT_DCR */
1621 struct {
1622 __u32 dcrn;
1623 __u32 data;
1624 __u8 is_write;
1625 } dcr;
1626
1627powerpc specific.
1628
Alexander Grafad0a0482010-03-24 21:48:30 +01001629 /* KVM_EXIT_OSI */
1630 struct {
1631 __u64 gprs[32];
1632 } osi;
1633
1634MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1635hypercalls and exit with this exit struct that contains all the guest gprs.
1636
1637If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1638Userspace can now handle the hypercall and when it's done modify the gprs as
1639necessary. Upon guest entry all guest GPRs will then be replaced by the values
1640in this struct.
1641
Paul Mackerrasde56a942011-06-29 00:21:34 +00001642 /* KVM_EXIT_PAPR_HCALL */
1643 struct {
1644 __u64 nr;
1645 __u64 ret;
1646 __u64 args[9];
1647 } papr_hcall;
1648
1649This is used on 64-bit PowerPC when emulating a pSeries partition,
1650e.g. with the 'pseries' machine type in qemu. It occurs when the
1651guest does a hypercall using the 'sc 1' instruction. The 'nr' field
1652contains the hypercall number (from the guest R3), and 'args' contains
1653the arguments (from the guest R4 - R12). Userspace should put the
1654return code in 'ret' and any extra returned values in args[].
1655The possible hypercalls are defined in the Power Architecture Platform
1656Requirements (PAPR) document available from www.power.org (free
1657developer registration required to access it).
1658
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001659 /* Fix the size of the union. */
1660 char padding[256];
1661 };
1662};
Alexander Graf821246a2011-08-31 10:58:55 +02001663
16646. Capabilities that can be enabled
1665
1666There are certain capabilities that change the behavior of the virtual CPU when
1667enabled. To enable them, please see section 4.37. Below you can find a list of
1668capabilities and what their effect on the vCPU is when enabling them.
1669
1670The following information is provided along with the description:
1671
1672 Architectures: which instruction set architectures provide this ioctl.
1673 x86 includes both i386 and x86_64.
1674
1675 Parameters: what parameters are accepted by the capability.
1676
1677 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
1678 are not detailed, but errors with specific meanings are.
1679
16806.1 KVM_CAP_PPC_OSI
1681
1682Architectures: ppc
1683Parameters: none
1684Returns: 0 on success; -1 on error
1685
1686This capability enables interception of OSI hypercalls that otherwise would
1687be treated as normal system calls to be injected into the guest. OSI hypercalls
1688were invented by Mac-on-Linux to have a standardized communication mechanism
1689between the guest and the host.
1690
1691When this capability is enabled, KVM_EXIT_OSI can occur.
1692
16936.2 KVM_CAP_PPC_PAPR
1694
1695Architectures: ppc
1696Parameters: none
1697Returns: 0 on success; -1 on error
1698
1699This capability enables interception of PAPR hypercalls. PAPR hypercalls are
1700done using the hypercall instruction "sc 1".
1701
1702It also sets the guest privilege level to "supervisor" mode. Usually the guest
1703runs in "hypervisor" privilege mode with a few missing features.
1704
1705In addition to the above, it changes the semantics of SDR1. In this mode, the
1706HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
1707HTAB invisible to the guest.
1708
1709When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.