blob: f64c41f8ba61746d2bad6b15ee6f01d319a84b18 [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
178in the range [0, max_vcpus).
179
Paul Bolle68ba6972011-02-15 00:05:59 +01001804.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300181
182Capability: basic
183Architectures: x86
184Type: vm ioctl
185Parameters: struct kvm_dirty_log (in/out)
186Returns: 0 on success, -1 on error
187
188/* for KVM_GET_DIRTY_LOG */
189struct kvm_dirty_log {
190 __u32 slot;
191 __u32 padding;
192 union {
193 void __user *dirty_bitmap; /* one bit per page */
194 __u64 padding;
195 };
196};
197
198Given a memory slot, return a bitmap containing any pages dirtied
199since the last call to this ioctl. Bit 0 is the first page in the
200memory slot. Ensure the entire structure is cleared to avoid padding
201issues.
202
Paul Bolle68ba6972011-02-15 00:05:59 +01002034.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300204
205Capability: basic
206Architectures: x86
207Type: vm ioctl
208Parameters: struct kvm_memory_alias (in)
209Returns: 0 (success), -1 (error)
210
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300211This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300212
Paul Bolle68ba6972011-02-15 00:05:59 +01002134.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300214
215Capability: basic
216Architectures: all
217Type: vcpu ioctl
218Parameters: none
219Returns: 0 on success, -1 on error
220Errors:
221 EINTR: an unmasked signal is pending
222
223This ioctl is used to run a guest virtual cpu. While there are no
224explicit parameters, there is an implicit parameter block that can be
225obtained by mmap()ing the vcpu fd at offset 0, with the size given by
226KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
227kvm_run' (see below).
228
Paul Bolle68ba6972011-02-15 00:05:59 +01002294.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300230
231Capability: basic
232Architectures: all
233Type: vcpu ioctl
234Parameters: struct kvm_regs (out)
235Returns: 0 on success, -1 on error
236
237Reads the general purpose registers from the vcpu.
238
239/* x86 */
240struct kvm_regs {
241 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
242 __u64 rax, rbx, rcx, rdx;
243 __u64 rsi, rdi, rsp, rbp;
244 __u64 r8, r9, r10, r11;
245 __u64 r12, r13, r14, r15;
246 __u64 rip, rflags;
247};
248
Paul Bolle68ba6972011-02-15 00:05:59 +01002494.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300250
251Capability: basic
252Architectures: all
253Type: vcpu ioctl
254Parameters: struct kvm_regs (in)
255Returns: 0 on success, -1 on error
256
257Writes the general purpose registers into the vcpu.
258
259See KVM_GET_REGS for the data structure.
260
Paul Bolle68ba6972011-02-15 00:05:59 +01002614.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300262
263Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500264Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300265Type: vcpu ioctl
266Parameters: struct kvm_sregs (out)
267Returns: 0 on success, -1 on error
268
269Reads special registers from the vcpu.
270
271/* x86 */
272struct kvm_sregs {
273 struct kvm_segment cs, ds, es, fs, gs, ss;
274 struct kvm_segment tr, ldt;
275 struct kvm_dtable gdt, idt;
276 __u64 cr0, cr2, cr3, cr4, cr8;
277 __u64 efer;
278 __u64 apic_base;
279 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
280};
281
Scott Wood5ce941e2011-04-27 17:24:21 -0500282/* ppc -- see arch/powerpc/include/asm/kvm.h */
283
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300284interrupt_bitmap is a bitmap of pending external interrupts. At most
285one bit may be set. This interrupt has been acknowledged by the APIC
286but not yet injected into the cpu core.
287
Paul Bolle68ba6972011-02-15 00:05:59 +01002884.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300289
290Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500291Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300292Type: vcpu ioctl
293Parameters: struct kvm_sregs (in)
294Returns: 0 on success, -1 on error
295
296Writes special registers into the vcpu. See KVM_GET_SREGS for the
297data structures.
298
Paul Bolle68ba6972011-02-15 00:05:59 +01002994.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300300
301Capability: basic
302Architectures: x86
303Type: vcpu ioctl
304Parameters: struct kvm_translation (in/out)
305Returns: 0 on success, -1 on error
306
307Translates a virtual address according to the vcpu's current address
308translation mode.
309
310struct kvm_translation {
311 /* in */
312 __u64 linear_address;
313
314 /* out */
315 __u64 physical_address;
316 __u8 valid;
317 __u8 writeable;
318 __u8 usermode;
319 __u8 pad[5];
320};
321
Paul Bolle68ba6972011-02-15 00:05:59 +01003224.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300323
324Capability: basic
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200325Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300326Type: vcpu ioctl
327Parameters: struct kvm_interrupt (in)
328Returns: 0 on success, -1 on error
329
330Queues a hardware interrupt vector to be injected. This is only
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200331useful if in-kernel local APIC or equivalent is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300332
333/* for KVM_INTERRUPT */
334struct kvm_interrupt {
335 /* in */
336 __u32 irq;
337};
338
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200339X86:
340
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300341Note 'irq' is an interrupt vector, not an interrupt pin or line.
342
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200343PPC:
344
345Queues an external interrupt to be injected. This ioctl is overleaded
346with 3 different irq values:
347
348a) KVM_INTERRUPT_SET
349
350 This injects an edge type external interrupt into the guest once it's ready
351 to receive interrupts. When injected, the interrupt is done.
352
353b) KVM_INTERRUPT_UNSET
354
355 This unsets any pending interrupt.
356
357 Only available with KVM_CAP_PPC_UNSET_IRQ.
358
359c) KVM_INTERRUPT_SET_LEVEL
360
361 This injects a level type external interrupt into the guest context. The
362 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
363 is triggered.
364
365 Only available with KVM_CAP_PPC_IRQ_LEVEL.
366
367Note that any value for 'irq' other than the ones stated above is invalid
368and incurs unexpected behavior.
369
Paul Bolle68ba6972011-02-15 00:05:59 +01003704.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300371
372Capability: basic
373Architectures: none
374Type: vcpu ioctl
375Parameters: none)
376Returns: -1 on error
377
378Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
379
Paul Bolle68ba6972011-02-15 00:05:59 +01003804.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300381
382Capability: basic
383Architectures: x86
384Type: vcpu ioctl
385Parameters: struct kvm_msrs (in/out)
386Returns: 0 on success, -1 on error
387
388Reads model-specific registers from the vcpu. Supported msr indices can
389be obtained using KVM_GET_MSR_INDEX_LIST.
390
391struct kvm_msrs {
392 __u32 nmsrs; /* number of msrs in entries */
393 __u32 pad;
394
395 struct kvm_msr_entry entries[0];
396};
397
398struct kvm_msr_entry {
399 __u32 index;
400 __u32 reserved;
401 __u64 data;
402};
403
404Application code should set the 'nmsrs' member (which indicates the
405size of the entries array) and the 'index' member of each array entry.
406kvm will fill in the 'data' member.
407
Paul Bolle68ba6972011-02-15 00:05:59 +01004084.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300409
410Capability: basic
411Architectures: x86
412Type: vcpu ioctl
413Parameters: struct kvm_msrs (in)
414Returns: 0 on success, -1 on error
415
416Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
417data structures.
418
419Application code should set the 'nmsrs' member (which indicates the
420size of the entries array), and the 'index' and 'data' members of each
421array entry.
422
Paul Bolle68ba6972011-02-15 00:05:59 +01004234.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300424
425Capability: basic
426Architectures: x86
427Type: vcpu ioctl
428Parameters: struct kvm_cpuid (in)
429Returns: 0 on success, -1 on error
430
431Defines the vcpu responses to the cpuid instruction. Applications
432should use the KVM_SET_CPUID2 ioctl if available.
433
434
435struct kvm_cpuid_entry {
436 __u32 function;
437 __u32 eax;
438 __u32 ebx;
439 __u32 ecx;
440 __u32 edx;
441 __u32 padding;
442};
443
444/* for KVM_SET_CPUID */
445struct kvm_cpuid {
446 __u32 nent;
447 __u32 padding;
448 struct kvm_cpuid_entry entries[0];
449};
450
Paul Bolle68ba6972011-02-15 00:05:59 +01004514.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300452
453Capability: basic
454Architectures: x86
455Type: vcpu ioctl
456Parameters: struct kvm_signal_mask (in)
457Returns: 0 on success, -1 on error
458
459Defines which signals are blocked during execution of KVM_RUN. This
460signal mask temporarily overrides the threads signal mask. Any
461unblocked signal received (except SIGKILL and SIGSTOP, which retain
462their traditional behaviour) will cause KVM_RUN to return with -EINTR.
463
464Note the signal will only be delivered if not blocked by the original
465signal mask.
466
467/* for KVM_SET_SIGNAL_MASK */
468struct kvm_signal_mask {
469 __u32 len;
470 __u8 sigset[0];
471};
472
Paul Bolle68ba6972011-02-15 00:05:59 +01004734.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300474
475Capability: basic
476Architectures: x86
477Type: vcpu ioctl
478Parameters: struct kvm_fpu (out)
479Returns: 0 on success, -1 on error
480
481Reads the floating point state from the vcpu.
482
483/* for KVM_GET_FPU and KVM_SET_FPU */
484struct kvm_fpu {
485 __u8 fpr[8][16];
486 __u16 fcw;
487 __u16 fsw;
488 __u8 ftwx; /* in fxsave format */
489 __u8 pad1;
490 __u16 last_opcode;
491 __u64 last_ip;
492 __u64 last_dp;
493 __u8 xmm[16][16];
494 __u32 mxcsr;
495 __u32 pad2;
496};
497
Paul Bolle68ba6972011-02-15 00:05:59 +01004984.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300499
500Capability: basic
501Architectures: x86
502Type: vcpu ioctl
503Parameters: struct kvm_fpu (in)
504Returns: 0 on success, -1 on error
505
506Writes the floating point state to the vcpu.
507
508/* for KVM_GET_FPU and KVM_SET_FPU */
509struct kvm_fpu {
510 __u8 fpr[8][16];
511 __u16 fcw;
512 __u16 fsw;
513 __u8 ftwx; /* in fxsave format */
514 __u8 pad1;
515 __u16 last_opcode;
516 __u64 last_ip;
517 __u64 last_dp;
518 __u8 xmm[16][16];
519 __u32 mxcsr;
520 __u32 pad2;
521};
522
Paul Bolle68ba6972011-02-15 00:05:59 +01005234.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300524
525Capability: KVM_CAP_IRQCHIP
526Architectures: x86, ia64
527Type: vm ioctl
528Parameters: none
529Returns: 0 on success, -1 on error
530
531Creates an interrupt controller model in the kernel. On x86, creates a virtual
532ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
533local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
534only go to the IOAPIC. On ia64, a IOSAPIC is created.
535
Paul Bolle68ba6972011-02-15 00:05:59 +01005364.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300537
538Capability: KVM_CAP_IRQCHIP
539Architectures: x86, ia64
540Type: vm ioctl
541Parameters: struct kvm_irq_level
542Returns: 0 on success, -1 on error
543
544Sets the level of a GSI input to the interrupt controller model in the kernel.
545Requires that an interrupt controller model has been previously created with
546KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
547to be set to 1 and then back to 0.
548
549struct kvm_irq_level {
550 union {
551 __u32 irq; /* GSI */
552 __s32 status; /* not used for KVM_IRQ_LEVEL */
553 };
554 __u32 level; /* 0 or 1 */
555};
556
Paul Bolle68ba6972011-02-15 00:05:59 +01005574.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300558
559Capability: KVM_CAP_IRQCHIP
560Architectures: x86, ia64
561Type: vm ioctl
562Parameters: struct kvm_irqchip (in/out)
563Returns: 0 on success, -1 on error
564
565Reads the state of a kernel interrupt controller created with
566KVM_CREATE_IRQCHIP into a buffer provided by the caller.
567
568struct kvm_irqchip {
569 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
570 __u32 pad;
571 union {
572 char dummy[512]; /* reserving space */
573 struct kvm_pic_state pic;
574 struct kvm_ioapic_state ioapic;
575 } chip;
576};
577
Paul Bolle68ba6972011-02-15 00:05:59 +01005784.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300579
580Capability: KVM_CAP_IRQCHIP
581Architectures: x86, ia64
582Type: vm ioctl
583Parameters: struct kvm_irqchip (in)
584Returns: 0 on success, -1 on error
585
586Sets the state of a kernel interrupt controller created with
587KVM_CREATE_IRQCHIP from a buffer provided by the caller.
588
589struct kvm_irqchip {
590 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
591 __u32 pad;
592 union {
593 char dummy[512]; /* reserving space */
594 struct kvm_pic_state pic;
595 struct kvm_ioapic_state ioapic;
596 } chip;
597};
598
Paul Bolle68ba6972011-02-15 00:05:59 +01005994.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700600
601Capability: KVM_CAP_XEN_HVM
602Architectures: x86
603Type: vm ioctl
604Parameters: struct kvm_xen_hvm_config (in)
605Returns: 0 on success, -1 on error
606
607Sets the MSR that the Xen HVM guest uses to initialize its hypercall
608page, and provides the starting address and size of the hypercall
609blobs in userspace. When the guest writes the MSR, kvm copies one
610page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
611memory.
612
613struct kvm_xen_hvm_config {
614 __u32 flags;
615 __u32 msr;
616 __u64 blob_addr_32;
617 __u64 blob_addr_64;
618 __u8 blob_size_32;
619 __u8 blob_size_64;
620 __u8 pad2[30];
621};
622
Paul Bolle68ba6972011-02-15 00:05:59 +01006234.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400624
625Capability: KVM_CAP_ADJUST_CLOCK
626Architectures: x86
627Type: vm ioctl
628Parameters: struct kvm_clock_data (out)
629Returns: 0 on success, -1 on error
630
631Gets the current timestamp of kvmclock as seen by the current guest. In
632conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
633such as migration.
634
635struct kvm_clock_data {
636 __u64 clock; /* kvmclock current value */
637 __u32 flags;
638 __u32 pad[9];
639};
640
Paul Bolle68ba6972011-02-15 00:05:59 +01006414.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400642
643Capability: KVM_CAP_ADJUST_CLOCK
644Architectures: x86
645Type: vm ioctl
646Parameters: struct kvm_clock_data (in)
647Returns: 0 on success, -1 on error
648
Wu Fengguang20448922009-12-24 09:04:16 +0800649Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400650In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
651such as migration.
652
653struct kvm_clock_data {
654 __u64 clock; /* kvmclock current value */
655 __u32 flags;
656 __u32 pad[9];
657};
658
Paul Bolle68ba6972011-02-15 00:05:59 +01006594.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100660
661Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100662Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100663Architectures: x86
664Type: vm ioctl
665Parameters: struct kvm_vcpu_event (out)
666Returns: 0 on success, -1 on error
667
668Gets currently pending exceptions, interrupts, and NMIs as well as related
669states of the vcpu.
670
671struct kvm_vcpu_events {
672 struct {
673 __u8 injected;
674 __u8 nr;
675 __u8 has_error_code;
676 __u8 pad;
677 __u32 error_code;
678 } exception;
679 struct {
680 __u8 injected;
681 __u8 nr;
682 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100683 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100684 } interrupt;
685 struct {
686 __u8 injected;
687 __u8 pending;
688 __u8 masked;
689 __u8 pad;
690 } nmi;
691 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100692 __u32 flags;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100693};
694
Jan Kiszka48005f62010-02-19 19:38:07 +0100695KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
696interrupt.shadow contains a valid state. Otherwise, this field is undefined.
697
Paul Bolle68ba6972011-02-15 00:05:59 +01006984.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100699
700Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100701Extended by: KVM_CAP_INTR_SHADOW
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100702Architectures: x86
703Type: vm ioctl
704Parameters: struct kvm_vcpu_event (in)
705Returns: 0 on success, -1 on error
706
707Set pending exceptions, interrupts, and NMIs as well as related states of the
708vcpu.
709
710See KVM_GET_VCPU_EVENTS for the data structure.
711
Jan Kiszkadab4b912009-12-06 18:24:15 +0100712Fields that may be modified asynchronously by running VCPUs can be excluded
713from the update. These fields are nmi.pending and sipi_vector. Keep the
714corresponding bits in the flags field cleared to suppress overwriting the
715current in-kernel state. The bits are:
716
717KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
718KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
719
Jan Kiszka48005f62010-02-19 19:38:07 +0100720If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
721the flags field to signal that interrupt.shadow contains a valid state and
722shall be written into the VCPU.
723
Paul Bolle68ba6972011-02-15 00:05:59 +01007244.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100725
726Capability: KVM_CAP_DEBUGREGS
727Architectures: x86
728Type: vm ioctl
729Parameters: struct kvm_debugregs (out)
730Returns: 0 on success, -1 on error
731
732Reads debug registers from the vcpu.
733
734struct kvm_debugregs {
735 __u64 db[4];
736 __u64 dr6;
737 __u64 dr7;
738 __u64 flags;
739 __u64 reserved[9];
740};
741
Paul Bolle68ba6972011-02-15 00:05:59 +01007424.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +0100743
744Capability: KVM_CAP_DEBUGREGS
745Architectures: x86
746Type: vm ioctl
747Parameters: struct kvm_debugregs (in)
748Returns: 0 on success, -1 on error
749
750Writes debug registers into the vcpu.
751
752See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
753yet and must be cleared on entry.
754
Paul Bolle68ba6972011-02-15 00:05:59 +01007554.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +0200756
757Capability: KVM_CAP_USER_MEM
758Architectures: all
759Type: vm ioctl
760Parameters: struct kvm_userspace_memory_region (in)
761Returns: 0 on success, -1 on error
762
763struct kvm_userspace_memory_region {
764 __u32 slot;
765 __u32 flags;
766 __u64 guest_phys_addr;
767 __u64 memory_size; /* bytes */
768 __u64 userspace_addr; /* start of the userspace allocated memory */
769};
770
771/* for kvm_memory_region::flags */
772#define KVM_MEM_LOG_DIRTY_PAGES 1UL
773
774This ioctl allows the user to create or modify a guest physical memory
775slot. When changing an existing slot, it may be moved in the guest
776physical memory space, or its flags may be modified. It may not be
777resized. Slots may not overlap in guest physical address space.
778
779Memory for the region is taken starting at the address denoted by the
780field userspace_addr, which must point at user addressable memory for
781the entire memory slot size. Any object may back this memory, including
782anonymous memory, ordinary files, and hugetlbfs.
783
784It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
785be identical. This allows large pages in the guest to be backed by large
786pages in the host.
787
788The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
789instructs kvm to keep track of writes to memory within the slot. See
790the KVM_GET_DIRTY_LOG ioctl.
791
792When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
793region are automatically reflected into the guest. For example, an mmap()
794that affects the region will be made visible immediately. Another example
795is madvise(MADV_DROP).
796
797It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
798The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
799allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100800
Paul Bolle68ba6972011-02-15 00:05:59 +01008014.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +0200802
803Capability: KVM_CAP_SET_TSS_ADDR
804Architectures: x86
805Type: vm ioctl
806Parameters: unsigned long tss_address (in)
807Returns: 0 on success, -1 on error
808
809This ioctl defines the physical address of a three-page region in the guest
810physical address space. The region must be within the first 4GB of the
811guest physical address space and must not conflict with any memory slot
812or any mmio address. The guest may malfunction if it accesses this memory
813region.
814
815This ioctl is required on Intel-based hosts. This is needed on Intel hardware
816because of a quirk in the virtualization implementation (see the internals
817documentation when it pops into existence).
818
Paul Bolle68ba6972011-02-15 00:05:59 +01008194.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +0100820
821Capability: KVM_CAP_ENABLE_CAP
822Architectures: ppc
823Type: vcpu ioctl
824Parameters: struct kvm_enable_cap (in)
825Returns: 0 on success; -1 on error
826
827+Not all extensions are enabled by default. Using this ioctl the application
828can enable an extension, making it available to the guest.
829
830On systems that do not support this ioctl, it always fails. On systems that
831do support it, it only works for extensions that are supported for enablement.
832
833To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
834be used.
835
836struct kvm_enable_cap {
837 /* in */
838 __u32 cap;
839
840The capability that is supposed to get enabled.
841
842 __u32 flags;
843
844A bitfield indicating future enhancements. Has to be 0 for now.
845
846 __u64 args[4];
847
848Arguments for enabling a feature. If a feature needs initial values to
849function properly, this is the place to put them.
850
851 __u8 pad[64];
852};
853
Paul Bolle68ba6972011-02-15 00:05:59 +01008544.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300855
856Capability: KVM_CAP_MP_STATE
857Architectures: x86, ia64
858Type: vcpu ioctl
859Parameters: struct kvm_mp_state (out)
860Returns: 0 on success; -1 on error
861
862struct kvm_mp_state {
863 __u32 mp_state;
864};
865
866Returns the vcpu's current "multiprocessing state" (though also valid on
867uniprocessor guests).
868
869Possible values are:
870
871 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running
872 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
873 which has not yet received an INIT signal
874 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
875 now ready for a SIPI
876 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
877 is waiting for an interrupt
878 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400879 accessible via KVM_GET_VCPU_EVENTS)
Avi Kivityb843f062010-04-25 15:51:46 +0300880
881This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
882irqchip, the multiprocessing state must be maintained by userspace.
883
Paul Bolle68ba6972011-02-15 00:05:59 +01008844.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +0300885
886Capability: KVM_CAP_MP_STATE
887Architectures: x86, ia64
888Type: vcpu ioctl
889Parameters: struct kvm_mp_state (in)
890Returns: 0 on success; -1 on error
891
892Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
893arguments.
894
895This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
896irqchip, the multiprocessing state must be maintained by userspace.
897
Paul Bolle68ba6972011-02-15 00:05:59 +01008984.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +0300899
900Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
901Architectures: x86
902Type: vm ioctl
903Parameters: unsigned long identity (in)
904Returns: 0 on success, -1 on error
905
906This ioctl defines the physical address of a one-page region in the guest
907physical address space. The region must be within the first 4GB of the
908guest physical address space and must not conflict with any memory slot
909or any mmio address. The guest may malfunction if it accesses this memory
910region.
911
912This ioctl is required on Intel-based hosts. This is needed on Intel hardware
913because of a quirk in the virtualization implementation (see the internals
914documentation when it pops into existence).
915
Paul Bolle68ba6972011-02-15 00:05:59 +01009164.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +0300917
918Capability: KVM_CAP_SET_BOOT_CPU_ID
919Architectures: x86, ia64
920Type: vm ioctl
921Parameters: unsigned long vcpu_id
922Returns: 0 on success, -1 on error
923
924Define which vcpu is the Bootstrap Processor (BSP). Values are the same
925as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
926is vcpu 0.
927
Paul Bolle68ba6972011-02-15 00:05:59 +01009284.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800929
930Capability: KVM_CAP_XSAVE
931Architectures: x86
932Type: vcpu ioctl
933Parameters: struct kvm_xsave (out)
934Returns: 0 on success, -1 on error
935
936struct kvm_xsave {
937 __u32 region[1024];
938};
939
940This ioctl would copy current vcpu's xsave struct to the userspace.
941
Paul Bolle68ba6972011-02-15 00:05:59 +01009424.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800943
944Capability: KVM_CAP_XSAVE
945Architectures: x86
946Type: vcpu ioctl
947Parameters: struct kvm_xsave (in)
948Returns: 0 on success, -1 on error
949
950struct kvm_xsave {
951 __u32 region[1024];
952};
953
954This ioctl would copy userspace's xsave struct to the kernel.
955
Paul Bolle68ba6972011-02-15 00:05:59 +01009564.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800957
958Capability: KVM_CAP_XCRS
959Architectures: x86
960Type: vcpu ioctl
961Parameters: struct kvm_xcrs (out)
962Returns: 0 on success, -1 on error
963
964struct kvm_xcr {
965 __u32 xcr;
966 __u32 reserved;
967 __u64 value;
968};
969
970struct kvm_xcrs {
971 __u32 nr_xcrs;
972 __u32 flags;
973 struct kvm_xcr xcrs[KVM_MAX_XCRS];
974 __u64 padding[16];
975};
976
977This ioctl would copy current vcpu's xcrs to the userspace.
978
Paul Bolle68ba6972011-02-15 00:05:59 +01009794.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +0800980
981Capability: KVM_CAP_XCRS
982Architectures: x86
983Type: vcpu ioctl
984Parameters: struct kvm_xcrs (in)
985Returns: 0 on success, -1 on error
986
987struct kvm_xcr {
988 __u32 xcr;
989 __u32 reserved;
990 __u64 value;
991};
992
993struct kvm_xcrs {
994 __u32 nr_xcrs;
995 __u32 flags;
996 struct kvm_xcr xcrs[KVM_MAX_XCRS];
997 __u64 padding[16];
998};
999
1000This ioctl would set vcpu's xcr to the value userspace specified.
1001
Paul Bolle68ba6972011-02-15 00:05:59 +010010024.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001003
1004Capability: KVM_CAP_EXT_CPUID
1005Architectures: x86
1006Type: system ioctl
1007Parameters: struct kvm_cpuid2 (in/out)
1008Returns: 0 on success, -1 on error
1009
1010struct kvm_cpuid2 {
1011 __u32 nent;
1012 __u32 padding;
1013 struct kvm_cpuid_entry2 entries[0];
1014};
1015
1016#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
1017#define KVM_CPUID_FLAG_STATEFUL_FUNC 2
1018#define KVM_CPUID_FLAG_STATE_READ_NEXT 4
1019
1020struct kvm_cpuid_entry2 {
1021 __u32 function;
1022 __u32 index;
1023 __u32 flags;
1024 __u32 eax;
1025 __u32 ebx;
1026 __u32 ecx;
1027 __u32 edx;
1028 __u32 padding[3];
1029};
1030
1031This ioctl returns x86 cpuid features which are supported by both the hardware
1032and kvm. Userspace can use the information returned by this ioctl to
1033construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1034hardware, kernel, and userspace capabilities, and with user requirements (for
1035example, the user may wish to constrain cpuid to emulate older hardware,
1036or for feature consistency across a cluster).
1037
1038Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1039with the 'nent' field indicating the number of entries in the variable-size
1040array 'entries'. If the number of entries is too low to describe the cpu
1041capabilities, an error (E2BIG) is returned. If the number is too high,
1042the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1043number is just right, the 'nent' field is adjusted to the number of valid
1044entries in the 'entries' array, which is then filled.
1045
1046The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001047with unknown or unsupported features masked out. Some features (for example,
1048x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1049emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001050
1051 function: the eax value used to obtain the entry
1052 index: the ecx value used to obtain the entry (for entries that are
1053 affected by ecx)
1054 flags: an OR of zero or more of the following:
1055 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1056 if the index field is valid
1057 KVM_CPUID_FLAG_STATEFUL_FUNC:
1058 if cpuid for this function returns different values for successive
1059 invocations; there will be several entries with the same function,
1060 all with this flag set
1061 KVM_CPUID_FLAG_STATE_READ_NEXT:
1062 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1063 the first entry to be read by a cpu
1064 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1065 this function/index combination
1066
Paul Bolle68ba6972011-02-15 00:05:59 +010010674.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001068
1069Capability: KVM_CAP_PPC_GET_PVINFO
1070Architectures: ppc
1071Type: vm ioctl
1072Parameters: struct kvm_ppc_pvinfo (out)
1073Returns: 0 on success, !0 on error
1074
1075struct kvm_ppc_pvinfo {
1076 __u32 flags;
1077 __u32 hcall[4];
1078 __u8 pad[108];
1079};
1080
1081This ioctl fetches PV specific information that need to be passed to the guest
1082using the device tree or other means from vm context.
1083
1084For now the only implemented piece of information distributed here is an array
1085of 4 instructions that make up a hypercall.
1086
1087If any additional field gets added to this structure later on, a bit for that
1088additional piece of information will be set in the flags bitmap.
1089
Paul Bolle68ba6972011-02-15 00:05:59 +010010904.48 KVM_ASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001091
1092Capability: KVM_CAP_DEVICE_ASSIGNMENT
1093Architectures: x86 ia64
1094Type: vm ioctl
1095Parameters: struct kvm_assigned_pci_dev (in)
1096Returns: 0 on success, -1 on error
1097
1098Assigns a host PCI device to the VM.
1099
1100struct kvm_assigned_pci_dev {
1101 __u32 assigned_dev_id;
1102 __u32 busnr;
1103 __u32 devfn;
1104 __u32 flags;
1105 __u32 segnr;
1106 union {
1107 __u32 reserved[11];
1108 };
1109};
1110
1111The PCI device is specified by the triple segnr, busnr, and devfn.
1112Identification in succeeding service requests is done via assigned_dev_id. The
1113following flags are specified:
1114
1115/* Depends on KVM_CAP_IOMMU */
1116#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1117
Paul Bolle68ba6972011-02-15 00:05:59 +010011184.49 KVM_DEASSIGN_PCI_DEVICE
Jan Kiszka49f48172010-11-16 22:30:07 +01001119
1120Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1121Architectures: x86 ia64
1122Type: vm ioctl
1123Parameters: struct kvm_assigned_pci_dev (in)
1124Returns: 0 on success, -1 on error
1125
1126Ends PCI device assignment, releasing all associated resources.
1127
1128See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1129used in kvm_assigned_pci_dev to identify the device.
1130
Paul Bolle68ba6972011-02-15 00:05:59 +010011314.50 KVM_ASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001132
1133Capability: KVM_CAP_ASSIGN_DEV_IRQ
1134Architectures: x86 ia64
1135Type: vm ioctl
1136Parameters: struct kvm_assigned_irq (in)
1137Returns: 0 on success, -1 on error
1138
1139Assigns an IRQ to a passed-through device.
1140
1141struct kvm_assigned_irq {
1142 __u32 assigned_dev_id;
1143 __u32 host_irq;
1144 __u32 guest_irq;
1145 __u32 flags;
1146 union {
1147 struct {
1148 __u32 addr_lo;
1149 __u32 addr_hi;
1150 __u32 data;
1151 } guest_msi;
1152 __u32 reserved[12];
1153 };
1154};
1155
1156The following flags are defined:
1157
1158#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
1159#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
1160#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
1161
1162#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
1163#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
1164#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
1165
1166It is not valid to specify multiple types per host or guest IRQ. However, the
1167IRQ type of host and guest can differ or can even be null.
1168
Paul Bolle68ba6972011-02-15 00:05:59 +010011694.51 KVM_DEASSIGN_DEV_IRQ
Jan Kiszka49f48172010-11-16 22:30:07 +01001170
1171Capability: KVM_CAP_ASSIGN_DEV_IRQ
1172Architectures: x86 ia64
1173Type: vm ioctl
1174Parameters: struct kvm_assigned_irq (in)
1175Returns: 0 on success, -1 on error
1176
1177Ends an IRQ assignment to a passed-through device.
1178
1179See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1180by assigned_dev_id, flags must correspond to the IRQ type specified on
1181KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1182
Paul Bolle68ba6972011-02-15 00:05:59 +010011834.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001184
1185Capability: KVM_CAP_IRQ_ROUTING
1186Architectures: x86 ia64
1187Type: vm ioctl
1188Parameters: struct kvm_irq_routing (in)
1189Returns: 0 on success, -1 on error
1190
1191Sets the GSI routing table entries, overwriting any previously set entries.
1192
1193struct kvm_irq_routing {
1194 __u32 nr;
1195 __u32 flags;
1196 struct kvm_irq_routing_entry entries[0];
1197};
1198
1199No flags are specified so far, the corresponding field must be set to zero.
1200
1201struct kvm_irq_routing_entry {
1202 __u32 gsi;
1203 __u32 type;
1204 __u32 flags;
1205 __u32 pad;
1206 union {
1207 struct kvm_irq_routing_irqchip irqchip;
1208 struct kvm_irq_routing_msi msi;
1209 __u32 pad[8];
1210 } u;
1211};
1212
1213/* gsi routing entry types */
1214#define KVM_IRQ_ROUTING_IRQCHIP 1
1215#define KVM_IRQ_ROUTING_MSI 2
1216
1217No flags are specified so far, the corresponding field must be set to zero.
1218
1219struct kvm_irq_routing_irqchip {
1220 __u32 irqchip;
1221 __u32 pin;
1222};
1223
1224struct kvm_irq_routing_msi {
1225 __u32 address_lo;
1226 __u32 address_hi;
1227 __u32 data;
1228 __u32 pad;
1229};
1230
Paul Bolle68ba6972011-02-15 00:05:59 +010012314.53 KVM_ASSIGN_SET_MSIX_NR
Jan Kiszka49f48172010-11-16 22:30:07 +01001232
1233Capability: KVM_CAP_DEVICE_MSIX
1234Architectures: x86 ia64
1235Type: vm ioctl
1236Parameters: struct kvm_assigned_msix_nr (in)
1237Returns: 0 on success, -1 on error
1238
1239Set the number of MSI-X interrupts for an assigned device. This service can
1240only be called once in the lifetime of an assigned device.
1241
1242struct kvm_assigned_msix_nr {
1243 __u32 assigned_dev_id;
1244 __u16 entry_nr;
1245 __u16 padding;
1246};
1247
1248#define KVM_MAX_MSIX_PER_DEV 256
1249
Paul Bolle68ba6972011-02-15 00:05:59 +010012504.54 KVM_ASSIGN_SET_MSIX_ENTRY
Jan Kiszka49f48172010-11-16 22:30:07 +01001251
1252Capability: KVM_CAP_DEVICE_MSIX
1253Architectures: x86 ia64
1254Type: vm ioctl
1255Parameters: struct kvm_assigned_msix_entry (in)
1256Returns: 0 on success, -1 on error
1257
1258Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1259the GSI vector to zero means disabling the interrupt.
1260
1261struct kvm_assigned_msix_entry {
1262 __u32 assigned_dev_id;
1263 __u32 gsi;
1264 __u16 entry; /* The index of entry in the MSI-X table */
1265 __u16 padding[3];
1266};
1267
Joerg Roedel92a1f122011-03-25 09:44:51 +010012684.54 KVM_SET_TSC_KHZ
1269
1270Capability: KVM_CAP_TSC_CONTROL
1271Architectures: x86
1272Type: vcpu ioctl
1273Parameters: virtual tsc_khz
1274Returns: 0 on success, -1 on error
1275
1276Specifies the tsc frequency for the virtual machine. The unit of the
1277frequency is KHz.
1278
12794.55 KVM_GET_TSC_KHZ
1280
1281Capability: KVM_CAP_GET_TSC_KHZ
1282Architectures: x86
1283Type: vcpu ioctl
1284Parameters: none
1285Returns: virtual tsc-khz on success, negative value on error
1286
1287Returns the tsc frequency of the guest. The unit of the return value is
1288KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1289error.
1290
Avi Kivity9c1b96e2009-06-09 12:37:58 +030012915. The kvm_run structure
1292
1293Application code obtains a pointer to the kvm_run structure by
1294mmap()ing a vcpu fd. From that point, application code can control
1295execution by changing fields in kvm_run prior to calling the KVM_RUN
1296ioctl, and obtain information about the reason KVM_RUN returned by
1297looking up structure members.
1298
1299struct kvm_run {
1300 /* in */
1301 __u8 request_interrupt_window;
1302
1303Request that KVM_RUN return when it becomes possible to inject external
1304interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1305
1306 __u8 padding1[7];
1307
1308 /* out */
1309 __u32 exit_reason;
1310
1311When KVM_RUN has returned successfully (return value 0), this informs
1312application code why KVM_RUN has returned. Allowable values for this
1313field are detailed below.
1314
1315 __u8 ready_for_interrupt_injection;
1316
1317If request_interrupt_window has been specified, this field indicates
1318an interrupt can be injected now with KVM_INTERRUPT.
1319
1320 __u8 if_flag;
1321
1322The value of the current interrupt flag. Only valid if in-kernel
1323local APIC is not used.
1324
1325 __u8 padding2[2];
1326
1327 /* in (pre_kvm_run), out (post_kvm_run) */
1328 __u64 cr8;
1329
1330The value of the cr8 register. Only valid if in-kernel local APIC is
1331not used. Both input and output.
1332
1333 __u64 apic_base;
1334
1335The value of the APIC BASE msr. Only valid if in-kernel local
1336APIC is not used. Both input and output.
1337
1338 union {
1339 /* KVM_EXIT_UNKNOWN */
1340 struct {
1341 __u64 hardware_exit_reason;
1342 } hw;
1343
1344If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1345reasons. Further architecture-specific information is available in
1346hardware_exit_reason.
1347
1348 /* KVM_EXIT_FAIL_ENTRY */
1349 struct {
1350 __u64 hardware_entry_failure_reason;
1351 } fail_entry;
1352
1353If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1354to unknown reasons. Further architecture-specific information is
1355available in hardware_entry_failure_reason.
1356
1357 /* KVM_EXIT_EXCEPTION */
1358 struct {
1359 __u32 exception;
1360 __u32 error_code;
1361 } ex;
1362
1363Unused.
1364
1365 /* KVM_EXIT_IO */
1366 struct {
1367#define KVM_EXIT_IO_IN 0
1368#define KVM_EXIT_IO_OUT 1
1369 __u8 direction;
1370 __u8 size; /* bytes */
1371 __u16 port;
1372 __u32 count;
1373 __u64 data_offset; /* relative to kvm_run start */
1374 } io;
1375
Wu Fengguang20448922009-12-24 09:04:16 +08001376If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001377executed a port I/O instruction which could not be satisfied by kvm.
1378data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1379where kvm expects application code to place the data for the next
Wu Fengguang20448922009-12-24 09:04:16 +08001380KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001381
1382 struct {
1383 struct kvm_debug_exit_arch arch;
1384 } debug;
1385
1386Unused.
1387
1388 /* KVM_EXIT_MMIO */
1389 struct {
1390 __u64 phys_addr;
1391 __u8 data[8];
1392 __u32 len;
1393 __u8 is_write;
1394 } mmio;
1395
Wu Fengguang20448922009-12-24 09:04:16 +08001396If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001397executed a memory-mapped I/O instruction which could not be satisfied
1398by kvm. The 'data' member contains the written data if 'is_write' is
1399true, and should be filled by application code otherwise.
1400
Alexander Grafad0a0482010-03-24 21:48:30 +01001401NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1402operations are complete (and guest state is consistent) only after userspace
1403has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02001404incomplete operations and then check for pending signals. Userspace
1405can re-enter the guest with an unmasked signal pending to complete
1406pending operations.
1407
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001408 /* KVM_EXIT_HYPERCALL */
1409 struct {
1410 __u64 nr;
1411 __u64 args[6];
1412 __u64 ret;
1413 __u32 longmode;
1414 __u32 pad;
1415 } hypercall;
1416
Avi Kivity647dc492010-04-01 14:39:21 +03001417Unused. This was once used for 'hypercall to userspace'. To implement
1418such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1419Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001420
1421 /* KVM_EXIT_TPR_ACCESS */
1422 struct {
1423 __u64 rip;
1424 __u32 is_write;
1425 __u32 pad;
1426 } tpr_access;
1427
1428To be documented (KVM_TPR_ACCESS_REPORTING).
1429
1430 /* KVM_EXIT_S390_SIEIC */
1431 struct {
1432 __u8 icptcode;
1433 __u64 mask; /* psw upper half */
1434 __u64 addr; /* psw lower half */
1435 __u16 ipa;
1436 __u32 ipb;
1437 } s390_sieic;
1438
1439s390 specific.
1440
1441 /* KVM_EXIT_S390_RESET */
1442#define KVM_S390_RESET_POR 1
1443#define KVM_S390_RESET_CLEAR 2
1444#define KVM_S390_RESET_SUBSYSTEM 4
1445#define KVM_S390_RESET_CPU_INIT 8
1446#define KVM_S390_RESET_IPL 16
1447 __u64 s390_reset_flags;
1448
1449s390 specific.
1450
1451 /* KVM_EXIT_DCR */
1452 struct {
1453 __u32 dcrn;
1454 __u32 data;
1455 __u8 is_write;
1456 } dcr;
1457
1458powerpc specific.
1459
Alexander Grafad0a0482010-03-24 21:48:30 +01001460 /* KVM_EXIT_OSI */
1461 struct {
1462 __u64 gprs[32];
1463 } osi;
1464
1465MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1466hypercalls and exit with this exit struct that contains all the guest gprs.
1467
1468If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1469Userspace can now handle the hypercall and when it's done modify the gprs as
1470necessary. Upon guest entry all guest GPRs will then be replaced by the values
1471in this struct.
1472
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001473 /* Fix the size of the union. */
1474 char padding[256];
1475 };
1476};