blob: 67cc0f5b9974c0cd96ecd0c1526d34a2ba1364da [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 Fengguang2044892d2009-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 Fengguang2044892d2009-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
Pekka Enberg76d25402011-05-09 22:48:54 +0300178in the range [0, max_vcpus). You can use KVM_CAP_NR_VCPUS of the
179KVM_CHECK_EXTENSION ioctl() to determine the value for max_vcpus at run-time.
180If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
181cpus max.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300182
Paul Bolle68ba6972011-02-15 00:05:59 +01001834.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300184
185Capability: basic
186Architectures: x86
187Type: vm ioctl
188Parameters: struct kvm_dirty_log (in/out)
189Returns: 0 on success, -1 on error
190
191/* for KVM_GET_DIRTY_LOG */
192struct kvm_dirty_log {
193 __u32 slot;
194 __u32 padding;
195 union {
196 void __user *dirty_bitmap; /* one bit per page */
197 __u64 padding;
198 };
199};
200
201Given a memory slot, return a bitmap containing any pages dirtied
202since the last call to this ioctl. Bit 0 is the first page in the
203memory slot. Ensure the entire structure is cleared to avoid padding
204issues.
205
Paul Bolle68ba6972011-02-15 00:05:59 +01002064.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300207
208Capability: basic
209Architectures: x86
210Type: vm ioctl
211Parameters: struct kvm_memory_alias (in)
212Returns: 0 (success), -1 (error)
213
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300214This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300215
Paul Bolle68ba6972011-02-15 00:05:59 +01002164.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300217
218Capability: basic
219Architectures: all
220Type: vcpu ioctl
221Parameters: none
222Returns: 0 on success, -1 on error
223Errors:
224 EINTR: an unmasked signal is pending
225
226This ioctl is used to run a guest virtual cpu. While there are no
227explicit parameters, there is an implicit parameter block that can be
228obtained by mmap()ing the vcpu fd at offset 0, with the size given by
229KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
230kvm_run' (see below).
231
Paul Bolle68ba6972011-02-15 00:05:59 +01002324.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300233
234Capability: basic
235Architectures: all
236Type: vcpu ioctl
237Parameters: struct kvm_regs (out)
238Returns: 0 on success, -1 on error
239
240Reads the general purpose registers from the vcpu.
241
242/* x86 */
243struct kvm_regs {
244 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
245 __u64 rax, rbx, rcx, rdx;
246 __u64 rsi, rdi, rsp, rbp;
247 __u64 r8, r9, r10, r11;
248 __u64 r12, r13, r14, r15;
249 __u64 rip, rflags;
250};
251
Paul Bolle68ba6972011-02-15 00:05:59 +01002524.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300253
254Capability: basic
255Architectures: all
256Type: vcpu ioctl
257Parameters: struct kvm_regs (in)
258Returns: 0 on success, -1 on error
259
260Writes the general purpose registers into the vcpu.
261
262See KVM_GET_REGS for the data structure.
263
Paul Bolle68ba6972011-02-15 00:05:59 +01002644.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300265
266Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500267Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300268Type: vcpu ioctl
269Parameters: struct kvm_sregs (out)
270Returns: 0 on success, -1 on error
271
272Reads special registers from the vcpu.
273
274/* x86 */
275struct kvm_sregs {
276 struct kvm_segment cs, ds, es, fs, gs, ss;
277 struct kvm_segment tr, ldt;
278 struct kvm_dtable gdt, idt;
279 __u64 cr0, cr2, cr3, cr4, cr8;
280 __u64 efer;
281 __u64 apic_base;
282 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
283};
284
Scott Wood5ce941e2011-04-27 17:24:21 -0500285/* ppc -- see arch/powerpc/include/asm/kvm.h */
286
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300287interrupt_bitmap is a bitmap of pending external interrupts. At most
288one bit may be set. This interrupt has been acknowledged by the APIC
289but not yet injected into the cpu core.
290
Paul Bolle68ba6972011-02-15 00:05:59 +01002914.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300292
293Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500294Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300295Type: vcpu ioctl
296Parameters: struct kvm_sregs (in)
297Returns: 0 on success, -1 on error
298
299Writes special registers into the vcpu. See KVM_GET_SREGS for the
300data structures.
301
Paul Bolle68ba6972011-02-15 00:05:59 +01003024.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300303
304Capability: basic
305Architectures: x86
306Type: vcpu ioctl
307Parameters: struct kvm_translation (in/out)
308Returns: 0 on success, -1 on error
309
310Translates a virtual address according to the vcpu's current address
311translation mode.
312
313struct kvm_translation {
314 /* in */
315 __u64 linear_address;
316
317 /* out */
318 __u64 physical_address;
319 __u8 valid;
320 __u8 writeable;
321 __u8 usermode;
322 __u8 pad[5];
323};
324
Paul Bolle68ba6972011-02-15 00:05:59 +01003254.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300326
327Capability: basic
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200328Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300329Type: vcpu ioctl
330Parameters: struct kvm_interrupt (in)
331Returns: 0 on success, -1 on error
332
333Queues a hardware interrupt vector to be injected. This is only
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200334useful if in-kernel local APIC or equivalent is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300335
336/* for KVM_INTERRUPT */
337struct kvm_interrupt {
338 /* in */
339 __u32 irq;
340};
341
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200342X86:
343
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300344Note 'irq' is an interrupt vector, not an interrupt pin or line.
345
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200346PPC:
347
348Queues an external interrupt to be injected. This ioctl is overleaded
349with 3 different irq values:
350
351a) KVM_INTERRUPT_SET
352
353 This injects an edge type external interrupt into the guest once it's ready
354 to receive interrupts. When injected, the interrupt is done.
355
356b) KVM_INTERRUPT_UNSET
357
358 This unsets any pending interrupt.
359
360 Only available with KVM_CAP_PPC_UNSET_IRQ.
361
362c) KVM_INTERRUPT_SET_LEVEL
363
364 This injects a level type external interrupt into the guest context. The
365 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
366 is triggered.
367
368 Only available with KVM_CAP_PPC_IRQ_LEVEL.
369
370Note that any value for 'irq' other than the ones stated above is invalid
371and incurs unexpected behavior.
372
Paul Bolle68ba6972011-02-15 00:05:59 +01003734.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300374
375Capability: basic
376Architectures: none
377Type: vcpu ioctl
378Parameters: none)
379Returns: -1 on error
380
381Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
382
Paul Bolle68ba6972011-02-15 00:05:59 +01003834.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300384
385Capability: basic
386Architectures: x86
387Type: vcpu ioctl
388Parameters: struct kvm_msrs (in/out)
389Returns: 0 on success, -1 on error
390
391Reads model-specific registers from the vcpu. Supported msr indices can
392be obtained using KVM_GET_MSR_INDEX_LIST.
393
394struct kvm_msrs {
395 __u32 nmsrs; /* number of msrs in entries */
396 __u32 pad;
397
398 struct kvm_msr_entry entries[0];
399};
400
401struct kvm_msr_entry {
402 __u32 index;
403 __u32 reserved;
404 __u64 data;
405};
406
407Application code should set the 'nmsrs' member (which indicates the
408size of the entries array) and the 'index' member of each array entry.
409kvm will fill in the 'data' member.
410
Paul Bolle68ba6972011-02-15 00:05:59 +01004114.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300412
413Capability: basic
414Architectures: x86
415Type: vcpu ioctl
416Parameters: struct kvm_msrs (in)
417Returns: 0 on success, -1 on error
418
419Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
420data structures.
421
422Application code should set the 'nmsrs' member (which indicates the
423size of the entries array), and the 'index' and 'data' members of each
424array entry.
425
Paul Bolle68ba6972011-02-15 00:05:59 +01004264.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300427
428Capability: basic
429Architectures: x86
430Type: vcpu ioctl
431Parameters: struct kvm_cpuid (in)
432Returns: 0 on success, -1 on error
433
434Defines the vcpu responses to the cpuid instruction. Applications
435should use the KVM_SET_CPUID2 ioctl if available.
436
437
438struct kvm_cpuid_entry {
439 __u32 function;
440 __u32 eax;
441 __u32 ebx;
442 __u32 ecx;
443 __u32 edx;
444 __u32 padding;
445};
446
447/* for KVM_SET_CPUID */
448struct kvm_cpuid {
449 __u32 nent;
450 __u32 padding;
451 struct kvm_cpuid_entry entries[0];
452};
453
Paul Bolle68ba6972011-02-15 00:05:59 +01004544.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300455
456Capability: basic
457Architectures: x86
458Type: vcpu ioctl
459Parameters: struct kvm_signal_mask (in)
460Returns: 0 on success, -1 on error
461
462Defines which signals are blocked during execution of KVM_RUN. This
463signal mask temporarily overrides the threads signal mask. Any
464unblocked signal received (except SIGKILL and SIGSTOP, which retain
465their traditional behaviour) will cause KVM_RUN to return with -EINTR.
466
467Note the signal will only be delivered if not blocked by the original
468signal mask.
469
470/* for KVM_SET_SIGNAL_MASK */
471struct kvm_signal_mask {
472 __u32 len;
473 __u8 sigset[0];
474};
475
Paul Bolle68ba6972011-02-15 00:05:59 +01004764.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300477
478Capability: basic
479Architectures: x86
480Type: vcpu ioctl
481Parameters: struct kvm_fpu (out)
482Returns: 0 on success, -1 on error
483
484Reads the floating point state from the vcpu.
485
486/* for KVM_GET_FPU and KVM_SET_FPU */
487struct kvm_fpu {
488 __u8 fpr[8][16];
489 __u16 fcw;
490 __u16 fsw;
491 __u8 ftwx; /* in fxsave format */
492 __u8 pad1;
493 __u16 last_opcode;
494 __u64 last_ip;
495 __u64 last_dp;
496 __u8 xmm[16][16];
497 __u32 mxcsr;
498 __u32 pad2;
499};
500
Paul Bolle68ba6972011-02-15 00:05:59 +01005014.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300502
503Capability: basic
504Architectures: x86
505Type: vcpu ioctl
506Parameters: struct kvm_fpu (in)
507Returns: 0 on success, -1 on error
508
509Writes the floating point state to the vcpu.
510
511/* for KVM_GET_FPU and KVM_SET_FPU */
512struct kvm_fpu {
513 __u8 fpr[8][16];
514 __u16 fcw;
515 __u16 fsw;
516 __u8 ftwx; /* in fxsave format */
517 __u8 pad1;
518 __u16 last_opcode;
519 __u64 last_ip;
520 __u64 last_dp;
521 __u8 xmm[16][16];
522 __u32 mxcsr;
523 __u32 pad2;
524};
525
Paul Bolle68ba6972011-02-15 00:05:59 +01005264.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300527
528Capability: KVM_CAP_IRQCHIP
529Architectures: x86, ia64
530Type: vm ioctl
531Parameters: none
532Returns: 0 on success, -1 on error
533
534Creates an interrupt controller model in the kernel. On x86, creates a virtual
535ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
536local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
537only go to the IOAPIC. On ia64, a IOSAPIC is created.
538
Paul Bolle68ba6972011-02-15 00:05:59 +01005394.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300540
541Capability: KVM_CAP_IRQCHIP
542Architectures: x86, ia64
543Type: vm ioctl
544Parameters: struct kvm_irq_level
545Returns: 0 on success, -1 on error
546
547Sets the level of a GSI input to the interrupt controller model in the kernel.
548Requires that an interrupt controller model has been previously created with
549KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
550to be set to 1 and then back to 0.
551
552struct kvm_irq_level {
553 union {
554 __u32 irq; /* GSI */
555 __s32 status; /* not used for KVM_IRQ_LEVEL */
556 };
557 __u32 level; /* 0 or 1 */
558};
559
Paul Bolle68ba6972011-02-15 00:05:59 +01005604.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300561
562Capability: KVM_CAP_IRQCHIP
563Architectures: x86, ia64
564Type: vm ioctl
565Parameters: struct kvm_irqchip (in/out)
566Returns: 0 on success, -1 on error
567
568Reads the state of a kernel interrupt controller created with
569KVM_CREATE_IRQCHIP into a buffer provided by the caller.
570
571struct kvm_irqchip {
572 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
573 __u32 pad;
574 union {
575 char dummy[512]; /* reserving space */
576 struct kvm_pic_state pic;
577 struct kvm_ioapic_state ioapic;
578 } chip;
579};
580
Paul Bolle68ba6972011-02-15 00:05:59 +01005814.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300582
583Capability: KVM_CAP_IRQCHIP
584Architectures: x86, ia64
585Type: vm ioctl
586Parameters: struct kvm_irqchip (in)
587Returns: 0 on success, -1 on error
588
589Sets the state of a kernel interrupt controller created with
590KVM_CREATE_IRQCHIP from a buffer provided by the caller.
591
592struct kvm_irqchip {
593 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
594 __u32 pad;
595 union {
596 char dummy[512]; /* reserving space */
597 struct kvm_pic_state pic;
598 struct kvm_ioapic_state ioapic;
599 } chip;
600};
601
Paul Bolle68ba6972011-02-15 00:05:59 +01006024.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700603
604Capability: KVM_CAP_XEN_HVM
605Architectures: x86
606Type: vm ioctl
607Parameters: struct kvm_xen_hvm_config (in)
608Returns: 0 on success, -1 on error
609
610Sets the MSR that the Xen HVM guest uses to initialize its hypercall
611page, and provides the starting address and size of the hypercall
612blobs in userspace. When the guest writes the MSR, kvm copies one
613page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
614memory.
615
616struct kvm_xen_hvm_config {
617 __u32 flags;
618 __u32 msr;
619 __u64 blob_addr_32;
620 __u64 blob_addr_64;
621 __u8 blob_size_32;
622 __u8 blob_size_64;
623 __u8 pad2[30];
624};
625
Paul Bolle68ba6972011-02-15 00:05:59 +01006264.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400627
628Capability: KVM_CAP_ADJUST_CLOCK
629Architectures: x86
630Type: vm ioctl
631Parameters: struct kvm_clock_data (out)
632Returns: 0 on success, -1 on error
633
634Gets the current timestamp of kvmclock as seen by the current guest. In
635conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
636such as migration.
637
638struct kvm_clock_data {
639 __u64 clock; /* kvmclock current value */
640 __u32 flags;
641 __u32 pad[9];
642};
643
Paul Bolle68ba6972011-02-15 00:05:59 +01006444.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400645
646Capability: KVM_CAP_ADJUST_CLOCK
647Architectures: x86
648Type: vm ioctl
649Parameters: struct kvm_clock_data (in)
650Returns: 0 on success, -1 on error
651
Wu Fengguang2044892d2009-12-24 09:04:16 +0800652Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400653In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
654such as migration.
655
656struct kvm_clock_data {
657 __u64 clock; /* kvmclock current value */
658 __u32 flags;
659 __u32 pad[9];
660};
661
Paul Bolle68ba6972011-02-15 00:05:59 +01006624.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100663
664Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100665Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100666Architectures: x86
667Type: vm ioctl
668Parameters: struct kvm_vcpu_event (out)
669Returns: 0 on success, -1 on error
670
671Gets currently pending exceptions, interrupts, and NMIs as well as related
672states of the vcpu.
673
674struct kvm_vcpu_events {
675 struct {
676 __u8 injected;
677 __u8 nr;
678 __u8 has_error_code;
679 __u8 pad;
680 __u32 error_code;
681 } exception;
682 struct {
683 __u8 injected;
684 __u8 nr;
685 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100686 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100687 } interrupt;
688 struct {
689 __u8 injected;
690 __u8 pending;
691 __u8 masked;
692 __u8 pad;
693 } nmi;
694 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100695 __u32 flags;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100696};
697
Jan Kiszka48005f62010-02-19 19:38:07 +0100698KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
699interrupt.shadow contains a valid state. Otherwise, this field is undefined.
700
Paul Bolle68ba6972011-02-15 00:05:59 +01007014.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100702
703Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100704Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100705Architectures: x86
706Type: vm ioctl
707Parameters: struct kvm_vcpu_event (in)
708Returns: 0 on success, -1 on error
709
710Set pending exceptions, interrupts, and NMIs as well as related states of the
711vcpu.
712
713See KVM_GET_VCPU_EVENTS for the data structure.
714
Jan Kiszkadab4b912009-12-06 18:24:15 +0100715Fields that may be modified asynchronously by running VCPUs can be excluded
716from the update. These fields are nmi.pending and sipi_vector. Keep the
717corresponding bits in the flags field cleared to suppress overwriting the
718current in-kernel state. The bits are:
719
720KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
721KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
722
Jan Kiszka48005f62010-02-19 19:38:07 +0100723If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
724the flags field to signal that interrupt.shadow contains a valid state and
725shall be written into the VCPU.
726
Paul Bolle68ba6972011-02-15 00:05:59 +01007274.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100728
729Capability: KVM_CAP_DEBUGREGS
730Architectures: x86
731Type: vm ioctl
732Parameters: struct kvm_debugregs (out)
733Returns: 0 on success, -1 on error
734
735Reads debug registers from the vcpu.
736
737struct kvm_debugregs {
738 __u64 db[4];
739 __u64 dr6;
740 __u64 dr7;
741 __u64 flags;
742 __u64 reserved[9];
743};
744
Paul Bolle68ba6972011-02-15 00:05:59 +01007454.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100746
747Capability: KVM_CAP_DEBUGREGS
748Architectures: x86
749Type: vm ioctl
750Parameters: struct kvm_debugregs (in)
751Returns: 0 on success, -1 on error
752
753Writes debug registers into the vcpu.
754
755See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
756yet and must be cleared on entry.
757
Paul Bolle68ba6972011-02-15 00:05:59 +01007584.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +0200759
760Capability: KVM_CAP_USER_MEM
761Architectures: all
762Type: vm ioctl
763Parameters: struct kvm_userspace_memory_region (in)
764Returns: 0 on success, -1 on error
765
766struct kvm_userspace_memory_region {
767 __u32 slot;
768 __u32 flags;
769 __u64 guest_phys_addr;
770 __u64 memory_size; /* bytes */
771 __u64 userspace_addr; /* start of the userspace allocated memory */
772};
773
774/* for kvm_memory_region::flags */
775#define KVM_MEM_LOG_DIRTY_PAGES 1UL
776
777This ioctl allows the user to create or modify a guest physical memory
778slot. When changing an existing slot, it may be moved in the guest
779physical memory space, or its flags may be modified. It may not be
780resized. Slots may not overlap in guest physical address space.
781
782Memory for the region is taken starting at the address denoted by the
783field userspace_addr, which must point at user addressable memory for
784the entire memory slot size. Any object may back this memory, including
785anonymous memory, ordinary files, and hugetlbfs.
786
787It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
788be identical. This allows large pages in the guest to be backed by large
789pages in the host.
790
791The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
792instructs kvm to keep track of writes to memory within the slot. See
793the KVM_GET_DIRTY_LOG ioctl.
794
795When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
796region are automatically reflected into the guest. For example, an mmap()
797that affects the region will be made visible immediately. Another example
798is madvise(MADV_DROP).
799
800It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
801The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
802allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100803
Paul Bolle68ba6972011-02-15 00:05:59 +01008044.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +0200805
806Capability: KVM_CAP_SET_TSS_ADDR
807Architectures: x86
808Type: vm ioctl
809Parameters: unsigned long tss_address (in)
810Returns: 0 on success, -1 on error
811
812This ioctl defines the physical address of a three-page region in the guest
813physical address space. The region must be within the first 4GB of the
814guest physical address space and must not conflict with any memory slot
815or any mmio address. The guest may malfunction if it accesses this memory
816region.
817
818This ioctl is required on Intel-based hosts. This is needed on Intel hardware
819because of a quirk in the virtualization implementation (see the internals
820documentation when it pops into existence).
821
Paul Bolle68ba6972011-02-15 00:05:59 +01008224.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +0100823
824Capability: KVM_CAP_ENABLE_CAP
825Architectures: ppc
826Type: vcpu ioctl
827Parameters: struct kvm_enable_cap (in)
828Returns: 0 on success; -1 on error
829
830+Not all extensions are enabled by default. Using this ioctl the application
831can enable an extension, making it available to the guest.
832
833On systems that do not support this ioctl, it always fails. On systems that
834do support it, it only works for extensions that are supported for enablement.
835
836To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
837be used.
838
839struct kvm_enable_cap {
840 /* in */
841 __u32 cap;
842
843The capability that is supposed to get enabled.
844
845 __u32 flags;
846
847A bitfield indicating future enhancements. Has to be 0 for now.
848
849 __u64 args[4];
850
851Arguments for enabling a feature. If a feature needs initial values to
852function properly, this is the place to put them.
853
854 __u8 pad[64];
855};
856
Paul Bolle68ba6972011-02-15 00:05:59 +01008574.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300858
859Capability: KVM_CAP_MP_STATE
860Architectures: x86, ia64
861Type: vcpu ioctl
862Parameters: struct kvm_mp_state (out)
863Returns: 0 on success; -1 on error
864
865struct kvm_mp_state {
866 __u32 mp_state;
867};
868
869Returns the vcpu's current "multiprocessing state" (though also valid on
870uniprocessor guests).
871
872Possible values are:
873
874 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
875 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
876 which has not yet received an INIT signal
877 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
878 now ready for a SIPI
879 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
880 is waiting for an interrupt
881 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400882 accessible via KVM_GET_VCPU_EVENTS)
Avi Kivityb843f062010-04-25 15:51:46 +0300883
884This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
885irqchip, the multiprocessing state must be maintained by userspace.
886
Paul Bolle68ba6972011-02-15 00:05:59 +01008874.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300888
889Capability: KVM_CAP_MP_STATE
890Architectures: x86, ia64
891Type: vcpu ioctl
892Parameters: struct kvm_mp_state (in)
893Returns: 0 on success; -1 on error
894
895Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
896arguments.
897
898This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
899irqchip, the multiprocessing state must be maintained by userspace.
900
Paul Bolle68ba6972011-02-15 00:05:59 +01009014.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +0300902
903Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
904Architectures: x86
905Type: vm ioctl
906Parameters: unsigned long identity (in)
907Returns: 0 on success, -1 on error
908
909This ioctl defines the physical address of a one-page region in the guest
910physical address space. The region must be within the first 4GB of the
911guest physical address space and must not conflict with any memory slot
912or any mmio address. The guest may malfunction if it accesses this memory
913region.
914
915This ioctl is required on Intel-based hosts. This is needed on Intel hardware
916because of a quirk in the virtualization implementation (see the internals
917documentation when it pops into existence).
918
Paul Bolle68ba6972011-02-15 00:05:59 +01009194.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +0300920
921Capability: KVM_CAP_SET_BOOT_CPU_ID
922Architectures: x86, ia64
923Type: vm ioctl
924Parameters: unsigned long vcpu_id
925Returns: 0 on success, -1 on error
926
927Define which vcpu is the Bootstrap Processor (BSP). Values are the same
928as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
929is vcpu 0.
930
Paul Bolle68ba6972011-02-15 00:05:59 +01009314.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800932
933Capability: KVM_CAP_XSAVE
934Architectures: x86
935Type: vcpu ioctl
936Parameters: struct kvm_xsave (out)
937Returns: 0 on success, -1 on error
938
939struct kvm_xsave {
940 __u32 region[1024];
941};
942
943This ioctl would copy current vcpu's xsave struct to the userspace.
944
Paul Bolle68ba6972011-02-15 00:05:59 +01009454.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800946
947Capability: KVM_CAP_XSAVE
948Architectures: x86
949Type: vcpu ioctl
950Parameters: struct kvm_xsave (in)
951Returns: 0 on success, -1 on error
952
953struct kvm_xsave {
954 __u32 region[1024];
955};
956
957This ioctl would copy userspace's xsave struct to the kernel.
958
Paul Bolle68ba6972011-02-15 00:05:59 +01009594.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800960
961Capability: KVM_CAP_XCRS
962Architectures: x86
963Type: vcpu ioctl
964Parameters: struct kvm_xcrs (out)
965Returns: 0 on success, -1 on error
966
967struct kvm_xcr {
968 __u32 xcr;
969 __u32 reserved;
970 __u64 value;
971};
972
973struct kvm_xcrs {
974 __u32 nr_xcrs;
975 __u32 flags;
976 struct kvm_xcr xcrs[KVM_MAX_XCRS];
977 __u64 padding[16];
978};
979
980This ioctl would copy current vcpu's xcrs to the userspace.
981
Paul Bolle68ba6972011-02-15 00:05:59 +01009824.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800983
984Capability: KVM_CAP_XCRS
985Architectures: x86
986Type: vcpu ioctl
987Parameters: struct kvm_xcrs (in)
988Returns: 0 on success, -1 on error
989
990struct kvm_xcr {
991 __u32 xcr;
992 __u32 reserved;
993 __u64 value;
994};
995
996struct kvm_xcrs {
997 __u32 nr_xcrs;
998 __u32 flags;
999 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1000 __u64 padding[16];
1001};
1002
1003This ioctl would set vcpu's xcr to the value userspace specified.
1004
Paul Bolle68ba6972011-02-15 00:05:59 +010010054.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001006
1007Capability: KVM_CAP_EXT_CPUID
1008Architectures: x86
1009Type: system ioctl
1010Parameters: struct kvm_cpuid2 (in/out)
1011Returns: 0 on success, -1 on error
1012
1013struct kvm_cpuid2 {
1014 __u32 nent;
1015 __u32 padding;
1016 struct kvm_cpuid_entry2 entries[0];
1017};
1018
1019#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
1020#define KVM_CPUID_FLAG_STATEFUL_FUNC 2
1021#define KVM_CPUID_FLAG_STATE_READ_NEXT 4
1022
1023struct kvm_cpuid_entry2 {
1024 __u32 function;
1025 __u32 index;
1026 __u32 flags;
1027 __u32 eax;
1028 __u32 ebx;
1029 __u32 ecx;
1030 __u32 edx;
1031 __u32 padding[3];
1032};
1033
1034This ioctl returns x86 cpuid features which are supported by both the hardware
1035and kvm. Userspace can use the information returned by this ioctl to
1036construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1037hardware, kernel, and userspace capabilities, and with user requirements (for
1038example, the user may wish to constrain cpuid to emulate older hardware,
1039or for feature consistency across a cluster).
1040
1041Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1042with the 'nent' field indicating the number of entries in the variable-size
1043array 'entries'. If the number of entries is too low to describe the cpu
1044capabilities, an error (E2BIG) is returned. If the number is too high,
1045the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1046number is just right, the 'nent' field is adjusted to the number of valid
1047entries in the 'entries' array, which is then filled.
1048
1049The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001050with unknown or unsupported features masked out. Some features (for example,
1051x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1052emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001053
1054 function: the eax value used to obtain the entry
1055 index: the ecx value used to obtain the entry (for entries that are
1056 affected by ecx)
1057 flags: an OR of zero or more of the following:
1058 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1059 if the index field is valid
1060 KVM_CPUID_FLAG_STATEFUL_FUNC:
1061 if cpuid for this function returns different values for successive
1062 invocations; there will be several entries with the same function,
1063 all with this flag set
1064 KVM_CPUID_FLAG_STATE_READ_NEXT:
1065 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1066 the first entry to be read by a cpu
1067 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1068 this function/index combination
1069
Paul Bolle68ba6972011-02-15 00:05:59 +010010704.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001071
1072Capability: KVM_CAP_PPC_GET_PVINFO
1073Architectures: ppc
1074Type: vm ioctl
1075Parameters: struct kvm_ppc_pvinfo (out)
1076Returns: 0 on success, !0 on error
1077
1078struct kvm_ppc_pvinfo {
1079 __u32 flags;
1080 __u32 hcall[4];
1081 __u8 pad[108];
1082};
1083
1084This ioctl fetches PV specific information that need to be passed to the guest
1085using the device tree or other means from vm context.
1086
1087For now the only implemented piece of information distributed here is an array
1088of 4 instructions that make up a hypercall.
1089
1090If any additional field gets added to this structure later on, a bit for that
1091additional piece of information will be set in the flags bitmap.
1092
Paul Bolle68ba6972011-02-15 00:05:59 +010010934.48 KVM_ASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001094
1095Capability: KVM_CAP_DEVICE_ASSIGNMENT
1096Architectures: x86 ia64
1097Type: vm ioctl
1098Parameters: struct kvm_assigned_pci_dev (in)
1099Returns: 0 on success, -1 on error
1100
1101Assigns a host PCI device to the VM.
1102
1103struct kvm_assigned_pci_dev {
1104 __u32 assigned_dev_id;
1105 __u32 busnr;
1106 __u32 devfn;
1107 __u32 flags;
1108 __u32 segnr;
1109 union {
1110 __u32 reserved[11];
1111 };
1112};
1113
1114The PCI device is specified by the triple segnr, busnr, and devfn.
1115Identification in succeeding service requests is done via assigned_dev_id. The
1116following flags are specified:
1117
1118/* Depends on KVM_CAP_IOMMU */
1119#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1120
Paul Bolle68ba6972011-02-15 00:05:59 +010011214.49 KVM_DEASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001122
1123Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1124Architectures: x86 ia64
1125Type: vm ioctl
1126Parameters: struct kvm_assigned_pci_dev (in)
1127Returns: 0 on success, -1 on error
1128
1129Ends PCI device assignment, releasing all associated resources.
1130
1131See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1132used in kvm_assigned_pci_dev to identify the device.
1133
Paul Bolle68ba6972011-02-15 00:05:59 +010011344.50 KVM_ASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001135
1136Capability: KVM_CAP_ASSIGN_DEV_IRQ
1137Architectures: x86 ia64
1138Type: vm ioctl
1139Parameters: struct kvm_assigned_irq (in)
1140Returns: 0 on success, -1 on error
1141
1142Assigns an IRQ to a passed-through device.
1143
1144struct kvm_assigned_irq {
1145 __u32 assigned_dev_id;
1146 __u32 host_irq;
1147 __u32 guest_irq;
1148 __u32 flags;
1149 union {
1150 struct {
1151 __u32 addr_lo;
1152 __u32 addr_hi;
1153 __u32 data;
1154 } guest_msi;
1155 __u32 reserved[12];
1156 };
1157};
1158
1159The following flags are defined:
1160
1161#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
1162#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
1163#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
1164
1165#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
1166#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
1167#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
1168
1169It is not valid to specify multiple types per host or guest IRQ. However, the
1170IRQ type of host and guest can differ or can even be null.
1171
Paul Bolle68ba6972011-02-15 00:05:59 +010011724.51 KVM_DEASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001173
1174Capability: KVM_CAP_ASSIGN_DEV_IRQ
1175Architectures: x86 ia64
1176Type: vm ioctl
1177Parameters: struct kvm_assigned_irq (in)
1178Returns: 0 on success, -1 on error
1179
1180Ends an IRQ assignment to a passed-through device.
1181
1182See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1183by assigned_dev_id, flags must correspond to the IRQ type specified on
1184KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1185
Paul Bolle68ba6972011-02-15 00:05:59 +010011864.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001187
1188Capability: KVM_CAP_IRQ_ROUTING
1189Architectures: x86 ia64
1190Type: vm ioctl
1191Parameters: struct kvm_irq_routing (in)
1192Returns: 0 on success, -1 on error
1193
1194Sets the GSI routing table entries, overwriting any previously set entries.
1195
1196struct kvm_irq_routing {
1197 __u32 nr;
1198 __u32 flags;
1199 struct kvm_irq_routing_entry entries[0];
1200};
1201
1202No flags are specified so far, the corresponding field must be set to zero.
1203
1204struct kvm_irq_routing_entry {
1205 __u32 gsi;
1206 __u32 type;
1207 __u32 flags;
1208 __u32 pad;
1209 union {
1210 struct kvm_irq_routing_irqchip irqchip;
1211 struct kvm_irq_routing_msi msi;
1212 __u32 pad[8];
1213 } u;
1214};
1215
1216/* gsi routing entry types */
1217#define KVM_IRQ_ROUTING_IRQCHIP 1
1218#define KVM_IRQ_ROUTING_MSI 2
1219
1220No flags are specified so far, the corresponding field must be set to zero.
1221
1222struct kvm_irq_routing_irqchip {
1223 __u32 irqchip;
1224 __u32 pin;
1225};
1226
1227struct kvm_irq_routing_msi {
1228 __u32 address_lo;
1229 __u32 address_hi;
1230 __u32 data;
1231 __u32 pad;
1232};
1233
Paul Bolle68ba6972011-02-15 00:05:59 +010012344.53 KVM_ASSIGN_SET_MSIX_NR
Jan Kiszka49f48172010-11-16 22:30:07 +01001235
1236Capability: KVM_CAP_DEVICE_MSIX
1237Architectures: x86 ia64
1238Type: vm ioctl
1239Parameters: struct kvm_assigned_msix_nr (in)
1240Returns: 0 on success, -1 on error
1241
1242Set the number of MSI-X interrupts for an assigned device. This service can
1243only be called once in the lifetime of an assigned device.
1244
1245struct kvm_assigned_msix_nr {
1246 __u32 assigned_dev_id;
1247 __u16 entry_nr;
1248 __u16 padding;
1249};
1250
1251#define KVM_MAX_MSIX_PER_DEV 256
1252
Paul Bolle68ba6972011-02-15 00:05:59 +010012534.54 KVM_ASSIGN_SET_MSIX_ENTRY
Jan Kiszka49f48172010-11-16 22:30:07 +01001254
1255Capability: KVM_CAP_DEVICE_MSIX
1256Architectures: x86 ia64
1257Type: vm ioctl
1258Parameters: struct kvm_assigned_msix_entry (in)
1259Returns: 0 on success, -1 on error
1260
1261Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1262the GSI vector to zero means disabling the interrupt.
1263
1264struct kvm_assigned_msix_entry {
1265 __u32 assigned_dev_id;
1266 __u32 gsi;
1267 __u16 entry; /* The index of entry in the MSI-X table */
1268 __u16 padding[3];
1269};
1270
Joerg Roedel92a1f122011-03-25 09:44:51 +010012714.54 KVM_SET_TSC_KHZ
1272
1273Capability: KVM_CAP_TSC_CONTROL
1274Architectures: x86
1275Type: vcpu ioctl
1276Parameters: virtual tsc_khz
1277Returns: 0 on success, -1 on error
1278
1279Specifies the tsc frequency for the virtual machine. The unit of the
1280frequency is KHz.
1281
12824.55 KVM_GET_TSC_KHZ
1283
1284Capability: KVM_CAP_GET_TSC_KHZ
1285Architectures: x86
1286Type: vcpu ioctl
1287Parameters: none
1288Returns: virtual tsc-khz on success, negative value on error
1289
1290Returns the tsc frequency of the guest. The unit of the return value is
1291KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1292error.
1293
Avi Kivitye7677932011-05-11 08:30:51 -040012944.56 KVM_GET_LAPIC
1295
1296Capability: KVM_CAP_IRQCHIP
1297Architectures: x86
1298Type: vcpu ioctl
1299Parameters: struct kvm_lapic_state (out)
1300Returns: 0 on success, -1 on error
1301
1302#define KVM_APIC_REG_SIZE 0x400
1303struct kvm_lapic_state {
1304 char regs[KVM_APIC_REG_SIZE];
1305};
1306
1307Reads the Local APIC registers and copies them into the input argument. The
1308data format and layout are the same as documented in the architecture manual.
1309
13104.57 KVM_SET_LAPIC
1311
1312Capability: KVM_CAP_IRQCHIP
1313Architectures: x86
1314Type: vcpu ioctl
1315Parameters: struct kvm_lapic_state (in)
1316Returns: 0 on success, -1 on error
1317
1318#define KVM_APIC_REG_SIZE 0x400
1319struct kvm_lapic_state {
1320 char regs[KVM_APIC_REG_SIZE];
1321};
1322
1323Copies the input argument into the the Local APIC registers. The data format
1324and layout are the same as documented in the architecture manual.
1325
Avi Kivity9c1b96e2009-06-09 12:37:58 +030013265. The kvm_run structure
1327
1328Application code obtains a pointer to the kvm_run structure by
1329mmap()ing a vcpu fd. From that point, application code can control
1330execution by changing fields in kvm_run prior to calling the KVM_RUN
1331ioctl, and obtain information about the reason KVM_RUN returned by
1332looking up structure members.
1333
1334struct kvm_run {
1335 /* in */
1336 __u8 request_interrupt_window;
1337
1338Request that KVM_RUN return when it becomes possible to inject external
1339interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1340
1341 __u8 padding1[7];
1342
1343 /* out */
1344 __u32 exit_reason;
1345
1346When KVM_RUN has returned successfully (return value 0), this informs
1347application code why KVM_RUN has returned. Allowable values for this
1348field are detailed below.
1349
1350 __u8 ready_for_interrupt_injection;
1351
1352If request_interrupt_window has been specified, this field indicates
1353an interrupt can be injected now with KVM_INTERRUPT.
1354
1355 __u8 if_flag;
1356
1357The value of the current interrupt flag. Only valid if in-kernel
1358local APIC is not used.
1359
1360 __u8 padding2[2];
1361
1362 /* in (pre_kvm_run), out (post_kvm_run) */
1363 __u64 cr8;
1364
1365The value of the cr8 register. Only valid if in-kernel local APIC is
1366not used. Both input and output.
1367
1368 __u64 apic_base;
1369
1370The value of the APIC BASE msr. Only valid if in-kernel local
1371APIC is not used. Both input and output.
1372
1373 union {
1374 /* KVM_EXIT_UNKNOWN */
1375 struct {
1376 __u64 hardware_exit_reason;
1377 } hw;
1378
1379If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1380reasons. Further architecture-specific information is available in
1381hardware_exit_reason.
1382
1383 /* KVM_EXIT_FAIL_ENTRY */
1384 struct {
1385 __u64 hardware_entry_failure_reason;
1386 } fail_entry;
1387
1388If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1389to unknown reasons. Further architecture-specific information is
1390available in hardware_entry_failure_reason.
1391
1392 /* KVM_EXIT_EXCEPTION */
1393 struct {
1394 __u32 exception;
1395 __u32 error_code;
1396 } ex;
1397
1398Unused.
1399
1400 /* KVM_EXIT_IO */
1401 struct {
1402#define KVM_EXIT_IO_IN 0
1403#define KVM_EXIT_IO_OUT 1
1404 __u8 direction;
1405 __u8 size; /* bytes */
1406 __u16 port;
1407 __u32 count;
1408 __u64 data_offset; /* relative to kvm_run start */
1409 } io;
1410
Wu Fengguang2044892d2009-12-24 09:04:16 +08001411If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001412executed a port I/O instruction which could not be satisfied by kvm.
1413data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1414where kvm expects application code to place the data for the next
Wu Fengguang2044892d2009-12-24 09:04:16 +08001415KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001416
1417 struct {
1418 struct kvm_debug_exit_arch arch;
1419 } debug;
1420
1421Unused.
1422
1423 /* KVM_EXIT_MMIO */
1424 struct {
1425 __u64 phys_addr;
1426 __u8 data[8];
1427 __u32 len;
1428 __u8 is_write;
1429 } mmio;
1430
Wu Fengguang2044892d2009-12-24 09:04:16 +08001431If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001432executed a memory-mapped I/O instruction which could not be satisfied
1433by kvm. The 'data' member contains the written data if 'is_write' is
1434true, and should be filled by application code otherwise.
1435
Alexander Grafad0a0482010-03-24 21:48:30 +01001436NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1437operations are complete (and guest state is consistent) only after userspace
1438has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02001439incomplete operations and then check for pending signals. Userspace
1440can re-enter the guest with an unmasked signal pending to complete
1441pending operations.
1442
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001443 /* KVM_EXIT_HYPERCALL */
1444 struct {
1445 __u64 nr;
1446 __u64 args[6];
1447 __u64 ret;
1448 __u32 longmode;
1449 __u32 pad;
1450 } hypercall;
1451
Avi Kivity647dc492010-04-01 14:39:21 +03001452Unused. This was once used for 'hypercall to userspace'. To implement
1453such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1454Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001455
1456 /* KVM_EXIT_TPR_ACCESS */
1457 struct {
1458 __u64 rip;
1459 __u32 is_write;
1460 __u32 pad;
1461 } tpr_access;
1462
1463To be documented (KVM_TPR_ACCESS_REPORTING).
1464
1465 /* KVM_EXIT_S390_SIEIC */
1466 struct {
1467 __u8 icptcode;
1468 __u64 mask; /* psw upper half */
1469 __u64 addr; /* psw lower half */
1470 __u16 ipa;
1471 __u32 ipb;
1472 } s390_sieic;
1473
1474s390 specific.
1475
1476 /* KVM_EXIT_S390_RESET */
1477#define KVM_S390_RESET_POR 1
1478#define KVM_S390_RESET_CLEAR 2
1479#define KVM_S390_RESET_SUBSYSTEM 4
1480#define KVM_S390_RESET_CPU_INIT 8
1481#define KVM_S390_RESET_IPL 16
1482 __u64 s390_reset_flags;
1483
1484s390 specific.
1485
1486 /* KVM_EXIT_DCR */
1487 struct {
1488 __u32 dcrn;
1489 __u32 data;
1490 __u8 is_write;
1491 } dcr;
1492
1493powerpc specific.
1494
Alexander Grafad0a0482010-03-24 21:48:30 +01001495 /* KVM_EXIT_OSI */
1496 struct {
1497 __u64 gprs[32];
1498 } osi;
1499
1500MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1501hypercalls and exit with this exit struct that contains all the guest gprs.
1502
1503If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1504Userspace can now handle the hypercall and when it's done modify the gprs as
1505necessary. Upon guest entry all guest GPRs will then be replaced by the values
1506in this struct.
1507
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001508 /* Fix the size of the union. */
1509 char padding[256];
1510 };
1511};