xref: /openbmc/linux/Documentation/virt/kvm/api.rst (revision f21e49be)
1.. SPDX-License-Identifier: GPL-2.0
2
3===================================================================
4The Definitive KVM (Kernel-based Virtual Machine) API Documentation
5===================================================================
6
71. General description
8======================
9
10The kvm API is a set of ioctls that are issued to control various aspects
11of a virtual machine.  The ioctls belong to the following classes:
12
13 - System ioctls: These query and set global attributes which affect the
14   whole kvm subsystem.  In addition a system ioctl is used to create
15   virtual machines.
16
17 - VM ioctls: These query and set attributes that affect an entire virtual
18   machine, for example memory layout.  In addition a VM ioctl is used to
19   create virtual cpus (vcpus) and devices.
20
21   VM ioctls must be issued from the same process (address space) that was
22   used to create the VM.
23
24 - vcpu ioctls: These query and set attributes that control the operation
25   of a single virtual cpu.
26
27   vcpu ioctls should be issued from the same thread that was used to create
28   the vcpu, except for asynchronous vcpu ioctl that are marked as such in
29   the documentation.  Otherwise, the first ioctl after switching threads
30   could see a performance impact.
31
32 - device ioctls: These query and set attributes that control the operation
33   of a single device.
34
35   device ioctls must be issued from the same process (address space) that
36   was used to create the VM.
37
382. File descriptors
39===================
40
41The kvm API is centered around file descriptors.  An initial
42open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
43can be used to issue system ioctls.  A KVM_CREATE_VM ioctl on this
44handle will create a VM file descriptor which can be used to issue VM
45ioctls.  A KVM_CREATE_VCPU or KVM_CREATE_DEVICE ioctl on a VM fd will
46create a virtual cpu or device and return a file descriptor pointing to
47the new resource.  Finally, ioctls on a vcpu or device fd can be used
48to control the vcpu or device.  For vcpus, this includes the important
49task of actually running guest code.
50
51In general file descriptors can be migrated among processes by means
52of fork() and the SCM_RIGHTS facility of unix domain socket.  These
53kinds of tricks are explicitly not supported by kvm.  While they will
54not cause harm to the host, their actual behavior is not guaranteed by
55the API.  See "General description" for details on the ioctl usage
56model that is supported by KVM.
57
58It is important to note that although VM ioctls may only be issued from
59the process that created the VM, a VM's lifecycle is associated with its
60file descriptor, not its creator (process).  In other words, the VM and
61its resources, *including the associated address space*, are not freed
62until the last reference to the VM's file descriptor has been released.
63For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
64not be freed until both the parent (original) process and its child have
65put their references to the VM's file descriptor.
66
67Because a VM's resources are not freed until the last reference to its
68file descriptor is released, creating additional references to a VM
69via fork(), dup(), etc... without careful consideration is strongly
70discouraged and may have unwanted side effects, e.g. memory allocated
71by and on behalf of the VM's process may not be freed/unaccounted when
72the VM is shut down.
73
74
753. Extensions
76=============
77
78As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
79incompatible change are allowed.  However, there is an extension
80facility that allows backward-compatible extensions to the API to be
81queried and used.
82
83The extension mechanism is not based on the Linux version number.
84Instead, kvm defines extension identifiers and a facility to query
85whether a particular extension identifier is available.  If it is, a
86set of ioctls is available for application use.
87
88
894. API description
90==================
91
92This section describes ioctls that can be used to control kvm guests.
93For each ioctl, the following information is provided along with a
94description:
95
96  Capability:
97      which KVM extension provides this ioctl.  Can be 'basic',
98      which means that is will be provided by any kernel that supports
99      API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
100      means availability needs to be checked with KVM_CHECK_EXTENSION
101      (see section 4.4), or 'none' which means that while not all kernels
102      support this ioctl, there's no capability bit to check its
103      availability: for kernels that don't support the ioctl,
104      the ioctl returns -ENOTTY.
105
106  Architectures:
107      which instruction set architectures provide this ioctl.
108      x86 includes both i386 and x86_64.
109
110  Type:
111      system, vm, or vcpu.
112
113  Parameters:
114      what parameters are accepted by the ioctl.
115
116  Returns:
117      the return value.  General error numbers (EBADF, ENOMEM, EINVAL)
118      are not detailed, but errors with specific meanings are.
119
120
1214.1 KVM_GET_API_VERSION
122-----------------------
123
124:Capability: basic
125:Architectures: all
126:Type: system ioctl
127:Parameters: none
128:Returns: the constant KVM_API_VERSION (=12)
129
130This identifies the API version as the stable kvm API. It is not
131expected that this number will change.  However, Linux 2.6.20 and
1322.6.21 report earlier versions; these are not documented and not
133supported.  Applications should refuse to run if KVM_GET_API_VERSION
134returns a value other than 12.  If this check passes, all ioctls
135described as 'basic' will be available.
136
137
1384.2 KVM_CREATE_VM
139-----------------
140
141:Capability: basic
142:Architectures: all
143:Type: system ioctl
144:Parameters: machine type identifier (KVM_VM_*)
145:Returns: a VM fd that can be used to control the new virtual machine.
146
147The new VM has no virtual cpus and no memory.
148You probably want to use 0 as machine type.
149
150In order to create user controlled virtual machines on S390, check
151KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
152privileged user (CAP_SYS_ADMIN).
153
154To use hardware assisted virtualization on MIPS (VZ ASE) rather than
155the default trap & emulate implementation (which changes the virtual
156memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the
157flag KVM_VM_MIPS_VZ.
158
159
160On arm64, the physical address size for a VM (IPA Size limit) is limited
161to 40bits by default. The limit can be configured if the host supports the
162extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use
163KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type
164identifier, where IPA_Bits is the maximum width of any physical
165address used by the VM. The IPA_Bits is encoded in bits[7-0] of the
166machine type identifier.
167
168e.g, to configure a guest to use 48bit physical address size::
169
170    vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48));
171
172The requested size (IPA_Bits) must be:
173
174 ==   =========================================================
175  0   Implies default size, 40bits (for backward compatibility)
176  N   Implies N bits, where N is a positive integer such that,
177      32 <= N <= Host_IPA_Limit
178 ==   =========================================================
179
180Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and
181is dependent on the CPU capability and the kernel configuration. The limit can
182be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
183ioctl() at run-time.
184
185Creation of the VM will fail if the requested IPA size (whether it is
186implicit or explicit) is unsupported on the host.
187
188Please note that configuring the IPA size does not affect the capability
189exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
190size of the address translated by the stage2 level (guest physical to
191host physical address translations).
192
193
1944.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
195----------------------------------------------------------
196
197:Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
198:Architectures: x86
199:Type: system ioctl
200:Parameters: struct kvm_msr_list (in/out)
201:Returns: 0 on success; -1 on error
202
203Errors:
204
205  ======     ============================================================
206  EFAULT     the msr index list cannot be read from or written to
207  E2BIG      the msr index list is too big to fit in the array specified by
208             the user.
209  ======     ============================================================
210
211::
212
213  struct kvm_msr_list {
214	__u32 nmsrs; /* number of msrs in entries */
215	__u32 indices[0];
216  };
217
218The user fills in the size of the indices array in nmsrs, and in return
219kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
220indices array with their numbers.
221
222KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported.  The list
223varies by kvm version and host processor, but does not change otherwise.
224
225Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
226not returned in the MSR list, as different vcpus can have a different number
227of banks, as set via the KVM_X86_SETUP_MCE ioctl.
228
229KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
230to the KVM_GET_MSRS system ioctl.  This lets userspace probe host capabilities
231and processor features that are exposed via MSRs (e.g., VMX capabilities).
232This list also varies by kvm version and host processor, but does not change
233otherwise.
234
235
2364.4 KVM_CHECK_EXTENSION
237-----------------------
238
239:Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
240:Architectures: all
241:Type: system ioctl, vm ioctl
242:Parameters: extension identifier (KVM_CAP_*)
243:Returns: 0 if unsupported; 1 (or some other positive integer) if supported
244
245The API allows the application to query about extensions to the core
246kvm API.  Userspace passes an extension identifier (an integer) and
247receives an integer that describes the extension availability.
248Generally 0 means no and 1 means yes, but some extensions may report
249additional information in the integer return value.
250
251Based on their initialization different VMs may have different capabilities.
252It is thus encouraged to use the vm ioctl to query for capabilities (available
253with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
254
2554.5 KVM_GET_VCPU_MMAP_SIZE
256--------------------------
257
258:Capability: basic
259:Architectures: all
260:Type: system ioctl
261:Parameters: none
262:Returns: size of vcpu mmap area, in bytes
263
264The KVM_RUN ioctl (cf.) communicates with userspace via a shared
265memory region.  This ioctl returns the size of that region.  See the
266KVM_RUN documentation for details.
267
268Besides the size of the KVM_RUN communication region, other areas of
269the VCPU file descriptor can be mmap-ed, including:
270
271- if KVM_CAP_COALESCED_MMIO is available, a page at
272  KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons,
273  this page is included in the result of KVM_GET_VCPU_MMAP_SIZE.
274  KVM_CAP_COALESCED_MMIO is not documented yet.
275
276- if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at
277  KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE.  For more information on
278  KVM_CAP_DIRTY_LOG_RING, see section 8.3.
279
280
2814.6 KVM_SET_MEMORY_REGION
282-------------------------
283
284:Capability: basic
285:Architectures: all
286:Type: vm ioctl
287:Parameters: struct kvm_memory_region (in)
288:Returns: 0 on success, -1 on error
289
290This ioctl is obsolete and has been removed.
291
292
2934.7 KVM_CREATE_VCPU
294-------------------
295
296:Capability: basic
297:Architectures: all
298:Type: vm ioctl
299:Parameters: vcpu id (apic id on x86)
300:Returns: vcpu fd on success, -1 on error
301
302This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
303The vcpu id is an integer in the range [0, max_vcpu_id).
304
305The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
306the KVM_CHECK_EXTENSION ioctl() at run-time.
307The maximum possible value for max_vcpus can be retrieved using the
308KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
309
310If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
311cpus max.
312If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
313same as the value returned from KVM_CAP_NR_VCPUS.
314
315The maximum possible value for max_vcpu_id can be retrieved using the
316KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
317
318If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
319is the same as the value returned from KVM_CAP_MAX_VCPUS.
320
321On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
322threads in one or more virtual CPU cores.  (This is because the
323hardware requires all the hardware threads in a CPU core to be in the
324same partition.)  The KVM_CAP_PPC_SMT capability indicates the number
325of vcpus per virtual core (vcore).  The vcore id is obtained by
326dividing the vcpu id by the number of vcpus per vcore.  The vcpus in a
327given vcore will always be in the same physical core as each other
328(though that might be a different physical core from time to time).
329Userspace can control the threading (SMT) mode of the guest by its
330allocation of vcpu ids.  For example, if userspace wants
331single-threaded guest vcpus, it should make all vcpu ids be a multiple
332of the number of vcpus per vcore.
333
334For virtual cpus that have been created with S390 user controlled virtual
335machines, the resulting vcpu fd can be memory mapped at page offset
336KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
337cpu's hardware control block.
338
339
3404.8 KVM_GET_DIRTY_LOG (vm ioctl)
341--------------------------------
342
343:Capability: basic
344:Architectures: all
345:Type: vm ioctl
346:Parameters: struct kvm_dirty_log (in/out)
347:Returns: 0 on success, -1 on error
348
349::
350
351  /* for KVM_GET_DIRTY_LOG */
352  struct kvm_dirty_log {
353	__u32 slot;
354	__u32 padding;
355	union {
356		void __user *dirty_bitmap; /* one bit per page */
357		__u64 padding;
358	};
359  };
360
361Given a memory slot, return a bitmap containing any pages dirtied
362since the last call to this ioctl.  Bit 0 is the first page in the
363memory slot.  Ensure the entire structure is cleared to avoid padding
364issues.
365
366If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
367the address space for which you want to return the dirty bitmap.  See
368KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
369
370The bits in the dirty bitmap are cleared before the ioctl returns, unless
371KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled.  For more information,
372see the description of the capability.
373
3744.9 KVM_SET_MEMORY_ALIAS
375------------------------
376
377:Capability: basic
378:Architectures: x86
379:Type: vm ioctl
380:Parameters: struct kvm_memory_alias (in)
381:Returns: 0 (success), -1 (error)
382
383This ioctl is obsolete and has been removed.
384
385
3864.10 KVM_RUN
387------------
388
389:Capability: basic
390:Architectures: all
391:Type: vcpu ioctl
392:Parameters: none
393:Returns: 0 on success, -1 on error
394
395Errors:
396
397  =======    ==============================================================
398  EINTR      an unmasked signal is pending
399  ENOEXEC    the vcpu hasn't been initialized or the guest tried to execute
400             instructions from device memory (arm64)
401  ENOSYS     data abort outside memslots with no syndrome info and
402             KVM_CAP_ARM_NISV_TO_USER not enabled (arm64)
403  EPERM      SVE feature set but not finalized (arm64)
404  =======    ==============================================================
405
406This ioctl is used to run a guest virtual cpu.  While there are no
407explicit parameters, there is an implicit parameter block that can be
408obtained by mmap()ing the vcpu fd at offset 0, with the size given by
409KVM_GET_VCPU_MMAP_SIZE.  The parameter block is formatted as a 'struct
410kvm_run' (see below).
411
412
4134.11 KVM_GET_REGS
414-----------------
415
416:Capability: basic
417:Architectures: all except ARM, arm64
418:Type: vcpu ioctl
419:Parameters: struct kvm_regs (out)
420:Returns: 0 on success, -1 on error
421
422Reads the general purpose registers from the vcpu.
423
424::
425
426  /* x86 */
427  struct kvm_regs {
428	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
429	__u64 rax, rbx, rcx, rdx;
430	__u64 rsi, rdi, rsp, rbp;
431	__u64 r8,  r9,  r10, r11;
432	__u64 r12, r13, r14, r15;
433	__u64 rip, rflags;
434  };
435
436  /* mips */
437  struct kvm_regs {
438	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
439	__u64 gpr[32];
440	__u64 hi;
441	__u64 lo;
442	__u64 pc;
443  };
444
445
4464.12 KVM_SET_REGS
447-----------------
448
449:Capability: basic
450:Architectures: all except ARM, arm64
451:Type: vcpu ioctl
452:Parameters: struct kvm_regs (in)
453:Returns: 0 on success, -1 on error
454
455Writes the general purpose registers into the vcpu.
456
457See KVM_GET_REGS for the data structure.
458
459
4604.13 KVM_GET_SREGS
461------------------
462
463:Capability: basic
464:Architectures: x86, ppc
465:Type: vcpu ioctl
466:Parameters: struct kvm_sregs (out)
467:Returns: 0 on success, -1 on error
468
469Reads special registers from the vcpu.
470
471::
472
473  /* x86 */
474  struct kvm_sregs {
475	struct kvm_segment cs, ds, es, fs, gs, ss;
476	struct kvm_segment tr, ldt;
477	struct kvm_dtable gdt, idt;
478	__u64 cr0, cr2, cr3, cr4, cr8;
479	__u64 efer;
480	__u64 apic_base;
481	__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
482  };
483
484  /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
485
486interrupt_bitmap is a bitmap of pending external interrupts.  At most
487one bit may be set.  This interrupt has been acknowledged by the APIC
488but not yet injected into the cpu core.
489
490
4914.14 KVM_SET_SREGS
492------------------
493
494:Capability: basic
495:Architectures: x86, ppc
496:Type: vcpu ioctl
497:Parameters: struct kvm_sregs (in)
498:Returns: 0 on success, -1 on error
499
500Writes special registers into the vcpu.  See KVM_GET_SREGS for the
501data structures.
502
503
5044.15 KVM_TRANSLATE
505------------------
506
507:Capability: basic
508:Architectures: x86
509:Type: vcpu ioctl
510:Parameters: struct kvm_translation (in/out)
511:Returns: 0 on success, -1 on error
512
513Translates a virtual address according to the vcpu's current address
514translation mode.
515
516::
517
518  struct kvm_translation {
519	/* in */
520	__u64 linear_address;
521
522	/* out */
523	__u64 physical_address;
524	__u8  valid;
525	__u8  writeable;
526	__u8  usermode;
527	__u8  pad[5];
528  };
529
530
5314.16 KVM_INTERRUPT
532------------------
533
534:Capability: basic
535:Architectures: x86, ppc, mips, riscv
536:Type: vcpu ioctl
537:Parameters: struct kvm_interrupt (in)
538:Returns: 0 on success, negative on failure.
539
540Queues a hardware interrupt vector to be injected.
541
542::
543
544  /* for KVM_INTERRUPT */
545  struct kvm_interrupt {
546	/* in */
547	__u32 irq;
548  };
549
550X86:
551^^^^
552
553:Returns:
554
555	========= ===================================
556	  0       on success,
557	 -EEXIST  if an interrupt is already enqueued
558	 -EINVAL  the irq number is invalid
559	 -ENXIO   if the PIC is in the kernel
560	 -EFAULT  if the pointer is invalid
561	========= ===================================
562
563Note 'irq' is an interrupt vector, not an interrupt pin or line. This
564ioctl is useful if the in-kernel PIC is not used.
565
566PPC:
567^^^^
568
569Queues an external interrupt to be injected. This ioctl is overleaded
570with 3 different irq values:
571
572a) KVM_INTERRUPT_SET
573
574   This injects an edge type external interrupt into the guest once it's ready
575   to receive interrupts. When injected, the interrupt is done.
576
577b) KVM_INTERRUPT_UNSET
578
579   This unsets any pending interrupt.
580
581   Only available with KVM_CAP_PPC_UNSET_IRQ.
582
583c) KVM_INTERRUPT_SET_LEVEL
584
585   This injects a level type external interrupt into the guest context. The
586   interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
587   is triggered.
588
589   Only available with KVM_CAP_PPC_IRQ_LEVEL.
590
591Note that any value for 'irq' other than the ones stated above is invalid
592and incurs unexpected behavior.
593
594This is an asynchronous vcpu ioctl and can be invoked from any thread.
595
596MIPS:
597^^^^^
598
599Queues an external interrupt to be injected into the virtual CPU. A negative
600interrupt number dequeues the interrupt.
601
602This is an asynchronous vcpu ioctl and can be invoked from any thread.
603
604RISC-V:
605^^^^^^^
606
607Queues an external interrupt to be injected into the virutal CPU. This ioctl
608is overloaded with 2 different irq values:
609
610a) KVM_INTERRUPT_SET
611
612   This sets external interrupt for a virtual CPU and it will receive
613   once it is ready.
614
615b) KVM_INTERRUPT_UNSET
616
617   This clears pending external interrupt for a virtual CPU.
618
619This is an asynchronous vcpu ioctl and can be invoked from any thread.
620
621
6224.17 KVM_DEBUG_GUEST
623--------------------
624
625:Capability: basic
626:Architectures: none
627:Type: vcpu ioctl
628:Parameters: none)
629:Returns: -1 on error
630
631Support for this has been removed.  Use KVM_SET_GUEST_DEBUG instead.
632
633
6344.18 KVM_GET_MSRS
635-----------------
636
637:Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
638:Architectures: x86
639:Type: system ioctl, vcpu ioctl
640:Parameters: struct kvm_msrs (in/out)
641:Returns: number of msrs successfully returned;
642          -1 on error
643
644When used as a system ioctl:
645Reads the values of MSR-based features that are available for the VM.  This
646is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
647The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
648in a system ioctl.
649
650When used as a vcpu ioctl:
651Reads model-specific registers from the vcpu.  Supported msr indices can
652be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
653
654::
655
656  struct kvm_msrs {
657	__u32 nmsrs; /* number of msrs in entries */
658	__u32 pad;
659
660	struct kvm_msr_entry entries[0];
661  };
662
663  struct kvm_msr_entry {
664	__u32 index;
665	__u32 reserved;
666	__u64 data;
667  };
668
669Application code should set the 'nmsrs' member (which indicates the
670size of the entries array) and the 'index' member of each array entry.
671kvm will fill in the 'data' member.
672
673
6744.19 KVM_SET_MSRS
675-----------------
676
677:Capability: basic
678:Architectures: x86
679:Type: vcpu ioctl
680:Parameters: struct kvm_msrs (in)
681:Returns: number of msrs successfully set (see below), -1 on error
682
683Writes model-specific registers to the vcpu.  See KVM_GET_MSRS for the
684data structures.
685
686Application code should set the 'nmsrs' member (which indicates the
687size of the entries array), and the 'index' and 'data' members of each
688array entry.
689
690It tries to set the MSRs in array entries[] one by one. If setting an MSR
691fails, e.g., due to setting reserved bits, the MSR isn't supported/emulated
692by KVM, etc..., it stops processing the MSR list and returns the number of
693MSRs that have been set successfully.
694
695
6964.20 KVM_SET_CPUID
697------------------
698
699:Capability: basic
700:Architectures: x86
701:Type: vcpu ioctl
702:Parameters: struct kvm_cpuid (in)
703:Returns: 0 on success, -1 on error
704
705Defines the vcpu responses to the cpuid instruction.  Applications
706should use the KVM_SET_CPUID2 ioctl if available.
707
708Caveat emptor:
709  - If this IOCTL fails, KVM gives no guarantees that previous valid CPUID
710    configuration (if there is) is not corrupted. Userspace can get a copy
711    of the resulting CPUID configuration through KVM_GET_CPUID2 in case.
712  - Using KVM_SET_CPUID{,2} after KVM_RUN, i.e. changing the guest vCPU model
713    after running the guest, may cause guest instability.
714  - Using heterogeneous CPUID configurations, modulo APIC IDs, topology, etc...
715    may cause guest instability.
716
717::
718
719  struct kvm_cpuid_entry {
720	__u32 function;
721	__u32 eax;
722	__u32 ebx;
723	__u32 ecx;
724	__u32 edx;
725	__u32 padding;
726  };
727
728  /* for KVM_SET_CPUID */
729  struct kvm_cpuid {
730	__u32 nent;
731	__u32 padding;
732	struct kvm_cpuid_entry entries[0];
733  };
734
735
7364.21 KVM_SET_SIGNAL_MASK
737------------------------
738
739:Capability: basic
740:Architectures: all
741:Type: vcpu ioctl
742:Parameters: struct kvm_signal_mask (in)
743:Returns: 0 on success, -1 on error
744
745Defines which signals are blocked during execution of KVM_RUN.  This
746signal mask temporarily overrides the threads signal mask.  Any
747unblocked signal received (except SIGKILL and SIGSTOP, which retain
748their traditional behaviour) will cause KVM_RUN to return with -EINTR.
749
750Note the signal will only be delivered if not blocked by the original
751signal mask.
752
753::
754
755  /* for KVM_SET_SIGNAL_MASK */
756  struct kvm_signal_mask {
757	__u32 len;
758	__u8  sigset[0];
759  };
760
761
7624.22 KVM_GET_FPU
763----------------
764
765:Capability: basic
766:Architectures: x86
767:Type: vcpu ioctl
768:Parameters: struct kvm_fpu (out)
769:Returns: 0 on success, -1 on error
770
771Reads the floating point state from the vcpu.
772
773::
774
775  /* for KVM_GET_FPU and KVM_SET_FPU */
776  struct kvm_fpu {
777	__u8  fpr[8][16];
778	__u16 fcw;
779	__u16 fsw;
780	__u8  ftwx;  /* in fxsave format */
781	__u8  pad1;
782	__u16 last_opcode;
783	__u64 last_ip;
784	__u64 last_dp;
785	__u8  xmm[16][16];
786	__u32 mxcsr;
787	__u32 pad2;
788  };
789
790
7914.23 KVM_SET_FPU
792----------------
793
794:Capability: basic
795:Architectures: x86
796:Type: vcpu ioctl
797:Parameters: struct kvm_fpu (in)
798:Returns: 0 on success, -1 on error
799
800Writes the floating point state to the vcpu.
801
802::
803
804  /* for KVM_GET_FPU and KVM_SET_FPU */
805  struct kvm_fpu {
806	__u8  fpr[8][16];
807	__u16 fcw;
808	__u16 fsw;
809	__u8  ftwx;  /* in fxsave format */
810	__u8  pad1;
811	__u16 last_opcode;
812	__u64 last_ip;
813	__u64 last_dp;
814	__u8  xmm[16][16];
815	__u32 mxcsr;
816	__u32 pad2;
817  };
818
819
8204.24 KVM_CREATE_IRQCHIP
821-----------------------
822
823:Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
824:Architectures: x86, ARM, arm64, s390
825:Type: vm ioctl
826:Parameters: none
827:Returns: 0 on success, -1 on error
828
829Creates an interrupt controller model in the kernel.
830On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
831future vcpus to have a local APIC.  IRQ routing for GSIs 0-15 is set to both
832PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
833On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of
834KVM_CREATE_DEVICE, which also supports creating a GICv2.  Using
835KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
836On s390, a dummy irq routing table is created.
837
838Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
839before KVM_CREATE_IRQCHIP can be used.
840
841
8424.25 KVM_IRQ_LINE
843-----------------
844
845:Capability: KVM_CAP_IRQCHIP
846:Architectures: x86, arm, arm64
847:Type: vm ioctl
848:Parameters: struct kvm_irq_level
849:Returns: 0 on success, -1 on error
850
851Sets the level of a GSI input to the interrupt controller model in the kernel.
852On some architectures it is required that an interrupt controller model has
853been previously created with KVM_CREATE_IRQCHIP.  Note that edge-triggered
854interrupts require the level to be set to 1 and then back to 0.
855
856On real hardware, interrupt pins can be active-low or active-high.  This
857does not matter for the level field of struct kvm_irq_level: 1 always
858means active (asserted), 0 means inactive (deasserted).
859
860x86 allows the operating system to program the interrupt polarity
861(active-low/active-high) for level-triggered interrupts, and KVM used
862to consider the polarity.  However, due to bitrot in the handling of
863active-low interrupts, the above convention is now valid on x86 too.
864This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED.  Userspace
865should not present interrupts to the guest as active-low unless this
866capability is present (or unless it is not using the in-kernel irqchip,
867of course).
868
869
870ARM/arm64 can signal an interrupt either at the CPU level, or at the
871in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
872use PPIs designated for specific cpus.  The irq field is interpreted
873like this::
874
875  bits:  |  31 ... 28  | 27 ... 24 | 23  ... 16 | 15 ... 0 |
876  field: | vcpu2_index | irq_type  | vcpu_index |  irq_id  |
877
878The irq_type field has the following values:
879
880- irq_type[0]:
881	       out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
882- irq_type[1]:
883	       in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
884               (the vcpu_index field is ignored)
885- irq_type[2]:
886	       in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
887
888(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
889
890In both cases, level is used to assert/deassert the line.
891
892When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is
893identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index
894must be zero.
895
896Note that on arm/arm64, the KVM_CAP_IRQCHIP capability only conditions
897injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always
898be used for a userspace interrupt controller.
899
900::
901
902  struct kvm_irq_level {
903	union {
904		__u32 irq;     /* GSI */
905		__s32 status;  /* not used for KVM_IRQ_LEVEL */
906	};
907	__u32 level;           /* 0 or 1 */
908  };
909
910
9114.26 KVM_GET_IRQCHIP
912--------------------
913
914:Capability: KVM_CAP_IRQCHIP
915:Architectures: x86
916:Type: vm ioctl
917:Parameters: struct kvm_irqchip (in/out)
918:Returns: 0 on success, -1 on error
919
920Reads the state of a kernel interrupt controller created with
921KVM_CREATE_IRQCHIP into a buffer provided by the caller.
922
923::
924
925  struct kvm_irqchip {
926	__u32 chip_id;  /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
927	__u32 pad;
928        union {
929		char dummy[512];  /* reserving space */
930		struct kvm_pic_state pic;
931		struct kvm_ioapic_state ioapic;
932	} chip;
933  };
934
935
9364.27 KVM_SET_IRQCHIP
937--------------------
938
939:Capability: KVM_CAP_IRQCHIP
940:Architectures: x86
941:Type: vm ioctl
942:Parameters: struct kvm_irqchip (in)
943:Returns: 0 on success, -1 on error
944
945Sets the state of a kernel interrupt controller created with
946KVM_CREATE_IRQCHIP from a buffer provided by the caller.
947
948::
949
950  struct kvm_irqchip {
951	__u32 chip_id;  /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
952	__u32 pad;
953        union {
954		char dummy[512];  /* reserving space */
955		struct kvm_pic_state pic;
956		struct kvm_ioapic_state ioapic;
957	} chip;
958  };
959
960
9614.28 KVM_XEN_HVM_CONFIG
962-----------------------
963
964:Capability: KVM_CAP_XEN_HVM
965:Architectures: x86
966:Type: vm ioctl
967:Parameters: struct kvm_xen_hvm_config (in)
968:Returns: 0 on success, -1 on error
969
970Sets the MSR that the Xen HVM guest uses to initialize its hypercall
971page, and provides the starting address and size of the hypercall
972blobs in userspace.  When the guest writes the MSR, kvm copies one
973page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
974memory.
975
976::
977
978  struct kvm_xen_hvm_config {
979	__u32 flags;
980	__u32 msr;
981	__u64 blob_addr_32;
982	__u64 blob_addr_64;
983	__u8 blob_size_32;
984	__u8 blob_size_64;
985	__u8 pad2[30];
986  };
987
988If the KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag is returned from the
989KVM_CAP_XEN_HVM check, it may be set in the flags field of this ioctl.
990This requests KVM to generate the contents of the hypercall page
991automatically; hypercalls will be intercepted and passed to userspace
992through KVM_EXIT_XEN.  In this case, all of the blob size and address
993fields must be zero.
994
995No other flags are currently valid in the struct kvm_xen_hvm_config.
996
9974.29 KVM_GET_CLOCK
998------------------
999
1000:Capability: KVM_CAP_ADJUST_CLOCK
1001:Architectures: x86
1002:Type: vm ioctl
1003:Parameters: struct kvm_clock_data (out)
1004:Returns: 0 on success, -1 on error
1005
1006Gets the current timestamp of kvmclock as seen by the current guest. In
1007conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
1008such as migration.
1009
1010When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
1011set of bits that KVM can return in struct kvm_clock_data's flag member.
1012
1013The following flags are defined:
1014
1015KVM_CLOCK_TSC_STABLE
1016  If set, the returned value is the exact kvmclock
1017  value seen by all VCPUs at the instant when KVM_GET_CLOCK was called.
1018  If clear, the returned value is simply CLOCK_MONOTONIC plus a constant
1019  offset; the offset can be modified with KVM_SET_CLOCK.  KVM will try
1020  to make all VCPUs follow this clock, but the exact value read by each
1021  VCPU could differ, because the host TSC is not stable.
1022
1023KVM_CLOCK_REALTIME
1024  If set, the `realtime` field in the kvm_clock_data
1025  structure is populated with the value of the host's real time
1026  clocksource at the instant when KVM_GET_CLOCK was called. If clear,
1027  the `realtime` field does not contain a value.
1028
1029KVM_CLOCK_HOST_TSC
1030  If set, the `host_tsc` field in the kvm_clock_data
1031  structure is populated with the value of the host's timestamp counter (TSC)
1032  at the instant when KVM_GET_CLOCK was called. If clear, the `host_tsc` field
1033  does not contain a value.
1034
1035::
1036
1037  struct kvm_clock_data {
1038	__u64 clock;  /* kvmclock current value */
1039	__u32 flags;
1040	__u32 pad0;
1041	__u64 realtime;
1042	__u64 host_tsc;
1043	__u32 pad[4];
1044  };
1045
1046
10474.30 KVM_SET_CLOCK
1048------------------
1049
1050:Capability: KVM_CAP_ADJUST_CLOCK
1051:Architectures: x86
1052:Type: vm ioctl
1053:Parameters: struct kvm_clock_data (in)
1054:Returns: 0 on success, -1 on error
1055
1056Sets the current timestamp of kvmclock to the value specified in its parameter.
1057In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
1058such as migration.
1059
1060The following flags can be passed:
1061
1062KVM_CLOCK_REALTIME
1063  If set, KVM will compare the value of the `realtime` field
1064  with the value of the host's real time clocksource at the instant when
1065  KVM_SET_CLOCK was called. The difference in elapsed time is added to the final
1066  kvmclock value that will be provided to guests.
1067
1068Other flags returned by ``KVM_GET_CLOCK`` are accepted but ignored.
1069
1070::
1071
1072  struct kvm_clock_data {
1073	__u64 clock;  /* kvmclock current value */
1074	__u32 flags;
1075	__u32 pad0;
1076	__u64 realtime;
1077	__u64 host_tsc;
1078	__u32 pad[4];
1079  };
1080
1081
10824.31 KVM_GET_VCPU_EVENTS
1083------------------------
1084
1085:Capability: KVM_CAP_VCPU_EVENTS
1086:Extended by: KVM_CAP_INTR_SHADOW
1087:Architectures: x86, arm, arm64
1088:Type: vcpu ioctl
1089:Parameters: struct kvm_vcpu_event (out)
1090:Returns: 0 on success, -1 on error
1091
1092X86:
1093^^^^
1094
1095Gets currently pending exceptions, interrupts, and NMIs as well as related
1096states of the vcpu.
1097
1098::
1099
1100  struct kvm_vcpu_events {
1101	struct {
1102		__u8 injected;
1103		__u8 nr;
1104		__u8 has_error_code;
1105		__u8 pending;
1106		__u32 error_code;
1107	} exception;
1108	struct {
1109		__u8 injected;
1110		__u8 nr;
1111		__u8 soft;
1112		__u8 shadow;
1113	} interrupt;
1114	struct {
1115		__u8 injected;
1116		__u8 pending;
1117		__u8 masked;
1118		__u8 pad;
1119	} nmi;
1120	__u32 sipi_vector;
1121	__u32 flags;
1122	struct {
1123		__u8 smm;
1124		__u8 pending;
1125		__u8 smm_inside_nmi;
1126		__u8 latched_init;
1127	} smi;
1128	__u8 reserved[27];
1129	__u8 exception_has_payload;
1130	__u64 exception_payload;
1131  };
1132
1133The following bits are defined in the flags field:
1134
1135- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that
1136  interrupt.shadow contains a valid state.
1137
1138- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a
1139  valid state.
1140
1141- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the
1142  exception_has_payload, exception_payload, and exception.pending
1143  fields contain a valid state. This bit will be set whenever
1144  KVM_CAP_EXCEPTION_PAYLOAD is enabled.
1145
1146ARM/ARM64:
1147^^^^^^^^^^
1148
1149If the guest accesses a device that is being emulated by the host kernel in
1150such a way that a real device would generate a physical SError, KVM may make
1151a virtual SError pending for that VCPU. This system error interrupt remains
1152pending until the guest takes the exception by unmasking PSTATE.A.
1153
1154Running the VCPU may cause it to take a pending SError, or make an access that
1155causes an SError to become pending. The event's description is only valid while
1156the VPCU is not running.
1157
1158This API provides a way to read and write the pending 'event' state that is not
1159visible to the guest. To save, restore or migrate a VCPU the struct representing
1160the state can be read then written using this GET/SET API, along with the other
1161guest-visible registers. It is not possible to 'cancel' an SError that has been
1162made pending.
1163
1164A device being emulated in user-space may also wish to generate an SError. To do
1165this the events structure can be populated by user-space. The current state
1166should be read first, to ensure no existing SError is pending. If an existing
1167SError is pending, the architecture's 'Multiple SError interrupts' rules should
1168be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
1169Serviceability (RAS) Specification").
1170
1171SError exceptions always have an ESR value. Some CPUs have the ability to
1172specify what the virtual SError's ESR value should be. These systems will
1173advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will
1174always have a non-zero value when read, and the agent making an SError pending
1175should specify the ISS field in the lower 24 bits of exception.serror_esr. If
1176the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events
1177with exception.has_esr as zero, KVM will choose an ESR.
1178
1179Specifying exception.has_esr on a system that does not support it will return
1180-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
1181will return -EINVAL.
1182
1183It is not possible to read back a pending external abort (injected via
1184KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered
1185directly to the virtual CPU).
1186
1187::
1188
1189  struct kvm_vcpu_events {
1190	struct {
1191		__u8 serror_pending;
1192		__u8 serror_has_esr;
1193		__u8 ext_dabt_pending;
1194		/* Align it to 8 bytes */
1195		__u8 pad[5];
1196		__u64 serror_esr;
1197	} exception;
1198	__u32 reserved[12];
1199  };
1200
12014.32 KVM_SET_VCPU_EVENTS
1202------------------------
1203
1204:Capability: KVM_CAP_VCPU_EVENTS
1205:Extended by: KVM_CAP_INTR_SHADOW
1206:Architectures: x86, arm, arm64
1207:Type: vcpu ioctl
1208:Parameters: struct kvm_vcpu_event (in)
1209:Returns: 0 on success, -1 on error
1210
1211X86:
1212^^^^
1213
1214Set pending exceptions, interrupts, and NMIs as well as related states of the
1215vcpu.
1216
1217See KVM_GET_VCPU_EVENTS for the data structure.
1218
1219Fields that may be modified asynchronously by running VCPUs can be excluded
1220from the update. These fields are nmi.pending, sipi_vector, smi.smm,
1221smi.pending. Keep the corresponding bits in the flags field cleared to
1222suppress overwriting the current in-kernel state. The bits are:
1223
1224===============================  ==================================
1225KVM_VCPUEVENT_VALID_NMI_PENDING  transfer nmi.pending to the kernel
1226KVM_VCPUEVENT_VALID_SIPI_VECTOR  transfer sipi_vector
1227KVM_VCPUEVENT_VALID_SMM          transfer the smi sub-struct.
1228===============================  ==================================
1229
1230If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
1231the flags field to signal that interrupt.shadow contains a valid state and
1232shall be written into the VCPU.
1233
1234KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
1235
1236If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD
1237can be set in the flags field to signal that the
1238exception_has_payload, exception_payload, and exception.pending fields
1239contain a valid state and shall be written into the VCPU.
1240
1241ARM/ARM64:
1242^^^^^^^^^^
1243
1244User space may need to inject several types of events to the guest.
1245
1246Set the pending SError exception state for this VCPU. It is not possible to
1247'cancel' an Serror that has been made pending.
1248
1249If the guest performed an access to I/O memory which could not be handled by
1250userspace, for example because of missing instruction syndrome decode
1251information or because there is no device mapped at the accessed IPA, then
1252userspace can ask the kernel to inject an external abort using the address
1253from the exiting fault on the VCPU. It is a programming error to set
1254ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or
1255KVM_EXIT_ARM_NISV. This feature is only available if the system supports
1256KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in
1257how userspace reports accesses for the above cases to guests, across different
1258userspace implementations. Nevertheless, userspace can still emulate all Arm
1259exceptions by manipulating individual registers using the KVM_SET_ONE_REG API.
1260
1261See KVM_GET_VCPU_EVENTS for the data structure.
1262
1263
12644.33 KVM_GET_DEBUGREGS
1265----------------------
1266
1267:Capability: KVM_CAP_DEBUGREGS
1268:Architectures: x86
1269:Type: vm ioctl
1270:Parameters: struct kvm_debugregs (out)
1271:Returns: 0 on success, -1 on error
1272
1273Reads debug registers from the vcpu.
1274
1275::
1276
1277  struct kvm_debugregs {
1278	__u64 db[4];
1279	__u64 dr6;
1280	__u64 dr7;
1281	__u64 flags;
1282	__u64 reserved[9];
1283  };
1284
1285
12864.34 KVM_SET_DEBUGREGS
1287----------------------
1288
1289:Capability: KVM_CAP_DEBUGREGS
1290:Architectures: x86
1291:Type: vm ioctl
1292:Parameters: struct kvm_debugregs (in)
1293:Returns: 0 on success, -1 on error
1294
1295Writes debug registers into the vcpu.
1296
1297See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
1298yet and must be cleared on entry.
1299
1300
13014.35 KVM_SET_USER_MEMORY_REGION
1302-------------------------------
1303
1304:Capability: KVM_CAP_USER_MEMORY
1305:Architectures: all
1306:Type: vm ioctl
1307:Parameters: struct kvm_userspace_memory_region (in)
1308:Returns: 0 on success, -1 on error
1309
1310::
1311
1312  struct kvm_userspace_memory_region {
1313	__u32 slot;
1314	__u32 flags;
1315	__u64 guest_phys_addr;
1316	__u64 memory_size; /* bytes */
1317	__u64 userspace_addr; /* start of the userspace allocated memory */
1318  };
1319
1320  /* for kvm_memory_region::flags */
1321  #define KVM_MEM_LOG_DIRTY_PAGES	(1UL << 0)
1322  #define KVM_MEM_READONLY	(1UL << 1)
1323
1324This ioctl allows the user to create, modify or delete a guest physical
1325memory slot.  Bits 0-15 of "slot" specify the slot id and this value
1326should be less than the maximum number of user memory slots supported per
1327VM.  The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS.
1328Slots may not overlap in guest physical address space.
1329
1330If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1331specifies the address space which is being modified.  They must be
1332less than the value that KVM_CHECK_EXTENSION returns for the
1333KVM_CAP_MULTI_ADDRESS_SPACE capability.  Slots in separate address spaces
1334are unrelated; the restriction on overlapping slots only applies within
1335each address space.
1336
1337Deleting a slot is done by passing zero for memory_size.  When changing
1338an existing slot, it may be moved in the guest physical memory space,
1339or its flags may be modified, but it may not be resized.
1340
1341Memory for the region is taken starting at the address denoted by the
1342field userspace_addr, which must point at user addressable memory for
1343the entire memory slot size.  Any object may back this memory, including
1344anonymous memory, ordinary files, and hugetlbfs.
1345
1346On architectures that support a form of address tagging, userspace_addr must
1347be an untagged address.
1348
1349It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1350be identical.  This allows large pages in the guest to be backed by large
1351pages in the host.
1352
1353The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1354KVM_MEM_READONLY.  The former can be set to instruct KVM to keep track of
1355writes to memory within the slot.  See KVM_GET_DIRTY_LOG ioctl to know how to
1356use it.  The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1357to make a new slot read-only.  In this case, writes to this memory will be
1358posted to userspace as KVM_EXIT_MMIO exits.
1359
1360When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1361the memory region are automatically reflected into the guest.  For example, an
1362mmap() that affects the region will be made visible immediately.  Another
1363example is madvise(MADV_DROP).
1364
1365It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
1366The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
1367allocation and is deprecated.
1368
1369
13704.36 KVM_SET_TSS_ADDR
1371---------------------
1372
1373:Capability: KVM_CAP_SET_TSS_ADDR
1374:Architectures: x86
1375:Type: vm ioctl
1376:Parameters: unsigned long tss_address (in)
1377:Returns: 0 on success, -1 on error
1378
1379This ioctl defines the physical address of a three-page region in the guest
1380physical address space.  The region must be within the first 4GB of the
1381guest physical address space and must not conflict with any memory slot
1382or any mmio address.  The guest may malfunction if it accesses this memory
1383region.
1384
1385This ioctl is required on Intel-based hosts.  This is needed on Intel hardware
1386because of a quirk in the virtualization implementation (see the internals
1387documentation when it pops into existence).
1388
1389
13904.37 KVM_ENABLE_CAP
1391-------------------
1392
1393:Capability: KVM_CAP_ENABLE_CAP
1394:Architectures: mips, ppc, s390
1395:Type: vcpu ioctl
1396:Parameters: struct kvm_enable_cap (in)
1397:Returns: 0 on success; -1 on error
1398
1399:Capability: KVM_CAP_ENABLE_CAP_VM
1400:Architectures: all
1401:Type: vm ioctl
1402:Parameters: struct kvm_enable_cap (in)
1403:Returns: 0 on success; -1 on error
1404
1405.. note::
1406
1407   Not all extensions are enabled by default. Using this ioctl the application
1408   can enable an extension, making it available to the guest.
1409
1410On systems that do not support this ioctl, it always fails. On systems that
1411do support it, it only works for extensions that are supported for enablement.
1412
1413To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1414be used.
1415
1416::
1417
1418  struct kvm_enable_cap {
1419       /* in */
1420       __u32 cap;
1421
1422The capability that is supposed to get enabled.
1423
1424::
1425
1426       __u32 flags;
1427
1428A bitfield indicating future enhancements. Has to be 0 for now.
1429
1430::
1431
1432       __u64 args[4];
1433
1434Arguments for enabling a feature. If a feature needs initial values to
1435function properly, this is the place to put them.
1436
1437::
1438
1439       __u8  pad[64];
1440  };
1441
1442The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1443for vm-wide capabilities.
1444
14454.38 KVM_GET_MP_STATE
1446---------------------
1447
1448:Capability: KVM_CAP_MP_STATE
1449:Architectures: x86, s390, arm, arm64, riscv
1450:Type: vcpu ioctl
1451:Parameters: struct kvm_mp_state (out)
1452:Returns: 0 on success; -1 on error
1453
1454::
1455
1456  struct kvm_mp_state {
1457	__u32 mp_state;
1458  };
1459
1460Returns the vcpu's current "multiprocessing state" (though also valid on
1461uniprocessor guests).
1462
1463Possible values are:
1464
1465   ==========================    ===============================================
1466   KVM_MP_STATE_RUNNABLE         the vcpu is currently running
1467                                 [x86,arm/arm64,riscv]
1468   KVM_MP_STATE_UNINITIALIZED    the vcpu is an application processor (AP)
1469                                 which has not yet received an INIT signal [x86]
1470   KVM_MP_STATE_INIT_RECEIVED    the vcpu has received an INIT signal, and is
1471                                 now ready for a SIPI [x86]
1472   KVM_MP_STATE_HALTED           the vcpu has executed a HLT instruction and
1473                                 is waiting for an interrupt [x86]
1474   KVM_MP_STATE_SIPI_RECEIVED    the vcpu has just received a SIPI (vector
1475                                 accessible via KVM_GET_VCPU_EVENTS) [x86]
1476   KVM_MP_STATE_STOPPED          the vcpu is stopped [s390,arm/arm64,riscv]
1477   KVM_MP_STATE_CHECK_STOP       the vcpu is in a special error state [s390]
1478   KVM_MP_STATE_OPERATING        the vcpu is operating (running or halted)
1479                                 [s390]
1480   KVM_MP_STATE_LOAD             the vcpu is in a special load/startup state
1481                                 [s390]
1482   ==========================    ===============================================
1483
1484On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
1485in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1486these architectures.
1487
1488For arm/arm64/riscv:
1489^^^^^^^^^^^^^^^^^^^^
1490
1491The only states that are valid are KVM_MP_STATE_STOPPED and
1492KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
1493
14944.39 KVM_SET_MP_STATE
1495---------------------
1496
1497:Capability: KVM_CAP_MP_STATE
1498:Architectures: x86, s390, arm, arm64, riscv
1499:Type: vcpu ioctl
1500:Parameters: struct kvm_mp_state (in)
1501:Returns: 0 on success; -1 on error
1502
1503Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1504arguments.
1505
1506On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
1507in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1508these architectures.
1509
1510For arm/arm64/riscv:
1511^^^^^^^^^^^^^^^^^^^^
1512
1513The only states that are valid are KVM_MP_STATE_STOPPED and
1514KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
1515
15164.40 KVM_SET_IDENTITY_MAP_ADDR
1517------------------------------
1518
1519:Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1520:Architectures: x86
1521:Type: vm ioctl
1522:Parameters: unsigned long identity (in)
1523:Returns: 0 on success, -1 on error
1524
1525This ioctl defines the physical address of a one-page region in the guest
1526physical address space.  The region must be within the first 4GB of the
1527guest physical address space and must not conflict with any memory slot
1528or any mmio address.  The guest may malfunction if it accesses this memory
1529region.
1530
1531Setting the address to 0 will result in resetting the address to its default
1532(0xfffbc000).
1533
1534This ioctl is required on Intel-based hosts.  This is needed on Intel hardware
1535because of a quirk in the virtualization implementation (see the internals
1536documentation when it pops into existence).
1537
1538Fails if any VCPU has already been created.
1539
15404.41 KVM_SET_BOOT_CPU_ID
1541------------------------
1542
1543:Capability: KVM_CAP_SET_BOOT_CPU_ID
1544:Architectures: x86
1545:Type: vm ioctl
1546:Parameters: unsigned long vcpu_id
1547:Returns: 0 on success, -1 on error
1548
1549Define which vcpu is the Bootstrap Processor (BSP).  Values are the same
1550as the vcpu id in KVM_CREATE_VCPU.  If this ioctl is not called, the default
1551is vcpu 0. This ioctl has to be called before vcpu creation,
1552otherwise it will return EBUSY error.
1553
1554
15554.42 KVM_GET_XSAVE
1556------------------
1557
1558:Capability: KVM_CAP_XSAVE
1559:Architectures: x86
1560:Type: vcpu ioctl
1561:Parameters: struct kvm_xsave (out)
1562:Returns: 0 on success, -1 on error
1563
1564
1565::
1566
1567  struct kvm_xsave {
1568	__u32 region[1024];
1569  };
1570
1571This ioctl would copy current vcpu's xsave struct to the userspace.
1572
1573
15744.43 KVM_SET_XSAVE
1575------------------
1576
1577:Capability: KVM_CAP_XSAVE
1578:Architectures: x86
1579:Type: vcpu ioctl
1580:Parameters: struct kvm_xsave (in)
1581:Returns: 0 on success, -1 on error
1582
1583::
1584
1585
1586  struct kvm_xsave {
1587	__u32 region[1024];
1588  };
1589
1590This ioctl would copy userspace's xsave struct to the kernel.
1591
1592
15934.44 KVM_GET_XCRS
1594-----------------
1595
1596:Capability: KVM_CAP_XCRS
1597:Architectures: x86
1598:Type: vcpu ioctl
1599:Parameters: struct kvm_xcrs (out)
1600:Returns: 0 on success, -1 on error
1601
1602::
1603
1604  struct kvm_xcr {
1605	__u32 xcr;
1606	__u32 reserved;
1607	__u64 value;
1608  };
1609
1610  struct kvm_xcrs {
1611	__u32 nr_xcrs;
1612	__u32 flags;
1613	struct kvm_xcr xcrs[KVM_MAX_XCRS];
1614	__u64 padding[16];
1615  };
1616
1617This ioctl would copy current vcpu's xcrs to the userspace.
1618
1619
16204.45 KVM_SET_XCRS
1621-----------------
1622
1623:Capability: KVM_CAP_XCRS
1624:Architectures: x86
1625:Type: vcpu ioctl
1626:Parameters: struct kvm_xcrs (in)
1627:Returns: 0 on success, -1 on error
1628
1629::
1630
1631  struct kvm_xcr {
1632	__u32 xcr;
1633	__u32 reserved;
1634	__u64 value;
1635  };
1636
1637  struct kvm_xcrs {
1638	__u32 nr_xcrs;
1639	__u32 flags;
1640	struct kvm_xcr xcrs[KVM_MAX_XCRS];
1641	__u64 padding[16];
1642  };
1643
1644This ioctl would set vcpu's xcr to the value userspace specified.
1645
1646
16474.46 KVM_GET_SUPPORTED_CPUID
1648----------------------------
1649
1650:Capability: KVM_CAP_EXT_CPUID
1651:Architectures: x86
1652:Type: system ioctl
1653:Parameters: struct kvm_cpuid2 (in/out)
1654:Returns: 0 on success, -1 on error
1655
1656::
1657
1658  struct kvm_cpuid2 {
1659	__u32 nent;
1660	__u32 padding;
1661	struct kvm_cpuid_entry2 entries[0];
1662  };
1663
1664  #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		BIT(0)
1665  #define KVM_CPUID_FLAG_STATEFUL_FUNC		BIT(1) /* deprecated */
1666  #define KVM_CPUID_FLAG_STATE_READ_NEXT		BIT(2) /* deprecated */
1667
1668  struct kvm_cpuid_entry2 {
1669	__u32 function;
1670	__u32 index;
1671	__u32 flags;
1672	__u32 eax;
1673	__u32 ebx;
1674	__u32 ecx;
1675	__u32 edx;
1676	__u32 padding[3];
1677  };
1678
1679This ioctl returns x86 cpuid features which are supported by both the
1680hardware and kvm in its default configuration.  Userspace can use the
1681information returned by this ioctl to construct cpuid information (for
1682KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1683userspace capabilities, and with user requirements (for example, the
1684user may wish to constrain cpuid to emulate older hardware, or for
1685feature consistency across a cluster).
1686
1687Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1688expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1689its default configuration. If userspace enables such capabilities, it
1690is responsible for modifying the results of this ioctl appropriately.
1691
1692Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1693with the 'nent' field indicating the number of entries in the variable-size
1694array 'entries'.  If the number of entries is too low to describe the cpu
1695capabilities, an error (E2BIG) is returned.  If the number is too high,
1696the 'nent' field is adjusted and an error (ENOMEM) is returned.  If the
1697number is just right, the 'nent' field is adjusted to the number of valid
1698entries in the 'entries' array, which is then filled.
1699
1700The entries returned are the host cpuid as returned by the cpuid instruction,
1701with unknown or unsupported features masked out.  Some features (for example,
1702x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1703emulate them efficiently. The fields in each entry are defined as follows:
1704
1705  function:
1706         the eax value used to obtain the entry
1707
1708  index:
1709         the ecx value used to obtain the entry (for entries that are
1710         affected by ecx)
1711
1712  flags:
1713     an OR of zero or more of the following:
1714
1715        KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1716           if the index field is valid
1717
1718   eax, ebx, ecx, edx:
1719         the values returned by the cpuid instruction for
1720         this function/index combination
1721
1722The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1723as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1724support.  Instead it is reported via::
1725
1726  ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1727
1728if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1729feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1730
1731
17324.47 KVM_PPC_GET_PVINFO
1733-----------------------
1734
1735:Capability: KVM_CAP_PPC_GET_PVINFO
1736:Architectures: ppc
1737:Type: vm ioctl
1738:Parameters: struct kvm_ppc_pvinfo (out)
1739:Returns: 0 on success, !0 on error
1740
1741::
1742
1743  struct kvm_ppc_pvinfo {
1744	__u32 flags;
1745	__u32 hcall[4];
1746	__u8  pad[108];
1747  };
1748
1749This ioctl fetches PV specific information that need to be passed to the guest
1750using the device tree or other means from vm context.
1751
1752The hcall array defines 4 instructions that make up a hypercall.
1753
1754If any additional field gets added to this structure later on, a bit for that
1755additional piece of information will be set in the flags bitmap.
1756
1757The flags bitmap is defined as::
1758
1759   /* the host supports the ePAPR idle hcall
1760   #define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (1<<0)
1761
17624.52 KVM_SET_GSI_ROUTING
1763------------------------
1764
1765:Capability: KVM_CAP_IRQ_ROUTING
1766:Architectures: x86 s390 arm arm64
1767:Type: vm ioctl
1768:Parameters: struct kvm_irq_routing (in)
1769:Returns: 0 on success, -1 on error
1770
1771Sets the GSI routing table entries, overwriting any previously set entries.
1772
1773On arm/arm64, GSI routing has the following limitation:
1774
1775- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1776
1777::
1778
1779  struct kvm_irq_routing {
1780	__u32 nr;
1781	__u32 flags;
1782	struct kvm_irq_routing_entry entries[0];
1783  };
1784
1785No flags are specified so far, the corresponding field must be set to zero.
1786
1787::
1788
1789  struct kvm_irq_routing_entry {
1790	__u32 gsi;
1791	__u32 type;
1792	__u32 flags;
1793	__u32 pad;
1794	union {
1795		struct kvm_irq_routing_irqchip irqchip;
1796		struct kvm_irq_routing_msi msi;
1797		struct kvm_irq_routing_s390_adapter adapter;
1798		struct kvm_irq_routing_hv_sint hv_sint;
1799		__u32 pad[8];
1800	} u;
1801  };
1802
1803  /* gsi routing entry types */
1804  #define KVM_IRQ_ROUTING_IRQCHIP 1
1805  #define KVM_IRQ_ROUTING_MSI 2
1806  #define KVM_IRQ_ROUTING_S390_ADAPTER 3
1807  #define KVM_IRQ_ROUTING_HV_SINT 4
1808
1809flags:
1810
1811- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1812  type, specifies that the devid field contains a valid value.  The per-VM
1813  KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1814  the device ID.  If this capability is not available, userspace should
1815  never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
1816- zero otherwise
1817
1818::
1819
1820  struct kvm_irq_routing_irqchip {
1821	__u32 irqchip;
1822	__u32 pin;
1823  };
1824
1825  struct kvm_irq_routing_msi {
1826	__u32 address_lo;
1827	__u32 address_hi;
1828	__u32 data;
1829	union {
1830		__u32 pad;
1831		__u32 devid;
1832	};
1833  };
1834
1835If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1836for the device that wrote the MSI message.  For PCI, this is usually a
1837BFD identifier in the lower 16 bits.
1838
1839On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1840feature of KVM_CAP_X2APIC_API capability is enabled.  If it is enabled,
1841address_hi bits 31-8 provide bits 31-8 of the destination id.  Bits 7-0 of
1842address_hi must be zero.
1843
1844::
1845
1846  struct kvm_irq_routing_s390_adapter {
1847	__u64 ind_addr;
1848	__u64 summary_addr;
1849	__u64 ind_offset;
1850	__u32 summary_offset;
1851	__u32 adapter_id;
1852  };
1853
1854  struct kvm_irq_routing_hv_sint {
1855	__u32 vcpu;
1856	__u32 sint;
1857  };
1858
1859
18604.55 KVM_SET_TSC_KHZ
1861--------------------
1862
1863:Capability: KVM_CAP_TSC_CONTROL
1864:Architectures: x86
1865:Type: vcpu ioctl
1866:Parameters: virtual tsc_khz
1867:Returns: 0 on success, -1 on error
1868
1869Specifies the tsc frequency for the virtual machine. The unit of the
1870frequency is KHz.
1871
1872
18734.56 KVM_GET_TSC_KHZ
1874--------------------
1875
1876:Capability: KVM_CAP_GET_TSC_KHZ
1877:Architectures: x86
1878:Type: vcpu ioctl
1879:Parameters: none
1880:Returns: virtual tsc-khz on success, negative value on error
1881
1882Returns the tsc frequency of the guest. The unit of the return value is
1883KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1884error.
1885
1886
18874.57 KVM_GET_LAPIC
1888------------------
1889
1890:Capability: KVM_CAP_IRQCHIP
1891:Architectures: x86
1892:Type: vcpu ioctl
1893:Parameters: struct kvm_lapic_state (out)
1894:Returns: 0 on success, -1 on error
1895
1896::
1897
1898  #define KVM_APIC_REG_SIZE 0x400
1899  struct kvm_lapic_state {
1900	char regs[KVM_APIC_REG_SIZE];
1901  };
1902
1903Reads the Local APIC registers and copies them into the input argument.  The
1904data format and layout are the same as documented in the architecture manual.
1905
1906If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
1907enabled, then the format of APIC_ID register depends on the APIC mode
1908(reported by MSR_IA32_APICBASE) of its VCPU.  x2APIC stores APIC ID in
1909the APIC_ID register (bytes 32-35).  xAPIC only allows an 8-bit APIC ID
1910which is stored in bits 31-24 of the APIC register, or equivalently in
1911byte 35 of struct kvm_lapic_state's regs field.  KVM_GET_LAPIC must then
1912be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
1913
1914If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
1915always uses xAPIC format.
1916
1917
19184.58 KVM_SET_LAPIC
1919------------------
1920
1921:Capability: KVM_CAP_IRQCHIP
1922:Architectures: x86
1923:Type: vcpu ioctl
1924:Parameters: struct kvm_lapic_state (in)
1925:Returns: 0 on success, -1 on error
1926
1927::
1928
1929  #define KVM_APIC_REG_SIZE 0x400
1930  struct kvm_lapic_state {
1931	char regs[KVM_APIC_REG_SIZE];
1932  };
1933
1934Copies the input argument into the Local APIC registers.  The data format
1935and layout are the same as documented in the architecture manual.
1936
1937The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
1938regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
1939See the note in KVM_GET_LAPIC.
1940
1941
19424.59 KVM_IOEVENTFD
1943------------------
1944
1945:Capability: KVM_CAP_IOEVENTFD
1946:Architectures: all
1947:Type: vm ioctl
1948:Parameters: struct kvm_ioeventfd (in)
1949:Returns: 0 on success, !0 on error
1950
1951This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1952within the guest.  A guest write in the registered address will signal the
1953provided event instead of triggering an exit.
1954
1955::
1956
1957  struct kvm_ioeventfd {
1958	__u64 datamatch;
1959	__u64 addr;        /* legal pio/mmio address */
1960	__u32 len;         /* 0, 1, 2, 4, or 8 bytes    */
1961	__s32 fd;
1962	__u32 flags;
1963	__u8  pad[36];
1964  };
1965
1966For the special case of virtio-ccw devices on s390, the ioevent is matched
1967to a subchannel/virtqueue tuple instead.
1968
1969The following flags are defined::
1970
1971  #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1972  #define KVM_IOEVENTFD_FLAG_PIO       (1 << kvm_ioeventfd_flag_nr_pio)
1973  #define KVM_IOEVENTFD_FLAG_DEASSIGN  (1 << kvm_ioeventfd_flag_nr_deassign)
1974  #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
1975	(1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
1976
1977If datamatch flag is set, the event will be signaled only if the written value
1978to the registered address is equal to datamatch in struct kvm_ioeventfd.
1979
1980For virtio-ccw devices, addr contains the subchannel id and datamatch the
1981virtqueue index.
1982
1983With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
1984the kernel will ignore the length of guest write and may get a faster vmexit.
1985The speedup may only apply to specific architectures, but the ioeventfd will
1986work anyway.
1987
19884.60 KVM_DIRTY_TLB
1989------------------
1990
1991:Capability: KVM_CAP_SW_TLB
1992:Architectures: ppc
1993:Type: vcpu ioctl
1994:Parameters: struct kvm_dirty_tlb (in)
1995:Returns: 0 on success, -1 on error
1996
1997::
1998
1999  struct kvm_dirty_tlb {
2000	__u64 bitmap;
2001	__u32 num_dirty;
2002  };
2003
2004This must be called whenever userspace has changed an entry in the shared
2005TLB, prior to calling KVM_RUN on the associated vcpu.
2006
2007The "bitmap" field is the userspace address of an array.  This array
2008consists of a number of bits, equal to the total number of TLB entries as
2009determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
2010nearest multiple of 64.
2011
2012Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
2013array.
2014
2015The array is little-endian: the bit 0 is the least significant bit of the
2016first byte, bit 8 is the least significant bit of the second byte, etc.
2017This avoids any complications with differing word sizes.
2018
2019The "num_dirty" field is a performance hint for KVM to determine whether it
2020should skip processing the bitmap and just invalidate everything.  It must
2021be set to the number of set bits in the bitmap.
2022
2023
20244.62 KVM_CREATE_SPAPR_TCE
2025-------------------------
2026
2027:Capability: KVM_CAP_SPAPR_TCE
2028:Architectures: powerpc
2029:Type: vm ioctl
2030:Parameters: struct kvm_create_spapr_tce (in)
2031:Returns: file descriptor for manipulating the created TCE table
2032
2033This creates a virtual TCE (translation control entry) table, which
2034is an IOMMU for PAPR-style virtual I/O.  It is used to translate
2035logical addresses used in virtual I/O into guest physical addresses,
2036and provides a scatter/gather capability for PAPR virtual I/O.
2037
2038::
2039
2040  /* for KVM_CAP_SPAPR_TCE */
2041  struct kvm_create_spapr_tce {
2042	__u64 liobn;
2043	__u32 window_size;
2044  };
2045
2046The liobn field gives the logical IO bus number for which to create a
2047TCE table.  The window_size field specifies the size of the DMA window
2048which this TCE table will translate - the table will contain one 64
2049bit TCE entry for every 4kiB of the DMA window.
2050
2051When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
2052table has been created using this ioctl(), the kernel will handle it
2053in real mode, updating the TCE table.  H_PUT_TCE calls for other
2054liobns will cause a vm exit and must be handled by userspace.
2055
2056The return value is a file descriptor which can be passed to mmap(2)
2057to map the created TCE table into userspace.  This lets userspace read
2058the entries written by kernel-handled H_PUT_TCE calls, and also lets
2059userspace update the TCE table directly which is useful in some
2060circumstances.
2061
2062
20634.63 KVM_ALLOCATE_RMA
2064---------------------
2065
2066:Capability: KVM_CAP_PPC_RMA
2067:Architectures: powerpc
2068:Type: vm ioctl
2069:Parameters: struct kvm_allocate_rma (out)
2070:Returns: file descriptor for mapping the allocated RMA
2071
2072This allocates a Real Mode Area (RMA) from the pool allocated at boot
2073time by the kernel.  An RMA is a physically-contiguous, aligned region
2074of memory used on older POWER processors to provide the memory which
2075will be accessed by real-mode (MMU off) accesses in a KVM guest.
2076POWER processors support a set of sizes for the RMA that usually
2077includes 64MB, 128MB, 256MB and some larger powers of two.
2078
2079::
2080
2081  /* for KVM_ALLOCATE_RMA */
2082  struct kvm_allocate_rma {
2083	__u64 rma_size;
2084  };
2085
2086The return value is a file descriptor which can be passed to mmap(2)
2087to map the allocated RMA into userspace.  The mapped area can then be
2088passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
2089RMA for a virtual machine.  The size of the RMA in bytes (which is
2090fixed at host kernel boot time) is returned in the rma_size field of
2091the argument structure.
2092
2093The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
2094is supported; 2 if the processor requires all virtual machines to have
2095an RMA, or 1 if the processor can use an RMA but doesn't require it,
2096because it supports the Virtual RMA (VRMA) facility.
2097
2098
20994.64 KVM_NMI
2100------------
2101
2102:Capability: KVM_CAP_USER_NMI
2103:Architectures: x86
2104:Type: vcpu ioctl
2105:Parameters: none
2106:Returns: 0 on success, -1 on error
2107
2108Queues an NMI on the thread's vcpu.  Note this is well defined only
2109when KVM_CREATE_IRQCHIP has not been called, since this is an interface
2110between the virtual cpu core and virtual local APIC.  After KVM_CREATE_IRQCHIP
2111has been called, this interface is completely emulated within the kernel.
2112
2113To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
2114following algorithm:
2115
2116  - pause the vcpu
2117  - read the local APIC's state (KVM_GET_LAPIC)
2118  - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
2119  - if so, issue KVM_NMI
2120  - resume the vcpu
2121
2122Some guests configure the LINT1 NMI input to cause a panic, aiding in
2123debugging.
2124
2125
21264.65 KVM_S390_UCAS_MAP
2127----------------------
2128
2129:Capability: KVM_CAP_S390_UCONTROL
2130:Architectures: s390
2131:Type: vcpu ioctl
2132:Parameters: struct kvm_s390_ucas_mapping (in)
2133:Returns: 0 in case of success
2134
2135The parameter is defined like this::
2136
2137	struct kvm_s390_ucas_mapping {
2138		__u64 user_addr;
2139		__u64 vcpu_addr;
2140		__u64 length;
2141	};
2142
2143This ioctl maps the memory at "user_addr" with the length "length" to
2144the vcpu's address space starting at "vcpu_addr". All parameters need to
2145be aligned by 1 megabyte.
2146
2147
21484.66 KVM_S390_UCAS_UNMAP
2149------------------------
2150
2151:Capability: KVM_CAP_S390_UCONTROL
2152:Architectures: s390
2153:Type: vcpu ioctl
2154:Parameters: struct kvm_s390_ucas_mapping (in)
2155:Returns: 0 in case of success
2156
2157The parameter is defined like this::
2158
2159	struct kvm_s390_ucas_mapping {
2160		__u64 user_addr;
2161		__u64 vcpu_addr;
2162		__u64 length;
2163	};
2164
2165This ioctl unmaps the memory in the vcpu's address space starting at
2166"vcpu_addr" with the length "length". The field "user_addr" is ignored.
2167All parameters need to be aligned by 1 megabyte.
2168
2169
21704.67 KVM_S390_VCPU_FAULT
2171------------------------
2172
2173:Capability: KVM_CAP_S390_UCONTROL
2174:Architectures: s390
2175:Type: vcpu ioctl
2176:Parameters: vcpu absolute address (in)
2177:Returns: 0 in case of success
2178
2179This call creates a page table entry on the virtual cpu's address space
2180(for user controlled virtual machines) or the virtual machine's address
2181space (for regular virtual machines). This only works for minor faults,
2182thus it's recommended to access subject memory page via the user page
2183table upfront. This is useful to handle validity intercepts for user
2184controlled virtual machines to fault in the virtual cpu's lowcore pages
2185prior to calling the KVM_RUN ioctl.
2186
2187
21884.68 KVM_SET_ONE_REG
2189--------------------
2190
2191:Capability: KVM_CAP_ONE_REG
2192:Architectures: all
2193:Type: vcpu ioctl
2194:Parameters: struct kvm_one_reg (in)
2195:Returns: 0 on success, negative value on failure
2196
2197Errors:
2198
2199  ======   ============================================================
2200  ENOENT   no such register
2201  EINVAL   invalid register ID, or no such register or used with VMs in
2202           protected virtualization mode on s390
2203  EPERM    (arm64) register access not allowed before vcpu finalization
2204  ======   ============================================================
2205
2206(These error codes are indicative only: do not rely on a specific error
2207code being returned in a specific situation.)
2208
2209::
2210
2211  struct kvm_one_reg {
2212       __u64 id;
2213       __u64 addr;
2214 };
2215
2216Using this ioctl, a single vcpu register can be set to a specific value
2217defined by user space with the passed in struct kvm_one_reg, where id
2218refers to the register identifier as described below and addr is a pointer
2219to a variable with the respective size. There can be architecture agnostic
2220and architecture specific registers. Each have their own range of operation
2221and their own constants and width. To keep track of the implemented
2222registers, find a list below:
2223
2224  ======= =============================== ============
2225  Arch              Register              Width (bits)
2226  ======= =============================== ============
2227  PPC     KVM_REG_PPC_HIOR                64
2228  PPC     KVM_REG_PPC_IAC1                64
2229  PPC     KVM_REG_PPC_IAC2                64
2230  PPC     KVM_REG_PPC_IAC3                64
2231  PPC     KVM_REG_PPC_IAC4                64
2232  PPC     KVM_REG_PPC_DAC1                64
2233  PPC     KVM_REG_PPC_DAC2                64
2234  PPC     KVM_REG_PPC_DABR                64
2235  PPC     KVM_REG_PPC_DSCR                64
2236  PPC     KVM_REG_PPC_PURR                64
2237  PPC     KVM_REG_PPC_SPURR               64
2238  PPC     KVM_REG_PPC_DAR                 64
2239  PPC     KVM_REG_PPC_DSISR               32
2240  PPC     KVM_REG_PPC_AMR                 64
2241  PPC     KVM_REG_PPC_UAMOR               64
2242  PPC     KVM_REG_PPC_MMCR0               64
2243  PPC     KVM_REG_PPC_MMCR1               64
2244  PPC     KVM_REG_PPC_MMCRA               64
2245  PPC     KVM_REG_PPC_MMCR2               64
2246  PPC     KVM_REG_PPC_MMCRS               64
2247  PPC     KVM_REG_PPC_MMCR3               64
2248  PPC     KVM_REG_PPC_SIAR                64
2249  PPC     KVM_REG_PPC_SDAR                64
2250  PPC     KVM_REG_PPC_SIER                64
2251  PPC     KVM_REG_PPC_SIER2               64
2252  PPC     KVM_REG_PPC_SIER3               64
2253  PPC     KVM_REG_PPC_PMC1                32
2254  PPC     KVM_REG_PPC_PMC2                32
2255  PPC     KVM_REG_PPC_PMC3                32
2256  PPC     KVM_REG_PPC_PMC4                32
2257  PPC     KVM_REG_PPC_PMC5                32
2258  PPC     KVM_REG_PPC_PMC6                32
2259  PPC     KVM_REG_PPC_PMC7                32
2260  PPC     KVM_REG_PPC_PMC8                32
2261  PPC     KVM_REG_PPC_FPR0                64
2262  ...
2263  PPC     KVM_REG_PPC_FPR31               64
2264  PPC     KVM_REG_PPC_VR0                 128
2265  ...
2266  PPC     KVM_REG_PPC_VR31                128
2267  PPC     KVM_REG_PPC_VSR0                128
2268  ...
2269  PPC     KVM_REG_PPC_VSR31               128
2270  PPC     KVM_REG_PPC_FPSCR               64
2271  PPC     KVM_REG_PPC_VSCR                32
2272  PPC     KVM_REG_PPC_VPA_ADDR            64
2273  PPC     KVM_REG_PPC_VPA_SLB             128
2274  PPC     KVM_REG_PPC_VPA_DTL             128
2275  PPC     KVM_REG_PPC_EPCR                32
2276  PPC     KVM_REG_PPC_EPR                 32
2277  PPC     KVM_REG_PPC_TCR                 32
2278  PPC     KVM_REG_PPC_TSR                 32
2279  PPC     KVM_REG_PPC_OR_TSR              32
2280  PPC     KVM_REG_PPC_CLEAR_TSR           32
2281  PPC     KVM_REG_PPC_MAS0                32
2282  PPC     KVM_REG_PPC_MAS1                32
2283  PPC     KVM_REG_PPC_MAS2                64
2284  PPC     KVM_REG_PPC_MAS7_3              64
2285  PPC     KVM_REG_PPC_MAS4                32
2286  PPC     KVM_REG_PPC_MAS6                32
2287  PPC     KVM_REG_PPC_MMUCFG              32
2288  PPC     KVM_REG_PPC_TLB0CFG             32
2289  PPC     KVM_REG_PPC_TLB1CFG             32
2290  PPC     KVM_REG_PPC_TLB2CFG             32
2291  PPC     KVM_REG_PPC_TLB3CFG             32
2292  PPC     KVM_REG_PPC_TLB0PS              32
2293  PPC     KVM_REG_PPC_TLB1PS              32
2294  PPC     KVM_REG_PPC_TLB2PS              32
2295  PPC     KVM_REG_PPC_TLB3PS              32
2296  PPC     KVM_REG_PPC_EPTCFG              32
2297  PPC     KVM_REG_PPC_ICP_STATE           64
2298  PPC     KVM_REG_PPC_VP_STATE            128
2299  PPC     KVM_REG_PPC_TB_OFFSET           64
2300  PPC     KVM_REG_PPC_SPMC1               32
2301  PPC     KVM_REG_PPC_SPMC2               32
2302  PPC     KVM_REG_PPC_IAMR                64
2303  PPC     KVM_REG_PPC_TFHAR               64
2304  PPC     KVM_REG_PPC_TFIAR               64
2305  PPC     KVM_REG_PPC_TEXASR              64
2306  PPC     KVM_REG_PPC_FSCR                64
2307  PPC     KVM_REG_PPC_PSPB                32
2308  PPC     KVM_REG_PPC_EBBHR               64
2309  PPC     KVM_REG_PPC_EBBRR               64
2310  PPC     KVM_REG_PPC_BESCR               64
2311  PPC     KVM_REG_PPC_TAR                 64
2312  PPC     KVM_REG_PPC_DPDES               64
2313  PPC     KVM_REG_PPC_DAWR                64
2314  PPC     KVM_REG_PPC_DAWRX               64
2315  PPC     KVM_REG_PPC_CIABR               64
2316  PPC     KVM_REG_PPC_IC                  64
2317  PPC     KVM_REG_PPC_VTB                 64
2318  PPC     KVM_REG_PPC_CSIGR               64
2319  PPC     KVM_REG_PPC_TACR                64
2320  PPC     KVM_REG_PPC_TCSCR               64
2321  PPC     KVM_REG_PPC_PID                 64
2322  PPC     KVM_REG_PPC_ACOP                64
2323  PPC     KVM_REG_PPC_VRSAVE              32
2324  PPC     KVM_REG_PPC_LPCR                32
2325  PPC     KVM_REG_PPC_LPCR_64             64
2326  PPC     KVM_REG_PPC_PPR                 64
2327  PPC     KVM_REG_PPC_ARCH_COMPAT         32
2328  PPC     KVM_REG_PPC_DABRX               32
2329  PPC     KVM_REG_PPC_WORT                64
2330  PPC	  KVM_REG_PPC_SPRG9               64
2331  PPC	  KVM_REG_PPC_DBSR                32
2332  PPC     KVM_REG_PPC_TIDR                64
2333  PPC     KVM_REG_PPC_PSSCR               64
2334  PPC     KVM_REG_PPC_DEC_EXPIRY          64
2335  PPC     KVM_REG_PPC_PTCR                64
2336  PPC     KVM_REG_PPC_DAWR1               64
2337  PPC     KVM_REG_PPC_DAWRX1              64
2338  PPC     KVM_REG_PPC_TM_GPR0             64
2339  ...
2340  PPC     KVM_REG_PPC_TM_GPR31            64
2341  PPC     KVM_REG_PPC_TM_VSR0             128
2342  ...
2343  PPC     KVM_REG_PPC_TM_VSR63            128
2344  PPC     KVM_REG_PPC_TM_CR               64
2345  PPC     KVM_REG_PPC_TM_LR               64
2346  PPC     KVM_REG_PPC_TM_CTR              64
2347  PPC     KVM_REG_PPC_TM_FPSCR            64
2348  PPC     KVM_REG_PPC_TM_AMR              64
2349  PPC     KVM_REG_PPC_TM_PPR              64
2350  PPC     KVM_REG_PPC_TM_VRSAVE           64
2351  PPC     KVM_REG_PPC_TM_VSCR             32
2352  PPC     KVM_REG_PPC_TM_DSCR             64
2353  PPC     KVM_REG_PPC_TM_TAR              64
2354  PPC     KVM_REG_PPC_TM_XER              64
2355
2356  MIPS    KVM_REG_MIPS_R0                 64
2357  ...
2358  MIPS    KVM_REG_MIPS_R31                64
2359  MIPS    KVM_REG_MIPS_HI                 64
2360  MIPS    KVM_REG_MIPS_LO                 64
2361  MIPS    KVM_REG_MIPS_PC                 64
2362  MIPS    KVM_REG_MIPS_CP0_INDEX          32
2363  MIPS    KVM_REG_MIPS_CP0_ENTRYLO0       64
2364  MIPS    KVM_REG_MIPS_CP0_ENTRYLO1       64
2365  MIPS    KVM_REG_MIPS_CP0_CONTEXT        64
2366  MIPS    KVM_REG_MIPS_CP0_CONTEXTCONFIG  32
2367  MIPS    KVM_REG_MIPS_CP0_USERLOCAL      64
2368  MIPS    KVM_REG_MIPS_CP0_XCONTEXTCONFIG 64
2369  MIPS    KVM_REG_MIPS_CP0_PAGEMASK       32
2370  MIPS    KVM_REG_MIPS_CP0_PAGEGRAIN      32
2371  MIPS    KVM_REG_MIPS_CP0_SEGCTL0        64
2372  MIPS    KVM_REG_MIPS_CP0_SEGCTL1        64
2373  MIPS    KVM_REG_MIPS_CP0_SEGCTL2        64
2374  MIPS    KVM_REG_MIPS_CP0_PWBASE         64
2375  MIPS    KVM_REG_MIPS_CP0_PWFIELD        64
2376  MIPS    KVM_REG_MIPS_CP0_PWSIZE         64
2377  MIPS    KVM_REG_MIPS_CP0_WIRED          32
2378  MIPS    KVM_REG_MIPS_CP0_PWCTL          32
2379  MIPS    KVM_REG_MIPS_CP0_HWRENA         32
2380  MIPS    KVM_REG_MIPS_CP0_BADVADDR       64
2381  MIPS    KVM_REG_MIPS_CP0_BADINSTR       32
2382  MIPS    KVM_REG_MIPS_CP0_BADINSTRP      32
2383  MIPS    KVM_REG_MIPS_CP0_COUNT          32
2384  MIPS    KVM_REG_MIPS_CP0_ENTRYHI        64
2385  MIPS    KVM_REG_MIPS_CP0_COMPARE        32
2386  MIPS    KVM_REG_MIPS_CP0_STATUS         32
2387  MIPS    KVM_REG_MIPS_CP0_INTCTL         32
2388  MIPS    KVM_REG_MIPS_CP0_CAUSE          32
2389  MIPS    KVM_REG_MIPS_CP0_EPC            64
2390  MIPS    KVM_REG_MIPS_CP0_PRID           32
2391  MIPS    KVM_REG_MIPS_CP0_EBASE          64
2392  MIPS    KVM_REG_MIPS_CP0_CONFIG         32
2393  MIPS    KVM_REG_MIPS_CP0_CONFIG1        32
2394  MIPS    KVM_REG_MIPS_CP0_CONFIG2        32
2395  MIPS    KVM_REG_MIPS_CP0_CONFIG3        32
2396  MIPS    KVM_REG_MIPS_CP0_CONFIG4        32
2397  MIPS    KVM_REG_MIPS_CP0_CONFIG5        32
2398  MIPS    KVM_REG_MIPS_CP0_CONFIG7        32
2399  MIPS    KVM_REG_MIPS_CP0_XCONTEXT       64
2400  MIPS    KVM_REG_MIPS_CP0_ERROREPC       64
2401  MIPS    KVM_REG_MIPS_CP0_KSCRATCH1      64
2402  MIPS    KVM_REG_MIPS_CP0_KSCRATCH2      64
2403  MIPS    KVM_REG_MIPS_CP0_KSCRATCH3      64
2404  MIPS    KVM_REG_MIPS_CP0_KSCRATCH4      64
2405  MIPS    KVM_REG_MIPS_CP0_KSCRATCH5      64
2406  MIPS    KVM_REG_MIPS_CP0_KSCRATCH6      64
2407  MIPS    KVM_REG_MIPS_CP0_MAAR(0..63)    64
2408  MIPS    KVM_REG_MIPS_COUNT_CTL          64
2409  MIPS    KVM_REG_MIPS_COUNT_RESUME       64
2410  MIPS    KVM_REG_MIPS_COUNT_HZ           64
2411  MIPS    KVM_REG_MIPS_FPR_32(0..31)      32
2412  MIPS    KVM_REG_MIPS_FPR_64(0..31)      64
2413  MIPS    KVM_REG_MIPS_VEC_128(0..31)     128
2414  MIPS    KVM_REG_MIPS_FCR_IR             32
2415  MIPS    KVM_REG_MIPS_FCR_CSR            32
2416  MIPS    KVM_REG_MIPS_MSA_IR             32
2417  MIPS    KVM_REG_MIPS_MSA_CSR            32
2418  ======= =============================== ============
2419
2420ARM registers are mapped using the lower 32 bits.  The upper 16 of that
2421is the register group type, or coprocessor number:
2422
2423ARM core registers have the following id bit patterns::
2424
2425  0x4020 0000 0010 <index into the kvm_regs struct:16>
2426
2427ARM 32-bit CP15 registers have the following id bit patterns::
2428
2429  0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
2430
2431ARM 64-bit CP15 registers have the following id bit patterns::
2432
2433  0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
2434
2435ARM CCSIDR registers are demultiplexed by CSSELR value::
2436
2437  0x4020 0000 0011 00 <csselr:8>
2438
2439ARM 32-bit VFP control registers have the following id bit patterns::
2440
2441  0x4020 0000 0012 1 <regno:12>
2442
2443ARM 64-bit FP registers have the following id bit patterns::
2444
2445  0x4030 0000 0012 0 <regno:12>
2446
2447ARM firmware pseudo-registers have the following bit pattern::
2448
2449  0x4030 0000 0014 <regno:16>
2450
2451
2452arm64 registers are mapped using the lower 32 bits. The upper 16 of
2453that is the register group type, or coprocessor number:
2454
2455arm64 core/FP-SIMD registers have the following id bit patterns. Note
2456that the size of the access is variable, as the kvm_regs structure
2457contains elements ranging from 32 to 128 bits. The index is a 32bit
2458value in the kvm_regs structure seen as a 32bit array::
2459
2460  0x60x0 0000 0010 <index into the kvm_regs struct:16>
2461
2462Specifically:
2463
2464======================= ========= ===== =======================================
2465    Encoding            Register  Bits  kvm_regs member
2466======================= ========= ===== =======================================
2467  0x6030 0000 0010 0000 X0          64  regs.regs[0]
2468  0x6030 0000 0010 0002 X1          64  regs.regs[1]
2469  ...
2470  0x6030 0000 0010 003c X30         64  regs.regs[30]
2471  0x6030 0000 0010 003e SP          64  regs.sp
2472  0x6030 0000 0010 0040 PC          64  regs.pc
2473  0x6030 0000 0010 0042 PSTATE      64  regs.pstate
2474  0x6030 0000 0010 0044 SP_EL1      64  sp_el1
2475  0x6030 0000 0010 0046 ELR_EL1     64  elr_el1
2476  0x6030 0000 0010 0048 SPSR_EL1    64  spsr[KVM_SPSR_EL1] (alias SPSR_SVC)
2477  0x6030 0000 0010 004a SPSR_ABT    64  spsr[KVM_SPSR_ABT]
2478  0x6030 0000 0010 004c SPSR_UND    64  spsr[KVM_SPSR_UND]
2479  0x6030 0000 0010 004e SPSR_IRQ    64  spsr[KVM_SPSR_IRQ]
2480  0x6060 0000 0010 0050 SPSR_FIQ    64  spsr[KVM_SPSR_FIQ]
2481  0x6040 0000 0010 0054 V0         128  fp_regs.vregs[0]    [1]_
2482  0x6040 0000 0010 0058 V1         128  fp_regs.vregs[1]    [1]_
2483  ...
2484  0x6040 0000 0010 00d0 V31        128  fp_regs.vregs[31]   [1]_
2485  0x6020 0000 0010 00d4 FPSR        32  fp_regs.fpsr
2486  0x6020 0000 0010 00d5 FPCR        32  fp_regs.fpcr
2487======================= ========= ===== =======================================
2488
2489.. [1] These encodings are not accepted for SVE-enabled vcpus.  See
2490       KVM_ARM_VCPU_INIT.
2491
2492       The equivalent register content can be accessed via bits [127:0] of
2493       the corresponding SVE Zn registers instead for vcpus that have SVE
2494       enabled (see below).
2495
2496arm64 CCSIDR registers are demultiplexed by CSSELR value::
2497
2498  0x6020 0000 0011 00 <csselr:8>
2499
2500arm64 system registers have the following id bit patterns::
2501
2502  0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2503
2504.. warning::
2505
2506     Two system register IDs do not follow the specified pattern.  These
2507     are KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT, which map to
2508     system registers CNTV_CVAL_EL0 and CNTVCT_EL0 respectively.  These
2509     two had their values accidentally swapped, which means TIMER_CVAL is
2510     derived from the register encoding for CNTVCT_EL0 and TIMER_CNT is
2511     derived from the register encoding for CNTV_CVAL_EL0.  As this is
2512     API, it must remain this way.
2513
2514arm64 firmware pseudo-registers have the following bit pattern::
2515
2516  0x6030 0000 0014 <regno:16>
2517
2518arm64 SVE registers have the following bit patterns::
2519
2520  0x6080 0000 0015 00 <n:5> <slice:5>   Zn bits[2048*slice + 2047 : 2048*slice]
2521  0x6050 0000 0015 04 <n:4> <slice:5>   Pn bits[256*slice + 255 : 256*slice]
2522  0x6050 0000 0015 060 <slice:5>        FFR bits[256*slice + 255 : 256*slice]
2523  0x6060 0000 0015 ffff                 KVM_REG_ARM64_SVE_VLS pseudo-register
2524
2525Access to register IDs where 2048 * slice >= 128 * max_vq will fail with
2526ENOENT.  max_vq is the vcpu's maximum supported vector length in 128-bit
2527quadwords: see [2]_ below.
2528
2529These registers are only accessible on vcpus for which SVE is enabled.
2530See KVM_ARM_VCPU_INIT for details.
2531
2532In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not
2533accessible until the vcpu's SVE configuration has been finalized
2534using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE).  See KVM_ARM_VCPU_INIT
2535and KVM_ARM_VCPU_FINALIZE for more information about this procedure.
2536
2537KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector
2538lengths supported by the vcpu to be discovered and configured by
2539userspace.  When transferred to or from user memory via KVM_GET_ONE_REG
2540or KVM_SET_ONE_REG, the value of this register is of type
2541__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as
2542follows::
2543
2544  __u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS];
2545
2546  if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX &&
2547      ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >>
2548		((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1))
2549	/* Vector length vq * 16 bytes supported */
2550  else
2551	/* Vector length vq * 16 bytes not supported */
2552
2553.. [2] The maximum value vq for which the above condition is true is
2554       max_vq.  This is the maximum vector length available to the guest on
2555       this vcpu, and determines which register slices are visible through
2556       this ioctl interface.
2557
2558(See Documentation/arm64/sve.rst for an explanation of the "vq"
2559nomenclature.)
2560
2561KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT.
2562KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that
2563the host supports.
2564
2565Userspace may subsequently modify it if desired until the vcpu's SVE
2566configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE).
2567
2568Apart from simply removing all vector lengths from the host set that
2569exceed some value, support for arbitrarily chosen sets of vector lengths
2570is hardware-dependent and may not be available.  Attempting to configure
2571an invalid set of vector lengths via KVM_SET_ONE_REG will fail with
2572EINVAL.
2573
2574After the vcpu's SVE configuration is finalized, further attempts to
2575write this register will fail with EPERM.
2576
2577
2578MIPS registers are mapped using the lower 32 bits.  The upper 16 of that is
2579the register group type:
2580
2581MIPS core registers (see above) have the following id bit patterns::
2582
2583  0x7030 0000 0000 <reg:16>
2584
2585MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
2586patterns depending on whether they're 32-bit or 64-bit registers::
2587
2588  0x7020 0000 0001 00 <reg:5> <sel:3>   (32-bit)
2589  0x7030 0000 0001 00 <reg:5> <sel:3>   (64-bit)
2590
2591Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2592versions of the EntryLo registers regardless of the word size of the host
2593hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2594with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2595the PFNX field starting at bit 30.
2596
2597MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
2598patterns::
2599
2600  0x7030 0000 0001 01 <reg:8>
2601
2602MIPS KVM control registers (see above) have the following id bit patterns::
2603
2604  0x7030 0000 0002 <reg:16>
2605
2606MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2607id bit patterns depending on the size of the register being accessed. They are
2608always accessed according to the current guest FPU mode (Status.FR and
2609Config5.FRE), i.e. as the guest would see them, and they become unpredictable
2610if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2611registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
2612overlap the FPU registers::
2613
2614  0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2615  0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
2616  0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
2617
2618MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
2619following id bit patterns::
2620
2621  0x7020 0000 0003 01 <0:3> <reg:5>
2622
2623MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
2624following id bit patterns::
2625
2626  0x7020 0000 0003 02 <0:3> <reg:5>
2627
2628RISC-V registers are mapped using the lower 32 bits. The upper 8 bits of
2629that is the register group type.
2630
2631RISC-V config registers are meant for configuring a Guest VCPU and it has
2632the following id bit patterns::
2633
2634  0x8020 0000 01 <index into the kvm_riscv_config struct:24> (32bit Host)
2635  0x8030 0000 01 <index into the kvm_riscv_config struct:24> (64bit Host)
2636
2637Following are the RISC-V config registers:
2638
2639======================= ========= =============================================
2640    Encoding            Register  Description
2641======================= ========= =============================================
2642  0x80x0 0000 0100 0000 isa       ISA feature bitmap of Guest VCPU
2643======================= ========= =============================================
2644
2645The isa config register can be read anytime but can only be written before
2646a Guest VCPU runs. It will have ISA feature bits matching underlying host
2647set by default.
2648
2649RISC-V core registers represent the general excution state of a Guest VCPU
2650and it has the following id bit patterns::
2651
2652  0x8020 0000 02 <index into the kvm_riscv_core struct:24> (32bit Host)
2653  0x8030 0000 02 <index into the kvm_riscv_core struct:24> (64bit Host)
2654
2655Following are the RISC-V core registers:
2656
2657======================= ========= =============================================
2658    Encoding            Register  Description
2659======================= ========= =============================================
2660  0x80x0 0000 0200 0000 regs.pc   Program counter
2661  0x80x0 0000 0200 0001 regs.ra   Return address
2662  0x80x0 0000 0200 0002 regs.sp   Stack pointer
2663  0x80x0 0000 0200 0003 regs.gp   Global pointer
2664  0x80x0 0000 0200 0004 regs.tp   Task pointer
2665  0x80x0 0000 0200 0005 regs.t0   Caller saved register 0
2666  0x80x0 0000 0200 0006 regs.t1   Caller saved register 1
2667  0x80x0 0000 0200 0007 regs.t2   Caller saved register 2
2668  0x80x0 0000 0200 0008 regs.s0   Callee saved register 0
2669  0x80x0 0000 0200 0009 regs.s1   Callee saved register 1
2670  0x80x0 0000 0200 000a regs.a0   Function argument (or return value) 0
2671  0x80x0 0000 0200 000b regs.a1   Function argument (or return value) 1
2672  0x80x0 0000 0200 000c regs.a2   Function argument 2
2673  0x80x0 0000 0200 000d regs.a3   Function argument 3
2674  0x80x0 0000 0200 000e regs.a4   Function argument 4
2675  0x80x0 0000 0200 000f regs.a5   Function argument 5
2676  0x80x0 0000 0200 0010 regs.a6   Function argument 6
2677  0x80x0 0000 0200 0011 regs.a7   Function argument 7
2678  0x80x0 0000 0200 0012 regs.s2   Callee saved register 2
2679  0x80x0 0000 0200 0013 regs.s3   Callee saved register 3
2680  0x80x0 0000 0200 0014 regs.s4   Callee saved register 4
2681  0x80x0 0000 0200 0015 regs.s5   Callee saved register 5
2682  0x80x0 0000 0200 0016 regs.s6   Callee saved register 6
2683  0x80x0 0000 0200 0017 regs.s7   Callee saved register 7
2684  0x80x0 0000 0200 0018 regs.s8   Callee saved register 8
2685  0x80x0 0000 0200 0019 regs.s9   Callee saved register 9
2686  0x80x0 0000 0200 001a regs.s10  Callee saved register 10
2687  0x80x0 0000 0200 001b regs.s11  Callee saved register 11
2688  0x80x0 0000 0200 001c regs.t3   Caller saved register 3
2689  0x80x0 0000 0200 001d regs.t4   Caller saved register 4
2690  0x80x0 0000 0200 001e regs.t5   Caller saved register 5
2691  0x80x0 0000 0200 001f regs.t6   Caller saved register 6
2692  0x80x0 0000 0200 0020 mode      Privilege mode (1 = S-mode or 0 = U-mode)
2693======================= ========= =============================================
2694
2695RISC-V csr registers represent the supervisor mode control/status registers
2696of a Guest VCPU and it has the following id bit patterns::
2697
2698  0x8020 0000 03 <index into the kvm_riscv_csr struct:24> (32bit Host)
2699  0x8030 0000 03 <index into the kvm_riscv_csr struct:24> (64bit Host)
2700
2701Following are the RISC-V csr registers:
2702
2703======================= ========= =============================================
2704    Encoding            Register  Description
2705======================= ========= =============================================
2706  0x80x0 0000 0300 0000 sstatus   Supervisor status
2707  0x80x0 0000 0300 0001 sie       Supervisor interrupt enable
2708  0x80x0 0000 0300 0002 stvec     Supervisor trap vector base
2709  0x80x0 0000 0300 0003 sscratch  Supervisor scratch register
2710  0x80x0 0000 0300 0004 sepc      Supervisor exception program counter
2711  0x80x0 0000 0300 0005 scause    Supervisor trap cause
2712  0x80x0 0000 0300 0006 stval     Supervisor bad address or instruction
2713  0x80x0 0000 0300 0007 sip       Supervisor interrupt pending
2714  0x80x0 0000 0300 0008 satp      Supervisor address translation and protection
2715======================= ========= =============================================
2716
2717RISC-V timer registers represent the timer state of a Guest VCPU and it has
2718the following id bit patterns::
2719
2720  0x8030 0000 04 <index into the kvm_riscv_timer struct:24>
2721
2722Following are the RISC-V timer registers:
2723
2724======================= ========= =============================================
2725    Encoding            Register  Description
2726======================= ========= =============================================
2727  0x8030 0000 0400 0000 frequency Time base frequency (read-only)
2728  0x8030 0000 0400 0001 time      Time value visible to Guest
2729  0x8030 0000 0400 0002 compare   Time compare programmed by Guest
2730  0x8030 0000 0400 0003 state     Time compare state (1 = ON or 0 = OFF)
2731======================= ========= =============================================
2732
2733RISC-V F-extension registers represent the single precision floating point
2734state of a Guest VCPU and it has the following id bit patterns::
2735
2736  0x8020 0000 05 <index into the __riscv_f_ext_state struct:24>
2737
2738Following are the RISC-V F-extension registers:
2739
2740======================= ========= =============================================
2741    Encoding            Register  Description
2742======================= ========= =============================================
2743  0x8020 0000 0500 0000 f[0]      Floating point register 0
2744  ...
2745  0x8020 0000 0500 001f f[31]     Floating point register 31
2746  0x8020 0000 0500 0020 fcsr      Floating point control and status register
2747======================= ========= =============================================
2748
2749RISC-V D-extension registers represent the double precision floating point
2750state of a Guest VCPU and it has the following id bit patterns::
2751
2752  0x8020 0000 06 <index into the __riscv_d_ext_state struct:24> (fcsr)
2753  0x8030 0000 06 <index into the __riscv_d_ext_state struct:24> (non-fcsr)
2754
2755Following are the RISC-V D-extension registers:
2756
2757======================= ========= =============================================
2758    Encoding            Register  Description
2759======================= ========= =============================================
2760  0x8030 0000 0600 0000 f[0]      Floating point register 0
2761  ...
2762  0x8030 0000 0600 001f f[31]     Floating point register 31
2763  0x8020 0000 0600 0020 fcsr      Floating point control and status register
2764======================= ========= =============================================
2765
2766
27674.69 KVM_GET_ONE_REG
2768--------------------
2769
2770:Capability: KVM_CAP_ONE_REG
2771:Architectures: all
2772:Type: vcpu ioctl
2773:Parameters: struct kvm_one_reg (in and out)
2774:Returns: 0 on success, negative value on failure
2775
2776Errors include:
2777
2778  ======== ============================================================
2779  ENOENT   no such register
2780  EINVAL   invalid register ID, or no such register or used with VMs in
2781           protected virtualization mode on s390
2782  EPERM    (arm64) register access not allowed before vcpu finalization
2783  ======== ============================================================
2784
2785(These error codes are indicative only: do not rely on a specific error
2786code being returned in a specific situation.)
2787
2788This ioctl allows to receive the value of a single register implemented
2789in a vcpu. The register to read is indicated by the "id" field of the
2790kvm_one_reg struct passed in. On success, the register value can be found
2791at the memory location pointed to by "addr".
2792
2793The list of registers accessible using this interface is identical to the
2794list in 4.68.
2795
2796
27974.70 KVM_KVMCLOCK_CTRL
2798----------------------
2799
2800:Capability: KVM_CAP_KVMCLOCK_CTRL
2801:Architectures: Any that implement pvclocks (currently x86 only)
2802:Type: vcpu ioctl
2803:Parameters: None
2804:Returns: 0 on success, -1 on error
2805
2806This ioctl sets a flag accessible to the guest indicating that the specified
2807vCPU has been paused by the host userspace.
2808
2809The host will set a flag in the pvclock structure that is checked from the
2810soft lockup watchdog.  The flag is part of the pvclock structure that is
2811shared between guest and host, specifically the second bit of the flags
2812field of the pvclock_vcpu_time_info structure.  It will be set exclusively by
2813the host and read/cleared exclusively by the guest.  The guest operation of
2814checking and clearing the flag must be an atomic operation so
2815load-link/store-conditional, or equivalent must be used.  There are two cases
2816where the guest will clear the flag: when the soft lockup watchdog timer resets
2817itself or when a soft lockup is detected.  This ioctl can be called any time
2818after pausing the vcpu, but before it is resumed.
2819
2820
28214.71 KVM_SIGNAL_MSI
2822-------------------
2823
2824:Capability: KVM_CAP_SIGNAL_MSI
2825:Architectures: x86 arm arm64
2826:Type: vm ioctl
2827:Parameters: struct kvm_msi (in)
2828:Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
2829
2830Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2831MSI messages.
2832
2833::
2834
2835  struct kvm_msi {
2836	__u32 address_lo;
2837	__u32 address_hi;
2838	__u32 data;
2839	__u32 flags;
2840	__u32 devid;
2841	__u8  pad[12];
2842  };
2843
2844flags:
2845  KVM_MSI_VALID_DEVID: devid contains a valid value.  The per-VM
2846  KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2847  the device ID.  If this capability is not available, userspace
2848  should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
2849
2850If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2851for the device that wrote the MSI message.  For PCI, this is usually a
2852BFD identifier in the lower 16 bits.
2853
2854On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2855feature of KVM_CAP_X2APIC_API capability is enabled.  If it is enabled,
2856address_hi bits 31-8 provide bits 31-8 of the destination id.  Bits 7-0 of
2857address_hi must be zero.
2858
2859
28604.71 KVM_CREATE_PIT2
2861--------------------
2862
2863:Capability: KVM_CAP_PIT2
2864:Architectures: x86
2865:Type: vm ioctl
2866:Parameters: struct kvm_pit_config (in)
2867:Returns: 0 on success, -1 on error
2868
2869Creates an in-kernel device model for the i8254 PIT. This call is only valid
2870after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
2871parameters have to be passed::
2872
2873  struct kvm_pit_config {
2874	__u32 flags;
2875	__u32 pad[15];
2876  };
2877
2878Valid flags are::
2879
2880  #define KVM_PIT_SPEAKER_DUMMY     1 /* emulate speaker port stub */
2881
2882PIT timer interrupts may use a per-VM kernel thread for injection. If it
2883exists, this thread will have a name of the following pattern::
2884
2885  kvm-pit/<owner-process-pid>
2886
2887When running a guest with elevated priorities, the scheduling parameters of
2888this thread may have to be adjusted accordingly.
2889
2890This IOCTL replaces the obsolete KVM_CREATE_PIT.
2891
2892
28934.72 KVM_GET_PIT2
2894-----------------
2895
2896:Capability: KVM_CAP_PIT_STATE2
2897:Architectures: x86
2898:Type: vm ioctl
2899:Parameters: struct kvm_pit_state2 (out)
2900:Returns: 0 on success, -1 on error
2901
2902Retrieves the state of the in-kernel PIT model. Only valid after
2903KVM_CREATE_PIT2. The state is returned in the following structure::
2904
2905  struct kvm_pit_state2 {
2906	struct kvm_pit_channel_state channels[3];
2907	__u32 flags;
2908	__u32 reserved[9];
2909  };
2910
2911Valid flags are::
2912
2913  /* disable PIT in HPET legacy mode */
2914  #define KVM_PIT_FLAGS_HPET_LEGACY  0x00000001
2915
2916This IOCTL replaces the obsolete KVM_GET_PIT.
2917
2918
29194.73 KVM_SET_PIT2
2920-----------------
2921
2922:Capability: KVM_CAP_PIT_STATE2
2923:Architectures: x86
2924:Type: vm ioctl
2925:Parameters: struct kvm_pit_state2 (in)
2926:Returns: 0 on success, -1 on error
2927
2928Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
2929See KVM_GET_PIT2 for details on struct kvm_pit_state2.
2930
2931This IOCTL replaces the obsolete KVM_SET_PIT.
2932
2933
29344.74 KVM_PPC_GET_SMMU_INFO
2935--------------------------
2936
2937:Capability: KVM_CAP_PPC_GET_SMMU_INFO
2938:Architectures: powerpc
2939:Type: vm ioctl
2940:Parameters: None
2941:Returns: 0 on success, -1 on error
2942
2943This populates and returns a structure describing the features of
2944the "Server" class MMU emulation supported by KVM.
2945This can in turn be used by userspace to generate the appropriate
2946device-tree properties for the guest operating system.
2947
2948The structure contains some global information, followed by an
2949array of supported segment page sizes::
2950
2951      struct kvm_ppc_smmu_info {
2952	     __u64 flags;
2953	     __u32 slb_size;
2954	     __u32 pad;
2955	     struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
2956      };
2957
2958The supported flags are:
2959
2960    - KVM_PPC_PAGE_SIZES_REAL:
2961        When that flag is set, guest page sizes must "fit" the backing
2962        store page sizes. When not set, any page size in the list can
2963        be used regardless of how they are backed by userspace.
2964
2965    - KVM_PPC_1T_SEGMENTS
2966        The emulated MMU supports 1T segments in addition to the
2967        standard 256M ones.
2968
2969    - KVM_PPC_NO_HASH
2970	This flag indicates that HPT guests are not supported by KVM,
2971	thus all guests must use radix MMU mode.
2972
2973The "slb_size" field indicates how many SLB entries are supported
2974
2975The "sps" array contains 8 entries indicating the supported base
2976page sizes for a segment in increasing order. Each entry is defined
2977as follow::
2978
2979   struct kvm_ppc_one_seg_page_size {
2980	__u32 page_shift;	/* Base page shift of segment (or 0) */
2981	__u32 slb_enc;		/* SLB encoding for BookS */
2982	struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
2983   };
2984
2985An entry with a "page_shift" of 0 is unused. Because the array is
2986organized in increasing order, a lookup can stop when encoutering
2987such an entry.
2988
2989The "slb_enc" field provides the encoding to use in the SLB for the
2990page size. The bits are in positions such as the value can directly
2991be OR'ed into the "vsid" argument of the slbmte instruction.
2992
2993The "enc" array is a list which for each of those segment base page
2994size provides the list of supported actual page sizes (which can be
2995only larger or equal to the base page size), along with the
2996corresponding encoding in the hash PTE. Similarly, the array is
29978 entries sorted by increasing sizes and an entry with a "0" shift
2998is an empty entry and a terminator::
2999
3000   struct kvm_ppc_one_page_size {
3001	__u32 page_shift;	/* Page shift (or 0) */
3002	__u32 pte_enc;		/* Encoding in the HPTE (>>12) */
3003   };
3004
3005The "pte_enc" field provides a value that can OR'ed into the hash
3006PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
3007into the hash PTE second double word).
3008
30094.75 KVM_IRQFD
3010--------------
3011
3012:Capability: KVM_CAP_IRQFD
3013:Architectures: x86 s390 arm arm64
3014:Type: vm ioctl
3015:Parameters: struct kvm_irqfd (in)
3016:Returns: 0 on success, -1 on error
3017
3018Allows setting an eventfd to directly trigger a guest interrupt.
3019kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
3020kvm_irqfd.gsi specifies the irqchip pin toggled by this event.  When
3021an event is triggered on the eventfd, an interrupt is injected into
3022the guest using the specified gsi pin.  The irqfd is removed using
3023the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
3024and kvm_irqfd.gsi.
3025
3026With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
3027mechanism allowing emulation of level-triggered, irqfd-based
3028interrupts.  When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
3029additional eventfd in the kvm_irqfd.resamplefd field.  When operating
3030in resample mode, posting of an interrupt through kvm_irq.fd asserts
3031the specified gsi in the irqchip.  When the irqchip is resampled, such
3032as from an EOI, the gsi is de-asserted and the user is notified via
3033kvm_irqfd.resamplefd.  It is the user's responsibility to re-queue
3034the interrupt if the device making use of it still requires service.
3035Note that closing the resamplefd is not sufficient to disable the
3036irqfd.  The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
3037and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
3038
3039On arm/arm64, gsi routing being supported, the following can happen:
3040
3041- in case no routing entry is associated to this gsi, injection fails
3042- in case the gsi is associated to an irqchip routing entry,
3043  irqchip.pin + 32 corresponds to the injected SPI ID.
3044- in case the gsi is associated to an MSI routing entry, the MSI
3045  message and device ID are translated into an LPI (support restricted
3046  to GICv3 ITS in-kernel emulation).
3047
30484.76 KVM_PPC_ALLOCATE_HTAB
3049--------------------------
3050
3051:Capability: KVM_CAP_PPC_ALLOC_HTAB
3052:Architectures: powerpc
3053:Type: vm ioctl
3054:Parameters: Pointer to u32 containing hash table order (in/out)
3055:Returns: 0 on success, -1 on error
3056
3057This requests the host kernel to allocate an MMU hash table for a
3058guest using the PAPR paravirtualization interface.  This only does
3059anything if the kernel is configured to use the Book 3S HV style of
3060virtualization.  Otherwise the capability doesn't exist and the ioctl
3061returns an ENOTTY error.  The rest of this description assumes Book 3S
3062HV.
3063
3064There must be no vcpus running when this ioctl is called; if there
3065are, it will do nothing and return an EBUSY error.
3066
3067The parameter is a pointer to a 32-bit unsigned integer variable
3068containing the order (log base 2) of the desired size of the hash
3069table, which must be between 18 and 46.  On successful return from the
3070ioctl, the value will not be changed by the kernel.
3071
3072If no hash table has been allocated when any vcpu is asked to run
3073(with the KVM_RUN ioctl), the host kernel will allocate a
3074default-sized hash table (16 MB).
3075
3076If this ioctl is called when a hash table has already been allocated,
3077with a different order from the existing hash table, the existing hash
3078table will be freed and a new one allocated.  If this is ioctl is
3079called when a hash table has already been allocated of the same order
3080as specified, the kernel will clear out the existing hash table (zero
3081all HPTEs).  In either case, if the guest is using the virtualized
3082real-mode area (VRMA) facility, the kernel will re-create the VMRA
3083HPTEs on the next KVM_RUN of any vcpu.
3084
30854.77 KVM_S390_INTERRUPT
3086-----------------------
3087
3088:Capability: basic
3089:Architectures: s390
3090:Type: vm ioctl, vcpu ioctl
3091:Parameters: struct kvm_s390_interrupt (in)
3092:Returns: 0 on success, -1 on error
3093
3094Allows to inject an interrupt to the guest. Interrupts can be floating
3095(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
3096
3097Interrupt parameters are passed via kvm_s390_interrupt::
3098
3099  struct kvm_s390_interrupt {
3100	__u32 type;
3101	__u32 parm;
3102	__u64 parm64;
3103  };
3104
3105type can be one of the following:
3106
3107KVM_S390_SIGP_STOP (vcpu)
3108    - sigp stop; optional flags in parm
3109KVM_S390_PROGRAM_INT (vcpu)
3110    - program check; code in parm
3111KVM_S390_SIGP_SET_PREFIX (vcpu)
3112    - sigp set prefix; prefix address in parm
3113KVM_S390_RESTART (vcpu)
3114    - restart
3115KVM_S390_INT_CLOCK_COMP (vcpu)
3116    - clock comparator interrupt
3117KVM_S390_INT_CPU_TIMER (vcpu)
3118    - CPU timer interrupt
3119KVM_S390_INT_VIRTIO (vm)
3120    - virtio external interrupt; external interrupt
3121      parameters in parm and parm64
3122KVM_S390_INT_SERVICE (vm)
3123    - sclp external interrupt; sclp parameter in parm
3124KVM_S390_INT_EMERGENCY (vcpu)
3125    - sigp emergency; source cpu in parm
3126KVM_S390_INT_EXTERNAL_CALL (vcpu)
3127    - sigp external call; source cpu in parm
3128KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm)
3129    - compound value to indicate an
3130      I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
3131      I/O interruption parameters in parm (subchannel) and parm64 (intparm,
3132      interruption subclass)
3133KVM_S390_MCHK (vm, vcpu)
3134    - machine check interrupt; cr 14 bits in parm, machine check interrupt
3135      code in parm64 (note that machine checks needing further payload are not
3136      supported by this ioctl)
3137
3138This is an asynchronous vcpu ioctl and can be invoked from any thread.
3139
31404.78 KVM_PPC_GET_HTAB_FD
3141------------------------
3142
3143:Capability: KVM_CAP_PPC_HTAB_FD
3144:Architectures: powerpc
3145:Type: vm ioctl
3146:Parameters: Pointer to struct kvm_get_htab_fd (in)
3147:Returns: file descriptor number (>= 0) on success, -1 on error
3148
3149This returns a file descriptor that can be used either to read out the
3150entries in the guest's hashed page table (HPT), or to write entries to
3151initialize the HPT.  The returned fd can only be written to if the
3152KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
3153can only be read if that bit is clear.  The argument struct looks like
3154this::
3155
3156  /* For KVM_PPC_GET_HTAB_FD */
3157  struct kvm_get_htab_fd {
3158	__u64	flags;
3159	__u64	start_index;
3160	__u64	reserved[2];
3161  };
3162
3163  /* Values for kvm_get_htab_fd.flags */
3164  #define KVM_GET_HTAB_BOLTED_ONLY	((__u64)0x1)
3165  #define KVM_GET_HTAB_WRITE		((__u64)0x2)
3166
3167The 'start_index' field gives the index in the HPT of the entry at
3168which to start reading.  It is ignored when writing.
3169
3170Reads on the fd will initially supply information about all
3171"interesting" HPT entries.  Interesting entries are those with the
3172bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
3173all entries.  When the end of the HPT is reached, the read() will
3174return.  If read() is called again on the fd, it will start again from
3175the beginning of the HPT, but will only return HPT entries that have
3176changed since they were last read.
3177
3178Data read or written is structured as a header (8 bytes) followed by a
3179series of valid HPT entries (16 bytes) each.  The header indicates how
3180many valid HPT entries there are and how many invalid entries follow
3181the valid entries.  The invalid entries are not represented explicitly
3182in the stream.  The header format is::
3183
3184  struct kvm_get_htab_header {
3185	__u32	index;
3186	__u16	n_valid;
3187	__u16	n_invalid;
3188  };
3189
3190Writes to the fd create HPT entries starting at the index given in the
3191header; first 'n_valid' valid entries with contents from the data
3192written, then 'n_invalid' invalid entries, invalidating any previously
3193valid entries found.
3194
31954.79 KVM_CREATE_DEVICE
3196----------------------
3197
3198:Capability: KVM_CAP_DEVICE_CTRL
3199:Type: vm ioctl
3200:Parameters: struct kvm_create_device (in/out)
3201:Returns: 0 on success, -1 on error
3202
3203Errors:
3204
3205  ======  =======================================================
3206  ENODEV  The device type is unknown or unsupported
3207  EEXIST  Device already created, and this type of device may not
3208          be instantiated multiple times
3209  ======  =======================================================
3210
3211  Other error conditions may be defined by individual device types or
3212  have their standard meanings.
3213
3214Creates an emulated device in the kernel.  The file descriptor returned
3215in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
3216
3217If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
3218device type is supported (not necessarily whether it can be created
3219in the current vm).
3220
3221Individual devices should not define flags.  Attributes should be used
3222for specifying any behavior that is not implied by the device type
3223number.
3224
3225::
3226
3227  struct kvm_create_device {
3228	__u32	type;	/* in: KVM_DEV_TYPE_xxx */
3229	__u32	fd;	/* out: device handle */
3230	__u32	flags;	/* in: KVM_CREATE_DEVICE_xxx */
3231  };
3232
32334.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
3234--------------------------------------------
3235
3236:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3237             KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3238:Type: device ioctl, vm ioctl, vcpu ioctl
3239:Parameters: struct kvm_device_attr
3240:Returns: 0 on success, -1 on error
3241
3242Errors:
3243
3244  =====   =============================================================
3245  ENXIO   The group or attribute is unknown/unsupported for this device
3246          or hardware support is missing.
3247  EPERM   The attribute cannot (currently) be accessed this way
3248          (e.g. read-only attribute, or attribute that only makes
3249          sense when the device is in a different state)
3250  =====   =============================================================
3251
3252  Other error conditions may be defined by individual device types.
3253
3254Gets/sets a specified piece of device configuration and/or state.  The
3255semantics are device-specific.  See individual device documentation in
3256the "devices" directory.  As with ONE_REG, the size of the data
3257transferred is defined by the particular attribute.
3258
3259::
3260
3261  struct kvm_device_attr {
3262	__u32	flags;		/* no flags currently defined */
3263	__u32	group;		/* device-defined */
3264	__u64	attr;		/* group-defined */
3265	__u64	addr;		/* userspace address of attr data */
3266  };
3267
32684.81 KVM_HAS_DEVICE_ATTR
3269------------------------
3270
3271:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3272	     KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3273:Type: device ioctl, vm ioctl, vcpu ioctl
3274:Parameters: struct kvm_device_attr
3275:Returns: 0 on success, -1 on error
3276
3277Errors:
3278
3279  =====   =============================================================
3280  ENXIO   The group or attribute is unknown/unsupported for this device
3281          or hardware support is missing.
3282  =====   =============================================================
3283
3284Tests whether a device supports a particular attribute.  A successful
3285return indicates the attribute is implemented.  It does not necessarily
3286indicate that the attribute can be read or written in the device's
3287current state.  "addr" is ignored.
3288
32894.82 KVM_ARM_VCPU_INIT
3290----------------------
3291
3292:Capability: basic
3293:Architectures: arm, arm64
3294:Type: vcpu ioctl
3295:Parameters: struct kvm_vcpu_init (in)
3296:Returns: 0 on success; -1 on error
3297
3298Errors:
3299
3300  ======     =================================================================
3301  EINVAL     the target is unknown, or the combination of features is invalid.
3302  ENOENT     a features bit specified is unknown.
3303  ======     =================================================================
3304
3305This tells KVM what type of CPU to present to the guest, and what
3306optional features it should have.  This will cause a reset of the cpu
3307registers to their initial values.  If this is not called, KVM_RUN will
3308return ENOEXEC for that vcpu.
3309
3310The initial values are defined as:
3311	- Processor state:
3312		* AArch64: EL1h, D, A, I and F bits set. All other bits
3313		  are cleared.
3314		* AArch32: SVC, A, I and F bits set. All other bits are
3315		  cleared.
3316	- General Purpose registers, including PC and SP: set to 0
3317	- FPSIMD/NEON registers: set to 0
3318	- SVE registers: set to 0
3319	- System registers: Reset to their architecturally defined
3320	  values as for a warm reset to EL1 (resp. SVC)
3321
3322Note that because some registers reflect machine topology, all vcpus
3323should be created before this ioctl is invoked.
3324
3325Userspace can call this function multiple times for a given vcpu, including
3326after the vcpu has been run. This will reset the vcpu to its initial
3327state. All calls to this function after the initial call must use the same
3328target and same set of feature flags, otherwise EINVAL will be returned.
3329
3330Possible features:
3331
3332	- KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
3333	  Depends on KVM_CAP_ARM_PSCI.  If not set, the CPU will be powered on
3334	  and execute guest code when KVM_RUN is called.
3335	- KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
3336	  Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
3337	- KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
3338          backward compatible with v0.2) for the CPU.
3339	  Depends on KVM_CAP_ARM_PSCI_0_2.
3340	- KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
3341	  Depends on KVM_CAP_ARM_PMU_V3.
3342
3343	- KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication
3344	  for arm64 only.
3345	  Depends on KVM_CAP_ARM_PTRAUTH_ADDRESS.
3346	  If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3347	  both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3348	  KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3349	  requested.
3350
3351	- KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication
3352	  for arm64 only.
3353	  Depends on KVM_CAP_ARM_PTRAUTH_GENERIC.
3354	  If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3355	  both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3356	  KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3357	  requested.
3358
3359	- KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only).
3360	  Depends on KVM_CAP_ARM_SVE.
3361	  Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3362
3363	   * After KVM_ARM_VCPU_INIT:
3364
3365	      - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the
3366	        initial value of this pseudo-register indicates the best set of
3367	        vector lengths possible for a vcpu on this host.
3368
3369	   * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3370
3371	      - KVM_RUN and KVM_GET_REG_LIST are not available;
3372
3373	      - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access
3374	        the scalable archietctural SVE registers
3375	        KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or
3376	        KVM_REG_ARM64_SVE_FFR;
3377
3378	      - KVM_REG_ARM64_SVE_VLS may optionally be written using
3379	        KVM_SET_ONE_REG, to modify the set of vector lengths available
3380	        for the vcpu.
3381
3382	   * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3383
3384	      - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can
3385	        no longer be written using KVM_SET_ONE_REG.
3386
33874.83 KVM_ARM_PREFERRED_TARGET
3388-----------------------------
3389
3390:Capability: basic
3391:Architectures: arm, arm64
3392:Type: vm ioctl
3393:Parameters: struct kvm_vcpu_init (out)
3394:Returns: 0 on success; -1 on error
3395
3396Errors:
3397
3398  ======     ==========================================
3399  ENODEV     no preferred target available for the host
3400  ======     ==========================================
3401
3402This queries KVM for preferred CPU target type which can be emulated
3403by KVM on underlying host.
3404
3405The ioctl returns struct kvm_vcpu_init instance containing information
3406about preferred CPU target type and recommended features for it.  The
3407kvm_vcpu_init->features bitmap returned will have feature bits set if
3408the preferred target recommends setting these features, but this is
3409not mandatory.
3410
3411The information returned by this ioctl can be used to prepare an instance
3412of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
3413VCPU matching underlying host.
3414
3415
34164.84 KVM_GET_REG_LIST
3417---------------------
3418
3419:Capability: basic
3420:Architectures: arm, arm64, mips
3421:Type: vcpu ioctl
3422:Parameters: struct kvm_reg_list (in/out)
3423:Returns: 0 on success; -1 on error
3424
3425Errors:
3426
3427  =====      ==============================================================
3428  E2BIG      the reg index list is too big to fit in the array specified by
3429             the user (the number required will be written into n).
3430  =====      ==============================================================
3431
3432::
3433
3434  struct kvm_reg_list {
3435	__u64 n; /* number of registers in reg[] */
3436	__u64 reg[0];
3437  };
3438
3439This ioctl returns the guest registers that are supported for the
3440KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
3441
3442
34434.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
3444-----------------------------------------
3445
3446:Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
3447:Architectures: arm, arm64
3448:Type: vm ioctl
3449:Parameters: struct kvm_arm_device_address (in)
3450:Returns: 0 on success, -1 on error
3451
3452Errors:
3453
3454  ======  ============================================
3455  ENODEV  The device id is unknown
3456  ENXIO   Device not supported on current system
3457  EEXIST  Address already set
3458  E2BIG   Address outside guest physical address space
3459  EBUSY   Address overlaps with other device range
3460  ======  ============================================
3461
3462::
3463
3464  struct kvm_arm_device_addr {
3465	__u64 id;
3466	__u64 addr;
3467  };
3468
3469Specify a device address in the guest's physical address space where guests
3470can access emulated or directly exposed devices, which the host kernel needs
3471to know about. The id field is an architecture specific identifier for a
3472specific device.
3473
3474ARM/arm64 divides the id field into two parts, a device id and an
3475address type id specific to the individual device::
3476
3477  bits:  | 63        ...       32 | 31    ...    16 | 15    ...    0 |
3478  field: |        0x00000000      |     device id   |  addr type id  |
3479
3480ARM/arm64 currently only require this when using the in-kernel GIC
3481support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
3482as the device id.  When setting the base address for the guest's
3483mapping of the VGIC virtual CPU and distributor interface, the ioctl
3484must be called after calling KVM_CREATE_IRQCHIP, but before calling
3485KVM_RUN on any of the VCPUs.  Calling this ioctl twice for any of the
3486base addresses will return -EEXIST.
3487
3488Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
3489should be used instead.
3490
3491
34924.86 KVM_PPC_RTAS_DEFINE_TOKEN
3493------------------------------
3494
3495:Capability: KVM_CAP_PPC_RTAS
3496:Architectures: ppc
3497:Type: vm ioctl
3498:Parameters: struct kvm_rtas_token_args
3499:Returns: 0 on success, -1 on error
3500
3501Defines a token value for a RTAS (Run Time Abstraction Services)
3502service in order to allow it to be handled in the kernel.  The
3503argument struct gives the name of the service, which must be the name
3504of a service that has a kernel-side implementation.  If the token
3505value is non-zero, it will be associated with that service, and
3506subsequent RTAS calls by the guest specifying that token will be
3507handled by the kernel.  If the token value is 0, then any token
3508associated with the service will be forgotten, and subsequent RTAS
3509calls by the guest for that service will be passed to userspace to be
3510handled.
3511
35124.87 KVM_SET_GUEST_DEBUG
3513------------------------
3514
3515:Capability: KVM_CAP_SET_GUEST_DEBUG
3516:Architectures: x86, s390, ppc, arm64
3517:Type: vcpu ioctl
3518:Parameters: struct kvm_guest_debug (in)
3519:Returns: 0 on success; -1 on error
3520
3521::
3522
3523  struct kvm_guest_debug {
3524       __u32 control;
3525       __u32 pad;
3526       struct kvm_guest_debug_arch arch;
3527  };
3528
3529Set up the processor specific debug registers and configure vcpu for
3530handling guest debug events. There are two parts to the structure, the
3531first a control bitfield indicates the type of debug events to handle
3532when running. Common control bits are:
3533
3534  - KVM_GUESTDBG_ENABLE:        guest debugging is enabled
3535  - KVM_GUESTDBG_SINGLESTEP:    the next run should single-step
3536
3537The top 16 bits of the control field are architecture specific control
3538flags which can include the following:
3539
3540  - KVM_GUESTDBG_USE_SW_BP:     using software breakpoints [x86, arm64]
3541  - KVM_GUESTDBG_USE_HW_BP:     using hardware breakpoints [x86, s390]
3542  - KVM_GUESTDBG_USE_HW:        using hardware debug events [arm64]
3543  - KVM_GUESTDBG_INJECT_DB:     inject DB type exception [x86]
3544  - KVM_GUESTDBG_INJECT_BP:     inject BP type exception [x86]
3545  - KVM_GUESTDBG_EXIT_PENDING:  trigger an immediate guest exit [s390]
3546  - KVM_GUESTDBG_BLOCKIRQ:      avoid injecting interrupts/NMI/SMI [x86]
3547
3548For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
3549are enabled in memory so we need to ensure breakpoint exceptions are
3550correctly trapped and the KVM run loop exits at the breakpoint and not
3551running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
3552we need to ensure the guest vCPUs architecture specific registers are
3553updated to the correct (supplied) values.
3554
3555The second part of the structure is architecture specific and
3556typically contains a set of debug registers.
3557
3558For arm64 the number of debug registers is implementation defined and
3559can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
3560KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
3561indicating the number of supported registers.
3562
3563For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether
3564the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported.
3565
3566Also when supported, KVM_CAP_SET_GUEST_DEBUG2 capability indicates the
3567supported KVM_GUESTDBG_* bits in the control field.
3568
3569When debug events exit the main run loop with the reason
3570KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
3571structure containing architecture specific debug information.
3572
35734.88 KVM_GET_EMULATED_CPUID
3574---------------------------
3575
3576:Capability: KVM_CAP_EXT_EMUL_CPUID
3577:Architectures: x86
3578:Type: system ioctl
3579:Parameters: struct kvm_cpuid2 (in/out)
3580:Returns: 0 on success, -1 on error
3581
3582::
3583
3584  struct kvm_cpuid2 {
3585	__u32 nent;
3586	__u32 flags;
3587	struct kvm_cpuid_entry2 entries[0];
3588  };
3589
3590The member 'flags' is used for passing flags from userspace.
3591
3592::
3593
3594  #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		BIT(0)
3595  #define KVM_CPUID_FLAG_STATEFUL_FUNC		BIT(1) /* deprecated */
3596  #define KVM_CPUID_FLAG_STATE_READ_NEXT		BIT(2) /* deprecated */
3597
3598  struct kvm_cpuid_entry2 {
3599	__u32 function;
3600	__u32 index;
3601	__u32 flags;
3602	__u32 eax;
3603	__u32 ebx;
3604	__u32 ecx;
3605	__u32 edx;
3606	__u32 padding[3];
3607  };
3608
3609This ioctl returns x86 cpuid features which are emulated by
3610kvm.Userspace can use the information returned by this ioctl to query
3611which features are emulated by kvm instead of being present natively.
3612
3613Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
3614structure with the 'nent' field indicating the number of entries in
3615the variable-size array 'entries'. If the number of entries is too low
3616to describe the cpu capabilities, an error (E2BIG) is returned. If the
3617number is too high, the 'nent' field is adjusted and an error (ENOMEM)
3618is returned. If the number is just right, the 'nent' field is adjusted
3619to the number of valid entries in the 'entries' array, which is then
3620filled.
3621
3622The entries returned are the set CPUID bits of the respective features
3623which kvm emulates, as returned by the CPUID instruction, with unknown
3624or unsupported feature bits cleared.
3625
3626Features like x2apic, for example, may not be present in the host cpu
3627but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
3628emulated efficiently and thus not included here.
3629
3630The fields in each entry are defined as follows:
3631
3632  function:
3633	 the eax value used to obtain the entry
3634  index:
3635	 the ecx value used to obtain the entry (for entries that are
3636         affected by ecx)
3637  flags:
3638    an OR of zero or more of the following:
3639
3640        KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
3641           if the index field is valid
3642
3643   eax, ebx, ecx, edx:
3644
3645         the values returned by the cpuid instruction for
3646         this function/index combination
3647
36484.89 KVM_S390_MEM_OP
3649--------------------
3650
3651:Capability: KVM_CAP_S390_MEM_OP
3652:Architectures: s390
3653:Type: vcpu ioctl
3654:Parameters: struct kvm_s390_mem_op (in)
3655:Returns: = 0 on success,
3656          < 0 on generic error (e.g. -EFAULT or -ENOMEM),
3657          > 0 if an exception occurred while walking the page tables
3658
3659Read or write data from/to the logical (virtual) memory of a VCPU.
3660
3661Parameters are specified via the following structure::
3662
3663  struct kvm_s390_mem_op {
3664	__u64 gaddr;		/* the guest address */
3665	__u64 flags;		/* flags */
3666	__u32 size;		/* amount of bytes */
3667	__u32 op;		/* type of operation */
3668	__u64 buf;		/* buffer in userspace */
3669	__u8 ar;		/* the access register number */
3670	__u8 reserved[31];	/* should be set to 0 */
3671  };
3672
3673The type of operation is specified in the "op" field. It is either
3674KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or
3675KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The
3676KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check
3677whether the corresponding memory access would create an access exception
3678(without touching the data in the memory at the destination). In case an
3679access exception occurred while walking the MMU tables of the guest, the
3680ioctl returns a positive error number to indicate the type of exception.
3681This exception is also raised directly at the corresponding VCPU if the
3682flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field.
3683
3684The start address of the memory region has to be specified in the "gaddr"
3685field, and the length of the region in the "size" field (which must not
3686be 0). The maximum value for "size" can be obtained by checking the
3687KVM_CAP_S390_MEM_OP capability. "buf" is the buffer supplied by the
3688userspace application where the read data should be written to for
3689KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written is
3690stored for a KVM_S390_MEMOP_LOGICAL_WRITE. When KVM_S390_MEMOP_F_CHECK_ONLY
3691is specified, "buf" is unused and can be NULL. "ar" designates the access
3692register number to be used; the valid range is 0..15.
3693
3694The "reserved" field is meant for future extensions. It is not used by
3695KVM with the currently defined set of flags.
3696
36974.90 KVM_S390_GET_SKEYS
3698-----------------------
3699
3700:Capability: KVM_CAP_S390_SKEYS
3701:Architectures: s390
3702:Type: vm ioctl
3703:Parameters: struct kvm_s390_skeys
3704:Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
3705          keys, negative value on error
3706
3707This ioctl is used to get guest storage key values on the s390
3708architecture. The ioctl takes parameters via the kvm_s390_skeys struct::
3709
3710  struct kvm_s390_skeys {
3711	__u64 start_gfn;
3712	__u64 count;
3713	__u64 skeydata_addr;
3714	__u32 flags;
3715	__u32 reserved[9];
3716  };
3717
3718The start_gfn field is the number of the first guest frame whose storage keys
3719you want to get.
3720
3721The count field is the number of consecutive frames (starting from start_gfn)
3722whose storage keys to get. The count field must be at least 1 and the maximum
3723allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
3724will cause the ioctl to return -EINVAL.
3725
3726The skeydata_addr field is the address to a buffer large enough to hold count
3727bytes. This buffer will be filled with storage key data by the ioctl.
3728
37294.91 KVM_S390_SET_SKEYS
3730-----------------------
3731
3732:Capability: KVM_CAP_S390_SKEYS
3733:Architectures: s390
3734:Type: vm ioctl
3735:Parameters: struct kvm_s390_skeys
3736:Returns: 0 on success, negative value on error
3737
3738This ioctl is used to set guest storage key values on the s390
3739architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
3740See section on KVM_S390_GET_SKEYS for struct definition.
3741
3742The start_gfn field is the number of the first guest frame whose storage keys
3743you want to set.
3744
3745The count field is the number of consecutive frames (starting from start_gfn)
3746whose storage keys to get. The count field must be at least 1 and the maximum
3747allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
3748will cause the ioctl to return -EINVAL.
3749
3750The skeydata_addr field is the address to a buffer containing count bytes of
3751storage keys. Each byte in the buffer will be set as the storage key for a
3752single frame starting at start_gfn for count frames.
3753
3754Note: If any architecturally invalid key value is found in the given data then
3755the ioctl will return -EINVAL.
3756
37574.92 KVM_S390_IRQ
3758-----------------
3759
3760:Capability: KVM_CAP_S390_INJECT_IRQ
3761:Architectures: s390
3762:Type: vcpu ioctl
3763:Parameters: struct kvm_s390_irq (in)
3764:Returns: 0 on success, -1 on error
3765
3766Errors:
3767
3768
3769  ======  =================================================================
3770  EINVAL  interrupt type is invalid
3771          type is KVM_S390_SIGP_STOP and flag parameter is invalid value,
3772          type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
3773          than the maximum of VCPUs
3774  EBUSY   type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped,
3775          type is KVM_S390_SIGP_STOP and a stop irq is already pending,
3776          type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
3777          is already pending
3778  ======  =================================================================
3779
3780Allows to inject an interrupt to the guest.
3781
3782Using struct kvm_s390_irq as a parameter allows
3783to inject additional payload which is not
3784possible via KVM_S390_INTERRUPT.
3785
3786Interrupt parameters are passed via kvm_s390_irq::
3787
3788  struct kvm_s390_irq {
3789	__u64 type;
3790	union {
3791		struct kvm_s390_io_info io;
3792		struct kvm_s390_ext_info ext;
3793		struct kvm_s390_pgm_info pgm;
3794		struct kvm_s390_emerg_info emerg;
3795		struct kvm_s390_extcall_info extcall;
3796		struct kvm_s390_prefix_info prefix;
3797		struct kvm_s390_stop_info stop;
3798		struct kvm_s390_mchk_info mchk;
3799		char reserved[64];
3800	} u;
3801  };
3802
3803type can be one of the following:
3804
3805- KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
3806- KVM_S390_PROGRAM_INT - program check; parameters in .pgm
3807- KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
3808- KVM_S390_RESTART - restart; no parameters
3809- KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
3810- KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
3811- KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
3812- KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
3813- KVM_S390_MCHK - machine check interrupt; parameters in .mchk
3814
3815This is an asynchronous vcpu ioctl and can be invoked from any thread.
3816
38174.94 KVM_S390_GET_IRQ_STATE
3818---------------------------
3819
3820:Capability: KVM_CAP_S390_IRQ_STATE
3821:Architectures: s390
3822:Type: vcpu ioctl
3823:Parameters: struct kvm_s390_irq_state (out)
3824:Returns: >= number of bytes copied into buffer,
3825          -EINVAL if buffer size is 0,
3826          -ENOBUFS if buffer size is too small to fit all pending interrupts,
3827          -EFAULT if the buffer address was invalid
3828
3829This ioctl allows userspace to retrieve the complete state of all currently
3830pending interrupts in a single buffer. Use cases include migration
3831and introspection. The parameter structure contains the address of a
3832userspace buffer and its length::
3833
3834  struct kvm_s390_irq_state {
3835	__u64 buf;
3836	__u32 flags;        /* will stay unused for compatibility reasons */
3837	__u32 len;
3838	__u32 reserved[4];  /* will stay unused for compatibility reasons */
3839  };
3840
3841Userspace passes in the above struct and for each pending interrupt a
3842struct kvm_s390_irq is copied to the provided buffer.
3843
3844The structure contains a flags and a reserved field for future extensions. As
3845the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
3846reserved, these fields can not be used in the future without breaking
3847compatibility.
3848
3849If -ENOBUFS is returned the buffer provided was too small and userspace
3850may retry with a bigger buffer.
3851
38524.95 KVM_S390_SET_IRQ_STATE
3853---------------------------
3854
3855:Capability: KVM_CAP_S390_IRQ_STATE
3856:Architectures: s390
3857:Type: vcpu ioctl
3858:Parameters: struct kvm_s390_irq_state (in)
3859:Returns: 0 on success,
3860          -EFAULT if the buffer address was invalid,
3861          -EINVAL for an invalid buffer length (see below),
3862          -EBUSY if there were already interrupts pending,
3863          errors occurring when actually injecting the
3864          interrupt. See KVM_S390_IRQ.
3865
3866This ioctl allows userspace to set the complete state of all cpu-local
3867interrupts currently pending for the vcpu. It is intended for restoring
3868interrupt state after a migration. The input parameter is a userspace buffer
3869containing a struct kvm_s390_irq_state::
3870
3871  struct kvm_s390_irq_state {
3872	__u64 buf;
3873	__u32 flags;        /* will stay unused for compatibility reasons */
3874	__u32 len;
3875	__u32 reserved[4];  /* will stay unused for compatibility reasons */
3876  };
3877
3878The restrictions for flags and reserved apply as well.
3879(see KVM_S390_GET_IRQ_STATE)
3880
3881The userspace memory referenced by buf contains a struct kvm_s390_irq
3882for each interrupt to be injected into the guest.
3883If one of the interrupts could not be injected for some reason the
3884ioctl aborts.
3885
3886len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
3887and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
3888which is the maximum number of possibly pending cpu-local interrupts.
3889
38904.96 KVM_SMI
3891------------
3892
3893:Capability: KVM_CAP_X86_SMM
3894:Architectures: x86
3895:Type: vcpu ioctl
3896:Parameters: none
3897:Returns: 0 on success, -1 on error
3898
3899Queues an SMI on the thread's vcpu.
3900
39014.97 KVM_X86_SET_MSR_FILTER
3902----------------------------
3903
3904:Capability: KVM_X86_SET_MSR_FILTER
3905:Architectures: x86
3906:Type: vm ioctl
3907:Parameters: struct kvm_msr_filter
3908:Returns: 0 on success, < 0 on error
3909
3910::
3911
3912  struct kvm_msr_filter_range {
3913  #define KVM_MSR_FILTER_READ  (1 << 0)
3914  #define KVM_MSR_FILTER_WRITE (1 << 1)
3915	__u32 flags;
3916	__u32 nmsrs; /* number of msrs in bitmap */
3917	__u32 base;  /* MSR index the bitmap starts at */
3918	__u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
3919  };
3920
3921  #define KVM_MSR_FILTER_MAX_RANGES 16
3922  struct kvm_msr_filter {
3923  #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
3924  #define KVM_MSR_FILTER_DEFAULT_DENY  (1 << 0)
3925	__u32 flags;
3926	struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
3927  };
3928
3929flags values for ``struct kvm_msr_filter_range``:
3930
3931``KVM_MSR_FILTER_READ``
3932
3933  Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap
3934  indicates that a read should immediately fail, while a 1 indicates that
3935  a read for a particular MSR should be handled regardless of the default
3936  filter action.
3937
3938``KVM_MSR_FILTER_WRITE``
3939
3940  Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap
3941  indicates that a write should immediately fail, while a 1 indicates that
3942  a write for a particular MSR should be handled regardless of the default
3943  filter action.
3944
3945``KVM_MSR_FILTER_READ | KVM_MSR_FILTER_WRITE``
3946
3947  Filter both read and write accesses to MSRs using the given bitmap. A 0
3948  in the bitmap indicates that both reads and writes should immediately fail,
3949  while a 1 indicates that reads and writes for a particular MSR are not
3950  filtered by this range.
3951
3952flags values for ``struct kvm_msr_filter``:
3953
3954``KVM_MSR_FILTER_DEFAULT_ALLOW``
3955
3956  If no filter range matches an MSR index that is getting accessed, KVM will
3957  fall back to allowing access to the MSR.
3958
3959``KVM_MSR_FILTER_DEFAULT_DENY``
3960
3961  If no filter range matches an MSR index that is getting accessed, KVM will
3962  fall back to rejecting access to the MSR. In this mode, all MSRs that should
3963  be processed by KVM need to explicitly be marked as allowed in the bitmaps.
3964
3965This ioctl allows user space to define up to 16 bitmaps of MSR ranges to
3966specify whether a certain MSR access should be explicitly filtered for or not.
3967
3968If this ioctl has never been invoked, MSR accesses are not guarded and the
3969default KVM in-kernel emulation behavior is fully preserved.
3970
3971Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR
3972filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes
3973an error.
3974
3975As soon as the filtering is in place, every MSR access is processed through
3976the filtering except for accesses to the x2APIC MSRs (from 0x800 to 0x8ff);
3977x2APIC MSRs are always allowed, independent of the ``default_allow`` setting,
3978and their behavior depends on the ``X2APIC_ENABLE`` bit of the APIC base
3979register.
3980
3981If a bit is within one of the defined ranges, read and write accesses are
3982guarded by the bitmap's value for the MSR index if the kind of access
3983is included in the ``struct kvm_msr_filter_range`` flags.  If no range
3984cover this particular access, the behavior is determined by the flags
3985field in the kvm_msr_filter struct: ``KVM_MSR_FILTER_DEFAULT_ALLOW``
3986and ``KVM_MSR_FILTER_DEFAULT_DENY``.
3987
3988Each bitmap range specifies a range of MSRs to potentially allow access on.
3989The range goes from MSR index [base .. base+nmsrs]. The flags field
3990indicates whether reads, writes or both reads and writes are filtered
3991by setting a 1 bit in the bitmap for the corresponding MSR index.
3992
3993If an MSR access is not permitted through the filtering, it generates a
3994#GP inside the guest. When combined with KVM_CAP_X86_USER_SPACE_MSR, that
3995allows user space to deflect and potentially handle various MSR accesses
3996into user space.
3997
3998If a vCPU is in running state while this ioctl is invoked, the vCPU may
3999experience inconsistent filtering behavior on MSR accesses.
4000
40014.98 KVM_CREATE_SPAPR_TCE_64
4002----------------------------
4003
4004:Capability: KVM_CAP_SPAPR_TCE_64
4005:Architectures: powerpc
4006:Type: vm ioctl
4007:Parameters: struct kvm_create_spapr_tce_64 (in)
4008:Returns: file descriptor for manipulating the created TCE table
4009
4010This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
4011windows, described in 4.62 KVM_CREATE_SPAPR_TCE
4012
4013This capability uses extended struct in ioctl interface::
4014
4015  /* for KVM_CAP_SPAPR_TCE_64 */
4016  struct kvm_create_spapr_tce_64 {
4017	__u64 liobn;
4018	__u32 page_shift;
4019	__u32 flags;
4020	__u64 offset;	/* in pages */
4021	__u64 size; 	/* in pages */
4022  };
4023
4024The aim of extension is to support an additional bigger DMA window with
4025a variable page size.
4026KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
4027a bus offset of the corresponding DMA window, @size and @offset are numbers
4028of IOMMU pages.
4029
4030@flags are not used at the moment.
4031
4032The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
4033
40344.99 KVM_REINJECT_CONTROL
4035-------------------------
4036
4037:Capability: KVM_CAP_REINJECT_CONTROL
4038:Architectures: x86
4039:Type: vm ioctl
4040:Parameters: struct kvm_reinject_control (in)
4041:Returns: 0 on success,
4042         -EFAULT if struct kvm_reinject_control cannot be read,
4043         -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
4044
4045i8254 (PIT) has two modes, reinject and !reinject.  The default is reinject,
4046where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
4047vector(s) that i8254 injects.  Reinject mode dequeues a tick and injects its
4048interrupt whenever there isn't a pending interrupt from i8254.
4049!reinject mode injects an interrupt as soon as a tick arrives.
4050
4051::
4052
4053  struct kvm_reinject_control {
4054	__u8 pit_reinject;
4055	__u8 reserved[31];
4056  };
4057
4058pit_reinject = 0 (!reinject mode) is recommended, unless running an old
4059operating system that uses the PIT for timing (e.g. Linux 2.4.x).
4060
40614.100 KVM_PPC_CONFIGURE_V3_MMU
4062------------------------------
4063
4064:Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
4065:Architectures: ppc
4066:Type: vm ioctl
4067:Parameters: struct kvm_ppc_mmuv3_cfg (in)
4068:Returns: 0 on success,
4069         -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
4070         -EINVAL if the configuration is invalid
4071
4072This ioctl controls whether the guest will use radix or HPT (hashed
4073page table) translation, and sets the pointer to the process table for
4074the guest.
4075
4076::
4077
4078  struct kvm_ppc_mmuv3_cfg {
4079	__u64	flags;
4080	__u64	process_table;
4081  };
4082
4083There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
4084KVM_PPC_MMUV3_GTSE.  KVM_PPC_MMUV3_RADIX, if set, configures the guest
4085to use radix tree translation, and if clear, to use HPT translation.
4086KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
4087to be able to use the global TLB and SLB invalidation instructions;
4088if clear, the guest may not use these instructions.
4089
4090The process_table field specifies the address and size of the guest
4091process table, which is in the guest's space.  This field is formatted
4092as the second doubleword of the partition table entry, as defined in
4093the Power ISA V3.00, Book III section 5.7.6.1.
4094
40954.101 KVM_PPC_GET_RMMU_INFO
4096---------------------------
4097
4098:Capability: KVM_CAP_PPC_RADIX_MMU
4099:Architectures: ppc
4100:Type: vm ioctl
4101:Parameters: struct kvm_ppc_rmmu_info (out)
4102:Returns: 0 on success,
4103	 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
4104	 -EINVAL if no useful information can be returned
4105
4106This ioctl returns a structure containing two things: (a) a list
4107containing supported radix tree geometries, and (b) a list that maps
4108page sizes to put in the "AP" (actual page size) field for the tlbie
4109(TLB invalidate entry) instruction.
4110
4111::
4112
4113  struct kvm_ppc_rmmu_info {
4114	struct kvm_ppc_radix_geom {
4115		__u8	page_shift;
4116		__u8	level_bits[4];
4117		__u8	pad[3];
4118	}	geometries[8];
4119	__u32	ap_encodings[8];
4120  };
4121
4122The geometries[] field gives up to 8 supported geometries for the
4123radix page table, in terms of the log base 2 of the smallest page
4124size, and the number of bits indexed at each level of the tree, from
4125the PTE level up to the PGD level in that order.  Any unused entries
4126will have 0 in the page_shift field.
4127
4128The ap_encodings gives the supported page sizes and their AP field
4129encodings, encoded with the AP value in the top 3 bits and the log
4130base 2 of the page size in the bottom 6 bits.
4131
41324.102 KVM_PPC_RESIZE_HPT_PREPARE
4133--------------------------------
4134
4135:Capability: KVM_CAP_SPAPR_RESIZE_HPT
4136:Architectures: powerpc
4137:Type: vm ioctl
4138:Parameters: struct kvm_ppc_resize_hpt (in)
4139:Returns: 0 on successful completion,
4140	 >0 if a new HPT is being prepared, the value is an estimated
4141         number of milliseconds until preparation is complete,
4142         -EFAULT if struct kvm_reinject_control cannot be read,
4143	 -EINVAL if the supplied shift or flags are invalid,
4144	 -ENOMEM if unable to allocate the new HPT,
4145
4146Used to implement the PAPR extension for runtime resizing of a guest's
4147Hashed Page Table (HPT).  Specifically this starts, stops or monitors
4148the preparation of a new potential HPT for the guest, essentially
4149implementing the H_RESIZE_HPT_PREPARE hypercall.
4150
4151::
4152
4153  struct kvm_ppc_resize_hpt {
4154	__u64 flags;
4155	__u32 shift;
4156	__u32 pad;
4157  };
4158
4159If called with shift > 0 when there is no pending HPT for the guest,
4160this begins preparation of a new pending HPT of size 2^(shift) bytes.
4161It then returns a positive integer with the estimated number of
4162milliseconds until preparation is complete.
4163
4164If called when there is a pending HPT whose size does not match that
4165requested in the parameters, discards the existing pending HPT and
4166creates a new one as above.
4167
4168If called when there is a pending HPT of the size requested, will:
4169
4170  * If preparation of the pending HPT is already complete, return 0
4171  * If preparation of the pending HPT has failed, return an error
4172    code, then discard the pending HPT.
4173  * If preparation of the pending HPT is still in progress, return an
4174    estimated number of milliseconds until preparation is complete.
4175
4176If called with shift == 0, discards any currently pending HPT and
4177returns 0 (i.e. cancels any in-progress preparation).
4178
4179flags is reserved for future expansion, currently setting any bits in
4180flags will result in an -EINVAL.
4181
4182Normally this will be called repeatedly with the same parameters until
4183it returns <= 0.  The first call will initiate preparation, subsequent
4184ones will monitor preparation until it completes or fails.
4185
41864.103 KVM_PPC_RESIZE_HPT_COMMIT
4187-------------------------------
4188
4189:Capability: KVM_CAP_SPAPR_RESIZE_HPT
4190:Architectures: powerpc
4191:Type: vm ioctl
4192:Parameters: struct kvm_ppc_resize_hpt (in)
4193:Returns: 0 on successful completion,
4194         -EFAULT if struct kvm_reinject_control cannot be read,
4195	 -EINVAL if the supplied shift or flags are invalid,
4196	 -ENXIO is there is no pending HPT, or the pending HPT doesn't
4197         have the requested size,
4198	 -EBUSY if the pending HPT is not fully prepared,
4199	 -ENOSPC if there was a hash collision when moving existing
4200         HPT entries to the new HPT,
4201	 -EIO on other error conditions
4202
4203Used to implement the PAPR extension for runtime resizing of a guest's
4204Hashed Page Table (HPT).  Specifically this requests that the guest be
4205transferred to working with the new HPT, essentially implementing the
4206H_RESIZE_HPT_COMMIT hypercall.
4207
4208::
4209
4210  struct kvm_ppc_resize_hpt {
4211	__u64 flags;
4212	__u32 shift;
4213	__u32 pad;
4214  };
4215
4216This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
4217returned 0 with the same parameters.  In other cases
4218KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
4219-EBUSY, though others may be possible if the preparation was started,
4220but failed).
4221
4222This will have undefined effects on the guest if it has not already
4223placed itself in a quiescent state where no vcpu will make MMU enabled
4224memory accesses.
4225
4226On succsful completion, the pending HPT will become the guest's active
4227HPT and the previous HPT will be discarded.
4228
4229On failure, the guest will still be operating on its previous HPT.
4230
42314.104 KVM_X86_GET_MCE_CAP_SUPPORTED
4232-----------------------------------
4233
4234:Capability: KVM_CAP_MCE
4235:Architectures: x86
4236:Type: system ioctl
4237:Parameters: u64 mce_cap (out)
4238:Returns: 0 on success, -1 on error
4239
4240Returns supported MCE capabilities. The u64 mce_cap parameter
4241has the same format as the MSR_IA32_MCG_CAP register. Supported
4242capabilities will have the corresponding bits set.
4243
42444.105 KVM_X86_SETUP_MCE
4245-----------------------
4246
4247:Capability: KVM_CAP_MCE
4248:Architectures: x86
4249:Type: vcpu ioctl
4250:Parameters: u64 mcg_cap (in)
4251:Returns: 0 on success,
4252         -EFAULT if u64 mcg_cap cannot be read,
4253         -EINVAL if the requested number of banks is invalid,
4254         -EINVAL if requested MCE capability is not supported.
4255
4256Initializes MCE support for use. The u64 mcg_cap parameter
4257has the same format as the MSR_IA32_MCG_CAP register and
4258specifies which capabilities should be enabled. The maximum
4259supported number of error-reporting banks can be retrieved when
4260checking for KVM_CAP_MCE. The supported capabilities can be
4261retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
4262
42634.106 KVM_X86_SET_MCE
4264---------------------
4265
4266:Capability: KVM_CAP_MCE
4267:Architectures: x86
4268:Type: vcpu ioctl
4269:Parameters: struct kvm_x86_mce (in)
4270:Returns: 0 on success,
4271         -EFAULT if struct kvm_x86_mce cannot be read,
4272         -EINVAL if the bank number is invalid,
4273         -EINVAL if VAL bit is not set in status field.
4274
4275Inject a machine check error (MCE) into the guest. The input
4276parameter is::
4277
4278  struct kvm_x86_mce {
4279	__u64 status;
4280	__u64 addr;
4281	__u64 misc;
4282	__u64 mcg_status;
4283	__u8 bank;
4284	__u8 pad1[7];
4285	__u64 pad2[3];
4286  };
4287
4288If the MCE being reported is an uncorrected error, KVM will
4289inject it as an MCE exception into the guest. If the guest
4290MCG_STATUS register reports that an MCE is in progress, KVM
4291causes an KVM_EXIT_SHUTDOWN vmexit.
4292
4293Otherwise, if the MCE is a corrected error, KVM will just
4294store it in the corresponding bank (provided this bank is
4295not holding a previously reported uncorrected error).
4296
42974.107 KVM_S390_GET_CMMA_BITS
4298----------------------------
4299
4300:Capability: KVM_CAP_S390_CMMA_MIGRATION
4301:Architectures: s390
4302:Type: vm ioctl
4303:Parameters: struct kvm_s390_cmma_log (in, out)
4304:Returns: 0 on success, a negative value on error
4305
4306This ioctl is used to get the values of the CMMA bits on the s390
4307architecture. It is meant to be used in two scenarios:
4308
4309- During live migration to save the CMMA values. Live migration needs
4310  to be enabled via the KVM_REQ_START_MIGRATION VM property.
4311- To non-destructively peek at the CMMA values, with the flag
4312  KVM_S390_CMMA_PEEK set.
4313
4314The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
4315values are written to a buffer whose location is indicated via the "values"
4316member in the kvm_s390_cmma_log struct.  The values in the input struct are
4317also updated as needed.
4318
4319Each CMMA value takes up one byte.
4320
4321::
4322
4323  struct kvm_s390_cmma_log {
4324	__u64 start_gfn;
4325	__u32 count;
4326	__u32 flags;
4327	union {
4328		__u64 remaining;
4329		__u64 mask;
4330	};
4331	__u64 values;
4332  };
4333
4334start_gfn is the number of the first guest frame whose CMMA values are
4335to be retrieved,
4336
4337count is the length of the buffer in bytes,
4338
4339values points to the buffer where the result will be written to.
4340
4341If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
4342KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
4343other ioctls.
4344
4345The result is written in the buffer pointed to by the field values, and
4346the values of the input parameter are updated as follows.
4347
4348Depending on the flags, different actions are performed. The only
4349supported flag so far is KVM_S390_CMMA_PEEK.
4350
4351The default behaviour if KVM_S390_CMMA_PEEK is not set is:
4352start_gfn will indicate the first page frame whose CMMA bits were dirty.
4353It is not necessarily the same as the one passed as input, as clean pages
4354are skipped.
4355
4356count will indicate the number of bytes actually written in the buffer.
4357It can (and very often will) be smaller than the input value, since the
4358buffer is only filled until 16 bytes of clean values are found (which
4359are then not copied in the buffer). Since a CMMA migration block needs
4360the base address and the length, for a total of 16 bytes, we will send
4361back some clean data if there is some dirty data afterwards, as long as
4362the size of the clean data does not exceed the size of the header. This
4363allows to minimize the amount of data to be saved or transferred over
4364the network at the expense of more roundtrips to userspace. The next
4365invocation of the ioctl will skip over all the clean values, saving
4366potentially more than just the 16 bytes we found.
4367
4368If KVM_S390_CMMA_PEEK is set:
4369the existing storage attributes are read even when not in migration
4370mode, and no other action is performed;
4371
4372the output start_gfn will be equal to the input start_gfn,
4373
4374the output count will be equal to the input count, except if the end of
4375memory has been reached.
4376
4377In both cases:
4378the field "remaining" will indicate the total number of dirty CMMA values
4379still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
4380not enabled.
4381
4382mask is unused.
4383
4384values points to the userspace buffer where the result will be stored.
4385
4386This ioctl can fail with -ENOMEM if not enough memory can be allocated to
4387complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
4388KVM_S390_CMMA_PEEK is not set but migration mode was not enabled, with
4389-EFAULT if the userspace address is invalid or if no page table is
4390present for the addresses (e.g. when using hugepages).
4391
43924.108 KVM_S390_SET_CMMA_BITS
4393----------------------------
4394
4395:Capability: KVM_CAP_S390_CMMA_MIGRATION
4396:Architectures: s390
4397:Type: vm ioctl
4398:Parameters: struct kvm_s390_cmma_log (in)
4399:Returns: 0 on success, a negative value on error
4400
4401This ioctl is used to set the values of the CMMA bits on the s390
4402architecture. It is meant to be used during live migration to restore
4403the CMMA values, but there are no restrictions on its use.
4404The ioctl takes parameters via the kvm_s390_cmma_values struct.
4405Each CMMA value takes up one byte.
4406
4407::
4408
4409  struct kvm_s390_cmma_log {
4410	__u64 start_gfn;
4411	__u32 count;
4412	__u32 flags;
4413	union {
4414		__u64 remaining;
4415		__u64 mask;
4416 	};
4417	__u64 values;
4418  };
4419
4420start_gfn indicates the starting guest frame number,
4421
4422count indicates how many values are to be considered in the buffer,
4423
4424flags is not used and must be 0.
4425
4426mask indicates which PGSTE bits are to be considered.
4427
4428remaining is not used.
4429
4430values points to the buffer in userspace where to store the values.
4431
4432This ioctl can fail with -ENOMEM if not enough memory can be allocated to
4433complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
4434the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
4435if the flags field was not 0, with -EFAULT if the userspace address is
4436invalid, if invalid pages are written to (e.g. after the end of memory)
4437or if no page table is present for the addresses (e.g. when using
4438hugepages).
4439
44404.109 KVM_PPC_GET_CPU_CHAR
4441--------------------------
4442
4443:Capability: KVM_CAP_PPC_GET_CPU_CHAR
4444:Architectures: powerpc
4445:Type: vm ioctl
4446:Parameters: struct kvm_ppc_cpu_char (out)
4447:Returns: 0 on successful completion,
4448	 -EFAULT if struct kvm_ppc_cpu_char cannot be written
4449
4450This ioctl gives userspace information about certain characteristics
4451of the CPU relating to speculative execution of instructions and
4452possible information leakage resulting from speculative execution (see
4453CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754).  The information is
4454returned in struct kvm_ppc_cpu_char, which looks like this::
4455
4456  struct kvm_ppc_cpu_char {
4457	__u64	character;		/* characteristics of the CPU */
4458	__u64	behaviour;		/* recommended software behaviour */
4459	__u64	character_mask;		/* valid bits in character */
4460	__u64	behaviour_mask;		/* valid bits in behaviour */
4461  };
4462
4463For extensibility, the character_mask and behaviour_mask fields
4464indicate which bits of character and behaviour have been filled in by
4465the kernel.  If the set of defined bits is extended in future then
4466userspace will be able to tell whether it is running on a kernel that
4467knows about the new bits.
4468
4469The character field describes attributes of the CPU which can help
4470with preventing inadvertent information disclosure - specifically,
4471whether there is an instruction to flash-invalidate the L1 data cache
4472(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
4473to a mode where entries can only be used by the thread that created
4474them, whether the bcctr[l] instruction prevents speculation, and
4475whether a speculation barrier instruction (ori 31,31,0) is provided.
4476
4477The behaviour field describes actions that software should take to
4478prevent inadvertent information disclosure, and thus describes which
4479vulnerabilities the hardware is subject to; specifically whether the
4480L1 data cache should be flushed when returning to user mode from the
4481kernel, and whether a speculation barrier should be placed between an
4482array bounds check and the array access.
4483
4484These fields use the same bit definitions as the new
4485H_GET_CPU_CHARACTERISTICS hypercall.
4486
44874.110 KVM_MEMORY_ENCRYPT_OP
4488---------------------------
4489
4490:Capability: basic
4491:Architectures: x86
4492:Type: vm
4493:Parameters: an opaque platform specific structure (in/out)
4494:Returns: 0 on success; -1 on error
4495
4496If the platform supports creating encrypted VMs then this ioctl can be used
4497for issuing platform-specific memory encryption commands to manage those
4498encrypted VMs.
4499
4500Currently, this ioctl is used for issuing Secure Encrypted Virtualization
4501(SEV) commands on AMD Processors. The SEV commands are defined in
4502Documentation/virt/kvm/amd-memory-encryption.rst.
4503
45044.111 KVM_MEMORY_ENCRYPT_REG_REGION
4505-----------------------------------
4506
4507:Capability: basic
4508:Architectures: x86
4509:Type: system
4510:Parameters: struct kvm_enc_region (in)
4511:Returns: 0 on success; -1 on error
4512
4513This ioctl can be used to register a guest memory region which may
4514contain encrypted data (e.g. guest RAM, SMRAM etc).
4515
4516It is used in the SEV-enabled guest. When encryption is enabled, a guest
4517memory region may contain encrypted data. The SEV memory encryption
4518engine uses a tweak such that two identical plaintext pages, each at
4519different locations will have differing ciphertexts. So swapping or
4520moving ciphertext of those pages will not result in plaintext being
4521swapped. So relocating (or migrating) physical backing pages for the SEV
4522guest will require some additional steps.
4523
4524Note: The current SEV key management spec does not provide commands to
4525swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
4526memory region registered with the ioctl.
4527
45284.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
4529-------------------------------------
4530
4531:Capability: basic
4532:Architectures: x86
4533:Type: system
4534:Parameters: struct kvm_enc_region (in)
4535:Returns: 0 on success; -1 on error
4536
4537This ioctl can be used to unregister the guest memory region registered
4538with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
4539
45404.113 KVM_HYPERV_EVENTFD
4541------------------------
4542
4543:Capability: KVM_CAP_HYPERV_EVENTFD
4544:Architectures: x86
4545:Type: vm ioctl
4546:Parameters: struct kvm_hyperv_eventfd (in)
4547
4548This ioctl (un)registers an eventfd to receive notifications from the guest on
4549the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
4550causing a user exit.  SIGNAL_EVENT hypercall with non-zero event flag number
4551(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
4552
4553::
4554
4555  struct kvm_hyperv_eventfd {
4556	__u32 conn_id;
4557	__s32 fd;
4558	__u32 flags;
4559	__u32 padding[3];
4560  };
4561
4562The conn_id field should fit within 24 bits::
4563
4564  #define KVM_HYPERV_CONN_ID_MASK		0x00ffffff
4565
4566The acceptable values for the flags field are::
4567
4568  #define KVM_HYPERV_EVENTFD_DEASSIGN	(1 << 0)
4569
4570:Returns: 0 on success,
4571 	  -EINVAL if conn_id or flags is outside the allowed range,
4572	  -ENOENT on deassign if the conn_id isn't registered,
4573	  -EEXIST on assign if the conn_id is already registered
4574
45754.114 KVM_GET_NESTED_STATE
4576--------------------------
4577
4578:Capability: KVM_CAP_NESTED_STATE
4579:Architectures: x86
4580:Type: vcpu ioctl
4581:Parameters: struct kvm_nested_state (in/out)
4582:Returns: 0 on success, -1 on error
4583
4584Errors:
4585
4586  =====      =============================================================
4587  E2BIG      the total state size exceeds the value of 'size' specified by
4588             the user; the size required will be written into size.
4589  =====      =============================================================
4590
4591::
4592
4593  struct kvm_nested_state {
4594	__u16 flags;
4595	__u16 format;
4596	__u32 size;
4597
4598	union {
4599		struct kvm_vmx_nested_state_hdr vmx;
4600		struct kvm_svm_nested_state_hdr svm;
4601
4602		/* Pad the header to 128 bytes.  */
4603		__u8 pad[120];
4604	} hdr;
4605
4606	union {
4607		struct kvm_vmx_nested_state_data vmx[0];
4608		struct kvm_svm_nested_state_data svm[0];
4609	} data;
4610  };
4611
4612  #define KVM_STATE_NESTED_GUEST_MODE		0x00000001
4613  #define KVM_STATE_NESTED_RUN_PENDING		0x00000002
4614  #define KVM_STATE_NESTED_EVMCS		0x00000004
4615
4616  #define KVM_STATE_NESTED_FORMAT_VMX		0
4617  #define KVM_STATE_NESTED_FORMAT_SVM		1
4618
4619  #define KVM_STATE_NESTED_VMX_VMCS_SIZE	0x1000
4620
4621  #define KVM_STATE_NESTED_VMX_SMM_GUEST_MODE	0x00000001
4622  #define KVM_STATE_NESTED_VMX_SMM_VMXON	0x00000002
4623
4624  #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001
4625
4626  struct kvm_vmx_nested_state_hdr {
4627	__u64 vmxon_pa;
4628	__u64 vmcs12_pa;
4629
4630	struct {
4631		__u16 flags;
4632	} smm;
4633
4634	__u32 flags;
4635	__u64 preemption_timer_deadline;
4636  };
4637
4638  struct kvm_vmx_nested_state_data {
4639	__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
4640	__u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
4641  };
4642
4643This ioctl copies the vcpu's nested virtualization state from the kernel to
4644userspace.
4645
4646The maximum size of the state can be retrieved by passing KVM_CAP_NESTED_STATE
4647to the KVM_CHECK_EXTENSION ioctl().
4648
46494.115 KVM_SET_NESTED_STATE
4650--------------------------
4651
4652:Capability: KVM_CAP_NESTED_STATE
4653:Architectures: x86
4654:Type: vcpu ioctl
4655:Parameters: struct kvm_nested_state (in)
4656:Returns: 0 on success, -1 on error
4657
4658This copies the vcpu's kvm_nested_state struct from userspace to the kernel.
4659For the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
4660
46614.116 KVM_(UN)REGISTER_COALESCED_MMIO
4662-------------------------------------
4663
4664:Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio)
4665	     KVM_CAP_COALESCED_PIO (for coalesced pio)
4666:Architectures: all
4667:Type: vm ioctl
4668:Parameters: struct kvm_coalesced_mmio_zone
4669:Returns: 0 on success, < 0 on error
4670
4671Coalesced I/O is a performance optimization that defers hardware
4672register write emulation so that userspace exits are avoided.  It is
4673typically used to reduce the overhead of emulating frequently accessed
4674hardware registers.
4675
4676When a hardware register is configured for coalesced I/O, write accesses
4677do not exit to userspace and their value is recorded in a ring buffer
4678that is shared between kernel and userspace.
4679
4680Coalesced I/O is used if one or more write accesses to a hardware
4681register can be deferred until a read or a write to another hardware
4682register on the same device.  This last access will cause a vmexit and
4683userspace will process accesses from the ring buffer before emulating
4684it. That will avoid exiting to userspace on repeated writes.
4685
4686Coalesced pio is based on coalesced mmio. There is little difference
4687between coalesced mmio and pio except that coalesced pio records accesses
4688to I/O ports.
4689
46904.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
4691------------------------------------
4692
4693:Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
4694:Architectures: x86, arm, arm64, mips
4695:Type: vm ioctl
4696:Parameters: struct kvm_clear_dirty_log (in)
4697:Returns: 0 on success, -1 on error
4698
4699::
4700
4701  /* for KVM_CLEAR_DIRTY_LOG */
4702  struct kvm_clear_dirty_log {
4703	__u32 slot;
4704	__u32 num_pages;
4705	__u64 first_page;
4706	union {
4707		void __user *dirty_bitmap; /* one bit per page */
4708		__u64 padding;
4709	};
4710  };
4711
4712The ioctl clears the dirty status of pages in a memory slot, according to
4713the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap
4714field.  Bit 0 of the bitmap corresponds to page "first_page" in the
4715memory slot, and num_pages is the size in bits of the input bitmap.
4716first_page must be a multiple of 64; num_pages must also be a multiple of
471764 unless first_page + num_pages is the size of the memory slot.  For each
4718bit that is set in the input bitmap, the corresponding page is marked "clean"
4719in KVM's dirty bitmap, and dirty tracking is re-enabled for that page
4720(for example via write-protection, or by clearing the dirty bit in
4721a page table entry).
4722
4723If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
4724the address space for which you want to clear the dirty status.  See
4725KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
4726
4727This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
4728is enabled; for more information, see the description of the capability.
4729However, it can always be used as long as KVM_CHECK_EXTENSION confirms
4730that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present.
4731
47324.118 KVM_GET_SUPPORTED_HV_CPUID
4733--------------------------------
4734
4735:Capability: KVM_CAP_HYPERV_CPUID (vcpu), KVM_CAP_SYS_HYPERV_CPUID (system)
4736:Architectures: x86
4737:Type: system ioctl, vcpu ioctl
4738:Parameters: struct kvm_cpuid2 (in/out)
4739:Returns: 0 on success, -1 on error
4740
4741::
4742
4743  struct kvm_cpuid2 {
4744	__u32 nent;
4745	__u32 padding;
4746	struct kvm_cpuid_entry2 entries[0];
4747  };
4748
4749  struct kvm_cpuid_entry2 {
4750	__u32 function;
4751	__u32 index;
4752	__u32 flags;
4753	__u32 eax;
4754	__u32 ebx;
4755	__u32 ecx;
4756	__u32 edx;
4757	__u32 padding[3];
4758  };
4759
4760This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in
4761KVM.  Userspace can use the information returned by this ioctl to construct
4762cpuid information presented to guests consuming Hyper-V enlightenments (e.g.
4763Windows or Hyper-V guests).
4764
4765CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level
4766Functional Specification (TLFS). These leaves can't be obtained with
4767KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature
4768leaves (0x40000000, 0x40000001).
4769
4770Currently, the following list of CPUID leaves are returned:
4771
4772 - HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS
4773 - HYPERV_CPUID_INTERFACE
4774 - HYPERV_CPUID_VERSION
4775 - HYPERV_CPUID_FEATURES
4776 - HYPERV_CPUID_ENLIGHTMENT_INFO
4777 - HYPERV_CPUID_IMPLEMENT_LIMITS
4778 - HYPERV_CPUID_NESTED_FEATURES
4779 - HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS
4780 - HYPERV_CPUID_SYNDBG_INTERFACE
4781 - HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES
4782
4783Userspace invokes KVM_GET_SUPPORTED_HV_CPUID by passing a kvm_cpuid2 structure
4784with the 'nent' field indicating the number of entries in the variable-size
4785array 'entries'.  If the number of entries is too low to describe all Hyper-V
4786feature leaves, an error (E2BIG) is returned. If the number is more or equal
4787to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the
4788number of valid entries in the 'entries' array, which is then filled.
4789
4790'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved,
4791userspace should not expect to get any particular value there.
4792
4793Note, vcpu version of KVM_GET_SUPPORTED_HV_CPUID is currently deprecated. Unlike
4794system ioctl which exposes all supported feature bits unconditionally, vcpu
4795version has the following quirks:
4796
4797- HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED
4798  feature bit are only exposed when Enlightened VMCS was previously enabled
4799  on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
4800- HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC.
4801  (presumes KVM_CREATE_IRQCHIP has already been called).
4802
48034.119 KVM_ARM_VCPU_FINALIZE
4804---------------------------
4805
4806:Architectures: arm, arm64
4807:Type: vcpu ioctl
4808:Parameters: int feature (in)
4809:Returns: 0 on success, -1 on error
4810
4811Errors:
4812
4813  ======     ==============================================================
4814  EPERM      feature not enabled, needs configuration, or already finalized
4815  EINVAL     feature unknown or not present
4816  ======     ==============================================================
4817
4818Recognised values for feature:
4819
4820  =====      ===========================================
4821  arm64      KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE)
4822  =====      ===========================================
4823
4824Finalizes the configuration of the specified vcpu feature.
4825
4826The vcpu must already have been initialised, enabling the affected feature, by
4827means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in
4828features[].
4829
4830For affected vcpu features, this is a mandatory step that must be performed
4831before the vcpu is fully usable.
4832
4833Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be
4834configured by use of ioctls such as KVM_SET_ONE_REG.  The exact configuration
4835that should be performaned and how to do it are feature-dependent.
4836
4837Other calls that depend on a particular feature being finalized, such as
4838KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with
4839-EPERM unless the feature has already been finalized by means of a
4840KVM_ARM_VCPU_FINALIZE call.
4841
4842See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization
4843using this ioctl.
4844
48454.120 KVM_SET_PMU_EVENT_FILTER
4846------------------------------
4847
4848:Capability: KVM_CAP_PMU_EVENT_FILTER
4849:Architectures: x86
4850:Type: vm ioctl
4851:Parameters: struct kvm_pmu_event_filter (in)
4852:Returns: 0 on success, -1 on error
4853
4854::
4855
4856  struct kvm_pmu_event_filter {
4857	__u32 action;
4858	__u32 nevents;
4859	__u32 fixed_counter_bitmap;
4860	__u32 flags;
4861	__u32 pad[4];
4862	__u64 events[0];
4863  };
4864
4865This ioctl restricts the set of PMU events that the guest can program.
4866The argument holds a list of events which will be allowed or denied.
4867The eventsel+umask of each event the guest attempts to program is compared
4868against the events field to determine whether the guest should have access.
4869The events field only controls general purpose counters; fixed purpose
4870counters are controlled by the fixed_counter_bitmap.
4871
4872No flags are defined yet, the field must be zero.
4873
4874Valid values for 'action'::
4875
4876  #define KVM_PMU_EVENT_ALLOW 0
4877  #define KVM_PMU_EVENT_DENY 1
4878
48794.121 KVM_PPC_SVM_OFF
4880---------------------
4881
4882:Capability: basic
4883:Architectures: powerpc
4884:Type: vm ioctl
4885:Parameters: none
4886:Returns: 0 on successful completion,
4887
4888Errors:
4889
4890  ======     ================================================================
4891  EINVAL     if ultravisor failed to terminate the secure guest
4892  ENOMEM     if hypervisor failed to allocate new radix page tables for guest
4893  ======     ================================================================
4894
4895This ioctl is used to turn off the secure mode of the guest or transition
4896the guest from secure mode to normal mode. This is invoked when the guest
4897is reset. This has no effect if called for a normal guest.
4898
4899This ioctl issues an ultravisor call to terminate the secure guest,
4900unpins the VPA pages and releases all the device pages that are used to
4901track the secure pages by hypervisor.
4902
49034.122 KVM_S390_NORMAL_RESET
4904---------------------------
4905
4906:Capability: KVM_CAP_S390_VCPU_RESETS
4907:Architectures: s390
4908:Type: vcpu ioctl
4909:Parameters: none
4910:Returns: 0
4911
4912This ioctl resets VCPU registers and control structures according to
4913the cpu reset definition in the POP (Principles Of Operation).
4914
49154.123 KVM_S390_INITIAL_RESET
4916----------------------------
4917
4918:Capability: none
4919:Architectures: s390
4920:Type: vcpu ioctl
4921:Parameters: none
4922:Returns: 0
4923
4924This ioctl resets VCPU registers and control structures according to
4925the initial cpu reset definition in the POP. However, the cpu is not
4926put into ESA mode. This reset is a superset of the normal reset.
4927
49284.124 KVM_S390_CLEAR_RESET
4929--------------------------
4930
4931:Capability: KVM_CAP_S390_VCPU_RESETS
4932:Architectures: s390
4933:Type: vcpu ioctl
4934:Parameters: none
4935:Returns: 0
4936
4937This ioctl resets VCPU registers and control structures according to
4938the clear cpu reset definition in the POP. However, the cpu is not put
4939into ESA mode. This reset is a superset of the initial reset.
4940
4941
49424.125 KVM_S390_PV_COMMAND
4943-------------------------
4944
4945:Capability: KVM_CAP_S390_PROTECTED
4946:Architectures: s390
4947:Type: vm ioctl
4948:Parameters: struct kvm_pv_cmd
4949:Returns: 0 on success, < 0 on error
4950
4951::
4952
4953  struct kvm_pv_cmd {
4954	__u32 cmd;	/* Command to be executed */
4955	__u16 rc;	/* Ultravisor return code */
4956	__u16 rrc;	/* Ultravisor return reason code */
4957	__u64 data;	/* Data or address */
4958	__u32 flags;    /* flags for future extensions. Must be 0 for now */
4959	__u32 reserved[3];
4960  };
4961
4962cmd values:
4963
4964KVM_PV_ENABLE
4965  Allocate memory and register the VM with the Ultravisor, thereby
4966  donating memory to the Ultravisor that will become inaccessible to
4967  KVM. All existing CPUs are converted to protected ones. After this
4968  command has succeeded, any CPU added via hotplug will become
4969  protected during its creation as well.
4970
4971  Errors:
4972
4973  =====      =============================
4974  EINTR      an unmasked signal is pending
4975  =====      =============================
4976
4977KVM_PV_DISABLE
4978
4979  Deregister the VM from the Ultravisor and reclaim the memory that
4980  had been donated to the Ultravisor, making it usable by the kernel
4981  again.  All registered VCPUs are converted back to non-protected
4982  ones.
4983
4984KVM_PV_VM_SET_SEC_PARMS
4985  Pass the image header from VM memory to the Ultravisor in
4986  preparation of image unpacking and verification.
4987
4988KVM_PV_VM_UNPACK
4989  Unpack (protect and decrypt) a page of the encrypted boot image.
4990
4991KVM_PV_VM_VERIFY
4992  Verify the integrity of the unpacked image. Only if this succeeds,
4993  KVM is allowed to start protected VCPUs.
4994
49954.126 KVM_X86_SET_MSR_FILTER
4996----------------------------
4997
4998:Capability: KVM_CAP_X86_MSR_FILTER
4999:Architectures: x86
5000:Type: vm ioctl
5001:Parameters: struct kvm_msr_filter
5002:Returns: 0 on success, < 0 on error
5003
5004::
5005
5006  struct kvm_msr_filter_range {
5007  #define KVM_MSR_FILTER_READ  (1 << 0)
5008  #define KVM_MSR_FILTER_WRITE (1 << 1)
5009	__u32 flags;
5010	__u32 nmsrs; /* number of msrs in bitmap */
5011	__u32 base;  /* MSR index the bitmap starts at */
5012	__u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
5013  };
5014
5015  #define KVM_MSR_FILTER_MAX_RANGES 16
5016  struct kvm_msr_filter {
5017  #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
5018  #define KVM_MSR_FILTER_DEFAULT_DENY  (1 << 0)
5019	__u32 flags;
5020	struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
5021  };
5022
5023flags values for ``struct kvm_msr_filter_range``:
5024
5025``KVM_MSR_FILTER_READ``
5026
5027  Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap
5028  indicates that a read should immediately fail, while a 1 indicates that
5029  a read for a particular MSR should be handled regardless of the default
5030  filter action.
5031
5032``KVM_MSR_FILTER_WRITE``
5033
5034  Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap
5035  indicates that a write should immediately fail, while a 1 indicates that
5036  a write for a particular MSR should be handled regardless of the default
5037  filter action.
5038
5039``KVM_MSR_FILTER_READ | KVM_MSR_FILTER_WRITE``
5040
5041  Filter both read and write accesses to MSRs using the given bitmap. A 0
5042  in the bitmap indicates that both reads and writes should immediately fail,
5043  while a 1 indicates that reads and writes for a particular MSR are not
5044  filtered by this range.
5045
5046flags values for ``struct kvm_msr_filter``:
5047
5048``KVM_MSR_FILTER_DEFAULT_ALLOW``
5049
5050  If no filter range matches an MSR index that is getting accessed, KVM will
5051  fall back to allowing access to the MSR.
5052
5053``KVM_MSR_FILTER_DEFAULT_DENY``
5054
5055  If no filter range matches an MSR index that is getting accessed, KVM will
5056  fall back to rejecting access to the MSR. In this mode, all MSRs that should
5057  be processed by KVM need to explicitly be marked as allowed in the bitmaps.
5058
5059This ioctl allows user space to define up to 16 bitmaps of MSR ranges to
5060specify whether a certain MSR access should be explicitly filtered for or not.
5061
5062If this ioctl has never been invoked, MSR accesses are not guarded and the
5063default KVM in-kernel emulation behavior is fully preserved.
5064
5065Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR
5066filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes
5067an error.
5068
5069As soon as the filtering is in place, every MSR access is processed through
5070the filtering except for accesses to the x2APIC MSRs (from 0x800 to 0x8ff);
5071x2APIC MSRs are always allowed, independent of the ``default_allow`` setting,
5072and their behavior depends on the ``X2APIC_ENABLE`` bit of the APIC base
5073register.
5074
5075If a bit is within one of the defined ranges, read and write accesses are
5076guarded by the bitmap's value for the MSR index if the kind of access
5077is included in the ``struct kvm_msr_filter_range`` flags.  If no range
5078cover this particular access, the behavior is determined by the flags
5079field in the kvm_msr_filter struct: ``KVM_MSR_FILTER_DEFAULT_ALLOW``
5080and ``KVM_MSR_FILTER_DEFAULT_DENY``.
5081
5082Each bitmap range specifies a range of MSRs to potentially allow access on.
5083The range goes from MSR index [base .. base+nmsrs]. The flags field
5084indicates whether reads, writes or both reads and writes are filtered
5085by setting a 1 bit in the bitmap for the corresponding MSR index.
5086
5087If an MSR access is not permitted through the filtering, it generates a
5088#GP inside the guest. When combined with KVM_CAP_X86_USER_SPACE_MSR, that
5089allows user space to deflect and potentially handle various MSR accesses
5090into user space.
5091
5092Note, invoking this ioctl with a vCPU is running is inherently racy.  However,
5093KVM does guarantee that vCPUs will see either the previous filter or the new
5094filter, e.g. MSRs with identical settings in both the old and new filter will
5095have deterministic behavior.
5096
50974.127 KVM_XEN_HVM_SET_ATTR
5098--------------------------
5099
5100:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5101:Architectures: x86
5102:Type: vm ioctl
5103:Parameters: struct kvm_xen_hvm_attr
5104:Returns: 0 on success, < 0 on error
5105
5106::
5107
5108  struct kvm_xen_hvm_attr {
5109	__u16 type;
5110	__u16 pad[3];
5111	union {
5112		__u8 long_mode;
5113		__u8 vector;
5114		struct {
5115			__u64 gfn;
5116		} shared_info;
5117		__u64 pad[4];
5118	} u;
5119  };
5120
5121type values:
5122
5123KVM_XEN_ATTR_TYPE_LONG_MODE
5124  Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This
5125  determines the layout of the shared info pages exposed to the VM.
5126
5127KVM_XEN_ATTR_TYPE_SHARED_INFO
5128  Sets the guest physical frame number at which the Xen "shared info"
5129  page resides. Note that although Xen places vcpu_info for the first
5130  32 vCPUs in the shared_info page, KVM does not automatically do so
5131  and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
5132  explicitly even when the vcpu_info for a given vCPU resides at the
5133  "default" location in the shared_info page. This is because KVM is
5134  not aware of the Xen CPU id which is used as the index into the
5135  vcpu_info[] array, so cannot know the correct default location.
5136
5137KVM_XEN_ATTR_TYPE_UPCALL_VECTOR
5138  Sets the exception vector used to deliver Xen event channel upcalls.
5139
51404.127 KVM_XEN_HVM_GET_ATTR
5141--------------------------
5142
5143:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5144:Architectures: x86
5145:Type: vm ioctl
5146:Parameters: struct kvm_xen_hvm_attr
5147:Returns: 0 on success, < 0 on error
5148
5149Allows Xen VM attributes to be read. For the structure and types,
5150see KVM_XEN_HVM_SET_ATTR above.
5151
51524.128 KVM_XEN_VCPU_SET_ATTR
5153---------------------------
5154
5155:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5156:Architectures: x86
5157:Type: vcpu ioctl
5158:Parameters: struct kvm_xen_vcpu_attr
5159:Returns: 0 on success, < 0 on error
5160
5161::
5162
5163  struct kvm_xen_vcpu_attr {
5164	__u16 type;
5165	__u16 pad[3];
5166	union {
5167		__u64 gpa;
5168		__u64 pad[4];
5169		struct {
5170			__u64 state;
5171			__u64 state_entry_time;
5172			__u64 time_running;
5173			__u64 time_runnable;
5174			__u64 time_blocked;
5175			__u64 time_offline;
5176		} runstate;
5177	} u;
5178  };
5179
5180type values:
5181
5182KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
5183  Sets the guest physical address of the vcpu_info for a given vCPU.
5184
5185KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
5186  Sets the guest physical address of an additional pvclock structure
5187  for a given vCPU. This is typically used for guest vsyscall support.
5188
5189KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR
5190  Sets the guest physical address of the vcpu_runstate_info for a given
5191  vCPU. This is how a Xen guest tracks CPU state such as steal time.
5192
5193KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT
5194  Sets the runstate (RUNSTATE_running/_runnable/_blocked/_offline) of
5195  the given vCPU from the .u.runstate.state member of the structure.
5196  KVM automatically accounts running and runnable time but blocked
5197  and offline states are only entered explicitly.
5198
5199KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA
5200  Sets all fields of the vCPU runstate data from the .u.runstate member
5201  of the structure, including the current runstate. The state_entry_time
5202  must equal the sum of the other four times.
5203
5204KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST
5205  This *adds* the contents of the .u.runstate members of the structure
5206  to the corresponding members of the given vCPU's runstate data, thus
5207  permitting atomic adjustments to the runstate times. The adjustment
5208  to the state_entry_time must equal the sum of the adjustments to the
5209  other four times. The state field must be set to -1, or to a valid
5210  runstate value (RUNSTATE_running, RUNSTATE_runnable, RUNSTATE_blocked
5211  or RUNSTATE_offline) to set the current accounted state as of the
5212  adjusted state_entry_time.
5213
52144.129 KVM_XEN_VCPU_GET_ATTR
5215---------------------------
5216
5217:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5218:Architectures: x86
5219:Type: vcpu ioctl
5220:Parameters: struct kvm_xen_vcpu_attr
5221:Returns: 0 on success, < 0 on error
5222
5223Allows Xen vCPU attributes to be read. For the structure and types,
5224see KVM_XEN_VCPU_SET_ATTR above.
5225
5226The KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST type may not be used
5227with the KVM_XEN_VCPU_GET_ATTR ioctl.
5228
52294.130 KVM_ARM_MTE_COPY_TAGS
5230---------------------------
5231
5232:Capability: KVM_CAP_ARM_MTE
5233:Architectures: arm64
5234:Type: vm ioctl
5235:Parameters: struct kvm_arm_copy_mte_tags
5236:Returns: number of bytes copied, < 0 on error (-EINVAL for incorrect
5237          arguments, -EFAULT if memory cannot be accessed).
5238
5239::
5240
5241  struct kvm_arm_copy_mte_tags {
5242	__u64 guest_ipa;
5243	__u64 length;
5244	void __user *addr;
5245	__u64 flags;
5246	__u64 reserved[2];
5247  };
5248
5249Copies Memory Tagging Extension (MTE) tags to/from guest tag memory. The
5250``guest_ipa`` and ``length`` fields must be ``PAGE_SIZE`` aligned. The ``addr``
5251field must point to a buffer which the tags will be copied to or from.
5252
5253``flags`` specifies the direction of copy, either ``KVM_ARM_TAGS_TO_GUEST`` or
5254``KVM_ARM_TAGS_FROM_GUEST``.
5255
5256The size of the buffer to store the tags is ``(length / 16)`` bytes
5257(granules in MTE are 16 bytes long). Each byte contains a single tag
5258value. This matches the format of ``PTRACE_PEEKMTETAGS`` and
5259``PTRACE_POKEMTETAGS``.
5260
5261If an error occurs before any data is copied then a negative error code is
5262returned. If some tags have been copied before an error occurs then the number
5263of bytes successfully copied is returned. If the call completes successfully
5264then ``length`` is returned.
5265
52664.131 KVM_GET_SREGS2
5267--------------------
5268
5269:Capability: KVM_CAP_SREGS2
5270:Architectures: x86
5271:Type: vcpu ioctl
5272:Parameters: struct kvm_sregs2 (out)
5273:Returns: 0 on success, -1 on error
5274
5275Reads special registers from the vcpu.
5276This ioctl (when supported) replaces the KVM_GET_SREGS.
5277
5278::
5279
5280        struct kvm_sregs2 {
5281                /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */
5282                struct kvm_segment cs, ds, es, fs, gs, ss;
5283                struct kvm_segment tr, ldt;
5284                struct kvm_dtable gdt, idt;
5285                __u64 cr0, cr2, cr3, cr4, cr8;
5286                __u64 efer;
5287                __u64 apic_base;
5288                __u64 flags;
5289                __u64 pdptrs[4];
5290        };
5291
5292flags values for ``kvm_sregs2``:
5293
5294``KVM_SREGS2_FLAGS_PDPTRS_VALID``
5295
5296  Indicates thats the struct contain valid PDPTR values.
5297
5298
52994.132 KVM_SET_SREGS2
5300--------------------
5301
5302:Capability: KVM_CAP_SREGS2
5303:Architectures: x86
5304:Type: vcpu ioctl
5305:Parameters: struct kvm_sregs2 (in)
5306:Returns: 0 on success, -1 on error
5307
5308Writes special registers into the vcpu.
5309See KVM_GET_SREGS2 for the data structures.
5310This ioctl (when supported) replaces the KVM_SET_SREGS.
5311
53124.133 KVM_GET_STATS_FD
5313----------------------
5314
5315:Capability: KVM_CAP_STATS_BINARY_FD
5316:Architectures: all
5317:Type: vm ioctl, vcpu ioctl
5318:Parameters: none
5319:Returns: statistics file descriptor on success, < 0 on error
5320
5321Errors:
5322
5323  ======     ======================================================
5324  ENOMEM     if the fd could not be created due to lack of memory
5325  EMFILE     if the number of opened files exceeds the limit
5326  ======     ======================================================
5327
5328The returned file descriptor can be used to read VM/vCPU statistics data in
5329binary format. The data in the file descriptor consists of four blocks
5330organized as follows:
5331
5332+-------------+
5333|   Header    |
5334+-------------+
5335|  id string  |
5336+-------------+
5337| Descriptors |
5338+-------------+
5339| Stats Data  |
5340+-------------+
5341
5342Apart from the header starting at offset 0, please be aware that it is
5343not guaranteed that the four blocks are adjacent or in the above order;
5344the offsets of the id, descriptors and data blocks are found in the
5345header.  However, all four blocks are aligned to 64 bit offsets in the
5346file and they do not overlap.
5347
5348All blocks except the data block are immutable.  Userspace can read them
5349only one time after retrieving the file descriptor, and then use ``pread`` or
5350``lseek`` to read the statistics repeatedly.
5351
5352All data is in system endianness.
5353
5354The format of the header is as follows::
5355
5356	struct kvm_stats_header {
5357		__u32 flags;
5358		__u32 name_size;
5359		__u32 num_desc;
5360		__u32 id_offset;
5361		__u32 desc_offset;
5362		__u32 data_offset;
5363	};
5364
5365The ``flags`` field is not used at the moment. It is always read as 0.
5366
5367The ``name_size`` field is the size (in byte) of the statistics name string
5368(including trailing '\0') which is contained in the "id string" block and
5369appended at the end of every descriptor.
5370
5371The ``num_desc`` field is the number of descriptors that are included in the
5372descriptor block.  (The actual number of values in the data block may be
5373larger, since each descriptor may comprise more than one value).
5374
5375The ``id_offset`` field is the offset of the id string from the start of the
5376file indicated by the file descriptor. It is a multiple of 8.
5377
5378The ``desc_offset`` field is the offset of the Descriptors block from the start
5379of the file indicated by the file descriptor. It is a multiple of 8.
5380
5381The ``data_offset`` field is the offset of the Stats Data block from the start
5382of the file indicated by the file descriptor. It is a multiple of 8.
5383
5384The id string block contains a string which identifies the file descriptor on
5385which KVM_GET_STATS_FD was invoked.  The size of the block, including the
5386trailing ``'\0'``, is indicated by the ``name_size`` field in the header.
5387
5388The descriptors block is only needed to be read once for the lifetime of the
5389file descriptor contains a sequence of ``struct kvm_stats_desc``, each followed
5390by a string of size ``name_size``.
5391::
5392
5393	#define KVM_STATS_TYPE_SHIFT		0
5394	#define KVM_STATS_TYPE_MASK		(0xF << KVM_STATS_TYPE_SHIFT)
5395	#define KVM_STATS_TYPE_CUMULATIVE	(0x0 << KVM_STATS_TYPE_SHIFT)
5396	#define KVM_STATS_TYPE_INSTANT		(0x1 << KVM_STATS_TYPE_SHIFT)
5397	#define KVM_STATS_TYPE_PEAK		(0x2 << KVM_STATS_TYPE_SHIFT)
5398	#define KVM_STATS_TYPE_LINEAR_HIST	(0x3 << KVM_STATS_TYPE_SHIFT)
5399	#define KVM_STATS_TYPE_LOG_HIST		(0x4 << KVM_STATS_TYPE_SHIFT)
5400	#define KVM_STATS_TYPE_MAX		KVM_STATS_TYPE_LOG_HIST
5401
5402	#define KVM_STATS_UNIT_SHIFT		4
5403	#define KVM_STATS_UNIT_MASK		(0xF << KVM_STATS_UNIT_SHIFT)
5404	#define KVM_STATS_UNIT_NONE		(0x0 << KVM_STATS_UNIT_SHIFT)
5405	#define KVM_STATS_UNIT_BYTES		(0x1 << KVM_STATS_UNIT_SHIFT)
5406	#define KVM_STATS_UNIT_SECONDS		(0x2 << KVM_STATS_UNIT_SHIFT)
5407	#define KVM_STATS_UNIT_CYCLES		(0x3 << KVM_STATS_UNIT_SHIFT)
5408	#define KVM_STATS_UNIT_MAX		KVM_STATS_UNIT_CYCLES
5409
5410	#define KVM_STATS_BASE_SHIFT		8
5411	#define KVM_STATS_BASE_MASK		(0xF << KVM_STATS_BASE_SHIFT)
5412	#define KVM_STATS_BASE_POW10		(0x0 << KVM_STATS_BASE_SHIFT)
5413	#define KVM_STATS_BASE_POW2		(0x1 << KVM_STATS_BASE_SHIFT)
5414	#define KVM_STATS_BASE_MAX		KVM_STATS_BASE_POW2
5415
5416	struct kvm_stats_desc {
5417		__u32 flags;
5418		__s16 exponent;
5419		__u16 size;
5420		__u32 offset;
5421		__u32 bucket_size;
5422		char name[];
5423	};
5424
5425The ``flags`` field contains the type and unit of the statistics data described
5426by this descriptor. Its endianness is CPU native.
5427The following flags are supported:
5428
5429Bits 0-3 of ``flags`` encode the type:
5430
5431  * ``KVM_STATS_TYPE_CUMULATIVE``
5432    The statistics reports a cumulative count. The value of data can only be increased.
5433    Most of the counters used in KVM are of this type.
5434    The corresponding ``size`` field for this type is always 1.
5435    All cumulative statistics data are read/write.
5436  * ``KVM_STATS_TYPE_INSTANT``
5437    The statistics reports an instantaneous value. Its value can be increased or
5438    decreased. This type is usually used as a measurement of some resources,
5439    like the number of dirty pages, the number of large pages, etc.
5440    All instant statistics are read only.
5441    The corresponding ``size`` field for this type is always 1.
5442  * ``KVM_STATS_TYPE_PEAK``
5443    The statistics data reports a peak value, for example the maximum number
5444    of items in a hash table bucket, the longest time waited and so on.
5445    The value of data can only be increased.
5446    The corresponding ``size`` field for this type is always 1.
5447  * ``KVM_STATS_TYPE_LINEAR_HIST``
5448    The statistic is reported as a linear histogram. The number of
5449    buckets is specified by the ``size`` field. The size of buckets is specified
5450    by the ``hist_param`` field. The range of the Nth bucket (1 <= N < ``size``)
5451    is [``hist_param``*(N-1), ``hist_param``*N), while the range of the last
5452    bucket is [``hist_param``*(``size``-1), +INF). (+INF means positive infinity
5453    value.) The bucket value indicates how many samples fell in the bucket's range.
5454  * ``KVM_STATS_TYPE_LOG_HIST``
5455    The statistic is reported as a logarithmic histogram. The number of
5456    buckets is specified by the ``size`` field. The range of the first bucket is
5457    [0, 1), while the range of the last bucket is [pow(2, ``size``-2), +INF).
5458    Otherwise, The Nth bucket (1 < N < ``size``) covers
5459    [pow(2, N-2), pow(2, N-1)). The bucket value indicates how many samples fell
5460    in the bucket's range.
5461
5462Bits 4-7 of ``flags`` encode the unit:
5463
5464  * ``KVM_STATS_UNIT_NONE``
5465    There is no unit for the value of statistics data. This usually means that
5466    the value is a simple counter of an event.
5467  * ``KVM_STATS_UNIT_BYTES``
5468    It indicates that the statistics data is used to measure memory size, in the
5469    unit of Byte, KiByte, MiByte, GiByte, etc. The unit of the data is
5470    determined by the ``exponent`` field in the descriptor.
5471  * ``KVM_STATS_UNIT_SECONDS``
5472    It indicates that the statistics data is used to measure time or latency.
5473  * ``KVM_STATS_UNIT_CYCLES``
5474    It indicates that the statistics data is used to measure CPU clock cycles.
5475
5476Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the
5477unit:
5478
5479  * ``KVM_STATS_BASE_POW10``
5480    The scale is based on power of 10. It is used for measurement of time and
5481    CPU clock cycles.  For example, an exponent of -9 can be used with
5482    ``KVM_STATS_UNIT_SECONDS`` to express that the unit is nanoseconds.
5483  * ``KVM_STATS_BASE_POW2``
5484    The scale is based on power of 2. It is used for measurement of memory size.
5485    For example, an exponent of 20 can be used with ``KVM_STATS_UNIT_BYTES`` to
5486    express that the unit is MiB.
5487
5488The ``size`` field is the number of values of this statistics data. Its
5489value is usually 1 for most of simple statistics. 1 means it contains an
5490unsigned 64bit data.
5491
5492The ``offset`` field is the offset from the start of Data Block to the start of
5493the corresponding statistics data.
5494
5495The ``bucket_size`` field is used as a parameter for histogram statistics data.
5496It is only used by linear histogram statistics data, specifying the size of a
5497bucket.
5498
5499The ``name`` field is the name string of the statistics data. The name string
5500starts at the end of ``struct kvm_stats_desc``.  The maximum length including
5501the trailing ``'\0'``, is indicated by ``name_size`` in the header.
5502
5503The Stats Data block contains an array of 64-bit values in the same order
5504as the descriptors in Descriptors block.
5505
55065. The kvm_run structure
5507========================
5508
5509Application code obtains a pointer to the kvm_run structure by
5510mmap()ing a vcpu fd.  From that point, application code can control
5511execution by changing fields in kvm_run prior to calling the KVM_RUN
5512ioctl, and obtain information about the reason KVM_RUN returned by
5513looking up structure members.
5514
5515::
5516
5517  struct kvm_run {
5518	/* in */
5519	__u8 request_interrupt_window;
5520
5521Request that KVM_RUN return when it becomes possible to inject external
5522interrupts into the guest.  Useful in conjunction with KVM_INTERRUPT.
5523
5524::
5525
5526	__u8 immediate_exit;
5527
5528This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
5529exits immediately, returning -EINTR.  In the common scenario where a
5530signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
5531to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
5532Rather than blocking the signal outside KVM_RUN, userspace can set up
5533a signal handler that sets run->immediate_exit to a non-zero value.
5534
5535This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
5536
5537::
5538
5539	__u8 padding1[6];
5540
5541	/* out */
5542	__u32 exit_reason;
5543
5544When KVM_RUN has returned successfully (return value 0), this informs
5545application code why KVM_RUN has returned.  Allowable values for this
5546field are detailed below.
5547
5548::
5549
5550	__u8 ready_for_interrupt_injection;
5551
5552If request_interrupt_window has been specified, this field indicates
5553an interrupt can be injected now with KVM_INTERRUPT.
5554
5555::
5556
5557	__u8 if_flag;
5558
5559The value of the current interrupt flag.  Only valid if in-kernel
5560local APIC is not used.
5561
5562::
5563
5564	__u16 flags;
5565
5566More architecture-specific flags detailing state of the VCPU that may
5567affect the device's behavior. Current defined flags::
5568
5569  /* x86, set if the VCPU is in system management mode */
5570  #define KVM_RUN_X86_SMM     (1 << 0)
5571  /* x86, set if bus lock detected in VM */
5572  #define KVM_RUN_BUS_LOCK    (1 << 1)
5573
5574::
5575
5576	/* in (pre_kvm_run), out (post_kvm_run) */
5577	__u64 cr8;
5578
5579The value of the cr8 register.  Only valid if in-kernel local APIC is
5580not used.  Both input and output.
5581
5582::
5583
5584	__u64 apic_base;
5585
5586The value of the APIC BASE msr.  Only valid if in-kernel local
5587APIC is not used.  Both input and output.
5588
5589::
5590
5591	union {
5592		/* KVM_EXIT_UNKNOWN */
5593		struct {
5594			__u64 hardware_exit_reason;
5595		} hw;
5596
5597If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
5598reasons.  Further architecture-specific information is available in
5599hardware_exit_reason.
5600
5601::
5602
5603		/* KVM_EXIT_FAIL_ENTRY */
5604		struct {
5605			__u64 hardware_entry_failure_reason;
5606			__u32 cpu; /* if KVM_LAST_CPU */
5607		} fail_entry;
5608
5609If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
5610to unknown reasons.  Further architecture-specific information is
5611available in hardware_entry_failure_reason.
5612
5613::
5614
5615		/* KVM_EXIT_EXCEPTION */
5616		struct {
5617			__u32 exception;
5618			__u32 error_code;
5619		} ex;
5620
5621Unused.
5622
5623::
5624
5625		/* KVM_EXIT_IO */
5626		struct {
5627  #define KVM_EXIT_IO_IN  0
5628  #define KVM_EXIT_IO_OUT 1
5629			__u8 direction;
5630			__u8 size; /* bytes */
5631			__u16 port;
5632			__u32 count;
5633			__u64 data_offset; /* relative to kvm_run start */
5634		} io;
5635
5636If exit_reason is KVM_EXIT_IO, then the vcpu has
5637executed a port I/O instruction which could not be satisfied by kvm.
5638data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
5639where kvm expects application code to place the data for the next
5640KVM_RUN invocation (KVM_EXIT_IO_IN).  Data format is a packed array.
5641
5642::
5643
5644		/* KVM_EXIT_DEBUG */
5645		struct {
5646			struct kvm_debug_exit_arch arch;
5647		} debug;
5648
5649If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
5650for which architecture specific information is returned.
5651
5652::
5653
5654		/* KVM_EXIT_MMIO */
5655		struct {
5656			__u64 phys_addr;
5657			__u8  data[8];
5658			__u32 len;
5659			__u8  is_write;
5660		} mmio;
5661
5662If exit_reason is KVM_EXIT_MMIO, then the vcpu has
5663executed a memory-mapped I/O instruction which could not be satisfied
5664by kvm.  The 'data' member contains the written data if 'is_write' is
5665true, and should be filled by application code otherwise.
5666
5667The 'data' member contains, in its first 'len' bytes, the value as it would
5668appear if the VCPU performed a load or store of the appropriate width directly
5669to the byte array.
5670
5671.. note::
5672
5673      For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN,
5674      KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding
5675      operations are complete (and guest state is consistent) only after userspace
5676      has re-entered the kernel with KVM_RUN.  The kernel side will first finish
5677      incomplete operations and then check for pending signals.
5678
5679      The pending state of the operation is not preserved in state which is
5680      visible to userspace, thus userspace should ensure that the operation is
5681      completed before performing a live migration.  Userspace can re-enter the
5682      guest with an unmasked signal pending or with the immediate_exit field set
5683      to complete pending operations without allowing any further instructions
5684      to be executed.
5685
5686::
5687
5688		/* KVM_EXIT_HYPERCALL */
5689		struct {
5690			__u64 nr;
5691			__u64 args[6];
5692			__u64 ret;
5693			__u32 longmode;
5694			__u32 pad;
5695		} hypercall;
5696
5697Unused.  This was once used for 'hypercall to userspace'.  To implement
5698such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
5699
5700.. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
5701
5702::
5703
5704		/* KVM_EXIT_TPR_ACCESS */
5705		struct {
5706			__u64 rip;
5707			__u32 is_write;
5708			__u32 pad;
5709		} tpr_access;
5710
5711To be documented (KVM_TPR_ACCESS_REPORTING).
5712
5713::
5714
5715		/* KVM_EXIT_S390_SIEIC */
5716		struct {
5717			__u8 icptcode;
5718			__u64 mask; /* psw upper half */
5719			__u64 addr; /* psw lower half */
5720			__u16 ipa;
5721			__u32 ipb;
5722		} s390_sieic;
5723
5724s390 specific.
5725
5726::
5727
5728		/* KVM_EXIT_S390_RESET */
5729  #define KVM_S390_RESET_POR       1
5730  #define KVM_S390_RESET_CLEAR     2
5731  #define KVM_S390_RESET_SUBSYSTEM 4
5732  #define KVM_S390_RESET_CPU_INIT  8
5733  #define KVM_S390_RESET_IPL       16
5734		__u64 s390_reset_flags;
5735
5736s390 specific.
5737
5738::
5739
5740		/* KVM_EXIT_S390_UCONTROL */
5741		struct {
5742			__u64 trans_exc_code;
5743			__u32 pgm_code;
5744		} s390_ucontrol;
5745
5746s390 specific. A page fault has occurred for a user controlled virtual
5747machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
5748resolved by the kernel.
5749The program code and the translation exception code that were placed
5750in the cpu's lowcore are presented here as defined by the z Architecture
5751Principles of Operation Book in the Chapter for Dynamic Address Translation
5752(DAT)
5753
5754::
5755
5756		/* KVM_EXIT_DCR */
5757		struct {
5758			__u32 dcrn;
5759			__u32 data;
5760			__u8  is_write;
5761		} dcr;
5762
5763Deprecated - was used for 440 KVM.
5764
5765::
5766
5767		/* KVM_EXIT_OSI */
5768		struct {
5769			__u64 gprs[32];
5770		} osi;
5771
5772MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
5773hypercalls and exit with this exit struct that contains all the guest gprs.
5774
5775If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
5776Userspace can now handle the hypercall and when it's done modify the gprs as
5777necessary. Upon guest entry all guest GPRs will then be replaced by the values
5778in this struct.
5779
5780::
5781
5782		/* KVM_EXIT_PAPR_HCALL */
5783		struct {
5784			__u64 nr;
5785			__u64 ret;
5786			__u64 args[9];
5787		} papr_hcall;
5788
5789This is used on 64-bit PowerPC when emulating a pSeries partition,
5790e.g. with the 'pseries' machine type in qemu.  It occurs when the
5791guest does a hypercall using the 'sc 1' instruction.  The 'nr' field
5792contains the hypercall number (from the guest R3), and 'args' contains
5793the arguments (from the guest R4 - R12).  Userspace should put the
5794return code in 'ret' and any extra returned values in args[].
5795The possible hypercalls are defined in the Power Architecture Platform
5796Requirements (PAPR) document available from www.power.org (free
5797developer registration required to access it).
5798
5799::
5800
5801		/* KVM_EXIT_S390_TSCH */
5802		struct {
5803			__u16 subchannel_id;
5804			__u16 subchannel_nr;
5805			__u32 io_int_parm;
5806			__u32 io_int_word;
5807			__u32 ipb;
5808			__u8 dequeued;
5809		} s390_tsch;
5810
5811s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
5812and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
5813interrupt for the target subchannel has been dequeued and subchannel_id,
5814subchannel_nr, io_int_parm and io_int_word contain the parameters for that
5815interrupt. ipb is needed for instruction parameter decoding.
5816
5817::
5818
5819		/* KVM_EXIT_EPR */
5820		struct {
5821			__u32 epr;
5822		} epr;
5823
5824On FSL BookE PowerPC chips, the interrupt controller has a fast patch
5825interrupt acknowledge path to the core. When the core successfully
5826delivers an interrupt, it automatically populates the EPR register with
5827the interrupt vector number and acknowledges the interrupt inside
5828the interrupt controller.
5829
5830In case the interrupt controller lives in user space, we need to do
5831the interrupt acknowledge cycle through it to fetch the next to be
5832delivered interrupt vector using this exit.
5833
5834It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
5835external interrupt has just been delivered into the guest. User space
5836should put the acknowledged interrupt vector into the 'epr' field.
5837
5838::
5839
5840		/* KVM_EXIT_SYSTEM_EVENT */
5841		struct {
5842  #define KVM_SYSTEM_EVENT_SHUTDOWN       1
5843  #define KVM_SYSTEM_EVENT_RESET          2
5844  #define KVM_SYSTEM_EVENT_CRASH          3
5845			__u32 type;
5846			__u64 flags;
5847		} system_event;
5848
5849If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
5850a system-level event using some architecture specific mechanism (hypercall
5851or some special instruction). In case of ARM/ARM64, this is triggered using
5852HVC instruction based PSCI call from the vcpu. The 'type' field describes
5853the system-level event type. The 'flags' field describes architecture
5854specific flags for the system-level event.
5855
5856Valid values for 'type' are:
5857
5858 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
5859   VM. Userspace is not obliged to honour this, and if it does honour
5860   this does not need to destroy the VM synchronously (ie it may call
5861   KVM_RUN again before shutdown finally occurs).
5862 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
5863   As with SHUTDOWN, userspace can choose to ignore the request, or
5864   to schedule the reset to occur in the future and may call KVM_RUN again.
5865 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
5866   has requested a crash condition maintenance. Userspace can choose
5867   to ignore the request, or to gather VM memory core dump and/or
5868   reset/shutdown of the VM.
5869
5870::
5871
5872		/* KVM_EXIT_IOAPIC_EOI */
5873		struct {
5874			__u8 vector;
5875		} eoi;
5876
5877Indicates that the VCPU's in-kernel local APIC received an EOI for a
5878level-triggered IOAPIC interrupt.  This exit only triggers when the
5879IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
5880the userspace IOAPIC should process the EOI and retrigger the interrupt if
5881it is still asserted.  Vector is the LAPIC interrupt vector for which the
5882EOI was received.
5883
5884::
5885
5886		struct kvm_hyperv_exit {
5887  #define KVM_EXIT_HYPERV_SYNIC          1
5888  #define KVM_EXIT_HYPERV_HCALL          2
5889  #define KVM_EXIT_HYPERV_SYNDBG         3
5890			__u32 type;
5891			__u32 pad1;
5892			union {
5893				struct {
5894					__u32 msr;
5895					__u32 pad2;
5896					__u64 control;
5897					__u64 evt_page;
5898					__u64 msg_page;
5899				} synic;
5900				struct {
5901					__u64 input;
5902					__u64 result;
5903					__u64 params[2];
5904				} hcall;
5905				struct {
5906					__u32 msr;
5907					__u32 pad2;
5908					__u64 control;
5909					__u64 status;
5910					__u64 send_page;
5911					__u64 recv_page;
5912					__u64 pending_page;
5913				} syndbg;
5914			} u;
5915		};
5916		/* KVM_EXIT_HYPERV */
5917                struct kvm_hyperv_exit hyperv;
5918
5919Indicates that the VCPU exits into userspace to process some tasks
5920related to Hyper-V emulation.
5921
5922Valid values for 'type' are:
5923
5924	- KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
5925
5926Hyper-V SynIC state change. Notification is used to remap SynIC
5927event/message pages and to enable/disable SynIC messages/events processing
5928in userspace.
5929
5930	- KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about
5931
5932Hyper-V Synthetic debugger state change. Notification is used to either update
5933the pending_page location or to send a control command (send the buffer located
5934in send_page or recv a buffer to recv_page).
5935
5936::
5937
5938		/* KVM_EXIT_ARM_NISV */
5939		struct {
5940			__u64 esr_iss;
5941			__u64 fault_ipa;
5942		} arm_nisv;
5943
5944Used on arm and arm64 systems. If a guest accesses memory not in a memslot,
5945KVM will typically return to userspace and ask it to do MMIO emulation on its
5946behalf. However, for certain classes of instructions, no instruction decode
5947(direction, length of memory access) is provided, and fetching and decoding
5948the instruction from the VM is overly complicated to live in the kernel.
5949
5950Historically, when this situation occurred, KVM would print a warning and kill
5951the VM. KVM assumed that if the guest accessed non-memslot memory, it was
5952trying to do I/O, which just couldn't be emulated, and the warning message was
5953phrased accordingly. However, what happened more often was that a guest bug
5954caused access outside the guest memory areas which should lead to a more
5955meaningful warning message and an external abort in the guest, if the access
5956did not fall within an I/O window.
5957
5958Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable
5959this capability at VM creation. Once this is done, these types of errors will
5960instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from
5961the HSR (arm) and ESR_EL2 (arm64) in the esr_iss field, and the faulting IPA
5962in the fault_ipa field. Userspace can either fix up the access if it's
5963actually an I/O access by decoding the instruction from guest memory (if it's
5964very brave) and continue executing the guest, or it can decide to suspend,
5965dump, or restart the guest.
5966
5967Note that KVM does not skip the faulting instruction as it does for
5968KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state
5969if it decides to decode and emulate the instruction.
5970
5971::
5972
5973		/* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */
5974		struct {
5975			__u8 error; /* user -> kernel */
5976			__u8 pad[7];
5977			__u32 reason; /* kernel -> user */
5978			__u32 index; /* kernel -> user */
5979			__u64 data; /* kernel <-> user */
5980		} msr;
5981
5982Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is
5983enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code
5984will instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR
5985exit for writes.
5986
5987The "reason" field specifies why the MSR trap occurred. User space will only
5988receive MSR exit traps when a particular reason was requested during through
5989ENABLE_CAP. Currently valid exit reasons are:
5990
5991	KVM_MSR_EXIT_REASON_UNKNOWN - access to MSR that is unknown to KVM
5992	KVM_MSR_EXIT_REASON_INVAL - access to invalid MSRs or reserved bits
5993	KVM_MSR_EXIT_REASON_FILTER - access blocked by KVM_X86_SET_MSR_FILTER
5994
5995For KVM_EXIT_X86_RDMSR, the "index" field tells user space which MSR the guest
5996wants to read. To respond to this request with a successful read, user space
5997writes the respective data into the "data" field and must continue guest
5998execution to ensure the read data is transferred into guest register state.
5999
6000If the RDMSR request was unsuccessful, user space indicates that with a "1" in
6001the "error" field. This will inject a #GP into the guest when the VCPU is
6002executed again.
6003
6004For KVM_EXIT_X86_WRMSR, the "index" field tells user space which MSR the guest
6005wants to write. Once finished processing the event, user space must continue
6006vCPU execution. If the MSR write was unsuccessful, user space also sets the
6007"error" field to "1".
6008
6009::
6010
6011
6012		struct kvm_xen_exit {
6013  #define KVM_EXIT_XEN_HCALL          1
6014			__u32 type;
6015			union {
6016				struct {
6017					__u32 longmode;
6018					__u32 cpl;
6019					__u64 input;
6020					__u64 result;
6021					__u64 params[6];
6022				} hcall;
6023			} u;
6024		};
6025		/* KVM_EXIT_XEN */
6026                struct kvm_hyperv_exit xen;
6027
6028Indicates that the VCPU exits into userspace to process some tasks
6029related to Xen emulation.
6030
6031Valid values for 'type' are:
6032
6033  - KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall.
6034    Userspace is expected to place the hypercall result into the appropriate
6035    field before invoking KVM_RUN again.
6036
6037::
6038
6039		/* KVM_EXIT_RISCV_SBI */
6040		struct {
6041			unsigned long extension_id;
6042			unsigned long function_id;
6043			unsigned long args[6];
6044			unsigned long ret[2];
6045		} riscv_sbi;
6046If exit reason is KVM_EXIT_RISCV_SBI then it indicates that the VCPU has
6047done a SBI call which is not handled by KVM RISC-V kernel module. The details
6048of the SBI call are available in 'riscv_sbi' member of kvm_run structure. The
6049'extension_id' field of 'riscv_sbi' represents SBI extension ID whereas the
6050'function_id' field represents function ID of given SBI extension. The 'args'
6051array field of 'riscv_sbi' represents parameters for the SBI call and 'ret'
6052array field represents return values. The userspace should update the return
6053values of SBI call before resuming the VCPU. For more details on RISC-V SBI
6054spec refer, https://github.com/riscv/riscv-sbi-doc.
6055
6056::
6057
6058		/* Fix the size of the union. */
6059		char padding[256];
6060	};
6061
6062	/*
6063	 * shared registers between kvm and userspace.
6064	 * kvm_valid_regs specifies the register classes set by the host
6065	 * kvm_dirty_regs specified the register classes dirtied by userspace
6066	 * struct kvm_sync_regs is architecture specific, as well as the
6067	 * bits for kvm_valid_regs and kvm_dirty_regs
6068	 */
6069	__u64 kvm_valid_regs;
6070	__u64 kvm_dirty_regs;
6071	union {
6072		struct kvm_sync_regs regs;
6073		char padding[SYNC_REGS_SIZE_BYTES];
6074	} s;
6075
6076If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
6077certain guest registers without having to call SET/GET_*REGS. Thus we can
6078avoid some system call overhead if userspace has to handle the exit.
6079Userspace can query the validity of the structure by checking
6080kvm_valid_regs for specific bits. These bits are architecture specific
6081and usually define the validity of a groups of registers. (e.g. one bit
6082for general purpose registers)
6083
6084Please note that the kernel is allowed to use the kvm_run structure as the
6085primary storage for certain register types. Therefore, the kernel may use the
6086values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
6087
6088::
6089
6090  };
6091
6092
6093
60946. Capabilities that can be enabled on vCPUs
6095============================================
6096
6097There are certain capabilities that change the behavior of the virtual CPU or
6098the virtual machine when enabled. To enable them, please see section 4.37.
6099Below you can find a list of capabilities and what their effect on the vCPU or
6100the virtual machine is when enabling them.
6101
6102The following information is provided along with the description:
6103
6104  Architectures:
6105      which instruction set architectures provide this ioctl.
6106      x86 includes both i386 and x86_64.
6107
6108  Target:
6109      whether this is a per-vcpu or per-vm capability.
6110
6111  Parameters:
6112      what parameters are accepted by the capability.
6113
6114  Returns:
6115      the return value.  General error numbers (EBADF, ENOMEM, EINVAL)
6116      are not detailed, but errors with specific meanings are.
6117
6118
61196.1 KVM_CAP_PPC_OSI
6120-------------------
6121
6122:Architectures: ppc
6123:Target: vcpu
6124:Parameters: none
6125:Returns: 0 on success; -1 on error
6126
6127This capability enables interception of OSI hypercalls that otherwise would
6128be treated as normal system calls to be injected into the guest. OSI hypercalls
6129were invented by Mac-on-Linux to have a standardized communication mechanism
6130between the guest and the host.
6131
6132When this capability is enabled, KVM_EXIT_OSI can occur.
6133
6134
61356.2 KVM_CAP_PPC_PAPR
6136--------------------
6137
6138:Architectures: ppc
6139:Target: vcpu
6140:Parameters: none
6141:Returns: 0 on success; -1 on error
6142
6143This capability enables interception of PAPR hypercalls. PAPR hypercalls are
6144done using the hypercall instruction "sc 1".
6145
6146It also sets the guest privilege level to "supervisor" mode. Usually the guest
6147runs in "hypervisor" privilege mode with a few missing features.
6148
6149In addition to the above, it changes the semantics of SDR1. In this mode, the
6150HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
6151HTAB invisible to the guest.
6152
6153When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
6154
6155
61566.3 KVM_CAP_SW_TLB
6157------------------
6158
6159:Architectures: ppc
6160:Target: vcpu
6161:Parameters: args[0] is the address of a struct kvm_config_tlb
6162:Returns: 0 on success; -1 on error
6163
6164::
6165
6166  struct kvm_config_tlb {
6167	__u64 params;
6168	__u64 array;
6169	__u32 mmu_type;
6170	__u32 array_len;
6171  };
6172
6173Configures the virtual CPU's TLB array, establishing a shared memory area
6174between userspace and KVM.  The "params" and "array" fields are userspace
6175addresses of mmu-type-specific data structures.  The "array_len" field is an
6176safety mechanism, and should be set to the size in bytes of the memory that
6177userspace has reserved for the array.  It must be at least the size dictated
6178by "mmu_type" and "params".
6179
6180While KVM_RUN is active, the shared region is under control of KVM.  Its
6181contents are undefined, and any modification by userspace results in
6182boundedly undefined behavior.
6183
6184On return from KVM_RUN, the shared region will reflect the current state of
6185the guest's TLB.  If userspace makes any changes, it must call KVM_DIRTY_TLB
6186to tell KVM which entries have been changed, prior to calling KVM_RUN again
6187on this vcpu.
6188
6189For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
6190
6191 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
6192 - The "array" field points to an array of type "struct
6193   kvm_book3e_206_tlb_entry".
6194 - The array consists of all entries in the first TLB, followed by all
6195   entries in the second TLB.
6196 - Within a TLB, entries are ordered first by increasing set number.  Within a
6197   set, entries are ordered by way (increasing ESEL).
6198 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
6199   where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
6200 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
6201   hardware ignores this value for TLB0.
6202
62036.4 KVM_CAP_S390_CSS_SUPPORT
6204----------------------------
6205
6206:Architectures: s390
6207:Target: vcpu
6208:Parameters: none
6209:Returns: 0 on success; -1 on error
6210
6211This capability enables support for handling of channel I/O instructions.
6212
6213TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
6214handled in-kernel, while the other I/O instructions are passed to userspace.
6215
6216When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
6217SUBCHANNEL intercepts.
6218
6219Note that even though this capability is enabled per-vcpu, the complete
6220virtual machine is affected.
6221
62226.5 KVM_CAP_PPC_EPR
6223-------------------
6224
6225:Architectures: ppc
6226:Target: vcpu
6227:Parameters: args[0] defines whether the proxy facility is active
6228:Returns: 0 on success; -1 on error
6229
6230This capability enables or disables the delivery of interrupts through the
6231external proxy facility.
6232
6233When enabled (args[0] != 0), every time the guest gets an external interrupt
6234delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
6235to receive the topmost interrupt vector.
6236
6237When disabled (args[0] == 0), behavior is as if this facility is unsupported.
6238
6239When this capability is enabled, KVM_EXIT_EPR can occur.
6240
62416.6 KVM_CAP_IRQ_MPIC
6242--------------------
6243
6244:Architectures: ppc
6245:Parameters: args[0] is the MPIC device fd;
6246             args[1] is the MPIC CPU number for this vcpu
6247
6248This capability connects the vcpu to an in-kernel MPIC device.
6249
62506.7 KVM_CAP_IRQ_XICS
6251--------------------
6252
6253:Architectures: ppc
6254:Target: vcpu
6255:Parameters: args[0] is the XICS device fd;
6256             args[1] is the XICS CPU number (server ID) for this vcpu
6257
6258This capability connects the vcpu to an in-kernel XICS device.
6259
62606.8 KVM_CAP_S390_IRQCHIP
6261------------------------
6262
6263:Architectures: s390
6264:Target: vm
6265:Parameters: none
6266
6267This capability enables the in-kernel irqchip for s390. Please refer to
6268"4.24 KVM_CREATE_IRQCHIP" for details.
6269
62706.9 KVM_CAP_MIPS_FPU
6271--------------------
6272
6273:Architectures: mips
6274:Target: vcpu
6275:Parameters: args[0] is reserved for future use (should be 0).
6276
6277This capability allows the use of the host Floating Point Unit by the guest. It
6278allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
6279done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be
6280accessed (depending on the current guest FPU register mode), and the Status.FR,
6281Config5.FRE bits are accessible via the KVM API and also from the guest,
6282depending on them being supported by the FPU.
6283
62846.10 KVM_CAP_MIPS_MSA
6285---------------------
6286
6287:Architectures: mips
6288:Target: vcpu
6289:Parameters: args[0] is reserved for future use (should be 0).
6290
6291This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
6292It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
6293Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*``
6294registers can be accessed, and the Config5.MSAEn bit is accessible via the
6295KVM API and also from the guest.
6296
62976.74 KVM_CAP_SYNC_REGS
6298----------------------
6299
6300:Architectures: s390, x86
6301:Target: s390: always enabled, x86: vcpu
6302:Parameters: none
6303:Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
6304          sets are supported
6305          (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
6306
6307As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
6308KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
6309without having to call SET/GET_*REGS". This reduces overhead by eliminating
6310repeated ioctl calls for setting and/or getting register values. This is
6311particularly important when userspace is making synchronous guest state
6312modifications, e.g. when emulating and/or intercepting instructions in
6313userspace.
6314
6315For s390 specifics, please refer to the source code.
6316
6317For x86:
6318
6319- the register sets to be copied out to kvm_run are selectable
6320  by userspace (rather that all sets being copied out for every exit).
6321- vcpu_events are available in addition to regs and sregs.
6322
6323For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
6324function as an input bit-array field set by userspace to indicate the
6325specific register sets to be copied out on the next exit.
6326
6327To indicate when userspace has modified values that should be copied into
6328the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
6329This is done using the same bitflags as for the 'kvm_valid_regs' field.
6330If the dirty bit is not set, then the register set values will not be copied
6331into the vCPU even if they've been modified.
6332
6333Unused bitfields in the bitarrays must be set to zero.
6334
6335::
6336
6337  struct kvm_sync_regs {
6338        struct kvm_regs regs;
6339        struct kvm_sregs sregs;
6340        struct kvm_vcpu_events events;
6341  };
6342
63436.75 KVM_CAP_PPC_IRQ_XIVE
6344-------------------------
6345
6346:Architectures: ppc
6347:Target: vcpu
6348:Parameters: args[0] is the XIVE device fd;
6349             args[1] is the XIVE CPU number (server ID) for this vcpu
6350
6351This capability connects the vcpu to an in-kernel XIVE device.
6352
63537. Capabilities that can be enabled on VMs
6354==========================================
6355
6356There are certain capabilities that change the behavior of the virtual
6357machine when enabled. To enable them, please see section 4.37. Below
6358you can find a list of capabilities and what their effect on the VM
6359is when enabling them.
6360
6361The following information is provided along with the description:
6362
6363  Architectures:
6364      which instruction set architectures provide this ioctl.
6365      x86 includes both i386 and x86_64.
6366
6367  Parameters:
6368      what parameters are accepted by the capability.
6369
6370  Returns:
6371      the return value.  General error numbers (EBADF, ENOMEM, EINVAL)
6372      are not detailed, but errors with specific meanings are.
6373
6374
63757.1 KVM_CAP_PPC_ENABLE_HCALL
6376----------------------------
6377
6378:Architectures: ppc
6379:Parameters: args[0] is the sPAPR hcall number;
6380	     args[1] is 0 to disable, 1 to enable in-kernel handling
6381
6382This capability controls whether individual sPAPR hypercalls (hcalls)
6383get handled by the kernel or not.  Enabling or disabling in-kernel
6384handling of an hcall is effective across the VM.  On creation, an
6385initial set of hcalls are enabled for in-kernel handling, which
6386consists of those hcalls for which in-kernel handlers were implemented
6387before this capability was implemented.  If disabled, the kernel will
6388not to attempt to handle the hcall, but will always exit to userspace
6389to handle it.  Note that it may not make sense to enable some and
6390disable others of a group of related hcalls, but KVM does not prevent
6391userspace from doing that.
6392
6393If the hcall number specified is not one that has an in-kernel
6394implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
6395error.
6396
63977.2 KVM_CAP_S390_USER_SIGP
6398--------------------------
6399
6400:Architectures: s390
6401:Parameters: none
6402
6403This capability controls which SIGP orders will be handled completely in user
6404space. With this capability enabled, all fast orders will be handled completely
6405in the kernel:
6406
6407- SENSE
6408- SENSE RUNNING
6409- EXTERNAL CALL
6410- EMERGENCY SIGNAL
6411- CONDITIONAL EMERGENCY SIGNAL
6412
6413All other orders will be handled completely in user space.
6414
6415Only privileged operation exceptions will be checked for in the kernel (or even
6416in the hardware prior to interception). If this capability is not enabled, the
6417old way of handling SIGP orders is used (partially in kernel and user space).
6418
64197.3 KVM_CAP_S390_VECTOR_REGISTERS
6420---------------------------------
6421
6422:Architectures: s390
6423:Parameters: none
6424:Returns: 0 on success, negative value on error
6425
6426Allows use of the vector registers introduced with z13 processor, and
6427provides for the synchronization between host and user space.  Will
6428return -EINVAL if the machine does not support vectors.
6429
64307.4 KVM_CAP_S390_USER_STSI
6431--------------------------
6432
6433:Architectures: s390
6434:Parameters: none
6435
6436This capability allows post-handlers for the STSI instruction. After
6437initial handling in the kernel, KVM exits to user space with
6438KVM_EXIT_S390_STSI to allow user space to insert further data.
6439
6440Before exiting to userspace, kvm handlers should fill in s390_stsi field of
6441vcpu->run::
6442
6443  struct {
6444	__u64 addr;
6445	__u8 ar;
6446	__u8 reserved;
6447	__u8 fc;
6448	__u8 sel1;
6449	__u16 sel2;
6450  } s390_stsi;
6451
6452  @addr - guest address of STSI SYSIB
6453  @fc   - function code
6454  @sel1 - selector 1
6455  @sel2 - selector 2
6456  @ar   - access register number
6457
6458KVM handlers should exit to userspace with rc = -EREMOTE.
6459
64607.5 KVM_CAP_SPLIT_IRQCHIP
6461-------------------------
6462
6463:Architectures: x86
6464:Parameters: args[0] - number of routes reserved for userspace IOAPICs
6465:Returns: 0 on success, -1 on error
6466
6467Create a local apic for each processor in the kernel. This can be used
6468instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
6469IOAPIC and PIC (and also the PIT, even though this has to be enabled
6470separately).
6471
6472This capability also enables in kernel routing of interrupt requests;
6473when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
6474used in the IRQ routing table.  The first args[0] MSI routes are reserved
6475for the IOAPIC pins.  Whenever the LAPIC receives an EOI for these routes,
6476a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
6477
6478Fails if VCPU has already been created, or if the irqchip is already in the
6479kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
6480
64817.6 KVM_CAP_S390_RI
6482-------------------
6483
6484:Architectures: s390
6485:Parameters: none
6486
6487Allows use of runtime-instrumentation introduced with zEC12 processor.
6488Will return -EINVAL if the machine does not support runtime-instrumentation.
6489Will return -EBUSY if a VCPU has already been created.
6490
64917.7 KVM_CAP_X2APIC_API
6492----------------------
6493
6494:Architectures: x86
6495:Parameters: args[0] - features that should be enabled
6496:Returns: 0 on success, -EINVAL when args[0] contains invalid features
6497
6498Valid feature flags in args[0] are::
6499
6500  #define KVM_X2APIC_API_USE_32BIT_IDS            (1ULL << 0)
6501  #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK  (1ULL << 1)
6502
6503Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
6504KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
6505allowing the use of 32-bit APIC IDs.  See KVM_CAP_X2APIC_API in their
6506respective sections.
6507
6508KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
6509in logical mode or with more than 255 VCPUs.  Otherwise, KVM treats 0xff
6510as a broadcast even in x2APIC mode in order to support physical x2APIC
6511without interrupt remapping.  This is undesirable in logical mode,
6512where 0xff represents CPUs 0-7 in cluster 0.
6513
65147.8 KVM_CAP_S390_USER_INSTR0
6515----------------------------
6516
6517:Architectures: s390
6518:Parameters: none
6519
6520With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
6521be intercepted and forwarded to user space. User space can use this
6522mechanism e.g. to realize 2-byte software breakpoints. The kernel will
6523not inject an operating exception for these instructions, user space has
6524to take care of that.
6525
6526This capability can be enabled dynamically even if VCPUs were already
6527created and are running.
6528
65297.9 KVM_CAP_S390_GS
6530-------------------
6531
6532:Architectures: s390
6533:Parameters: none
6534:Returns: 0 on success; -EINVAL if the machine does not support
6535          guarded storage; -EBUSY if a VCPU has already been created.
6536
6537Allows use of guarded storage for the KVM guest.
6538
65397.10 KVM_CAP_S390_AIS
6540---------------------
6541
6542:Architectures: s390
6543:Parameters: none
6544
6545Allow use of adapter-interruption suppression.
6546:Returns: 0 on success; -EBUSY if a VCPU has already been created.
6547
65487.11 KVM_CAP_PPC_SMT
6549--------------------
6550
6551:Architectures: ppc
6552:Parameters: vsmt_mode, flags
6553
6554Enabling this capability on a VM provides userspace with a way to set
6555the desired virtual SMT mode (i.e. the number of virtual CPUs per
6556virtual core).  The virtual SMT mode, vsmt_mode, must be a power of 2
6557between 1 and 8.  On POWER8, vsmt_mode must also be no greater than
6558the number of threads per subcore for the host.  Currently flags must
6559be 0.  A successful call to enable this capability will result in
6560vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
6561subsequently queried for the VM.  This capability is only supported by
6562HV KVM, and can only be set before any VCPUs have been created.
6563The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
6564modes are available.
6565
65667.12 KVM_CAP_PPC_FWNMI
6567----------------------
6568
6569:Architectures: ppc
6570:Parameters: none
6571
6572With this capability a machine check exception in the guest address
6573space will cause KVM to exit the guest with NMI exit reason. This
6574enables QEMU to build error log and branch to guest kernel registered
6575machine check handling routine. Without this capability KVM will
6576branch to guests' 0x200 interrupt vector.
6577
65787.13 KVM_CAP_X86_DISABLE_EXITS
6579------------------------------
6580
6581:Architectures: x86
6582:Parameters: args[0] defines which exits are disabled
6583:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
6584
6585Valid bits in args[0] are::
6586
6587  #define KVM_X86_DISABLE_EXITS_MWAIT            (1 << 0)
6588  #define KVM_X86_DISABLE_EXITS_HLT              (1 << 1)
6589  #define KVM_X86_DISABLE_EXITS_PAUSE            (1 << 2)
6590  #define KVM_X86_DISABLE_EXITS_CSTATE           (1 << 3)
6591
6592Enabling this capability on a VM provides userspace with a way to no
6593longer intercept some instructions for improved latency in some
6594workloads, and is suggested when vCPUs are associated to dedicated
6595physical CPUs.  More bits can be added in the future; userspace can
6596just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
6597all such vmexits.
6598
6599Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
6600
66017.14 KVM_CAP_S390_HPAGE_1M
6602--------------------------
6603
6604:Architectures: s390
6605:Parameters: none
6606:Returns: 0 on success, -EINVAL if hpage module parameter was not set
6607	  or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
6608	  flag set
6609
6610With this capability the KVM support for memory backing with 1m pages
6611through hugetlbfs can be enabled for a VM. After the capability is
6612enabled, cmma can't be enabled anymore and pfmfi and the storage key
6613interpretation are disabled. If cmma has already been enabled or the
6614hpage module parameter is not set to 1, -EINVAL is returned.
6615
6616While it is generally possible to create a huge page backed VM without
6617this capability, the VM will not be able to run.
6618
66197.15 KVM_CAP_MSR_PLATFORM_INFO
6620------------------------------
6621
6622:Architectures: x86
6623:Parameters: args[0] whether feature should be enabled or not
6624
6625With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
6626a #GP would be raised when the guest tries to access. Currently, this
6627capability does not enable write permissions of this MSR for the guest.
6628
66297.16 KVM_CAP_PPC_NESTED_HV
6630--------------------------
6631
6632:Architectures: ppc
6633:Parameters: none
6634:Returns: 0 on success, -EINVAL when the implementation doesn't support
6635	  nested-HV virtualization.
6636
6637HV-KVM on POWER9 and later systems allows for "nested-HV"
6638virtualization, which provides a way for a guest VM to run guests that
6639can run using the CPU's supervisor mode (privileged non-hypervisor
6640state).  Enabling this capability on a VM depends on the CPU having
6641the necessary functionality and on the facility being enabled with a
6642kvm-hv module parameter.
6643
66447.17 KVM_CAP_EXCEPTION_PAYLOAD
6645------------------------------
6646
6647:Architectures: x86
6648:Parameters: args[0] whether feature should be enabled or not
6649
6650With this capability enabled, CR2 will not be modified prior to the
6651emulated VM-exit when L1 intercepts a #PF exception that occurs in
6652L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
6653the emulated VM-exit when L1 intercepts a #DB exception that occurs in
6654L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
6655#DB) exception for L2, exception.has_payload will be set and the
6656faulting address (or the new DR6 bits*) will be reported in the
6657exception_payload field. Similarly, when userspace injects a #PF (or
6658#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
6659exception.has_payload and to put the faulting address - or the new DR6
6660bits\ [#]_ - in the exception_payload field.
6661
6662This capability also enables exception.pending in struct
6663kvm_vcpu_events, which allows userspace to distinguish between pending
6664and injected exceptions.
6665
6666
6667.. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception
6668       will clear DR6.RTM.
6669
66707.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
6671
6672:Architectures: x86, arm, arm64, mips
6673:Parameters: args[0] whether feature should be enabled or not
6674
6675Valid flags are::
6676
6677  #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE   (1 << 0)
6678  #define KVM_DIRTY_LOG_INITIALLY_SET           (1 << 1)
6679
6680With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not
6681automatically clear and write-protect all pages that are returned as dirty.
6682Rather, userspace will have to do this operation separately using
6683KVM_CLEAR_DIRTY_LOG.
6684
6685At the cost of a slightly more complicated operation, this provides better
6686scalability and responsiveness for two reasons.  First,
6687KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
6688than requiring to sync a full memslot; this ensures that KVM does not
6689take spinlocks for an extended period of time.  Second, in some cases a
6690large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
6691userspace actually using the data in the page.  Pages can be modified
6692during this time, which is inefficient for both the guest and userspace:
6693the guest will incur a higher penalty due to write protection faults,
6694while userspace can see false reports of dirty pages.  Manual reprotection
6695helps reducing this time, improving guest performance and reducing the
6696number of dirty log false positives.
6697
6698With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap
6699will be initialized to 1 when created.  This also improves performance because
6700dirty logging can be enabled gradually in small chunks on the first call
6701to KVM_CLEAR_DIRTY_LOG.  KVM_DIRTY_LOG_INITIALLY_SET depends on
6702KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
6703x86 and arm64 for now).
6704
6705KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
6706KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make
6707it hard or impossible to use it correctly.  The availability of
6708KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed.
6709Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
6710
67117.19 KVM_CAP_PPC_SECURE_GUEST
6712------------------------------
6713
6714:Architectures: ppc
6715
6716This capability indicates that KVM is running on a host that has
6717ultravisor firmware and thus can support a secure guest.  On such a
6718system, a guest can ask the ultravisor to make it a secure guest,
6719one whose memory is inaccessible to the host except for pages which
6720are explicitly requested to be shared with the host.  The ultravisor
6721notifies KVM when a guest requests to become a secure guest, and KVM
6722has the opportunity to veto the transition.
6723
6724If present, this capability can be enabled for a VM, meaning that KVM
6725will allow the transition to secure guest mode.  Otherwise KVM will
6726veto the transition.
6727
67287.20 KVM_CAP_HALT_POLL
6729----------------------
6730
6731:Architectures: all
6732:Target: VM
6733:Parameters: args[0] is the maximum poll time in nanoseconds
6734:Returns: 0 on success; -1 on error
6735
6736This capability overrides the kvm module parameter halt_poll_ns for the
6737target VM.
6738
6739VCPU polling allows a VCPU to poll for wakeup events instead of immediately
6740scheduling during guest halts. The maximum time a VCPU can spend polling is
6741controlled by the kvm module parameter halt_poll_ns. This capability allows
6742the maximum halt time to specified on a per-VM basis, effectively overriding
6743the module parameter for the target VM.
6744
67457.21 KVM_CAP_X86_USER_SPACE_MSR
6746-------------------------------
6747
6748:Architectures: x86
6749:Target: VM
6750:Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report
6751:Returns: 0 on success; -1 on error
6752
6753This capability enables trapping of #GP invoking RDMSR and WRMSR instructions
6754into user space.
6755
6756When a guest requests to read or write an MSR, KVM may not implement all MSRs
6757that are relevant to a respective system. It also does not differentiate by
6758CPU type.
6759
6760To allow more fine grained control over MSR handling, user space may enable
6761this capability. With it enabled, MSR accesses that match the mask specified in
6762args[0] and trigger a #GP event inside the guest by KVM will instead trigger
6763KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications which user space
6764can then handle to implement model specific MSR handling and/or user notifications
6765to inform a user that an MSR was not handled.
6766
67677.22 KVM_CAP_X86_BUS_LOCK_EXIT
6768-------------------------------
6769
6770:Architectures: x86
6771:Target: VM
6772:Parameters: args[0] defines the policy used when bus locks detected in guest
6773:Returns: 0 on success, -EINVAL when args[0] contains invalid bits
6774
6775Valid bits in args[0] are::
6776
6777  #define KVM_BUS_LOCK_DETECTION_OFF      (1 << 0)
6778  #define KVM_BUS_LOCK_DETECTION_EXIT     (1 << 1)
6779
6780Enabling this capability on a VM provides userspace with a way to select
6781a policy to handle the bus locks detected in guest. Userspace can obtain
6782the supported modes from the result of KVM_CHECK_EXTENSION and define it
6783through the KVM_ENABLE_CAP.
6784
6785KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
6786currently and mutually exclusive with each other. More bits can be added in
6787the future.
6788
6789With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
6790so that no additional actions are needed. This is the default mode.
6791
6792With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
6793in VM. KVM just exits to userspace when handling them. Userspace can enforce
6794its own throttling or other policy based mitigations.
6795
6796This capability is aimed to address the thread that VM can exploit bus locks to
6797degree the performance of the whole system. Once the userspace enable this
6798capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
6799KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
6800the bus lock vm exit can be preempted by a higher priority VM exit, the exit
6801notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
6802KVM_RUN_BUS_LOCK flag is used to distinguish between them.
6803
68047.23 KVM_CAP_PPC_DAWR1
6805----------------------
6806
6807:Architectures: ppc
6808:Parameters: none
6809:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
6810
6811This capability can be used to check / enable 2nd DAWR feature provided
6812by POWER10 processor.
6813
6814
68157.24 KVM_CAP_VM_COPY_ENC_CONTEXT_FROM
6816-------------------------------------
6817
6818Architectures: x86 SEV enabled
6819Type: vm
6820Parameters: args[0] is the fd of the source vm
6821Returns: 0 on success; ENOTTY on error
6822
6823This capability enables userspace to copy encryption context from the vm
6824indicated by the fd to the vm this is called on.
6825
6826This is intended to support in-guest workloads scheduled by the host. This
6827allows the in-guest workload to maintain its own NPTs and keeps the two vms
6828from accidentally clobbering each other with interrupts and the like (separate
6829APIC/MSRs/etc).
6830
68317.25 KVM_CAP_SGX_ATTRIBUTE
6832--------------------------
6833
6834:Architectures: x86
6835:Target: VM
6836:Parameters: args[0] is a file handle of a SGX attribute file in securityfs
6837:Returns: 0 on success, -EINVAL if the file handle is invalid or if a requested
6838          attribute is not supported by KVM.
6839
6840KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or
6841more priveleged enclave attributes.  args[0] must hold a file handle to a valid
6842SGX attribute file corresponding to an attribute that is supported/restricted
6843by KVM (currently only PROVISIONKEY).
6844
6845The SGX subsystem restricts access to a subset of enclave attributes to provide
6846additional security for an uncompromised kernel, e.g. use of the PROVISIONKEY
6847is restricted to deter malware from using the PROVISIONKEY to obtain a stable
6848system fingerprint.  To prevent userspace from circumventing such restrictions
6849by running an enclave in a VM, KVM prevents access to privileged attributes by
6850default.
6851
6852See Documentation/x86/sgx.rst for more details.
6853
68547.26 KVM_CAP_PPC_RPT_INVALIDATE
6855-------------------------------
6856
6857:Capability: KVM_CAP_PPC_RPT_INVALIDATE
6858:Architectures: ppc
6859:Type: vm
6860
6861This capability indicates that the kernel is capable of handling
6862H_RPT_INVALIDATE hcall.
6863
6864In order to enable the use of H_RPT_INVALIDATE in the guest,
6865user space might have to advertise it for the guest. For example,
6866IBM pSeries (sPAPR) guest starts using it if "hcall-rpt-invalidate" is
6867present in the "ibm,hypertas-functions" device-tree property.
6868
6869This capability is enabled for hypervisors on platforms like POWER9
6870that support radix MMU.
6871
68727.27 KVM_CAP_EXIT_ON_EMULATION_FAILURE
6873--------------------------------------
6874
6875:Architectures: x86
6876:Parameters: args[0] whether the feature should be enabled or not
6877
6878When this capability is enabled, an emulation failure will result in an exit
6879to userspace with KVM_INTERNAL_ERROR (except when the emulator was invoked
6880to handle a VMware backdoor instruction). Furthermore, KVM will now provide up
6881to 15 instruction bytes for any exit to userspace resulting from an emulation
6882failure.  When these exits to userspace occur use the emulation_failure struct
6883instead of the internal struct.  They both have the same layout, but the
6884emulation_failure struct matches the content better.  It also explicitly
6885defines the 'flags' field which is used to describe the fields in the struct
6886that are valid (ie: if KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES is
6887set in the 'flags' field then both 'insn_size' and 'insn_bytes' have valid data
6888in them.)
6889
68907.28 KVM_CAP_ARM_MTE
6891--------------------
6892
6893:Architectures: arm64
6894:Parameters: none
6895
6896This capability indicates that KVM (and the hardware) supports exposing the
6897Memory Tagging Extensions (MTE) to the guest. It must also be enabled by the
6898VMM before creating any VCPUs to allow the guest access. Note that MTE is only
6899available to a guest running in AArch64 mode and enabling this capability will
6900cause attempts to create AArch32 VCPUs to fail.
6901
6902When enabled the guest is able to access tags associated with any memory given
6903to the guest. KVM will ensure that the tags are maintained during swap or
6904hibernation of the host; however the VMM needs to manually save/restore the
6905tags as appropriate if the VM is migrated.
6906
6907When this capability is enabled all memory in memslots must be mapped as
6908not-shareable (no MAP_SHARED), attempts to create a memslot with a
6909MAP_SHARED mmap will result in an -EINVAL return.
6910
6911When enabled the VMM may make use of the ``KVM_ARM_MTE_COPY_TAGS`` ioctl to
6912perform a bulk copy of tags to/from the guest.
6913
69147.29 KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM
6915-------------------------------------
6916
6917Architectures: x86 SEV enabled
6918Type: vm
6919Parameters: args[0] is the fd of the source vm
6920Returns: 0 on success
6921
6922This capability enables userspace to migrate the encryption context from the VM
6923indicated by the fd to the VM this is called on.
6924
6925This is intended to support intra-host migration of VMs between userspace VMMs,
6926upgrading the VMM process without interrupting the guest.
6927
69288. Other capabilities.
6929======================
6930
6931This section lists capabilities that give information about other
6932features of the KVM implementation.
6933
69348.1 KVM_CAP_PPC_HWRNG
6935---------------------
6936
6937:Architectures: ppc
6938
6939This capability, if KVM_CHECK_EXTENSION indicates that it is
6940available, means that the kernel has an implementation of the
6941H_RANDOM hypercall backed by a hardware random-number generator.
6942If present, the kernel H_RANDOM handler can be enabled for guest use
6943with the KVM_CAP_PPC_ENABLE_HCALL capability.
6944
69458.2 KVM_CAP_HYPERV_SYNIC
6946------------------------
6947
6948:Architectures: x86
6949
6950This capability, if KVM_CHECK_EXTENSION indicates that it is
6951available, means that the kernel has an implementation of the
6952Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
6953used to support Windows Hyper-V based guest paravirt drivers(VMBus).
6954
6955In order to use SynIC, it has to be activated by setting this
6956capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
6957will disable the use of APIC hardware virtualization even if supported
6958by the CPU, as it's incompatible with SynIC auto-EOI behavior.
6959
69608.3 KVM_CAP_PPC_RADIX_MMU
6961-------------------------
6962
6963:Architectures: ppc
6964
6965This capability, if KVM_CHECK_EXTENSION indicates that it is
6966available, means that the kernel can support guests using the
6967radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
6968processor).
6969
69708.4 KVM_CAP_PPC_HASH_MMU_V3
6971---------------------------
6972
6973:Architectures: ppc
6974
6975This capability, if KVM_CHECK_EXTENSION indicates that it is
6976available, means that the kernel can support guests using the
6977hashed page table MMU defined in Power ISA V3.00 (as implemented in
6978the POWER9 processor), including in-memory segment tables.
6979
69808.5 KVM_CAP_MIPS_VZ
6981-------------------
6982
6983:Architectures: mips
6984
6985This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
6986it is available, means that full hardware assisted virtualization capabilities
6987of the hardware are available for use through KVM. An appropriate
6988KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
6989utilises it.
6990
6991If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
6992available, it means that the VM is using full hardware assisted virtualization
6993capabilities of the hardware. This is useful to check after creating a VM with
6994KVM_VM_MIPS_DEFAULT.
6995
6996The value returned by KVM_CHECK_EXTENSION should be compared against known
6997values (see below). All other values are reserved. This is to allow for the
6998possibility of other hardware assisted virtualization implementations which
6999may be incompatible with the MIPS VZ ASE.
7000
7001==  ==========================================================================
7002 0  The trap & emulate implementation is in use to run guest code in user
7003    mode. Guest virtual memory segments are rearranged to fit the guest in the
7004    user mode address space.
7005
7006 1  The MIPS VZ ASE is in use, providing full hardware assisted
7007    virtualization, including standard guest virtual memory segments.
7008==  ==========================================================================
7009
70108.6 KVM_CAP_MIPS_TE
7011-------------------
7012
7013:Architectures: mips
7014
7015This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
7016it is available, means that the trap & emulate implementation is available to
7017run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
7018assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
7019to KVM_CREATE_VM to create a VM which utilises it.
7020
7021If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
7022available, it means that the VM is using trap & emulate.
7023
70248.7 KVM_CAP_MIPS_64BIT
7025----------------------
7026
7027:Architectures: mips
7028
7029This capability indicates the supported architecture type of the guest, i.e. the
7030supported register and address width.
7031
7032The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
7033kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
7034be checked specifically against known values (see below). All other values are
7035reserved.
7036
7037==  ========================================================================
7038 0  MIPS32 or microMIPS32.
7039    Both registers and addresses are 32-bits wide.
7040    It will only be possible to run 32-bit guest code.
7041
7042 1  MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
7043    Registers are 64-bits wide, but addresses are 32-bits wide.
7044    64-bit guest code may run but cannot access MIPS64 memory segments.
7045    It will also be possible to run 32-bit guest code.
7046
7047 2  MIPS64 or microMIPS64 with access to all address segments.
7048    Both registers and addresses are 64-bits wide.
7049    It will be possible to run 64-bit or 32-bit guest code.
7050==  ========================================================================
7051
70528.9 KVM_CAP_ARM_USER_IRQ
7053------------------------
7054
7055:Architectures: arm, arm64
7056
7057This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
7058that if userspace creates a VM without an in-kernel interrupt controller, it
7059will be notified of changes to the output level of in-kernel emulated devices,
7060which can generate virtual interrupts, presented to the VM.
7061For such VMs, on every return to userspace, the kernel
7062updates the vcpu's run->s.regs.device_irq_level field to represent the actual
7063output level of the device.
7064
7065Whenever kvm detects a change in the device output level, kvm guarantees at
7066least one return to userspace before running the VM.  This exit could either
7067be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
7068userspace can always sample the device output level and re-compute the state of
7069the userspace interrupt controller.  Userspace should always check the state
7070of run->s.regs.device_irq_level on every kvm exit.
7071The value in run->s.regs.device_irq_level can represent both level and edge
7072triggered interrupt signals, depending on the device.  Edge triggered interrupt
7073signals will exit to userspace with the bit in run->s.regs.device_irq_level
7074set exactly once per edge signal.
7075
7076The field run->s.regs.device_irq_level is available independent of
7077run->kvm_valid_regs or run->kvm_dirty_regs bits.
7078
7079If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
7080number larger than 0 indicating the version of this capability is implemented
7081and thereby which bits in run->s.regs.device_irq_level can signal values.
7082
7083Currently the following bits are defined for the device_irq_level bitmap::
7084
7085  KVM_CAP_ARM_USER_IRQ >= 1:
7086
7087    KVM_ARM_DEV_EL1_VTIMER -  EL1 virtual timer
7088    KVM_ARM_DEV_EL1_PTIMER -  EL1 physical timer
7089    KVM_ARM_DEV_PMU        -  ARM PMU overflow interrupt signal
7090
7091Future versions of kvm may implement additional events. These will get
7092indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
7093listed above.
7094
70958.10 KVM_CAP_PPC_SMT_POSSIBLE
7096-----------------------------
7097
7098:Architectures: ppc
7099
7100Querying this capability returns a bitmap indicating the possible
7101virtual SMT modes that can be set using KVM_CAP_PPC_SMT.  If bit N
7102(counting from the right) is set, then a virtual SMT mode of 2^N is
7103available.
7104
71058.11 KVM_CAP_HYPERV_SYNIC2
7106--------------------------
7107
7108:Architectures: x86
7109
7110This capability enables a newer version of Hyper-V Synthetic interrupt
7111controller (SynIC).  The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
7112doesn't clear SynIC message and event flags pages when they are enabled by
7113writing to the respective MSRs.
7114
71158.12 KVM_CAP_HYPERV_VP_INDEX
7116----------------------------
7117
7118:Architectures: x86
7119
7120This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr.  Its
7121value is used to denote the target vcpu for a SynIC interrupt.  For
7122compatibilty, KVM initializes this msr to KVM's internal vcpu index.  When this
7123capability is absent, userspace can still query this msr's value.
7124
71258.13 KVM_CAP_S390_AIS_MIGRATION
7126-------------------------------
7127
7128:Architectures: s390
7129:Parameters: none
7130
7131This capability indicates if the flic device will be able to get/set the
7132AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
7133to discover this without having to create a flic device.
7134
71358.14 KVM_CAP_S390_PSW
7136---------------------
7137
7138:Architectures: s390
7139
7140This capability indicates that the PSW is exposed via the kvm_run structure.
7141
71428.15 KVM_CAP_S390_GMAP
7143----------------------
7144
7145:Architectures: s390
7146
7147This capability indicates that the user space memory used as guest mapping can
7148be anywhere in the user memory address space, as long as the memory slots are
7149aligned and sized to a segment (1MB) boundary.
7150
71518.16 KVM_CAP_S390_COW
7152---------------------
7153
7154:Architectures: s390
7155
7156This capability indicates that the user space memory used as guest mapping can
7157use copy-on-write semantics as well as dirty pages tracking via read-only page
7158tables.
7159
71608.17 KVM_CAP_S390_BPB
7161---------------------
7162
7163:Architectures: s390
7164
7165This capability indicates that kvm will implement the interfaces to handle
7166reset, migration and nested KVM for branch prediction blocking. The stfle
7167facility 82 should not be provided to the guest without this capability.
7168
71698.18 KVM_CAP_HYPERV_TLBFLUSH
7170----------------------------
7171
7172:Architectures: x86
7173
7174This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
7175hypercalls:
7176HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
7177HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
7178
71798.19 KVM_CAP_ARM_INJECT_SERROR_ESR
7180----------------------------------
7181
7182:Architectures: arm, arm64
7183
7184This capability indicates that userspace can specify (via the
7185KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
7186takes a virtual SError interrupt exception.
7187If KVM advertises this capability, userspace can only specify the ISS field for
7188the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
7189CPU when the exception is taken. If this virtual SError is taken to EL1 using
7190AArch64, this value will be reported in the ISS field of ESR_ELx.
7191
7192See KVM_CAP_VCPU_EVENTS for more details.
7193
71948.20 KVM_CAP_HYPERV_SEND_IPI
7195----------------------------
7196
7197:Architectures: x86
7198
7199This capability indicates that KVM supports paravirtualized Hyper-V IPI send
7200hypercalls:
7201HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.
7202
72038.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH
7204-----------------------------------
7205
7206:Architectures: x86
7207
7208This capability indicates that KVM running on top of Hyper-V hypervisor
7209enables Direct TLB flush for its guests meaning that TLB flush
7210hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM.
7211Due to the different ABI for hypercall parameters between Hyper-V and
7212KVM, enabling this capability effectively disables all hypercall
7213handling by KVM (as some KVM hypercall may be mistakenly treated as TLB
7214flush hypercalls by Hyper-V) so userspace should disable KVM identification
7215in CPUID and only exposes Hyper-V identification. In this case, guest
7216thinks it's running on Hyper-V and only use Hyper-V hypercalls.
7217
72188.22 KVM_CAP_S390_VCPU_RESETS
7219-----------------------------
7220
7221:Architectures: s390
7222
7223This capability indicates that the KVM_S390_NORMAL_RESET and
7224KVM_S390_CLEAR_RESET ioctls are available.
7225
72268.23 KVM_CAP_S390_PROTECTED
7227---------------------------
7228
7229:Architectures: s390
7230
7231This capability indicates that the Ultravisor has been initialized and
7232KVM can therefore start protected VMs.
7233This capability governs the KVM_S390_PV_COMMAND ioctl and the
7234KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
7235guests when the state change is invalid.
7236
72378.24 KVM_CAP_STEAL_TIME
7238-----------------------
7239
7240:Architectures: arm64, x86
7241
7242This capability indicates that KVM supports steal time accounting.
7243When steal time accounting is supported it may be enabled with
7244architecture-specific interfaces.  This capability and the architecture-
7245specific interfaces must be consistent, i.e. if one says the feature
7246is supported, than the other should as well and vice versa.  For arm64
7247see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
7248For x86 see Documentation/virt/kvm/msr.rst "MSR_KVM_STEAL_TIME".
7249
72508.25 KVM_CAP_S390_DIAG318
7251-------------------------
7252
7253:Architectures: s390
7254
7255This capability enables a guest to set information about its control program
7256(i.e. guest kernel type and version). The information is helpful during
7257system/firmware service events, providing additional data about the guest
7258environments running on the machine.
7259
7260The information is associated with the DIAGNOSE 0x318 instruction, which sets
7261an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and
7262a 7-byte Control Program Version Code (CPVC). The CPNC determines what
7263environment the control program is running in (e.g. Linux, z/VM...), and the
7264CPVC is used for information specific to OS (e.g. Linux version, Linux
7265distribution...)
7266
7267If this capability is available, then the CPNC and CPVC can be synchronized
7268between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318).
7269
72708.26 KVM_CAP_X86_USER_SPACE_MSR
7271-------------------------------
7272
7273:Architectures: x86
7274
7275This capability indicates that KVM supports deflection of MSR reads and
7276writes to user space. It can be enabled on a VM level. If enabled, MSR
7277accesses that would usually trigger a #GP by KVM into the guest will
7278instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
7279KVM_EXIT_X86_WRMSR exit notifications.
7280
72818.27 KVM_CAP_X86_MSR_FILTER
7282---------------------------
7283
7284:Architectures: x86
7285
7286This capability indicates that KVM supports that accesses to user defined MSRs
7287may be rejected. With this capability exposed, KVM exports new VM ioctl
7288KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR
7289ranges that KVM should reject access to.
7290
7291In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
7292trap and emulate MSRs that are outside of the scope of KVM as well as
7293limit the attack surface on KVM's MSR emulation code.
7294
72958.28 KVM_CAP_ENFORCE_PV_FEATURE_CPUID
7296-----------------------------
7297
7298Architectures: x86
7299
7300When enabled, KVM will disable paravirtual features provided to the
7301guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
7302(0x40000001). Otherwise, a guest may use the paravirtual features
7303regardless of what has actually been exposed through the CPUID leaf.
7304
73058.29 KVM_CAP_DIRTY_LOG_RING
7306---------------------------
7307
7308:Architectures: x86
7309:Parameters: args[0] - size of the dirty log ring
7310
7311KVM is capable of tracking dirty memory using ring buffers that are
7312mmaped into userspace; there is one dirty ring per vcpu.
7313
7314The dirty ring is available to userspace as an array of
7315``struct kvm_dirty_gfn``.  Each dirty entry it's defined as::
7316
7317  struct kvm_dirty_gfn {
7318          __u32 flags;
7319          __u32 slot; /* as_id | slot_id */
7320          __u64 offset;
7321  };
7322
7323The following values are defined for the flags field to define the
7324current state of the entry::
7325
7326  #define KVM_DIRTY_GFN_F_DIRTY           BIT(0)
7327  #define KVM_DIRTY_GFN_F_RESET           BIT(1)
7328  #define KVM_DIRTY_GFN_F_MASK            0x3
7329
7330Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM
7331ioctl to enable this capability for the new guest and set the size of
7332the rings.  Enabling the capability is only allowed before creating any
7333vCPU, and the size of the ring must be a power of two.  The larger the
7334ring buffer, the less likely the ring is full and the VM is forced to
7335exit to userspace. The optimal size depends on the workload, but it is
7336recommended that it be at least 64 KiB (4096 entries).
7337
7338Just like for dirty page bitmaps, the buffer tracks writes to
7339all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was
7340set in KVM_SET_USER_MEMORY_REGION.  Once a memory region is registered
7341with the flag set, userspace can start harvesting dirty pages from the
7342ring buffer.
7343
7344An entry in the ring buffer can be unused (flag bits ``00``),
7345dirty (flag bits ``01``) or harvested (flag bits ``1X``).  The
7346state machine for the entry is as follows::
7347
7348          dirtied         harvested        reset
7349     00 -----------> 01 -------------> 1X -------+
7350      ^                                          |
7351      |                                          |
7352      +------------------------------------------+
7353
7354To harvest the dirty pages, userspace accesses the mmaped ring buffer
7355to read the dirty GFNs.  If the flags has the DIRTY bit set (at this stage
7356the RESET bit must be cleared), then it means this GFN is a dirty GFN.
7357The userspace should harvest this GFN and mark the flags from state
7358``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set
7359to show that this GFN is harvested and waiting for a reset), and move
7360on to the next GFN.  The userspace should continue to do this until the
7361flags of a GFN have the DIRTY bit cleared, meaning that it has harvested
7362all the dirty GFNs that were available.
7363
7364It's not necessary for userspace to harvest the all dirty GFNs at once.
7365However it must collect the dirty GFNs in sequence, i.e., the userspace
7366program cannot skip one dirty GFN to collect the one next to it.
7367
7368After processing one or more entries in the ring buffer, userspace
7369calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about
7370it, so that the kernel will reprotect those collected GFNs.
7371Therefore, the ioctl must be called *before* reading the content of
7372the dirty pages.
7373
7374The dirty ring can get full.  When it happens, the KVM_RUN of the
7375vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL.
7376
7377The dirty ring interface has a major difference comparing to the
7378KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from
7379userspace, it's still possible that the kernel has not yet flushed the
7380processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the
7381flushing is done by the KVM_GET_DIRTY_LOG ioctl).  To achieve that, one
7382needs to kick the vcpu out of KVM_RUN using a signal.  The resulting
7383vmexit ensures that all dirty GFNs are flushed to the dirty rings.
7384
7385NOTE: the capability KVM_CAP_DIRTY_LOG_RING and the corresponding
7386ioctl KVM_RESET_DIRTY_RINGS are mutual exclusive to the existing ioctls
7387KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG.  After enabling
7388KVM_CAP_DIRTY_LOG_RING with an acceptable dirty ring size, the virtual
7389machine will switch to ring-buffer dirty page tracking and further
7390KVM_GET_DIRTY_LOG or KVM_CLEAR_DIRTY_LOG ioctls will fail.
7391
73928.30 KVM_CAP_XEN_HVM
7393--------------------
7394
7395:Architectures: x86
7396
7397This capability indicates the features that Xen supports for hosting Xen
7398PVHVM guests. Valid flags are::
7399
7400  #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR	(1 << 0)
7401  #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL	(1 << 1)
7402  #define KVM_XEN_HVM_CONFIG_SHARED_INFO	(1 << 2)
7403  #define KVM_XEN_HVM_CONFIG_RUNSTATE		(1 << 2)
7404
7405The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
7406ioctl is available, for the guest to set its hypercall page.
7407
7408If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be
7409provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page
7410contents, to request that KVM generate hypercall page content automatically
7411and also enable interception of guest hypercalls with KVM_EXIT_XEN.
7412
7413The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the
7414KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and
7415KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors
7416for event channel upcalls when the evtchn_upcall_pending field of a vcpu's
7417vcpu_info is set.
7418
7419The KVM_XEN_HVM_CONFIG_RUNSTATE flag indicates that the runstate-related
7420features KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR/_CURRENT/_DATA/_ADJUST are
7421supported by the KVM_XEN_VCPU_SET_ATTR/KVM_XEN_VCPU_GET_ATTR ioctls.
7422
74238.31 KVM_CAP_PPC_MULTITCE
7424-------------------------
7425
7426:Capability: KVM_CAP_PPC_MULTITCE
7427:Architectures: ppc
7428:Type: vm
7429
7430This capability means the kernel is capable of handling hypercalls
7431H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
7432space. This significantly accelerates DMA operations for PPC KVM guests.
7433User space should expect that its handlers for these hypercalls
7434are not going to be called if user space previously registered LIOBN
7435in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
7436
7437In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
7438user space might have to advertise it for the guest. For example,
7439IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
7440present in the "ibm,hypertas-functions" device-tree property.
7441
7442The hypercalls mentioned above may or may not be processed successfully
7443in the kernel based fast path. If they can not be handled by the kernel,
7444they will get passed on to user space. So user space still has to have
7445an implementation for these despite the in kernel acceleration.
7446
7447This capability is always enabled.
7448
74498.32 KVM_CAP_PTP_KVM
7450--------------------
7451
7452:Architectures: arm64
7453
7454This capability indicates that the KVM virtual PTP service is
7455supported in the host. A VMM can check whether the service is
7456available to the guest on migration.
7457
74588.33 KVM_CAP_HYPERV_ENFORCE_CPUID
7459---------------------------------
7460
7461Architectures: x86
7462
7463When enabled, KVM will disable emulated Hyper-V features provided to the
7464guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all
7465currently implmented Hyper-V features are provided unconditionally when
7466Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001)
7467leaf.
7468
74698.34 KVM_CAP_EXIT_HYPERCALL
7470---------------------------
7471
7472:Capability: KVM_CAP_EXIT_HYPERCALL
7473:Architectures: x86
7474:Type: vm
7475
7476This capability, if enabled, will cause KVM to exit to userspace
7477with KVM_EXIT_HYPERCALL exit reason to process some hypercalls.
7478
7479Calling KVM_CHECK_EXTENSION for this capability will return a bitmask
7480of hypercalls that can be configured to exit to userspace.
7481Right now, the only such hypercall is KVM_HC_MAP_GPA_RANGE.
7482
7483The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset
7484of the result of KVM_CHECK_EXTENSION.  KVM will forward to userspace
7485the hypercalls whose corresponding bit is in the argument, and return
7486ENOSYS for the others.
7487