KVM: APIC: avoid instruction emulation for EOI writes
[deliverable/linux.git] / Documentation / virtual / kvm / api.txt
CommitLineData
9c1b96e3
AK
1The 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
2044892d 262. File descriptors
9c1b96e3
AK
27
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
2044892d 31handle will create a VM file descriptor which can be used to issue VM
9c1b96e3
AK
32ioctls. 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
2e2602ca
AK
129Note: 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
9c1b96e3
AK
1334.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
b74a07be 167This ioctl is obsolete and has been removed.
9c1b96e3 168
68ba6974 1694.7 KVM_CREATE_VCPU
9c1b96e3
AK
170
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
8c3ba334
SL
178in the range [0, max_vcpus).
179
180The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
181the KVM_CHECK_EXTENSION ioctl() at run-time.
182The maximum possible value for max_vcpus can be retrieved using the
183KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
184
76d25402
PE
185If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
186cpus max.
8c3ba334
SL
187If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
188same as the value returned from KVM_CAP_NR_VCPUS.
9c1b96e3 189
371fefd6
PM
190On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
191threads in one or more virtual CPU cores. (This is because the
192hardware requires all the hardware threads in a CPU core to be in the
193same partition.) The KVM_CAP_PPC_SMT capability indicates the number
194of vcpus per virtual core (vcore). The vcore id is obtained by
195dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
196given vcore will always be in the same physical core as each other
197(though that might be a different physical core from time to time).
198Userspace can control the threading (SMT) mode of the guest by its
199allocation of vcpu ids. For example, if userspace wants
200single-threaded guest vcpus, it should make all vcpu ids be a multiple
201of the number of vcpus per vcore.
202
68ba6974 2034.8 KVM_GET_DIRTY_LOG (vm ioctl)
9c1b96e3
AK
204
205Capability: basic
206Architectures: x86
207Type: vm ioctl
208Parameters: struct kvm_dirty_log (in/out)
209Returns: 0 on success, -1 on error
210
211/* for KVM_GET_DIRTY_LOG */
212struct 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
221Given a memory slot, return a bitmap containing any pages dirtied
222since the last call to this ioctl. Bit 0 is the first page in the
223memory slot. Ensure the entire structure is cleared to avoid padding
224issues.
225
68ba6974 2264.9 KVM_SET_MEMORY_ALIAS
9c1b96e3
AK
227
228Capability: basic
229Architectures: x86
230Type: vm ioctl
231Parameters: struct kvm_memory_alias (in)
232Returns: 0 (success), -1 (error)
233
a1f4d395 234This ioctl is obsolete and has been removed.
9c1b96e3 235
68ba6974 2364.10 KVM_RUN
9c1b96e3
AK
237
238Capability: basic
239Architectures: all
240Type: vcpu ioctl
241Parameters: none
242Returns: 0 on success, -1 on error
243Errors:
244 EINTR: an unmasked signal is pending
245
246This ioctl is used to run a guest virtual cpu. While there are no
247explicit parameters, there is an implicit parameter block that can be
248obtained by mmap()ing the vcpu fd at offset 0, with the size given by
249KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
250kvm_run' (see below).
251
68ba6974 2524.11 KVM_GET_REGS
9c1b96e3
AK
253
254Capability: basic
255Architectures: all
256Type: vcpu ioctl
257Parameters: struct kvm_regs (out)
258Returns: 0 on success, -1 on error
259
260Reads the general purpose registers from the vcpu.
261
262/* x86 */
263struct 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
68ba6974 2724.12 KVM_SET_REGS
9c1b96e3
AK
273
274Capability: basic
275Architectures: all
276Type: vcpu ioctl
277Parameters: struct kvm_regs (in)
278Returns: 0 on success, -1 on error
279
280Writes the general purpose registers into the vcpu.
281
282See KVM_GET_REGS for the data structure.
283
68ba6974 2844.13 KVM_GET_SREGS
9c1b96e3
AK
285
286Capability: basic
5ce941ee 287Architectures: x86, ppc
9c1b96e3
AK
288Type: vcpu ioctl
289Parameters: struct kvm_sregs (out)
290Returns: 0 on success, -1 on error
291
292Reads special registers from the vcpu.
293
294/* x86 */
295struct 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
5ce941ee
SW
305/* ppc -- see arch/powerpc/include/asm/kvm.h */
306
9c1b96e3
AK
307interrupt_bitmap is a bitmap of pending external interrupts. At most
308one bit may be set. This interrupt has been acknowledged by the APIC
309but not yet injected into the cpu core.
310
68ba6974 3114.14 KVM_SET_SREGS
9c1b96e3
AK
312
313Capability: basic
5ce941ee 314Architectures: x86, ppc
9c1b96e3
AK
315Type: vcpu ioctl
316Parameters: struct kvm_sregs (in)
317Returns: 0 on success, -1 on error
318
319Writes special registers into the vcpu. See KVM_GET_SREGS for the
320data structures.
321
68ba6974 3224.15 KVM_TRANSLATE
9c1b96e3
AK
323
324Capability: basic
325Architectures: x86
326Type: vcpu ioctl
327Parameters: struct kvm_translation (in/out)
328Returns: 0 on success, -1 on error
329
330Translates a virtual address according to the vcpu's current address
331translation mode.
332
333struct 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
68ba6974 3454.16 KVM_INTERRUPT
9c1b96e3
AK
346
347Capability: basic
6f7a2bd4 348Architectures: x86, ppc
9c1b96e3
AK
349Type: vcpu ioctl
350Parameters: struct kvm_interrupt (in)
351Returns: 0 on success, -1 on error
352
353Queues a hardware interrupt vector to be injected. This is only
6f7a2bd4 354useful if in-kernel local APIC or equivalent is not used.
9c1b96e3
AK
355
356/* for KVM_INTERRUPT */
357struct kvm_interrupt {
358 /* in */
359 __u32 irq;
360};
361
6f7a2bd4
AG
362X86:
363
9c1b96e3
AK
364Note 'irq' is an interrupt vector, not an interrupt pin or line.
365
6f7a2bd4
AG
366PPC:
367
368Queues an external interrupt to be injected. This ioctl is overleaded
369with 3 different irq values:
370
371a) 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
376b) KVM_INTERRUPT_UNSET
377
378 This unsets any pending interrupt.
379
380 Only available with KVM_CAP_PPC_UNSET_IRQ.
381
382c) 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
390Note that any value for 'irq' other than the ones stated above is invalid
391and incurs unexpected behavior.
392
68ba6974 3934.17 KVM_DEBUG_GUEST
9c1b96e3
AK
394
395Capability: basic
396Architectures: none
397Type: vcpu ioctl
398Parameters: none)
399Returns: -1 on error
400
401Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
402
68ba6974 4034.18 KVM_GET_MSRS
9c1b96e3
AK
404
405Capability: basic
406Architectures: x86
407Type: vcpu ioctl
408Parameters: struct kvm_msrs (in/out)
409Returns: 0 on success, -1 on error
410
411Reads model-specific registers from the vcpu. Supported msr indices can
412be obtained using KVM_GET_MSR_INDEX_LIST.
413
414struct kvm_msrs {
415 __u32 nmsrs; /* number of msrs in entries */
416 __u32 pad;
417
418 struct kvm_msr_entry entries[0];
419};
420
421struct kvm_msr_entry {
422 __u32 index;
423 __u32 reserved;
424 __u64 data;
425};
426
427Application code should set the 'nmsrs' member (which indicates the
428size of the entries array) and the 'index' member of each array entry.
429kvm will fill in the 'data' member.
430
68ba6974 4314.19 KVM_SET_MSRS
9c1b96e3
AK
432
433Capability: basic
434Architectures: x86
435Type: vcpu ioctl
436Parameters: struct kvm_msrs (in)
437Returns: 0 on success, -1 on error
438
439Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
440data structures.
441
442Application code should set the 'nmsrs' member (which indicates the
443size of the entries array), and the 'index' and 'data' members of each
444array entry.
445
68ba6974 4464.20 KVM_SET_CPUID
9c1b96e3
AK
447
448Capability: basic
449Architectures: x86
450Type: vcpu ioctl
451Parameters: struct kvm_cpuid (in)
452Returns: 0 on success, -1 on error
453
454Defines the vcpu responses to the cpuid instruction. Applications
455should use the KVM_SET_CPUID2 ioctl if available.
456
457
458struct 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 */
468struct kvm_cpuid {
469 __u32 nent;
470 __u32 padding;
471 struct kvm_cpuid_entry entries[0];
472};
473
68ba6974 4744.21 KVM_SET_SIGNAL_MASK
9c1b96e3
AK
475
476Capability: basic
477Architectures: x86
478Type: vcpu ioctl
479Parameters: struct kvm_signal_mask (in)
480Returns: 0 on success, -1 on error
481
482Defines which signals are blocked during execution of KVM_RUN. This
483signal mask temporarily overrides the threads signal mask. Any
484unblocked signal received (except SIGKILL and SIGSTOP, which retain
485their traditional behaviour) will cause KVM_RUN to return with -EINTR.
486
487Note the signal will only be delivered if not blocked by the original
488signal mask.
489
490/* for KVM_SET_SIGNAL_MASK */
491struct kvm_signal_mask {
492 __u32 len;
493 __u8 sigset[0];
494};
495
68ba6974 4964.22 KVM_GET_FPU
9c1b96e3
AK
497
498Capability: basic
499Architectures: x86
500Type: vcpu ioctl
501Parameters: struct kvm_fpu (out)
502Returns: 0 on success, -1 on error
503
504Reads the floating point state from the vcpu.
505
506/* for KVM_GET_FPU and KVM_SET_FPU */
507struct 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
68ba6974 5214.23 KVM_SET_FPU
9c1b96e3
AK
522
523Capability: basic
524Architectures: x86
525Type: vcpu ioctl
526Parameters: struct kvm_fpu (in)
527Returns: 0 on success, -1 on error
528
529Writes the floating point state to the vcpu.
530
531/* for KVM_GET_FPU and KVM_SET_FPU */
532struct 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
68ba6974 5464.24 KVM_CREATE_IRQCHIP
5dadbfd6
AK
547
548Capability: KVM_CAP_IRQCHIP
549Architectures: x86, ia64
550Type: vm ioctl
551Parameters: none
552Returns: 0 on success, -1 on error
553
554Creates an interrupt controller model in the kernel. On x86, creates a virtual
555ioapic, a virtual PIC (two PICs, nested), and sets up future vcpus to have a
556local APIC. IRQ routing for GSIs 0-15 is set to both PIC and IOAPIC; GSI 16-23
557only go to the IOAPIC. On ia64, a IOSAPIC is created.
558
68ba6974 5594.25 KVM_IRQ_LINE
5dadbfd6
AK
560
561Capability: KVM_CAP_IRQCHIP
562Architectures: x86, ia64
563Type: vm ioctl
564Parameters: struct kvm_irq_level
565Returns: 0 on success, -1 on error
566
567Sets the level of a GSI input to the interrupt controller model in the kernel.
568Requires that an interrupt controller model has been previously created with
569KVM_CREATE_IRQCHIP. Note that edge-triggered interrupts require the level
570to be set to 1 and then back to 0.
571
572struct 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
68ba6974 5804.26 KVM_GET_IRQCHIP
5dadbfd6
AK
581
582Capability: KVM_CAP_IRQCHIP
583Architectures: x86, ia64
584Type: vm ioctl
585Parameters: struct kvm_irqchip (in/out)
586Returns: 0 on success, -1 on error
587
588Reads the state of a kernel interrupt controller created with
589KVM_CREATE_IRQCHIP into a buffer provided by the caller.
590
591struct 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
68ba6974 6014.27 KVM_SET_IRQCHIP
5dadbfd6
AK
602
603Capability: KVM_CAP_IRQCHIP
604Architectures: x86, ia64
605Type: vm ioctl
606Parameters: struct kvm_irqchip (in)
607Returns: 0 on success, -1 on error
608
609Sets the state of a kernel interrupt controller created with
610KVM_CREATE_IRQCHIP from a buffer provided by the caller.
611
612struct 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
68ba6974 6224.28 KVM_XEN_HVM_CONFIG
ffde22ac
ES
623
624Capability: KVM_CAP_XEN_HVM
625Architectures: x86
626Type: vm ioctl
627Parameters: struct kvm_xen_hvm_config (in)
628Returns: 0 on success, -1 on error
629
630Sets the MSR that the Xen HVM guest uses to initialize its hypercall
631page, and provides the starting address and size of the hypercall
632blobs in userspace. When the guest writes the MSR, kvm copies one
633page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
634memory.
635
636struct 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
68ba6974 6464.29 KVM_GET_CLOCK
afbcf7ab
GC
647
648Capability: KVM_CAP_ADJUST_CLOCK
649Architectures: x86
650Type: vm ioctl
651Parameters: struct kvm_clock_data (out)
652Returns: 0 on success, -1 on error
653
654Gets the current timestamp of kvmclock as seen by the current guest. In
655conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
656such as migration.
657
658struct kvm_clock_data {
659 __u64 clock; /* kvmclock current value */
660 __u32 flags;
661 __u32 pad[9];
662};
663
68ba6974 6644.30 KVM_SET_CLOCK
afbcf7ab
GC
665
666Capability: KVM_CAP_ADJUST_CLOCK
667Architectures: x86
668Type: vm ioctl
669Parameters: struct kvm_clock_data (in)
670Returns: 0 on success, -1 on error
671
2044892d 672Sets the current timestamp of kvmclock to the value specified in its parameter.
afbcf7ab
GC
673In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
674such as migration.
675
676struct kvm_clock_data {
677 __u64 clock; /* kvmclock current value */
678 __u32 flags;
679 __u32 pad[9];
680};
681
68ba6974 6824.31 KVM_GET_VCPU_EVENTS
3cfc3092
JK
683
684Capability: KVM_CAP_VCPU_EVENTS
48005f64 685Extended by: KVM_CAP_INTR_SHADOW
3cfc3092
JK
686Architectures: x86
687Type: vm ioctl
688Parameters: struct kvm_vcpu_event (out)
689Returns: 0 on success, -1 on error
690
691Gets currently pending exceptions, interrupts, and NMIs as well as related
692states of the vcpu.
693
694struct 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;
48005f64 706 __u8 shadow;
3cfc3092
JK
707 } interrupt;
708 struct {
709 __u8 injected;
710 __u8 pending;
711 __u8 masked;
712 __u8 pad;
713 } nmi;
714 __u32 sipi_vector;
dab4b911 715 __u32 flags;
3cfc3092
JK
716};
717
48005f64
JK
718KVM_VCPUEVENT_VALID_SHADOW may be set in the flags field to signal that
719interrupt.shadow contains a valid state. Otherwise, this field is undefined.
720
68ba6974 7214.32 KVM_SET_VCPU_EVENTS
3cfc3092
JK
722
723Capability: KVM_CAP_VCPU_EVENTS
48005f64 724Extended by: KVM_CAP_INTR_SHADOW
3cfc3092
JK
725Architectures: x86
726Type: vm ioctl
727Parameters: struct kvm_vcpu_event (in)
728Returns: 0 on success, -1 on error
729
730Set pending exceptions, interrupts, and NMIs as well as related states of the
731vcpu.
732
733See KVM_GET_VCPU_EVENTS for the data structure.
734
dab4b911
JK
735Fields that may be modified asynchronously by running VCPUs can be excluded
736from the update. These fields are nmi.pending and sipi_vector. Keep the
737corresponding bits in the flags field cleared to suppress overwriting the
738current in-kernel state. The bits are:
739
740KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
741KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
742
48005f64
JK
743If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
744the flags field to signal that interrupt.shadow contains a valid state and
745shall be written into the VCPU.
746
68ba6974 7474.33 KVM_GET_DEBUGREGS
a1efbe77
JK
748
749Capability: KVM_CAP_DEBUGREGS
750Architectures: x86
751Type: vm ioctl
752Parameters: struct kvm_debugregs (out)
753Returns: 0 on success, -1 on error
754
755Reads debug registers from the vcpu.
756
757struct kvm_debugregs {
758 __u64 db[4];
759 __u64 dr6;
760 __u64 dr7;
761 __u64 flags;
762 __u64 reserved[9];
763};
764
68ba6974 7654.34 KVM_SET_DEBUGREGS
a1efbe77
JK
766
767Capability: KVM_CAP_DEBUGREGS
768Architectures: x86
769Type: vm ioctl
770Parameters: struct kvm_debugregs (in)
771Returns: 0 on success, -1 on error
772
773Writes debug registers into the vcpu.
774
775See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
776yet and must be cleared on entry.
777
68ba6974 7784.35 KVM_SET_USER_MEMORY_REGION
0f2d8f4d
AK
779
780Capability: KVM_CAP_USER_MEM
781Architectures: all
782Type: vm ioctl
783Parameters: struct kvm_userspace_memory_region (in)
784Returns: 0 on success, -1 on error
785
786struct 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
797This ioctl allows the user to create or modify a guest physical memory
798slot. When changing an existing slot, it may be moved in the guest
799physical memory space, or its flags may be modified. It may not be
800resized. Slots may not overlap in guest physical address space.
801
802Memory for the region is taken starting at the address denoted by the
803field userspace_addr, which must point at user addressable memory for
804the entire memory slot size. Any object may back this memory, including
805anonymous memory, ordinary files, and hugetlbfs.
806
807It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
808be identical. This allows large pages in the guest to be backed by large
809pages in the host.
810
811The flags field supports just one flag, KVM_MEM_LOG_DIRTY_PAGES, which
812instructs kvm to keep track of writes to memory within the slot. See
813the KVM_GET_DIRTY_LOG ioctl.
814
815When the KVM_CAP_SYNC_MMU capability, changes in the backing of the memory
816region are automatically reflected into the guest. For example, an mmap()
817that affects the region will be made visible immediately. Another example
818is madvise(MADV_DROP).
819
820It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
821The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
822allocation and is deprecated.
3cfc3092 823
68ba6974 8244.36 KVM_SET_TSS_ADDR
8a5416db
AK
825
826Capability: KVM_CAP_SET_TSS_ADDR
827Architectures: x86
828Type: vm ioctl
829Parameters: unsigned long tss_address (in)
830Returns: 0 on success, -1 on error
831
832This ioctl defines the physical address of a three-page region in the guest
833physical address space. The region must be within the first 4GB of the
834guest physical address space and must not conflict with any memory slot
835or any mmio address. The guest may malfunction if it accesses this memory
836region.
837
838This ioctl is required on Intel-based hosts. This is needed on Intel hardware
839because of a quirk in the virtualization implementation (see the internals
840documentation when it pops into existence).
841
68ba6974 8424.37 KVM_ENABLE_CAP
71fbfd5f
AG
843
844Capability: KVM_CAP_ENABLE_CAP
845Architectures: ppc
846Type: vcpu ioctl
847Parameters: struct kvm_enable_cap (in)
848Returns: 0 on success; -1 on error
849
850+Not all extensions are enabled by default. Using this ioctl the application
851can enable an extension, making it available to the guest.
852
853On systems that do not support this ioctl, it always fails. On systems that
854do support it, it only works for extensions that are supported for enablement.
855
856To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
857be used.
858
859struct kvm_enable_cap {
860 /* in */
861 __u32 cap;
862
863The capability that is supposed to get enabled.
864
865 __u32 flags;
866
867A bitfield indicating future enhancements. Has to be 0 for now.
868
869 __u64 args[4];
870
871Arguments for enabling a feature. If a feature needs initial values to
872function properly, this is the place to put them.
873
874 __u8 pad[64];
875};
876
68ba6974 8774.38 KVM_GET_MP_STATE
b843f065
AK
878
879Capability: KVM_CAP_MP_STATE
880Architectures: x86, ia64
881Type: vcpu ioctl
882Parameters: struct kvm_mp_state (out)
883Returns: 0 on success; -1 on error
884
885struct kvm_mp_state {
886 __u32 mp_state;
887};
888
889Returns the vcpu's current "multiprocessing state" (though also valid on
890uniprocessor guests).
891
892Possible 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
b595076a 902 accessible via KVM_GET_VCPU_EVENTS)
b843f065
AK
903
904This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
905irqchip, the multiprocessing state must be maintained by userspace.
906
68ba6974 9074.39 KVM_SET_MP_STATE
b843f065
AK
908
909Capability: KVM_CAP_MP_STATE
910Architectures: x86, ia64
911Type: vcpu ioctl
912Parameters: struct kvm_mp_state (in)
913Returns: 0 on success; -1 on error
914
915Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
916arguments.
917
918This ioctl is only useful after KVM_CREATE_IRQCHIP. Without an in-kernel
919irqchip, the multiprocessing state must be maintained by userspace.
920
68ba6974 9214.40 KVM_SET_IDENTITY_MAP_ADDR
47dbb84f
AK
922
923Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
924Architectures: x86
925Type: vm ioctl
926Parameters: unsigned long identity (in)
927Returns: 0 on success, -1 on error
928
929This ioctl defines the physical address of a one-page region in the guest
930physical address space. The region must be within the first 4GB of the
931guest physical address space and must not conflict with any memory slot
932or any mmio address. The guest may malfunction if it accesses this memory
933region.
934
935This ioctl is required on Intel-based hosts. This is needed on Intel hardware
936because of a quirk in the virtualization implementation (see the internals
937documentation when it pops into existence).
938
68ba6974 9394.41 KVM_SET_BOOT_CPU_ID
57bc24cf
AK
940
941Capability: KVM_CAP_SET_BOOT_CPU_ID
942Architectures: x86, ia64
943Type: vm ioctl
944Parameters: unsigned long vcpu_id
945Returns: 0 on success, -1 on error
946
947Define which vcpu is the Bootstrap Processor (BSP). Values are the same
948as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
949is vcpu 0.
950
68ba6974 9514.42 KVM_GET_XSAVE
2d5b5a66
SY
952
953Capability: KVM_CAP_XSAVE
954Architectures: x86
955Type: vcpu ioctl
956Parameters: struct kvm_xsave (out)
957Returns: 0 on success, -1 on error
958
959struct kvm_xsave {
960 __u32 region[1024];
961};
962
963This ioctl would copy current vcpu's xsave struct to the userspace.
964
68ba6974 9654.43 KVM_SET_XSAVE
2d5b5a66
SY
966
967Capability: KVM_CAP_XSAVE
968Architectures: x86
969Type: vcpu ioctl
970Parameters: struct kvm_xsave (in)
971Returns: 0 on success, -1 on error
972
973struct kvm_xsave {
974 __u32 region[1024];
975};
976
977This ioctl would copy userspace's xsave struct to the kernel.
978
68ba6974 9794.44 KVM_GET_XCRS
2d5b5a66
SY
980
981Capability: KVM_CAP_XCRS
982Architectures: x86
983Type: vcpu ioctl
984Parameters: struct kvm_xcrs (out)
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 copy current vcpu's xcrs to the userspace.
1001
68ba6974 10024.45 KVM_SET_XCRS
2d5b5a66
SY
1003
1004Capability: KVM_CAP_XCRS
1005Architectures: x86
1006Type: vcpu ioctl
1007Parameters: struct kvm_xcrs (in)
1008Returns: 0 on success, -1 on error
1009
1010struct kvm_xcr {
1011 __u32 xcr;
1012 __u32 reserved;
1013 __u64 value;
1014};
1015
1016struct kvm_xcrs {
1017 __u32 nr_xcrs;
1018 __u32 flags;
1019 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1020 __u64 padding[16];
1021};
1022
1023This ioctl would set vcpu's xcr to the value userspace specified.
1024
68ba6974 10254.46 KVM_GET_SUPPORTED_CPUID
d153513d
AK
1026
1027Capability: KVM_CAP_EXT_CPUID
1028Architectures: x86
1029Type: system ioctl
1030Parameters: struct kvm_cpuid2 (in/out)
1031Returns: 0 on success, -1 on error
1032
1033struct 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
1043struct 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
1054This ioctl returns x86 cpuid features which are supported by both the hardware
1055and kvm. Userspace can use the information returned by this ioctl to
1056construct cpuid information (for KVM_SET_CPUID2) that is consistent with
1057hardware, kernel, and userspace capabilities, and with user requirements (for
1058example, the user may wish to constrain cpuid to emulate older hardware,
1059or for feature consistency across a cluster).
1060
1061Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1062with the 'nent' field indicating the number of entries in the variable-size
1063array 'entries'. If the number of entries is too low to describe the cpu
1064capabilities, an error (E2BIG) is returned. If the number is too high,
1065the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1066number is just right, the 'nent' field is adjusted to the number of valid
1067entries in the 'entries' array, which is then filled.
1068
1069The entries returned are the host cpuid as returned by the cpuid instruction,
c39cbd2a
AK
1070with unknown or unsupported features masked out. Some features (for example,
1071x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1072emulate them efficiently. The fields in each entry are defined as follows:
d153513d
AK
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
68ba6974 10904.47 KVM_PPC_GET_PVINFO
15711e9c
AG
1091
1092Capability: KVM_CAP_PPC_GET_PVINFO
1093Architectures: ppc
1094Type: vm ioctl
1095Parameters: struct kvm_ppc_pvinfo (out)
1096Returns: 0 on success, !0 on error
1097
1098struct kvm_ppc_pvinfo {
1099 __u32 flags;
1100 __u32 hcall[4];
1101 __u8 pad[108];
1102};
1103
1104This ioctl fetches PV specific information that need to be passed to the guest
1105using the device tree or other means from vm context.
1106
1107For now the only implemented piece of information distributed here is an array
1108of 4 instructions that make up a hypercall.
1109
1110If any additional field gets added to this structure later on, a bit for that
1111additional piece of information will be set in the flags bitmap.
1112
68ba6974 11134.48 KVM_ASSIGN_PCI_DEVICE
49f48172
JK
1114
1115Capability: KVM_CAP_DEVICE_ASSIGNMENT
1116Architectures: x86 ia64
1117Type: vm ioctl
1118Parameters: struct kvm_assigned_pci_dev (in)
1119Returns: 0 on success, -1 on error
1120
1121Assigns a host PCI device to the VM.
1122
1123struct 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
1134The PCI device is specified by the triple segnr, busnr, and devfn.
1135Identification in succeeding service requests is done via assigned_dev_id. The
1136following flags are specified:
1137
1138/* Depends on KVM_CAP_IOMMU */
1139#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
1140
68ba6974 11414.49 KVM_DEASSIGN_PCI_DEVICE
49f48172
JK
1142
1143Capability: KVM_CAP_DEVICE_DEASSIGNMENT
1144Architectures: x86 ia64
1145Type: vm ioctl
1146Parameters: struct kvm_assigned_pci_dev (in)
1147Returns: 0 on success, -1 on error
1148
1149Ends PCI device assignment, releasing all associated resources.
1150
1151See KVM_CAP_DEVICE_ASSIGNMENT for the data structure. Only assigned_dev_id is
1152used in kvm_assigned_pci_dev to identify the device.
1153
68ba6974 11544.50 KVM_ASSIGN_DEV_IRQ
49f48172
JK
1155
1156Capability: KVM_CAP_ASSIGN_DEV_IRQ
1157Architectures: x86 ia64
1158Type: vm ioctl
1159Parameters: struct kvm_assigned_irq (in)
1160Returns: 0 on success, -1 on error
1161
1162Assigns an IRQ to a passed-through device.
1163
1164struct kvm_assigned_irq {
1165 __u32 assigned_dev_id;
91e3d71d 1166 __u32 host_irq; /* ignored (legacy field) */
49f48172
JK
1167 __u32 guest_irq;
1168 __u32 flags;
1169 union {
49f48172
JK
1170 __u32 reserved[12];
1171 };
1172};
1173
1174The 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
1184It is not valid to specify multiple types per host or guest IRQ. However, the
1185IRQ type of host and guest can differ or can even be null.
1186
68ba6974 11874.51 KVM_DEASSIGN_DEV_IRQ
49f48172
JK
1188
1189Capability: KVM_CAP_ASSIGN_DEV_IRQ
1190Architectures: x86 ia64
1191Type: vm ioctl
1192Parameters: struct kvm_assigned_irq (in)
1193Returns: 0 on success, -1 on error
1194
1195Ends an IRQ assignment to a passed-through device.
1196
1197See KVM_ASSIGN_DEV_IRQ for the data structure. The target device is specified
1198by assigned_dev_id, flags must correspond to the IRQ type specified on
1199KVM_ASSIGN_DEV_IRQ. Partial deassignment of host or guest IRQ is allowed.
1200
68ba6974 12014.52 KVM_SET_GSI_ROUTING
49f48172
JK
1202
1203Capability: KVM_CAP_IRQ_ROUTING
1204Architectures: x86 ia64
1205Type: vm ioctl
1206Parameters: struct kvm_irq_routing (in)
1207Returns: 0 on success, -1 on error
1208
1209Sets the GSI routing table entries, overwriting any previously set entries.
1210
1211struct kvm_irq_routing {
1212 __u32 nr;
1213 __u32 flags;
1214 struct kvm_irq_routing_entry entries[0];
1215};
1216
1217No flags are specified so far, the corresponding field must be set to zero.
1218
1219struct 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
1235No flags are specified so far, the corresponding field must be set to zero.
1236
1237struct kvm_irq_routing_irqchip {
1238 __u32 irqchip;
1239 __u32 pin;
1240};
1241
1242struct kvm_irq_routing_msi {
1243 __u32 address_lo;
1244 __u32 address_hi;
1245 __u32 data;
1246 __u32 pad;
1247};
1248
68ba6974 12494.53 KVM_ASSIGN_SET_MSIX_NR
49f48172
JK
1250
1251Capability: KVM_CAP_DEVICE_MSIX
1252Architectures: x86 ia64
1253Type: vm ioctl
1254Parameters: struct kvm_assigned_msix_nr (in)
1255Returns: 0 on success, -1 on error
1256
58f0964e
JK
1257Set the number of MSI-X interrupts for an assigned device. The number is
1258reset again by terminating the MSI-X assignment of the device via
1259KVM_DEASSIGN_DEV_IRQ. Calling this service more than once at any earlier
1260point will fail.
49f48172
JK
1261
1262struct 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
68ba6974 12704.54 KVM_ASSIGN_SET_MSIX_ENTRY
49f48172
JK
1271
1272Capability: KVM_CAP_DEVICE_MSIX
1273Architectures: x86 ia64
1274Type: vm ioctl
1275Parameters: struct kvm_assigned_msix_entry (in)
1276Returns: 0 on success, -1 on error
1277
1278Specifies the routing of an MSI-X assigned device interrupt to a GSI. Setting
1279the GSI vector to zero means disabling the interrupt.
1280
1281struct 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
92a1f12d
JR
12884.54 KVM_SET_TSC_KHZ
1289
1290Capability: KVM_CAP_TSC_CONTROL
1291Architectures: x86
1292Type: vcpu ioctl
1293Parameters: virtual tsc_khz
1294Returns: 0 on success, -1 on error
1295
1296Specifies the tsc frequency for the virtual machine. The unit of the
1297frequency is KHz.
1298
12994.55 KVM_GET_TSC_KHZ
1300
1301Capability: KVM_CAP_GET_TSC_KHZ
1302Architectures: x86
1303Type: vcpu ioctl
1304Parameters: none
1305Returns: virtual tsc-khz on success, negative value on error
1306
1307Returns the tsc frequency of the guest. The unit of the return value is
1308KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1309error.
1310
e7677933
AK
13114.56 KVM_GET_LAPIC
1312
1313Capability: KVM_CAP_IRQCHIP
1314Architectures: x86
1315Type: vcpu ioctl
1316Parameters: struct kvm_lapic_state (out)
1317Returns: 0 on success, -1 on error
1318
1319#define KVM_APIC_REG_SIZE 0x400
1320struct kvm_lapic_state {
1321 char regs[KVM_APIC_REG_SIZE];
1322};
1323
1324Reads the Local APIC registers and copies them into the input argument. The
1325data format and layout are the same as documented in the architecture manual.
1326
13274.57 KVM_SET_LAPIC
1328
1329Capability: KVM_CAP_IRQCHIP
1330Architectures: x86
1331Type: vcpu ioctl
1332Parameters: struct kvm_lapic_state (in)
1333Returns: 0 on success, -1 on error
1334
1335#define KVM_APIC_REG_SIZE 0x400
1336struct kvm_lapic_state {
1337 char regs[KVM_APIC_REG_SIZE];
1338};
1339
1340Copies the input argument into the the Local APIC registers. The data format
1341and layout are the same as documented in the architecture manual.
1342
7f4382e8 13434.58 KVM_IOEVENTFD
55399a02
SL
1344
1345Capability: KVM_CAP_IOEVENTFD
1346Architectures: all
1347Type: vm ioctl
1348Parameters: struct kvm_ioeventfd (in)
1349Returns: 0 on success, !0 on error
1350
1351This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1352within the guest. A guest write in the registered address will signal the
1353provided event instead of triggering an exit.
1354
1355struct 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
1364The 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
1370If datamatch flag is set, the event will be signaled only if the written value
1371to the registered address is equal to datamatch in struct kvm_ioeventfd.
1372
54738c09
DG
13734.62 KVM_CREATE_SPAPR_TCE
1374
1375Capability: KVM_CAP_SPAPR_TCE
1376Architectures: powerpc
1377Type: vm ioctl
1378Parameters: struct kvm_create_spapr_tce (in)
1379Returns: file descriptor for manipulating the created TCE table
1380
1381This creates a virtual TCE (translation control entry) table, which
1382is an IOMMU for PAPR-style virtual I/O. It is used to translate
1383logical addresses used in virtual I/O into guest physical addresses,
1384and provides a scatter/gather capability for PAPR virtual I/O.
1385
1386/* for KVM_CAP_SPAPR_TCE */
1387struct kvm_create_spapr_tce {
1388 __u64 liobn;
1389 __u32 window_size;
1390};
1391
1392The liobn field gives the logical IO bus number for which to create a
1393TCE table. The window_size field specifies the size of the DMA window
1394which this TCE table will translate - the table will contain one 64
1395bit TCE entry for every 4kiB of the DMA window.
1396
1397When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1398table has been created using this ioctl(), the kernel will handle it
1399in real mode, updating the TCE table. H_PUT_TCE calls for other
1400liobns will cause a vm exit and must be handled by userspace.
1401
1402The return value is a file descriptor which can be passed to mmap(2)
1403to map the created TCE table into userspace. This lets userspace read
1404the entries written by kernel-handled H_PUT_TCE calls, and also lets
1405userspace update the TCE table directly which is useful in some
1406circumstances.
1407
aa04b4cc
PM
14084.63 KVM_ALLOCATE_RMA
1409
1410Capability: KVM_CAP_PPC_RMA
1411Architectures: powerpc
1412Type: vm ioctl
1413Parameters: struct kvm_allocate_rma (out)
1414Returns: file descriptor for mapping the allocated RMA
1415
1416This allocates a Real Mode Area (RMA) from the pool allocated at boot
1417time by the kernel. An RMA is a physically-contiguous, aligned region
1418of memory used on older POWER processors to provide the memory which
1419will be accessed by real-mode (MMU off) accesses in a KVM guest.
1420POWER processors support a set of sizes for the RMA that usually
1421includes 64MB, 128MB, 256MB and some larger powers of two.
1422
1423/* for KVM_ALLOCATE_RMA */
1424struct kvm_allocate_rma {
1425 __u64 rma_size;
1426};
1427
1428The return value is a file descriptor which can be passed to mmap(2)
1429to map the allocated RMA into userspace. The mapped area can then be
1430passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1431RMA for a virtual machine. The size of the RMA in bytes (which is
1432fixed at host kernel boot time) is returned in the rma_size field of
1433the argument structure.
1434
1435The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1436is supported; 2 if the processor requires all virtual machines to have
1437an RMA, or 1 if the processor can use an RMA but doesn't require it,
1438because it supports the Virtual RMA (VRMA) facility.
1439
9c1b96e3
AK
14405. The kvm_run structure
1441
1442Application code obtains a pointer to the kvm_run structure by
1443mmap()ing a vcpu fd. From that point, application code can control
1444execution by changing fields in kvm_run prior to calling the KVM_RUN
1445ioctl, and obtain information about the reason KVM_RUN returned by
1446looking up structure members.
1447
1448struct kvm_run {
1449 /* in */
1450 __u8 request_interrupt_window;
1451
1452Request that KVM_RUN return when it becomes possible to inject external
1453interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
1454
1455 __u8 padding1[7];
1456
1457 /* out */
1458 __u32 exit_reason;
1459
1460When KVM_RUN has returned successfully (return value 0), this informs
1461application code why KVM_RUN has returned. Allowable values for this
1462field are detailed below.
1463
1464 __u8 ready_for_interrupt_injection;
1465
1466If request_interrupt_window has been specified, this field indicates
1467an interrupt can be injected now with KVM_INTERRUPT.
1468
1469 __u8 if_flag;
1470
1471The value of the current interrupt flag. Only valid if in-kernel
1472local APIC is not used.
1473
1474 __u8 padding2[2];
1475
1476 /* in (pre_kvm_run), out (post_kvm_run) */
1477 __u64 cr8;
1478
1479The value of the cr8 register. Only valid if in-kernel local APIC is
1480not used. Both input and output.
1481
1482 __u64 apic_base;
1483
1484The value of the APIC BASE msr. Only valid if in-kernel local
1485APIC is not used. Both input and output.
1486
1487 union {
1488 /* KVM_EXIT_UNKNOWN */
1489 struct {
1490 __u64 hardware_exit_reason;
1491 } hw;
1492
1493If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
1494reasons. Further architecture-specific information is available in
1495hardware_exit_reason.
1496
1497 /* KVM_EXIT_FAIL_ENTRY */
1498 struct {
1499 __u64 hardware_entry_failure_reason;
1500 } fail_entry;
1501
1502If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
1503to unknown reasons. Further architecture-specific information is
1504available in hardware_entry_failure_reason.
1505
1506 /* KVM_EXIT_EXCEPTION */
1507 struct {
1508 __u32 exception;
1509 __u32 error_code;
1510 } ex;
1511
1512Unused.
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
2044892d 1525If exit_reason is KVM_EXIT_IO, then the vcpu has
9c1b96e3
AK
1526executed a port I/O instruction which could not be satisfied by kvm.
1527data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
1528where kvm expects application code to place the data for the next
2044892d 1529KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
9c1b96e3
AK
1530
1531 struct {
1532 struct kvm_debug_exit_arch arch;
1533 } debug;
1534
1535Unused.
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
2044892d 1545If exit_reason is KVM_EXIT_MMIO, then the vcpu has
9c1b96e3
AK
1546executed a memory-mapped I/O instruction which could not be satisfied
1547by kvm. The 'data' member contains the written data if 'is_write' is
1548true, and should be filled by application code otherwise.
1549
ad0a048b
AG
1550NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO and KVM_EXIT_OSI, the corresponding
1551operations are complete (and guest state is consistent) only after userspace
1552has re-entered the kernel with KVM_RUN. The kernel side will first finish
67961344
MT
1553incomplete operations and then check for pending signals. Userspace
1554can re-enter the guest with an unmasked signal pending to complete
1555pending operations.
1556
9c1b96e3
AK
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
647dc49e
AK
1566Unused. This was once used for 'hypercall to userspace'. To implement
1567such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
1568Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
9c1b96e3
AK
1569
1570 /* KVM_EXIT_TPR_ACCESS */
1571 struct {
1572 __u64 rip;
1573 __u32 is_write;
1574 __u32 pad;
1575 } tpr_access;
1576
1577To 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
1588s390 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
1598s390 specific.
1599
1600 /* KVM_EXIT_DCR */
1601 struct {
1602 __u32 dcrn;
1603 __u32 data;
1604 __u8 is_write;
1605 } dcr;
1606
1607powerpc specific.
1608
ad0a048b
AG
1609 /* KVM_EXIT_OSI */
1610 struct {
1611 __u64 gprs[32];
1612 } osi;
1613
1614MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
1615hypercalls and exit with this exit struct that contains all the guest gprs.
1616
1617If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
1618Userspace can now handle the hypercall and when it's done modify the gprs as
1619necessary. Upon guest entry all guest GPRs will then be replaced by the values
1620in this struct.
1621
de56a948
PM
1622 /* KVM_EXIT_PAPR_HCALL */
1623 struct {
1624 __u64 nr;
1625 __u64 ret;
1626 __u64 args[9];
1627 } papr_hcall;
1628
1629This is used on 64-bit PowerPC when emulating a pSeries partition,
1630e.g. with the 'pseries' machine type in qemu. It occurs when the
1631guest does a hypercall using the 'sc 1' instruction. The 'nr' field
1632contains the hypercall number (from the guest R3), and 'args' contains
1633the arguments (from the guest R4 - R12). Userspace should put the
1634return code in 'ret' and any extra returned values in args[].
1635The possible hypercalls are defined in the Power Architecture Platform
1636Requirements (PAPR) document available from www.power.org (free
1637developer registration required to access it).
1638
9c1b96e3
AK
1639 /* Fix the size of the union. */
1640 char padding[256];
1641 };
1642};
This page took 0.223797 seconds and 5 git commands to generate.