]> git.karo-electronics.de Git - karo-tx-linux.git/blob - Documentation/virtual/kvm/api.txt
75cd8fba0cdef32c9d2300d83b800c6e83cc34ec
[karo-tx-linux.git] / Documentation / virtual / kvm / api.txt
1 The Definitive KVM (Kernel-based Virtual Machine) API Documentation
2 ===================================================================
3
4 1. General description
5
6 The kvm API is a set of ioctls that are issued to control various aspects
7 of 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
26 2. File descriptors
27
28 The kvm API is centered around file descriptors.  An initial
29 open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
30 can be used to issue system ioctls.  A KVM_CREATE_VM ioctl on this
31 handle will create a VM file descriptor which can be used to issue VM
32 ioctls.  A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
33 and return a file descriptor pointing to it.  Finally, ioctls on a vcpu
34 fd can be used to control the vcpu, including the important task of
35 actually running guest code.
36
37 In general file descriptors can be migrated among processes by means
38 of fork() and the SCM_RIGHTS facility of unix domain socket.  These
39 kinds of tricks are explicitly not supported by kvm.  While they will
40 not cause harm to the host, their actual behavior is not guaranteed by
41 the API.  The only supported use is one virtual machine per process,
42 and one vcpu per thread.
43
44 3. Extensions
45
46 As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
47 incompatible change are allowed.  However, there is an extension
48 facility that allows backward-compatible extensions to the API to be
49 queried and used.
50
51 The extension mechanism is not based on on the Linux version number.
52 Instead, kvm defines extension identifiers and a facility to query
53 whether a particular extension identifier is available.  If it is, a
54 set of ioctls is available for application use.
55
56 4. API description
57
58 This section describes ioctls that can be used to control kvm guests.
59 For each ioctl, the following information is provided along with a
60 description:
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
78 4.1 KVM_GET_API_VERSION
79
80 Capability: basic
81 Architectures: all
82 Type: system ioctl
83 Parameters: none
84 Returns: the constant KVM_API_VERSION (=12)
85
86 This identifies the API version as the stable kvm API. It is not
87 expected that this number will change.  However, Linux 2.6.20 and
88 2.6.21 report earlier versions; these are not documented and not
89 supported.  Applications should refuse to run if KVM_GET_API_VERSION
90 returns a value other than 12.  If this check passes, all ioctls
91 described as 'basic' will be available.
92
93 4.2 KVM_CREATE_VM
94
95 Capability: basic
96 Architectures: all
97 Type: system ioctl
98 Parameters: none
99 Returns: a VM fd that can be used to control the new virtual machine.
100
101 The new VM has no virtual cpus and no memory.  An mmap() of a VM fd
102 will access the virtual machine's physical address space; offset zero
103 corresponds to guest physical address zero.  Use of mmap() on a VM fd
104 is discouraged if userspace memory allocation (KVM_CAP_USER_MEMORY) is
105 available.
106
107 4.3 KVM_GET_MSR_INDEX_LIST
108
109 Capability: basic
110 Architectures: x86
111 Type: system
112 Parameters: struct kvm_msr_list (in/out)
113 Returns: 0 on success; -1 on error
114 Errors:
115   E2BIG:     the msr index list is to be to fit in the array specified by
116              the user.
117
118 struct kvm_msr_list {
119         __u32 nmsrs; /* number of msrs in entries */
120         __u32 indices[0];
121 };
122
123 This ioctl returns the guest msrs that are supported.  The list varies
124 by kvm version and host processor, but does not change otherwise.  The
125 user fills in the size of the indices array in nmsrs, and in return
126 kvm adjusts nmsrs to reflect the actual number of msrs and fills in
127 the indices array with their numbers.
128
129 Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
130 not returned in the MSR list, as different vcpus can have a different number
131 of banks, as set via the KVM_X86_SETUP_MCE ioctl.
132
133 4.4 KVM_CHECK_EXTENSION
134
135 Capability: basic
136 Architectures: all
137 Type: system ioctl
138 Parameters: extension identifier (KVM_CAP_*)
139 Returns: 0 if unsupported; 1 (or some other positive integer) if supported
140
141 The API allows the application to query about extensions to the core
142 kvm API.  Userspace passes an extension identifier (an integer) and
143 receives an integer that describes the extension availability.
144 Generally 0 means no and 1 means yes, but some extensions may report
145 additional information in the integer return value.
146
147 4.5 KVM_GET_VCPU_MMAP_SIZE
148
149 Capability: basic
150 Architectures: all
151 Type: system ioctl
152 Parameters: none
153 Returns: size of vcpu mmap area, in bytes
154
155 The KVM_RUN ioctl (cf.) communicates with userspace via a shared
156 memory region.  This ioctl returns the size of that region.  See the
157 KVM_RUN documentation for details.
158
159 4.6 KVM_SET_MEMORY_REGION
160
161 Capability: basic
162 Architectures: all
163 Type: vm ioctl
164 Parameters: struct kvm_memory_region (in)
165 Returns: 0 on success, -1 on error
166
167 This ioctl is obsolete and has been removed.
168
169 4.7 KVM_CREATE_VCPU
170
171 Capability: basic
172 Architectures: all
173 Type: vm ioctl
174 Parameters: vcpu id (apic id on x86)
175 Returns: vcpu fd on success, -1 on error
176
177 This API adds a vcpu to a virtual machine.  The vcpu id is a small integer
178 in the range [0, max_vcpus).
179
180 The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
181 the KVM_CHECK_EXTENSION ioctl() at run-time.
182 The maximum possible value for max_vcpus can be retrieved using the
183 KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
184
185 If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
186 cpus max.
187 If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
188 same as the value returned from KVM_CAP_NR_VCPUS.
189
190 On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
191 threads in one or more virtual CPU cores.  (This is because the
192 hardware requires all the hardware threads in a CPU core to be in the
193 same partition.)  The KVM_CAP_PPC_SMT capability indicates the number
194 of vcpus per virtual core (vcore).  The vcore id is obtained by
195 dividing the vcpu id by the number of vcpus per vcore.  The vcpus in a
196 given vcore will always be in the same physical core as each other
197 (though that might be a different physical core from time to time).
198 Userspace can control the threading (SMT) mode of the guest by its
199 allocation of vcpu ids.  For example, if userspace wants
200 single-threaded guest vcpus, it should make all vcpu ids be a multiple
201 of the number of vcpus per vcore.
202
203 4.8 KVM_GET_DIRTY_LOG (vm ioctl)
204
205 Capability: basic
206 Architectures: x86
207 Type: vm ioctl
208 Parameters: struct kvm_dirty_log (in/out)
209 Returns: 0 on success, -1 on error
210
211 /* for KVM_GET_DIRTY_LOG */
212 struct kvm_dirty_log {
213         __u32 slot;
214         __u32 padding;
215         union {
216                 void __user *dirty_bitmap; /* one bit per page */
217                 __u64 padding;
218         };
219 };
220
221 Given a memory slot, return a bitmap containing any pages dirtied
222 since the last call to this ioctl.  Bit 0 is the first page in the
223 memory slot.  Ensure the entire structure is cleared to avoid padding
224 issues.
225
226 4.9 KVM_SET_MEMORY_ALIAS
227
228 Capability: basic
229 Architectures: x86
230 Type: vm ioctl
231 Parameters: struct kvm_memory_alias (in)
232 Returns: 0 (success), -1 (error)
233
234 This ioctl is obsolete and has been removed.
235
236 4.10 KVM_RUN
237
238 Capability: basic
239 Architectures: all
240 Type: vcpu ioctl
241 Parameters: none
242 Returns: 0 on success, -1 on error
243 Errors:
244   EINTR:     an unmasked signal is pending
245
246 This ioctl is used to run a guest virtual cpu.  While there are no
247 explicit parameters, there is an implicit parameter block that can be
248 obtained by mmap()ing the vcpu fd at offset 0, with the size given by
249 KVM_GET_VCPU_MMAP_SIZE.  The parameter block is formatted as a 'struct
250 kvm_run' (see below).
251
252 4.11 KVM_GET_REGS
253
254 Capability: basic
255 Architectures: all
256 Type: vcpu ioctl
257 Parameters: struct kvm_regs (out)
258 Returns: 0 on success, -1 on error
259
260 Reads the general purpose registers from the vcpu.
261
262 /* x86 */
263 struct kvm_regs {
264         /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
265         __u64 rax, rbx, rcx, rdx;
266         __u64 rsi, rdi, rsp, rbp;
267         __u64 r8,  r9,  r10, r11;
268         __u64 r12, r13, r14, r15;
269         __u64 rip, rflags;
270 };
271
272 4.12 KVM_SET_REGS
273
274 Capability: basic
275 Architectures: all
276 Type: vcpu ioctl
277 Parameters: struct kvm_regs (in)
278 Returns: 0 on success, -1 on error
279
280 Writes the general purpose registers into the vcpu.
281
282 See KVM_GET_REGS for the data structure.
283
284 4.13 KVM_GET_SREGS
285
286 Capability: basic
287 Architectures: x86, ppc
288 Type: vcpu ioctl
289 Parameters: struct kvm_sregs (out)
290 Returns: 0 on success, -1 on error
291
292 Reads special registers from the vcpu.
293
294 /* x86 */
295 struct kvm_sregs {
296         struct kvm_segment cs, ds, es, fs, gs, ss;
297         struct kvm_segment tr, ldt;
298         struct kvm_dtable gdt, idt;
299         __u64 cr0, cr2, cr3, cr4, cr8;
300         __u64 efer;
301         __u64 apic_base;
302         __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
303 };
304
305 /* ppc -- see arch/powerpc/include/asm/kvm.h */
306
307 interrupt_bitmap is a bitmap of pending external interrupts.  At most
308 one bit may be set.  This interrupt has been acknowledged by the APIC
309 but not yet injected into the cpu core.
310
311 4.14 KVM_SET_SREGS
312
313 Capability: basic
314 Architectures: x86, ppc
315 Type: vcpu ioctl
316 Parameters: struct kvm_sregs (in)
317 Returns: 0 on success, -1 on error
318
319 Writes special registers into the vcpu.  See KVM_GET_SREGS for the
320 data structures.
321
322 4.15 KVM_TRANSLATE
323
324 Capability: basic
325 Architectures: x86
326 Type: vcpu ioctl
327 Parameters: struct kvm_translation (in/out)
328 Returns: 0 on success, -1 on error
329
330 Translates a virtual address according to the vcpu's current address
331 translation mode.
332
333 struct kvm_translation {
334         /* in */
335         __u64 linear_address;
336
337         /* out */
338         __u64 physical_address;
339         __u8  valid;
340         __u8  writeable;
341         __u8  usermode;
342         __u8  pad[5];
343 };
344
345 4.16 KVM_INTERRUPT
346
347 Capability: basic
348 Architectures: x86, ppc
349 Type: vcpu ioctl
350 Parameters: struct kvm_interrupt (in)
351 Returns: 0 on success, -1 on error
352
353 Queues a hardware interrupt vector to be injected.  This is only
354 useful if in-kernel local APIC or equivalent is not used.
355
356 /* for KVM_INTERRUPT */
357 struct kvm_interrupt {
358         /* in */
359         __u32 irq;
360 };
361
362 X86:
363
364 Note 'irq' is an interrupt vector, not an interrupt pin or line.
365
366 PPC:
367
368 Queues an external interrupt to be injected. This ioctl is overleaded
369 with 3 different irq values:
370
371 a) KVM_INTERRUPT_SET
372
373   This injects an edge type external interrupt into the guest once it's ready
374   to receive interrupts. When injected, the interrupt is done.
375
376 b) KVM_INTERRUPT_UNSET
377
378   This unsets any pending interrupt.
379
380   Only available with KVM_CAP_PPC_UNSET_IRQ.
381
382 c) KVM_INTERRUPT_SET_LEVEL
383
384   This injects a level type external interrupt into the guest context. The
385   interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
386   is triggered.
387
388   Only available with KVM_CAP_PPC_IRQ_LEVEL.
389
390 Note that any value for 'irq' other than the ones stated above is invalid
391 and incurs unexpected behavior.
392
393 4.17 KVM_DEBUG_GUEST
394
395 Capability: basic
396 Architectures: none
397 Type: vcpu ioctl
398 Parameters: none)
399 Returns: -1 on error
400
401 Support for this has been removed.  Use KVM_SET_GUEST_DEBUG instead.
402
403 4.18 KVM_GET_MSRS
404
405 Capability: basic
406 Architectures: x86
407 Type: vcpu ioctl
408 Parameters: struct kvm_msrs (in/out)
409 Returns: 0 on success, -1 on error
410
411 Reads model-specific registers from the vcpu.  Supported msr indices can
412 be obtained using KVM_GET_MSR_INDEX_LIST.
413
414 struct kvm_msrs {
415         __u32 nmsrs; /* number of msrs in entries */
416         __u32 pad;
417
418         struct kvm_msr_entry entries[0];
419 };
420
421 struct kvm_msr_entry {
422         __u32 index;
423         __u32 reserved;
424         __u64 data;
425 };
426
427 Application code should set the 'nmsrs' member (which indicates the
428 size of the entries array) and the 'index' member of each array entry.
429 kvm will fill in the 'data' member.
430
431 4.19 KVM_SET_MSRS
432
433 Capability: basic
434 Architectures: x86
435 Type: vcpu ioctl
436 Parameters: struct kvm_msrs (in)
437 Returns: 0 on success, -1 on error
438
439 Writes model-specific registers to the vcpu.  See KVM_GET_MSRS for the
440 data structures.
441
442 Application code should set the 'nmsrs' member (which indicates the
443 size of the entries array), and the 'index' and 'data' members of each
444 array entry.
445
446 4.20 KVM_SET_CPUID
447
448 Capability: basic
449 Architectures: x86
450 Type: vcpu ioctl
451 Parameters: struct kvm_cpuid (in)
452 Returns: 0 on success, -1 on error
453
454 Defines the vcpu responses to the cpuid instruction.  Applications
455 should use the KVM_SET_CPUID2 ioctl if available.
456
457
458 struct kvm_cpuid_entry {
459         __u32 function;
460         __u32 eax;
461         __u32 ebx;
462         __u32 ecx;
463         __u32 edx;
464         __u32 padding;
465 };
466
467 /* for KVM_SET_CPUID */
468 struct kvm_cpuid {
469         __u32 nent;
470         __u32 padding;
471         struct kvm_cpuid_entry entries[0];
472 };
473
474 4.21 KVM_SET_SIGNAL_MASK
475
476 Capability: basic
477 Architectures: x86
478 Type: vcpu ioctl
479 Parameters: struct kvm_signal_mask (in)
480 Returns: 0 on success, -1 on error
481
482 Defines which signals are blocked during execution of KVM_RUN.  This
483 signal mask temporarily overrides the threads signal mask.  Any
484 unblocked signal received (except SIGKILL and SIGSTOP, which retain
485 their traditional behaviour) will cause KVM_RUN to return with -EINTR.
486
487 Note the signal will only be delivered if not blocked by the original
488 signal mask.
489
490 /* for KVM_SET_SIGNAL_MASK */
491 struct kvm_signal_mask {
492         __u32 len;
493         __u8  sigset[0];
494 };
495
496 4.22 KVM_GET_FPU
497
498 Capability: basic
499 Architectures: x86
500 Type: vcpu ioctl
501 Parameters: struct kvm_fpu (out)
502 Returns: 0 on success, -1 on error
503
504 Reads the floating point state from the vcpu.
505
506 /* for KVM_GET_FPU and KVM_SET_FPU */
507 struct kvm_fpu {
508         __u8  fpr[8][16];
509         __u16 fcw;
510         __u16 fsw;
511         __u8  ftwx;  /* in fxsave format */
512         __u8  pad1;
513         __u16 last_opcode;
514         __u64 last_ip;
515         __u64 last_dp;
516         __u8  xmm[16][16];
517         __u32 mxcsr;
518         __u32 pad2;
519 };
520
521 4.23 KVM_SET_FPU
522
523 Capability: basic
524 Architectures: x86
525 Type: vcpu ioctl
526 Parameters: struct kvm_fpu (in)
527 Returns: 0 on success, -1 on error
528
529 Writes the floating point state to the vcpu.
530
531 /* for KVM_GET_FPU and KVM_SET_FPU */
532 struct kvm_fpu {
533         __u8  fpr[8][16];
534         __u16 fcw;
535         __u16 fsw;
536         __u8  ftwx;  /* in fxsave format */
537         __u8  pad1;
538         __u16 last_opcode;
539         __u64 last_ip;
540         __u64 last_dp;
541         __u8  xmm[16][16];
542         __u32 mxcsr;
543         __u32 pad2;
544 };
545
546 4.24 KVM_CREATE_IRQCHIP
547
548 Capability: KVM_CAP_IRQCHIP
549 Architectures: x86, ia64
550 Type: vm ioctl
551 Parameters: none
552 Returns: 0 on success, -1 on error
553
554 Creates an interrupt controller model in the kernel.  On x86, creates a virtual
555 ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
556 local APIC.  IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
557 only go to the IOAPIC.  On ia64, a IOSAPIC is created.
558
559 4.25 KVM_IRQ_LINE
560
561 Capability: KVM_CAP_IRQCHIP
562 Architectures: x86, ia64
563 Type: vm ioctl
564 Parameters: struct kvm_irq_level
565 Returns: 0 on success, -1 on error
566
567 Sets the level of a GSI input to the interrupt controller model in the kernel.
568 Requires that an interrupt controller model has been previously created with
569 KVM_CREATE_IRQCHIP.  Note that edge-triggered interrupts require the level
570 to be set to 1 and then back to 0.
571
572 struct kvm_irq_level {
573         union {
574                 __u32 irq;     /* GSI */
575                 __s32 status;  /* not used for KVM_IRQ_LEVEL */
576         };
577         __u32 level;           /* 0 or 1 */
578 };
579
580 4.26 KVM_GET_IRQCHIP
581
582 Capability: KVM_CAP_IRQCHIP
583 Architectures: x86, ia64
584 Type: vm ioctl
585 Parameters: struct kvm_irqchip (in/out)
586 Returns: 0 on success, -1 on error
587
588 Reads the state of a kernel interrupt controller created with
589 KVM_CREATE_IRQCHIP into a buffer provided by the caller.
590
591 struct kvm_irqchip {
592         __u32 chip_id;  /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
593         __u32 pad;
594         union {
595                 char dummy[512];  /* reserving space */
596                 struct kvm_pic_state pic;
597                 struct kvm_ioapic_state ioapic;
598         } chip;
599 };
600
601 4.27 KVM_SET_IRQCHIP
602
603 Capability: KVM_CAP_IRQCHIP
604 Architectures: x86, ia64
605 Type: vm ioctl
606 Parameters: struct kvm_irqchip (in)
607 Returns: 0 on success, -1 on error
608
609 Sets the state of a kernel interrupt controller created with
610 KVM_CREATE_IRQCHIP from a buffer provided by the caller.
611
612 struct kvm_irqchip {
613         __u32 chip_id;  /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
614         __u32 pad;
615         union {
616                 char dummy[512];  /* reserving space */
617                 struct kvm_pic_state pic;
618                 struct kvm_ioapic_state ioapic;
619         } chip;
620 };
621
622 4.28 KVM_XEN_HVM_CONFIG
623
624 Capability: KVM_CAP_XEN_HVM
625 Architectures: x86
626 Type: vm ioctl
627 Parameters: struct kvm_xen_hvm_config (in)
628 Returns: 0 on success, -1 on error
629
630 Sets the MSR that the Xen HVM guest uses to initialize its hypercall
631 page, and provides the starting address and size of the hypercall
632 blobs in userspace.  When the guest writes the MSR, kvm copies one
633 page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
634 memory.
635
636 struct kvm_xen_hvm_config {
637         __u32 flags;
638         __u32 msr;
639         __u64 blob_addr_32;
640         __u64 blob_addr_64;
641         __u8 blob_size_32;
642         __u8 blob_size_64;
643         __u8 pad2[30];
644 };
645
646 4.29 KVM_GET_CLOCK
647
648 Capability: KVM_CAP_ADJUST_CLOCK
649 Architectures: x86
650 Type: vm ioctl
651 Parameters: struct kvm_clock_data (out)
652 Returns: 0 on success, -1 on error
653
654 Gets the current timestamp of kvmclock as seen by the current guest. In
655 conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
656 such as migration.
657
658 struct kvm_clock_data {
659         __u64 clock;  /* kvmclock current value */
660         __u32 flags;
661         __u32 pad[9];
662 };
663
664 4.30 KVM_SET_CLOCK
665
666 Capability: KVM_CAP_ADJUST_CLOCK
667 Architectures: x86
668 Type: vm ioctl
669 Parameters: struct kvm_clock_data (in)
670 Returns: 0 on success, -1 on error
671
672 Sets the current timestamp of kvmclock to the value specified in its parameter.
673 In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
674 such as migration.
675
676 struct kvm_clock_data {
677         __u64 clock;  /* kvmclock current value */
678         __u32 flags;
679         __u32 pad[9];
680 };
681
682 4.31 KVM_GET_VCPU_EVENTS
683
684 Capability: KVM_CAP_VCPU_EVENTS
685 Extended by: KVM_CAP_INTR_SHADOW
686 Architectures: x86
687 Type: vm ioctl
688 Parameters: struct kvm_vcpu_event (out)
689 Returns: 0 on success, -1 on error
690
691 Gets currently pending exceptions, interrupts, and NMIs as well as related
692 states of the vcpu.
693
694 struct kvm_vcpu_events {
695         struct {
696                 __u8 injected;
697                 __u8 nr;
698                 __u8 has_error_code;
699                 __u8 pad;
700                 __u32 error_code;
701         } exception;
702         struct {
703                 __u8 injected;
704                 __u8 nr;
705                 __u8 soft;
706                 __u8 shadow;
707         } interrupt;
708         struct {
709                 __u8 injected;
710                 __u8 pending;
711                 __u8 masked;
712                 __u8 pad;
713         } nmi;
714         __u32 sipi_vector;
715         __u32 flags;
716 };
717
718 KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
719 interrupt.shadow contains a valid state. Otherwise, this field is undefined.
720
721 4.32 KVM_SET_VCPU_EVENTS
722
723 Capability: KVM_CAP_VCPU_EVENTS
724 Extended by: KVM_CAP_INTR_SHADOW
725 Architectures: x86
726 Type: vm ioctl
727 Parameters: struct kvm_vcpu_event (in)
728 Returns: 0 on success, -1 on error
729
730 Set pending exceptions, interrupts, and NMIs as well as related states of the
731 vcpu.
732
733 See KVM_GET_VCPU_EVENTS for the data structure.
734
735 Fields that may be modified asynchronously by running VCPUs can be excluded
736 from the update. These fields are nmi.pending and sipi_vector. Keep the
737 corresponding bits in the flags field cleared to suppress overwriting the
738 current in-kernel state. The bits are:
739
740 KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
741 KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
742
743 If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
744 the flags field to signal that interrupt.shadow contains a valid state and
745 shall be written into the VCPU.
746
747 4.33 KVM_GET_DEBUGREGS
748
749 Capability: KVM_CAP_DEBUGREGS
750 Architectures: x86
751 Type: vm ioctl
752 Parameters: struct kvm_debugregs (out)
753 Returns: 0 on success, -1 on error
754
755 Reads debug registers from the vcpu.
756
757 struct kvm_debugregs {
758         __u64 db[4];
759         __u64 dr6;
760         __u64 dr7;
761         __u64 flags;
762         __u64 reserved[9];
763 };
764
765 4.34 KVM_SET_DEBUGREGS
766
767 Capability: KVM_CAP_DEBUGREGS
768 Architectures: x86
769 Type: vm ioctl
770 Parameters: struct kvm_debugregs (in)
771 Returns: 0 on success, -1 on error
772
773 Writes debug registers into the vcpu.
774
775 See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
776 yet and must be cleared on entry.
777
778 4.35 KVM_SET_USER_MEMORY_REGION
779
780 Capability: KVM_CAP_USER_MEM
781 Architectures: all
782 Type: vm ioctl
783 Parameters: struct kvm_userspace_memory_region (in)
784 Returns: 0 on success, -1 on error
785
786 struct kvm_userspace_memory_region {
787         __u32 slot;
788         __u32 flags;
789         __u64 guest_phys_addr;
790         __u64 memory_size; /* bytes */
791         __u64 userspace_addr; /* start of the userspace allocated memory */
792 };
793
794 /* for kvm_memory_region::flags */
795 #define KVM_MEM_LOG_DIRTY_PAGES  1UL
796
797 This ioctl allows the user to create or modify a guest physical memory
798 slot.  When changing an existing slot, it may be moved in the guest
799 physical memory space, or its flags may be modified.  It may not be
800 resized.  Slots may not overlap in guest physical address space.
801
802 Memory for the region is taken starting at the address denoted by the
803 field userspace_addr, which must point at user addressable memory for
804 the entire memory slot size.  Any object may back this memory, including
805 anonymous memory, ordinary files, and hugetlbfs.
806
807 It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
808 be identical.  This allows large pages in the guest to be backed by large
809 pages in the host.
810
811 The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
812 instructs kvm to keep track of writes to memory within the slot.  See
813 the KVM_GET_DIRTY_LOG ioctl.
814
815 When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
816 region are automatically reflected into the guest.  For example, an mmap()
817 that affects the region will be made visible immediately.  Another example
818 is madvise(MADV_DROP).
819
820 It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
821 The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
822 allocation and is deprecated.
823
824 4.36 KVM_SET_TSS_ADDR
825
826 Capability: KVM_CAP_SET_TSS_ADDR
827 Architectures: x86
828 Type: vm ioctl
829 Parameters: unsigned long tss_address (in)
830 Returns: 0 on success, -1 on error
831
832 This ioctl defines the physical address of a three-page region in the guest
833 physical address space.  The region must be within the first 4GB of the
834 guest physical address space and must not conflict with any memory slot
835 or any mmio address.  The guest may malfunction if it accesses this memory
836 region.
837
838 This ioctl is required on Intel-based hosts.  This is needed on Intel hardware
839 because of a quirk in the virtualization implementation (see the internals
840 documentation when it pops into existence).
841
842 4.37 KVM_ENABLE_CAP
843
844 Capability: KVM_CAP_ENABLE_CAP
845 Architectures: ppc
846 Type: vcpu ioctl
847 Parameters: struct kvm_enable_cap (in)
848 Returns: 0 on success; -1 on error
849
850 +Not all extensions are enabled by default. Using this ioctl the application
851 can enable an extension, making it available to the guest.
852
853 On systems that do not support this ioctl, it always fails. On systems that
854 do support it, it only works for extensions that are supported for enablement.
855
856 To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
857 be used.
858
859 struct kvm_enable_cap {
860        /* in */
861        __u32 cap;
862
863 The capability that is supposed to get enabled.
864
865        __u32 flags;
866
867 A bitfield indicating future enhancements. Has to be 0 for now.
868
869        __u64 args[4];
870
871 Arguments for enabling a feature. If a feature needs initial values to
872 function properly, this is the place to put them.
873
874        __u8  pad[64];
875 };
876
877 4.38 KVM_GET_MP_STATE
878
879 Capability: KVM_CAP_MP_STATE
880 Architectures: x86, ia64
881 Type: vcpu ioctl
882 Parameters: struct kvm_mp_state (out)
883 Returns: 0 on success; -1 on error
884
885 struct kvm_mp_state {
886         __u32 mp_state;
887 };
888
889 Returns the vcpu's current "multiprocessing state" (though also valid on
890 uniprocessor guests).
891
892 Possible values are:
893
894  - KVM_MP_STATE_RUNNABLE:        the vcpu is currently running
895  - KVM_MP_STATE_UNINITIALIZED:   the vcpu is an application processor (AP)
896                                  which has not yet received an INIT signal
897  - KVM_MP_STATE_INIT_RECEIVED:   the vcpu has received an INIT signal, and is
898                                  now ready for a SIPI
899  - KVM_MP_STATE_HALTED:          the vcpu has executed a HLT instruction and
900                                  is waiting for an interrupt
901  - KVM_MP_STATE_SIPI_RECEIVED:   the vcpu has just received a SIPI (vector
902                                  accessible via KVM_GET_VCPU_EVENTS)
903
904 This ioctl is only useful after KVM_CREATE_IRQCHIP.  Without an in-kernel
905 irqchip, the multiprocessing state must be maintained by userspace.
906
907 4.39 KVM_SET_MP_STATE
908
909 Capability: KVM_CAP_MP_STATE
910 Architectures: x86, ia64
911 Type: vcpu ioctl
912 Parameters: struct kvm_mp_state (in)
913 Returns: 0 on success; -1 on error
914
915 Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
916 arguments.
917
918 This ioctl is only useful after KVM_CREATE_IRQCHIP.  Without an in-kernel
919 irqchip, the multiprocessing state must be maintained by userspace.
920
921 4.40 KVM_SET_IDENTITY_MAP_ADDR
922
923 Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
924 Architectures: x86
925 Type: vm ioctl
926 Parameters: unsigned long identity (in)
927 Returns: 0 on success, -1 on error
928
929 This ioctl defines the physical address of a one-page region in the guest
930 physical address space.  The region must be within the first 4GB of the
931 guest physical address space and must not conflict with any memory slot
932 or any mmio address.  The guest may malfunction if it accesses this memory
933 region.
934
935 This ioctl is required on Intel-based hosts.  This is needed on Intel hardware
936 because of a quirk in the virtualization implementation (see the internals
937 documentation when it pops into existence).
938
939 4.41 KVM_SET_BOOT_CPU_ID
940
941 Capability: KVM_CAP_SET_BOOT_CPU_ID
942 Architectures: x86, ia64
943 Type: vm ioctl
944 Parameters: unsigned long vcpu_id
945 Returns: 0 on success, -1 on error
946
947 Define which vcpu is the Bootstrap Processor (BSP).  Values are the same
948 as the vcpu id in KVM_CREATE_VCPU.  If this ioctl is not called, the default
949 is vcpu 0.
950
951 4.42 KVM_GET_XSAVE
952
953 Capability: KVM_CAP_XSAVE
954 Architectures: x86
955 Type: vcpu ioctl
956 Parameters: struct kvm_xsave (out)
957 Returns: 0 on success, -1 on error
958
959 struct kvm_xsave {
960         __u32 region[1024];
961 };
962
963 This ioctl would copy current vcpu's xsave struct to the userspace.
964
965 4.43 KVM_SET_XSAVE
966
967 Capability: KVM_CAP_XSAVE
968 Architectures: x86
969 Type: vcpu ioctl
970 Parameters: struct kvm_xsave (in)
971 Returns: 0 on success, -1 on error
972
973 struct kvm_xsave {
974         __u32 region[1024];
975 };
976
977 This ioctl would copy userspace's xsave struct to the kernel.
978
979 4.44 KVM_GET_XCRS
980
981 Capability: KVM_CAP_XCRS
982 Architectures: x86
983 Type: vcpu ioctl
984 Parameters: struct kvm_xcrs (out)
985 Returns: 0 on success, -1 on error
986
987 struct kvm_xcr {
988         __u32 xcr;
989         __u32 reserved;
990         __u64 value;
991 };
992
993 struct kvm_xcrs {
994         __u32 nr_xcrs;
995         __u32 flags;
996         struct kvm_xcr xcrs[KVM_MAX_XCRS];
997         __u64 padding[16];
998 };
999
1000 This ioctl would copy current vcpu's xcrs to the userspace.
1001
1002 4.45 KVM_SET_XCRS
1003
1004 Capability: KVM_CAP_XCRS
1005 Architectures: x86
1006 Type: vcpu ioctl
1007 Parameters: struct kvm_xcrs (in)
1008 Returns: 0 on success, -1 on error
1009
1010 struct kvm_xcr {
1011         __u32 xcr;
1012         __u32 reserved;
1013         __u64 value;
1014 };
1015
1016 struct kvm_xcrs {
1017         __u32 nr_xcrs;
1018         __u32 flags;
1019         struct kvm_xcr xcrs[KVM_MAX_XCRS];
1020         __u64 padding[16];
1021 };
1022
1023 This ioctl would set vcpu's xcr to the value userspace specified.
1024
1025 4.46 KVM_GET_SUPPORTED_CPUID
1026
1027 Capability: KVM_CAP_EXT_CPUID
1028 Architectures: x86
1029 Type: system ioctl
1030 Parameters: struct kvm_cpuid2 (in/out)
1031 Returns: 0 on success, -1 on error
1032
1033 struct kvm_cpuid2 {
1034         __u32 nent;
1035         __u32 padding;
1036         struct kvm_cpuid_entry2 entries[0];
1037 };
1038
1039 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
1040 #define KVM_CPUID_FLAG_STATEFUL_FUNC    2
1041 #define KVM_CPUID_FLAG_STATE_READ_NEXT  4
1042
1043 struct kvm_cpuid_entry2 {
1044         __u32 function;
1045         __u32 index;
1046         __u32 flags;
1047         __u32 eax;
1048         __u32 ebx;
1049         __u32 ecx;
1050         __u32 edx;
1051         __u32 padding[3];
1052 };
1053
1054 This ioctl returns x86 cpuid features which are supported by both the hardware
1055 and kvm.  Userspace can use the information returned by this ioctl to
1056 construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1057 hardware, kernel, and userspace capabilities, and with user requirements (for
1058 example, the user may wish to constrain cpuid to emulate older hardware,
1059 or for feature consistency across a cluster).
1060
1061 Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1062 with the 'nent' field indicating the number of entries in the variable-size
1063 array 'entries'.  If the number of entries is too low to describe the cpu
1064 capabilities, an error (E2BIG) is returned.  If the number is too high,
1065 the 'nent' field is adjusted and an error (ENOMEM) is returned.  If the
1066 number is just right, the 'nent' field is adjusted to the number of valid
1067 entries in the 'entries' array, which is then filled.
1068
1069 The entries returned are the host cpuid as returned by the cpuid instruction,
1070 with unknown or unsupported features masked out.  Some features (for example,
1071 x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1072 emulate them efficiently. The fields in each entry are defined as follows:
1073
1074   function: the eax value used to obtain the entry
1075   index: the ecx value used to obtain the entry (for entries that are
1076          affected by ecx)
1077   flags: an OR of zero or more of the following:
1078         KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1079            if the index field is valid
1080         KVM_CPUID_FLAG_STATEFUL_FUNC:
1081            if cpuid for this function returns different values for successive
1082            invocations; there will be several entries with the same function,
1083            all with this flag set
1084         KVM_CPUID_FLAG_STATE_READ_NEXT:
1085            for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1086            the first entry to be read by a cpu
1087    eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1088          this function/index combination
1089
1090 4.47 KVM_PPC_GET_PVINFO
1091
1092 Capability: KVM_CAP_PPC_GET_PVINFO
1093 Architectures: ppc
1094 Type: vm ioctl
1095 Parameters: struct kvm_ppc_pvinfo (out)
1096 Returns: 0 on success, !0 on error
1097
1098 struct kvm_ppc_pvinfo {
1099         __u32 flags;
1100         __u32 hcall[4];
1101         __u8  pad[108];
1102 };
1103
1104 This ioctl fetches PV specific information that need to be passed to the guest
1105 using the device tree or other means from vm context.
1106
1107 For now the only implemented piece of information distributed here is an array
1108 of 4 instructions that make up a hypercall.
1109
1110 If any additional field gets added to this structure later on, a bit for that
1111 additional piece of information will be set in the flags bitmap.
1112
1113 4.48 KVM_ASSIGN_PCI_DEVICE
1114
1115 Capability: KVM_CAP_DEVICE_ASSIGNMENT
1116 Architectures: x86 ia64
1117 Type: vm ioctl
1118 Parameters: struct kvm_assigned_pci_dev (in)
1119 Returns: 0 on success, -1 on error
1120
1121 Assigns a host PCI device to the VM.
1122
1123 struct kvm_assigned_pci_dev {
1124         __u32 assigned_dev_id;
1125         __u32 busnr;
1126         __u32 devfn;
1127         __u32 flags;
1128         __u32 segnr;
1129         union {
1130                 __u32 reserved[11];
1131         };
1132 };
1133
1134 The PCI device is specified by the triple segnr, busnr, and devfn.
1135 Identification in succeeding service requests is done via assigned_dev_id. The
1136 following flags are specified:
1137
1138 /* Depends on KVM_CAP_IOMMU */
1139 #define KVM_DEV_ASSIGN_ENABLE_IOMMU     (1 << 0)
1140
1141 4.49 KVM_DEASSIGN_PCI_DEVICE
1142
1143 Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1144 Architectures: x86 ia64
1145 Type: vm ioctl
1146 Parameters: struct kvm_assigned_pci_dev (in)
1147 Returns: 0 on success, -1 on error
1148
1149 Ends PCI device assignment, releasing all associated resources.
1150
1151 See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1152 used in kvm_assigned_pci_dev to identify the device.
1153
1154 4.50 KVM_ASSIGN_DEV_IRQ
1155
1156 Capability: KVM_CAP_ASSIGN_DEV_IRQ
1157 Architectures: x86 ia64
1158 Type: vm ioctl
1159 Parameters: struct kvm_assigned_irq (in)
1160 Returns: 0 on success, -1 on error
1161
1162 Assigns an IRQ to a passed-through device.
1163
1164 struct kvm_assigned_irq {
1165         __u32 assigned_dev_id;
1166         __u32 host_irq; /* ignored (legacy field) */
1167         __u32 guest_irq;
1168         __u32 flags;
1169         union {
1170                 __u32 reserved[12];
1171         };
1172 };
1173
1174 The following flags are defined:
1175
1176 #define KVM_DEV_IRQ_HOST_INTX    (1 << 0)
1177 #define KVM_DEV_IRQ_HOST_MSI     (1 << 1)
1178 #define KVM_DEV_IRQ_HOST_MSIX    (1 << 2)
1179
1180 #define KVM_DEV_IRQ_GUEST_INTX   (1 << 8)
1181 #define KVM_DEV_IRQ_GUEST_MSI    (1 << 9)
1182 #define KVM_DEV_IRQ_GUEST_MSIX   (1 << 10)
1183
1184 It is not valid to specify multiple types per host or guest IRQ. However, the
1185 IRQ type of host and guest can differ or can even be null.
1186
1187 4.51 KVM_DEASSIGN_DEV_IRQ
1188
1189 Capability: KVM_CAP_ASSIGN_DEV_IRQ
1190 Architectures: x86 ia64
1191 Type: vm ioctl
1192 Parameters: struct kvm_assigned_irq (in)
1193 Returns: 0 on success, -1 on error
1194
1195 Ends an IRQ assignment to a passed-through device.
1196
1197 See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1198 by assigned_dev_id, flags must correspond to the IRQ type specified on
1199 KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1200
1201 4.52 KVM_SET_GSI_ROUTING
1202
1203 Capability: KVM_CAP_IRQ_ROUTING
1204 Architectures: x86 ia64
1205 Type: vm ioctl
1206 Parameters: struct kvm_irq_routing (in)
1207 Returns: 0 on success, -1 on error
1208
1209 Sets the GSI routing table entries, overwriting any previously set entries.
1210
1211 struct kvm_irq_routing {
1212         __u32 nr;
1213         __u32 flags;
1214         struct kvm_irq_routing_entry entries[0];
1215 };
1216
1217 No flags are specified so far, the corresponding field must be set to zero.
1218
1219 struct kvm_irq_routing_entry {
1220         __u32 gsi;
1221         __u32 type;
1222         __u32 flags;
1223         __u32 pad;
1224         union {
1225                 struct kvm_irq_routing_irqchip irqchip;
1226                 struct kvm_irq_routing_msi msi;
1227                 __u32 pad[8];
1228         } u;
1229 };
1230
1231 /* gsi routing entry types */
1232 #define KVM_IRQ_ROUTING_IRQCHIP 1
1233 #define KVM_IRQ_ROUTING_MSI 2
1234
1235 No flags are specified so far, the corresponding field must be set to zero.
1236
1237 struct kvm_irq_routing_irqchip {
1238         __u32 irqchip;
1239         __u32 pin;
1240 };
1241
1242 struct kvm_irq_routing_msi {
1243         __u32 address_lo;
1244         __u32 address_hi;
1245         __u32 data;
1246         __u32 pad;
1247 };
1248
1249 4.53 KVM_ASSIGN_SET_MSIX_NR
1250
1251 Capability: KVM_CAP_DEVICE_MSIX
1252 Architectures: x86 ia64
1253 Type: vm ioctl
1254 Parameters: struct kvm_assigned_msix_nr (in)
1255 Returns: 0 on success, -1 on error
1256
1257 Set the number of MSI-X interrupts for an assigned device. The number is
1258 reset again by terminating the MSI-X assignment of the device via
1259 KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
1260 point will fail.
1261
1262 struct kvm_assigned_msix_nr {
1263         __u32 assigned_dev_id;
1264         __u16 entry_nr;
1265         __u16 padding;
1266 };
1267
1268 #define KVM_MAX_MSIX_PER_DEV            256
1269
1270 4.54 KVM_ASSIGN_SET_MSIX_ENTRY
1271
1272 Capability: KVM_CAP_DEVICE_MSIX
1273 Architectures: x86 ia64
1274 Type: vm ioctl
1275 Parameters: struct kvm_assigned_msix_entry (in)
1276 Returns: 0 on success, -1 on error
1277
1278 Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1279 the GSI vector to zero means disabling the interrupt.
1280
1281 struct kvm_assigned_msix_entry {
1282         __u32 assigned_dev_id;
1283         __u32 gsi;
1284         __u16 entry; /* The index of entry in the MSI-X table */
1285         __u16 padding[3];
1286 };
1287
1288 4.54 KVM_SET_TSC_KHZ
1289
1290 Capability: KVM_CAP_TSC_CONTROL
1291 Architectures: x86
1292 Type: vcpu ioctl
1293 Parameters: virtual tsc_khz
1294 Returns: 0 on success, -1 on error
1295
1296 Specifies the tsc frequency for the virtual machine. The unit of the
1297 frequency is KHz.
1298
1299 4.55 KVM_GET_TSC_KHZ
1300
1301 Capability: KVM_CAP_GET_TSC_KHZ
1302 Architectures: x86
1303 Type: vcpu ioctl
1304 Parameters: none
1305 Returns: virtual tsc-khz on success, negative value on error
1306
1307 Returns the tsc frequency of the guest. The unit of the return value is
1308 KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1309 error.
1310
1311 4.56 KVM_GET_LAPIC
1312
1313 Capability: KVM_CAP_IRQCHIP
1314 Architectures: x86
1315 Type: vcpu ioctl
1316 Parameters: struct kvm_lapic_state (out)
1317 Returns: 0 on success, -1 on error
1318
1319 #define KVM_APIC_REG_SIZE 0x400
1320 struct kvm_lapic_state {
1321         char regs[KVM_APIC_REG_SIZE];
1322 };
1323
1324 Reads the Local APIC registers and copies them into the input argument.  The
1325 data format and layout are the same as documented in the architecture manual.
1326
1327 4.57 KVM_SET_LAPIC
1328
1329 Capability: KVM_CAP_IRQCHIP
1330 Architectures: x86
1331 Type: vcpu ioctl
1332 Parameters: struct kvm_lapic_state (in)
1333 Returns: 0 on success, -1 on error
1334
1335 #define KVM_APIC_REG_SIZE 0x400
1336 struct kvm_lapic_state {
1337         char regs[KVM_APIC_REG_SIZE];
1338 };
1339
1340 Copies the input argument into the the Local APIC registers.  The data format
1341 and layout are the same as documented in the architecture manual.
1342
1343 4.58 KVM_IOEVENTFD
1344
1345 Capability: KVM_CAP_IOEVENTFD
1346 Architectures: all
1347 Type: vm ioctl
1348 Parameters: struct kvm_ioeventfd (in)
1349 Returns: 0 on success, !0 on error
1350
1351 This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1352 within the guest.  A guest write in the registered address will signal the
1353 provided event instead of triggering an exit.
1354
1355 struct kvm_ioeventfd {
1356         __u64 datamatch;
1357         __u64 addr;        /* legal pio/mmio address */
1358         __u32 len;         /* 1, 2, 4, or 8 bytes    */
1359         __s32 fd;
1360         __u32 flags;
1361         __u8  pad[36];
1362 };
1363
1364 The following flags are defined:
1365
1366 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1367 #define KVM_IOEVENTFD_FLAG_PIO       (1 << kvm_ioeventfd_flag_nr_pio)
1368 #define KVM_IOEVENTFD_FLAG_DEASSIGN  (1 << kvm_ioeventfd_flag_nr_deassign)
1369
1370 If datamatch flag is set, the event will be signaled only if the written value
1371 to the registered address is equal to datamatch in struct kvm_ioeventfd.
1372
1373 4.62 KVM_CREATE_SPAPR_TCE
1374
1375 Capability: KVM_CAP_SPAPR_TCE
1376 Architectures: powerpc
1377 Type: vm ioctl
1378 Parameters: struct kvm_create_spapr_tce (in)
1379 Returns: file descriptor for manipulating the created TCE table
1380
1381 This creates a virtual TCE (translation control entry) table, which
1382 is an IOMMU for PAPR-style virtual I/O.  It is used to translate
1383 logical addresses used in virtual I/O into guest physical addresses,
1384 and provides a scatter/gather capability for PAPR virtual I/O.
1385
1386 /* for KVM_CAP_SPAPR_TCE */
1387 struct kvm_create_spapr_tce {
1388         __u64 liobn;
1389         __u32 window_size;
1390 };
1391
1392 The liobn field gives the logical IO bus number for which to create a
1393 TCE table.  The window_size field specifies the size of the DMA window
1394 which this TCE table will translate - the table will contain one 64
1395 bit TCE entry for every 4kiB of the DMA window.
1396
1397 When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1398 table has been created using this ioctl(), the kernel will handle it
1399 in real mode, updating the TCE table.  H_PUT_TCE calls for other
1400 liobns will cause a vm exit and must be handled by userspace.
1401
1402 The return value is a file descriptor which can be passed to mmap(2)
1403 to map the created TCE table into userspace.  This lets userspace read
1404 the entries written by kernel-handled H_PUT_TCE calls, and also lets
1405 userspace update the TCE table directly which is useful in some
1406 circumstances.
1407
1408 4.63 KVM_ALLOCATE_RMA
1409
1410 Capability: KVM_CAP_PPC_RMA
1411 Architectures: powerpc
1412 Type: vm ioctl
1413 Parameters: struct kvm_allocate_rma (out)
1414 Returns: file descriptor for mapping the allocated RMA
1415
1416 This allocates a Real Mode Area (RMA) from the pool allocated at boot
1417 time by the kernel.  An RMA is a physically-contiguous, aligned region
1418 of memory used on older POWER processors to provide the memory which
1419 will be accessed by real-mode (MMU off) accesses in a KVM guest.
1420 POWER processors support a set of sizes for the RMA that usually
1421 includes 64MB, 128MB, 256MB and some larger powers of two.
1422
1423 /* for KVM_ALLOCATE_RMA */
1424 struct kvm_allocate_rma {
1425         __u64 rma_size;
1426 };
1427
1428 The return value is a file descriptor which can be passed to mmap(2)
1429 to map the allocated RMA into userspace.  The mapped area can then be
1430 passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1431 RMA for a virtual machine.  The size of the RMA in bytes (which is
1432 fixed at host kernel boot time) is returned in the rma_size field of
1433 the argument structure.
1434
1435 The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1436 is supported; 2 if the processor requires all virtual machines to have
1437 an RMA, or 1 if the processor can use an RMA but doesn't require it,
1438 because it supports the Virtual RMA (VRMA) facility.
1439
1440 5. The kvm_run structure
1441
1442 Application code obtains a pointer to the kvm_run structure by
1443 mmap()ing a vcpu fd.  From that point, application code can control
1444 execution by changing fields in kvm_run prior to calling the KVM_RUN
1445 ioctl, and obtain information about the reason KVM_RUN returned by
1446 looking up structure members.
1447
1448 struct kvm_run {
1449         /* in */
1450         __u8 request_interrupt_window;
1451
1452 Request that KVM_RUN return when it becomes possible to inject external
1453 interrupts into the guest.  Useful in conjunction with KVM_INTERRUPT.
1454
1455         __u8 padding1[7];
1456
1457         /* out */
1458         __u32 exit_reason;
1459
1460 When KVM_RUN has returned successfully (return value 0), this informs
1461 application code why KVM_RUN has returned.  Allowable values for this
1462 field are detailed below.
1463
1464         __u8 ready_for_interrupt_injection;
1465
1466 If request_interrupt_window has been specified, this field indicates
1467 an interrupt can be injected now with KVM_INTERRUPT.
1468
1469         __u8 if_flag;
1470
1471 The value of the current interrupt flag.  Only valid if in-kernel
1472 local APIC is not used.
1473
1474         __u8 padding2[2];
1475
1476         /* in (pre_kvm_run), out (post_kvm_run) */
1477         __u64 cr8;
1478
1479 The value of the cr8 register.  Only valid if in-kernel local APIC is
1480 not used.  Both input and output.
1481
1482         __u64 apic_base;
1483
1484 The value of the APIC BASE msr.  Only valid if in-kernel local
1485 APIC is not used.  Both input and output.
1486
1487         union {
1488                 /* KVM_EXIT_UNKNOWN */
1489                 struct {
1490                         __u64 hardware_exit_reason;
1491                 } hw;
1492
1493 If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1494 reasons.  Further architecture-specific information is available in
1495 hardware_exit_reason.
1496
1497                 /* KVM_EXIT_FAIL_ENTRY */
1498                 struct {
1499                         __u64 hardware_entry_failure_reason;
1500                 } fail_entry;
1501
1502 If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1503 to unknown reasons.  Further architecture-specific information is
1504 available in hardware_entry_failure_reason.
1505
1506                 /* KVM_EXIT_EXCEPTION */
1507                 struct {
1508                         __u32 exception;
1509                         __u32 error_code;
1510                 } ex;
1511
1512 Unused.
1513
1514                 /* KVM_EXIT_IO */
1515                 struct {
1516 #define KVM_EXIT_IO_IN  0
1517 #define KVM_EXIT_IO_OUT 1
1518                         __u8 direction;
1519                         __u8 size; /* bytes */
1520                         __u16 port;
1521                         __u32 count;
1522                         __u64 data_offset; /* relative to kvm_run start */
1523                 } io;
1524
1525 If exit_reason is KVM_EXIT_IO, then the vcpu has
1526 executed a port I/O instruction which could not be satisfied by kvm.
1527 data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1528 where kvm expects application code to place the data for the next
1529 KVM_RUN invocation (KVM_EXIT_IO_IN).  Data format is a packed array.
1530
1531                 struct {
1532                         struct kvm_debug_exit_arch arch;
1533                 } debug;
1534
1535 Unused.
1536
1537                 /* KVM_EXIT_MMIO */
1538                 struct {
1539                         __u64 phys_addr;
1540                         __u8  data[8];
1541                         __u32 len;
1542                         __u8  is_write;
1543                 } mmio;
1544
1545 If exit_reason is KVM_EXIT_MMIO, then the vcpu has
1546 executed a memory-mapped I/O instruction which could not be satisfied
1547 by kvm.  The 'data' member contains the written data if 'is_write' is
1548 true, and should be filled by application code otherwise.
1549
1550 NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1551 operations are complete (and guest state is consistent) only after userspace
1552 has re-entered the kernel with KVM_RUN.  The kernel side will first finish
1553 incomplete operations and then check for pending signals.  Userspace
1554 can re-enter the guest with an unmasked signal pending to complete
1555 pending operations.
1556
1557                 /* KVM_EXIT_HYPERCALL */
1558                 struct {
1559                         __u64 nr;
1560                         __u64 args[6];
1561                         __u64 ret;
1562                         __u32 longmode;
1563                         __u32 pad;
1564                 } hypercall;
1565
1566 Unused.  This was once used for 'hypercall to userspace'.  To implement
1567 such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1568 Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
1569
1570                 /* KVM_EXIT_TPR_ACCESS */
1571                 struct {
1572                         __u64 rip;
1573                         __u32 is_write;
1574                         __u32 pad;
1575                 } tpr_access;
1576
1577 To be documented (KVM_TPR_ACCESS_REPORTING).
1578
1579                 /* KVM_EXIT_S390_SIEIC */
1580                 struct {
1581                         __u8 icptcode;
1582                         __u64 mask; /* psw upper half */
1583                         __u64 addr; /* psw lower half */
1584                         __u16 ipa;
1585                         __u32 ipb;
1586                 } s390_sieic;
1587
1588 s390 specific.
1589
1590                 /* KVM_EXIT_S390_RESET */
1591 #define KVM_S390_RESET_POR       1
1592 #define KVM_S390_RESET_CLEAR     2
1593 #define KVM_S390_RESET_SUBSYSTEM 4
1594 #define KVM_S390_RESET_CPU_INIT  8
1595 #define KVM_S390_RESET_IPL       16
1596                 __u64 s390_reset_flags;
1597
1598 s390 specific.
1599
1600                 /* KVM_EXIT_DCR */
1601                 struct {
1602                         __u32 dcrn;
1603                         __u32 data;
1604                         __u8  is_write;
1605                 } dcr;
1606
1607 powerpc specific.
1608
1609                 /* KVM_EXIT_OSI */
1610                 struct {
1611                         __u64 gprs[32];
1612                 } osi;
1613
1614 MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1615 hypercalls and exit with this exit struct that contains all the guest gprs.
1616
1617 If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1618 Userspace can now handle the hypercall and when it's done modify the gprs as
1619 necessary. Upon guest entry all guest GPRs will then be replaced by the values
1620 in this struct.
1621
1622                 /* KVM_EXIT_PAPR_HCALL */
1623                 struct {
1624                         __u64 nr;
1625                         __u64 ret;
1626                         __u64 args[9];
1627                 } papr_hcall;
1628
1629 This is used on 64-bit PowerPC when emulating a pSeries partition,
1630 e.g. with the 'pseries' machine type in qemu.  It occurs when the
1631 guest does a hypercall using the 'sc 1' instruction.  The 'nr' field
1632 contains the hypercall number (from the guest R3), and 'args' contains
1633 the arguments (from the guest R4 - R12).  Userspace should put the
1634 return code in 'ret' and any extra returned values in args[].
1635 The possible hypercalls are defined in the Power Architecture Platform
1636 Requirements (PAPR) document available from www.power.org (free
1637 developer registration required to access it).
1638
1639                 /* Fix the size of the union. */
1640                 char padding[256];
1641         };
1642 };