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