]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - Documentation/virt/kvm/api.rst
Merge tag 'kvm-x86-misc-6.7' of https://github.com/kvm-x86/linux into HEAD
[thirdparty/kernel/stable.git] / Documentation / virt / kvm / api.rst
CommitLineData
106ee47d
MCC
1.. SPDX-License-Identifier: GPL-2.0
2
3===================================================================
9c1b96e3
AK
4The Definitive KVM (Kernel-based Virtual Machine) API Documentation
5===================================================================
6
71. General description
106ee47d 8======================
9c1b96e3
AK
9
10The kvm API is a set of ioctls that are issued to control various aspects
80b10aa9 11of a virtual machine. The ioctls belong to the following classes:
9c1b96e3
AK
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
5e124900 15 virtual machines.
9c1b96e3
AK
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
ddba9180 19 create virtual cpus (vcpus) and devices.
9c1b96e3 20
5e124900
SC
21 VM ioctls must be issued from the same process (address space) that was
22 used to create the VM.
9c1b96e3
AK
23
24 - vcpu ioctls: These query and set attributes that control the operation
25 of a single virtual cpu.
26
5e124900
SC
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.
9c1b96e3 31
ddba9180
SC
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.
414fa985 37
2044892d 382. File descriptors
106ee47d 39===================
9c1b96e3
AK
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
2044892d 44handle will create a VM file descriptor which can be used to issue VM
ddba9180
SC
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.
9c1b96e3
AK
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
5e124900
SC
55the API. See "General description" for details on the ioctl usage
56model that is supported by KVM.
eca6be56 57
c44456f2 58It is important to note that although VM ioctls may only be issued from
919f6cd8
SC
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
3747c5d3 68file descriptor is released, creating additional references to a VM
919f6cd8
SC
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
9c1b96e3 753. Extensions
106ee47d 76=============
9c1b96e3
AK
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
c9f3f2d8 83The extension mechanism is not based on the Linux version number.
9c1b96e3
AK
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
414fa985 88
9c1b96e3 894. API description
106ee47d 90==================
9c1b96e3
AK
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
106ee47d
MCC
96 Capability:
97 which KVM extension provides this ioctl. Can be 'basic',
9c1b96e3 98 which means that is will be provided by any kernel that supports
7f05db6a 99 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
9c1b96e3 100 means availability needs to be checked with KVM_CHECK_EXTENSION
7f05db6a
MT
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.
9c1b96e3 105
106ee47d
MCC
106 Architectures:
107 which instruction set architectures provide this ioctl.
9c1b96e3
AK
108 x86 includes both i386 and x86_64.
109
106ee47d
MCC
110 Type:
111 system, vm, or vcpu.
9c1b96e3 112
106ee47d
MCC
113 Parameters:
114 what parameters are accepted by the ioctl.
9c1b96e3 115
106ee47d
MCC
116 Returns:
117 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
9c1b96e3
AK
118 are not detailed, but errors with specific meanings are.
119
414fa985 120
9c1b96e3 1214.1 KVM_GET_API_VERSION
106ee47d 122-----------------------
9c1b96e3 123
106ee47d
MCC
124:Capability: basic
125:Architectures: all
126:Type: system ioctl
127:Parameters: none
128:Returns: the constant KVM_API_VERSION (=12)
9c1b96e3
AK
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
414fa985 137
9c1b96e3 1384.2 KVM_CREATE_VM
106ee47d 139-----------------
9c1b96e3 140
106ee47d
MCC
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.
9c1b96e3 146
bcb85c88 147The new VM has no virtual cpus and no memory.
a8a3c426 148You probably want to use 0 as machine type.
e08b9637
CO
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).
9c1b96e3 153
233a7cb2
SP
154On arm64, the physical address size for a VM (IPA Size limit) is limited
155to 40bits by default. The limit can be configured if the host supports the
156extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use
157KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type
158identifier, where IPA_Bits is the maximum width of any physical
159address used by the VM. The IPA_Bits is encoded in bits[7-0] of the
160machine type identifier.
161
106ee47d 162e.g, to configure a guest to use 48bit physical address size::
233a7cb2
SP
163
164 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48));
165
106ee47d 166The requested size (IPA_Bits) must be:
233a7cb2 167
106ee47d
MCC
168 == =========================================================
169 0 Implies default size, 40bits (for backward compatibility)
170 N Implies N bits, where N is a positive integer such that,
233a7cb2 171 32 <= N <= Host_IPA_Limit
106ee47d 172 == =========================================================
233a7cb2
SP
173
174Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and
175is dependent on the CPU capability and the kernel configuration. The limit can
176be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
177ioctl() at run-time.
178
7d717558
MZ
179Creation of the VM will fail if the requested IPA size (whether it is
180implicit or explicit) is unsupported on the host.
181
233a7cb2
SP
182Please note that configuring the IPA size does not affect the capability
183exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
184size of the address translated by the stage2 level (guest physical to
185host physical address translations).
186
187
801e459a 1884.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
106ee47d
MCC
189----------------------------------------------------------
190
191:Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
192:Architectures: x86
193:Type: system ioctl
194:Parameters: struct kvm_msr_list (in/out)
195:Returns: 0 on success; -1 on error
9c1b96e3 196
9c1b96e3 197Errors:
106ee47d
MCC
198
199 ====== ============================================================
200 EFAULT the msr index list cannot be read from or written to
24e7475f 201 E2BIG the msr index list is too big to fit in the array specified by
9c1b96e3 202 the user.
106ee47d 203 ====== ============================================================
9c1b96e3 204
106ee47d
MCC
205::
206
207 struct kvm_msr_list {
9c1b96e3
AK
208 __u32 nmsrs; /* number of msrs in entries */
209 __u32 indices[0];
106ee47d 210 };
9c1b96e3 211
801e459a
TL
212The user fills in the size of the indices array in nmsrs, and in return
213kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
214indices array with their numbers.
215
216KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
217varies by kvm version and host processor, but does not change otherwise.
9c1b96e3 218
2e2602ca
AK
219Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
220not returned in the MSR list, as different vcpus can have a different number
221of banks, as set via the KVM_X86_SETUP_MCE ioctl.
222
801e459a
TL
223KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
224to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
225and processor features that are exposed via MSRs (e.g., VMX capabilities).
226This list also varies by kvm version and host processor, but does not change
227otherwise.
228
414fa985 229
9c1b96e3 2304.4 KVM_CHECK_EXTENSION
106ee47d 231-----------------------
9c1b96e3 232
106ee47d
MCC
233:Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
234:Architectures: all
235:Type: system ioctl, vm ioctl
236:Parameters: extension identifier (KVM_CAP_*)
237:Returns: 0 if unsupported; 1 (or some other positive integer) if supported
9c1b96e3
AK
238
239The API allows the application to query about extensions to the core
240kvm API. Userspace passes an extension identifier (an integer) and
241receives an integer that describes the extension availability.
242Generally 0 means no and 1 means yes, but some extensions may report
243additional information in the integer return value.
244
92b591a4
AG
245Based on their initialization different VMs may have different capabilities.
246It is thus encouraged to use the vm ioctl to query for capabilities (available
247with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
414fa985 248
9c1b96e3 2494.5 KVM_GET_VCPU_MMAP_SIZE
106ee47d 250--------------------------
9c1b96e3 251
106ee47d
MCC
252:Capability: basic
253:Architectures: all
254:Type: system ioctl
255:Parameters: none
256:Returns: size of vcpu mmap area, in bytes
9c1b96e3
AK
257
258The KVM_RUN ioctl (cf.) communicates with userspace via a shared
259memory region. This ioctl returns the size of that region. See the
260KVM_RUN documentation for details.
261
fb04a1ed
PX
262Besides the size of the KVM_RUN communication region, other areas of
263the VCPU file descriptor can be mmap-ed, including:
264
265- if KVM_CAP_COALESCED_MMIO is available, a page at
266 KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons,
267 this page is included in the result of KVM_GET_VCPU_MMAP_SIZE.
268 KVM_CAP_COALESCED_MMIO is not documented yet.
269
270- if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at
271 KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE. For more information on
272 KVM_CAP_DIRTY_LOG_RING, see section 8.3.
273
414fa985 274
68ba6974 2754.7 KVM_CREATE_VCPU
106ee47d 276-------------------
9c1b96e3 277
106ee47d
MCC
278:Capability: basic
279:Architectures: all
280:Type: vm ioctl
281:Parameters: vcpu id (apic id on x86)
282:Returns: vcpu fd on success, -1 on error
9c1b96e3 283
0b1b1dfd
GK
284This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
285The vcpu id is an integer in the range [0, max_vcpu_id).
8c3ba334
SL
286
287The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
288the KVM_CHECK_EXTENSION ioctl() at run-time.
289The maximum possible value for max_vcpus can be retrieved using the
290KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
291
76d25402
PE
292If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
293cpus max.
8c3ba334
SL
294If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
295same as the value returned from KVM_CAP_NR_VCPUS.
9c1b96e3 296
0b1b1dfd
GK
297The maximum possible value for max_vcpu_id can be retrieved using the
298KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
299
300If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
301is the same as the value returned from KVM_CAP_MAX_VCPUS.
302
371fefd6
PM
303On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
304threads in one or more virtual CPU cores. (This is because the
305hardware requires all the hardware threads in a CPU core to be in the
306same partition.) The KVM_CAP_PPC_SMT capability indicates the number
36442687
AK
307of vcpus per virtual core (vcore). The vcore id is obtained by
308dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
309given vcore will always be in the same physical core as each other
310(though that might be a different physical core from time to time).
311Userspace can control the threading (SMT) mode of the guest by its
312allocation of vcpu ids. For example, if userspace wants
313single-threaded guest vcpus, it should make all vcpu ids be a multiple
314of the number of vcpus per vcore.
315
5b1c1493
CO
316For virtual cpus that have been created with S390 user controlled virtual
317machines, the resulting vcpu fd can be memory mapped at page offset
318KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
319cpu's hardware control block.
320
414fa985 321
68ba6974 3224.8 KVM_GET_DIRTY_LOG (vm ioctl)
106ee47d 323--------------------------------
9c1b96e3 324
106ee47d
MCC
325:Capability: basic
326:Architectures: all
327:Type: vm ioctl
328:Parameters: struct kvm_dirty_log (in/out)
329:Returns: 0 on success, -1 on error
9c1b96e3 330
106ee47d
MCC
331::
332
333 /* for KVM_GET_DIRTY_LOG */
334 struct kvm_dirty_log {
9c1b96e3
AK
335 __u32 slot;
336 __u32 padding;
337 union {
338 void __user *dirty_bitmap; /* one bit per page */
339 __u64 padding;
340 };
106ee47d 341 };
9c1b96e3
AK
342
343Given a memory slot, return a bitmap containing any pages dirtied
344since the last call to this ioctl. Bit 0 is the first page in the
345memory slot. Ensure the entire structure is cleared to avoid padding
346issues.
347
01ead84c
ZY
348If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
349the address space for which you want to return the dirty bitmap. See
350KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
f481b069 351
2a31b9db 352The bits in the dirty bitmap are cleared before the ioctl returns, unless
d7547c55 353KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information,
2a31b9db 354see the description of the capability.
414fa985 355
1cfc9c4b
DW
356Note that the Xen shared info page, if configured, shall always be assumed
357to be dirty. KVM will not explicitly mark it such.
358
414fa985 359
68ba6974 3604.10 KVM_RUN
106ee47d
MCC
361------------
362
363:Capability: basic
364:Architectures: all
365:Type: vcpu ioctl
366:Parameters: none
367:Returns: 0 on success, -1 on error
9c1b96e3 368
9c1b96e3 369Errors:
106ee47d 370
3557ae18 371 ======= ==============================================================
106ee47d 372 EINTR an unmasked signal is pending
3557ae18
AE
373 ENOEXEC the vcpu hasn't been initialized or the guest tried to execute
374 instructions from device memory (arm64)
375 ENOSYS data abort outside memslots with no syndrome info and
376 KVM_CAP_ARM_NISV_TO_USER not enabled (arm64)
377 EPERM SVE feature set but not finalized (arm64)
378 ======= ==============================================================
9c1b96e3
AK
379
380This ioctl is used to run a guest virtual cpu. While there are no
381explicit parameters, there is an implicit parameter block that can be
382obtained by mmap()ing the vcpu fd at offset 0, with the size given by
383KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
384kvm_run' (see below).
385
414fa985 386
68ba6974 3874.11 KVM_GET_REGS
106ee47d 388-----------------
9c1b96e3 389
106ee47d 390:Capability: basic
3fbf4207 391:Architectures: all except arm64
106ee47d
MCC
392:Type: vcpu ioctl
393:Parameters: struct kvm_regs (out)
394:Returns: 0 on success, -1 on error
9c1b96e3
AK
395
396Reads the general purpose registers from the vcpu.
397
106ee47d
MCC
398::
399
400 /* x86 */
401 struct kvm_regs {
9c1b96e3
AK
402 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
403 __u64 rax, rbx, rcx, rdx;
404 __u64 rsi, rdi, rsp, rbp;
405 __u64 r8, r9, r10, r11;
406 __u64 r12, r13, r14, r15;
407 __u64 rip, rflags;
106ee47d 408 };
9c1b96e3 409
106ee47d
MCC
410 /* mips */
411 struct kvm_regs {
c2d2c21b
JH
412 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
413 __u64 gpr[32];
414 __u64 hi;
415 __u64 lo;
416 __u64 pc;
106ee47d 417 };
c2d2c21b 418
6f0257a0
TZ
419 /* LoongArch */
420 struct kvm_regs {
421 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
422 unsigned long gpr[32];
423 unsigned long pc;
424 };
425
414fa985 426
68ba6974 4274.12 KVM_SET_REGS
106ee47d 428-----------------
9c1b96e3 429
106ee47d 430:Capability: basic
3fbf4207 431:Architectures: all except arm64
106ee47d
MCC
432:Type: vcpu ioctl
433:Parameters: struct kvm_regs (in)
434:Returns: 0 on success, -1 on error
9c1b96e3
AK
435
436Writes the general purpose registers into the vcpu.
437
438See KVM_GET_REGS for the data structure.
439
414fa985 440
68ba6974 4414.13 KVM_GET_SREGS
106ee47d 442------------------
9c1b96e3 443
106ee47d
MCC
444:Capability: basic
445:Architectures: x86, ppc
446:Type: vcpu ioctl
447:Parameters: struct kvm_sregs (out)
448:Returns: 0 on success, -1 on error
9c1b96e3
AK
449
450Reads special registers from the vcpu.
451
106ee47d
MCC
452::
453
454 /* x86 */
455 struct kvm_sregs {
9c1b96e3
AK
456 struct kvm_segment cs, ds, es, fs, gs, ss;
457 struct kvm_segment tr, ldt;
458 struct kvm_dtable gdt, idt;
459 __u64 cr0, cr2, cr3, cr4, cr8;
460 __u64 efer;
461 __u64 apic_base;
462 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
106ee47d 463 };
9c1b96e3 464
106ee47d 465 /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
5ce941ee 466
9c1b96e3
AK
467interrupt_bitmap is a bitmap of pending external interrupts. At most
468one bit may be set. This interrupt has been acknowledged by the APIC
469but not yet injected into the cpu core.
470
414fa985 471
68ba6974 4724.14 KVM_SET_SREGS
106ee47d 473------------------
9c1b96e3 474
106ee47d
MCC
475:Capability: basic
476:Architectures: x86, ppc
477:Type: vcpu ioctl
478:Parameters: struct kvm_sregs (in)
479:Returns: 0 on success, -1 on error
9c1b96e3
AK
480
481Writes special registers into the vcpu. See KVM_GET_SREGS for the
482data structures.
483
414fa985 484
68ba6974 4854.15 KVM_TRANSLATE
106ee47d 486------------------
9c1b96e3 487
106ee47d
MCC
488:Capability: basic
489:Architectures: x86
490:Type: vcpu ioctl
491:Parameters: struct kvm_translation (in/out)
492:Returns: 0 on success, -1 on error
9c1b96e3
AK
493
494Translates a virtual address according to the vcpu's current address
495translation mode.
496
106ee47d
MCC
497::
498
499 struct kvm_translation {
9c1b96e3
AK
500 /* in */
501 __u64 linear_address;
502
503 /* out */
504 __u64 physical_address;
505 __u8 valid;
506 __u8 writeable;
507 __u8 usermode;
508 __u8 pad[5];
106ee47d 509 };
9c1b96e3 510
414fa985 511
68ba6974 5124.16 KVM_INTERRUPT
106ee47d 513------------------
9c1b96e3 514
106ee47d 515:Capability: basic
6f0257a0 516:Architectures: x86, ppc, mips, riscv, loongarch
106ee47d
MCC
517:Type: vcpu ioctl
518:Parameters: struct kvm_interrupt (in)
519:Returns: 0 on success, negative on failure.
9c1b96e3 520
1c1a9ce9 521Queues a hardware interrupt vector to be injected.
9c1b96e3 522
106ee47d
MCC
523::
524
525 /* for KVM_INTERRUPT */
526 struct kvm_interrupt {
9c1b96e3
AK
527 /* in */
528 __u32 irq;
106ee47d 529 };
9c1b96e3 530
6f7a2bd4 531X86:
106ee47d
MCC
532^^^^
533
534:Returns:
6f7a2bd4 535
106ee47d
MCC
536 ========= ===================================
537 0 on success,
538 -EEXIST if an interrupt is already enqueued
3747c5d3 539 -EINVAL the irq number is invalid
106ee47d
MCC
540 -ENXIO if the PIC is in the kernel
541 -EFAULT if the pointer is invalid
542 ========= ===================================
1c1a9ce9
SR
543
544Note 'irq' is an interrupt vector, not an interrupt pin or line. This
545ioctl is useful if the in-kernel PIC is not used.
9c1b96e3 546
6f7a2bd4 547PPC:
106ee47d 548^^^^
6f7a2bd4 549
57f33f1a 550Queues an external interrupt to be injected. This ioctl is overloaded
6f7a2bd4
AG
551with 3 different irq values:
552
553a) KVM_INTERRUPT_SET
554
106ee47d
MCC
555 This injects an edge type external interrupt into the guest once it's ready
556 to receive interrupts. When injected, the interrupt is done.
6f7a2bd4
AG
557
558b) KVM_INTERRUPT_UNSET
559
106ee47d 560 This unsets any pending interrupt.
6f7a2bd4 561
106ee47d 562 Only available with KVM_CAP_PPC_UNSET_IRQ.
6f7a2bd4
AG
563
564c) KVM_INTERRUPT_SET_LEVEL
565
106ee47d
MCC
566 This injects a level type external interrupt into the guest context. The
567 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
568 is triggered.
6f7a2bd4 569
106ee47d 570 Only available with KVM_CAP_PPC_IRQ_LEVEL.
6f7a2bd4
AG
571
572Note that any value for 'irq' other than the ones stated above is invalid
573and incurs unexpected behavior.
574
5e124900
SC
575This is an asynchronous vcpu ioctl and can be invoked from any thread.
576
c2d2c21b 577MIPS:
106ee47d 578^^^^^
c2d2c21b
JH
579
580Queues an external interrupt to be injected into the virtual CPU. A negative
581interrupt number dequeues the interrupt.
582
5e124900
SC
583This is an asynchronous vcpu ioctl and can be invoked from any thread.
584
da40d858
AP
585RISC-V:
586^^^^^^^
587
d56b699d 588Queues an external interrupt to be injected into the virtual CPU. This ioctl
da40d858
AP
589is overloaded with 2 different irq values:
590
591a) KVM_INTERRUPT_SET
592
593 This sets external interrupt for a virtual CPU and it will receive
594 once it is ready.
595
596b) KVM_INTERRUPT_UNSET
597
598 This clears pending external interrupt for a virtual CPU.
599
600This is an asynchronous vcpu ioctl and can be invoked from any thread.
601
6f0257a0
TZ
602LOONGARCH:
603^^^^^^^^^^
604
605Queues an external interrupt to be injected into the virtual CPU. A negative
606interrupt number dequeues the interrupt.
607
608This is an asynchronous vcpu ioctl and can be invoked from any thread.
609
414fa985 610
68ba6974 6114.17 KVM_DEBUG_GUEST
106ee47d 612--------------------
9c1b96e3 613
106ee47d
MCC
614:Capability: basic
615:Architectures: none
616:Type: vcpu ioctl
617:Parameters: none)
618:Returns: -1 on error
9c1b96e3
AK
619
620Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
621
414fa985 622
68ba6974 6234.18 KVM_GET_MSRS
106ee47d 624-----------------
9c1b96e3 625
106ee47d
MCC
626:Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
627:Architectures: x86
628:Type: system ioctl, vcpu ioctl
629:Parameters: struct kvm_msrs (in/out)
630:Returns: number of msrs successfully returned;
631 -1 on error
801e459a
TL
632
633When used as a system ioctl:
634Reads the values of MSR-based features that are available for the VM. This
635is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
636The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
637in a system ioctl.
9c1b96e3 638
801e459a 639When used as a vcpu ioctl:
9c1b96e3 640Reads model-specific registers from the vcpu. Supported msr indices can
801e459a 641be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
9c1b96e3 642
106ee47d
MCC
643::
644
645 struct kvm_msrs {
9c1b96e3
AK
646 __u32 nmsrs; /* number of msrs in entries */
647 __u32 pad;
648
649 struct kvm_msr_entry entries[0];
106ee47d 650 };
9c1b96e3 651
106ee47d 652 struct kvm_msr_entry {
9c1b96e3
AK
653 __u32 index;
654 __u32 reserved;
655 __u64 data;
106ee47d 656 };
9c1b96e3
AK
657
658Application code should set the 'nmsrs' member (which indicates the
659size of the entries array) and the 'index' member of each array entry.
660kvm will fill in the 'data' member.
661
414fa985 662
68ba6974 6634.19 KVM_SET_MSRS
106ee47d 664-----------------
9c1b96e3 665
106ee47d
MCC
666:Capability: basic
667:Architectures: x86
668:Type: vcpu ioctl
669:Parameters: struct kvm_msrs (in)
670:Returns: number of msrs successfully set (see below), -1 on error
9c1b96e3
AK
671
672Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
673data structures.
674
675Application code should set the 'nmsrs' member (which indicates the
676size of the entries array), and the 'index' and 'data' members of each
677array entry.
678
b274a290
XL
679It tries to set the MSRs in array entries[] one by one. If setting an MSR
680fails, e.g., due to setting reserved bits, the MSR isn't supported/emulated
681by KVM, etc..., it stops processing the MSR list and returns the number of
682MSRs that have been set successfully.
683
414fa985 684
68ba6974 6854.20 KVM_SET_CPUID
106ee47d 686------------------
9c1b96e3 687
106ee47d
MCC
688:Capability: basic
689:Architectures: x86
690:Type: vcpu ioctl
691:Parameters: struct kvm_cpuid (in)
692:Returns: 0 on success, -1 on error
9c1b96e3
AK
693
694Defines the vcpu responses to the cpuid instruction. Applications
695should use the KVM_SET_CPUID2 ioctl if available.
696
63f5a190
SC
697Caveat emptor:
698 - If this IOCTL fails, KVM gives no guarantees that previous valid CPUID
699 configuration (if there is) is not corrupted. Userspace can get a copy
700 of the resulting CPUID configuration through KVM_GET_CPUID2 in case.
701 - Using KVM_SET_CPUID{,2} after KVM_RUN, i.e. changing the guest vCPU model
702 after running the guest, may cause guest instability.
703 - Using heterogeneous CPUID configurations, modulo APIC IDs, topology, etc...
704 may cause guest instability.
18964092 705
106ee47d 706::
9c1b96e3 707
106ee47d 708 struct kvm_cpuid_entry {
9c1b96e3
AK
709 __u32 function;
710 __u32 eax;
711 __u32 ebx;
712 __u32 ecx;
713 __u32 edx;
714 __u32 padding;
106ee47d 715 };
9c1b96e3 716
106ee47d
MCC
717 /* for KVM_SET_CPUID */
718 struct kvm_cpuid {
9c1b96e3
AK
719 __u32 nent;
720 __u32 padding;
721 struct kvm_cpuid_entry entries[0];
106ee47d 722 };
9c1b96e3 723
414fa985 724
68ba6974 7254.21 KVM_SET_SIGNAL_MASK
106ee47d 726------------------------
9c1b96e3 727
106ee47d
MCC
728:Capability: basic
729:Architectures: all
730:Type: vcpu ioctl
731:Parameters: struct kvm_signal_mask (in)
732:Returns: 0 on success, -1 on error
9c1b96e3
AK
733
734Defines which signals are blocked during execution of KVM_RUN. This
735signal mask temporarily overrides the threads signal mask. Any
736unblocked signal received (except SIGKILL and SIGSTOP, which retain
737their traditional behaviour) will cause KVM_RUN to return with -EINTR.
738
739Note the signal will only be delivered if not blocked by the original
740signal mask.
741
106ee47d
MCC
742::
743
744 /* for KVM_SET_SIGNAL_MASK */
745 struct kvm_signal_mask {
9c1b96e3
AK
746 __u32 len;
747 __u8 sigset[0];
106ee47d 748 };
9c1b96e3 749
414fa985 750
68ba6974 7514.22 KVM_GET_FPU
106ee47d 752----------------
9c1b96e3 753
106ee47d 754:Capability: basic
6f0257a0 755:Architectures: x86, loongarch
106ee47d
MCC
756:Type: vcpu ioctl
757:Parameters: struct kvm_fpu (out)
758:Returns: 0 on success, -1 on error
9c1b96e3
AK
759
760Reads the floating point state from the vcpu.
761
106ee47d
MCC
762::
763
6f0257a0 764 /* x86: for KVM_GET_FPU and KVM_SET_FPU */
106ee47d 765 struct kvm_fpu {
9c1b96e3
AK
766 __u8 fpr[8][16];
767 __u16 fcw;
768 __u16 fsw;
769 __u8 ftwx; /* in fxsave format */
770 __u8 pad1;
771 __u16 last_opcode;
772 __u64 last_ip;
773 __u64 last_dp;
774 __u8 xmm[16][16];
775 __u32 mxcsr;
776 __u32 pad2;
106ee47d 777 };
9c1b96e3 778
6f0257a0
TZ
779 /* LoongArch: for KVM_GET_FPU and KVM_SET_FPU */
780 struct kvm_fpu {
781 __u32 fcsr;
782 __u64 fcc;
783 struct kvm_fpureg {
784 __u64 val64[4];
785 }fpr[32];
786 };
787
414fa985 788
68ba6974 7894.23 KVM_SET_FPU
106ee47d 790----------------
9c1b96e3 791
106ee47d 792:Capability: basic
6f0257a0 793:Architectures: x86, loongarch
106ee47d
MCC
794:Type: vcpu ioctl
795:Parameters: struct kvm_fpu (in)
796:Returns: 0 on success, -1 on error
9c1b96e3
AK
797
798Writes the floating point state to the vcpu.
799
106ee47d
MCC
800::
801
6f0257a0 802 /* x86: for KVM_GET_FPU and KVM_SET_FPU */
106ee47d 803 struct kvm_fpu {
9c1b96e3
AK
804 __u8 fpr[8][16];
805 __u16 fcw;
806 __u16 fsw;
807 __u8 ftwx; /* in fxsave format */
808 __u8 pad1;
809 __u16 last_opcode;
810 __u64 last_ip;
811 __u64 last_dp;
812 __u8 xmm[16][16];
813 __u32 mxcsr;
814 __u32 pad2;
106ee47d 815 };
9c1b96e3 816
6f0257a0
TZ
817 /* LoongArch: for KVM_GET_FPU and KVM_SET_FPU */
818 struct kvm_fpu {
819 __u32 fcsr;
820 __u64 fcc;
821 struct kvm_fpureg {
822 __u64 val64[4];
823 }fpr[32];
824 };
825
414fa985 826
68ba6974 8274.24 KVM_CREATE_IRQCHIP
106ee47d 828-----------------------
5dadbfd6 829
106ee47d 830:Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
3fbf4207 831:Architectures: x86, arm64, s390
106ee47d
MCC
832:Type: vm ioctl
833:Parameters: none
834:Returns: 0 on success, -1 on error
5dadbfd6 835
ac3d3735
AP
836Creates an interrupt controller model in the kernel.
837On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
838future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
839PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
3fbf4207 840On arm64, a GICv2 is created. Any other GIC versions require the usage of
ac3d3735
AP
841KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
842KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
843On s390, a dummy irq routing table is created.
84223598
CH
844
845Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
846before KVM_CREATE_IRQCHIP can be used.
5dadbfd6 847
414fa985 848
68ba6974 8494.25 KVM_IRQ_LINE
106ee47d 850-----------------
5dadbfd6 851
106ee47d 852:Capability: KVM_CAP_IRQCHIP
3fbf4207 853:Architectures: x86, arm64
106ee47d
MCC
854:Type: vm ioctl
855:Parameters: struct kvm_irq_level
856:Returns: 0 on success, -1 on error
5dadbfd6
AK
857
858Sets the level of a GSI input to the interrupt controller model in the kernel.
86ce8535
CD
859On some architectures it is required that an interrupt controller model has
860been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
861interrupts require the level to be set to 1 and then back to 0.
862
100943c5
GS
863On real hardware, interrupt pins can be active-low or active-high. This
864does not matter for the level field of struct kvm_irq_level: 1 always
865means active (asserted), 0 means inactive (deasserted).
866
867x86 allows the operating system to program the interrupt polarity
868(active-low/active-high) for level-triggered interrupts, and KVM used
869to consider the polarity. However, due to bitrot in the handling of
870active-low interrupts, the above convention is now valid on x86 too.
871This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
872should not present interrupts to the guest as active-low unless this
873capability is present (or unless it is not using the in-kernel irqchip,
874of course).
875
876
3fbf4207 877arm64 can signal an interrupt either at the CPU level, or at the
379e04c7
MZ
878in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
879use PPIs designated for specific cpus. The irq field is interpreted
106ee47d 880like this::
86ce8535 881
3b1c8c56 882 bits: | 31 ... 28 | 27 ... 24 | 23 ... 16 | 15 ... 0 |
92f35b75 883 field: | vcpu2_index | irq_type | vcpu_index | irq_id |
86ce8535
CD
884
885The irq_type field has the following values:
106ee47d
MCC
886
887- irq_type[0]:
888 out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
889- irq_type[1]:
890 in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
86ce8535 891 (the vcpu_index field is ignored)
106ee47d
MCC
892- irq_type[2]:
893 in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
86ce8535
CD
894
895(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
896
100943c5 897In both cases, level is used to assert/deassert the line.
5dadbfd6 898
92f35b75
MZ
899When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is
900identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index
901must be zero.
902
3fbf4207 903Note that on arm64, the KVM_CAP_IRQCHIP capability only conditions
92f35b75
MZ
904injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always
905be used for a userspace interrupt controller.
906
106ee47d
MCC
907::
908
909 struct kvm_irq_level {
5dadbfd6
AK
910 union {
911 __u32 irq; /* GSI */
912 __s32 status; /* not used for KVM_IRQ_LEVEL */
913 };
914 __u32 level; /* 0 or 1 */
106ee47d 915 };
5dadbfd6 916
414fa985 917
68ba6974 9184.26 KVM_GET_IRQCHIP
106ee47d 919--------------------
5dadbfd6 920
106ee47d
MCC
921:Capability: KVM_CAP_IRQCHIP
922:Architectures: x86
923:Type: vm ioctl
924:Parameters: struct kvm_irqchip (in/out)
925:Returns: 0 on success, -1 on error
5dadbfd6
AK
926
927Reads the state of a kernel interrupt controller created with
928KVM_CREATE_IRQCHIP into a buffer provided by the caller.
929
106ee47d
MCC
930::
931
932 struct kvm_irqchip {
5dadbfd6
AK
933 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
934 __u32 pad;
935 union {
936 char dummy[512]; /* reserving space */
937 struct kvm_pic_state pic;
938 struct kvm_ioapic_state ioapic;
939 } chip;
106ee47d 940 };
5dadbfd6 941
414fa985 942
68ba6974 9434.27 KVM_SET_IRQCHIP
106ee47d 944--------------------
5dadbfd6 945
106ee47d
MCC
946:Capability: KVM_CAP_IRQCHIP
947:Architectures: x86
948:Type: vm ioctl
949:Parameters: struct kvm_irqchip (in)
950:Returns: 0 on success, -1 on error
5dadbfd6
AK
951
952Sets the state of a kernel interrupt controller created with
953KVM_CREATE_IRQCHIP from a buffer provided by the caller.
954
106ee47d
MCC
955::
956
957 struct kvm_irqchip {
5dadbfd6
AK
958 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
959 __u32 pad;
960 union {
961 char dummy[512]; /* reserving space */
962 struct kvm_pic_state pic;
963 struct kvm_ioapic_state ioapic;
964 } chip;
106ee47d 965 };
5dadbfd6 966
414fa985 967
68ba6974 9684.28 KVM_XEN_HVM_CONFIG
106ee47d 969-----------------------
ffde22ac 970
106ee47d
MCC
971:Capability: KVM_CAP_XEN_HVM
972:Architectures: x86
973:Type: vm ioctl
974:Parameters: struct kvm_xen_hvm_config (in)
975:Returns: 0 on success, -1 on error
ffde22ac
ES
976
977Sets the MSR that the Xen HVM guest uses to initialize its hypercall
978page, and provides the starting address and size of the hypercall
979blobs in userspace. When the guest writes the MSR, kvm copies one
980page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
981memory.
982
106ee47d
MCC
983::
984
985 struct kvm_xen_hvm_config {
ffde22ac
ES
986 __u32 flags;
987 __u32 msr;
988 __u64 blob_addr_32;
989 __u64 blob_addr_64;
990 __u8 blob_size_32;
991 __u8 blob_size_64;
992 __u8 pad2[30];
106ee47d 993 };
ffde22ac 994
661a20fa
DW
995If certain flags are returned from the KVM_CAP_XEN_HVM check, they may
996be set in the flags field of this ioctl:
997
998The KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag requests KVM to generate
999the contents of the hypercall page automatically; hypercalls will be
1000intercepted and passed to userspace through KVM_EXIT_XEN. In this
57f33f1a 1001case, all of the blob size and address fields must be zero.
661a20fa
DW
1002
1003The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates to KVM that userspace
1004will always use the KVM_XEN_HVM_EVTCHN_SEND ioctl to deliver event
1005channel interrupts rather than manipulating the guest's shared_info
1006structures directly. This, in turn, may allow KVM to enable features
1007such as intercepting the SCHEDOP_poll hypercall to accelerate PV
1008spinlock operation for the guest. Userspace may still use the ioctl
1009to deliver events if it was advertised, even if userspace does not
1010send this indication that it will always do so
e1f68169
DW
1011
1012No other flags are currently valid in the struct kvm_xen_hvm_config.
414fa985 1013
68ba6974 10144.29 KVM_GET_CLOCK
106ee47d 1015------------------
afbcf7ab 1016
106ee47d
MCC
1017:Capability: KVM_CAP_ADJUST_CLOCK
1018:Architectures: x86
1019:Type: vm ioctl
1020:Parameters: struct kvm_clock_data (out)
1021:Returns: 0 on success, -1 on error
afbcf7ab
GC
1022
1023Gets the current timestamp of kvmclock as seen by the current guest. In
1024conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
1025such as migration.
1026
e3fd9a93
PB
1027When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
1028set of bits that KVM can return in struct kvm_clock_data's flag member.
1029
c68dc1b5
OU
1030The following flags are defined:
1031
1032KVM_CLOCK_TSC_STABLE
1033 If set, the returned value is the exact kvmclock
1034 value seen by all VCPUs at the instant when KVM_GET_CLOCK was called.
1035 If clear, the returned value is simply CLOCK_MONOTONIC plus a constant
1036 offset; the offset can be modified with KVM_SET_CLOCK. KVM will try
1037 to make all VCPUs follow this clock, but the exact value read by each
1038 VCPU could differ, because the host TSC is not stable.
1039
1040KVM_CLOCK_REALTIME
1041 If set, the `realtime` field in the kvm_clock_data
1042 structure is populated with the value of the host's real time
1043 clocksource at the instant when KVM_GET_CLOCK was called. If clear,
1044 the `realtime` field does not contain a value.
1045
1046KVM_CLOCK_HOST_TSC
1047 If set, the `host_tsc` field in the kvm_clock_data
1048 structure is populated with the value of the host's timestamp counter (TSC)
1049 at the instant when KVM_GET_CLOCK was called. If clear, the `host_tsc` field
1050 does not contain a value.
e3fd9a93 1051
106ee47d
MCC
1052::
1053
1054 struct kvm_clock_data {
afbcf7ab
GC
1055 __u64 clock; /* kvmclock current value */
1056 __u32 flags;
c68dc1b5
OU
1057 __u32 pad0;
1058 __u64 realtime;
1059 __u64 host_tsc;
1060 __u32 pad[4];
106ee47d 1061 };
afbcf7ab 1062
414fa985 1063
68ba6974 10644.30 KVM_SET_CLOCK
106ee47d 1065------------------
afbcf7ab 1066
106ee47d
MCC
1067:Capability: KVM_CAP_ADJUST_CLOCK
1068:Architectures: x86
1069:Type: vm ioctl
1070:Parameters: struct kvm_clock_data (in)
1071:Returns: 0 on success, -1 on error
afbcf7ab 1072
2044892d 1073Sets the current timestamp of kvmclock to the value specified in its parameter.
afbcf7ab
GC
1074In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
1075such as migration.
1076
c68dc1b5
OU
1077The following flags can be passed:
1078
1079KVM_CLOCK_REALTIME
1080 If set, KVM will compare the value of the `realtime` field
1081 with the value of the host's real time clocksource at the instant when
1082 KVM_SET_CLOCK was called. The difference in elapsed time is added to the final
1083 kvmclock value that will be provided to guests.
1084
1085Other flags returned by ``KVM_GET_CLOCK`` are accepted but ignored.
1086
106ee47d
MCC
1087::
1088
1089 struct kvm_clock_data {
afbcf7ab
GC
1090 __u64 clock; /* kvmclock current value */
1091 __u32 flags;
c68dc1b5
OU
1092 __u32 pad0;
1093 __u64 realtime;
1094 __u64 host_tsc;
1095 __u32 pad[4];
106ee47d 1096 };
afbcf7ab 1097
414fa985 1098
68ba6974 10994.31 KVM_GET_VCPU_EVENTS
106ee47d 1100------------------------
3cfc3092 1101
106ee47d
MCC
1102:Capability: KVM_CAP_VCPU_EVENTS
1103:Extended by: KVM_CAP_INTR_SHADOW
3fbf4207 1104:Architectures: x86, arm64
106ee47d 1105:Type: vcpu ioctl
57f33f1a 1106:Parameters: struct kvm_vcpu_events (out)
106ee47d 1107:Returns: 0 on success, -1 on error
3cfc3092 1108
b7b27fac 1109X86:
106ee47d 1110^^^^
b7b27fac 1111
3cfc3092
JK
1112Gets currently pending exceptions, interrupts, and NMIs as well as related
1113states of the vcpu.
1114
106ee47d
MCC
1115::
1116
1117 struct kvm_vcpu_events {
3cfc3092
JK
1118 struct {
1119 __u8 injected;
1120 __u8 nr;
1121 __u8 has_error_code;
59073aaf 1122 __u8 pending;
3cfc3092
JK
1123 __u32 error_code;
1124 } exception;
1125 struct {
1126 __u8 injected;
1127 __u8 nr;
1128 __u8 soft;
48005f64 1129 __u8 shadow;
3cfc3092
JK
1130 } interrupt;
1131 struct {
1132 __u8 injected;
1133 __u8 pending;
1134 __u8 masked;
1135 __u8 pad;
1136 } nmi;
1137 __u32 sipi_vector;
dab4b911 1138 __u32 flags;
f077825a
PB
1139 struct {
1140 __u8 smm;
1141 __u8 pending;
1142 __u8 smm_inside_nmi;
1143 __u8 latched_init;
1144 } smi;
59073aaf
JM
1145 __u8 reserved[27];
1146 __u8 exception_has_payload;
1147 __u64 exception_payload;
106ee47d 1148 };
3cfc3092 1149
59073aaf 1150The following bits are defined in the flags field:
f077825a 1151
59073aaf 1152- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that
f077825a 1153 interrupt.shadow contains a valid state.
48005f64 1154
59073aaf
JM
1155- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a
1156 valid state.
1157
1158- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the
1159 exception_has_payload, exception_payload, and exception.pending
1160 fields contain a valid state. This bit will be set whenever
1161 KVM_CAP_EXCEPTION_PAYLOAD is enabled.
414fa985 1162
ed235117
CQ
1163- KVM_VCPUEVENT_VALID_TRIPLE_FAULT may be set to signal that the
1164 triple_fault_pending field contains a valid state. This bit will
8deb03e7 1165 be set whenever KVM_CAP_X86_TRIPLE_FAULT_EVENT is enabled.
ed235117 1166
3fbf4207
OU
1167ARM64:
1168^^^^^^
b7b27fac
DG
1169
1170If the guest accesses a device that is being emulated by the host kernel in
1171such a way that a real device would generate a physical SError, KVM may make
1172a virtual SError pending for that VCPU. This system error interrupt remains
1173pending until the guest takes the exception by unmasking PSTATE.A.
1174
1175Running the VCPU may cause it to take a pending SError, or make an access that
1176causes an SError to become pending. The event's description is only valid while
1177the VPCU is not running.
1178
1179This API provides a way to read and write the pending 'event' state that is not
1180visible to the guest. To save, restore or migrate a VCPU the struct representing
1181the state can be read then written using this GET/SET API, along with the other
1182guest-visible registers. It is not possible to 'cancel' an SError that has been
1183made pending.
1184
1185A device being emulated in user-space may also wish to generate an SError. To do
1186this the events structure can be populated by user-space. The current state
1187should be read first, to ensure no existing SError is pending. If an existing
1188SError is pending, the architecture's 'Multiple SError interrupts' rules should
1189be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
1190Serviceability (RAS) Specification").
1191
be26b3a7
DG
1192SError exceptions always have an ESR value. Some CPUs have the ability to
1193specify what the virtual SError's ESR value should be. These systems will
688e0581 1194advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will
be26b3a7
DG
1195always have a non-zero value when read, and the agent making an SError pending
1196should specify the ISS field in the lower 24 bits of exception.serror_esr. If
688e0581 1197the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events
be26b3a7
DG
1198with exception.has_esr as zero, KVM will choose an ESR.
1199
1200Specifying exception.has_esr on a system that does not support it will return
1201-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
1202will return -EINVAL.
1203
da345174
CD
1204It is not possible to read back a pending external abort (injected via
1205KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered
1206directly to the virtual CPU).
1207
106ee47d 1208::
da345174 1209
106ee47d 1210 struct kvm_vcpu_events {
b7b27fac
DG
1211 struct {
1212 __u8 serror_pending;
1213 __u8 serror_has_esr;
da345174 1214 __u8 ext_dabt_pending;
b7b27fac 1215 /* Align it to 8 bytes */
da345174 1216 __u8 pad[5];
b7b27fac
DG
1217 __u64 serror_esr;
1218 } exception;
1219 __u32 reserved[12];
106ee47d 1220 };
b7b27fac 1221
68ba6974 12224.32 KVM_SET_VCPU_EVENTS
106ee47d 1223------------------------
3cfc3092 1224
106ee47d
MCC
1225:Capability: KVM_CAP_VCPU_EVENTS
1226:Extended by: KVM_CAP_INTR_SHADOW
3fbf4207 1227:Architectures: x86, arm64
106ee47d 1228:Type: vcpu ioctl
57f33f1a 1229:Parameters: struct kvm_vcpu_events (in)
106ee47d 1230:Returns: 0 on success, -1 on error
3cfc3092 1231
b7b27fac 1232X86:
106ee47d 1233^^^^
b7b27fac 1234
3cfc3092
JK
1235Set pending exceptions, interrupts, and NMIs as well as related states of the
1236vcpu.
1237
1238See KVM_GET_VCPU_EVENTS for the data structure.
1239
dab4b911 1240Fields that may be modified asynchronously by running VCPUs can be excluded
f077825a
PB
1241from the update. These fields are nmi.pending, sipi_vector, smi.smm,
1242smi.pending. Keep the corresponding bits in the flags field cleared to
1243suppress overwriting the current in-kernel state. The bits are:
dab4b911 1244
106ee47d
MCC
1245=============================== ==================================
1246KVM_VCPUEVENT_VALID_NMI_PENDING transfer nmi.pending to the kernel
1247KVM_VCPUEVENT_VALID_SIPI_VECTOR transfer sipi_vector
1248KVM_VCPUEVENT_VALID_SMM transfer the smi sub-struct.
1249=============================== ==================================
dab4b911 1250
48005f64
JK
1251If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
1252the flags field to signal that interrupt.shadow contains a valid state and
1253shall be written into the VCPU.
1254
f077825a
PB
1255KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
1256
59073aaf
JM
1257If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD
1258can be set in the flags field to signal that the
1259exception_has_payload, exception_payload, and exception.pending fields
1260contain a valid state and shall be written into the VCPU.
1261
8deb03e7 1262If KVM_CAP_X86_TRIPLE_FAULT_EVENT is enabled, KVM_VCPUEVENT_VALID_TRIPLE_FAULT
ed235117
CQ
1263can be set in flags field to signal that the triple_fault field contains
1264a valid state and shall be written into the VCPU.
1265
3fbf4207
OU
1266ARM64:
1267^^^^^^
b7b27fac 1268
da345174
CD
1269User space may need to inject several types of events to the guest.
1270
b7b27fac
DG
1271Set the pending SError exception state for this VCPU. It is not possible to
1272'cancel' an Serror that has been made pending.
1273
da345174
CD
1274If the guest performed an access to I/O memory which could not be handled by
1275userspace, for example because of missing instruction syndrome decode
1276information or because there is no device mapped at the accessed IPA, then
1277userspace can ask the kernel to inject an external abort using the address
1278from the exiting fault on the VCPU. It is a programming error to set
1279ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or
1280KVM_EXIT_ARM_NISV. This feature is only available if the system supports
1281KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in
1282how userspace reports accesses for the above cases to guests, across different
1283userspace implementations. Nevertheless, userspace can still emulate all Arm
1284exceptions by manipulating individual registers using the KVM_SET_ONE_REG API.
1285
b7b27fac
DG
1286See KVM_GET_VCPU_EVENTS for the data structure.
1287
414fa985 1288
68ba6974 12894.33 KVM_GET_DEBUGREGS
106ee47d 1290----------------------
a1efbe77 1291
106ee47d
MCC
1292:Capability: KVM_CAP_DEBUGREGS
1293:Architectures: x86
1294:Type: vm ioctl
1295:Parameters: struct kvm_debugregs (out)
1296:Returns: 0 on success, -1 on error
a1efbe77
JK
1297
1298Reads debug registers from the vcpu.
1299
106ee47d
MCC
1300::
1301
1302 struct kvm_debugregs {
a1efbe77
JK
1303 __u64 db[4];
1304 __u64 dr6;
1305 __u64 dr7;
1306 __u64 flags;
1307 __u64 reserved[9];
106ee47d 1308 };
a1efbe77 1309
414fa985 1310
68ba6974 13114.34 KVM_SET_DEBUGREGS
106ee47d 1312----------------------
a1efbe77 1313
106ee47d
MCC
1314:Capability: KVM_CAP_DEBUGREGS
1315:Architectures: x86
1316:Type: vm ioctl
1317:Parameters: struct kvm_debugregs (in)
1318:Returns: 0 on success, -1 on error
a1efbe77
JK
1319
1320Writes debug registers into the vcpu.
1321
1322See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
1323yet and must be cleared on entry.
1324
414fa985 1325
68ba6974 13264.35 KVM_SET_USER_MEMORY_REGION
106ee47d
MCC
1327-------------------------------
1328
1329:Capability: KVM_CAP_USER_MEMORY
1330:Architectures: all
1331:Type: vm ioctl
1332:Parameters: struct kvm_userspace_memory_region (in)
1333:Returns: 0 on success, -1 on error
0f2d8f4d 1334
106ee47d 1335::
0f2d8f4d 1336
106ee47d 1337 struct kvm_userspace_memory_region {
0f2d8f4d
AK
1338 __u32 slot;
1339 __u32 flags;
1340 __u64 guest_phys_addr;
1341 __u64 memory_size; /* bytes */
1342 __u64 userspace_addr; /* start of the userspace allocated memory */
106ee47d 1343 };
0f2d8f4d 1344
30ee198c 1345 /* for kvm_userspace_memory_region::flags */
106ee47d
MCC
1346 #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
1347 #define KVM_MEM_READONLY (1UL << 1)
0f2d8f4d 1348
e2788c4a
PB
1349This ioctl allows the user to create, modify or delete a guest physical
1350memory slot. Bits 0-15 of "slot" specify the slot id and this value
1351should be less than the maximum number of user memory slots supported per
c110ae57
PB
1352VM. The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS.
1353Slots may not overlap in guest physical address space.
0f2d8f4d 1354
f481b069
PB
1355If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1356specifies the address space which is being modified. They must be
1357less than the value that KVM_CHECK_EXTENSION returns for the
1358KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
1359are unrelated; the restriction on overlapping slots only applies within
1360each address space.
1361
e2788c4a
PB
1362Deleting a slot is done by passing zero for memory_size. When changing
1363an existing slot, it may be moved in the guest physical memory space,
1364or its flags may be modified, but it may not be resized.
1365
0f2d8f4d
AK
1366Memory for the region is taken starting at the address denoted by the
1367field userspace_addr, which must point at user addressable memory for
1368the entire memory slot size. Any object may back this memory, including
1369anonymous memory, ordinary files, and hugetlbfs.
1370
139bc8a6
MZ
1371On architectures that support a form of address tagging, userspace_addr must
1372be an untagged address.
1373
0f2d8f4d
AK
1374It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1375be identical. This allows large pages in the guest to be backed by large
1376pages in the host.
1377
75d61fbc
TY
1378The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1379KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
1380writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
1381use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1382to make a new slot read-only. In this case, writes to this memory will be
1383posted to userspace as KVM_EXIT_MMIO exits.
7efd8fa1
JK
1384
1385When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1386the memory region are automatically reflected into the guest. For example, an
1387mmap() that affects the region will be made visible immediately. Another
1388example is madvise(MADV_DROP).
0f2d8f4d 1389
b8f8d190
MZ
1390Note: On arm64, a write generated by the page-table walker (to update
1391the Access and Dirty flags, for example) never results in a
1392KVM_EXIT_MMIO exit when the slot has the KVM_MEM_READONLY flag. This
1393is because KVM cannot provide the data that would be written by the
1394page-table walker, making it impossible to emulate the access.
1395Instead, an abort (data abort if the cause of the page-table update
1396was a load or a store, instruction abort if it was an instruction
1397fetch) is injected in the guest.
414fa985 1398
68ba6974 13994.36 KVM_SET_TSS_ADDR
106ee47d 1400---------------------
8a5416db 1401
106ee47d
MCC
1402:Capability: KVM_CAP_SET_TSS_ADDR
1403:Architectures: x86
1404:Type: vm ioctl
1405:Parameters: unsigned long tss_address (in)
1406:Returns: 0 on success, -1 on error
8a5416db
AK
1407
1408This ioctl defines the physical address of a three-page region in the guest
1409physical address space. The region must be within the first 4GB of the
1410guest physical address space and must not conflict with any memory slot
1411or any mmio address. The guest may malfunction if it accesses this memory
1412region.
1413
1414This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1415because of a quirk in the virtualization implementation (see the internals
1416documentation when it pops into existence).
1417
414fa985 1418
68ba6974 14194.37 KVM_ENABLE_CAP
106ee47d 1420-------------------
71fbfd5f 1421
106ee47d 1422:Capability: KVM_CAP_ENABLE_CAP
6f0257a0 1423:Architectures: mips, ppc, s390, x86, loongarch
106ee47d
MCC
1424:Type: vcpu ioctl
1425:Parameters: struct kvm_enable_cap (in)
1426:Returns: 0 on success; -1 on error
e5d83c74 1427
106ee47d
MCC
1428:Capability: KVM_CAP_ENABLE_CAP_VM
1429:Architectures: all
a10f373a 1430:Type: vm ioctl
106ee47d
MCC
1431:Parameters: struct kvm_enable_cap (in)
1432:Returns: 0 on success; -1 on error
1433
1434.. note::
71fbfd5f 1435
106ee47d
MCC
1436 Not all extensions are enabled by default. Using this ioctl the application
1437 can enable an extension, making it available to the guest.
71fbfd5f
AG
1438
1439On systems that do not support this ioctl, it always fails. On systems that
1440do support it, it only works for extensions that are supported for enablement.
1441
1442To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1443be used.
1444
106ee47d
MCC
1445::
1446
1447 struct kvm_enable_cap {
71fbfd5f
AG
1448 /* in */
1449 __u32 cap;
1450
1451The capability that is supposed to get enabled.
1452
106ee47d
MCC
1453::
1454
71fbfd5f
AG
1455 __u32 flags;
1456
1457A bitfield indicating future enhancements. Has to be 0 for now.
1458
106ee47d
MCC
1459::
1460
71fbfd5f
AG
1461 __u64 args[4];
1462
1463Arguments for enabling a feature. If a feature needs initial values to
1464function properly, this is the place to put them.
1465
106ee47d
MCC
1466::
1467
71fbfd5f 1468 __u8 pad[64];
106ee47d 1469 };
71fbfd5f 1470
d938dc55
CH
1471The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1472for vm-wide capabilities.
414fa985 1473
68ba6974 14744.38 KVM_GET_MP_STATE
106ee47d 1475---------------------
b843f065 1476
106ee47d 1477:Capability: KVM_CAP_MP_STATE
6f0257a0 1478:Architectures: x86, s390, arm64, riscv, loongarch
106ee47d
MCC
1479:Type: vcpu ioctl
1480:Parameters: struct kvm_mp_state (out)
1481:Returns: 0 on success; -1 on error
1482
1483::
b843f065 1484
106ee47d 1485 struct kvm_mp_state {
b843f065 1486 __u32 mp_state;
106ee47d 1487 };
b843f065
AK
1488
1489Returns the vcpu's current "multiprocessing state" (though also valid on
1490uniprocessor guests).
1491
1492Possible values are:
1493
106ee47d 1494 ========================== ===============================================
da40d858 1495 KVM_MP_STATE_RUNNABLE the vcpu is currently running
6f0257a0 1496 [x86,arm64,riscv,loongarch]
106ee47d 1497 KVM_MP_STATE_UNINITIALIZED the vcpu is an application processor (AP)
c32a4272 1498 which has not yet received an INIT signal [x86]
106ee47d 1499 KVM_MP_STATE_INIT_RECEIVED the vcpu has received an INIT signal, and is
c32a4272 1500 now ready for a SIPI [x86]
106ee47d 1501 KVM_MP_STATE_HALTED the vcpu has executed a HLT instruction and
c32a4272 1502 is waiting for an interrupt [x86]
106ee47d 1503 KVM_MP_STATE_SIPI_RECEIVED the vcpu has just received a SIPI (vector
c32a4272 1504 accessible via KVM_GET_VCPU_EVENTS) [x86]
3fbf4207 1505 KVM_MP_STATE_STOPPED the vcpu is stopped [s390,arm64,riscv]
106ee47d
MCC
1506 KVM_MP_STATE_CHECK_STOP the vcpu is in a special error state [s390]
1507 KVM_MP_STATE_OPERATING the vcpu is operating (running or halted)
6352e4d2 1508 [s390]
106ee47d 1509 KVM_MP_STATE_LOAD the vcpu is in a special load/startup state
6352e4d2 1510 [s390]
7b33a09d
OU
1511 KVM_MP_STATE_SUSPENDED the vcpu is in a suspend state and is waiting
1512 for a wakeup event [arm64]
106ee47d 1513 ========================== ===============================================
b843f065 1514
c32a4272 1515On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
0b4820d6
DH
1516in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1517these architectures.
b843f065 1518
7b33a09d
OU
1519For arm64:
1520^^^^^^^^^^
1521
1522If a vCPU is in the KVM_MP_STATE_SUSPENDED state, KVM will emulate the
1523architectural execution of a WFI instruction.
1524
1525If a wakeup event is recognized, KVM will exit to userspace with a
1526KVM_SYSTEM_EVENT exit, where the event type is KVM_SYSTEM_EVENT_WAKEUP. If
1527userspace wants to honor the wakeup, it must set the vCPU's MP state to
1528KVM_MP_STATE_RUNNABLE. If it does not, KVM will continue to await a wakeup
1529event in subsequent calls to KVM_RUN.
1530
1531.. warning::
1532
1533 If userspace intends to keep the vCPU in a SUSPENDED state, it is
1534 strongly recommended that userspace take action to suppress the
1535 wakeup event (such as masking an interrupt). Otherwise, subsequent
1536 calls to KVM_RUN will immediately exit with a KVM_SYSTEM_EVENT_WAKEUP
1537 event and inadvertently waste CPU cycles.
1538
1539 Additionally, if userspace takes action to suppress a wakeup event,
1540 it is strongly recommended that it also restores the vCPU to its
1541 original state when the vCPU is made RUNNABLE again. For example,
1542 if userspace masked a pending interrupt to suppress the wakeup,
1543 the interrupt should be unmasked before returning control to the
1544 guest.
1545
1546For riscv:
1547^^^^^^^^^^
ecccf0cc
AB
1548
1549The only states that are valid are KVM_MP_STATE_STOPPED and
1550KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
414fa985 1551
6f0257a0
TZ
1552On LoongArch, only the KVM_MP_STATE_RUNNABLE state is used to reflect
1553whether the vcpu is runnable.
1554
68ba6974 15554.39 KVM_SET_MP_STATE
106ee47d 1556---------------------
b843f065 1557
106ee47d 1558:Capability: KVM_CAP_MP_STATE
6f0257a0 1559:Architectures: x86, s390, arm64, riscv, loongarch
106ee47d
MCC
1560:Type: vcpu ioctl
1561:Parameters: struct kvm_mp_state (in)
1562:Returns: 0 on success; -1 on error
b843f065
AK
1563
1564Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1565arguments.
1566
c32a4272 1567On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
0b4820d6
DH
1568in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1569these architectures.
b843f065 1570
3fbf4207
OU
1571For arm64/riscv:
1572^^^^^^^^^^^^^^^^
ecccf0cc
AB
1573
1574The only states that are valid are KVM_MP_STATE_STOPPED and
1575KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
414fa985 1576
6f0257a0
TZ
1577On LoongArch, only the KVM_MP_STATE_RUNNABLE state is used to reflect
1578whether the vcpu is runnable.
1579
68ba6974 15804.40 KVM_SET_IDENTITY_MAP_ADDR
106ee47d 1581------------------------------
47dbb84f 1582
106ee47d
MCC
1583:Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1584:Architectures: x86
1585:Type: vm ioctl
1586:Parameters: unsigned long identity (in)
1587:Returns: 0 on success, -1 on error
47dbb84f
AK
1588
1589This ioctl defines the physical address of a one-page region in the guest
1590physical address space. The region must be within the first 4GB of the
1591guest physical address space and must not conflict with any memory slot
1592or any mmio address. The guest may malfunction if it accesses this memory
1593region.
1594
726b99c4
DH
1595Setting the address to 0 will result in resetting the address to its default
1596(0xfffbc000).
1597
47dbb84f
AK
1598This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1599because of a quirk in the virtualization implementation (see the internals
1600documentation when it pops into existence).
1601
1af1ac91 1602Fails if any VCPU has already been created.
414fa985 1603
68ba6974 16044.41 KVM_SET_BOOT_CPU_ID
106ee47d 1605------------------------
57bc24cf 1606
106ee47d
MCC
1607:Capability: KVM_CAP_SET_BOOT_CPU_ID
1608:Architectures: x86
1609:Type: vm ioctl
1610:Parameters: unsigned long vcpu_id
1611:Returns: 0 on success, -1 on error
57bc24cf
AK
1612
1613Define which vcpu is the Bootstrap Processor (BSP). Values are the same
1614as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
9ce3746d
EGE
1615is vcpu 0. This ioctl has to be called before vcpu creation,
1616otherwise it will return EBUSY error.
57bc24cf 1617
414fa985 1618
68ba6974 16194.42 KVM_GET_XSAVE
106ee47d 1620------------------
2d5b5a66 1621
106ee47d
MCC
1622:Capability: KVM_CAP_XSAVE
1623:Architectures: x86
1624:Type: vcpu ioctl
1625:Parameters: struct kvm_xsave (out)
1626:Returns: 0 on success, -1 on error
1627
1628
1629::
2d5b5a66 1630
106ee47d 1631 struct kvm_xsave {
2d5b5a66 1632 __u32 region[1024];
be50b206 1633 __u32 extra[0];
106ee47d 1634 };
2d5b5a66
SY
1635
1636This ioctl would copy current vcpu's xsave struct to the userspace.
1637
414fa985 1638
68ba6974 16394.43 KVM_SET_XSAVE
106ee47d 1640------------------
2d5b5a66 1641
be50b206 1642:Capability: KVM_CAP_XSAVE and KVM_CAP_XSAVE2
106ee47d
MCC
1643:Architectures: x86
1644:Type: vcpu ioctl
1645:Parameters: struct kvm_xsave (in)
1646:Returns: 0 on success, -1 on error
1647
1648::
2d5b5a66 1649
106ee47d
MCC
1650
1651 struct kvm_xsave {
2d5b5a66 1652 __u32 region[1024];
be50b206 1653 __u32 extra[0];
106ee47d 1654 };
2d5b5a66 1655
be50b206
GZ
1656This ioctl would copy userspace's xsave struct to the kernel. It copies
1657as many bytes as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2),
1658when invoked on the vm file descriptor. The size value returned by
1659KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) will always be at least 4096.
1660Currently, it is only greater than 4096 if a dynamic feature has been
1661enabled with ``arch_prctl()``, but this may change in the future.
1662
1663The offsets of the state save areas in struct kvm_xsave follow the
1664contents of CPUID leaf 0xD on the host.
2d5b5a66 1665
414fa985 1666
68ba6974 16674.44 KVM_GET_XCRS
106ee47d 1668-----------------
2d5b5a66 1669
106ee47d
MCC
1670:Capability: KVM_CAP_XCRS
1671:Architectures: x86
1672:Type: vcpu ioctl
1673:Parameters: struct kvm_xcrs (out)
1674:Returns: 0 on success, -1 on error
1675
1676::
2d5b5a66 1677
106ee47d 1678 struct kvm_xcr {
2d5b5a66
SY
1679 __u32 xcr;
1680 __u32 reserved;
1681 __u64 value;
106ee47d 1682 };
2d5b5a66 1683
106ee47d 1684 struct kvm_xcrs {
2d5b5a66
SY
1685 __u32 nr_xcrs;
1686 __u32 flags;
1687 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1688 __u64 padding[16];
106ee47d 1689 };
2d5b5a66
SY
1690
1691This ioctl would copy current vcpu's xcrs to the userspace.
1692
414fa985 1693
68ba6974 16944.45 KVM_SET_XCRS
106ee47d 1695-----------------
2d5b5a66 1696
106ee47d
MCC
1697:Capability: KVM_CAP_XCRS
1698:Architectures: x86
1699:Type: vcpu ioctl
1700:Parameters: struct kvm_xcrs (in)
1701:Returns: 0 on success, -1 on error
1702
1703::
2d5b5a66 1704
106ee47d 1705 struct kvm_xcr {
2d5b5a66
SY
1706 __u32 xcr;
1707 __u32 reserved;
1708 __u64 value;
106ee47d 1709 };
2d5b5a66 1710
106ee47d 1711 struct kvm_xcrs {
2d5b5a66
SY
1712 __u32 nr_xcrs;
1713 __u32 flags;
1714 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1715 __u64 padding[16];
106ee47d 1716 };
2d5b5a66
SY
1717
1718This ioctl would set vcpu's xcr to the value userspace specified.
1719
414fa985 1720
68ba6974 17214.46 KVM_GET_SUPPORTED_CPUID
106ee47d
MCC
1722----------------------------
1723
1724:Capability: KVM_CAP_EXT_CPUID
1725:Architectures: x86
1726:Type: system ioctl
1727:Parameters: struct kvm_cpuid2 (in/out)
1728:Returns: 0 on success, -1 on error
d153513d 1729
106ee47d 1730::
d153513d 1731
106ee47d 1732 struct kvm_cpuid2 {
d153513d
AK
1733 __u32 nent;
1734 __u32 padding;
1735 struct kvm_cpuid_entry2 entries[0];
106ee47d 1736 };
d153513d 1737
106ee47d 1738 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
7ff6c035
SC
1739 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */
1740 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */
d153513d 1741
106ee47d 1742 struct kvm_cpuid_entry2 {
d153513d
AK
1743 __u32 function;
1744 __u32 index;
1745 __u32 flags;
1746 __u32 eax;
1747 __u32 ebx;
1748 __u32 ecx;
1749 __u32 edx;
1750 __u32 padding[3];
106ee47d 1751 };
d153513d 1752
df9cb9cc
JM
1753This ioctl returns x86 cpuid features which are supported by both the
1754hardware and kvm in its default configuration. Userspace can use the
1755information returned by this ioctl to construct cpuid information (for
1756KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1757userspace capabilities, and with user requirements (for example, the
1758user may wish to constrain cpuid to emulate older hardware, or for
1759feature consistency across a cluster).
1760
445ecdf7
JL
1761Dynamically-enabled feature bits need to be requested with
1762``arch_prctl()`` before calling this ioctl. Feature bits that have not
1763been requested are excluded from the result.
1764
df9cb9cc
JM
1765Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1766expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1767its default configuration. If userspace enables such capabilities, it
1768is responsible for modifying the results of this ioctl appropriately.
d153513d
AK
1769
1770Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1771with the 'nent' field indicating the number of entries in the variable-size
1772array 'entries'. If the number of entries is too low to describe the cpu
1773capabilities, an error (E2BIG) is returned. If the number is too high,
1774the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1775number is just right, the 'nent' field is adjusted to the number of valid
1776entries in the 'entries' array, which is then filled.
1777
1778The entries returned are the host cpuid as returned by the cpuid instruction,
c39cbd2a
AK
1779with unknown or unsupported features masked out. Some features (for example,
1780x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1781emulate them efficiently. The fields in each entry are defined as follows:
d153513d 1782
106ee47d
MCC
1783 function:
1784 the eax value used to obtain the entry
1785
1786 index:
1787 the ecx value used to obtain the entry (for entries that are
d153513d 1788 affected by ecx)
106ee47d
MCC
1789
1790 flags:
1791 an OR of zero or more of the following:
1792
d153513d
AK
1793 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1794 if the index field is valid
106ee47d
MCC
1795
1796 eax, ebx, ecx, edx:
1797 the values returned by the cpuid instruction for
d153513d
AK
1798 this function/index combination
1799
4d25a066
JK
1800The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1801as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
106ee47d 1802support. Instead it is reported via::
4d25a066
JK
1803
1804 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1805
1806if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1807feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1808
414fa985 1809
68ba6974 18104.47 KVM_PPC_GET_PVINFO
106ee47d
MCC
1811-----------------------
1812
1813:Capability: KVM_CAP_PPC_GET_PVINFO
1814:Architectures: ppc
1815:Type: vm ioctl
1816:Parameters: struct kvm_ppc_pvinfo (out)
1817:Returns: 0 on success, !0 on error
15711e9c 1818
106ee47d 1819::
15711e9c 1820
106ee47d 1821 struct kvm_ppc_pvinfo {
15711e9c
AG
1822 __u32 flags;
1823 __u32 hcall[4];
1824 __u8 pad[108];
106ee47d 1825 };
15711e9c
AG
1826
1827This ioctl fetches PV specific information that need to be passed to the guest
1828using the device tree or other means from vm context.
1829
9202e076 1830The hcall array defines 4 instructions that make up a hypercall.
15711e9c
AG
1831
1832If any additional field gets added to this structure later on, a bit for that
1833additional piece of information will be set in the flags bitmap.
1834
106ee47d 1835The flags bitmap is defined as::
9202e076
LYB
1836
1837 /* the host supports the ePAPR idle hcall
1838 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
414fa985 1839
68ba6974 18404.52 KVM_SET_GSI_ROUTING
106ee47d 1841------------------------
49f48172 1842
106ee47d 1843:Capability: KVM_CAP_IRQ_ROUTING
3fbf4207 1844:Architectures: x86 s390 arm64
106ee47d
MCC
1845:Type: vm ioctl
1846:Parameters: struct kvm_irq_routing (in)
1847:Returns: 0 on success, -1 on error
49f48172
JK
1848
1849Sets the GSI routing table entries, overwriting any previously set entries.
1850
3fbf4207 1851On arm64, GSI routing has the following limitation:
106ee47d 1852
180ae7b1
EA
1853- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1854
106ee47d
MCC
1855::
1856
1857 struct kvm_irq_routing {
49f48172
JK
1858 __u32 nr;
1859 __u32 flags;
1860 struct kvm_irq_routing_entry entries[0];
106ee47d 1861 };
49f48172
JK
1862
1863No flags are specified so far, the corresponding field must be set to zero.
1864
106ee47d
MCC
1865::
1866
1867 struct kvm_irq_routing_entry {
49f48172
JK
1868 __u32 gsi;
1869 __u32 type;
1870 __u32 flags;
1871 __u32 pad;
1872 union {
1873 struct kvm_irq_routing_irqchip irqchip;
1874 struct kvm_irq_routing_msi msi;
84223598 1875 struct kvm_irq_routing_s390_adapter adapter;
5c919412 1876 struct kvm_irq_routing_hv_sint hv_sint;
14243b38 1877 struct kvm_irq_routing_xen_evtchn xen_evtchn;
49f48172
JK
1878 __u32 pad[8];
1879 } u;
106ee47d 1880 };
49f48172 1881
106ee47d
MCC
1882 /* gsi routing entry types */
1883 #define KVM_IRQ_ROUTING_IRQCHIP 1
1884 #define KVM_IRQ_ROUTING_MSI 2
1885 #define KVM_IRQ_ROUTING_S390_ADAPTER 3
1886 #define KVM_IRQ_ROUTING_HV_SINT 4
14243b38 1887 #define KVM_IRQ_ROUTING_XEN_EVTCHN 5
49f48172 1888
76a10b86 1889flags:
106ee47d 1890
6f49b2f3
PB
1891- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1892 type, specifies that the devid field contains a valid value. The per-VM
1893 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1894 the device ID. If this capability is not available, userspace should
1895 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
76a10b86 1896- zero otherwise
49f48172 1897
106ee47d
MCC
1898::
1899
1900 struct kvm_irq_routing_irqchip {
49f48172
JK
1901 __u32 irqchip;
1902 __u32 pin;
106ee47d 1903 };
49f48172 1904
106ee47d 1905 struct kvm_irq_routing_msi {
49f48172
JK
1906 __u32 address_lo;
1907 __u32 address_hi;
1908 __u32 data;
76a10b86
EA
1909 union {
1910 __u32 pad;
1911 __u32 devid;
1912 };
106ee47d 1913 };
49f48172 1914
6f49b2f3
PB
1915If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1916for the device that wrote the MSI message. For PCI, this is usually a
1917BFD identifier in the lower 16 bits.
76a10b86 1918
37131313
RK
1919On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1920feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
1921address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
1922address_hi must be zero.
1923
106ee47d
MCC
1924::
1925
1926 struct kvm_irq_routing_s390_adapter {
84223598
CH
1927 __u64 ind_addr;
1928 __u64 summary_addr;
1929 __u64 ind_offset;
1930 __u32 summary_offset;
1931 __u32 adapter_id;
106ee47d 1932 };
84223598 1933
106ee47d 1934 struct kvm_irq_routing_hv_sint {
5c919412
AS
1935 __u32 vcpu;
1936 __u32 sint;
106ee47d 1937 };
414fa985 1938
14243b38
DW
1939 struct kvm_irq_routing_xen_evtchn {
1940 __u32 port;
1941 __u32 vcpu;
1942 __u32 priority;
1943 };
1944
1945
1946When KVM_CAP_XEN_HVM includes the KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL bit
1947in its indication of supported features, routing to Xen event channels
1948is supported. Although the priority field is present, only the value
1949KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL is supported, which means delivery by
19502 level event channels. FIFO event channel support may be added in
1951the future.
1952
414fa985
JK
1953
19544.55 KVM_SET_TSC_KHZ
106ee47d 1955--------------------
92a1f12d 1956
ffbb61d0 1957:Capability: KVM_CAP_TSC_CONTROL / KVM_CAP_VM_TSC_CONTROL
106ee47d 1958:Architectures: x86
ffbb61d0 1959:Type: vcpu ioctl / vm ioctl
106ee47d
MCC
1960:Parameters: virtual tsc_khz
1961:Returns: 0 on success, -1 on error
92a1f12d
JR
1962
1963Specifies the tsc frequency for the virtual machine. The unit of the
1964frequency is KHz.
1965
ffbb61d0
DW
1966If the KVM_CAP_VM_TSC_CONTROL capability is advertised, this can also
1967be used as a vm ioctl to set the initial tsc frequency of subsequently
1968created vCPUs.
414fa985
JK
1969
19704.56 KVM_GET_TSC_KHZ
106ee47d 1971--------------------
92a1f12d 1972
ffbb61d0 1973:Capability: KVM_CAP_GET_TSC_KHZ / KVM_CAP_VM_TSC_CONTROL
106ee47d 1974:Architectures: x86
ffbb61d0 1975:Type: vcpu ioctl / vm ioctl
106ee47d
MCC
1976:Parameters: none
1977:Returns: virtual tsc-khz on success, negative value on error
92a1f12d
JR
1978
1979Returns the tsc frequency of the guest. The unit of the return value is
1980KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1981error.
1982
414fa985
JK
1983
19844.57 KVM_GET_LAPIC
106ee47d 1985------------------
e7677933 1986
106ee47d
MCC
1987:Capability: KVM_CAP_IRQCHIP
1988:Architectures: x86
1989:Type: vcpu ioctl
1990:Parameters: struct kvm_lapic_state (out)
1991:Returns: 0 on success, -1 on error
e7677933 1992
106ee47d
MCC
1993::
1994
1995 #define KVM_APIC_REG_SIZE 0x400
1996 struct kvm_lapic_state {
e7677933 1997 char regs[KVM_APIC_REG_SIZE];
106ee47d 1998 };
e7677933
AK
1999
2000Reads the Local APIC registers and copies them into the input argument. The
2001data format and layout are the same as documented in the architecture manual.
2002
37131313
RK
2003If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
2004enabled, then the format of APIC_ID register depends on the APIC mode
2005(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in
2006the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID
2007which is stored in bits 31-24 of the APIC register, or equivalently in
2008byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then
2009be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
2010
2011If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
2012always uses xAPIC format.
2013
414fa985
JK
2014
20154.58 KVM_SET_LAPIC
106ee47d 2016------------------
e7677933 2017
106ee47d
MCC
2018:Capability: KVM_CAP_IRQCHIP
2019:Architectures: x86
2020:Type: vcpu ioctl
2021:Parameters: struct kvm_lapic_state (in)
2022:Returns: 0 on success, -1 on error
e7677933 2023
106ee47d
MCC
2024::
2025
2026 #define KVM_APIC_REG_SIZE 0x400
2027 struct kvm_lapic_state {
e7677933 2028 char regs[KVM_APIC_REG_SIZE];
106ee47d 2029 };
e7677933 2030
df5cbb27 2031Copies the input argument into the Local APIC registers. The data format
e7677933
AK
2032and layout are the same as documented in the architecture manual.
2033
37131313
RK
2034The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
2035regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
2036See the note in KVM_GET_LAPIC.
2037
414fa985
JK
2038
20394.59 KVM_IOEVENTFD
106ee47d 2040------------------
55399a02 2041
106ee47d
MCC
2042:Capability: KVM_CAP_IOEVENTFD
2043:Architectures: all
2044:Type: vm ioctl
2045:Parameters: struct kvm_ioeventfd (in)
2046:Returns: 0 on success, !0 on error
55399a02
SL
2047
2048This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
2049within the guest. A guest write in the registered address will signal the
2050provided event instead of triggering an exit.
2051
106ee47d
MCC
2052::
2053
2054 struct kvm_ioeventfd {
55399a02
SL
2055 __u64 datamatch;
2056 __u64 addr; /* legal pio/mmio address */
e9ea5069 2057 __u32 len; /* 0, 1, 2, 4, or 8 bytes */
55399a02
SL
2058 __s32 fd;
2059 __u32 flags;
2060 __u8 pad[36];
106ee47d 2061 };
55399a02 2062
2b83451b
CH
2063For the special case of virtio-ccw devices on s390, the ioevent is matched
2064to a subchannel/virtqueue tuple instead.
2065
106ee47d 2066The following flags are defined::
55399a02 2067
106ee47d
MCC
2068 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
2069 #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
2070 #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
2071 #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
2b83451b 2072 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
55399a02
SL
2073
2074If datamatch flag is set, the event will be signaled only if the written value
2075to the registered address is equal to datamatch in struct kvm_ioeventfd.
2076
2b83451b
CH
2077For virtio-ccw devices, addr contains the subchannel id and datamatch the
2078virtqueue index.
2079
e9ea5069
JW
2080With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
2081the kernel will ignore the length of guest write and may get a faster vmexit.
2082The speedup may only apply to specific architectures, but the ioeventfd will
2083work anyway.
414fa985
JK
2084
20854.60 KVM_DIRTY_TLB
106ee47d 2086------------------
dc83b8bc 2087
106ee47d
MCC
2088:Capability: KVM_CAP_SW_TLB
2089:Architectures: ppc
2090:Type: vcpu ioctl
2091:Parameters: struct kvm_dirty_tlb (in)
2092:Returns: 0 on success, -1 on error
2093
2094::
dc83b8bc 2095
106ee47d 2096 struct kvm_dirty_tlb {
dc83b8bc
SW
2097 __u64 bitmap;
2098 __u32 num_dirty;
106ee47d 2099 };
dc83b8bc
SW
2100
2101This must be called whenever userspace has changed an entry in the shared
2102TLB, prior to calling KVM_RUN on the associated vcpu.
2103
2104The "bitmap" field is the userspace address of an array. This array
2105consists of a number of bits, equal to the total number of TLB entries as
2106determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
2107nearest multiple of 64.
2108
2109Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
2110array.
2111
2112The array is little-endian: the bit 0 is the least significant bit of the
2113first byte, bit 8 is the least significant bit of the second byte, etc.
2114This avoids any complications with differing word sizes.
2115
2116The "num_dirty" field is a performance hint for KVM to determine whether it
2117should skip processing the bitmap and just invalidate everything. It must
2118be set to the number of set bits in the bitmap.
2119
414fa985 2120
54738c09 21214.62 KVM_CREATE_SPAPR_TCE
106ee47d 2122-------------------------
54738c09 2123
106ee47d
MCC
2124:Capability: KVM_CAP_SPAPR_TCE
2125:Architectures: powerpc
2126:Type: vm ioctl
2127:Parameters: struct kvm_create_spapr_tce (in)
2128:Returns: file descriptor for manipulating the created TCE table
54738c09
DG
2129
2130This creates a virtual TCE (translation control entry) table, which
2131is an IOMMU for PAPR-style virtual I/O. It is used to translate
2132logical addresses used in virtual I/O into guest physical addresses,
2133and provides a scatter/gather capability for PAPR virtual I/O.
2134
106ee47d
MCC
2135::
2136
2137 /* for KVM_CAP_SPAPR_TCE */
2138 struct kvm_create_spapr_tce {
54738c09
DG
2139 __u64 liobn;
2140 __u32 window_size;
106ee47d 2141 };
54738c09
DG
2142
2143The liobn field gives the logical IO bus number for which to create a
2144TCE table. The window_size field specifies the size of the DMA window
2145which this TCE table will translate - the table will contain one 64
2146bit TCE entry for every 4kiB of the DMA window.
2147
2148When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
2149table has been created using this ioctl(), the kernel will handle it
2150in real mode, updating the TCE table. H_PUT_TCE calls for other
2151liobns will cause a vm exit and must be handled by userspace.
2152
2153The return value is a file descriptor which can be passed to mmap(2)
2154to map the created TCE table into userspace. This lets userspace read
2155the entries written by kernel-handled H_PUT_TCE calls, and also lets
2156userspace update the TCE table directly which is useful in some
2157circumstances.
2158
414fa985 2159
aa04b4cc 21604.63 KVM_ALLOCATE_RMA
106ee47d 2161---------------------
aa04b4cc 2162
106ee47d
MCC
2163:Capability: KVM_CAP_PPC_RMA
2164:Architectures: powerpc
2165:Type: vm ioctl
2166:Parameters: struct kvm_allocate_rma (out)
2167:Returns: file descriptor for mapping the allocated RMA
aa04b4cc
PM
2168
2169This allocates a Real Mode Area (RMA) from the pool allocated at boot
2170time by the kernel. An RMA is a physically-contiguous, aligned region
2171of memory used on older POWER processors to provide the memory which
2172will be accessed by real-mode (MMU off) accesses in a KVM guest.
2173POWER processors support a set of sizes for the RMA that usually
2174includes 64MB, 128MB, 256MB and some larger powers of two.
2175
106ee47d
MCC
2176::
2177
2178 /* for KVM_ALLOCATE_RMA */
2179 struct kvm_allocate_rma {
aa04b4cc 2180 __u64 rma_size;
106ee47d 2181 };
aa04b4cc
PM
2182
2183The return value is a file descriptor which can be passed to mmap(2)
2184to map the allocated RMA into userspace. The mapped area can then be
2185passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
2186RMA for a virtual machine. The size of the RMA in bytes (which is
2187fixed at host kernel boot time) is returned in the rma_size field of
2188the argument structure.
2189
2190The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
2191is supported; 2 if the processor requires all virtual machines to have
2192an RMA, or 1 if the processor can use an RMA but doesn't require it,
2193because it supports the Virtual RMA (VRMA) facility.
2194
414fa985 2195
3f745f1e 21964.64 KVM_NMI
106ee47d 2197------------
3f745f1e 2198
106ee47d
MCC
2199:Capability: KVM_CAP_USER_NMI
2200:Architectures: x86
2201:Type: vcpu ioctl
2202:Parameters: none
2203:Returns: 0 on success, -1 on error
3f745f1e
AK
2204
2205Queues an NMI on the thread's vcpu. Note this is well defined only
2206when KVM_CREATE_IRQCHIP has not been called, since this is an interface
2207between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
2208has been called, this interface is completely emulated within the kernel.
2209
2210To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
2211following algorithm:
2212
5d4f6f3d 2213 - pause the vcpu
3f745f1e
AK
2214 - read the local APIC's state (KVM_GET_LAPIC)
2215 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
2216 - if so, issue KVM_NMI
2217 - resume the vcpu
2218
2219Some guests configure the LINT1 NMI input to cause a panic, aiding in
2220debugging.
2221
414fa985 2222
e24ed81f 22234.65 KVM_S390_UCAS_MAP
106ee47d 2224----------------------
27e0393f 2225
106ee47d
MCC
2226:Capability: KVM_CAP_S390_UCONTROL
2227:Architectures: s390
2228:Type: vcpu ioctl
2229:Parameters: struct kvm_s390_ucas_mapping (in)
2230:Returns: 0 in case of success
2231
2232The parameter is defined like this::
27e0393f 2233
27e0393f
CO
2234 struct kvm_s390_ucas_mapping {
2235 __u64 user_addr;
2236 __u64 vcpu_addr;
2237 __u64 length;
2238 };
2239
2240This ioctl maps the memory at "user_addr" with the length "length" to
2241the vcpu's address space starting at "vcpu_addr". All parameters need to
f884ab15 2242be aligned by 1 megabyte.
27e0393f 2243
414fa985 2244
e24ed81f 22454.66 KVM_S390_UCAS_UNMAP
106ee47d 2246------------------------
27e0393f 2247
106ee47d
MCC
2248:Capability: KVM_CAP_S390_UCONTROL
2249:Architectures: s390
2250:Type: vcpu ioctl
2251:Parameters: struct kvm_s390_ucas_mapping (in)
2252:Returns: 0 in case of success
2253
2254The parameter is defined like this::
27e0393f 2255
27e0393f
CO
2256 struct kvm_s390_ucas_mapping {
2257 __u64 user_addr;
2258 __u64 vcpu_addr;
2259 __u64 length;
2260 };
2261
2262This ioctl unmaps the memory in the vcpu's address space starting at
2263"vcpu_addr" with the length "length". The field "user_addr" is ignored.
f884ab15 2264All parameters need to be aligned by 1 megabyte.
27e0393f 2265
414fa985 2266
e24ed81f 22674.67 KVM_S390_VCPU_FAULT
106ee47d 2268------------------------
ccc7910f 2269
106ee47d
MCC
2270:Capability: KVM_CAP_S390_UCONTROL
2271:Architectures: s390
2272:Type: vcpu ioctl
2273:Parameters: vcpu absolute address (in)
2274:Returns: 0 in case of success
ccc7910f
CO
2275
2276This call creates a page table entry on the virtual cpu's address space
2277(for user controlled virtual machines) or the virtual machine's address
2278space (for regular virtual machines). This only works for minor faults,
2279thus it's recommended to access subject memory page via the user page
2280table upfront. This is useful to handle validity intercepts for user
2281controlled virtual machines to fault in the virtual cpu's lowcore pages
2282prior to calling the KVM_RUN ioctl.
2283
414fa985 2284
e24ed81f 22854.68 KVM_SET_ONE_REG
106ee47d
MCC
2286--------------------
2287
2288:Capability: KVM_CAP_ONE_REG
2289:Architectures: all
2290:Type: vcpu ioctl
2291:Parameters: struct kvm_one_reg (in)
2292:Returns: 0 on success, negative value on failure
e24ed81f 2293
395f562f 2294Errors:
106ee47d
MCC
2295
2296 ====== ============================================================
3b1c8c56
MCC
2297 ENOENT no such register
2298 EINVAL invalid register ID, or no such register or used with VMs in
68cf7b1f 2299 protected virtualization mode on s390
3b1c8c56 2300 EPERM (arm64) register access not allowed before vcpu finalization
e47f3c28
DHB
2301 EBUSY (riscv) changing register value not allowed after the vcpu
2302 has run at least once
106ee47d
MCC
2303 ====== ============================================================
2304
fe365b4e
DM
2305(These error codes are indicative only: do not rely on a specific error
2306code being returned in a specific situation.)
e24ed81f 2307
106ee47d
MCC
2308::
2309
2310 struct kvm_one_reg {
e24ed81f
AG
2311 __u64 id;
2312 __u64 addr;
106ee47d 2313 };
e24ed81f
AG
2314
2315Using this ioctl, a single vcpu register can be set to a specific value
2316defined by user space with the passed in struct kvm_one_reg, where id
2317refers to the register identifier as described below and addr is a pointer
2318to a variable with the respective size. There can be architecture agnostic
2319and architecture specific registers. Each have their own range of operation
2320and their own constants and width. To keep track of the implemented
2321registers, find a list below:
2322
106ee47d
MCC
2323 ======= =============================== ============
2324 Arch Register Width (bits)
2325 ======= =============================== ============
2326 PPC KVM_REG_PPC_HIOR 64
2327 PPC KVM_REG_PPC_IAC1 64
2328 PPC KVM_REG_PPC_IAC2 64
2329 PPC KVM_REG_PPC_IAC3 64
2330 PPC KVM_REG_PPC_IAC4 64
2331 PPC KVM_REG_PPC_DAC1 64
2332 PPC KVM_REG_PPC_DAC2 64
2333 PPC KVM_REG_PPC_DABR 64
2334 PPC KVM_REG_PPC_DSCR 64
2335 PPC KVM_REG_PPC_PURR 64
2336 PPC KVM_REG_PPC_SPURR 64
2337 PPC KVM_REG_PPC_DAR 64
2338 PPC KVM_REG_PPC_DSISR 32
2339 PPC KVM_REG_PPC_AMR 64
2340 PPC KVM_REG_PPC_UAMOR 64
2341 PPC KVM_REG_PPC_MMCR0 64
2342 PPC KVM_REG_PPC_MMCR1 64
2343 PPC KVM_REG_PPC_MMCRA 64
2344 PPC KVM_REG_PPC_MMCR2 64
2345 PPC KVM_REG_PPC_MMCRS 64
5752fe0b 2346 PPC KVM_REG_PPC_MMCR3 64
106ee47d
MCC
2347 PPC KVM_REG_PPC_SIAR 64
2348 PPC KVM_REG_PPC_SDAR 64
2349 PPC KVM_REG_PPC_SIER 64
5752fe0b
AR
2350 PPC KVM_REG_PPC_SIER2 64
2351 PPC KVM_REG_PPC_SIER3 64
106ee47d
MCC
2352 PPC KVM_REG_PPC_PMC1 32
2353 PPC KVM_REG_PPC_PMC2 32
2354 PPC KVM_REG_PPC_PMC3 32
2355 PPC KVM_REG_PPC_PMC4 32
2356 PPC KVM_REG_PPC_PMC5 32
2357 PPC KVM_REG_PPC_PMC6 32
2358 PPC KVM_REG_PPC_PMC7 32
2359 PPC KVM_REG_PPC_PMC8 32
2360 PPC KVM_REG_PPC_FPR0 64
2361 ...
2362 PPC KVM_REG_PPC_FPR31 64
2363 PPC KVM_REG_PPC_VR0 128
2364 ...
2365 PPC KVM_REG_PPC_VR31 128
2366 PPC KVM_REG_PPC_VSR0 128
2367 ...
2368 PPC KVM_REG_PPC_VSR31 128
2369 PPC KVM_REG_PPC_FPSCR 64
2370 PPC KVM_REG_PPC_VSCR 32
2371 PPC KVM_REG_PPC_VPA_ADDR 64
2372 PPC KVM_REG_PPC_VPA_SLB 128
2373 PPC KVM_REG_PPC_VPA_DTL 128
2374 PPC KVM_REG_PPC_EPCR 32
2375 PPC KVM_REG_PPC_EPR 32
2376 PPC KVM_REG_PPC_TCR 32
2377 PPC KVM_REG_PPC_TSR 32
2378 PPC KVM_REG_PPC_OR_TSR 32
2379 PPC KVM_REG_PPC_CLEAR_TSR 32
2380 PPC KVM_REG_PPC_MAS0 32
2381 PPC KVM_REG_PPC_MAS1 32
2382 PPC KVM_REG_PPC_MAS2 64
2383 PPC KVM_REG_PPC_MAS7_3 64
2384 PPC KVM_REG_PPC_MAS4 32
2385 PPC KVM_REG_PPC_MAS6 32
2386 PPC KVM_REG_PPC_MMUCFG 32
2387 PPC KVM_REG_PPC_TLB0CFG 32
2388 PPC KVM_REG_PPC_TLB1CFG 32
2389 PPC KVM_REG_PPC_TLB2CFG 32
2390 PPC KVM_REG_PPC_TLB3CFG 32
2391 PPC KVM_REG_PPC_TLB0PS 32
2392 PPC KVM_REG_PPC_TLB1PS 32
2393 PPC KVM_REG_PPC_TLB2PS 32
2394 PPC KVM_REG_PPC_TLB3PS 32
2395 PPC KVM_REG_PPC_EPTCFG 32
2396 PPC KVM_REG_PPC_ICP_STATE 64
2397 PPC KVM_REG_PPC_VP_STATE 128
2398 PPC KVM_REG_PPC_TB_OFFSET 64
2399 PPC KVM_REG_PPC_SPMC1 32
2400 PPC KVM_REG_PPC_SPMC2 32
2401 PPC KVM_REG_PPC_IAMR 64
2402 PPC KVM_REG_PPC_TFHAR 64
2403 PPC KVM_REG_PPC_TFIAR 64
2404 PPC KVM_REG_PPC_TEXASR 64
2405 PPC KVM_REG_PPC_FSCR 64
2406 PPC KVM_REG_PPC_PSPB 32
2407 PPC KVM_REG_PPC_EBBHR 64
2408 PPC KVM_REG_PPC_EBBRR 64
2409 PPC KVM_REG_PPC_BESCR 64
2410 PPC KVM_REG_PPC_TAR 64
2411 PPC KVM_REG_PPC_DPDES 64
2412 PPC KVM_REG_PPC_DAWR 64
2413 PPC KVM_REG_PPC_DAWRX 64
2414 PPC KVM_REG_PPC_CIABR 64
2415 PPC KVM_REG_PPC_IC 64
2416 PPC KVM_REG_PPC_VTB 64
2417 PPC KVM_REG_PPC_CSIGR 64
2418 PPC KVM_REG_PPC_TACR 64
2419 PPC KVM_REG_PPC_TCSCR 64
2420 PPC KVM_REG_PPC_PID 64
2421 PPC KVM_REG_PPC_ACOP 64
2422 PPC KVM_REG_PPC_VRSAVE 32
2423 PPC KVM_REG_PPC_LPCR 32
2424 PPC KVM_REG_PPC_LPCR_64 64
2425 PPC KVM_REG_PPC_PPR 64
2426 PPC KVM_REG_PPC_ARCH_COMPAT 32
2427 PPC KVM_REG_PPC_DABRX 32
2428 PPC KVM_REG_PPC_WORT 64
2429 PPC KVM_REG_PPC_SPRG9 64
2430 PPC KVM_REG_PPC_DBSR 32
2431 PPC KVM_REG_PPC_TIDR 64
2432 PPC KVM_REG_PPC_PSSCR 64
2433 PPC KVM_REG_PPC_DEC_EXPIRY 64
2434 PPC KVM_REG_PPC_PTCR 64
bd1de1a0
RB
2435 PPC KVM_REG_PPC_DAWR1 64
2436 PPC KVM_REG_PPC_DAWRX1 64
106ee47d
MCC
2437 PPC KVM_REG_PPC_TM_GPR0 64
2438 ...
2439 PPC KVM_REG_PPC_TM_GPR31 64
2440 PPC KVM_REG_PPC_TM_VSR0 128
2441 ...
2442 PPC KVM_REG_PPC_TM_VSR63 128
2443 PPC KVM_REG_PPC_TM_CR 64
2444 PPC KVM_REG_PPC_TM_LR 64
2445 PPC KVM_REG_PPC_TM_CTR 64
2446 PPC KVM_REG_PPC_TM_FPSCR 64
2447 PPC KVM_REG_PPC_TM_AMR 64
2448 PPC KVM_REG_PPC_TM_PPR 64
2449 PPC KVM_REG_PPC_TM_VRSAVE 64
2450 PPC KVM_REG_PPC_TM_VSCR 32
2451 PPC KVM_REG_PPC_TM_DSCR 64
2452 PPC KVM_REG_PPC_TM_TAR 64
2453 PPC KVM_REG_PPC_TM_XER 64
2454
2455 MIPS KVM_REG_MIPS_R0 64
2456 ...
2457 MIPS KVM_REG_MIPS_R31 64
2458 MIPS KVM_REG_MIPS_HI 64
2459 MIPS KVM_REG_MIPS_LO 64
2460 MIPS KVM_REG_MIPS_PC 64
2461 MIPS KVM_REG_MIPS_CP0_INDEX 32
2462 MIPS KVM_REG_MIPS_CP0_ENTRYLO0 64
2463 MIPS KVM_REG_MIPS_CP0_ENTRYLO1 64
2464 MIPS KVM_REG_MIPS_CP0_CONTEXT 64
2465 MIPS KVM_REG_MIPS_CP0_CONTEXTCONFIG 32
2466 MIPS KVM_REG_MIPS_CP0_USERLOCAL 64
2467 MIPS KVM_REG_MIPS_CP0_XCONTEXTCONFIG 64
2468 MIPS KVM_REG_MIPS_CP0_PAGEMASK 32
2469 MIPS KVM_REG_MIPS_CP0_PAGEGRAIN 32
2470 MIPS KVM_REG_MIPS_CP0_SEGCTL0 64
2471 MIPS KVM_REG_MIPS_CP0_SEGCTL1 64
2472 MIPS KVM_REG_MIPS_CP0_SEGCTL2 64
2473 MIPS KVM_REG_MIPS_CP0_PWBASE 64
2474 MIPS KVM_REG_MIPS_CP0_PWFIELD 64
2475 MIPS KVM_REG_MIPS_CP0_PWSIZE 64
2476 MIPS KVM_REG_MIPS_CP0_WIRED 32
2477 MIPS KVM_REG_MIPS_CP0_PWCTL 32
2478 MIPS KVM_REG_MIPS_CP0_HWRENA 32
2479 MIPS KVM_REG_MIPS_CP0_BADVADDR 64
2480 MIPS KVM_REG_MIPS_CP0_BADINSTR 32
2481 MIPS KVM_REG_MIPS_CP0_BADINSTRP 32
2482 MIPS KVM_REG_MIPS_CP0_COUNT 32
2483 MIPS KVM_REG_MIPS_CP0_ENTRYHI 64
2484 MIPS KVM_REG_MIPS_CP0_COMPARE 32
2485 MIPS KVM_REG_MIPS_CP0_STATUS 32
2486 MIPS KVM_REG_MIPS_CP0_INTCTL 32
2487 MIPS KVM_REG_MIPS_CP0_CAUSE 32
2488 MIPS KVM_REG_MIPS_CP0_EPC 64
2489 MIPS KVM_REG_MIPS_CP0_PRID 32
2490 MIPS KVM_REG_MIPS_CP0_EBASE 64
2491 MIPS KVM_REG_MIPS_CP0_CONFIG 32
2492 MIPS KVM_REG_MIPS_CP0_CONFIG1 32
2493 MIPS KVM_REG_MIPS_CP0_CONFIG2 32
2494 MIPS KVM_REG_MIPS_CP0_CONFIG3 32
2495 MIPS KVM_REG_MIPS_CP0_CONFIG4 32
2496 MIPS KVM_REG_MIPS_CP0_CONFIG5 32
2497 MIPS KVM_REG_MIPS_CP0_CONFIG7 32
2498 MIPS KVM_REG_MIPS_CP0_XCONTEXT 64
2499 MIPS KVM_REG_MIPS_CP0_ERROREPC 64
2500 MIPS KVM_REG_MIPS_CP0_KSCRATCH1 64
2501 MIPS KVM_REG_MIPS_CP0_KSCRATCH2 64
2502 MIPS KVM_REG_MIPS_CP0_KSCRATCH3 64
2503 MIPS KVM_REG_MIPS_CP0_KSCRATCH4 64
2504 MIPS KVM_REG_MIPS_CP0_KSCRATCH5 64
2505 MIPS KVM_REG_MIPS_CP0_KSCRATCH6 64
2506 MIPS KVM_REG_MIPS_CP0_MAAR(0..63) 64
2507 MIPS KVM_REG_MIPS_COUNT_CTL 64
2508 MIPS KVM_REG_MIPS_COUNT_RESUME 64
2509 MIPS KVM_REG_MIPS_COUNT_HZ 64
2510 MIPS KVM_REG_MIPS_FPR_32(0..31) 32
2511 MIPS KVM_REG_MIPS_FPR_64(0..31) 64
2512 MIPS KVM_REG_MIPS_VEC_128(0..31) 128
2513 MIPS KVM_REG_MIPS_FCR_IR 32
2514 MIPS KVM_REG_MIPS_FCR_CSR 32
2515 MIPS KVM_REG_MIPS_MSA_IR 32
2516 MIPS KVM_REG_MIPS_MSA_CSR 32
2517 ======= =============================== ============
414fa985 2518
749cf76c
CD
2519ARM registers are mapped using the lower 32 bits. The upper 16 of that
2520is the register group type, or coprocessor number:
2521
106ee47d
MCC
2522ARM core registers have the following id bit patterns::
2523
aa404ddf 2524 0x4020 0000 0010 <index into the kvm_regs struct:16>
749cf76c 2525
106ee47d
MCC
2526ARM 32-bit CP15 registers have the following id bit patterns::
2527
aa404ddf 2528 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
1138245c 2529
106ee47d
MCC
2530ARM 64-bit CP15 registers have the following id bit patterns::
2531
aa404ddf 2532 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
749cf76c 2533
106ee47d
MCC
2534ARM CCSIDR registers are demultiplexed by CSSELR value::
2535
aa404ddf 2536 0x4020 0000 0011 00 <csselr:8>
749cf76c 2537
106ee47d
MCC
2538ARM 32-bit VFP control registers have the following id bit patterns::
2539
aa404ddf 2540 0x4020 0000 0012 1 <regno:12>
4fe21e4c 2541
106ee47d
MCC
2542ARM 64-bit FP registers have the following id bit patterns::
2543
aa404ddf 2544 0x4030 0000 0012 0 <regno:12>
4fe21e4c 2545
106ee47d
MCC
2546ARM firmware pseudo-registers have the following bit pattern::
2547
85bd0ba1
MZ
2548 0x4030 0000 0014 <regno:16>
2549
379e04c7
MZ
2550
2551arm64 registers are mapped using the lower 32 bits. The upper 16 of
2552that is the register group type, or coprocessor number:
2553
2554arm64 core/FP-SIMD registers have the following id bit patterns. Note
2555that the size of the access is variable, as the kvm_regs structure
2556contains elements ranging from 32 to 128 bits. The index is a 32bit
106ee47d
MCC
2557value in the kvm_regs structure seen as a 32bit array::
2558
379e04c7
MZ
2559 0x60x0 0000 0010 <index into the kvm_regs struct:16>
2560
fd3bc912 2561Specifically:
106ee47d
MCC
2562
2563======================= ========= ===== =======================================
fd3bc912 2564 Encoding Register Bits kvm_regs member
106ee47d 2565======================= ========= ===== =======================================
fd3bc912
DM
2566 0x6030 0000 0010 0000 X0 64 regs.regs[0]
2567 0x6030 0000 0010 0002 X1 64 regs.regs[1]
106ee47d 2568 ...
fd3bc912
DM
2569 0x6030 0000 0010 003c X30 64 regs.regs[30]
2570 0x6030 0000 0010 003e SP 64 regs.sp
2571 0x6030 0000 0010 0040 PC 64 regs.pc
2572 0x6030 0000 0010 0042 PSTATE 64 regs.pstate
2573 0x6030 0000 0010 0044 SP_EL1 64 sp_el1
2574 0x6030 0000 0010 0046 ELR_EL1 64 elr_el1
2575 0x6030 0000 0010 0048 SPSR_EL1 64 spsr[KVM_SPSR_EL1] (alias SPSR_SVC)
2576 0x6030 0000 0010 004a SPSR_ABT 64 spsr[KVM_SPSR_ABT]
2577 0x6030 0000 0010 004c SPSR_UND 64 spsr[KVM_SPSR_UND]
2578 0x6030 0000 0010 004e SPSR_IRQ 64 spsr[KVM_SPSR_IRQ]
2579 0x6060 0000 0010 0050 SPSR_FIQ 64 spsr[KVM_SPSR_FIQ]
106ee47d
MCC
2580 0x6040 0000 0010 0054 V0 128 fp_regs.vregs[0] [1]_
2581 0x6040 0000 0010 0058 V1 128 fp_regs.vregs[1] [1]_
2582 ...
2583 0x6040 0000 0010 00d0 V31 128 fp_regs.vregs[31] [1]_
fd3bc912
DM
2584 0x6020 0000 0010 00d4 FPSR 32 fp_regs.fpsr
2585 0x6020 0000 0010 00d5 FPCR 32 fp_regs.fpcr
106ee47d 2586======================= ========= ===== =======================================
fd3bc912 2587
106ee47d
MCC
2588.. [1] These encodings are not accepted for SVE-enabled vcpus. See
2589 KVM_ARM_VCPU_INIT.
50036ad0 2590
106ee47d
MCC
2591 The equivalent register content can be accessed via bits [127:0] of
2592 the corresponding SVE Zn registers instead for vcpus that have SVE
2593 enabled (see below).
2594
2595arm64 CCSIDR registers are demultiplexed by CSSELR value::
50036ad0 2596
379e04c7
MZ
2597 0x6020 0000 0011 00 <csselr:8>
2598
106ee47d
MCC
2599arm64 system registers have the following id bit patterns::
2600
379e04c7
MZ
2601 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2602
106ee47d
MCC
2603.. warning::
2604
290a6bb0
AJ
2605 Two system register IDs do not follow the specified pattern. These
2606 are KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT, which map to
2607 system registers CNTV_CVAL_EL0 and CNTVCT_EL0 respectively. These
2608 two had their values accidentally swapped, which means TIMER_CVAL is
2609 derived from the register encoding for CNTVCT_EL0 and TIMER_CNT is
2610 derived from the register encoding for CNTV_CVAL_EL0. As this is
2611 API, it must remain this way.
2612
106ee47d
MCC
2613arm64 firmware pseudo-registers have the following bit pattern::
2614
85bd0ba1
MZ
2615 0x6030 0000 0014 <regno:16>
2616
106ee47d
MCC
2617arm64 SVE registers have the following bit patterns::
2618
50036ad0
DM
2619 0x6080 0000 0015 00 <n:5> <slice:5> Zn bits[2048*slice + 2047 : 2048*slice]
2620 0x6050 0000 0015 04 <n:4> <slice:5> Pn bits[256*slice + 255 : 256*slice]
2621 0x6050 0000 0015 060 <slice:5> FFR bits[256*slice + 255 : 256*slice]
2622 0x6060 0000 0015 ffff KVM_REG_ARM64_SVE_VLS pseudo-register
2623
43b8e1f0
DM
2624Access to register IDs where 2048 * slice >= 128 * max_vq will fail with
2625ENOENT. max_vq is the vcpu's maximum supported vector length in 128-bit
106ee47d 2626quadwords: see [2]_ below.
50036ad0
DM
2627
2628These registers are only accessible on vcpus for which SVE is enabled.
2629See KVM_ARM_VCPU_INIT for details.
2630
2631In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not
2632accessible until the vcpu's SVE configuration has been finalized
2633using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). See KVM_ARM_VCPU_INIT
2634and KVM_ARM_VCPU_FINALIZE for more information about this procedure.
2635
2636KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector
2637lengths supported by the vcpu to be discovered and configured by
2638userspace. When transferred to or from user memory via KVM_GET_ONE_REG
4bd774e5
DM
2639or KVM_SET_ONE_REG, the value of this register is of type
2640__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as
106ee47d 2641follows::
50036ad0 2642
106ee47d 2643 __u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS];
50036ad0 2644
106ee47d
MCC
2645 if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX &&
2646 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >>
4bd774e5 2647 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1))
50036ad0 2648 /* Vector length vq * 16 bytes supported */
106ee47d 2649 else
50036ad0
DM
2650 /* Vector length vq * 16 bytes not supported */
2651
106ee47d
MCC
2652.. [2] The maximum value vq for which the above condition is true is
2653 max_vq. This is the maximum vector length available to the guest on
2654 this vcpu, and determines which register slices are visible through
2655 this ioctl interface.
50036ad0 2656
e4624435 2657(See Documentation/arch/arm64/sve.rst for an explanation of the "vq"
50036ad0
DM
2658nomenclature.)
2659
2660KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT.
2661KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that
2662the host supports.
2663
2664Userspace may subsequently modify it if desired until the vcpu's SVE
2665configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE).
2666
2667Apart from simply removing all vector lengths from the host set that
2668exceed some value, support for arbitrarily chosen sets of vector lengths
2669is hardware-dependent and may not be available. Attempting to configure
2670an invalid set of vector lengths via KVM_SET_ONE_REG will fail with
2671EINVAL.
2672
2673After the vcpu's SVE configuration is finalized, further attempts to
2674write this register will fail with EPERM.
2675
fa246c68
RRA
2676arm64 bitmap feature firmware pseudo-registers have the following bit pattern::
2677
2678 0x6030 0000 0016 <regno:16>
2679
2680The bitmap feature firmware registers exposes the hypercall services that
2681are available for userspace to configure. The set bits corresponds to the
2682services that are available for the guests to access. By default, KVM
2683sets all the supported bits during VM initialization. The userspace can
2684discover the available services via KVM_GET_ONE_REG, and write back the
2685bitmap corresponding to the features that it wishes guests to see via
2686KVM_SET_ONE_REG.
2687
2688Note: These registers are immutable once any of the vCPUs of the VM has
2689run at least once. A KVM_SET_ONE_REG in such a scenario will return
2690a -EBUSY to userspace.
2691
2692(See Documentation/virt/kvm/arm/hypercalls.rst for more details.)
2693
c2d2c21b
JH
2694
2695MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
2696the register group type:
2697
106ee47d
MCC
2698MIPS core registers (see above) have the following id bit patterns::
2699
c2d2c21b
JH
2700 0x7030 0000 0000 <reg:16>
2701
2702MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
106ee47d
MCC
2703patterns depending on whether they're 32-bit or 64-bit registers::
2704
c2d2c21b
JH
2705 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
2706 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2707
013044cc
JH
2708Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2709versions of the EntryLo registers regardless of the word size of the host
2710hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2711with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2712the PFNX field starting at bit 30.
2713
d42a008f 2714MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
106ee47d
MCC
2715patterns::
2716
d42a008f
JH
2717 0x7030 0000 0001 01 <reg:8>
2718
106ee47d
MCC
2719MIPS KVM control registers (see above) have the following id bit patterns::
2720
c2d2c21b
JH
2721 0x7030 0000 0002 <reg:16>
2722
379245cd
JH
2723MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2724id bit patterns depending on the size of the register being accessed. They are
2725always accessed according to the current guest FPU mode (Status.FR and
2726Config5.FRE), i.e. as the guest would see them, and they become unpredictable
ab86bd60
JH
2727if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2728registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
106ee47d
MCC
2729overlap the FPU registers::
2730
379245cd
JH
2731 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2732 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
ab86bd60 2733 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
379245cd
JH
2734
2735MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
106ee47d
MCC
2736following id bit patterns::
2737
379245cd
JH
2738 0x7020 0000 0003 01 <0:3> <reg:5>
2739
ab86bd60 2740MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
106ee47d
MCC
2741following id bit patterns::
2742
ab86bd60
JH
2743 0x7020 0000 0003 02 <0:3> <reg:5>
2744
da40d858
AP
2745RISC-V registers are mapped using the lower 32 bits. The upper 8 bits of
2746that is the register group type.
2747
2748RISC-V config registers are meant for configuring a Guest VCPU and it has
2749the following id bit patterns::
2750
2751 0x8020 0000 01 <index into the kvm_riscv_config struct:24> (32bit Host)
2752 0x8030 0000 01 <index into the kvm_riscv_config struct:24> (64bit Host)
2753
2754Following are the RISC-V config registers:
2755
2756======================= ========= =============================================
2757 Encoding Register Description
2758======================= ========= =============================================
2759 0x80x0 0000 0100 0000 isa ISA feature bitmap of Guest VCPU
2760======================= ========= =============================================
2761
2762The isa config register can be read anytime but can only be written before
2763a Guest VCPU runs. It will have ISA feature bits matching underlying host
2764set by default.
2765
d56b699d 2766RISC-V core registers represent the general execution state of a Guest VCPU
da40d858
AP
2767and it has the following id bit patterns::
2768
2769 0x8020 0000 02 <index into the kvm_riscv_core struct:24> (32bit Host)
2770 0x8030 0000 02 <index into the kvm_riscv_core struct:24> (64bit Host)
2771
2772Following are the RISC-V core registers:
2773
2774======================= ========= =============================================
2775 Encoding Register Description
2776======================= ========= =============================================
2777 0x80x0 0000 0200 0000 regs.pc Program counter
2778 0x80x0 0000 0200 0001 regs.ra Return address
2779 0x80x0 0000 0200 0002 regs.sp Stack pointer
2780 0x80x0 0000 0200 0003 regs.gp Global pointer
2781 0x80x0 0000 0200 0004 regs.tp Task pointer
2782 0x80x0 0000 0200 0005 regs.t0 Caller saved register 0
2783 0x80x0 0000 0200 0006 regs.t1 Caller saved register 1
2784 0x80x0 0000 0200 0007 regs.t2 Caller saved register 2
2785 0x80x0 0000 0200 0008 regs.s0 Callee saved register 0
2786 0x80x0 0000 0200 0009 regs.s1 Callee saved register 1
2787 0x80x0 0000 0200 000a regs.a0 Function argument (or return value) 0
2788 0x80x0 0000 0200 000b regs.a1 Function argument (or return value) 1
2789 0x80x0 0000 0200 000c regs.a2 Function argument 2
2790 0x80x0 0000 0200 000d regs.a3 Function argument 3
2791 0x80x0 0000 0200 000e regs.a4 Function argument 4
2792 0x80x0 0000 0200 000f regs.a5 Function argument 5
2793 0x80x0 0000 0200 0010 regs.a6 Function argument 6
2794 0x80x0 0000 0200 0011 regs.a7 Function argument 7
2795 0x80x0 0000 0200 0012 regs.s2 Callee saved register 2
2796 0x80x0 0000 0200 0013 regs.s3 Callee saved register 3
2797 0x80x0 0000 0200 0014 regs.s4 Callee saved register 4
2798 0x80x0 0000 0200 0015 regs.s5 Callee saved register 5
2799 0x80x0 0000 0200 0016 regs.s6 Callee saved register 6
2800 0x80x0 0000 0200 0017 regs.s7 Callee saved register 7
2801 0x80x0 0000 0200 0018 regs.s8 Callee saved register 8
2802 0x80x0 0000 0200 0019 regs.s9 Callee saved register 9
2803 0x80x0 0000 0200 001a regs.s10 Callee saved register 10
2804 0x80x0 0000 0200 001b regs.s11 Callee saved register 11
2805 0x80x0 0000 0200 001c regs.t3 Caller saved register 3
2806 0x80x0 0000 0200 001d regs.t4 Caller saved register 4
2807 0x80x0 0000 0200 001e regs.t5 Caller saved register 5
2808 0x80x0 0000 0200 001f regs.t6 Caller saved register 6
2809 0x80x0 0000 0200 0020 mode Privilege mode (1 = S-mode or 0 = U-mode)
2810======================= ========= =============================================
2811
2812RISC-V csr registers represent the supervisor mode control/status registers
2813of a Guest VCPU and it has the following id bit patterns::
2814
2815 0x8020 0000 03 <index into the kvm_riscv_csr struct:24> (32bit Host)
2816 0x8030 0000 03 <index into the kvm_riscv_csr struct:24> (64bit Host)
2817
2818Following are the RISC-V csr registers:
2819
2820======================= ========= =============================================
2821 Encoding Register Description
2822======================= ========= =============================================
2823 0x80x0 0000 0300 0000 sstatus Supervisor status
2824 0x80x0 0000 0300 0001 sie Supervisor interrupt enable
2825 0x80x0 0000 0300 0002 stvec Supervisor trap vector base
2826 0x80x0 0000 0300 0003 sscratch Supervisor scratch register
2827 0x80x0 0000 0300 0004 sepc Supervisor exception program counter
2828 0x80x0 0000 0300 0005 scause Supervisor trap cause
2829 0x80x0 0000 0300 0006 stval Supervisor bad address or instruction
2830 0x80x0 0000 0300 0007 sip Supervisor interrupt pending
2831 0x80x0 0000 0300 0008 satp Supervisor address translation and protection
2832======================= ========= =============================================
2833
2834RISC-V timer registers represent the timer state of a Guest VCPU and it has
2835the following id bit patterns::
2836
2837 0x8030 0000 04 <index into the kvm_riscv_timer struct:24>
2838
2839Following are the RISC-V timer registers:
2840
2841======================= ========= =============================================
2842 Encoding Register Description
2843======================= ========= =============================================
2844 0x8030 0000 0400 0000 frequency Time base frequency (read-only)
2845 0x8030 0000 0400 0001 time Time value visible to Guest
2846 0x8030 0000 0400 0002 compare Time compare programmed by Guest
2847 0x8030 0000 0400 0003 state Time compare state (1 = ON or 0 = OFF)
2848======================= ========= =============================================
2849
2850RISC-V F-extension registers represent the single precision floating point
2851state of a Guest VCPU and it has the following id bit patterns::
2852
2853 0x8020 0000 05 <index into the __riscv_f_ext_state struct:24>
2854
2855Following are the RISC-V F-extension registers:
2856
2857======================= ========= =============================================
2858 Encoding Register Description
2859======================= ========= =============================================
2860 0x8020 0000 0500 0000 f[0] Floating point register 0
2861 ...
2862 0x8020 0000 0500 001f f[31] Floating point register 31
2863 0x8020 0000 0500 0020 fcsr Floating point control and status register
2864======================= ========= =============================================
2865
2866RISC-V D-extension registers represent the double precision floating point
2867state of a Guest VCPU and it has the following id bit patterns::
2868
2869 0x8020 0000 06 <index into the __riscv_d_ext_state struct:24> (fcsr)
2870 0x8030 0000 06 <index into the __riscv_d_ext_state struct:24> (non-fcsr)
2871
2872Following are the RISC-V D-extension registers:
2873
2874======================= ========= =============================================
2875 Encoding Register Description
2876======================= ========= =============================================
2877 0x8030 0000 0600 0000 f[0] Floating point register 0
2878 ...
2879 0x8030 0000 0600 001f f[31] Floating point register 31
2880 0x8020 0000 0600 0020 fcsr Floating point control and status register
2881======================= ========= =============================================
2882
6f0257a0
TZ
2883LoongArch registers are mapped using the lower 32 bits. The upper 16 bits of
2884that is the register group type.
2885
2886LoongArch csr registers are used to control guest cpu or get status of guest
2887cpu, and they have the following id bit patterns::
2888
2889 0x9030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2890
2891LoongArch KVM control registers are used to implement some new defined functions
2892such as set vcpu counter or reset vcpu, and they have the following id bit patterns::
2893
2894 0x9030 0000 0002 <reg:16>
2895
c2d2c21b 2896
e24ed81f 28974.69 KVM_GET_ONE_REG
106ee47d
MCC
2898--------------------
2899
2900:Capability: KVM_CAP_ONE_REG
2901:Architectures: all
2902:Type: vcpu ioctl
2903:Parameters: struct kvm_one_reg (in and out)
2904:Returns: 0 on success, negative value on failure
e24ed81f 2905
fe365b4e 2906Errors include:
106ee47d
MCC
2907
2908 ======== ============================================================
3b1c8c56
MCC
2909 ENOENT no such register
2910 EINVAL invalid register ID, or no such register or used with VMs in
68cf7b1f 2911 protected virtualization mode on s390
3b1c8c56 2912 EPERM (arm64) register access not allowed before vcpu finalization
106ee47d
MCC
2913 ======== ============================================================
2914
fe365b4e
DM
2915(These error codes are indicative only: do not rely on a specific error
2916code being returned in a specific situation.)
e24ed81f
AG
2917
2918This ioctl allows to receive the value of a single register implemented
2919in a vcpu. The register to read is indicated by the "id" field of the
2920kvm_one_reg struct passed in. On success, the register value can be found
2921at the memory location pointed to by "addr".
2922
2923The list of registers accessible using this interface is identical to the
2e232702 2924list in 4.68.
e24ed81f 2925
414fa985 2926
1c0b28c2 29274.70 KVM_KVMCLOCK_CTRL
106ee47d 2928----------------------
1c0b28c2 2929
106ee47d
MCC
2930:Capability: KVM_CAP_KVMCLOCK_CTRL
2931:Architectures: Any that implement pvclocks (currently x86 only)
2932:Type: vcpu ioctl
2933:Parameters: None
2934:Returns: 0 on success, -1 on error
1c0b28c2 2935
35c59990
JA
2936This ioctl sets a flag accessible to the guest indicating that the specified
2937vCPU has been paused by the host userspace.
2938
2939The host will set a flag in the pvclock structure that is checked from the
2940soft lockup watchdog. The flag is part of the pvclock structure that is
2941shared between guest and host, specifically the second bit of the flags
1c0b28c2
EM
2942field of the pvclock_vcpu_time_info structure. It will be set exclusively by
2943the host and read/cleared exclusively by the guest. The guest operation of
35c59990 2944checking and clearing the flag must be an atomic operation so
1c0b28c2
EM
2945load-link/store-conditional, or equivalent must be used. There are two cases
2946where the guest will clear the flag: when the soft lockup watchdog timer resets
2947itself or when a soft lockup is detected. This ioctl can be called any time
2948after pausing the vcpu, but before it is resumed.
2949
414fa985 2950
07975ad3 29514.71 KVM_SIGNAL_MSI
106ee47d 2952-------------------
07975ad3 2953
106ee47d 2954:Capability: KVM_CAP_SIGNAL_MSI
3fbf4207 2955:Architectures: x86 arm64
106ee47d
MCC
2956:Type: vm ioctl
2957:Parameters: struct kvm_msi (in)
2958:Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
07975ad3
JK
2959
2960Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2961MSI messages.
2962
106ee47d
MCC
2963::
2964
2965 struct kvm_msi {
07975ad3
JK
2966 __u32 address_lo;
2967 __u32 address_hi;
2968 __u32 data;
2969 __u32 flags;
2b8ddd93
AP
2970 __u32 devid;
2971 __u8 pad[12];
106ee47d 2972 };
07975ad3 2973
106ee47d
MCC
2974flags:
2975 KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM
6f49b2f3
PB
2976 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2977 the device ID. If this capability is not available, userspace
2978 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
2b8ddd93 2979
6f49b2f3
PB
2980If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2981for the device that wrote the MSI message. For PCI, this is usually a
2982BFD identifier in the lower 16 bits.
07975ad3 2983
055b6ae9
PB
2984On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2985feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
2986address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
2987address_hi must be zero.
37131313 2988
414fa985 2989
0589ff6c 29904.71 KVM_CREATE_PIT2
106ee47d 2991--------------------
0589ff6c 2992
106ee47d
MCC
2993:Capability: KVM_CAP_PIT2
2994:Architectures: x86
2995:Type: vm ioctl
2996:Parameters: struct kvm_pit_config (in)
2997:Returns: 0 on success, -1 on error
0589ff6c
JK
2998
2999Creates an in-kernel device model for the i8254 PIT. This call is only valid
3000after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
106ee47d 3001parameters have to be passed::
0589ff6c 3002
106ee47d 3003 struct kvm_pit_config {
0589ff6c
JK
3004 __u32 flags;
3005 __u32 pad[15];
106ee47d 3006 };
0589ff6c 3007
106ee47d 3008Valid flags are::
0589ff6c 3009
106ee47d 3010 #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
0589ff6c 3011
b6ddf05f 3012PIT timer interrupts may use a per-VM kernel thread for injection. If it
106ee47d 3013exists, this thread will have a name of the following pattern::
b6ddf05f 3014
106ee47d 3015 kvm-pit/<owner-process-pid>
b6ddf05f
JK
3016
3017When running a guest with elevated priorities, the scheduling parameters of
3018this thread may have to be adjusted accordingly.
3019
0589ff6c
JK
3020This IOCTL replaces the obsolete KVM_CREATE_PIT.
3021
3022
30234.72 KVM_GET_PIT2
106ee47d 3024-----------------
0589ff6c 3025
106ee47d
MCC
3026:Capability: KVM_CAP_PIT_STATE2
3027:Architectures: x86
3028:Type: vm ioctl
3029:Parameters: struct kvm_pit_state2 (out)
3030:Returns: 0 on success, -1 on error
0589ff6c
JK
3031
3032Retrieves the state of the in-kernel PIT model. Only valid after
106ee47d 3033KVM_CREATE_PIT2. The state is returned in the following structure::
0589ff6c 3034
106ee47d 3035 struct kvm_pit_state2 {
0589ff6c
JK
3036 struct kvm_pit_channel_state channels[3];
3037 __u32 flags;
3038 __u32 reserved[9];
106ee47d 3039 };
0589ff6c 3040
106ee47d 3041Valid flags are::
0589ff6c 3042
106ee47d 3043 /* disable PIT in HPET legacy mode */
b1728622
PD
3044 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
3045 /* speaker port data bit enabled */
3046 #define KVM_PIT_FLAGS_SPEAKER_DATA_ON 0x00000002
0589ff6c
JK
3047
3048This IOCTL replaces the obsolete KVM_GET_PIT.
3049
3050
30514.73 KVM_SET_PIT2
106ee47d 3052-----------------
0589ff6c 3053
106ee47d
MCC
3054:Capability: KVM_CAP_PIT_STATE2
3055:Architectures: x86
3056:Type: vm ioctl
3057:Parameters: struct kvm_pit_state2 (in)
3058:Returns: 0 on success, -1 on error
0589ff6c
JK
3059
3060Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
3061See KVM_GET_PIT2 for details on struct kvm_pit_state2.
3062
3063This IOCTL replaces the obsolete KVM_SET_PIT.
3064
3065
5b74716e 30664.74 KVM_PPC_GET_SMMU_INFO
106ee47d 3067--------------------------
5b74716e 3068
106ee47d
MCC
3069:Capability: KVM_CAP_PPC_GET_SMMU_INFO
3070:Architectures: powerpc
3071:Type: vm ioctl
3072:Parameters: None
3073:Returns: 0 on success, -1 on error
5b74716e
BH
3074
3075This populates and returns a structure describing the features of
3076the "Server" class MMU emulation supported by KVM.
cc22c354 3077This can in turn be used by userspace to generate the appropriate
5b74716e
BH
3078device-tree properties for the guest operating system.
3079
c98be0c9 3080The structure contains some global information, followed by an
106ee47d 3081array of supported segment page sizes::
5b74716e
BH
3082
3083 struct kvm_ppc_smmu_info {
3084 __u64 flags;
3085 __u32 slb_size;
3086 __u32 pad;
3087 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
3088 };
3089
3090The supported flags are:
3091
3092 - KVM_PPC_PAGE_SIZES_REAL:
3093 When that flag is set, guest page sizes must "fit" the backing
3094 store page sizes. When not set, any page size in the list can
3095 be used regardless of how they are backed by userspace.
3096
3097 - KVM_PPC_1T_SEGMENTS
3098 The emulated MMU supports 1T segments in addition to the
3099 standard 256M ones.
3100
901f8c3f
PM
3101 - KVM_PPC_NO_HASH
3102 This flag indicates that HPT guests are not supported by KVM,
3103 thus all guests must use radix MMU mode.
3104
5b74716e
BH
3105The "slb_size" field indicates how many SLB entries are supported
3106
3107The "sps" array contains 8 entries indicating the supported base
3108page sizes for a segment in increasing order. Each entry is defined
106ee47d 3109as follow::
5b74716e
BH
3110
3111 struct kvm_ppc_one_seg_page_size {
3112 __u32 page_shift; /* Base page shift of segment (or 0) */
3113 __u32 slb_enc; /* SLB encoding for BookS */
3114 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
3115 };
3116
3117An entry with a "page_shift" of 0 is unused. Because the array is
57f33f1a 3118organized in increasing order, a lookup can stop when encountering
5b74716e
BH
3119such an entry.
3120
3121The "slb_enc" field provides the encoding to use in the SLB for the
3122page size. The bits are in positions such as the value can directly
3123be OR'ed into the "vsid" argument of the slbmte instruction.
3124
3125The "enc" array is a list which for each of those segment base page
3126size provides the list of supported actual page sizes (which can be
3127only larger or equal to the base page size), along with the
f884ab15 3128corresponding encoding in the hash PTE. Similarly, the array is
5b74716e 31298 entries sorted by increasing sizes and an entry with a "0" shift
106ee47d 3130is an empty entry and a terminator::
5b74716e
BH
3131
3132 struct kvm_ppc_one_page_size {
3133 __u32 page_shift; /* Page shift (or 0) */
3134 __u32 pte_enc; /* Encoding in the HPTE (>>12) */
3135 };
3136
3137The "pte_enc" field provides a value that can OR'ed into the hash
3138PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
3139into the hash PTE second double word).
3140
f36992e3 31414.75 KVM_IRQFD
106ee47d 3142--------------
f36992e3 3143
106ee47d 3144:Capability: KVM_CAP_IRQFD
3fbf4207 3145:Architectures: x86 s390 arm64
106ee47d
MCC
3146:Type: vm ioctl
3147:Parameters: struct kvm_irqfd (in)
3148:Returns: 0 on success, -1 on error
f36992e3
AW
3149
3150Allows setting an eventfd to directly trigger a guest interrupt.
3151kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
3152kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
17180032 3153an event is triggered on the eventfd, an interrupt is injected into
f36992e3
AW
3154the guest using the specified gsi pin. The irqfd is removed using
3155the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
3156and kvm_irqfd.gsi.
3157
7a84428a
AW
3158With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
3159mechanism allowing emulation of level-triggered, irqfd-based
3160interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
3161additional eventfd in the kvm_irqfd.resamplefd field. When operating
3162in resample mode, posting of an interrupt through kvm_irq.fd asserts
3163the specified gsi in the irqchip. When the irqchip is resampled, such
17180032 3164as from an EOI, the gsi is de-asserted and the user is notified via
7a84428a
AW
3165kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
3166the interrupt if the device making use of it still requires service.
3167Note that closing the resamplefd is not sufficient to disable the
3168irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
3169and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
3170
3fbf4207 3171On arm64, gsi routing being supported, the following can happen:
106ee47d 3172
180ae7b1
EA
3173- in case no routing entry is associated to this gsi, injection fails
3174- in case the gsi is associated to an irqchip routing entry,
3175 irqchip.pin + 32 corresponds to the injected SPI ID.
995a0ee9
EA
3176- in case the gsi is associated to an MSI routing entry, the MSI
3177 message and device ID are translated into an LPI (support restricted
3178 to GICv3 ITS in-kernel emulation).
174178fe 3179
5fecc9d8 31804.76 KVM_PPC_ALLOCATE_HTAB
106ee47d 3181--------------------------
32fad281 3182
106ee47d
MCC
3183:Capability: KVM_CAP_PPC_ALLOC_HTAB
3184:Architectures: powerpc
3185:Type: vm ioctl
3186:Parameters: Pointer to u32 containing hash table order (in/out)
3187:Returns: 0 on success, -1 on error
32fad281
PM
3188
3189This requests the host kernel to allocate an MMU hash table for a
3190guest using the PAPR paravirtualization interface. This only does
3191anything if the kernel is configured to use the Book 3S HV style of
3192virtualization. Otherwise the capability doesn't exist and the ioctl
3193returns an ENOTTY error. The rest of this description assumes Book 3S
3194HV.
3195
3196There must be no vcpus running when this ioctl is called; if there
3197are, it will do nothing and return an EBUSY error.
3198
3199The parameter is a pointer to a 32-bit unsigned integer variable
3200containing the order (log base 2) of the desired size of the hash
3201table, which must be between 18 and 46. On successful return from the
f98a8bf9 3202ioctl, the value will not be changed by the kernel.
32fad281
PM
3203
3204If no hash table has been allocated when any vcpu is asked to run
3205(with the KVM_RUN ioctl), the host kernel will allocate a
3206default-sized hash table (16 MB).
3207
3208If this ioctl is called when a hash table has already been allocated,
f98a8bf9
DG
3209with a different order from the existing hash table, the existing hash
3210table will be freed and a new one allocated. If this is ioctl is
3211called when a hash table has already been allocated of the same order
3212as specified, the kernel will clear out the existing hash table (zero
3213all HPTEs). In either case, if the guest is using the virtualized
3214real-mode area (VRMA) facility, the kernel will re-create the VMRA
3215HPTEs on the next KVM_RUN of any vcpu.
32fad281 3216
416ad65f 32174.77 KVM_S390_INTERRUPT
106ee47d 3218-----------------------
416ad65f 3219
106ee47d
MCC
3220:Capability: basic
3221:Architectures: s390
3222:Type: vm ioctl, vcpu ioctl
3223:Parameters: struct kvm_s390_interrupt (in)
3224:Returns: 0 on success, -1 on error
416ad65f
CH
3225
3226Allows to inject an interrupt to the guest. Interrupts can be floating
3227(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
3228
106ee47d 3229Interrupt parameters are passed via kvm_s390_interrupt::
416ad65f 3230
106ee47d 3231 struct kvm_s390_interrupt {
416ad65f
CH
3232 __u32 type;
3233 __u32 parm;
3234 __u64 parm64;
106ee47d 3235 };
416ad65f
CH
3236
3237type can be one of the following:
3238
106ee47d
MCC
3239KVM_S390_SIGP_STOP (vcpu)
3240 - sigp stop; optional flags in parm
3241KVM_S390_PROGRAM_INT (vcpu)
3242 - program check; code in parm
3243KVM_S390_SIGP_SET_PREFIX (vcpu)
3244 - sigp set prefix; prefix address in parm
3245KVM_S390_RESTART (vcpu)
3246 - restart
3247KVM_S390_INT_CLOCK_COMP (vcpu)
3248 - clock comparator interrupt
3249KVM_S390_INT_CPU_TIMER (vcpu)
3250 - CPU timer interrupt
3251KVM_S390_INT_VIRTIO (vm)
3252 - virtio external interrupt; external interrupt
3253 parameters in parm and parm64
3254KVM_S390_INT_SERVICE (vm)
3255 - sclp external interrupt; sclp parameter in parm
3256KVM_S390_INT_EMERGENCY (vcpu)
3257 - sigp emergency; source cpu in parm
3258KVM_S390_INT_EXTERNAL_CALL (vcpu)
3259 - sigp external call; source cpu in parm
3260KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm)
3261 - compound value to indicate an
3262 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
3263 I/O interruption parameters in parm (subchannel) and parm64 (intparm,
3264 interruption subclass)
3265KVM_S390_MCHK (vm, vcpu)
3266 - machine check interrupt; cr 14 bits in parm, machine check interrupt
3267 code in parm64 (note that machine checks needing further payload are not
3268 supported by this ioctl)
416ad65f 3269
5e124900 3270This is an asynchronous vcpu ioctl and can be invoked from any thread.
416ad65f 3271
a2932923 32724.78 KVM_PPC_GET_HTAB_FD
106ee47d 3273------------------------
a2932923 3274
106ee47d
MCC
3275:Capability: KVM_CAP_PPC_HTAB_FD
3276:Architectures: powerpc
3277:Type: vm ioctl
3278:Parameters: Pointer to struct kvm_get_htab_fd (in)
3279:Returns: file descriptor number (>= 0) on success, -1 on error
a2932923
PM
3280
3281This returns a file descriptor that can be used either to read out the
3282entries in the guest's hashed page table (HPT), or to write entries to
3283initialize the HPT. The returned fd can only be written to if the
3284KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
3285can only be read if that bit is clear. The argument struct looks like
106ee47d 3286this::
a2932923 3287
106ee47d
MCC
3288 /* For KVM_PPC_GET_HTAB_FD */
3289 struct kvm_get_htab_fd {
a2932923
PM
3290 __u64 flags;
3291 __u64 start_index;
3292 __u64 reserved[2];
106ee47d 3293 };
a2932923 3294
106ee47d
MCC
3295 /* Values for kvm_get_htab_fd.flags */
3296 #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
3297 #define KVM_GET_HTAB_WRITE ((__u64)0x2)
a2932923 3298
106ee47d 3299The 'start_index' field gives the index in the HPT of the entry at
a2932923
PM
3300which to start reading. It is ignored when writing.
3301
3302Reads on the fd will initially supply information about all
3303"interesting" HPT entries. Interesting entries are those with the
3304bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
3305all entries. When the end of the HPT is reached, the read() will
3306return. If read() is called again on the fd, it will start again from
3307the beginning of the HPT, but will only return HPT entries that have
3308changed since they were last read.
3309
3310Data read or written is structured as a header (8 bytes) followed by a
3311series of valid HPT entries (16 bytes) each. The header indicates how
3312many valid HPT entries there are and how many invalid entries follow
3313the valid entries. The invalid entries are not represented explicitly
106ee47d 3314in the stream. The header format is::
a2932923 3315
106ee47d 3316 struct kvm_get_htab_header {
a2932923
PM
3317 __u32 index;
3318 __u16 n_valid;
3319 __u16 n_invalid;
106ee47d 3320 };
a2932923
PM
3321
3322Writes to the fd create HPT entries starting at the index given in the
106ee47d
MCC
3323header; first 'n_valid' valid entries with contents from the data
3324written, then 'n_invalid' invalid entries, invalidating any previously
a2932923
PM
3325valid entries found.
3326
852b6d57 33274.79 KVM_CREATE_DEVICE
106ee47d
MCC
3328----------------------
3329
3330:Capability: KVM_CAP_DEVICE_CTRL
10c5e80b 3331:Architectures: all
106ee47d
MCC
3332:Type: vm ioctl
3333:Parameters: struct kvm_create_device (in/out)
3334:Returns: 0 on success, -1 on error
852b6d57 3335
852b6d57 3336Errors:
106ee47d
MCC
3337
3338 ====== =======================================================
3339 ENODEV The device type is unknown or unsupported
3340 EEXIST Device already created, and this type of device may not
852b6d57 3341 be instantiated multiple times
106ee47d 3342 ====== =======================================================
852b6d57
SW
3343
3344 Other error conditions may be defined by individual device types or
3345 have their standard meanings.
3346
3347Creates an emulated device in the kernel. The file descriptor returned
3348in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
3349
3350If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
3351device type is supported (not necessarily whether it can be created
3352in the current vm).
3353
3354Individual devices should not define flags. Attributes should be used
3355for specifying any behavior that is not implied by the device type
3356number.
3357
106ee47d
MCC
3358::
3359
3360 struct kvm_create_device {
852b6d57
SW
3361 __u32 type; /* in: KVM_DEV_TYPE_xxx */
3362 __u32 fd; /* out: device handle */
3363 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
106ee47d 3364 };
852b6d57
SW
3365
33664.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
106ee47d
MCC
3367--------------------------------------------
3368
3369:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3370 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
dd6e6312 3371 KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device (no set)
10c5e80b 3372:Architectures: x86, arm64, s390
106ee47d
MCC
3373:Type: device ioctl, vm ioctl, vcpu ioctl
3374:Parameters: struct kvm_device_attr
3375:Returns: 0 on success, -1 on error
852b6d57 3376
852b6d57 3377Errors:
106ee47d
MCC
3378
3379 ===== =============================================================
3380 ENXIO The group or attribute is unknown/unsupported for this device
f9cbd9b0 3381 or hardware support is missing.
106ee47d 3382 EPERM The attribute cannot (currently) be accessed this way
852b6d57
SW
3383 (e.g. read-only attribute, or attribute that only makes
3384 sense when the device is in a different state)
106ee47d 3385 ===== =============================================================
852b6d57
SW
3386
3387 Other error conditions may be defined by individual device types.
3388
3389Gets/sets a specified piece of device configuration and/or state. The
3390semantics are device-specific. See individual device documentation in
3391the "devices" directory. As with ONE_REG, the size of the data
3392transferred is defined by the particular attribute.
3393
106ee47d
MCC
3394::
3395
3396 struct kvm_device_attr {
852b6d57
SW
3397 __u32 flags; /* no flags currently defined */
3398 __u32 group; /* device-defined */
3399 __u64 attr; /* group-defined */
3400 __u64 addr; /* userspace address of attr data */
106ee47d 3401 };
852b6d57
SW
3402
34034.81 KVM_HAS_DEVICE_ATTR
106ee47d
MCC
3404------------------------
3405
3406:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
dd6e6312
PB
3407 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3408 KVM_CAP_SYS_ATTRIBUTES for system (/dev/kvm) device
106ee47d
MCC
3409:Type: device ioctl, vm ioctl, vcpu ioctl
3410:Parameters: struct kvm_device_attr
3411:Returns: 0 on success, -1 on error
852b6d57 3412
852b6d57 3413Errors:
106ee47d
MCC
3414
3415 ===== =============================================================
3416 ENXIO The group or attribute is unknown/unsupported for this device
f9cbd9b0 3417 or hardware support is missing.
106ee47d 3418 ===== =============================================================
852b6d57
SW
3419
3420Tests whether a device supports a particular attribute. A successful
3421return indicates the attribute is implemented. It does not necessarily
3422indicate that the attribute can be read or written in the device's
3423current state. "addr" is ignored.
f36992e3 3424
d8968f1f 34254.82 KVM_ARM_VCPU_INIT
106ee47d
MCC
3426----------------------
3427
3428:Capability: basic
3fbf4207 3429:Architectures: arm64
106ee47d
MCC
3430:Type: vcpu ioctl
3431:Parameters: struct kvm_vcpu_init (in)
3432:Returns: 0 on success; -1 on error
749cf76c 3433
749cf76c 3434Errors:
106ee47d
MCC
3435
3436 ====== =================================================================
3b1c8c56
MCC
3437 EINVAL the target is unknown, or the combination of features is invalid.
3438 ENOENT a features bit specified is unknown.
106ee47d 3439 ====== =================================================================
749cf76c
CD
3440
3441This tells KVM what type of CPU to present to the guest, and what
3b1c8c56
MCC
3442optional features it should have. This will cause a reset of the cpu
3443registers to their initial values. If this is not called, KVM_RUN will
749cf76c
CD
3444return ENOEXEC for that vcpu.
3445
5b32a53d
MZ
3446The initial values are defined as:
3447 - Processor state:
3448 * AArch64: EL1h, D, A, I and F bits set. All other bits
3449 are cleared.
3450 * AArch32: SVC, A, I and F bits set. All other bits are
3451 cleared.
3452 - General Purpose registers, including PC and SP: set to 0
3453 - FPSIMD/NEON registers: set to 0
3454 - SVE registers: set to 0
3455 - System registers: Reset to their architecturally defined
3456 values as for a warm reset to EL1 (resp. SVC)
3457
749cf76c
CD
3458Note that because some registers reflect machine topology, all vcpus
3459should be created before this ioctl is invoked.
3460
f7fa034d
CD
3461Userspace can call this function multiple times for a given vcpu, including
3462after the vcpu has been run. This will reset the vcpu to its initial
3463state. All calls to this function after the initial call must use the same
3464target and same set of feature flags, otherwise EINVAL will be returned.
3465
aa024c2f 3466Possible features:
106ee47d 3467
aa024c2f 3468 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
3ad8b3de
CD
3469 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
3470 and execute guest code when KVM_RUN is called.
379e04c7
MZ
3471 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
3472 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
85bd0ba1
MZ
3473 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
3474 backward compatible with v0.2) for the CPU.
50bb0c94 3475 Depends on KVM_CAP_ARM_PSCI_0_2.
808e7381
SZ
3476 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
3477 Depends on KVM_CAP_ARM_PMU_V3.
aa024c2f 3478
a22fa321
ADK
3479 - KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication
3480 for arm64 only.
a243c16d
ADK
3481 Depends on KVM_CAP_ARM_PTRAUTH_ADDRESS.
3482 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3483 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3484 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3485 requested.
a22fa321
ADK
3486
3487 - KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication
3488 for arm64 only.
a243c16d
ADK
3489 Depends on KVM_CAP_ARM_PTRAUTH_GENERIC.
3490 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3491 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3492 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3493 requested.
a22fa321 3494
50036ad0
DM
3495 - KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only).
3496 Depends on KVM_CAP_ARM_SVE.
3497 Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3498
3499 * After KVM_ARM_VCPU_INIT:
3500
3501 - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the
3502 initial value of this pseudo-register indicates the best set of
3503 vector lengths possible for a vcpu on this host.
3504
3505 * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3506
3507 - KVM_RUN and KVM_GET_REG_LIST are not available;
3508
3509 - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access
57f33f1a 3510 the scalable architectural SVE registers
50036ad0
DM
3511 KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or
3512 KVM_REG_ARM64_SVE_FFR;
3513
3514 - KVM_REG_ARM64_SVE_VLS may optionally be written using
3515 KVM_SET_ONE_REG, to modify the set of vector lengths available
3516 for the vcpu.
3517
3518 * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3519
3520 - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can
3521 no longer be written using KVM_SET_ONE_REG.
749cf76c 3522
740edfc0 35234.83 KVM_ARM_PREFERRED_TARGET
106ee47d
MCC
3524-----------------------------
3525
3526:Capability: basic
3fbf4207 3527:Architectures: arm64
106ee47d 3528:Type: vm ioctl
a84b757e 3529:Parameters: struct kvm_vcpu_init (out)
106ee47d 3530:Returns: 0 on success; -1 on error
740edfc0 3531
740edfc0 3532Errors:
106ee47d
MCC
3533
3534 ====== ==========================================
3535 ENODEV no preferred target available for the host
3536 ====== ==========================================
740edfc0
AP
3537
3538This queries KVM for preferred CPU target type which can be emulated
3539by KVM on underlying host.
3540
3541The ioctl returns struct kvm_vcpu_init instance containing information
3542about preferred CPU target type and recommended features for it. The
3543kvm_vcpu_init->features bitmap returned will have feature bits set if
3544the preferred target recommends setting these features, but this is
3545not mandatory.
3546
3547The information returned by this ioctl can be used to prepare an instance
3548of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
3747c5d3 3549VCPU matching underlying host.
740edfc0
AP
3550
3551
35524.84 KVM_GET_REG_LIST
106ee47d
MCC
3553---------------------
3554
3555:Capability: basic
031f9efa 3556:Architectures: arm64, mips, riscv
106ee47d
MCC
3557:Type: vcpu ioctl
3558:Parameters: struct kvm_reg_list (in/out)
3559:Returns: 0 on success; -1 on error
749cf76c 3560
749cf76c 3561Errors:
106ee47d
MCC
3562
3563 ===== ==============================================================
3b1c8c56
MCC
3564 E2BIG the reg index list is too big to fit in the array specified by
3565 the user (the number required will be written into n).
106ee47d
MCC
3566 ===== ==============================================================
3567
3568::
749cf76c 3569
106ee47d 3570 struct kvm_reg_list {
749cf76c
CD
3571 __u64 n; /* number of registers in reg[] */
3572 __u64 reg[0];
106ee47d 3573 };
749cf76c
CD
3574
3575This ioctl returns the guest registers that are supported for the
3576KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
3577
ce01e4e8
CD
3578
35794.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
106ee47d
MCC
3580-----------------------------------------
3581
3582:Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
3fbf4207 3583:Architectures: arm64
106ee47d
MCC
3584:Type: vm ioctl
3585:Parameters: struct kvm_arm_device_address (in)
3586:Returns: 0 on success, -1 on error
3401d546 3587
3401d546 3588Errors:
3401d546 3589
106ee47d
MCC
3590 ====== ============================================
3591 ENODEV The device id is unknown
3592 ENXIO Device not supported on current system
3593 EEXIST Address already set
3594 E2BIG Address outside guest physical address space
3595 EBUSY Address overlaps with other device range
3596 ====== ============================================
3597
3598::
3599
3600 struct kvm_arm_device_addr {
3401d546
CD
3601 __u64 id;
3602 __u64 addr;
106ee47d 3603 };
3401d546
CD
3604
3605Specify a device address in the guest's physical address space where guests
3606can access emulated or directly exposed devices, which the host kernel needs
3607to know about. The id field is an architecture specific identifier for a
3608specific device.
3609
3fbf4207 3610arm64 divides the id field into two parts, a device id and an
106ee47d 3611address type id specific to the individual device::
3401d546 3612
3b1c8c56 3613 bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
3401d546
CD
3614 field: | 0x00000000 | device id | addr type id |
3615
3fbf4207 3616arm64 currently only require this when using the in-kernel GIC
379e04c7
MZ
3617support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
3618as the device id. When setting the base address for the guest's
3619mapping of the VGIC virtual CPU and distributor interface, the ioctl
3620must be called after calling KVM_CREATE_IRQCHIP, but before calling
3621KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
3622base addresses will return -EEXIST.
3401d546 3623
ce01e4e8
CD
3624Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
3625should be used instead.
3626
3627
740edfc0 36284.86 KVM_PPC_RTAS_DEFINE_TOKEN
106ee47d 3629------------------------------
8e591cb7 3630
106ee47d
MCC
3631:Capability: KVM_CAP_PPC_RTAS
3632:Architectures: ppc
3633:Type: vm ioctl
3634:Parameters: struct kvm_rtas_token_args
3635:Returns: 0 on success, -1 on error
8e591cb7
ME
3636
3637Defines a token value for a RTAS (Run Time Abstraction Services)
3638service in order to allow it to be handled in the kernel. The
3639argument struct gives the name of the service, which must be the name
3640of a service that has a kernel-side implementation. If the token
3641value is non-zero, it will be associated with that service, and
3642subsequent RTAS calls by the guest specifying that token will be
3643handled by the kernel. If the token value is 0, then any token
3644associated with the service will be forgotten, and subsequent RTAS
3645calls by the guest for that service will be passed to userspace to be
3646handled.
3647
4bd9d344 36484.87 KVM_SET_GUEST_DEBUG
106ee47d 3649------------------------
4bd9d344 3650
106ee47d
MCC
3651:Capability: KVM_CAP_SET_GUEST_DEBUG
3652:Architectures: x86, s390, ppc, arm64
3653:Type: vcpu ioctl
3654:Parameters: struct kvm_guest_debug (in)
3655:Returns: 0 on success; -1 on error
3656
3657::
4bd9d344 3658
106ee47d 3659 struct kvm_guest_debug {
4bd9d344
AB
3660 __u32 control;
3661 __u32 pad;
3662 struct kvm_guest_debug_arch arch;
106ee47d 3663 };
4bd9d344
AB
3664
3665Set up the processor specific debug registers and configure vcpu for
3666handling guest debug events. There are two parts to the structure, the
3667first a control bitfield indicates the type of debug events to handle
3668when running. Common control bits are:
3669
3670 - KVM_GUESTDBG_ENABLE: guest debugging is enabled
3671 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
3672
3673The top 16 bits of the control field are architecture specific control
3674flags which can include the following:
3675
4bd611ca 3676 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
feb5dc3d
AE
3677 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390]
3678 - KVM_GUESTDBG_USE_HW: using hardware debug events [arm64]
4bd9d344
AB
3679 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
3680 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
3681 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
61e5f69e 3682 - KVM_GUESTDBG_BLOCKIRQ: avoid injecting interrupts/NMI/SMI [x86]
4bd9d344
AB
3683
3684For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
3685are enabled in memory so we need to ensure breakpoint exceptions are
3686correctly trapped and the KVM run loop exits at the breakpoint and not
3687running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
3688we need to ensure the guest vCPUs architecture specific registers are
3689updated to the correct (supplied) values.
3690
3691The second part of the structure is architecture specific and
3692typically contains a set of debug registers.
3693
834bf887
AB
3694For arm64 the number of debug registers is implementation defined and
3695can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
3696KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
3697indicating the number of supported registers.
3698
1a9167a2
FR
3699For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether
3700the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported.
3701
8b13c364
PB
3702Also when supported, KVM_CAP_SET_GUEST_DEBUG2 capability indicates the
3703supported KVM_GUESTDBG_* bits in the control field.
3704
4bd9d344
AB
3705When debug events exit the main run loop with the reason
3706KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
3707structure containing architecture specific debug information.
3401d546 3708
209cf19f 37094.88 KVM_GET_EMULATED_CPUID
106ee47d
MCC
3710---------------------------
3711
3712:Capability: KVM_CAP_EXT_EMUL_CPUID
3713:Architectures: x86
3714:Type: system ioctl
3715:Parameters: struct kvm_cpuid2 (in/out)
3716:Returns: 0 on success, -1 on error
209cf19f 3717
106ee47d 3718::
209cf19f 3719
106ee47d 3720 struct kvm_cpuid2 {
209cf19f
AB
3721 __u32 nent;
3722 __u32 flags;
3723 struct kvm_cpuid_entry2 entries[0];
106ee47d 3724 };
209cf19f
AB
3725
3726The member 'flags' is used for passing flags from userspace.
3727
106ee47d 3728::
209cf19f 3729
106ee47d 3730 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
7ff6c035
SC
3731 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */
3732 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */
106ee47d
MCC
3733
3734 struct kvm_cpuid_entry2 {
209cf19f
AB
3735 __u32 function;
3736 __u32 index;
3737 __u32 flags;
3738 __u32 eax;
3739 __u32 ebx;
3740 __u32 ecx;
3741 __u32 edx;
3742 __u32 padding[3];
106ee47d 3743 };
209cf19f
AB
3744
3745This ioctl returns x86 cpuid features which are emulated by
3746kvm.Userspace can use the information returned by this ioctl to query
3747which features are emulated by kvm instead of being present natively.
3748
3749Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
3750structure with the 'nent' field indicating the number of entries in
3751the variable-size array 'entries'. If the number of entries is too low
3752to describe the cpu capabilities, an error (E2BIG) is returned. If the
3753number is too high, the 'nent' field is adjusted and an error (ENOMEM)
3754is returned. If the number is just right, the 'nent' field is adjusted
3755to the number of valid entries in the 'entries' array, which is then
3756filled.
3757
3758The entries returned are the set CPUID bits of the respective features
3759which kvm emulates, as returned by the CPUID instruction, with unknown
3760or unsupported feature bits cleared.
3761
3762Features like x2apic, for example, may not be present in the host cpu
3763but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
3764emulated efficiently and thus not included here.
3765
3766The fields in each entry are defined as follows:
3767
106ee47d
MCC
3768 function:
3769 the eax value used to obtain the entry
3770 index:
3771 the ecx value used to obtain the entry (for entries that are
209cf19f 3772 affected by ecx)
106ee47d
MCC
3773 flags:
3774 an OR of zero or more of the following:
3775
209cf19f
AB
3776 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
3777 if the index field is valid
106ee47d
MCC
3778
3779 eax, ebx, ecx, edx:
3780
3781 the values returned by the cpuid instruction for
209cf19f
AB
3782 this function/index combination
3783
41408c28 37844.89 KVM_S390_MEM_OP
106ee47d 3785--------------------
41408c28 3786
5e35d0eb 3787:Capability: KVM_CAP_S390_MEM_OP, KVM_CAP_S390_PROTECTED, KVM_CAP_S390_MEM_OP_EXTENSION
106ee47d 3788:Architectures: s390
5e35d0eb 3789:Type: vm ioctl, vcpu ioctl
106ee47d
MCC
3790:Parameters: struct kvm_s390_mem_op (in)
3791:Returns: = 0 on success,
3792 < 0 on generic error (e.g. -EFAULT or -ENOMEM),
a7b04173 3793 16 bit program exception code if the access causes such an exception
41408c28 3794
5e35d0eb
JSG
3795Read or write data from/to the VM's memory.
3796The KVM_CAP_S390_MEM_OP_EXTENSION capability specifies what functionality is
3797supported.
41408c28 3798
106ee47d 3799Parameters are specified via the following structure::
41408c28 3800
106ee47d 3801 struct kvm_s390_mem_op {
41408c28
TH
3802 __u64 gaddr; /* the guest address */
3803 __u64 flags; /* flags */
3804 __u32 size; /* amount of bytes */
3805 __u32 op; /* type of operation */
3806 __u64 buf; /* buffer in userspace */
5e35d0eb
JSG
3807 union {
3808 struct {
3809 __u8 ar; /* the access register number */
3810 __u8 key; /* access key, ignored if flag unset */
a7b04173
JSG
3811 __u8 pad1[6]; /* ignored */
3812 __u64 old_addr; /* ignored if flag unset */
5e35d0eb
JSG
3813 };
3814 __u32 sida_offset; /* offset into the sida */
3815 __u8 reserved[32]; /* ignored */
3816 };
106ee47d 3817 };
41408c28 3818
41408c28 3819The start address of the memory region has to be specified in the "gaddr"
b4d863c3
CH
3820field, and the length of the region in the "size" field (which must not
3821be 0). The maximum value for "size" can be obtained by checking the
3822KVM_CAP_S390_MEM_OP capability. "buf" is the buffer supplied by the
3823userspace application where the read data should be written to for
5e35d0eb
JSG
3824a read access, or where the data that should be written is stored for
3825a write access. The "reserved" field is meant for future extensions.
3826Reserved and unused values are ignored. Future extension that add members must
3827introduce new flags.
3828
3829The type of operation is specified in the "op" field. Flags modifying
3830their behavior can be set in the "flags" field. Undefined flag bits must
3831be set to 0.
3832
3833Possible operations are:
3834 * ``KVM_S390_MEMOP_LOGICAL_READ``
3835 * ``KVM_S390_MEMOP_LOGICAL_WRITE``
3836 * ``KVM_S390_MEMOP_ABSOLUTE_READ``
3837 * ``KVM_S390_MEMOP_ABSOLUTE_WRITE``
3838 * ``KVM_S390_MEMOP_SIDA_READ``
3839 * ``KVM_S390_MEMOP_SIDA_WRITE``
a7b04173 3840 * ``KVM_S390_MEMOP_ABSOLUTE_CMPXCHG``
5e35d0eb
JSG
3841
3842Logical read/write:
3843^^^^^^^^^^^^^^^^^^^
3844
3845Access logical memory, i.e. translate the given guest address to an absolute
3846address given the state of the VCPU and use the absolute address as target of
3847the access. "ar" designates the access register number to be used; the valid
3848range is 0..15.
3849Logical accesses are permitted for the VCPU ioctl only.
3850Logical accesses are permitted for non-protected guests only.
3851
3852Supported flags:
3853 * ``KVM_S390_MEMOP_F_CHECK_ONLY``
3854 * ``KVM_S390_MEMOP_F_INJECT_EXCEPTION``
3855 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION``
3856
3857The KVM_S390_MEMOP_F_CHECK_ONLY flag can be set to check whether the
3858corresponding memory access would cause an access exception; however,
3859no actual access to the data in memory at the destination is performed.
3860In this case, "buf" is unused and can be NULL.
3861
3862In case an access exception occurred during the access (or would occur
3863in case of KVM_S390_MEMOP_F_CHECK_ONLY), the ioctl returns a positive
3864error number indicating the type of exception. This exception is also
3865raised directly at the corresponding VCPU if the flag
3866KVM_S390_MEMOP_F_INJECT_EXCEPTION is set.
c783631b
JSG
3867On protection exceptions, unless specified otherwise, the injected
3868translation-exception identifier (TEID) indicates suppression.
5e35d0eb
JSG
3869
3870If the KVM_S390_MEMOP_F_SKEY_PROTECTION flag is set, storage key
3871protection is also in effect and may cause exceptions if accesses are
cbf9b810 3872prohibited given the access key designated by "key"; the valid range is 0..15.
5e35d0eb
JSG
3873KVM_S390_MEMOP_F_SKEY_PROTECTION is available if KVM_CAP_S390_MEM_OP_EXTENSION
3874is > 0.
c783631b
JSG
3875Since the accessed memory may span multiple pages and those pages might have
3876different storage keys, it is possible that a protection exception occurs
3877after memory has been modified. In this case, if the exception is injected,
3878the TEID does not indicate suppression.
5e35d0eb
JSG
3879
3880Absolute read/write:
3881^^^^^^^^^^^^^^^^^^^^
3882
3883Access absolute memory. This operation is intended to be used with the
3884KVM_S390_MEMOP_F_SKEY_PROTECTION flag, to allow accessing memory and performing
3885the checks required for storage key protection as one operation (as opposed to
3886user space getting the storage keys, performing the checks, and accessing
3887memory thereafter, which could lead to a delay between check and access).
3888Absolute accesses are permitted for the VM ioctl if KVM_CAP_S390_MEM_OP_EXTENSION
a7b04173 3889has the KVM_S390_MEMOP_EXTENSION_CAP_BASE bit set.
5e35d0eb
JSG
3890Currently absolute accesses are not permitted for VCPU ioctls.
3891Absolute accesses are permitted for non-protected guests only.
3892
3893Supported flags:
3894 * ``KVM_S390_MEMOP_F_CHECK_ONLY``
3895 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION``
3896
a7b04173
JSG
3897The semantics of the flags common with logical accesses are as for logical
3898accesses.
3899
3900Absolute cmpxchg:
3901^^^^^^^^^^^^^^^^^
3902
3903Perform cmpxchg on absolute guest memory. Intended for use with the
3904KVM_S390_MEMOP_F_SKEY_PROTECTION flag.
3905Instead of doing an unconditional write, the access occurs only if the target
3906location contains the value pointed to by "old_addr".
3907This is performed as an atomic cmpxchg with the length specified by the "size"
3908parameter. "size" must be a power of two up to and including 16.
3909If the exchange did not take place because the target value doesn't match the
3910old value, the value "old_addr" points to is replaced by the target value.
3911User space can tell if an exchange took place by checking if this replacement
3912occurred. The cmpxchg op is permitted for the VM ioctl if
3913KVM_CAP_S390_MEM_OP_EXTENSION has flag KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG set.
3914
3915Supported flags:
3916 * ``KVM_S390_MEMOP_F_SKEY_PROTECTION``
5e35d0eb
JSG
3917
3918SIDA read/write:
3919^^^^^^^^^^^^^^^^
3920
3921Access the secure instruction data area which contains memory operands necessary
3922for instruction emulation for protected guests.
3923SIDA accesses are available if the KVM_CAP_S390_PROTECTED capability is available.
3924SIDA accesses are permitted for the VCPU ioctl only.
3925SIDA accesses are permitted for protected guests only.
41408c28 3926
5e35d0eb 3927No flags are supported.
41408c28 3928
30ee2a98 39294.90 KVM_S390_GET_SKEYS
106ee47d 3930-----------------------
30ee2a98 3931
106ee47d
MCC
3932:Capability: KVM_CAP_S390_SKEYS
3933:Architectures: s390
3934:Type: vm ioctl
3935:Parameters: struct kvm_s390_skeys
49ae248b 3936:Returns: 0 on success, KVM_S390_GET_SKEYS_NONE if guest is not using storage
106ee47d 3937 keys, negative value on error
30ee2a98
JH
3938
3939This ioctl is used to get guest storage key values on the s390
106ee47d 3940architecture. The ioctl takes parameters via the kvm_s390_skeys struct::
30ee2a98 3941
106ee47d 3942 struct kvm_s390_skeys {
30ee2a98
JH
3943 __u64 start_gfn;
3944 __u64 count;
3945 __u64 skeydata_addr;
3946 __u32 flags;
3947 __u32 reserved[9];
106ee47d 3948 };
30ee2a98
JH
3949
3950The start_gfn field is the number of the first guest frame whose storage keys
3951you want to get.
3952
3953The count field is the number of consecutive frames (starting from start_gfn)
3954whose storage keys to get. The count field must be at least 1 and the maximum
49ae248b 3955allowed value is defined as KVM_S390_SKEYS_MAX. Values outside this range
30ee2a98
JH
3956will cause the ioctl to return -EINVAL.
3957
3958The skeydata_addr field is the address to a buffer large enough to hold count
3959bytes. This buffer will be filled with storage key data by the ioctl.
3960
39614.91 KVM_S390_SET_SKEYS
106ee47d 3962-----------------------
30ee2a98 3963
106ee47d
MCC
3964:Capability: KVM_CAP_S390_SKEYS
3965:Architectures: s390
3966:Type: vm ioctl
3967:Parameters: struct kvm_s390_skeys
3968:Returns: 0 on success, negative value on error
30ee2a98
JH
3969
3970This ioctl is used to set guest storage key values on the s390
3971architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
3972See section on KVM_S390_GET_SKEYS for struct definition.
3973
3974The start_gfn field is the number of the first guest frame whose storage keys
3975you want to set.
3976
3977The count field is the number of consecutive frames (starting from start_gfn)
3978whose storage keys to get. The count field must be at least 1 and the maximum
49ae248b 3979allowed value is defined as KVM_S390_SKEYS_MAX. Values outside this range
30ee2a98
JH
3980will cause the ioctl to return -EINVAL.
3981
3982The skeydata_addr field is the address to a buffer containing count bytes of
3983storage keys. Each byte in the buffer will be set as the storage key for a
3984single frame starting at start_gfn for count frames.
3985
3986Note: If any architecturally invalid key value is found in the given data then
3987the ioctl will return -EINVAL.
3988
47b43c52 39894.92 KVM_S390_IRQ
106ee47d
MCC
3990-----------------
3991
3992:Capability: KVM_CAP_S390_INJECT_IRQ
3993:Architectures: s390
3994:Type: vcpu ioctl
3995:Parameters: struct kvm_s390_irq (in)
3996:Returns: 0 on success, -1 on error
47b43c52 3997
47b43c52 3998Errors:
106ee47d
MCC
3999
4000
4001 ====== =================================================================
4002 EINVAL interrupt type is invalid
4003 type is KVM_S390_SIGP_STOP and flag parameter is invalid value,
47b43c52 4004 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
106ee47d
MCC
4005 than the maximum of VCPUs
4006 EBUSY type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped,
4007 type is KVM_S390_SIGP_STOP and a stop irq is already pending,
47b43c52 4008 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
106ee47d
MCC
4009 is already pending
4010 ====== =================================================================
47b43c52
JF
4011
4012Allows to inject an interrupt to the guest.
4013
4014Using struct kvm_s390_irq as a parameter allows
4015to inject additional payload which is not
4016possible via KVM_S390_INTERRUPT.
4017
106ee47d 4018Interrupt parameters are passed via kvm_s390_irq::
47b43c52 4019
106ee47d 4020 struct kvm_s390_irq {
47b43c52
JF
4021 __u64 type;
4022 union {
4023 struct kvm_s390_io_info io;
4024 struct kvm_s390_ext_info ext;
4025 struct kvm_s390_pgm_info pgm;
4026 struct kvm_s390_emerg_info emerg;
4027 struct kvm_s390_extcall_info extcall;
4028 struct kvm_s390_prefix_info prefix;
4029 struct kvm_s390_stop_info stop;
4030 struct kvm_s390_mchk_info mchk;
4031 char reserved[64];
4032 } u;
106ee47d 4033 };
47b43c52
JF
4034
4035type can be one of the following:
4036
106ee47d
MCC
4037- KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
4038- KVM_S390_PROGRAM_INT - program check; parameters in .pgm
4039- KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
4040- KVM_S390_RESTART - restart; no parameters
4041- KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
4042- KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
4043- KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
4044- KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
4045- KVM_S390_MCHK - machine check interrupt; parameters in .mchk
47b43c52 4046
5e124900 4047This is an asynchronous vcpu ioctl and can be invoked from any thread.
47b43c52 4048
816c7667 40494.94 KVM_S390_GET_IRQ_STATE
106ee47d 4050---------------------------
816c7667 4051
106ee47d
MCC
4052:Capability: KVM_CAP_S390_IRQ_STATE
4053:Architectures: s390
4054:Type: vcpu ioctl
4055:Parameters: struct kvm_s390_irq_state (out)
4056:Returns: >= number of bytes copied into buffer,
4057 -EINVAL if buffer size is 0,
4058 -ENOBUFS if buffer size is too small to fit all pending interrupts,
4059 -EFAULT if the buffer address was invalid
816c7667
JF
4060
4061This ioctl allows userspace to retrieve the complete state of all currently
4062pending interrupts in a single buffer. Use cases include migration
4063and introspection. The parameter structure contains the address of a
106ee47d 4064userspace buffer and its length::
816c7667 4065
106ee47d 4066 struct kvm_s390_irq_state {
816c7667 4067 __u64 buf;
bb64da9a 4068 __u32 flags; /* will stay unused for compatibility reasons */
816c7667 4069 __u32 len;
bb64da9a 4070 __u32 reserved[4]; /* will stay unused for compatibility reasons */
106ee47d 4071 };
816c7667
JF
4072
4073Userspace passes in the above struct and for each pending interrupt a
4074struct kvm_s390_irq is copied to the provided buffer.
4075
bb64da9a
CB
4076The structure contains a flags and a reserved field for future extensions. As
4077the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
4078reserved, these fields can not be used in the future without breaking
4079compatibility.
4080
816c7667
JF
4081If -ENOBUFS is returned the buffer provided was too small and userspace
4082may retry with a bigger buffer.
4083
40844.95 KVM_S390_SET_IRQ_STATE
106ee47d
MCC
4085---------------------------
4086
4087:Capability: KVM_CAP_S390_IRQ_STATE
4088:Architectures: s390
4089:Type: vcpu ioctl
4090:Parameters: struct kvm_s390_irq_state (in)
4091:Returns: 0 on success,
4092 -EFAULT if the buffer address was invalid,
4093 -EINVAL for an invalid buffer length (see below),
4094 -EBUSY if there were already interrupts pending,
4095 errors occurring when actually injecting the
816c7667
JF
4096 interrupt. See KVM_S390_IRQ.
4097
4098This ioctl allows userspace to set the complete state of all cpu-local
4099interrupts currently pending for the vcpu. It is intended for restoring
4100interrupt state after a migration. The input parameter is a userspace buffer
106ee47d 4101containing a struct kvm_s390_irq_state::
816c7667 4102
106ee47d 4103 struct kvm_s390_irq_state {
816c7667 4104 __u64 buf;
bb64da9a 4105 __u32 flags; /* will stay unused for compatibility reasons */
816c7667 4106 __u32 len;
bb64da9a 4107 __u32 reserved[4]; /* will stay unused for compatibility reasons */
106ee47d 4108 };
816c7667 4109
bb64da9a
CB
4110The restrictions for flags and reserved apply as well.
4111(see KVM_S390_GET_IRQ_STATE)
4112
816c7667
JF
4113The userspace memory referenced by buf contains a struct kvm_s390_irq
4114for each interrupt to be injected into the guest.
4115If one of the interrupts could not be injected for some reason the
4116ioctl aborts.
4117
4118len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
4119and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
4120which is the maximum number of possibly pending cpu-local interrupts.
47b43c52 4121
ed8e5a24 41224.96 KVM_SMI
106ee47d 4123------------
f077825a 4124
106ee47d
MCC
4125:Capability: KVM_CAP_X86_SMM
4126:Architectures: x86
4127:Type: vcpu ioctl
4128:Parameters: none
4129:Returns: 0 on success, -1 on error
f077825a
PB
4130
4131Queues an SMI on the thread's vcpu.
4132
24e7475f
EGE
41334.97 KVM_X86_SET_MSR_FILTER
4134----------------------------
d3695aa4 4135
b5cb32b1 4136:Capability: KVM_CAP_X86_MSR_FILTER
24e7475f
EGE
4137:Architectures: x86
4138:Type: vm ioctl
4139:Parameters: struct kvm_msr_filter
4140:Returns: 0 on success, < 0 on error
d3695aa4 4141
24e7475f 4142::
d3695aa4 4143
24e7475f
EGE
4144 struct kvm_msr_filter_range {
4145 #define KVM_MSR_FILTER_READ (1 << 0)
4146 #define KVM_MSR_FILTER_WRITE (1 << 1)
4147 __u32 flags;
4148 __u32 nmsrs; /* number of msrs in bitmap */
4149 __u32 base; /* MSR index the bitmap starts at */
4150 __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
4151 };
d3695aa4 4152
24e7475f
EGE
4153 #define KVM_MSR_FILTER_MAX_RANGES 16
4154 struct kvm_msr_filter {
4155 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
4156 #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0)
4157 __u32 flags;
4158 struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
4159 };
d3695aa4 4160
24e7475f
EGE
4161flags values for ``struct kvm_msr_filter_range``:
4162
4163``KVM_MSR_FILTER_READ``
4164
4165 Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap
b93d2ec3
SC
4166 indicates that read accesses should be denied, while a 1 indicates that
4167 a read for a particular MSR should be allowed regardless of the default
24e7475f
EGE
4168 filter action.
4169
4170``KVM_MSR_FILTER_WRITE``
4171
4172 Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap
b93d2ec3
SC
4173 indicates that write accesses should be denied, while a 1 indicates that
4174 a write for a particular MSR should be allowed regardless of the default
24e7475f
EGE
4175 filter action.
4176
24e7475f
EGE
4177flags values for ``struct kvm_msr_filter``:
4178
4179``KVM_MSR_FILTER_DEFAULT_ALLOW``
4180
4181 If no filter range matches an MSR index that is getting accessed, KVM will
b93d2ec3 4182 allow accesses to all MSRs by default.
24e7475f
EGE
4183
4184``KVM_MSR_FILTER_DEFAULT_DENY``
4185
4186 If no filter range matches an MSR index that is getting accessed, KVM will
b93d2ec3 4187 deny accesses to all MSRs by default.
24e7475f 4188
b93d2ec3
SC
4189This ioctl allows userspace to define up to 16 bitmaps of MSR ranges to deny
4190guest MSR accesses that would normally be allowed by KVM. If an MSR is not
4191covered by a specific range, the "default" filtering behavior applies. Each
4192bitmap range covers MSRs from [base .. base+nmsrs).
24e7475f 4193
b93d2ec3
SC
4194If an MSR access is denied by userspace, the resulting KVM behavior depends on
4195whether or not KVM_CAP_X86_USER_SPACE_MSR's KVM_MSR_EXIT_REASON_FILTER is
4196enabled. If KVM_MSR_EXIT_REASON_FILTER is enabled, KVM will exit to userspace
4197on denied accesses, i.e. userspace effectively intercepts the MSR access. If
4198KVM_MSR_EXIT_REASON_FILTER is not enabled, KVM will inject a #GP into the guest
4199on denied accesses.
24e7475f 4200
b93d2ec3
SC
4201If an MSR access is allowed by userspace, KVM will emulate and/or virtualize
4202the access in accordance with the vCPU model. Note, KVM may still ultimately
4203inject a #GP if an access is allowed by userspace, e.g. if KVM doesn't support
4204the MSR, or to follow architectural behavior for the MSR.
4205
4206By default, KVM operates in KVM_MSR_FILTER_DEFAULT_ALLOW mode with no MSR range
4207filters.
24e7475f
EGE
4208
4209Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR
4210filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes
4211an error.
4212
ce2f72e2 4213.. warning::
b93d2ec3 4214 MSR accesses as part of nested VM-Enter/VM-Exit are not filtered.
ce2f72e2
PB
4215 This includes both writes to individual VMCS fields and reads/writes
4216 through the MSR lists pointed to by the VMCS.
4217
b93d2ec3
SC
4218 x2APIC MSR accesses cannot be filtered (KVM silently ignores filters that
4219 cover any x2APIC MSRs).
24e7475f 4220
b5cb32b1
AL
4221Note, invoking this ioctl while a vCPU is running is inherently racy. However,
4222KVM does guarantee that vCPUs will see either the previous filter or the new
4223filter, e.g. MSRs with identical settings in both the old and new filter will
4224have deterministic behavior.
d3695aa4 4225
b93d2ec3
SC
4226Similarly, if userspace wishes to intercept on denied accesses,
4227KVM_MSR_EXIT_REASON_FILTER must be enabled before activating any filters, and
4228left enabled until after all filters are deactivated. Failure to do so may
4229result in KVM injecting a #GP instead of exiting to userspace.
4230
58ded420 42314.98 KVM_CREATE_SPAPR_TCE_64
106ee47d 4232----------------------------
58ded420 4233
106ee47d
MCC
4234:Capability: KVM_CAP_SPAPR_TCE_64
4235:Architectures: powerpc
4236:Type: vm ioctl
4237:Parameters: struct kvm_create_spapr_tce_64 (in)
4238:Returns: file descriptor for manipulating the created TCE table
58ded420
AK
4239
4240This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
4241windows, described in 4.62 KVM_CREATE_SPAPR_TCE
4242
106ee47d 4243This capability uses extended struct in ioctl interface::
58ded420 4244
106ee47d
MCC
4245 /* for KVM_CAP_SPAPR_TCE_64 */
4246 struct kvm_create_spapr_tce_64 {
58ded420
AK
4247 __u64 liobn;
4248 __u32 page_shift;
4249 __u32 flags;
4250 __u64 offset; /* in pages */
4251 __u64 size; /* in pages */
106ee47d 4252 };
58ded420
AK
4253
4254The aim of extension is to support an additional bigger DMA window with
4255a variable page size.
4256KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
4257a bus offset of the corresponding DMA window, @size and @offset are numbers
4258of IOMMU pages.
4259
4260@flags are not used at the moment.
4261
4262The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
4263
ccc4df4e 42644.99 KVM_REINJECT_CONTROL
106ee47d 4265-------------------------
107d44a2 4266
106ee47d
MCC
4267:Capability: KVM_CAP_REINJECT_CONTROL
4268:Architectures: x86
4269:Type: vm ioctl
4270:Parameters: struct kvm_reinject_control (in)
4271:Returns: 0 on success,
107d44a2
RK
4272 -EFAULT if struct kvm_reinject_control cannot be read,
4273 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
4274
4275i8254 (PIT) has two modes, reinject and !reinject. The default is reinject,
4276where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
4277vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its
4278interrupt whenever there isn't a pending interrupt from i8254.
4279!reinject mode injects an interrupt as soon as a tick arrives.
4280
106ee47d
MCC
4281::
4282
4283 struct kvm_reinject_control {
107d44a2
RK
4284 __u8 pit_reinject;
4285 __u8 reserved[31];
106ee47d 4286 };
107d44a2
RK
4287
4288pit_reinject = 0 (!reinject mode) is recommended, unless running an old
4289operating system that uses the PIT for timing (e.g. Linux 2.4.x).
4290
ccc4df4e 42914.100 KVM_PPC_CONFIGURE_V3_MMU
106ee47d 4292------------------------------
c9270132 4293
106ee47d
MCC
4294:Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
4295:Architectures: ppc
4296:Type: vm ioctl
4297:Parameters: struct kvm_ppc_mmuv3_cfg (in)
4298:Returns: 0 on success,
c9270132
PM
4299 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
4300 -EINVAL if the configuration is invalid
4301
4302This ioctl controls whether the guest will use radix or HPT (hashed
4303page table) translation, and sets the pointer to the process table for
4304the guest.
4305
106ee47d
MCC
4306::
4307
4308 struct kvm_ppc_mmuv3_cfg {
c9270132
PM
4309 __u64 flags;
4310 __u64 process_table;
106ee47d 4311 };
c9270132
PM
4312
4313There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
4314KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest
4315to use radix tree translation, and if clear, to use HPT translation.
4316KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
4317to be able to use the global TLB and SLB invalidation instructions;
4318if clear, the guest may not use these instructions.
4319
4320The process_table field specifies the address and size of the guest
4321process table, which is in the guest's space. This field is formatted
4322as the second doubleword of the partition table entry, as defined in
4323the Power ISA V3.00, Book III section 5.7.6.1.
4324
ccc4df4e 43254.101 KVM_PPC_GET_RMMU_INFO
106ee47d 4326---------------------------
c9270132 4327
106ee47d
MCC
4328:Capability: KVM_CAP_PPC_RADIX_MMU
4329:Architectures: ppc
4330:Type: vm ioctl
4331:Parameters: struct kvm_ppc_rmmu_info (out)
4332:Returns: 0 on success,
c9270132
PM
4333 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
4334 -EINVAL if no useful information can be returned
4335
4336This ioctl returns a structure containing two things: (a) a list
4337containing supported radix tree geometries, and (b) a list that maps
4338page sizes to put in the "AP" (actual page size) field for the tlbie
4339(TLB invalidate entry) instruction.
4340
106ee47d
MCC
4341::
4342
4343 struct kvm_ppc_rmmu_info {
c9270132
PM
4344 struct kvm_ppc_radix_geom {
4345 __u8 page_shift;
4346 __u8 level_bits[4];
4347 __u8 pad[3];
4348 } geometries[8];
4349 __u32 ap_encodings[8];
106ee47d 4350 };
c9270132
PM
4351
4352The geometries[] field gives up to 8 supported geometries for the
4353radix page table, in terms of the log base 2 of the smallest page
4354size, and the number of bits indexed at each level of the tree, from
4355the PTE level up to the PGD level in that order. Any unused entries
4356will have 0 in the page_shift field.
4357
4358The ap_encodings gives the supported page sizes and their AP field
4359encodings, encoded with the AP value in the top 3 bits and the log
4360base 2 of the page size in the bottom 6 bits.
4361
ef1ead0c 43624.102 KVM_PPC_RESIZE_HPT_PREPARE
106ee47d 4363--------------------------------
ef1ead0c 4364
106ee47d
MCC
4365:Capability: KVM_CAP_SPAPR_RESIZE_HPT
4366:Architectures: powerpc
4367:Type: vm ioctl
4368:Parameters: struct kvm_ppc_resize_hpt (in)
4369:Returns: 0 on successful completion,
ef1ead0c 4370 >0 if a new HPT is being prepared, the value is an estimated
106ee47d 4371 number of milliseconds until preparation is complete,
ef1ead0c 4372 -EFAULT if struct kvm_reinject_control cannot be read,
106ee47d
MCC
4373 -EINVAL if the supplied shift or flags are invalid,
4374 -ENOMEM if unable to allocate the new HPT,
ef1ead0c
DG
4375
4376Used to implement the PAPR extension for runtime resizing of a guest's
4377Hashed Page Table (HPT). Specifically this starts, stops or monitors
4378the preparation of a new potential HPT for the guest, essentially
4379implementing the H_RESIZE_HPT_PREPARE hypercall.
4380
e2a0fcac
PB
4381::
4382
4383 struct kvm_ppc_resize_hpt {
4384 __u64 flags;
4385 __u32 shift;
4386 __u32 pad;
4387 };
4388
ef1ead0c
DG
4389If called with shift > 0 when there is no pending HPT for the guest,
4390this begins preparation of a new pending HPT of size 2^(shift) bytes.
4391It then returns a positive integer with the estimated number of
4392milliseconds until preparation is complete.
4393
4394If called when there is a pending HPT whose size does not match that
4395requested in the parameters, discards the existing pending HPT and
4396creates a new one as above.
4397
4398If called when there is a pending HPT of the size requested, will:
106ee47d 4399
ef1ead0c
DG
4400 * If preparation of the pending HPT is already complete, return 0
4401 * If preparation of the pending HPT has failed, return an error
4402 code, then discard the pending HPT.
4403 * If preparation of the pending HPT is still in progress, return an
4404 estimated number of milliseconds until preparation is complete.
4405
4406If called with shift == 0, discards any currently pending HPT and
4407returns 0 (i.e. cancels any in-progress preparation).
4408
4409flags is reserved for future expansion, currently setting any bits in
4410flags will result in an -EINVAL.
4411
4412Normally this will be called repeatedly with the same parameters until
4413it returns <= 0. The first call will initiate preparation, subsequent
4414ones will monitor preparation until it completes or fails.
4415
ef1ead0c 44164.103 KVM_PPC_RESIZE_HPT_COMMIT
106ee47d 4417-------------------------------
ef1ead0c 4418
106ee47d
MCC
4419:Capability: KVM_CAP_SPAPR_RESIZE_HPT
4420:Architectures: powerpc
4421:Type: vm ioctl
4422:Parameters: struct kvm_ppc_resize_hpt (in)
4423:Returns: 0 on successful completion,
ef1ead0c 4424 -EFAULT if struct kvm_reinject_control cannot be read,
106ee47d 4425 -EINVAL if the supplied shift or flags are invalid,
ef1ead0c 4426 -ENXIO is there is no pending HPT, or the pending HPT doesn't
106ee47d
MCC
4427 have the requested size,
4428 -EBUSY if the pending HPT is not fully prepared,
ef1ead0c 4429 -ENOSPC if there was a hash collision when moving existing
106ee47d 4430 HPT entries to the new HPT,
ef1ead0c
DG
4431 -EIO on other error conditions
4432
4433Used to implement the PAPR extension for runtime resizing of a guest's
4434Hashed Page Table (HPT). Specifically this requests that the guest be
4435transferred to working with the new HPT, essentially implementing the
4436H_RESIZE_HPT_COMMIT hypercall.
4437
e2a0fcac
PB
4438::
4439
4440 struct kvm_ppc_resize_hpt {
4441 __u64 flags;
4442 __u32 shift;
4443 __u32 pad;
4444 };
4445
ef1ead0c
DG
4446This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
4447returned 0 with the same parameters. In other cases
4448KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
4449-EBUSY, though others may be possible if the preparation was started,
4450but failed).
4451
4452This will have undefined effects on the guest if it has not already
4453placed itself in a quiescent state where no vcpu will make MMU enabled
4454memory accesses.
4455
57f33f1a 4456On successful completion, the pending HPT will become the guest's active
ef1ead0c
DG
4457HPT and the previous HPT will be discarded.
4458
4459On failure, the guest will still be operating on its previous HPT.
4460
3aa53859 44614.104 KVM_X86_GET_MCE_CAP_SUPPORTED
106ee47d 4462-----------------------------------
3aa53859 4463
106ee47d
MCC
4464:Capability: KVM_CAP_MCE
4465:Architectures: x86
4466:Type: system ioctl
4467:Parameters: u64 mce_cap (out)
4468:Returns: 0 on success, -1 on error
3aa53859
LC
4469
4470Returns supported MCE capabilities. The u64 mce_cap parameter
4471has the same format as the MSR_IA32_MCG_CAP register. Supported
4472capabilities will have the corresponding bits set.
4473
44744.105 KVM_X86_SETUP_MCE
106ee47d 4475-----------------------
3aa53859 4476
106ee47d
MCC
4477:Capability: KVM_CAP_MCE
4478:Architectures: x86
4479:Type: vcpu ioctl
4480:Parameters: u64 mcg_cap (in)
4481:Returns: 0 on success,
3aa53859
LC
4482 -EFAULT if u64 mcg_cap cannot be read,
4483 -EINVAL if the requested number of banks is invalid,
4484 -EINVAL if requested MCE capability is not supported.
4485
4486Initializes MCE support for use. The u64 mcg_cap parameter
4487has the same format as the MSR_IA32_MCG_CAP register and
4488specifies which capabilities should be enabled. The maximum
4489supported number of error-reporting banks can be retrieved when
4490checking for KVM_CAP_MCE. The supported capabilities can be
4491retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
4492
44934.106 KVM_X86_SET_MCE
106ee47d 4494---------------------
3aa53859 4495
106ee47d
MCC
4496:Capability: KVM_CAP_MCE
4497:Architectures: x86
4498:Type: vcpu ioctl
4499:Parameters: struct kvm_x86_mce (in)
4500:Returns: 0 on success,
3aa53859
LC
4501 -EFAULT if struct kvm_x86_mce cannot be read,
4502 -EINVAL if the bank number is invalid,
4503 -EINVAL if VAL bit is not set in status field.
4504
4505Inject a machine check error (MCE) into the guest. The input
106ee47d 4506parameter is::
3aa53859 4507
106ee47d 4508 struct kvm_x86_mce {
3aa53859
LC
4509 __u64 status;
4510 __u64 addr;
4511 __u64 misc;
4512 __u64 mcg_status;
4513 __u8 bank;
4514 __u8 pad1[7];
4515 __u64 pad2[3];
106ee47d 4516 };
3aa53859
LC
4517
4518If the MCE being reported is an uncorrected error, KVM will
4519inject it as an MCE exception into the guest. If the guest
4520MCG_STATUS register reports that an MCE is in progress, KVM
4521causes an KVM_EXIT_SHUTDOWN vmexit.
4522
4523Otherwise, if the MCE is a corrected error, KVM will just
4524store it in the corresponding bank (provided this bank is
4525not holding a previously reported uncorrected error).
4526
4036e387 45274.107 KVM_S390_GET_CMMA_BITS
106ee47d 4528----------------------------
4036e387 4529
106ee47d
MCC
4530:Capability: KVM_CAP_S390_CMMA_MIGRATION
4531:Architectures: s390
4532:Type: vm ioctl
4533:Parameters: struct kvm_s390_cmma_log (in, out)
4534:Returns: 0 on success, a negative value on error
4036e387 4535
f2d3155e
NB
4536Errors:
4537
4538 ====== =============================================================
4539 ENOMEM not enough memory can be allocated to complete the task
4540 ENXIO if CMMA is not enabled
4541 EINVAL if KVM_S390_CMMA_PEEK is not set but migration mode was not enabled
4542 EINVAL if KVM_S390_CMMA_PEEK is not set but dirty tracking has been
4543 disabled (and thus migration mode was automatically disabled)
4544 EFAULT if the userspace address is invalid or if no page table is
4545 present for the addresses (e.g. when using hugepages).
4546 ====== =============================================================
4547
4036e387
CI
4548This ioctl is used to get the values of the CMMA bits on the s390
4549architecture. It is meant to be used in two scenarios:
106ee47d 4550
4036e387
CI
4551- During live migration to save the CMMA values. Live migration needs
4552 to be enabled via the KVM_REQ_START_MIGRATION VM property.
4553- To non-destructively peek at the CMMA values, with the flag
4554 KVM_S390_CMMA_PEEK set.
4555
4556The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
4557values are written to a buffer whose location is indicated via the "values"
4558member in the kvm_s390_cmma_log struct. The values in the input struct are
4559also updated as needed.
106ee47d 4560
4036e387
CI
4561Each CMMA value takes up one byte.
4562
106ee47d
MCC
4563::
4564
4565 struct kvm_s390_cmma_log {
4036e387
CI
4566 __u64 start_gfn;
4567 __u32 count;
4568 __u32 flags;
4569 union {
4570 __u64 remaining;
4571 __u64 mask;
4572 };
4573 __u64 values;
106ee47d 4574 };
4036e387
CI
4575
4576start_gfn is the number of the first guest frame whose CMMA values are
4577to be retrieved,
4578
4579count is the length of the buffer in bytes,
4580
4581values points to the buffer where the result will be written to.
4582
4583If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
4584KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
4585other ioctls.
4586
4587The result is written in the buffer pointed to by the field values, and
4588the values of the input parameter are updated as follows.
4589
4590Depending on the flags, different actions are performed. The only
4591supported flag so far is KVM_S390_CMMA_PEEK.
4592
4593The default behaviour if KVM_S390_CMMA_PEEK is not set is:
4594start_gfn will indicate the first page frame whose CMMA bits were dirty.
4595It is not necessarily the same as the one passed as input, as clean pages
4596are skipped.
4597
4598count will indicate the number of bytes actually written in the buffer.
4599It can (and very often will) be smaller than the input value, since the
4600buffer is only filled until 16 bytes of clean values are found (which
4601are then not copied in the buffer). Since a CMMA migration block needs
4602the base address and the length, for a total of 16 bytes, we will send
4603back some clean data if there is some dirty data afterwards, as long as
4604the size of the clean data does not exceed the size of the header. This
4605allows to minimize the amount of data to be saved or transferred over
4606the network at the expense of more roundtrips to userspace. The next
4607invocation of the ioctl will skip over all the clean values, saving
4608potentially more than just the 16 bytes we found.
4609
4610If KVM_S390_CMMA_PEEK is set:
4611the existing storage attributes are read even when not in migration
4612mode, and no other action is performed;
4613
4614the output start_gfn will be equal to the input start_gfn,
4615
4616the output count will be equal to the input count, except if the end of
4617memory has been reached.
4618
4619In both cases:
4620the field "remaining" will indicate the total number of dirty CMMA values
4621still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
4622not enabled.
4623
4624mask is unused.
4625
4626values points to the userspace buffer where the result will be stored.
4627
4036e387 46284.108 KVM_S390_SET_CMMA_BITS
106ee47d 4629----------------------------
4036e387 4630
106ee47d
MCC
4631:Capability: KVM_CAP_S390_CMMA_MIGRATION
4632:Architectures: s390
4633:Type: vm ioctl
4634:Parameters: struct kvm_s390_cmma_log (in)
4635:Returns: 0 on success, a negative value on error
4036e387
CI
4636
4637This ioctl is used to set the values of the CMMA bits on the s390
4638architecture. It is meant to be used during live migration to restore
4639the CMMA values, but there are no restrictions on its use.
4640The ioctl takes parameters via the kvm_s390_cmma_values struct.
4641Each CMMA value takes up one byte.
4642
106ee47d
MCC
4643::
4644
4645 struct kvm_s390_cmma_log {
4036e387
CI
4646 __u64 start_gfn;
4647 __u32 count;
4648 __u32 flags;
4649 union {
4650 __u64 remaining;
4651 __u64 mask;
106ee47d 4652 };
4036e387 4653 __u64 values;
106ee47d 4654 };
4036e387
CI
4655
4656start_gfn indicates the starting guest frame number,
4657
4658count indicates how many values are to be considered in the buffer,
4659
4660flags is not used and must be 0.
4661
4662mask indicates which PGSTE bits are to be considered.
4663
4664remaining is not used.
4665
4666values points to the buffer in userspace where to store the values.
4667
4668This ioctl can fail with -ENOMEM if not enough memory can be allocated to
4669complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
4670the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
4671if the flags field was not 0, with -EFAULT if the userspace address is
4672invalid, if invalid pages are written to (e.g. after the end of memory)
4673or if no page table is present for the addresses (e.g. when using
4674hugepages).
4675
7bf14c28 46764.109 KVM_PPC_GET_CPU_CHAR
106ee47d 4677--------------------------
3214d01f 4678
106ee47d
MCC
4679:Capability: KVM_CAP_PPC_GET_CPU_CHAR
4680:Architectures: powerpc
4681:Type: vm ioctl
4682:Parameters: struct kvm_ppc_cpu_char (out)
4683:Returns: 0 on successful completion,
3214d01f
PM
4684 -EFAULT if struct kvm_ppc_cpu_char cannot be written
4685
4686This ioctl gives userspace information about certain characteristics
4687of the CPU relating to speculative execution of instructions and
4688possible information leakage resulting from speculative execution (see
4689CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is
106ee47d 4690returned in struct kvm_ppc_cpu_char, which looks like this::
3214d01f 4691
106ee47d 4692 struct kvm_ppc_cpu_char {
3214d01f
PM
4693 __u64 character; /* characteristics of the CPU */
4694 __u64 behaviour; /* recommended software behaviour */
4695 __u64 character_mask; /* valid bits in character */
4696 __u64 behaviour_mask; /* valid bits in behaviour */
106ee47d 4697 };
3214d01f
PM
4698
4699For extensibility, the character_mask and behaviour_mask fields
4700indicate which bits of character and behaviour have been filled in by
4701the kernel. If the set of defined bits is extended in future then
4702userspace will be able to tell whether it is running on a kernel that
4703knows about the new bits.
4704
4705The character field describes attributes of the CPU which can help
4706with preventing inadvertent information disclosure - specifically,
4707whether there is an instruction to flash-invalidate the L1 data cache
4708(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
4709to a mode where entries can only be used by the thread that created
4710them, whether the bcctr[l] instruction prevents speculation, and
4711whether a speculation barrier instruction (ori 31,31,0) is provided.
4712
4713The behaviour field describes actions that software should take to
4714prevent inadvertent information disclosure, and thus describes which
4715vulnerabilities the hardware is subject to; specifically whether the
4716L1 data cache should be flushed when returning to user mode from the
4717kernel, and whether a speculation barrier should be placed between an
4718array bounds check and the array access.
4719
4720These fields use the same bit definitions as the new
4721H_GET_CPU_CHARACTERISTICS hypercall.
4722
7bf14c28 47234.110 KVM_MEMORY_ENCRYPT_OP
106ee47d 4724---------------------------
5acc5c06 4725
106ee47d
MCC
4726:Capability: basic
4727:Architectures: x86
46ca9ee5 4728:Type: vm
106ee47d
MCC
4729:Parameters: an opaque platform specific structure (in/out)
4730:Returns: 0 on success; -1 on error
5acc5c06
BS
4731
4732If the platform supports creating encrypted VMs then this ioctl can be used
4733for issuing platform-specific memory encryption commands to manage those
4734encrypted VMs.
4735
4736Currently, this ioctl is used for issuing Secure Encrypted Virtualization
4737(SEV) commands on AMD Processors. The SEV commands are defined in
7ac3945d 4738Documentation/virt/kvm/x86/amd-memory-encryption.rst.
5acc5c06 4739
7bf14c28 47404.111 KVM_MEMORY_ENCRYPT_REG_REGION
106ee47d 4741-----------------------------------
69eaedee 4742
106ee47d
MCC
4743:Capability: basic
4744:Architectures: x86
4745:Type: system
4746:Parameters: struct kvm_enc_region (in)
4747:Returns: 0 on success; -1 on error
69eaedee
BS
4748
4749This ioctl can be used to register a guest memory region which may
4750contain encrypted data (e.g. guest RAM, SMRAM etc).
4751
4752It is used in the SEV-enabled guest. When encryption is enabled, a guest
4753memory region may contain encrypted data. The SEV memory encryption
4754engine uses a tweak such that two identical plaintext pages, each at
4755different locations will have differing ciphertexts. So swapping or
4756moving ciphertext of those pages will not result in plaintext being
4757swapped. So relocating (or migrating) physical backing pages for the SEV
4758guest will require some additional steps.
4759
4760Note: The current SEV key management spec does not provide commands to
4761swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
4762memory region registered with the ioctl.
4763
7bf14c28 47644.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
106ee47d 4765-------------------------------------
69eaedee 4766
106ee47d
MCC
4767:Capability: basic
4768:Architectures: x86
4769:Type: system
4770:Parameters: struct kvm_enc_region (in)
4771:Returns: 0 on success; -1 on error
69eaedee
BS
4772
4773This ioctl can be used to unregister the guest memory region registered
4774with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
4775
faeb7833 47764.113 KVM_HYPERV_EVENTFD
106ee47d 4777------------------------
faeb7833 4778
106ee47d
MCC
4779:Capability: KVM_CAP_HYPERV_EVENTFD
4780:Architectures: x86
4781:Type: vm ioctl
4782:Parameters: struct kvm_hyperv_eventfd (in)
faeb7833
RK
4783
4784This ioctl (un)registers an eventfd to receive notifications from the guest on
4785the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
4786causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
4787(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
4788
106ee47d
MCC
4789::
4790
4791 struct kvm_hyperv_eventfd {
faeb7833
RK
4792 __u32 conn_id;
4793 __s32 fd;
4794 __u32 flags;
4795 __u32 padding[3];
106ee47d 4796 };
faeb7833 4797
106ee47d 4798The conn_id field should fit within 24 bits::
faeb7833 4799
106ee47d 4800 #define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
faeb7833 4801
106ee47d 4802The acceptable values for the flags field are::
faeb7833 4803
106ee47d 4804 #define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
faeb7833 4805
106ee47d
MCC
4806:Returns: 0 on success,
4807 -EINVAL if conn_id or flags is outside the allowed range,
4808 -ENOENT on deassign if the conn_id isn't registered,
4809 -EEXIST on assign if the conn_id is already registered
faeb7833 4810
8fcc4b59 48114.114 KVM_GET_NESTED_STATE
106ee47d
MCC
4812--------------------------
4813
4814:Capability: KVM_CAP_NESTED_STATE
4815:Architectures: x86
4816:Type: vcpu ioctl
4817:Parameters: struct kvm_nested_state (in/out)
4818:Returns: 0 on success, -1 on error
8fcc4b59 4819
8fcc4b59 4820Errors:
106ee47d
MCC
4821
4822 ===== =============================================================
4823 E2BIG the total state size exceeds the value of 'size' specified by
8fcc4b59 4824 the user; the size required will be written into size.
106ee47d 4825 ===== =============================================================
8fcc4b59 4826
106ee47d
MCC
4827::
4828
4829 struct kvm_nested_state {
8fcc4b59
JM
4830 __u16 flags;
4831 __u16 format;
4832 __u32 size;
6ca00dfa 4833
8fcc4b59 4834 union {
6ca00dfa
LA
4835 struct kvm_vmx_nested_state_hdr vmx;
4836 struct kvm_svm_nested_state_hdr svm;
4837
4838 /* Pad the header to 128 bytes. */
8fcc4b59 4839 __u8 pad[120];
6ca00dfa
LA
4840 } hdr;
4841
4842 union {
4843 struct kvm_vmx_nested_state_data vmx[0];
4844 struct kvm_svm_nested_state_data svm[0];
4845 } data;
106ee47d 4846 };
8fcc4b59 4847
106ee47d
MCC
4848 #define KVM_STATE_NESTED_GUEST_MODE 0x00000001
4849 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002
4850 #define KVM_STATE_NESTED_EVMCS 0x00000004
8fcc4b59 4851
106ee47d
MCC
4852 #define KVM_STATE_NESTED_FORMAT_VMX 0
4853 #define KVM_STATE_NESTED_FORMAT_SVM 1
8fcc4b59 4854
106ee47d 4855 #define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000
6ca00dfa 4856
106ee47d
MCC
4857 #define KVM_STATE_NESTED_VMX_SMM_GUEST_MODE 0x00000001
4858 #define KVM_STATE_NESTED_VMX_SMM_VMXON 0x00000002
6ca00dfa 4859
3c97f03e 4860 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001
850448f3 4861
106ee47d 4862 struct kvm_vmx_nested_state_hdr {
8fcc4b59 4863 __u64 vmxon_pa;
6ca00dfa 4864 __u64 vmcs12_pa;
8fcc4b59
JM
4865
4866 struct {
4867 __u16 flags;
4868 } smm;
83d31e52
PB
4869
4870 __u32 flags;
4871 __u64 preemption_timer_deadline;
106ee47d 4872 };
8fcc4b59 4873
106ee47d 4874 struct kvm_vmx_nested_state_data {
6ca00dfa
LA
4875 __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
4876 __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
106ee47d 4877 };
6ca00dfa 4878
8fcc4b59
JM
4879This ioctl copies the vcpu's nested virtualization state from the kernel to
4880userspace.
4881
6ca00dfa
LA
4882The maximum size of the state can be retrieved by passing KVM_CAP_NESTED_STATE
4883to the KVM_CHECK_EXTENSION ioctl().
8fcc4b59
JM
4884
48854.115 KVM_SET_NESTED_STATE
106ee47d 4886--------------------------
8fcc4b59 4887
106ee47d
MCC
4888:Capability: KVM_CAP_NESTED_STATE
4889:Architectures: x86
4890:Type: vcpu ioctl
4891:Parameters: struct kvm_nested_state (in)
4892:Returns: 0 on success, -1 on error
8fcc4b59 4893
6ca00dfa
LA
4894This copies the vcpu's kvm_nested_state struct from userspace to the kernel.
4895For the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
7bf14c28 4896
9943450b 48974.116 KVM_(UN)REGISTER_COALESCED_MMIO
106ee47d 4898-------------------------------------
9943450b 4899
106ee47d
MCC
4900:Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio)
4901 KVM_CAP_COALESCED_PIO (for coalesced pio)
4902:Architectures: all
4903:Type: vm ioctl
4904:Parameters: struct kvm_coalesced_mmio_zone
4905:Returns: 0 on success, < 0 on error
9943450b 4906
0804c849 4907Coalesced I/O is a performance optimization that defers hardware
9943450b
PH
4908register write emulation so that userspace exits are avoided. It is
4909typically used to reduce the overhead of emulating frequently accessed
4910hardware registers.
4911
0804c849 4912When a hardware register is configured for coalesced I/O, write accesses
9943450b
PH
4913do not exit to userspace and their value is recorded in a ring buffer
4914that is shared between kernel and userspace.
4915
0804c849 4916Coalesced I/O is used if one or more write accesses to a hardware
9943450b
PH
4917register can be deferred until a read or a write to another hardware
4918register on the same device. This last access will cause a vmexit and
4919userspace will process accesses from the ring buffer before emulating
0804c849
PH
4920it. That will avoid exiting to userspace on repeated writes.
4921
4922Coalesced pio is based on coalesced mmio. There is little difference
4923between coalesced mmio and pio except that coalesced pio records accesses
4924to I/O ports.
9943450b 4925
2a31b9db 49264.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
106ee47d
MCC
4927------------------------------------
4928
4929:Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
3fbf4207 4930:Architectures: x86, arm64, mips
106ee47d 4931:Type: vm ioctl
01ead84c 4932:Parameters: struct kvm_clear_dirty_log (in)
106ee47d 4933:Returns: 0 on success, -1 on error
2a31b9db 4934
106ee47d 4935::
2a31b9db 4936
106ee47d
MCC
4937 /* for KVM_CLEAR_DIRTY_LOG */
4938 struct kvm_clear_dirty_log {
2a31b9db
PB
4939 __u32 slot;
4940 __u32 num_pages;
4941 __u64 first_page;
4942 union {
4943 void __user *dirty_bitmap; /* one bit per page */
4944 __u64 padding;
4945 };
106ee47d 4946 };
2a31b9db
PB
4947
4948The ioctl clears the dirty status of pages in a memory slot, according to
4949the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap
4950field. Bit 0 of the bitmap corresponds to page "first_page" in the
4951memory slot, and num_pages is the size in bits of the input bitmap.
76d58e0f
PB
4952first_page must be a multiple of 64; num_pages must also be a multiple of
495364 unless first_page + num_pages is the size of the memory slot. For each
4954bit that is set in the input bitmap, the corresponding page is marked "clean"
2a31b9db
PB
4955in KVM's dirty bitmap, and dirty tracking is re-enabled for that page
4956(for example via write-protection, or by clearing the dirty bit in
4957a page table entry).
4958
01ead84c
ZY
4959If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
4960the address space for which you want to clear the dirty status. See
4961KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
2a31b9db 4962
d7547c55 4963This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
2a31b9db
PB
4964is enabled; for more information, see the description of the capability.
4965However, it can always be used as long as KVM_CHECK_EXTENSION confirms
d7547c55 4966that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present.
2a31b9db 4967
2bc39970 49684.118 KVM_GET_SUPPORTED_HV_CPUID
106ee47d 4969--------------------------------
2bc39970 4970
c21d54f0 4971:Capability: KVM_CAP_HYPERV_CPUID (vcpu), KVM_CAP_SYS_HYPERV_CPUID (system)
106ee47d 4972:Architectures: x86
c21d54f0 4973:Type: system ioctl, vcpu ioctl
106ee47d
MCC
4974:Parameters: struct kvm_cpuid2 (in/out)
4975:Returns: 0 on success, -1 on error
4976
4977::
2bc39970 4978
106ee47d 4979 struct kvm_cpuid2 {
2bc39970
VK
4980 __u32 nent;
4981 __u32 padding;
4982 struct kvm_cpuid_entry2 entries[0];
106ee47d 4983 };
2bc39970 4984
106ee47d 4985 struct kvm_cpuid_entry2 {
2bc39970
VK
4986 __u32 function;
4987 __u32 index;
4988 __u32 flags;
4989 __u32 eax;
4990 __u32 ebx;
4991 __u32 ecx;
4992 __u32 edx;
4993 __u32 padding[3];
106ee47d 4994 };
2bc39970
VK
4995
4996This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in
4997KVM. Userspace can use the information returned by this ioctl to construct
4998cpuid information presented to guests consuming Hyper-V enlightenments (e.g.
4999Windows or Hyper-V guests).
5000
5001CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level
5002Functional Specification (TLFS). These leaves can't be obtained with
5003KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature
5004leaves (0x40000000, 0x40000001).
5005
5006Currently, the following list of CPUID leaves are returned:
356c7558 5007
106ee47d
MCC
5008 - HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS
5009 - HYPERV_CPUID_INTERFACE
5010 - HYPERV_CPUID_VERSION
5011 - HYPERV_CPUID_FEATURES
5012 - HYPERV_CPUID_ENLIGHTMENT_INFO
5013 - HYPERV_CPUID_IMPLEMENT_LIMITS
5014 - HYPERV_CPUID_NESTED_FEATURES
b44f50d8
VK
5015 - HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS
5016 - HYPERV_CPUID_SYNDBG_INTERFACE
5017 - HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES
2bc39970 5018
b44f50d8 5019Userspace invokes KVM_GET_SUPPORTED_HV_CPUID by passing a kvm_cpuid2 structure
2bc39970
VK
5020with the 'nent' field indicating the number of entries in the variable-size
5021array 'entries'. If the number of entries is too low to describe all Hyper-V
5022feature leaves, an error (E2BIG) is returned. If the number is more or equal
5023to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the
5024number of valid entries in the 'entries' array, which is then filled.
5025
5026'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved,
5027userspace should not expect to get any particular value there.
2a31b9db 5028
c21d54f0
VK
5029Note, vcpu version of KVM_GET_SUPPORTED_HV_CPUID is currently deprecated. Unlike
5030system ioctl which exposes all supported feature bits unconditionally, vcpu
5031version has the following quirks:
356c7558 5032
c21d54f0
VK
5033- HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED
5034 feature bit are only exposed when Enlightened VMCS was previously enabled
5035 on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
5036- HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC.
5037 (presumes KVM_CREATE_IRQCHIP has already been called).
5038
50036ad0 50394.119 KVM_ARM_VCPU_FINALIZE
106ee47d
MCC
5040---------------------------
5041
3fbf4207 5042:Architectures: arm64
106ee47d
MCC
5043:Type: vcpu ioctl
5044:Parameters: int feature (in)
5045:Returns: 0 on success, -1 on error
50036ad0 5046
50036ad0 5047Errors:
106ee47d
MCC
5048
5049 ====== ==============================================================
5050 EPERM feature not enabled, needs configuration, or already finalized
5051 EINVAL feature unknown or not present
5052 ====== ==============================================================
50036ad0
DM
5053
5054Recognised values for feature:
106ee47d
MCC
5055
5056 ===== ===========================================
9df2d660 5057 arm64 KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE)
106ee47d 5058 ===== ===========================================
50036ad0
DM
5059
5060Finalizes the configuration of the specified vcpu feature.
5061
5062The vcpu must already have been initialised, enabling the affected feature, by
5063means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in
5064features[].
5065
5066For affected vcpu features, this is a mandatory step that must be performed
5067before the vcpu is fully usable.
5068
5069Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be
5070configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration
57f33f1a 5071that should be performed and how to do it are feature-dependent.
50036ad0
DM
5072
5073Other calls that depend on a particular feature being finalized, such as
5074KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with
5075-EPERM unless the feature has already been finalized by means of a
5076KVM_ARM_VCPU_FINALIZE call.
5077
5078See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization
5079using this ioctl.
5080
66bb8a06 50814.120 KVM_SET_PMU_EVENT_FILTER
106ee47d 5082------------------------------
66bb8a06 5083
106ee47d
MCC
5084:Capability: KVM_CAP_PMU_EVENT_FILTER
5085:Architectures: x86
5086:Type: vm ioctl
5087:Parameters: struct kvm_pmu_event_filter (in)
5088:Returns: 0 on success, -1 on error
66bb8a06 5089
14329b82
AL
5090Errors:
5091
5092 ====== ============================================================
5093 EFAULT args[0] cannot be accessed
5094 EINVAL args[0] contains invalid data in the filter or filter events
5095 E2BIG nevents is too large
5096 EBUSY not enough memory to allocate the filter
5097 ====== ============================================================
5098
106ee47d
MCC
5099::
5100
5101 struct kvm_pmu_event_filter {
30cd8604
EH
5102 __u32 action;
5103 __u32 nevents;
5104 __u32 fixed_counter_bitmap;
5105 __u32 flags;
5106 __u32 pad[4];
5107 __u64 events[0];
106ee47d 5108 };
66bb8a06 5109
14329b82
AL
5110This ioctl restricts the set of PMU events the guest can program by limiting
5111which event select and unit mask combinations are permitted.
5112
5113The argument holds a list of filter events which will be allowed or denied.
5114
5115Filter events only control general purpose counters; fixed purpose counters
5116are controlled by the fixed_counter_bitmap.
5117
5118Valid values for 'flags'::
5119
5120``0``
5121
5122To use this mode, clear the 'flags' field.
5123
5124In this mode each event will contain an event select + unit mask.
5125
5126When the guest attempts to program the PMU the guest's event select +
5127unit mask is compared against the filter events to determine whether the
5128guest should have access.
5129
5130``KVM_PMU_EVENT_FLAG_MASKED_EVENTS``
5131:Capability: KVM_CAP_PMU_EVENT_MASKED_EVENTS
5132
5133In this mode each filter event will contain an event select, mask, match, and
5134exclude value. To encode a masked event use::
5135
5136 KVM_PMU_ENCODE_MASKED_ENTRY()
5137
5138An encoded event will follow this layout::
5139
5140 Bits Description
5141 ---- -----------
5142 7:0 event select (low bits)
5143 15:8 umask match
5144 31:16 unused
5145 35:32 event select (high bits)
5146 36:54 unused
5147 55 exclude bit
5148 63:56 umask mask
5149
5150When the guest attempts to program the PMU, these steps are followed in
5151determining if the guest should have access:
5152
5153 1. Match the event select from the guest against the filter events.
5154 2. If a match is found, match the guest's unit mask to the mask and match
5155 values of the included filter events.
5156 I.e. (unit mask & mask) == match && !exclude.
5157 3. If a match is found, match the guest's unit mask to the mask and match
5158 values of the excluded filter events.
5159 I.e. (unit mask & mask) == match && exclude.
5160 4.
5161 a. If an included match is found and an excluded match is not found, filter
5162 the event.
5163 b. For everything else, do not filter the event.
5164 5.
5165 a. If the event is filtered and it's an allow list, allow the guest to
5166 program the event.
5167 b. If the event is filtered and it's a deny list, do not allow the guest to
5168 program the event.
30cd8604 5169
14329b82
AL
5170When setting a new pmu event filter, -EINVAL will be returned if any of the
5171unused fields are set or if any of the high bits (35:32) in the event
5172select are set when called on Intel.
66bb8a06 5173
106ee47d
MCC
5174Valid values for 'action'::
5175
5176 #define KVM_PMU_EVENT_ALLOW 0
5177 #define KVM_PMU_EVENT_DENY 1
66bb8a06 5178
b35babd3
JL
5179Via this API, KVM userspace can also control the behavior of the VM's fixed
5180counters (if any) by configuring the "action" and "fixed_counter_bitmap" fields.
5181
5182Specifically, KVM follows the following pseudo-code when determining whether to
5183allow the guest FixCtr[i] to count its pre-defined fixed event::
5184
5185 FixCtr[i]_is_allowed = (action == ALLOW) && (bitmap & BIT(i)) ||
5186 (action == DENY) && !(bitmap & BIT(i));
5187 FixCtr[i]_is_denied = !FixCtr[i]_is_allowed;
5188
5189KVM always consumes fixed_counter_bitmap, it's userspace's responsibility to
5190ensure fixed_counter_bitmap is set correctly, e.g. if userspace wants to define
5191a filter that only affects general purpose counters.
5192
5193Note, the "events" field also applies to fixed counters' hardcoded event_select
5194and unit_mask values. "fixed_counter_bitmap" has higher priority than "events"
5195if there is a contradiction between the two.
5196
22945688 51974.121 KVM_PPC_SVM_OFF
106ee47d
MCC
5198---------------------
5199
5200:Capability: basic
5201:Architectures: powerpc
5202:Type: vm ioctl
5203:Parameters: none
5204:Returns: 0 on successful completion,
22945688 5205
22945688 5206Errors:
106ee47d
MCC
5207
5208 ====== ================================================================
5209 EINVAL if ultravisor failed to terminate the secure guest
5210 ENOMEM if hypervisor failed to allocate new radix page tables for guest
5211 ====== ================================================================
22945688
BR
5212
5213This ioctl is used to turn off the secure mode of the guest or transition
5214the guest from secure mode to normal mode. This is invoked when the guest
5215is reset. This has no effect if called for a normal guest.
5216
5217This ioctl issues an ultravisor call to terminate the secure guest,
5218unpins the VPA pages and releases all the device pages that are used to
5219track the secure pages by hypervisor.
66bb8a06 5220
7de3f142 52214.122 KVM_S390_NORMAL_RESET
a93236fc 5222---------------------------
7de3f142 5223
a93236fc
CB
5224:Capability: KVM_CAP_S390_VCPU_RESETS
5225:Architectures: s390
5226:Type: vcpu ioctl
5227:Parameters: none
5228:Returns: 0
7de3f142
JF
5229
5230This ioctl resets VCPU registers and control structures according to
5231the cpu reset definition in the POP (Principles Of Operation).
5232
52334.123 KVM_S390_INITIAL_RESET
a93236fc 5234----------------------------
7de3f142 5235
a93236fc
CB
5236:Capability: none
5237:Architectures: s390
5238:Type: vcpu ioctl
5239:Parameters: none
5240:Returns: 0
7de3f142
JF
5241
5242This ioctl resets VCPU registers and control structures according to
5243the initial cpu reset definition in the POP. However, the cpu is not
5244put into ESA mode. This reset is a superset of the normal reset.
5245
52464.124 KVM_S390_CLEAR_RESET
a93236fc 5247--------------------------
7de3f142 5248
a93236fc
CB
5249:Capability: KVM_CAP_S390_VCPU_RESETS
5250:Architectures: s390
5251:Type: vcpu ioctl
5252:Parameters: none
5253:Returns: 0
7de3f142
JF
5254
5255This ioctl resets VCPU registers and control structures according to
5256the clear cpu reset definition in the POP. However, the cpu is not put
5257into ESA mode. This reset is a superset of the initial reset.
5258
5259
04ed89dc
JF
52604.125 KVM_S390_PV_COMMAND
5261-------------------------
5262
5263:Capability: KVM_CAP_S390_PROTECTED
5264:Architectures: s390
5265:Type: vm ioctl
5266:Parameters: struct kvm_pv_cmd
5267:Returns: 0 on success, < 0 on error
5268
5269::
5270
5271 struct kvm_pv_cmd {
5272 __u32 cmd; /* Command to be executed */
5273 __u16 rc; /* Ultravisor return code */
5274 __u16 rrc; /* Ultravisor return reason code */
5275 __u64 data; /* Data or address */
5276 __u32 flags; /* flags for future extensions. Must be 0 for now */
5277 __u32 reserved[3];
5278 };
5279
b0f46280
JF
5280**Ultravisor return codes**
5281The Ultravisor return (reason) codes are provided by the kernel if a
5282Ultravisor call has been executed to achieve the results expected by
5283the command. Therefore they are independent of the IOCTL return
5284code. If KVM changes `rc`, its value will always be greater than 0
5285hence setting it to 0 before issuing a PV command is advised to be
5286able to detect a change of `rc`.
5287
437cfd71 5288**cmd values:**
04ed89dc
JF
5289
5290KVM_PV_ENABLE
5291 Allocate memory and register the VM with the Ultravisor, thereby
5292 donating memory to the Ultravisor that will become inaccessible to
5293 KVM. All existing CPUs are converted to protected ones. After this
5294 command has succeeded, any CPU added via hotplug will become
5295 protected during its creation as well.
5296
7a265361
CB
5297 Errors:
5298
5299 ===== =============================
5300 EINTR an unmasked signal is pending
5301 ===== =============================
5302
04ed89dc 5303KVM_PV_DISABLE
d9459922
CI
5304 Deregister the VM from the Ultravisor and reclaim the memory that had
5305 been donated to the Ultravisor, making it usable by the kernel again.
5306 All registered VCPUs are converted back to non-protected ones. If a
d56b699d 5307 previous protected VM had been prepared for asynchronous teardown with
d9459922
CI
5308 KVM_PV_ASYNC_CLEANUP_PREPARE and not subsequently torn down with
5309 KVM_PV_ASYNC_CLEANUP_PERFORM, it will be torn down in this call
5310 together with the current protected VM.
04ed89dc
JF
5311
5312KVM_PV_VM_SET_SEC_PARMS
5313 Pass the image header from VM memory to the Ultravisor in
5314 preparation of image unpacking and verification.
5315
5316KVM_PV_VM_UNPACK
5317 Unpack (protect and decrypt) a page of the encrypted boot image.
5318
5319KVM_PV_VM_VERIFY
5320 Verify the integrity of the unpacked image. Only if this succeeds,
5321 KVM is allowed to start protected VCPUs.
5322
437cfd71
JF
5323KVM_PV_INFO
5324 :Capability: KVM_CAP_S390_PROTECTED_DUMP
5325
5326 Presents an API that provides Ultravisor related data to userspace
5327 via subcommands. len_max is the size of the user space buffer,
5328 len_written is KVM's indication of how much bytes of that buffer
5329 were actually written to. len_written can be used to determine the
5330 valid fields if more response fields are added in the future.
5331
5332 ::
5333
5334 enum pv_cmd_info_id {
5335 KVM_PV_INFO_VM,
5336 KVM_PV_INFO_DUMP,
5337 };
5338
5339 struct kvm_s390_pv_info_header {
5340 __u32 id;
5341 __u32 len_max;
5342 __u32 len_written;
5343 __u32 reserved;
5344 };
5345
5346 struct kvm_s390_pv_info {
5347 struct kvm_s390_pv_info_header header;
5348 struct kvm_s390_pv_info_dump dump;
5349 struct kvm_s390_pv_info_vm vm;
5350 };
5351
5352**subcommands:**
5353
5354 KVM_PV_INFO_VM
5355 This subcommand provides basic Ultravisor information for PV
5356 hosts. These values are likely also exported as files in the sysfs
5357 firmware UV query interface but they are more easily available to
5358 programs in this API.
5359
5360 The installed calls and feature_indication members provide the
5361 installed UV calls and the UV's other feature indications.
5362
5363 The max_* members provide information about the maximum number of PV
5364 vcpus, PV guests and PV guest memory size.
5365
5366 ::
5367
5368 struct kvm_s390_pv_info_vm {
5369 __u64 inst_calls_list[4];
5370 __u64 max_cpus;
5371 __u64 max_guests;
5372 __u64 max_guest_addr;
5373 __u64 feature_indication;
5374 };
5375
5376
5377 KVM_PV_INFO_DUMP
5378 This subcommand provides information related to dumping PV guests.
5379
5380 ::
5381
5382 struct kvm_s390_pv_info_dump {
5383 __u64 dump_cpu_buffer_len;
5384 __u64 dump_config_mem_buffer_per_1m;
5385 __u64 dump_config_finalize_len;
5386 };
5387
5388KVM_PV_DUMP
5389 :Capability: KVM_CAP_S390_PROTECTED_DUMP
5390
5391 Presents an API that provides calls which facilitate dumping a
5392 protected VM.
5393
5394 ::
5395
5396 struct kvm_s390_pv_dmp {
5397 __u64 subcmd;
5398 __u64 buff_addr;
5399 __u64 buff_len;
5400 __u64 gaddr; /* For dump storage state */
5401 };
5402
5403 **subcommands:**
5404
5405 KVM_PV_DUMP_INIT
5406 Initializes the dump process of a protected VM. If this call does
5407 not succeed all other subcommands will fail with -EINVAL. This
5408 subcommand will return -EINVAL if a dump process has not yet been
5409 completed.
5410
5411 Not all PV vms can be dumped, the owner needs to set `dump
5412 allowed` PCF bit 34 in the SE header to allow dumping.
5413
5414 KVM_PV_DUMP_CONFIG_STOR_STATE
5415 Stores `buff_len` bytes of tweak component values starting with
5416 the 1MB block specified by the absolute guest address
5417 (`gaddr`). `buff_len` needs to be `conf_dump_storage_state_len`
5418 aligned and at least >= the `conf_dump_storage_state_len` value
5419 provided by the dump uv_info data. buff_user might be written to
5420 even if an error rc is returned. For instance if we encounter a
5421 fault after writing the first page of data.
5422
5423 KVM_PV_DUMP_COMPLETE
5424 If the subcommand succeeds it completes the dump process and lets
5425 KVM_PV_DUMP_INIT be called again.
5426
5427 On success `conf_dump_finalize_len` bytes of completion data will be
5428 stored to the `buff_addr`. The completion data contains a key
5429 derivation seed, IV, tweak nonce and encryption keys as well as an
5430 authentication tag all of which are needed to decrypt the dump at a
5431 later time.
5432
d9459922
CI
5433KVM_PV_ASYNC_CLEANUP_PREPARE
5434 :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE
5435
5436 Prepare the current protected VM for asynchronous teardown. Most
5437 resources used by the current protected VM will be set aside for a
5438 subsequent asynchronous teardown. The current protected VM will then
5439 resume execution immediately as non-protected. There can be at most
5440 one protected VM prepared for asynchronous teardown at any time. If
5441 a protected VM had already been prepared for teardown without
5442 subsequently calling KVM_PV_ASYNC_CLEANUP_PERFORM, this call will
5443 fail. In that case, the userspace process should issue a normal
5444 KVM_PV_DISABLE. The resources set aside with this call will need to
5445 be cleaned up with a subsequent call to KVM_PV_ASYNC_CLEANUP_PERFORM
5446 or KVM_PV_DISABLE, otherwise they will be cleaned up when KVM
5447 terminates. KVM_PV_ASYNC_CLEANUP_PREPARE can be called again as soon
5448 as cleanup starts, i.e. before KVM_PV_ASYNC_CLEANUP_PERFORM finishes.
5449
5450KVM_PV_ASYNC_CLEANUP_PERFORM
5451 :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE
5452
5453 Tear down the protected VM previously prepared for teardown with
5454 KVM_PV_ASYNC_CLEANUP_PREPARE. The resources that had been set aside
5455 will be freed during the execution of this command. This PV command
5456 should ideally be issued by userspace from a separate thread. If a
5457 fatal signal is received (or the process terminates naturally), the
5458 command will terminate immediately without completing, and the normal
5459 KVM shutdown procedure will take care of cleaning up all remaining
5460 protected VMs, including the ones whose teardown was interrupted by
5461 process termination.
5462
b5cb32b1 54634.126 KVM_XEN_HVM_SET_ATTR
e1f68169
DW
5464--------------------------
5465
5466:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5467:Architectures: x86
5468:Type: vm ioctl
5469:Parameters: struct kvm_xen_hvm_attr
5470:Returns: 0 on success, < 0 on error
5471
5472::
5473
5474 struct kvm_xen_hvm_attr {
5475 __u16 type;
5476 __u16 pad[3];
5477 union {
5478 __u8 long_mode;
5479 __u8 vector;
d8ba8ba4 5480 __u8 runstate_update_flag;
e1f68169
DW
5481 struct {
5482 __u64 gfn;
5483 } shared_info;
661a20fa
DW
5484 struct {
5485 __u32 send_port;
5486 __u32 type; /* EVTCHNSTAT_ipi / EVTCHNSTAT_interdomain */
5487 __u32 flags;
5488 union {
5489 struct {
5490 __u32 port;
5491 __u32 vcpu;
5492 __u32 priority;
5493 } port;
5494 struct {
5495 __u32 port; /* Zero for eventfd */
5496 __s32 fd;
5497 } eventfd;
5498 __u32 padding[4];
5499 } deliver;
5500 } evtchn;
5501 __u32 xen_version;
5502 __u64 pad[8];
e1f68169
DW
5503 } u;
5504 };
5505
5506type values:
5507
5508KVM_XEN_ATTR_TYPE_LONG_MODE
5509 Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This
5510 determines the layout of the shared info pages exposed to the VM.
5511
5512KVM_XEN_ATTR_TYPE_SHARED_INFO
5513 Sets the guest physical frame number at which the Xen "shared info"
5514 page resides. Note that although Xen places vcpu_info for the first
5515 32 vCPUs in the shared_info page, KVM does not automatically do so
5516 and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
5517 explicitly even when the vcpu_info for a given vCPU resides at the
af280890
DW
5518 "default" location in the shared_info page. This is because KVM may
5519 not be aware of the Xen CPU id which is used as the index into the
5520 vcpu_info[] array, so may know the correct default location.
e1f68169 5521
1cfc9c4b
DW
5522 Note that the shared info page may be constantly written to by KVM;
5523 it contains the event channel bitmap used to deliver interrupts to
5524 a Xen guest, amongst other things. It is exempt from dirty tracking
5525 mechanisms — KVM will not explicitly mark the page as dirty each
5526 time an event channel interrupt is delivered to the guest! Thus,
5527 userspace should always assume that the designated GFN is dirty if
5528 any vCPU has been running or any event channel interrupts can be
5529 routed to the guest.
5530
af280890
DW
5531 Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared info
5532 page.
5533
e1f68169
DW
5534KVM_XEN_ATTR_TYPE_UPCALL_VECTOR
5535 Sets the exception vector used to deliver Xen event channel upcalls.
661a20fa
DW
5536 This is the HVM-wide vector injected directly by the hypervisor
5537 (not through the local APIC), typically configured by a guest via
af280890
DW
5538 HVM_PARAM_CALLBACK_IRQ. This can be disabled again (e.g. for guest
5539 SHUTDOWN_soft_reset) by setting it to zero.
661a20fa
DW
5540
5541KVM_XEN_ATTR_TYPE_EVTCHN
5542 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5543 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It configures
5544 an outbound port number for interception of EVTCHNOP_send requests
af280890
DW
5545 from the guest. A given sending port number may be directed back to
5546 a specified vCPU (by APIC ID) / port / priority on the guest, or to
5547 trigger events on an eventfd. The vCPU and priority can be changed
57f33f1a 5548 by setting KVM_XEN_EVTCHN_UPDATE in a subsequent call, but other
af280890
DW
5549 fields cannot change for a given sending port. A port mapping is
5550 removed by using KVM_XEN_EVTCHN_DEASSIGN in the flags field. Passing
5551 KVM_XEN_EVTCHN_RESET in the flags field removes all interception of
5552 outbound event channels. The values of the flags field are mutually
5553 exclusive and cannot be combined as a bitmask.
661a20fa
DW
5554
5555KVM_XEN_ATTR_TYPE_XEN_VERSION
5556 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5557 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It configures
5558 the 32-bit version code returned to the guest when it invokes the
5559 XENVER_version call; typically (XEN_MAJOR << 16 | XEN_MINOR). PV
5560 Xen guests will often use this to as a dummy hypercall to trigger
5561 event channel delivery, so responding within the kernel without
5562 exiting to userspace is beneficial.
e1f68169 5563
d8ba8ba4
DW
5564KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG
5565 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5566 support for KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG. It enables the
5567 XEN_RUNSTATE_UPDATE flag which allows guest vCPUs to safely read
5568 other vCPUs' vcpu_runstate_info. Xen guests enable this feature via
af280890 5569 the VMASST_TYPE_runstate_update_flag of the HYPERVISOR_vm_assist
d8ba8ba4
DW
5570 hypercall.
5571
24e7475f 55724.127 KVM_XEN_HVM_GET_ATTR
e1f68169
DW
5573--------------------------
5574
5575:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5576:Architectures: x86
5577:Type: vm ioctl
5578:Parameters: struct kvm_xen_hvm_attr
5579:Returns: 0 on success, < 0 on error
5580
5581Allows Xen VM attributes to be read. For the structure and types,
661a20fa
DW
5582see KVM_XEN_HVM_SET_ATTR above. The KVM_XEN_ATTR_TYPE_EVTCHN
5583attribute cannot be read.
e1f68169 5584
24e7475f 55854.128 KVM_XEN_VCPU_SET_ATTR
e1f68169
DW
5586---------------------------
5587
5588:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5589:Architectures: x86
5590:Type: vcpu ioctl
5591:Parameters: struct kvm_xen_vcpu_attr
5592:Returns: 0 on success, < 0 on error
5593
5594::
5595
5596 struct kvm_xen_vcpu_attr {
5597 __u16 type;
5598 __u16 pad[3];
5599 union {
5600 __u64 gpa;
5601 __u64 pad[4];
30b5c851
DW
5602 struct {
5603 __u64 state;
5604 __u64 state_entry_time;
5605 __u64 time_running;
5606 __u64 time_runnable;
5607 __u64 time_blocked;
5608 __u64 time_offline;
5609 } runstate;
661a20fa
DW
5610 __u32 vcpu_id;
5611 struct {
5612 __u32 port;
5613 __u32 priority;
5614 __u64 expires_ns;
5615 } timer;
5616 __u8 vector;
e1f68169
DW
5617 } u;
5618 };
5619
5620type values:
5621
5622KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
5623 Sets the guest physical address of the vcpu_info for a given vCPU.
cf1d88b3
DW
5624 As with the shared_info page for the VM, the corresponding page may be
5625 dirtied at any time if event channel interrupt delivery is enabled, so
5626 userspace should always assume that the page is dirty without relying
af280890
DW
5627 on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable
5628 the vcpu_info.
e1f68169
DW
5629
5630KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
5631 Sets the guest physical address of an additional pvclock structure
5632 for a given vCPU. This is typically used for guest vsyscall support.
af280890 5633 Setting the gpa to KVM_XEN_INVALID_GPA will disable the structure.
e1f68169 5634
30b5c851
DW
5635KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR
5636 Sets the guest physical address of the vcpu_runstate_info for a given
5637 vCPU. This is how a Xen guest tracks CPU state such as steal time.
af280890 5638 Setting the gpa to KVM_XEN_INVALID_GPA will disable the runstate area.
30b5c851
DW
5639
5640KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT
5641 Sets the runstate (RUNSTATE_running/_runnable/_blocked/_offline) of
5642 the given vCPU from the .u.runstate.state member of the structure.
5643 KVM automatically accounts running and runnable time but blocked
5644 and offline states are only entered explicitly.
5645
5646KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA
5647 Sets all fields of the vCPU runstate data from the .u.runstate member
5648 of the structure, including the current runstate. The state_entry_time
5649 must equal the sum of the other four times.
5650
5651KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST
5652 This *adds* the contents of the .u.runstate members of the structure
5653 to the corresponding members of the given vCPU's runstate data, thus
5654 permitting atomic adjustments to the runstate times. The adjustment
5655 to the state_entry_time must equal the sum of the adjustments to the
5656 other four times. The state field must be set to -1, or to a valid
5657 runstate value (RUNSTATE_running, RUNSTATE_runnable, RUNSTATE_blocked
5658 or RUNSTATE_offline) to set the current accounted state as of the
5659 adjusted state_entry_time.
5660
661a20fa
DW
5661KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID
5662 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5663 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the Xen
5664 vCPU ID of the given vCPU, to allow timer-related VCPU operations to
5665 be intercepted by KVM.
5666
5667KVM_XEN_VCPU_ATTR_TYPE_TIMER
5668 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5669 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the
5670 event channel port/priority for the VIRQ_TIMER of the vCPU, as well
af280890
DW
5671 as allowing a pending timer to be saved/restored. Setting the timer
5672 port to zero disables kernel handling of the singleshot timer.
661a20fa
DW
5673
5674KVM_XEN_VCPU_ATTR_TYPE_UPCALL_VECTOR
5675 This attribute is available when the KVM_CAP_XEN_HVM ioctl indicates
5676 support for KVM_XEN_HVM_CONFIG_EVTCHN_SEND features. It sets the
5677 per-vCPU local APIC upcall vector, configured by a Xen guest with
5678 the HVMOP_set_evtchn_upcall_vector hypercall. This is typically
5679 used by Windows guests, and is distinct from the HVM-wide upcall
af280890
DW
5680 vector configured with HVM_PARAM_CALLBACK_IRQ. It is disabled by
5681 setting the vector to zero.
661a20fa
DW
5682
5683
24e7475f 56844.129 KVM_XEN_VCPU_GET_ATTR
9294b8a1 5685---------------------------
e1f68169
DW
5686
5687:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5688:Architectures: x86
5689:Type: vcpu ioctl
5690:Parameters: struct kvm_xen_vcpu_attr
5691:Returns: 0 on success, < 0 on error
5692
5693Allows Xen vCPU attributes to be read. For the structure and types,
5694see KVM_XEN_VCPU_SET_ATTR above.
04ed89dc 5695
30b5c851
DW
5696The KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST type may not be used
5697with the KVM_XEN_VCPU_GET_ATTR ioctl.
5698
04c02c20
SP
56994.130 KVM_ARM_MTE_COPY_TAGS
5700---------------------------
5701
5702:Capability: KVM_CAP_ARM_MTE
5703:Architectures: arm64
5704:Type: vm ioctl
5705:Parameters: struct kvm_arm_copy_mte_tags
5706:Returns: number of bytes copied, < 0 on error (-EINVAL for incorrect
5707 arguments, -EFAULT if memory cannot be accessed).
5708
5709::
5710
5711 struct kvm_arm_copy_mte_tags {
5712 __u64 guest_ipa;
5713 __u64 length;
5714 void __user *addr;
5715 __u64 flags;
5716 __u64 reserved[2];
5717 };
5718
5719Copies Memory Tagging Extension (MTE) tags to/from guest tag memory. The
2def950c
TH
5720``guest_ipa`` and ``length`` fields must be ``PAGE_SIZE`` aligned.
5721``length`` must not be bigger than 2^31 - PAGE_SIZE bytes. The ``addr``
04c02c20
SP
5722field must point to a buffer which the tags will be copied to or from.
5723
5724``flags`` specifies the direction of copy, either ``KVM_ARM_TAGS_TO_GUEST`` or
5725``KVM_ARM_TAGS_FROM_GUEST``.
5726
5727The size of the buffer to store the tags is ``(length / 16)`` bytes
5728(granules in MTE are 16 bytes long). Each byte contains a single tag
5729value. This matches the format of ``PTRACE_PEEKMTETAGS`` and
5730``PTRACE_POKEMTETAGS``.
5731
5732If an error occurs before any data is copied then a negative error code is
5733returned. If some tags have been copied before an error occurs then the number
5734of bytes successfully copied is returned. If the call completes successfully
5735then ``length`` is returned.
6dba9403
ML
5736
57374.131 KVM_GET_SREGS2
8b967164 5738--------------------
6dba9403
ML
5739
5740:Capability: KVM_CAP_SREGS2
5741:Architectures: x86
5742:Type: vcpu ioctl
5743:Parameters: struct kvm_sregs2 (out)
5744:Returns: 0 on success, -1 on error
5745
5746Reads special registers from the vcpu.
5747This ioctl (when supported) replaces the KVM_GET_SREGS.
5748
5749::
5750
8b967164
IC
5751 struct kvm_sregs2 {
5752 /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */
5753 struct kvm_segment cs, ds, es, fs, gs, ss;
5754 struct kvm_segment tr, ldt;
5755 struct kvm_dtable gdt, idt;
5756 __u64 cr0, cr2, cr3, cr4, cr8;
5757 __u64 efer;
5758 __u64 apic_base;
5759 __u64 flags;
5760 __u64 pdptrs[4];
5761 };
6dba9403
ML
5762
5763flags values for ``kvm_sregs2``:
5764
5765``KVM_SREGS2_FLAGS_PDPTRS_VALID``
5766
d56b699d 5767 Indicates that the struct contains valid PDPTR values.
6dba9403
ML
5768
5769
57704.132 KVM_SET_SREGS2
8b967164 5771--------------------
6dba9403
ML
5772
5773:Capability: KVM_CAP_SREGS2
5774:Architectures: x86
5775:Type: vcpu ioctl
5776:Parameters: struct kvm_sregs2 (in)
5777:Returns: 0 on success, -1 on error
5778
5779Writes special registers into the vcpu.
5780See KVM_GET_SREGS2 for the data structures.
5781This ioctl (when supported) replaces the KVM_SET_SREGS.
5782
fdc09ddd
JZ
57834.133 KVM_GET_STATS_FD
5784----------------------
5785
5786:Capability: KVM_CAP_STATS_BINARY_FD
5787:Architectures: all
5788:Type: vm ioctl, vcpu ioctl
5789:Parameters: none
5790:Returns: statistics file descriptor on success, < 0 on error
5791
5792Errors:
5793
5794 ====== ======================================================
5795 ENOMEM if the fd could not be created due to lack of memory
5796 EMFILE if the number of opened files exceeds the limit
5797 ====== ======================================================
5798
5799The returned file descriptor can be used to read VM/vCPU statistics data in
5800binary format. The data in the file descriptor consists of four blocks
5801organized as follows:
5802
5803+-------------+
5804| Header |
5805+-------------+
5806| id string |
5807+-------------+
5808| Descriptors |
5809+-------------+
5810| Stats Data |
5811+-------------+
5812
5813Apart from the header starting at offset 0, please be aware that it is
5814not guaranteed that the four blocks are adjacent or in the above order;
5815the offsets of the id, descriptors and data blocks are found in the
5816header. However, all four blocks are aligned to 64 bit offsets in the
5817file and they do not overlap.
5818
5819All blocks except the data block are immutable. Userspace can read them
5820only one time after retrieving the file descriptor, and then use ``pread`` or
5821``lseek`` to read the statistics repeatedly.
5822
5823All data is in system endianness.
5824
5825The format of the header is as follows::
5826
5827 struct kvm_stats_header {
5828 __u32 flags;
5829 __u32 name_size;
5830 __u32 num_desc;
5831 __u32 id_offset;
5832 __u32 desc_offset;
5833 __u32 data_offset;
5834 };
5835
5836The ``flags`` field is not used at the moment. It is always read as 0.
5837
5838The ``name_size`` field is the size (in byte) of the statistics name string
5839(including trailing '\0') which is contained in the "id string" block and
5840appended at the end of every descriptor.
5841
5842The ``num_desc`` field is the number of descriptors that are included in the
5843descriptor block. (The actual number of values in the data block may be
5844larger, since each descriptor may comprise more than one value).
5845
5846The ``id_offset`` field is the offset of the id string from the start of the
5847file indicated by the file descriptor. It is a multiple of 8.
5848
5849The ``desc_offset`` field is the offset of the Descriptors block from the start
5850of the file indicated by the file descriptor. It is a multiple of 8.
5851
5852The ``data_offset`` field is the offset of the Stats Data block from the start
5853of the file indicated by the file descriptor. It is a multiple of 8.
5854
5855The id string block contains a string which identifies the file descriptor on
5856which KVM_GET_STATS_FD was invoked. The size of the block, including the
5857trailing ``'\0'``, is indicated by the ``name_size`` field in the header.
5858
5859The descriptors block is only needed to be read once for the lifetime of the
5860file descriptor contains a sequence of ``struct kvm_stats_desc``, each followed
5861by a string of size ``name_size``.
a9fd134b 5862::
fdc09ddd
JZ
5863
5864 #define KVM_STATS_TYPE_SHIFT 0
5865 #define KVM_STATS_TYPE_MASK (0xF << KVM_STATS_TYPE_SHIFT)
5866 #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT)
5867 #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT)
5868 #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT)
0176ec51
JZ
5869 #define KVM_STATS_TYPE_LINEAR_HIST (0x3 << KVM_STATS_TYPE_SHIFT)
5870 #define KVM_STATS_TYPE_LOG_HIST (0x4 << KVM_STATS_TYPE_SHIFT)
5871 #define KVM_STATS_TYPE_MAX KVM_STATS_TYPE_LOG_HIST
fdc09ddd
JZ
5872
5873 #define KVM_STATS_UNIT_SHIFT 4
5874 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT)
5875 #define KVM_STATS_UNIT_NONE (0x0 << KVM_STATS_UNIT_SHIFT)
5876 #define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT)
5877 #define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT)
5878 #define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT)
1b870fa5 5879 #define KVM_STATS_UNIT_BOOLEAN (0x4 << KVM_STATS_UNIT_SHIFT)
450a5639 5880 #define KVM_STATS_UNIT_MAX KVM_STATS_UNIT_BOOLEAN
fdc09ddd
JZ
5881
5882 #define KVM_STATS_BASE_SHIFT 8
5883 #define KVM_STATS_BASE_MASK (0xF << KVM_STATS_BASE_SHIFT)
5884 #define KVM_STATS_BASE_POW10 (0x0 << KVM_STATS_BASE_SHIFT)
5885 #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT)
0176ec51 5886 #define KVM_STATS_BASE_MAX KVM_STATS_BASE_POW2
fdc09ddd
JZ
5887
5888 struct kvm_stats_desc {
5889 __u32 flags;
5890 __s16 exponent;
5891 __u16 size;
5892 __u32 offset;
0176ec51 5893 __u32 bucket_size;
fdc09ddd
JZ
5894 char name[];
5895 };
5896
5897The ``flags`` field contains the type and unit of the statistics data described
5898by this descriptor. Its endianness is CPU native.
5899The following flags are supported:
5900
5901Bits 0-3 of ``flags`` encode the type:
a9fd134b 5902
fdc09ddd 5903 * ``KVM_STATS_TYPE_CUMULATIVE``
0176ec51 5904 The statistics reports a cumulative count. The value of data can only be increased.
fdc09ddd
JZ
5905 Most of the counters used in KVM are of this type.
5906 The corresponding ``size`` field for this type is always 1.
5907 All cumulative statistics data are read/write.
5908 * ``KVM_STATS_TYPE_INSTANT``
0176ec51 5909 The statistics reports an instantaneous value. Its value can be increased or
fdc09ddd
JZ
5910 decreased. This type is usually used as a measurement of some resources,
5911 like the number of dirty pages, the number of large pages, etc.
5912 All instant statistics are read only.
5913 The corresponding ``size`` field for this type is always 1.
5914 * ``KVM_STATS_TYPE_PEAK``
0176ec51 5915 The statistics data reports a peak value, for example the maximum number
fdc09ddd 5916 of items in a hash table bucket, the longest time waited and so on.
0176ec51 5917 The value of data can only be increased.
fdc09ddd 5918 The corresponding ``size`` field for this type is always 1.
0176ec51
JZ
5919 * ``KVM_STATS_TYPE_LINEAR_HIST``
5920 The statistic is reported as a linear histogram. The number of
5921 buckets is specified by the ``size`` field. The size of buckets is specified
5922 by the ``hist_param`` field. The range of the Nth bucket (1 <= N < ``size``)
5923 is [``hist_param``*(N-1), ``hist_param``*N), while the range of the last
5924 bucket is [``hist_param``*(``size``-1), +INF). (+INF means positive infinity
942d9e89 5925 value.)
0176ec51
JZ
5926 * ``KVM_STATS_TYPE_LOG_HIST``
5927 The statistic is reported as a logarithmic histogram. The number of
5928 buckets is specified by the ``size`` field. The range of the first bucket is
5929 [0, 1), while the range of the last bucket is [pow(2, ``size``-2), +INF).
5930 Otherwise, The Nth bucket (1 < N < ``size``) covers
942d9e89 5931 [pow(2, N-2), pow(2, N-1)).
fdc09ddd
JZ
5932
5933Bits 4-7 of ``flags`` encode the unit:
a9fd134b 5934
fdc09ddd
JZ
5935 * ``KVM_STATS_UNIT_NONE``
5936 There is no unit for the value of statistics data. This usually means that
5937 the value is a simple counter of an event.
5938 * ``KVM_STATS_UNIT_BYTES``
5939 It indicates that the statistics data is used to measure memory size, in the
5940 unit of Byte, KiByte, MiByte, GiByte, etc. The unit of the data is
5941 determined by the ``exponent`` field in the descriptor.
5942 * ``KVM_STATS_UNIT_SECONDS``
5943 It indicates that the statistics data is used to measure time or latency.
5944 * ``KVM_STATS_UNIT_CYCLES``
5945 It indicates that the statistics data is used to measure CPU clock cycles.
1b870fa5
PB
5946 * ``KVM_STATS_UNIT_BOOLEAN``
5947 It indicates that the statistic will always be either 0 or 1. Boolean
5948 statistics of "peak" type will never go back from 1 to 0. Boolean
5949 statistics can be linear histograms (with two buckets) but not logarithmic
5950 histograms.
fdc09ddd 5951
942d9e89
PB
5952Note that, in the case of histograms, the unit applies to the bucket
5953ranges, while the bucket value indicates how many samples fell in the
5954bucket's range.
5955
fdc09ddd
JZ
5956Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the
5957unit:
a9fd134b 5958
fdc09ddd
JZ
5959 * ``KVM_STATS_BASE_POW10``
5960 The scale is based on power of 10. It is used for measurement of time and
5961 CPU clock cycles. For example, an exponent of -9 can be used with
5962 ``KVM_STATS_UNIT_SECONDS`` to express that the unit is nanoseconds.
5963 * ``KVM_STATS_BASE_POW2``
5964 The scale is based on power of 2. It is used for measurement of memory size.
5965 For example, an exponent of 20 can be used with ``KVM_STATS_UNIT_BYTES`` to
5966 express that the unit is MiB.
5967
5968The ``size`` field is the number of values of this statistics data. Its
5969value is usually 1 for most of simple statistics. 1 means it contains an
5970unsigned 64bit data.
5971
5972The ``offset`` field is the offset from the start of Data Block to the start of
5973the corresponding statistics data.
5974
0176ec51
JZ
5975The ``bucket_size`` field is used as a parameter for histogram statistics data.
5976It is only used by linear histogram statistics data, specifying the size of a
942d9e89 5977bucket in the unit expressed by bits 4-11 of ``flags`` together with ``exponent``.
fdc09ddd
JZ
5978
5979The ``name`` field is the name string of the statistics data. The name string
5980starts at the end of ``struct kvm_stats_desc``. The maximum length including
5981the trailing ``'\0'``, is indicated by ``name_size`` in the header.
5982
5983The Stats Data block contains an array of 64-bit values in the same order
5984as the descriptors in Descriptors block.
6dba9403 5985
e2e83a73
WW
59864.134 KVM_GET_XSAVE2
5987--------------------
be50b206
GZ
5988
5989:Capability: KVM_CAP_XSAVE2
5990:Architectures: x86
5991:Type: vcpu ioctl
5992:Parameters: struct kvm_xsave (out)
5993:Returns: 0 on success, -1 on error
5994
5995
5996::
5997
5998 struct kvm_xsave {
5999 __u32 region[1024];
6000 __u32 extra[0];
6001 };
6002
6003This ioctl would copy current vcpu's xsave struct to the userspace. It
6004copies as many bytes as are returned by KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2)
6005when invoked on the vm file descriptor. The size value returned by
6006KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) will always be at least 4096.
6007Currently, it is only greater than 4096 if a dynamic feature has been
6008enabled with ``arch_prctl()``, but this may change in the future.
6009
6010The offsets of the state save areas in struct kvm_xsave follow the contents
6011of CPUID leaf 0xD on the host.
6012
661a20fa
DW
60134.135 KVM_XEN_HVM_EVTCHN_SEND
6014-----------------------------
6015
6016:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND
6017:Architectures: x86
6018:Type: vm ioctl
6019:Parameters: struct kvm_irq_routing_xen_evtchn
6020:Returns: 0 on success, < 0 on error
6021
6022
6023::
6024
6025 struct kvm_irq_routing_xen_evtchn {
6026 __u32 port;
6027 __u32 vcpu;
6028 __u32 priority;
6029 };
6030
6031This ioctl injects an event channel interrupt directly to the guest vCPU.
be50b206 6032
437cfd71
JF
60334.136 KVM_S390_PV_CPU_COMMAND
6034-----------------------------
6035
6036:Capability: KVM_CAP_S390_PROTECTED_DUMP
6037:Architectures: s390
6038:Type: vcpu ioctl
6039:Parameters: none
6040:Returns: 0 on success, < 0 on error
6041
6042This ioctl closely mirrors `KVM_S390_PV_COMMAND` but handles requests
6043for vcpus. It re-uses the kvm_s390_pv_dmp struct and hence also shares
6044the command ids.
6045
6046**command:**
6047
6048KVM_PV_DUMP
6049 Presents an API that provides calls which facilitate dumping a vcpu
6050 of a protected VM.
6051
6052**subcommand:**
6053
6054KVM_PV_DUMP_CPU
6055 Provides encrypted dump data like register values.
6056 The length of the returned data is provided by uv_info.guest_cpu_stor_len.
6057
db1c875e 60584.137 KVM_S390_ZPCI_OP
5efab5cd 6059----------------------
db1c875e
MR
6060
6061:Capability: KVM_CAP_S390_ZPCI_OP
6062:Architectures: s390
6063:Type: vm ioctl
6064:Parameters: struct kvm_s390_zpci_op (in)
6065:Returns: 0 on success, <0 on error
6066
6067Used to manage hardware-assisted virtualization features for zPCI devices.
6068
6069Parameters are specified via the following structure::
6070
6071 struct kvm_s390_zpci_op {
6072 /* in */
6073 __u32 fh; /* target device */
6074 __u8 op; /* operation to perform */
6075 __u8 pad[3];
6076 union {
6077 /* for KVM_S390_ZPCIOP_REG_AEN */
6078 struct {
6079 __u64 ibv; /* Guest addr of interrupt bit vector */
6080 __u64 sb; /* Guest addr of summary bit */
6081 __u32 flags;
6082 __u32 noi; /* Number of interrupts */
6083 __u8 isc; /* Guest interrupt subclass */
6084 __u8 sbo; /* Offset of guest summary bit vector */
6085 __u16 pad;
6086 } reg_aen;
6087 __u64 reserved[8];
6088 } u;
6089 };
6090
6091The type of operation is specified in the "op" field.
6092KVM_S390_ZPCIOP_REG_AEN is used to register the VM for adapter event
6093notification interpretation, which will allow firmware delivery of adapter
6094events directly to the vm, with KVM providing a backup delivery mechanism;
6095KVM_S390_ZPCIOP_DEREG_AEN is used to subsequently disable interpretation of
6096adapter event notifications.
6097
6098The target zPCI function must also be specified via the "fh" field. For the
6099KVM_S390_ZPCIOP_REG_AEN operation, additional information to establish firmware
6100delivery must be provided via the "reg_aen" struct.
6101
6102The "pad" and "reserved" fields may be used for future extensions and should be
6103set to 0s by userspace.
437cfd71 6104
1935d34a
MZ
61054.138 KVM_ARM_SET_COUNTER_OFFSET
6106--------------------------------
6107
6108:Capability: KVM_CAP_COUNTER_OFFSET
6109:Architectures: arm64
6110:Type: vm ioctl
6111:Parameters: struct kvm_arm_counter_offset (in)
6112:Returns: 0 on success, < 0 on error
6113
6114This capability indicates that userspace is able to apply a single VM-wide
6115offset to both the virtual and physical counters as viewed by the guest
6116using the KVM_ARM_SET_CNT_OFFSET ioctl and the following data structure:
6117
6118::
6119
6120 struct kvm_arm_counter_offset {
6121 __u64 counter_offset;
6122 __u64 reserved;
6123 };
6124
6125The offset describes a number of counter cycles that are subtracted from
6126both virtual and physical counter views (similar to the effects of the
6127CNTVOFF_EL2 and CNTPOFF_EL2 system registers, but only global). The offset
6128always applies to all vcpus (already created or created after this ioctl)
6129for this VM.
6130
6131It is userspace's responsibility to compute the offset based, for example,
6132on previous values of the guest counters.
6133
6134Any value other than 0 for the "reserved" field may result in an error
6135(-EINVAL) being returned. This ioctl can also return -EBUSY if any vcpu
6136ioctl is issued concurrently.
6137
6138Note that using this ioctl results in KVM ignoring subsequent userspace
6139writes to the CNTVCT_EL0 and CNTPCT_EL0 registers using the SET_ONE_REG
6140interface. No error will be returned, but the resulting offset will not be
6141applied.
6142
9c1b96e3 61435. The kvm_run structure
106ee47d 6144========================
9c1b96e3
AK
6145
6146Application code obtains a pointer to the kvm_run structure by
6147mmap()ing a vcpu fd. From that point, application code can control
6148execution by changing fields in kvm_run prior to calling the KVM_RUN
6149ioctl, and obtain information about the reason KVM_RUN returned by
6150looking up structure members.
6151
106ee47d
MCC
6152::
6153
6154 struct kvm_run {
9c1b96e3
AK
6155 /* in */
6156 __u8 request_interrupt_window;
6157
6158Request that KVM_RUN return when it becomes possible to inject external
6159interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
6160
106ee47d
MCC
6161::
6162
460df4c1
PB
6163 __u8 immediate_exit;
6164
6165This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
6166exits immediately, returning -EINTR. In the common scenario where a
6167signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
6168to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
6169Rather than blocking the signal outside KVM_RUN, userspace can set up
6170a signal handler that sets run->immediate_exit to a non-zero value.
6171
6172This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
6173
106ee47d
MCC
6174::
6175
460df4c1 6176 __u8 padding1[6];
9c1b96e3
AK
6177
6178 /* out */
6179 __u32 exit_reason;
6180
6181When KVM_RUN has returned successfully (return value 0), this informs
6182application code why KVM_RUN has returned. Allowable values for this
6183field are detailed below.
6184
106ee47d
MCC
6185::
6186
9c1b96e3
AK
6187 __u8 ready_for_interrupt_injection;
6188
6189If request_interrupt_window has been specified, this field indicates
6190an interrupt can be injected now with KVM_INTERRUPT.
6191
106ee47d
MCC
6192::
6193
9c1b96e3
AK
6194 __u8 if_flag;
6195
6196The value of the current interrupt flag. Only valid if in-kernel
6197local APIC is not used.
6198
106ee47d
MCC
6199::
6200
f077825a
PB
6201 __u16 flags;
6202
6203More architecture-specific flags detailing state of the VCPU that may
96564d77
CQ
6204affect the device's behavior. Current defined flags::
6205
c32b1b89
CQ
6206 /* x86, set if the VCPU is in system management mode */
6207 #define KVM_RUN_X86_SMM (1 << 0)
6208 /* x86, set if bus lock detected in VM */
6209 #define KVM_RUN_BUS_LOCK (1 << 1)
18f3976f
AE
6210 /* arm64, set for KVM_EXIT_DEBUG */
6211 #define KVM_DEBUG_ARCH_HSR_HIGH_VALID (1 << 0)
9c1b96e3 6212
106ee47d
MCC
6213::
6214
9c1b96e3
AK
6215 /* in (pre_kvm_run), out (post_kvm_run) */
6216 __u64 cr8;
6217
6218The value of the cr8 register. Only valid if in-kernel local APIC is
6219not used. Both input and output.
6220
106ee47d
MCC
6221::
6222
9c1b96e3
AK
6223 __u64 apic_base;
6224
6225The value of the APIC BASE msr. Only valid if in-kernel local
6226APIC is not used. Both input and output.
6227
106ee47d
MCC
6228::
6229
9c1b96e3
AK
6230 union {
6231 /* KVM_EXIT_UNKNOWN */
6232 struct {
6233 __u64 hardware_exit_reason;
6234 } hw;
6235
6236If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
6237reasons. Further architecture-specific information is available in
6238hardware_exit_reason.
6239
106ee47d
MCC
6240::
6241
9c1b96e3
AK
6242 /* KVM_EXIT_FAIL_ENTRY */
6243 struct {
6244 __u64 hardware_entry_failure_reason;
1aa561b1 6245 __u32 cpu; /* if KVM_LAST_CPU */
9c1b96e3
AK
6246 } fail_entry;
6247
6248If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
6249to unknown reasons. Further architecture-specific information is
6250available in hardware_entry_failure_reason.
6251
106ee47d
MCC
6252::
6253
9c1b96e3
AK
6254 /* KVM_EXIT_EXCEPTION */
6255 struct {
6256 __u32 exception;
6257 __u32 error_code;
6258 } ex;
6259
6260Unused.
6261
106ee47d
MCC
6262::
6263
9c1b96e3
AK
6264 /* KVM_EXIT_IO */
6265 struct {
106ee47d
MCC
6266 #define KVM_EXIT_IO_IN 0
6267 #define KVM_EXIT_IO_OUT 1
9c1b96e3
AK
6268 __u8 direction;
6269 __u8 size; /* bytes */
6270 __u16 port;
6271 __u32 count;
6272 __u64 data_offset; /* relative to kvm_run start */
6273 } io;
6274
2044892d 6275If exit_reason is KVM_EXIT_IO, then the vcpu has
9c1b96e3
AK
6276executed a port I/O instruction which could not be satisfied by kvm.
6277data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
6278where kvm expects application code to place the data for the next
2044892d 6279KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
9c1b96e3 6280
106ee47d
MCC
6281::
6282
8ab30c15 6283 /* KVM_EXIT_DEBUG */
9c1b96e3
AK
6284 struct {
6285 struct kvm_debug_exit_arch arch;
6286 } debug;
6287
8ab30c15
AB
6288If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
6289for which architecture specific information is returned.
9c1b96e3 6290
106ee47d
MCC
6291::
6292
9c1b96e3
AK
6293 /* KVM_EXIT_MMIO */
6294 struct {
6295 __u64 phys_addr;
6296 __u8 data[8];
6297 __u32 len;
6298 __u8 is_write;
6299 } mmio;
6300
2044892d 6301If exit_reason is KVM_EXIT_MMIO, then the vcpu has
9c1b96e3
AK
6302executed a memory-mapped I/O instruction which could not be satisfied
6303by kvm. The 'data' member contains the written data if 'is_write' is
6304true, and should be filled by application code otherwise.
6305
6acdb160
CD
6306The 'data' member contains, in its first 'len' bytes, the value as it would
6307appear if the VCPU performed a load or store of the appropriate width directly
6308to the byte array.
6309
106ee47d
MCC
6310.. note::
6311
e1f68169 6312 For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN,
1ae09954
AG
6313 KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding
6314 operations are complete (and guest state is consistent) only after userspace
6315 has re-entered the kernel with KVM_RUN. The kernel side will first finish
e1f68169
DW
6316 incomplete operations and then check for pending signals.
6317
6318 The pending state of the operation is not preserved in state which is
6319 visible to userspace, thus userspace should ensure that the operation is
6320 completed before performing a live migration. Userspace can re-enter the
6321 guest with an unmasked signal pending or with the immediate_exit field set
6322 to complete pending operations without allowing any further instructions
6323 to be executed.
67961344 6324
106ee47d
MCC
6325::
6326
9c1b96e3
AK
6327 /* KVM_EXIT_HYPERCALL */
6328 struct {
6329 __u64 nr;
6330 __u64 args[6];
6331 __u64 ret;
e65733b5 6332 __u64 flags;
9c1b96e3
AK
6333 } hypercall;
6334
d824dff1
OU
6335
6336It is strongly recommended that userspace use ``KVM_EXIT_IO`` (x86) or
6337``KVM_EXIT_MMIO`` (all except s390) to implement functionality that
d56b699d 6338requires a guest to interact with host userspace.
106ee47d
MCC
6339
6340.. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
6341
d824dff1
OU
6342For arm64:
6343----------
6344
821d935c
OU
6345SMCCC exits can be enabled depending on the configuration of the SMCCC
6346filter. See the Documentation/virt/kvm/devices/vm.rst
6347``KVM_ARM_SMCCC_FILTER`` for more details.
6348
d824dff1
OU
6349``nr`` contains the function ID of the guest's SMCCC call. Userspace is
6350expected to use the ``KVM_GET_ONE_REG`` ioctl to retrieve the call
6351parameters from the vCPU's GPRs.
6352
6353Definition of ``flags``:
6354 - ``KVM_HYPERCALL_EXIT_SMC``: Indicates that the guest used the SMC
6355 conduit to initiate the SMCCC call. If this bit is 0 then the guest
6356 used the HVC conduit for the SMCCC call.
6357
0e5c9a9d
MZ
6358 - ``KVM_HYPERCALL_EXIT_16BIT``: Indicates that the guest used a 16bit
6359 instruction to initiate the SMCCC call. If this bit is 0 then the
6360 guest used a 32bit instruction. An AArch64 guest always has this
6361 bit set to 0.
6362
6363At the point of exit, PC points to the instruction immediately following
6364the trapping instruction.
6365
106ee47d 6366::
9c1b96e3
AK
6367
6368 /* KVM_EXIT_TPR_ACCESS */
6369 struct {
6370 __u64 rip;
6371 __u32 is_write;
6372 __u32 pad;
6373 } tpr_access;
6374
6375To be documented (KVM_TPR_ACCESS_REPORTING).
6376
106ee47d
MCC
6377::
6378
9c1b96e3
AK
6379 /* KVM_EXIT_S390_SIEIC */
6380 struct {
6381 __u8 icptcode;
6382 __u64 mask; /* psw upper half */
6383 __u64 addr; /* psw lower half */
6384 __u16 ipa;
6385 __u32 ipb;
6386 } s390_sieic;
6387
6388s390 specific.
6389
106ee47d
MCC
6390::
6391
9c1b96e3 6392 /* KVM_EXIT_S390_RESET */
106ee47d
MCC
6393 #define KVM_S390_RESET_POR 1
6394 #define KVM_S390_RESET_CLEAR 2
6395 #define KVM_S390_RESET_SUBSYSTEM 4
6396 #define KVM_S390_RESET_CPU_INIT 8
6397 #define KVM_S390_RESET_IPL 16
9c1b96e3
AK
6398 __u64 s390_reset_flags;
6399
6400s390 specific.
6401
106ee47d
MCC
6402::
6403
e168bf8d
CO
6404 /* KVM_EXIT_S390_UCONTROL */
6405 struct {
6406 __u64 trans_exc_code;
6407 __u32 pgm_code;
6408 } s390_ucontrol;
6409
6410s390 specific. A page fault has occurred for a user controlled virtual
d56b699d 6411machine (KVM_VM_S390_UNCONTROL) on its host page table that cannot be
e168bf8d
CO
6412resolved by the kernel.
6413The program code and the translation exception code that were placed
6414in the cpu's lowcore are presented here as defined by the z Architecture
6415Principles of Operation Book in the Chapter for Dynamic Address Translation
6416(DAT)
6417
106ee47d
MCC
6418::
6419
9c1b96e3
AK
6420 /* KVM_EXIT_DCR */
6421 struct {
6422 __u32 dcrn;
6423 __u32 data;
6424 __u8 is_write;
6425 } dcr;
6426
ce91ddc4 6427Deprecated - was used for 440 KVM.
9c1b96e3 6428
106ee47d
MCC
6429::
6430
ad0a048b
AG
6431 /* KVM_EXIT_OSI */
6432 struct {
6433 __u64 gprs[32];
6434 } osi;
6435
6436MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
6437hypercalls and exit with this exit struct that contains all the guest gprs.
6438
6439If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
6440Userspace can now handle the hypercall and when it's done modify the gprs as
6441necessary. Upon guest entry all guest GPRs will then be replaced by the values
6442in this struct.
6443
106ee47d
MCC
6444::
6445
de56a948
PM
6446 /* KVM_EXIT_PAPR_HCALL */
6447 struct {
6448 __u64 nr;
6449 __u64 ret;
6450 __u64 args[9];
6451 } papr_hcall;
6452
6453This is used on 64-bit PowerPC when emulating a pSeries partition,
6454e.g. with the 'pseries' machine type in qemu. It occurs when the
6455guest does a hypercall using the 'sc 1' instruction. The 'nr' field
6456contains the hypercall number (from the guest R3), and 'args' contains
6457the arguments (from the guest R4 - R12). Userspace should put the
6458return code in 'ret' and any extra returned values in args[].
6459The possible hypercalls are defined in the Power Architecture Platform
6460Requirements (PAPR) document available from www.power.org (free
6461developer registration required to access it).
6462
106ee47d
MCC
6463::
6464
fa6b7fe9
CH
6465 /* KVM_EXIT_S390_TSCH */
6466 struct {
6467 __u16 subchannel_id;
6468 __u16 subchannel_nr;
6469 __u32 io_int_parm;
6470 __u32 io_int_word;
6471 __u32 ipb;
6472 __u8 dequeued;
6473 } s390_tsch;
6474
6475s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
6476and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
6477interrupt for the target subchannel has been dequeued and subchannel_id,
6478subchannel_nr, io_int_parm and io_int_word contain the parameters for that
6479interrupt. ipb is needed for instruction parameter decoding.
6480
106ee47d
MCC
6481::
6482
1c810636
AG
6483 /* KVM_EXIT_EPR */
6484 struct {
6485 __u32 epr;
6486 } epr;
6487
6488On FSL BookE PowerPC chips, the interrupt controller has a fast patch
6489interrupt acknowledge path to the core. When the core successfully
6490delivers an interrupt, it automatically populates the EPR register with
6491the interrupt vector number and acknowledges the interrupt inside
6492the interrupt controller.
6493
6494In case the interrupt controller lives in user space, we need to do
6495the interrupt acknowledge cycle through it to fetch the next to be
6496delivered interrupt vector using this exit.
6497
6498It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
6499external interrupt has just been delivered into the guest. User space
6500should put the acknowledged interrupt vector into the 'epr' field.
6501
106ee47d
MCC
6502::
6503
8ad6b634
AP
6504 /* KVM_EXIT_SYSTEM_EVENT */
6505 struct {
106ee47d
MCC
6506 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
6507 #define KVM_SYSTEM_EVENT_RESET 2
6508 #define KVM_SYSTEM_EVENT_CRASH 3
7b33a09d 6509 #define KVM_SYSTEM_EVENT_WAKEUP 4
bfbab445 6510 #define KVM_SYSTEM_EVENT_SUSPEND 5
47e8eec8 6511 #define KVM_SYSTEM_EVENT_SEV_TERM 6
8ad6b634 6512 __u32 type;
d495f942
PB
6513 __u32 ndata;
6514 __u64 data[16];
8ad6b634
AP
6515 } system_event;
6516
6517If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
6518a system-level event using some architecture specific mechanism (hypercall
3fbf4207 6519or some special instruction). In case of ARM64, this is triggered using
d495f942 6520HVC instruction based PSCI call from the vcpu.
8ad6b634 6521
d495f942 6522The 'type' field describes the system-level event type.
cf5d3188 6523Valid values for 'type' are:
106ee47d
MCC
6524
6525 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
cf5d3188
CD
6526 VM. Userspace is not obliged to honour this, and if it does honour
6527 this does not need to destroy the VM synchronously (ie it may call
6528 KVM_RUN again before shutdown finally occurs).
106ee47d 6529 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
cf5d3188
CD
6530 As with SHUTDOWN, userspace can choose to ignore the request, or
6531 to schedule the reset to occur in the future and may call KVM_RUN again.
106ee47d 6532 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
2ce79189
AS
6533 has requested a crash condition maintenance. Userspace can choose
6534 to ignore the request, or to gather VM memory core dump and/or
6535 reset/shutdown of the VM.
c24a950e
PG
6536 - KVM_SYSTEM_EVENT_SEV_TERM -- an AMD SEV guest requested termination.
6537 The guest physical address of the guest's GHCB is stored in `data[0]`.
7b33a09d
OU
6538 - KVM_SYSTEM_EVENT_WAKEUP -- the exiting vCPU is in a suspended state and
6539 KVM has recognized a wakeup event. Userspace may honor this event by
6540 marking the exiting vCPU as runnable, or deny it and call KVM_RUN again.
bfbab445
OU
6541 - KVM_SYSTEM_EVENT_SUSPEND -- the guest has requested a suspension of
6542 the VM.
cf5d3188 6543
d495f942
PB
6544If KVM_CAP_SYSTEM_EVENT_DATA is present, the 'data' field can contain
6545architecture specific information for the system-level event. Only
6546the first `ndata` items (possibly zero) of the data array are valid.
34739fd9 6547
d495f942
PB
6548 - for arm64, data[0] is set to KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 if
6549 the guest issued a SYSTEM_RESET2 call according to v1.1 of the PSCI
6550 specification.
6551
6552 - for RISC-V, data[0] is set to the value of the second argument of the
6553 ``sbi_system_reset`` call.
6554
6555Previous versions of Linux defined a `flags` member in this struct. The
6556field is now aliased to `data[0]`. Userspace can assume that it is only
6557written if ndata is greater than 0.
34739fd9 6558
186af6bb
PB
6559For arm/arm64:
6560--------------
6561
6562KVM_SYSTEM_EVENT_SUSPEND exits are enabled with the
6563KVM_CAP_ARM_SYSTEM_SUSPEND VM capability. If a guest invokes the PSCI
6564SYSTEM_SUSPEND function, KVM will exit to userspace with this event
6565type.
6566
6567It is the sole responsibility of userspace to implement the PSCI
6568SYSTEM_SUSPEND call according to ARM DEN0022D.b 5.19 "SYSTEM_SUSPEND".
6569KVM does not change the vCPU's state before exiting to userspace, so
6570the call parameters are left in-place in the vCPU registers.
6571
6572Userspace is _required_ to take action for such an exit. It must
6573either:
6574
6575 - Honor the guest request to suspend the VM. Userspace can request
6576 in-kernel emulation of suspension by setting the calling vCPU's
6577 state to KVM_MP_STATE_SUSPENDED. Userspace must configure the vCPU's
6578 state according to the parameters passed to the PSCI function when
6579 the calling vCPU is resumed. See ARM DEN0022D.b 5.19.1 "Intended use"
6580 for details on the function parameters.
6581
6582 - Deny the guest request to suspend the VM. See ARM DEN0022D.b 5.19.2
6583 "Caller responsibilities" for possible return values.
6584
106ee47d
MCC
6585::
6586
7543a635
SR
6587 /* KVM_EXIT_IOAPIC_EOI */
6588 struct {
6589 __u8 vector;
6590 } eoi;
6591
6592Indicates that the VCPU's in-kernel local APIC received an EOI for a
6593level-triggered IOAPIC interrupt. This exit only triggers when the
6594IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
6595the userspace IOAPIC should process the EOI and retrigger the interrupt if
6596it is still asserted. Vector is the LAPIC interrupt vector for which the
6597EOI was received.
6598
106ee47d
MCC
6599::
6600
db397571 6601 struct kvm_hyperv_exit {
106ee47d
MCC
6602 #define KVM_EXIT_HYPERV_SYNIC 1
6603 #define KVM_EXIT_HYPERV_HCALL 2
f97f5a56 6604 #define KVM_EXIT_HYPERV_SYNDBG 3
db397571 6605 __u32 type;
f7d31e65 6606 __u32 pad1;
db397571
AS
6607 union {
6608 struct {
6609 __u32 msr;
f7d31e65 6610 __u32 pad2;
db397571
AS
6611 __u64 control;
6612 __u64 evt_page;
6613 __u64 msg_page;
6614 } synic;
83326e43
AS
6615 struct {
6616 __u64 input;
6617 __u64 result;
6618 __u64 params[2];
6619 } hcall;
f97f5a56
JD
6620 struct {
6621 __u32 msr;
6622 __u32 pad2;
6623 __u64 control;
6624 __u64 status;
6625 __u64 send_page;
6626 __u64 recv_page;
6627 __u64 pending_page;
6628 } syndbg;
db397571
AS
6629 } u;
6630 };
6631 /* KVM_EXIT_HYPERV */
6632 struct kvm_hyperv_exit hyperv;
106ee47d 6633
db397571
AS
6634Indicates that the VCPU exits into userspace to process some tasks
6635related to Hyper-V emulation.
106ee47d 6636
db397571 6637Valid values for 'type' are:
106ee47d
MCC
6638
6639 - KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
6640
db397571
AS
6641Hyper-V SynIC state change. Notification is used to remap SynIC
6642event/message pages and to enable/disable SynIC messages/events processing
6643in userspace.
6644
f97f5a56
JD
6645 - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about
6646
6647Hyper-V Synthetic debugger state change. Notification is used to either update
6648the pending_page location or to send a control command (send the buffer located
6649in send_page or recv a buffer to recv_page).
6650
106ee47d
MCC
6651::
6652
c726200d
CD
6653 /* KVM_EXIT_ARM_NISV */
6654 struct {
6655 __u64 esr_iss;
6656 __u64 fault_ipa;
6657 } arm_nisv;
6658
3fbf4207 6659Used on arm64 systems. If a guest accesses memory not in a memslot,
c726200d
CD
6660KVM will typically return to userspace and ask it to do MMIO emulation on its
6661behalf. However, for certain classes of instructions, no instruction decode
6662(direction, length of memory access) is provided, and fetching and decoding
6663the instruction from the VM is overly complicated to live in the kernel.
6664
6665Historically, when this situation occurred, KVM would print a warning and kill
6666the VM. KVM assumed that if the guest accessed non-memslot memory, it was
6667trying to do I/O, which just couldn't be emulated, and the warning message was
6668phrased accordingly. However, what happened more often was that a guest bug
6669caused access outside the guest memory areas which should lead to a more
6670meaningful warning message and an external abort in the guest, if the access
6671did not fall within an I/O window.
6672
6673Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable
6674this capability at VM creation. Once this is done, these types of errors will
6675instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from
3fbf4207
OU
6676the ESR_EL2 in the esr_iss field, and the faulting IPA in the fault_ipa field.
6677Userspace can either fix up the access if it's actually an I/O access by
6678decoding the instruction from guest memory (if it's very brave) and continue
6679executing the guest, or it can decide to suspend, dump, or restart the guest.
c726200d
CD
6680
6681Note that KVM does not skip the faulting instruction as it does for
6682KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state
6683if it decides to decode and emulate the instruction.
6684
1ae09954
AG
6685::
6686
6687 /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */
6688 struct {
6689 __u8 error; /* user -> kernel */
6690 __u8 pad[7];
6691 __u32 reason; /* kernel -> user */
6692 __u32 index; /* kernel -> user */
6693 __u64 data; /* kernel <-> user */
6694 } msr;
6695
6696Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is
6697enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code
1f158147 6698may instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR
1ae09954
AG
6699exit for writes.
6700
1f158147
SC
6701The "reason" field specifies why the MSR interception occurred. Userspace will
6702only receive MSR exits when a particular reason was requested during through
1ae09954
AG
6703ENABLE_CAP. Currently valid exit reasons are:
6704
549a715b
SC
6705============================ ========================================
6706 KVM_MSR_EXIT_REASON_UNKNOWN access to MSR that is unknown to KVM
6707 KVM_MSR_EXIT_REASON_INVAL access to invalid MSRs or reserved bits
6708 KVM_MSR_EXIT_REASON_FILTER access blocked by KVM_X86_SET_MSR_FILTER
6709============================ ========================================
1ae09954 6710
1f158147
SC
6711For KVM_EXIT_X86_RDMSR, the "index" field tells userspace which MSR the guest
6712wants to read. To respond to this request with a successful read, userspace
1ae09954
AG
6713writes the respective data into the "data" field and must continue guest
6714execution to ensure the read data is transferred into guest register state.
6715
1f158147 6716If the RDMSR request was unsuccessful, userspace indicates that with a "1" in
1ae09954
AG
6717the "error" field. This will inject a #GP into the guest when the VCPU is
6718executed again.
6719
1f158147
SC
6720For KVM_EXIT_X86_WRMSR, the "index" field tells userspace which MSR the guest
6721wants to write. Once finished processing the event, userspace must continue
6722vCPU execution. If the MSR write was unsuccessful, userspace also sets the
1ae09954
AG
6723"error" field to "1".
6724
b93d2ec3
SC
6725See KVM_X86_SET_MSR_FILTER for details on the interaction with MSR filtering.
6726
e1f68169
DW
6727::
6728
6729
6730 struct kvm_xen_exit {
6731 #define KVM_EXIT_XEN_HCALL 1
6732 __u32 type;
6733 union {
6734 struct {
6735 __u32 longmode;
6736 __u32 cpl;
6737 __u64 input;
6738 __u64 result;
6739 __u64 params[6];
6740 } hcall;
6741 } u;
6742 };
6743 /* KVM_EXIT_XEN */
6744 struct kvm_hyperv_exit xen;
6745
6746Indicates that the VCPU exits into userspace to process some tasks
6747related to Xen emulation.
6748
6749Valid values for 'type' are:
6750
6751 - KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall.
6752 Userspace is expected to place the hypercall result into the appropriate
6753 field before invoking KVM_RUN again.
6754
da40d858
AP
6755::
6756
6757 /* KVM_EXIT_RISCV_SBI */
6758 struct {
6759 unsigned long extension_id;
6760 unsigned long function_id;
6761 unsigned long args[6];
6762 unsigned long ret[2];
6763 } riscv_sbi;
c1be1ef1 6764
da40d858
AP
6765If exit reason is KVM_EXIT_RISCV_SBI then it indicates that the VCPU has
6766done a SBI call which is not handled by KVM RISC-V kernel module. The details
6767of the SBI call are available in 'riscv_sbi' member of kvm_run structure. The
6768'extension_id' field of 'riscv_sbi' represents SBI extension ID whereas the
6769'function_id' field represents function ID of given SBI extension. The 'args'
6770array field of 'riscv_sbi' represents parameters for the SBI call and 'ret'
6771array field represents return values. The userspace should update the return
6772values of SBI call before resuming the VCPU. For more details on RISC-V SBI
6773spec refer, https://github.com/riscv/riscv-sbi-doc.
6774
2f4073e0
TX
6775::
6776
6777 /* KVM_EXIT_NOTIFY */
6778 struct {
6779 #define KVM_NOTIFY_CONTEXT_INVALID (1 << 0)
6780 __u32 flags;
6781 } notify;
6782
6783Used on x86 systems. When the VM capability KVM_CAP_X86_NOTIFY_VMEXIT is
6784enabled, a VM exit generated if no event window occurs in VM non-root mode
6785for a specified amount of time. Once KVM_X86_NOTIFY_VMEXIT_USER is set when
6786enabling the cap, it would exit to userspace with the exit reason
6787KVM_EXIT_NOTIFY for further handling. The "flags" field contains more
6788detailed info.
6789
6790The valid value for 'flags' is:
6791
6792 - KVM_NOTIFY_CONTEXT_INVALID -- the VM context is corrupted and not valid
6793 in VMCS. It would run into unknown result if resume the target VM.
6794
106ee47d
MCC
6795::
6796
9c1b96e3
AK
6797 /* Fix the size of the union. */
6798 char padding[256];
6799 };
b9e5dc8d
CB
6800
6801 /*
6802 * shared registers between kvm and userspace.
6803 * kvm_valid_regs specifies the register classes set by the host
6804 * kvm_dirty_regs specified the register classes dirtied by userspace
6805 * struct kvm_sync_regs is architecture specific, as well as the
6806 * bits for kvm_valid_regs and kvm_dirty_regs
6807 */
6808 __u64 kvm_valid_regs;
6809 __u64 kvm_dirty_regs;
6810 union {
6811 struct kvm_sync_regs regs;
7b7e3952 6812 char padding[SYNC_REGS_SIZE_BYTES];
b9e5dc8d
CB
6813 } s;
6814
6815If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
6816certain guest registers without having to call SET/GET_*REGS. Thus we can
6817avoid some system call overhead if userspace has to handle the exit.
6818Userspace can query the validity of the structure by checking
6819kvm_valid_regs for specific bits. These bits are architecture specific
6820and usually define the validity of a groups of registers. (e.g. one bit
106ee47d 6821for general purpose registers)
b9e5dc8d 6822
d8482c0d
DH
6823Please note that the kernel is allowed to use the kvm_run structure as the
6824primary storage for certain register types. Therefore, the kernel may use the
6825values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
6826
9c15bb1d 6827
699a0ea0 68286. Capabilities that can be enabled on vCPUs
106ee47d 6829============================================
821246a5 6830
0907c855
CH
6831There are certain capabilities that change the behavior of the virtual CPU or
6832the virtual machine when enabled. To enable them, please see section 4.37.
6833Below you can find a list of capabilities and what their effect on the vCPU or
6834the virtual machine is when enabling them.
821246a5
AG
6835
6836The following information is provided along with the description:
6837
106ee47d
MCC
6838 Architectures:
6839 which instruction set architectures provide this ioctl.
821246a5
AG
6840 x86 includes both i386 and x86_64.
6841
106ee47d
MCC
6842 Target:
6843 whether this is a per-vcpu or per-vm capability.
0907c855 6844
106ee47d
MCC
6845 Parameters:
6846 what parameters are accepted by the capability.
821246a5 6847
106ee47d
MCC
6848 Returns:
6849 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
821246a5
AG
6850 are not detailed, but errors with specific meanings are.
6851
414fa985 6852
821246a5 68536.1 KVM_CAP_PPC_OSI
106ee47d 6854-------------------
821246a5 6855
106ee47d
MCC
6856:Architectures: ppc
6857:Target: vcpu
6858:Parameters: none
6859:Returns: 0 on success; -1 on error
821246a5
AG
6860
6861This capability enables interception of OSI hypercalls that otherwise would
6862be treated as normal system calls to be injected into the guest. OSI hypercalls
6863were invented by Mac-on-Linux to have a standardized communication mechanism
6864between the guest and the host.
6865
6866When this capability is enabled, KVM_EXIT_OSI can occur.
6867
414fa985 6868
821246a5 68696.2 KVM_CAP_PPC_PAPR
106ee47d 6870--------------------
821246a5 6871
106ee47d
MCC
6872:Architectures: ppc
6873:Target: vcpu
6874:Parameters: none
6875:Returns: 0 on success; -1 on error
821246a5
AG
6876
6877This capability enables interception of PAPR hypercalls. PAPR hypercalls are
6878done using the hypercall instruction "sc 1".
6879
6880It also sets the guest privilege level to "supervisor" mode. Usually the guest
6881runs in "hypervisor" privilege mode with a few missing features.
6882
6883In addition to the above, it changes the semantics of SDR1. In this mode, the
6884HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
6885HTAB invisible to the guest.
6886
6887When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
dc83b8bc 6888
414fa985 6889
dc83b8bc 68906.3 KVM_CAP_SW_TLB
106ee47d
MCC
6891------------------
6892
6893:Architectures: ppc
6894:Target: vcpu
6895:Parameters: args[0] is the address of a struct kvm_config_tlb
6896:Returns: 0 on success; -1 on error
dc83b8bc 6897
106ee47d 6898::
dc83b8bc 6899
106ee47d 6900 struct kvm_config_tlb {
dc83b8bc
SW
6901 __u64 params;
6902 __u64 array;
6903 __u32 mmu_type;
6904 __u32 array_len;
106ee47d 6905 };
dc83b8bc
SW
6906
6907Configures the virtual CPU's TLB array, establishing a shared memory area
6908between userspace and KVM. The "params" and "array" fields are userspace
6909addresses of mmu-type-specific data structures. The "array_len" field is an
6910safety mechanism, and should be set to the size in bytes of the memory that
6911userspace has reserved for the array. It must be at least the size dictated
6912by "mmu_type" and "params".
6913
6914While KVM_RUN is active, the shared region is under control of KVM. Its
6915contents are undefined, and any modification by userspace results in
6916boundedly undefined behavior.
6917
6918On return from KVM_RUN, the shared region will reflect the current state of
6919the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
6920to tell KVM which entries have been changed, prior to calling KVM_RUN again
6921on this vcpu.
6922
6923For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
106ee47d 6924
dc83b8bc
SW
6925 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
6926 - The "array" field points to an array of type "struct
6927 kvm_book3e_206_tlb_entry".
6928 - The array consists of all entries in the first TLB, followed by all
6929 entries in the second TLB.
6930 - Within a TLB, entries are ordered first by increasing set number. Within a
6931 set, entries are ordered by way (increasing ESEL).
6932 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
6933 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
6934 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
6935 hardware ignores this value for TLB0.
fa6b7fe9
CH
6936
69376.4 KVM_CAP_S390_CSS_SUPPORT
106ee47d 6938----------------------------
fa6b7fe9 6939
106ee47d
MCC
6940:Architectures: s390
6941:Target: vcpu
6942:Parameters: none
6943:Returns: 0 on success; -1 on error
fa6b7fe9
CH
6944
6945This capability enables support for handling of channel I/O instructions.
6946
6947TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
6948handled in-kernel, while the other I/O instructions are passed to userspace.
6949
6950When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
6951SUBCHANNEL intercepts.
1c810636 6952
0907c855
CH
6953Note that even though this capability is enabled per-vcpu, the complete
6954virtual machine is affected.
6955
1c810636 69566.5 KVM_CAP_PPC_EPR
106ee47d 6957-------------------
1c810636 6958
106ee47d
MCC
6959:Architectures: ppc
6960:Target: vcpu
6961:Parameters: args[0] defines whether the proxy facility is active
6962:Returns: 0 on success; -1 on error
1c810636
AG
6963
6964This capability enables or disables the delivery of interrupts through the
6965external proxy facility.
6966
6967When enabled (args[0] != 0), every time the guest gets an external interrupt
6968delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
6969to receive the topmost interrupt vector.
6970
6971When disabled (args[0] == 0), behavior is as if this facility is unsupported.
6972
6973When this capability is enabled, KVM_EXIT_EPR can occur.
eb1e4f43
SW
6974
69756.6 KVM_CAP_IRQ_MPIC
106ee47d 6976--------------------
eb1e4f43 6977
106ee47d
MCC
6978:Architectures: ppc
6979:Parameters: args[0] is the MPIC device fd;
6980 args[1] is the MPIC CPU number for this vcpu
eb1e4f43
SW
6981
6982This capability connects the vcpu to an in-kernel MPIC device.
5975a2e0
PM
6983
69846.7 KVM_CAP_IRQ_XICS
106ee47d 6985--------------------
5975a2e0 6986
106ee47d
MCC
6987:Architectures: ppc
6988:Target: vcpu
6989:Parameters: args[0] is the XICS device fd;
6990 args[1] is the XICS CPU number (server ID) for this vcpu
5975a2e0
PM
6991
6992This capability connects the vcpu to an in-kernel XICS device.
8a366a4b
CH
6993
69946.8 KVM_CAP_S390_IRQCHIP
106ee47d 6995------------------------
8a366a4b 6996
106ee47d
MCC
6997:Architectures: s390
6998:Target: vm
6999:Parameters: none
8a366a4b
CH
7000
7001This capability enables the in-kernel irqchip for s390. Please refer to
7002"4.24 KVM_CREATE_IRQCHIP" for details.
699a0ea0 7003
5fafd874 70046.9 KVM_CAP_MIPS_FPU
106ee47d 7005--------------------
5fafd874 7006
106ee47d
MCC
7007:Architectures: mips
7008:Target: vcpu
7009:Parameters: args[0] is reserved for future use (should be 0).
5fafd874
JH
7010
7011This capability allows the use of the host Floating Point Unit by the guest. It
7012allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
106ee47d
MCC
7013done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be
7014accessed (depending on the current guest FPU register mode), and the Status.FR,
5fafd874
JH
7015Config5.FRE bits are accessible via the KVM API and also from the guest,
7016depending on them being supported by the FPU.
7017
d952bd07 70186.10 KVM_CAP_MIPS_MSA
106ee47d 7019---------------------
d952bd07 7020
106ee47d
MCC
7021:Architectures: mips
7022:Target: vcpu
7023:Parameters: args[0] is reserved for future use (should be 0).
d952bd07
JH
7024
7025This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
7026It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
106ee47d
MCC
7027Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*``
7028registers can be accessed, and the Config5.MSAEn bit is accessible via the
7029KVM API and also from the guest.
d952bd07 7030
01643c51 70316.74 KVM_CAP_SYNC_REGS
106ee47d
MCC
7032----------------------
7033
7034:Architectures: s390, x86
7035:Target: s390: always enabled, x86: vcpu
7036:Parameters: none
7037:Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
7038 sets are supported
7039 (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
01643c51
KH
7040
7041As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
7042KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
7043without having to call SET/GET_*REGS". This reduces overhead by eliminating
7044repeated ioctl calls for setting and/or getting register values. This is
7045particularly important when userspace is making synchronous guest state
7046modifications, e.g. when emulating and/or intercepting instructions in
7047userspace.
7048
7049For s390 specifics, please refer to the source code.
7050
7051For x86:
106ee47d 7052
01643c51
KH
7053- the register sets to be copied out to kvm_run are selectable
7054 by userspace (rather that all sets being copied out for every exit).
7055- vcpu_events are available in addition to regs and sregs.
7056
7057For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
7058function as an input bit-array field set by userspace to indicate the
7059specific register sets to be copied out on the next exit.
7060
7061To indicate when userspace has modified values that should be copied into
7062the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
7063This is done using the same bitflags as for the 'kvm_valid_regs' field.
7064If the dirty bit is not set, then the register set values will not be copied
7065into the vCPU even if they've been modified.
7066
7067Unused bitfields in the bitarrays must be set to zero.
7068
106ee47d
MCC
7069::
7070
7071 struct kvm_sync_regs {
01643c51
KH
7072 struct kvm_regs regs;
7073 struct kvm_sregs sregs;
7074 struct kvm_vcpu_events events;
106ee47d 7075 };
01643c51 7076
eacc56bb 70776.75 KVM_CAP_PPC_IRQ_XIVE
106ee47d 7078-------------------------
eacc56bb 7079
106ee47d
MCC
7080:Architectures: ppc
7081:Target: vcpu
7082:Parameters: args[0] is the XIVE device fd;
7083 args[1] is the XIVE CPU number (server ID) for this vcpu
eacc56bb
CLG
7084
7085This capability connects the vcpu to an in-kernel XIVE device.
7086
699a0ea0 70877. Capabilities that can be enabled on VMs
106ee47d 7088==========================================
699a0ea0
PM
7089
7090There are certain capabilities that change the behavior of the virtual
7091machine when enabled. To enable them, please see section 4.37. Below
7092you can find a list of capabilities and what their effect on the VM
7093is when enabling them.
7094
7095The following information is provided along with the description:
7096
106ee47d
MCC
7097 Architectures:
7098 which instruction set architectures provide this ioctl.
699a0ea0
PM
7099 x86 includes both i386 and x86_64.
7100
106ee47d
MCC
7101 Parameters:
7102 what parameters are accepted by the capability.
699a0ea0 7103
106ee47d
MCC
7104 Returns:
7105 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
699a0ea0
PM
7106 are not detailed, but errors with specific meanings are.
7107
7108
71097.1 KVM_CAP_PPC_ENABLE_HCALL
106ee47d 7110----------------------------
699a0ea0 7111
106ee47d
MCC
7112:Architectures: ppc
7113:Parameters: args[0] is the sPAPR hcall number;
7114 args[1] is 0 to disable, 1 to enable in-kernel handling
699a0ea0
PM
7115
7116This capability controls whether individual sPAPR hypercalls (hcalls)
7117get handled by the kernel or not. Enabling or disabling in-kernel
7118handling of an hcall is effective across the VM. On creation, an
7119initial set of hcalls are enabled for in-kernel handling, which
7120consists of those hcalls for which in-kernel handlers were implemented
7121before this capability was implemented. If disabled, the kernel will
7122not to attempt to handle the hcall, but will always exit to userspace
7123to handle it. Note that it may not make sense to enable some and
7124disable others of a group of related hcalls, but KVM does not prevent
7125userspace from doing that.
ae2113a4
PM
7126
7127If the hcall number specified is not one that has an in-kernel
7128implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
7129error.
2444b352
DH
7130
71317.2 KVM_CAP_S390_USER_SIGP
106ee47d 7132--------------------------
2444b352 7133
106ee47d
MCC
7134:Architectures: s390
7135:Parameters: none
2444b352
DH
7136
7137This capability controls which SIGP orders will be handled completely in user
7138space. With this capability enabled, all fast orders will be handled completely
7139in the kernel:
106ee47d 7140
2444b352
DH
7141- SENSE
7142- SENSE RUNNING
7143- EXTERNAL CALL
7144- EMERGENCY SIGNAL
7145- CONDITIONAL EMERGENCY SIGNAL
7146
7147All other orders will be handled completely in user space.
7148
7149Only privileged operation exceptions will be checked for in the kernel (or even
7150in the hardware prior to interception). If this capability is not enabled, the
7151old way of handling SIGP orders is used (partially in kernel and user space).
68c55750
EF
7152
71537.3 KVM_CAP_S390_VECTOR_REGISTERS
106ee47d 7154---------------------------------
68c55750 7155
106ee47d
MCC
7156:Architectures: s390
7157:Parameters: none
7158:Returns: 0 on success, negative value on error
68c55750
EF
7159
7160Allows use of the vector registers introduced with z13 processor, and
7161provides for the synchronization between host and user space. Will
7162return -EINVAL if the machine does not support vectors.
e44fc8c9
ET
7163
71647.4 KVM_CAP_S390_USER_STSI
106ee47d 7165--------------------------
e44fc8c9 7166
106ee47d
MCC
7167:Architectures: s390
7168:Parameters: none
e44fc8c9
ET
7169
7170This capability allows post-handlers for the STSI instruction. After
7171initial handling in the kernel, KVM exits to user space with
7172KVM_EXIT_S390_STSI to allow user space to insert further data.
7173
7174Before exiting to userspace, kvm handlers should fill in s390_stsi field of
106ee47d
MCC
7175vcpu->run::
7176
7177 struct {
e44fc8c9
ET
7178 __u64 addr;
7179 __u8 ar;
7180 __u8 reserved;
7181 __u8 fc;
7182 __u8 sel1;
7183 __u16 sel2;
106ee47d 7184 } s390_stsi;
e44fc8c9 7185
106ee47d
MCC
7186 @addr - guest address of STSI SYSIB
7187 @fc - function code
7188 @sel1 - selector 1
7189 @sel2 - selector 2
7190 @ar - access register number
e44fc8c9
ET
7191
7192KVM handlers should exit to userspace with rc = -EREMOTE.
e928e9cb 7193
49df6397 71947.5 KVM_CAP_SPLIT_IRQCHIP
106ee47d 7195-------------------------
49df6397 7196
106ee47d
MCC
7197:Architectures: x86
7198:Parameters: args[0] - number of routes reserved for userspace IOAPICs
7199:Returns: 0 on success, -1 on error
49df6397
SR
7200
7201Create a local apic for each processor in the kernel. This can be used
7202instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
7203IOAPIC and PIC (and also the PIT, even though this has to be enabled
7204separately).
7205
b053b2ae
SR
7206This capability also enables in kernel routing of interrupt requests;
7207when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
7208used in the IRQ routing table. The first args[0] MSI routes are reserved
7209for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
7210a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
49df6397
SR
7211
7212Fails if VCPU has already been created, or if the irqchip is already in the
7213kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
7214
051c87f7 72157.6 KVM_CAP_S390_RI
106ee47d 7216-------------------
051c87f7 7217
106ee47d
MCC
7218:Architectures: s390
7219:Parameters: none
051c87f7
DH
7220
7221Allows use of runtime-instrumentation introduced with zEC12 processor.
7222Will return -EINVAL if the machine does not support runtime-instrumentation.
7223Will return -EBUSY if a VCPU has already been created.
e928e9cb 7224
37131313 72257.7 KVM_CAP_X2APIC_API
106ee47d 7226----------------------
37131313 7227
106ee47d
MCC
7228:Architectures: x86
7229:Parameters: args[0] - features that should be enabled
7230:Returns: 0 on success, -EINVAL when args[0] contains invalid features
37131313 7231
106ee47d 7232Valid feature flags in args[0] are::
37131313 7233
106ee47d
MCC
7234 #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
7235 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
37131313
RK
7236
7237Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
7238KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
7239allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
7240respective sections.
7241
c519265f
RK
7242KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
7243in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
7244as a broadcast even in x2APIC mode in order to support physical x2APIC
7245without interrupt remapping. This is undesirable in logical mode,
7246where 0xff represents CPUs 0-7 in cluster 0.
37131313 7247
6502a34c 72487.8 KVM_CAP_S390_USER_INSTR0
106ee47d 7249----------------------------
6502a34c 7250
106ee47d
MCC
7251:Architectures: s390
7252:Parameters: none
6502a34c
DH
7253
7254With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
7255be intercepted and forwarded to user space. User space can use this
7256mechanism e.g. to realize 2-byte software breakpoints. The kernel will
7257not inject an operating exception for these instructions, user space has
7258to take care of that.
7259
7260This capability can be enabled dynamically even if VCPUs were already
7261created and are running.
37131313 7262
4e0b1ab7 72637.9 KVM_CAP_S390_GS
106ee47d 7264-------------------
4e0b1ab7 7265
106ee47d
MCC
7266:Architectures: s390
7267:Parameters: none
7268:Returns: 0 on success; -EINVAL if the machine does not support
7269 guarded storage; -EBUSY if a VCPU has already been created.
4e0b1ab7
FZ
7270
7271Allows use of guarded storage for the KVM guest.
7272
47a4693e 72737.10 KVM_CAP_S390_AIS
106ee47d 7274---------------------
47a4693e 7275
106ee47d
MCC
7276:Architectures: s390
7277:Parameters: none
47a4693e
YMZ
7278
7279Allow use of adapter-interruption suppression.
106ee47d 7280:Returns: 0 on success; -EBUSY if a VCPU has already been created.
47a4693e 7281
3c313524 72827.11 KVM_CAP_PPC_SMT
106ee47d 7283--------------------
3c313524 7284
106ee47d
MCC
7285:Architectures: ppc
7286:Parameters: vsmt_mode, flags
3c313524
PM
7287
7288Enabling this capability on a VM provides userspace with a way to set
7289the desired virtual SMT mode (i.e. the number of virtual CPUs per
7290virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
7291between 1 and 8. On POWER8, vsmt_mode must also be no greater than
7292the number of threads per subcore for the host. Currently flags must
7293be 0. A successful call to enable this capability will result in
7294vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
7295subsequently queried for the VM. This capability is only supported by
7296HV KVM, and can only be set before any VCPUs have been created.
2ed4f9dd
PM
7297The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
7298modes are available.
3c313524 7299
134764ed 73007.12 KVM_CAP_PPC_FWNMI
106ee47d 7301----------------------
134764ed 7302
106ee47d
MCC
7303:Architectures: ppc
7304:Parameters: none
134764ed
AP
7305
7306With this capability a machine check exception in the guest address
7307space will cause KVM to exit the guest with NMI exit reason. This
7308enables QEMU to build error log and branch to guest kernel registered
7309machine check handling routine. Without this capability KVM will
7310branch to guests' 0x200 interrupt vector.
7311
4d5422ce 73127.13 KVM_CAP_X86_DISABLE_EXITS
106ee47d 7313------------------------------
4d5422ce 7314
106ee47d
MCC
7315:Architectures: x86
7316:Parameters: args[0] defines which exits are disabled
7317:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
4d5422ce 7318
106ee47d 7319Valid bits in args[0] are::
4d5422ce 7320
106ee47d
MCC
7321 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
7322 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
7323 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
7324 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
4d5422ce
WL
7325
7326Enabling this capability on a VM provides userspace with a way to no
7327longer intercept some instructions for improved latency in some
7328workloads, and is suggested when vCPUs are associated to dedicated
7329physical CPUs. More bits can be added in the future; userspace can
7330just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
7331all such vmexits.
7332
caa057a2 7333Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
4d5422ce 7334
a4499382 73357.14 KVM_CAP_S390_HPAGE_1M
106ee47d 7336--------------------------
a4499382 7337
106ee47d
MCC
7338:Architectures: s390
7339:Parameters: none
7340:Returns: 0 on success, -EINVAL if hpage module parameter was not set
7341 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
7342 flag set
a4499382
JF
7343
7344With this capability the KVM support for memory backing with 1m pages
7345through hugetlbfs can be enabled for a VM. After the capability is
7346enabled, cmma can't be enabled anymore and pfmfi and the storage key
7347interpretation are disabled. If cmma has already been enabled or the
7348hpage module parameter is not set to 1, -EINVAL is returned.
7349
7350While it is generally possible to create a huge page backed VM without
7351this capability, the VM will not be able to run.
7352
c4f55198 73537.15 KVM_CAP_MSR_PLATFORM_INFO
106ee47d 7354------------------------------
6fbbde9a 7355
106ee47d
MCC
7356:Architectures: x86
7357:Parameters: args[0] whether feature should be enabled or not
6fbbde9a
DS
7358
7359With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
7360a #GP would be raised when the guest tries to access. Currently, this
7361capability does not enable write permissions of this MSR for the guest.
7362
aa069a99 73637.16 KVM_CAP_PPC_NESTED_HV
106ee47d 7364--------------------------
aa069a99 7365
106ee47d
MCC
7366:Architectures: ppc
7367:Parameters: none
7368:Returns: 0 on success, -EINVAL when the implementation doesn't support
7369 nested-HV virtualization.
aa069a99
PM
7370
7371HV-KVM on POWER9 and later systems allows for "nested-HV"
7372virtualization, which provides a way for a guest VM to run guests that
7373can run using the CPU's supervisor mode (privileged non-hypervisor
7374state). Enabling this capability on a VM depends on the CPU having
7375the necessary functionality and on the facility being enabled with a
7376kvm-hv module parameter.
7377
c4f55198 73787.17 KVM_CAP_EXCEPTION_PAYLOAD
106ee47d 7379------------------------------
c4f55198 7380
106ee47d
MCC
7381:Architectures: x86
7382:Parameters: args[0] whether feature should be enabled or not
c4f55198
JM
7383
7384With this capability enabled, CR2 will not be modified prior to the
7385emulated VM-exit when L1 intercepts a #PF exception that occurs in
7386L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
7387the emulated VM-exit when L1 intercepts a #DB exception that occurs in
7388L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
7389#DB) exception for L2, exception.has_payload will be set and the
7390faulting address (or the new DR6 bits*) will be reported in the
7391exception_payload field. Similarly, when userspace injects a #PF (or
7392#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
106ee47d
MCC
7393exception.has_payload and to put the faulting address - or the new DR6
7394bits\ [#]_ - in the exception_payload field.
c4f55198
JM
7395
7396This capability also enables exception.pending in struct
7397kvm_vcpu_events, which allows userspace to distinguish between pending
7398and injected exceptions.
7399
7400
106ee47d
MCC
7401.. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception
7402 will clear DR6.RTM.
c4f55198 7403
d7547c55 74047.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
752b8a9b 7405--------------------------------------
2a31b9db 7406
3fbf4207 7407:Architectures: x86, arm64, mips
106ee47d 7408:Parameters: args[0] whether feature should be enabled or not
2a31b9db 7409
3c9bd400
JZ
7410Valid flags are::
7411
7412 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0)
7413 #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1)
7414
7415With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not
7416automatically clear and write-protect all pages that are returned as dirty.
2a31b9db
PB
7417Rather, userspace will have to do this operation separately using
7418KVM_CLEAR_DIRTY_LOG.
7419
7420At the cost of a slightly more complicated operation, this provides better
7421scalability and responsiveness for two reasons. First,
7422KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
7423than requiring to sync a full memslot; this ensures that KVM does not
7424take spinlocks for an extended period of time. Second, in some cases a
7425large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
7426userspace actually using the data in the page. Pages can be modified
3c9bd400 7427during this time, which is inefficient for both the guest and userspace:
2a31b9db
PB
7428the guest will incur a higher penalty due to write protection faults,
7429while userspace can see false reports of dirty pages. Manual reprotection
7430helps reducing this time, improving guest performance and reducing the
7431number of dirty log false positives.
7432
3c9bd400
JZ
7433With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap
7434will be initialized to 1 when created. This also improves performance because
7435dirty logging can be enabled gradually in small chunks on the first call
7436to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on
7437KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
c862626e 7438x86 and arm64 for now).
3c9bd400 7439
d7547c55
PX
7440KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
7441KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make
7442it hard or impossible to use it correctly. The availability of
7443KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed.
7444Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
2a31b9db 7445
9a5788c6
PM
74467.19 KVM_CAP_PPC_SECURE_GUEST
7447------------------------------
7448
7449:Architectures: ppc
7450
7451This capability indicates that KVM is running on a host that has
7452ultravisor firmware and thus can support a secure guest. On such a
7453system, a guest can ask the ultravisor to make it a secure guest,
7454one whose memory is inaccessible to the host except for pages which
7455are explicitly requested to be shared with the host. The ultravisor
7456notifies KVM when a guest requests to become a secure guest, and KVM
7457has the opportunity to veto the transition.
7458
7459If present, this capability can be enabled for a VM, meaning that KVM
7460will allow the transition to secure guest mode. Otherwise KVM will
7461veto the transition.
7462
acd05785
DM
74637.20 KVM_CAP_HALT_POLL
7464----------------------
7465
7466:Architectures: all
7467:Target: VM
7468:Parameters: args[0] is the maximum poll time in nanoseconds
7469:Returns: 0 on success; -1 on error
7470
34e30ebb
DM
7471KVM_CAP_HALT_POLL overrides the kvm.halt_poll_ns module parameter to set the
7472maximum halt-polling time for all vCPUs in the target VM. This capability can
7473be invoked at any time and any number of times to dynamically change the
7474maximum halt-polling time.
7475
7476See Documentation/virt/kvm/halt-polling.rst for more information on halt
7477polling.
acd05785 7478
1ae09954
AG
74797.21 KVM_CAP_X86_USER_SPACE_MSR
7480-------------------------------
7481
7482:Architectures: x86
7483:Target: VM
7484:Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report
7485:Returns: 0 on success; -1 on error
7486
1f158147
SC
7487This capability allows userspace to intercept RDMSR and WRMSR instructions if
7488access to an MSR is denied. By default, KVM injects #GP on denied accesses.
1ae09954
AG
7489
7490When a guest requests to read or write an MSR, KVM may not implement all MSRs
7491that are relevant to a respective system. It also does not differentiate by
7492CPU type.
7493
1f158147 7494To allow more fine grained control over MSR handling, userspace may enable
1ae09954 7495this capability. With it enabled, MSR accesses that match the mask specified in
1f158147
SC
7496args[0] and would trigger a #GP inside the guest will instead trigger
7497KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications. Userspace
7498can then implement model specific MSR handling and/or user notifications
7499to inform a user that an MSR was not emulated/virtualized by KVM.
7500
7501The valid mask flags are:
7502
549a715b
SC
7503============================ ===============================================
7504 KVM_MSR_EXIT_REASON_UNKNOWN intercept accesses to unknown (to KVM) MSRs
7505 KVM_MSR_EXIT_REASON_INVAL intercept accesses that are architecturally
7506 invalid according to the vCPU model and/or mode
7507 KVM_MSR_EXIT_REASON_FILTER intercept accesses that are denied by userspace
7508 via KVM_X86_SET_MSR_FILTER
7509============================ ===============================================
1ae09954 7510
c32b1b89
CQ
75117.22 KVM_CAP_X86_BUS_LOCK_EXIT
7512-------------------------------
7513
7514:Architectures: x86
7515:Target: VM
7516:Parameters: args[0] defines the policy used when bus locks detected in guest
7517:Returns: 0 on success, -EINVAL when args[0] contains invalid bits
7518
7519Valid bits in args[0] are::
7520
7521 #define KVM_BUS_LOCK_DETECTION_OFF (1 << 0)
7522 #define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1)
7523
7524Enabling this capability on a VM provides userspace with a way to select
7525a policy to handle the bus locks detected in guest. Userspace can obtain
7526the supported modes from the result of KVM_CHECK_EXTENSION and define it
7527through the KVM_ENABLE_CAP.
7528
7529KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
7530currently and mutually exclusive with each other. More bits can be added in
7531the future.
7532
7533With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
7534so that no additional actions are needed. This is the default mode.
7535
7536With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
7537in VM. KVM just exits to userspace when handling them. Userspace can enforce
7538its own throttling or other policy based mitigations.
7539
7540This capability is aimed to address the thread that VM can exploit bus locks to
7541degree the performance of the whole system. Once the userspace enable this
7542capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
7543KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
7544the bus lock vm exit can be preempted by a higher priority VM exit, the exit
7545notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
7546KVM_RUN_BUS_LOCK flag is used to distinguish between them.
7547
7d2cdad0 75487.23 KVM_CAP_PPC_DAWR1
d9a47eda
RB
7549----------------------
7550
7551:Architectures: ppc
7552:Parameters: none
7553:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
7554
7555This capability can be used to check / enable 2nd DAWR feature provided
7556by POWER10 processor.
7557
19238e75 7558
54526d1f
NT
75597.24 KVM_CAP_VM_COPY_ENC_CONTEXT_FROM
7560-------------------------------------
7561
7562Architectures: x86 SEV enabled
7563Type: vm
7564Parameters: args[0] is the fd of the source vm
7565Returns: 0 on success; ENOTTY on error
7566
7567This capability enables userspace to copy encryption context from the vm
7568indicated by the fd to the vm this is called on.
7569
7570This is intended to support in-guest workloads scheduled by the host. This
7571allows the in-guest workload to maintain its own NPTs and keeps the two vms
7572from accidentally clobbering each other with interrupts and the like (separate
7573APIC/MSRs/etc).
7574
fe7e9488 75757.25 KVM_CAP_SGX_ATTRIBUTE
f82762fb 7576--------------------------
fe7e9488
SC
7577
7578:Architectures: x86
7579:Target: VM
7580:Parameters: args[0] is a file handle of a SGX attribute file in securityfs
7581:Returns: 0 on success, -EINVAL if the file handle is invalid or if a requested
7582 attribute is not supported by KVM.
7583
7584KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or
d56b699d 7585more privileged enclave attributes. args[0] must hold a file handle to a valid
fe7e9488
SC
7586SGX attribute file corresponding to an attribute that is supported/restricted
7587by KVM (currently only PROVISIONKEY).
7588
7589The SGX subsystem restricts access to a subset of enclave attributes to provide
7590additional security for an uncompromised kernel, e.g. use of the PROVISIONKEY
7591is restricted to deter malware from using the PROVISIONKEY to obtain a stable
7592system fingerprint. To prevent userspace from circumventing such restrictions
7593by running an enclave in a VM, KVM prevents access to privileged attributes by
7594default.
7595
ff61f079 7596See Documentation/arch/x86/sgx.rst for more details.
fe7e9488 7597
b87cc116
BR
75987.26 KVM_CAP_PPC_RPT_INVALIDATE
7599-------------------------------
7600
7601:Capability: KVM_CAP_PPC_RPT_INVALIDATE
7602:Architectures: ppc
7603:Type: vm
7604
7605This capability indicates that the kernel is capable of handling
7606H_RPT_INVALIDATE hcall.
7607
7608In order to enable the use of H_RPT_INVALIDATE in the guest,
7609user space might have to advertise it for the guest. For example,
7610IBM pSeries (sPAPR) guest starts using it if "hcall-rpt-invalidate" is
7611present in the "ibm,hypertas-functions" device-tree property.
7612
7613This capability is enabled for hypervisors on platforms like POWER9
7614that support radix MMU.
7615
19238e75
AL
76167.27 KVM_CAP_EXIT_ON_EMULATION_FAILURE
7617--------------------------------------
7618
7619:Architectures: x86
7620:Parameters: args[0] whether the feature should be enabled or not
7621
7622When this capability is enabled, an emulation failure will result in an exit
7623to userspace with KVM_INTERNAL_ERROR (except when the emulator was invoked
7624to handle a VMware backdoor instruction). Furthermore, KVM will now provide up
7625to 15 instruction bytes for any exit to userspace resulting from an emulation
7626failure. When these exits to userspace occur use the emulation_failure struct
7627instead of the internal struct. They both have the same layout, but the
7628emulation_failure struct matches the content better. It also explicitly
7629defines the 'flags' field which is used to describe the fields in the struct
7630that are valid (ie: if KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES is
7631set in the 'flags' field then both 'insn_size' and 'insn_bytes' have valid data
7632in them.)
7633
b8917b4a 76347.28 KVM_CAP_ARM_MTE
04c02c20
SP
7635--------------------
7636
7637:Architectures: arm64
7638:Parameters: none
7639
7640This capability indicates that KVM (and the hardware) supports exposing the
7641Memory Tagging Extensions (MTE) to the guest. It must also be enabled by the
7642VMM before creating any VCPUs to allow the guest access. Note that MTE is only
7643available to a guest running in AArch64 mode and enabling this capability will
7644cause attempts to create AArch32 VCPUs to fail.
7645
7646When enabled the guest is able to access tags associated with any memory given
7647to the guest. KVM will ensure that the tags are maintained during swap or
7648hibernation of the host; however the VMM needs to manually save/restore the
7649tags as appropriate if the VM is migrated.
7650
7651When this capability is enabled all memory in memslots must be mapped as
a4baf8d2
PC
7652``MAP_ANONYMOUS`` or with a RAM-based file mapping (``tmpfs``, ``memfd``),
7653attempts to create a memslot with an invalid mmap will result in an
7654-EINVAL return.
04c02c20
SP
7655
7656When enabled the VMM may make use of the ``KVM_ARM_MTE_COPY_TAGS`` ioctl to
7657perform a bulk copy of tags to/from the guest.
19238e75 7658
b5663931
PG
76597.29 KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM
7660-------------------------------------
7661
7662Architectures: x86 SEV enabled
7663Type: vm
7664Parameters: args[0] is the fd of the source vm
7665Returns: 0 on success
7666
7667This capability enables userspace to migrate the encryption context from the VM
7668indicated by the fd to the VM this is called on.
7669
7670This is intended to support intra-host migration of VMs between userspace VMMs,
7671upgrading the VMM process without interrupting the guest.
7672
93b71801
NP
76737.30 KVM_CAP_PPC_AIL_MODE_3
7674-------------------------------
7675
7676:Capability: KVM_CAP_PPC_AIL_MODE_3
7677:Architectures: ppc
7678:Type: vm
7679
7680This capability indicates that the kernel supports the mode 3 setting for the
7681"Address Translation Mode on Interrupt" aka "Alternate Interrupt Location"
7682resource that is controlled with the H_SET_MODE hypercall.
7683
7684This capability allows a guest kernel to use a better-performance mode for
7685handling interrupts and system calls.
7686
6d849191
OU
76877.31 KVM_CAP_DISABLE_QUIRKS2
7688----------------------------
7689
7690:Capability: KVM_CAP_DISABLE_QUIRKS2
7691:Parameters: args[0] - set of KVM quirks to disable
7692:Architectures: x86
7693:Type: vm
7694
7695This capability, if enabled, will cause KVM to disable some behavior
7696quirks.
7697
7698Calling KVM_CHECK_EXTENSION for this capability returns a bitmask of
7699quirks that can be disabled in KVM.
7700
7701The argument to KVM_ENABLE_CAP for this capability is a bitmask of
7702quirks to disable, and must be a subset of the bitmask returned by
7703KVM_CHECK_EXTENSION.
7704
7705The valid bits in cap.args[0] are:
7706
7707=================================== ============================================
7708 KVM_X86_QUIRK_LINT0_REENABLED By default, the reset value for the LVT
7709 LINT0 register is 0x700 (APIC_MODE_EXTINT).
7710 When this quirk is disabled, the reset value
7711 is 0x10000 (APIC_LVT_MASKED).
7712
7713 KVM_X86_QUIRK_CD_NW_CLEARED By default, KVM clears CR0.CD and CR0.NW.
7714 When this quirk is disabled, KVM does not
7715 change the value of CR0.CD and CR0.NW.
7716
7717 KVM_X86_QUIRK_LAPIC_MMIO_HOLE By default, the MMIO LAPIC interface is
7718 available even when configured for x2APIC
7719 mode. When this quirk is disabled, KVM
7720 disables the MMIO LAPIC interface if the
7721 LAPIC is in x2APIC mode.
7722
7723 KVM_X86_QUIRK_OUT_7E_INC_RIP By default, KVM pre-increments %rip before
7724 exiting to userspace for an OUT instruction
7725 to port 0x7e. When this quirk is disabled,
7726 KVM does not pre-increment %rip before
7727 exiting to userspace.
7728
7729 KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT When this quirk is disabled, KVM sets
7730 CPUID.01H:ECX[bit 3] (MONITOR/MWAIT) if
7731 IA32_MISC_ENABLE[bit 18] (MWAIT) is set.
7732 Additionally, when this quirk is disabled,
7733 KVM clears CPUID.01H:ECX[bit 3] if
7734 IA32_MISC_ENABLE[bit 18] is cleared.
f1a9761f
OU
7735
7736 KVM_X86_QUIRK_FIX_HYPERCALL_INSN By default, KVM rewrites guest
7737 VMMCALL/VMCALL instructions to match the
7738 vendor's hypercall instruction for the
7739 system. When this quirk is disabled, KVM
7740 will no longer rewrite invalid guest
7741 hypercall instructions. Executing the
7742 incorrect hypercall instruction will
7743 generate a #UD within the guest.
bfbcc81b 7744
43bb9e00 7745KVM_X86_QUIRK_MWAIT_NEVER_UD_FAULTS By default, KVM emulates MONITOR/MWAIT (if
bfbcc81b
SC
7746 they are intercepted) as NOPs regardless of
7747 whether or not MONITOR/MWAIT are supported
7748 according to guest CPUID. When this quirk
7749 is disabled and KVM_X86_DISABLE_EXITS_MWAIT
7750 is not set (MONITOR/MWAIT are intercepted),
7751 KVM will inject a #UD on MONITOR/MWAIT if
7752 they're unsupported per guest CPUID. Note,
7753 KVM will modify MONITOR/MWAIT support in
7754 guest CPUID on writes to MISC_ENABLE if
7755 KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT is
7756 disabled.
6d849191
OU
7757=================================== ============================================
7758
35875316
ZG
77597.32 KVM_CAP_MAX_VCPU_ID
7760------------------------
7761
7762:Architectures: x86
7763:Target: VM
7764:Parameters: args[0] - maximum APIC ID value set for current VM
7765:Returns: 0 on success, -EINVAL if args[0] is beyond KVM_MAX_VCPU_IDS
7766 supported in KVM or if it has been set.
7767
7768This capability allows userspace to specify maximum possible APIC ID
7769assigned for current VM session prior to the creation of vCPUs, saving
7770memory for data structures indexed by the APIC ID. Userspace is able
7771to calculate the limit to APIC ID values from designated
7772CPU topology.
7773
7774The value can be changed only until KVM_ENABLE_CAP is set to a nonzero
7775value or until a vCPU is created. Upon creation of the first vCPU,
7776if the value was set to zero or KVM_ENABLE_CAP was not invoked, KVM
7777uses the return value of KVM_CHECK_EXTENSION(KVM_CAP_MAX_VCPU_ID) as
7778the maximum APIC ID.
7779
2f4073e0
TX
77807.33 KVM_CAP_X86_NOTIFY_VMEXIT
7781------------------------------
7782
7783:Architectures: x86
7784:Target: VM
7785:Parameters: args[0] is the value of notify window as well as some flags
7786:Returns: 0 on success, -EINVAL if args[0] contains invalid flags or notify
7787 VM exit is unsupported.
7788
7789Bits 63:32 of args[0] are used for notify window.
7790Bits 31:0 of args[0] are for some flags. Valid bits are::
7791
7792 #define KVM_X86_NOTIFY_VMEXIT_ENABLED (1 << 0)
7793 #define KVM_X86_NOTIFY_VMEXIT_USER (1 << 1)
7794
7795This capability allows userspace to configure the notify VM exit on/off
7796in per-VM scope during VM creation. Notify VM exit is disabled by default.
7797When userspace sets KVM_X86_NOTIFY_VMEXIT_ENABLED bit in args[0], VMM will
7798enable this feature with the notify window provided, which will generate
7799a VM exit if no event window occurs in VM non-root mode for a specified of
7800time (notify window).
7801
7802If KVM_X86_NOTIFY_VMEXIT_USER is set in args[0], upon notify VM exits happen,
7803KVM would exit to userspace for handling.
7804
7805This capability is aimed to mitigate the threat that malicious VMs can
7806cause CPU stuck (due to event windows don't open up) and make the CPU
7807unavailable to host or other VMs.
7808
e928e9cb 78098. Other capabilities.
106ee47d 7810======================
e928e9cb
ME
7811
7812This section lists capabilities that give information about other
7813features of the KVM implementation.
7814
78158.1 KVM_CAP_PPC_HWRNG
106ee47d 7816---------------------
e928e9cb 7817
106ee47d 7818:Architectures: ppc
e928e9cb
ME
7819
7820This capability, if KVM_CHECK_EXTENSION indicates that it is
3747c5d3 7821available, means that the kernel has an implementation of the
e928e9cb
ME
7822H_RANDOM hypercall backed by a hardware random-number generator.
7823If present, the kernel H_RANDOM handler can be enabled for guest use
7824with the KVM_CAP_PPC_ENABLE_HCALL capability.
5c919412
AS
7825
78268.2 KVM_CAP_HYPERV_SYNIC
106ee47d
MCC
7827------------------------
7828
7829:Architectures: x86
5c919412 7830
5c919412 7831This capability, if KVM_CHECK_EXTENSION indicates that it is
3747c5d3 7832available, means that the kernel has an implementation of the
5c919412
AS
7833Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
7834used to support Windows Hyper-V based guest paravirt drivers(VMBus).
7835
7836In order to use SynIC, it has to be activated by setting this
7837capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
7838will disable the use of APIC hardware virtualization even if supported
7839by the CPU, as it's incompatible with SynIC auto-EOI behavior.
c9270132
PM
7840
78418.3 KVM_CAP_PPC_RADIX_MMU
106ee47d 7842-------------------------
c9270132 7843
106ee47d 7844:Architectures: ppc
c9270132
PM
7845
7846This capability, if KVM_CHECK_EXTENSION indicates that it is
3747c5d3 7847available, means that the kernel can support guests using the
c9270132
PM
7848radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
7849processor).
7850
78518.4 KVM_CAP_PPC_HASH_MMU_V3
106ee47d 7852---------------------------
c9270132 7853
106ee47d 7854:Architectures: ppc
c9270132
PM
7855
7856This capability, if KVM_CHECK_EXTENSION indicates that it is
3747c5d3 7857available, means that the kernel can support guests using the
c9270132
PM
7858hashed page table MMU defined in Power ISA V3.00 (as implemented in
7859the POWER9 processor), including in-memory segment tables.
a8a3c426
JH
7860
78618.5 KVM_CAP_MIPS_VZ
106ee47d 7862-------------------
a8a3c426 7863
106ee47d 7864:Architectures: mips
a8a3c426
JH
7865
7866This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
7867it is available, means that full hardware assisted virtualization capabilities
7868of the hardware are available for use through KVM. An appropriate
7869KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
7870utilises it.
7871
7872If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
7873available, it means that the VM is using full hardware assisted virtualization
7874capabilities of the hardware. This is useful to check after creating a VM with
7875KVM_VM_MIPS_DEFAULT.
7876
7877The value returned by KVM_CHECK_EXTENSION should be compared against known
7878values (see below). All other values are reserved. This is to allow for the
7879possibility of other hardware assisted virtualization implementations which
7880may be incompatible with the MIPS VZ ASE.
7881
106ee47d
MCC
7882== ==========================================================================
7883 0 The trap & emulate implementation is in use to run guest code in user
a8a3c426
JH
7884 mode. Guest virtual memory segments are rearranged to fit the guest in the
7885 user mode address space.
7886
106ee47d 7887 1 The MIPS VZ ASE is in use, providing full hardware assisted
a8a3c426 7888 virtualization, including standard guest virtual memory segments.
106ee47d 7889== ==========================================================================
a8a3c426
JH
7890
78918.6 KVM_CAP_MIPS_TE
106ee47d 7892-------------------
a8a3c426 7893
106ee47d 7894:Architectures: mips
a8a3c426
JH
7895
7896This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
7897it is available, means that the trap & emulate implementation is available to
7898run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
7899assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
7900to KVM_CREATE_VM to create a VM which utilises it.
7901
7902If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
7903available, it means that the VM is using trap & emulate.
578fd61d
JH
7904
79058.7 KVM_CAP_MIPS_64BIT
106ee47d 7906----------------------
578fd61d 7907
106ee47d 7908:Architectures: mips
578fd61d
JH
7909
7910This capability indicates the supported architecture type of the guest, i.e. the
7911supported register and address width.
7912
7913The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
7914kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
7915be checked specifically against known values (see below). All other values are
7916reserved.
7917
106ee47d
MCC
7918== ========================================================================
7919 0 MIPS32 or microMIPS32.
578fd61d
JH
7920 Both registers and addresses are 32-bits wide.
7921 It will only be possible to run 32-bit guest code.
7922
106ee47d 7923 1 MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
578fd61d
JH
7924 Registers are 64-bits wide, but addresses are 32-bits wide.
7925 64-bit guest code may run but cannot access MIPS64 memory segments.
7926 It will also be possible to run 32-bit guest code.
7927
106ee47d 7928 2 MIPS64 or microMIPS64 with access to all address segments.
578fd61d
JH
7929 Both registers and addresses are 64-bits wide.
7930 It will be possible to run 64-bit or 32-bit guest code.
106ee47d 7931== ========================================================================
668fffa3 7932
c24a7be2 79338.9 KVM_CAP_ARM_USER_IRQ
106ee47d
MCC
7934------------------------
7935
3fbf4207 7936:Architectures: arm64
3fe17e68 7937
3fe17e68
AG
7938This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
7939that if userspace creates a VM without an in-kernel interrupt controller, it
7940will be notified of changes to the output level of in-kernel emulated devices,
7941which can generate virtual interrupts, presented to the VM.
7942For such VMs, on every return to userspace, the kernel
7943updates the vcpu's run->s.regs.device_irq_level field to represent the actual
7944output level of the device.
7945
7946Whenever kvm detects a change in the device output level, kvm guarantees at
7947least one return to userspace before running the VM. This exit could either
7948be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
7949userspace can always sample the device output level and re-compute the state of
7950the userspace interrupt controller. Userspace should always check the state
7951of run->s.regs.device_irq_level on every kvm exit.
7952The value in run->s.regs.device_irq_level can represent both level and edge
7953triggered interrupt signals, depending on the device. Edge triggered interrupt
7954signals will exit to userspace with the bit in run->s.regs.device_irq_level
7955set exactly once per edge signal.
7956
7957The field run->s.regs.device_irq_level is available independent of
7958run->kvm_valid_regs or run->kvm_dirty_regs bits.
7959
7960If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
7961number larger than 0 indicating the version of this capability is implemented
3747c5d3 7962and thereby which bits in run->s.regs.device_irq_level can signal values.
3fe17e68 7963
106ee47d 7964Currently the following bits are defined for the device_irq_level bitmap::
3fe17e68
AG
7965
7966 KVM_CAP_ARM_USER_IRQ >= 1:
7967
7968 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
7969 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
7970 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
7971
7972Future versions of kvm may implement additional events. These will get
7973indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
7974listed above.
2ed4f9dd
PM
7975
79768.10 KVM_CAP_PPC_SMT_POSSIBLE
106ee47d 7977-----------------------------
2ed4f9dd 7978
106ee47d 7979:Architectures: ppc
2ed4f9dd
PM
7980
7981Querying this capability returns a bitmap indicating the possible
7982virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
7983(counting from the right) is set, then a virtual SMT mode of 2^N is
7984available.
efc479e6
RK
7985
79868.11 KVM_CAP_HYPERV_SYNIC2
106ee47d 7987--------------------------
efc479e6 7988
106ee47d 7989:Architectures: x86
efc479e6
RK
7990
7991This capability enables a newer version of Hyper-V Synthetic interrupt
7992controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
7993doesn't clear SynIC message and event flags pages when they are enabled by
7994writing to the respective MSRs.
d3457c87
RK
7995
79968.12 KVM_CAP_HYPERV_VP_INDEX
106ee47d 7997----------------------------
d3457c87 7998
106ee47d 7999:Architectures: x86
d3457c87
RK
8000
8001This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
8002value is used to denote the target vcpu for a SynIC interrupt. For
d56b699d 8003compatibility, KVM initializes this msr to KVM's internal vcpu index. When this
d3457c87 8004capability is absent, userspace can still query this msr's value.
da9a1446
CB
8005
80068.13 KVM_CAP_S390_AIS_MIGRATION
106ee47d 8007-------------------------------
da9a1446 8008
106ee47d
MCC
8009:Architectures: s390
8010:Parameters: none
da9a1446
CB
8011
8012This capability indicates if the flic device will be able to get/set the
8013AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
8014to discover this without having to create a flic device.
5c2b4d5b
CB
8015
80168.14 KVM_CAP_S390_PSW
106ee47d 8017---------------------
5c2b4d5b 8018
106ee47d 8019:Architectures: s390
5c2b4d5b
CB
8020
8021This capability indicates that the PSW is exposed via the kvm_run structure.
8022
80238.15 KVM_CAP_S390_GMAP
106ee47d 8024----------------------
5c2b4d5b 8025
106ee47d 8026:Architectures: s390
5c2b4d5b
CB
8027
8028This capability indicates that the user space memory used as guest mapping can
8029be anywhere in the user memory address space, as long as the memory slots are
8030aligned and sized to a segment (1MB) boundary.
8031
80328.16 KVM_CAP_S390_COW
106ee47d 8033---------------------
5c2b4d5b 8034
106ee47d 8035:Architectures: s390
5c2b4d5b
CB
8036
8037This capability indicates that the user space memory used as guest mapping can
8038use copy-on-write semantics as well as dirty pages tracking via read-only page
8039tables.
8040
80418.17 KVM_CAP_S390_BPB
106ee47d 8042---------------------
5c2b4d5b 8043
106ee47d 8044:Architectures: s390
5c2b4d5b
CB
8045
8046This capability indicates that kvm will implement the interfaces to handle
8047reset, migration and nested KVM for branch prediction blocking. The stfle
8048facility 82 should not be provided to the guest without this capability.
c1aea919 8049
2ddc6498 80508.18 KVM_CAP_HYPERV_TLBFLUSH
106ee47d 8051----------------------------
c1aea919 8052
106ee47d 8053:Architectures: x86
c1aea919
VK
8054
8055This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
8056hypercalls:
8057HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
8058HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
be26b3a7 8059
688e0581 80608.19 KVM_CAP_ARM_INJECT_SERROR_ESR
106ee47d 8061----------------------------------
be26b3a7 8062
3fbf4207 8063:Architectures: arm64
be26b3a7
DG
8064
8065This capability indicates that userspace can specify (via the
8066KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
8067takes a virtual SError interrupt exception.
8068If KVM advertises this capability, userspace can only specify the ISS field for
8069the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
8070CPU when the exception is taken. If this virtual SError is taken to EL1 using
8071AArch64, this value will be reported in the ISS field of ESR_ELx.
8072
8073See KVM_CAP_VCPU_EVENTS for more details.
106ee47d 8074
214ff83d 80758.20 KVM_CAP_HYPERV_SEND_IPI
106ee47d 8076----------------------------
214ff83d 8077
106ee47d 8078:Architectures: x86
214ff83d
VK
8079
8080This capability indicates that KVM supports paravirtualized Hyper-V IPI send
8081hypercalls:
8082HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.
106ee47d 8083
344c6c80 80848.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH
106ee47d 8085-----------------------------------
344c6c80 8086
739c7af7 8087:Architectures: x86
344c6c80
TL
8088
8089This capability indicates that KVM running on top of Hyper-V hypervisor
8090enables Direct TLB flush for its guests meaning that TLB flush
8091hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM.
8092Due to the different ABI for hypercall parameters between Hyper-V and
8093KVM, enabling this capability effectively disables all hypercall
8094handling by KVM (as some KVM hypercall may be mistakenly treated as TLB
8095flush hypercalls by Hyper-V) so userspace should disable KVM identification
8096in CPUID and only exposes Hyper-V identification. In this case, guest
8097thinks it's running on Hyper-V and only use Hyper-V hypercalls.
7de3f142
JF
8098
80998.22 KVM_CAP_S390_VCPU_RESETS
739c7af7 8100-----------------------------
7de3f142 8101
739c7af7 8102:Architectures: s390
7de3f142
JF
8103
8104This capability indicates that the KVM_S390_NORMAL_RESET and
8105KVM_S390_CLEAR_RESET ioctls are available.
04ed89dc
JF
8106
81078.23 KVM_CAP_S390_PROTECTED
739c7af7 8108---------------------------
04ed89dc 8109
739c7af7 8110:Architectures: s390
04ed89dc
JF
8111
8112This capability indicates that the Ultravisor has been initialized and
8113KVM can therefore start protected VMs.
8114This capability governs the KVM_S390_PV_COMMAND ioctl and the
8115KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
8116guests when the state change is invalid.
004a0124
AJ
8117
81188.24 KVM_CAP_STEAL_TIME
8119-----------------------
8120
8121:Architectures: arm64, x86
8122
8123This capability indicates that KVM supports steal time accounting.
8124When steal time accounting is supported it may be enabled with
8125architecture-specific interfaces. This capability and the architecture-
8126specific interfaces must be consistent, i.e. if one says the feature
8127is supported, than the other should as well and vice versa. For arm64
8128see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
48b36e59 8129For x86 see Documentation/virt/kvm/x86/msr.rst "MSR_KVM_STEAL_TIME".
f20d4e92
CW
8130
81318.25 KVM_CAP_S390_DIAG318
8132-------------------------
8133
8134:Architectures: s390
8135
8136This capability enables a guest to set information about its control program
8137(i.e. guest kernel type and version). The information is helpful during
8138system/firmware service events, providing additional data about the guest
8139environments running on the machine.
8140
8141The information is associated with the DIAGNOSE 0x318 instruction, which sets
8142an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and
8143a 7-byte Control Program Version Code (CPVC). The CPNC determines what
8144environment the control program is running in (e.g. Linux, z/VM...), and the
8145CPVC is used for information specific to OS (e.g. Linux version, Linux
8146distribution...)
8147
8148If this capability is available, then the CPNC and CPVC can be synchronized
8149between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318).
1ae09954
AG
8150
81518.26 KVM_CAP_X86_USER_SPACE_MSR
8152-------------------------------
8153
8154:Architectures: x86
8155
8156This capability indicates that KVM supports deflection of MSR reads and
8157writes to user space. It can be enabled on a VM level. If enabled, MSR
8158accesses that would usually trigger a #GP by KVM into the guest will
8159instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
8160KVM_EXIT_X86_WRMSR exit notifications.
1a155254 8161
46a63924 81628.27 KVM_CAP_X86_MSR_FILTER
1a155254
AG
8163---------------------------
8164
8165:Architectures: x86
8166
8167This capability indicates that KVM supports that accesses to user defined MSRs
8168may be rejected. With this capability exposed, KVM exports new VM ioctl
8169KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR
b93d2ec3 8170ranges that KVM should deny access to.
1a155254
AG
8171
8172In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
8173trap and emulate MSRs that are outside of the scope of KVM as well as
8174limit the attack surface on KVM's MSR emulation code.
66570e96 8175
0e691ee7 81768.28 KVM_CAP_ENFORCE_PV_FEATURE_CPUID
e2e83a73 8177-------------------------------------
66570e96
OU
8178
8179Architectures: x86
8180
8181When enabled, KVM will disable paravirtual features provided to the
8182guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
8183(0x40000001). Otherwise, a guest may use the paravirtual features
8184regardless of what has actually been exposed through the CPUID leaf.
fb04a1ed 8185
671c8c7f
MZ
81868.29 KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL
8187----------------------------------------------------------
fb04a1ed 8188
9cb1096f 8189:Architectures: x86, arm64
fb04a1ed
PX
8190:Parameters: args[0] - size of the dirty log ring
8191
8192KVM is capable of tracking dirty memory using ring buffers that are
d56b699d 8193mmapped into userspace; there is one dirty ring per vcpu.
fb04a1ed
PX
8194
8195The dirty ring is available to userspace as an array of
d56b699d 8196``struct kvm_dirty_gfn``. Each dirty entry is defined as::
fb04a1ed
PX
8197
8198 struct kvm_dirty_gfn {
8199 __u32 flags;
8200 __u32 slot; /* as_id | slot_id */
8201 __u64 offset;
8202 };
8203
8204The following values are defined for the flags field to define the
8205current state of the entry::
8206
8207 #define KVM_DIRTY_GFN_F_DIRTY BIT(0)
8208 #define KVM_DIRTY_GFN_F_RESET BIT(1)
8209 #define KVM_DIRTY_GFN_F_MASK 0x3
8210
8211Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM
8212ioctl to enable this capability for the new guest and set the size of
8213the rings. Enabling the capability is only allowed before creating any
8214vCPU, and the size of the ring must be a power of two. The larger the
8215ring buffer, the less likely the ring is full and the VM is forced to
8216exit to userspace. The optimal size depends on the workload, but it is
8217recommended that it be at least 64 KiB (4096 entries).
8218
8219Just like for dirty page bitmaps, the buffer tracks writes to
8220all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was
8221set in KVM_SET_USER_MEMORY_REGION. Once a memory region is registered
8222with the flag set, userspace can start harvesting dirty pages from the
8223ring buffer.
8224
8225An entry in the ring buffer can be unused (flag bits ``00``),
8226dirty (flag bits ``01``) or harvested (flag bits ``1X``). The
8227state machine for the entry is as follows::
8228
8229 dirtied harvested reset
8230 00 -----------> 01 -------------> 1X -------+
8231 ^ |
8232 | |
8233 +------------------------------------------+
8234
d56b699d 8235To harvest the dirty pages, userspace accesses the mmapped ring buffer
fb04a1ed
PX
8236to read the dirty GFNs. If the flags has the DIRTY bit set (at this stage
8237the RESET bit must be cleared), then it means this GFN is a dirty GFN.
8238The userspace should harvest this GFN and mark the flags from state
8239``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set
8240to show that this GFN is harvested and waiting for a reset), and move
8241on to the next GFN. The userspace should continue to do this until the
8242flags of a GFN have the DIRTY bit cleared, meaning that it has harvested
8243all the dirty GFNs that were available.
8244
671c8c7f
MZ
8245Note that on weakly ordered architectures, userspace accesses to the
8246ring buffer (and more specifically the 'flags' field) must be ordered,
8247using load-acquire/store-release accessors when available, or any
8248other memory barrier that will ensure this ordering.
8249
fb04a1ed
PX
8250It's not necessary for userspace to harvest the all dirty GFNs at once.
8251However it must collect the dirty GFNs in sequence, i.e., the userspace
8252program cannot skip one dirty GFN to collect the one next to it.
8253
8254After processing one or more entries in the ring buffer, userspace
8255calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about
8256it, so that the kernel will reprotect those collected GFNs.
8257Therefore, the ioctl must be called *before* reading the content of
8258the dirty pages.
8259
8260The dirty ring can get full. When it happens, the KVM_RUN of the
8261vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL.
8262
8263The dirty ring interface has a major difference comparing to the
8264KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from
8265userspace, it's still possible that the kernel has not yet flushed the
8266processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the
8267flushing is done by the KVM_GET_DIRTY_LOG ioctl). To achieve that, one
8268needs to kick the vcpu out of KVM_RUN using a signal. The resulting
8269vmexit ensures that all dirty GFNs are flushed to the dirty rings.
b2cc64c4 8270
671c8c7f
MZ
8271NOTE: KVM_CAP_DIRTY_LOG_RING_ACQ_REL is the only capability that
8272should be exposed by weakly ordered architecture, in order to indicate
8273the additional memory ordering requirements imposed on userspace when
8274reading the state of an entry and mutating it from DIRTY to HARVESTED.
8275Architecture with TSO-like ordering (such as x86) are allowed to
8276expose both KVM_CAP_DIRTY_LOG_RING and KVM_CAP_DIRTY_LOG_RING_ACQ_REL
8277to userspace.
8278
86bdf3eb
GS
8279After enabling the dirty rings, the userspace needs to detect the
8280capability of KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP to see whether the
8281ring structures can be backed by per-slot bitmaps. With this capability
8282advertised, it means the architecture can dirty guest pages without
8283vcpu/ring context, so that some of the dirty information will still be
8284maintained in the bitmap structure. KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP
8285can't be enabled if the capability of KVM_CAP_DIRTY_LOG_RING_ACQ_REL
8286hasn't been enabled, or any memslot has been existing.
8287
8288Note that the bitmap here is only a backup of the ring structure. The
8289use of the ring and bitmap combination is only beneficial if there is
8290only a very small amount of memory that is dirtied out of vcpu/ring
8291context. Otherwise, the stand-alone per-slot bitmap mechanism needs to
8292be considered.
8293
8294To collect dirty bits in the backup bitmap, userspace can use the same
8295KVM_GET_DIRTY_LOG ioctl. KVM_CLEAR_DIRTY_LOG isn't needed as long as all
8296the generation of the dirty bits is done in a single pass. Collecting
8297the dirty bitmap should be the very last thing that the VMM does before
8298considering the state as complete. VMM needs to ensure that the dirty
8299state is final and avoid missing dirty pages from another ioctl ordered
8300after the bitmap collection.
8301
2f8b1ad2
GS
8302NOTE: Multiple examples of using the backup bitmap: (1) save vgic/its
8303tables through command KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_SAVE_TABLES} on
8304KVM device "kvm-arm-vgic-its". (2) restore vgic/its tables through
8305command KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_RESTORE_TABLES} on KVM device
6028acbe
GS
8306"kvm-arm-vgic-its". VGICv3 LPI pending status is restored. (3) save
8307vgic3 pending table through KVM_DEV_ARM_VGIC_{GRP_CTRL, SAVE_PENDING_TABLES}
8308command on KVM device "kvm-arm-vgic-v3".
86bdf3eb 8309
e1f68169
DW
83108.30 KVM_CAP_XEN_HVM
8311--------------------
8312
8313:Architectures: x86
8314
8315This capability indicates the features that Xen supports for hosting Xen
8316PVHVM guests. Valid flags are::
8317
d8ba8ba4
DW
8318 #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR (1 << 0)
8319 #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL (1 << 1)
8320 #define KVM_XEN_HVM_CONFIG_SHARED_INFO (1 << 2)
8321 #define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 3)
8322 #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)
8323 #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5)
8324 #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)
e1f68169
DW
8325
8326The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
8327ioctl is available, for the guest to set its hypercall page.
8328
8329If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be
8330provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page
8331contents, to request that KVM generate hypercall page content automatically
8332and also enable interception of guest hypercalls with KVM_EXIT_XEN.
8333
8334The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the
8335KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and
8336KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors
8337for event channel upcalls when the evtchn_upcall_pending field of a vcpu's
8338vcpu_info is set.
30b5c851
DW
8339
8340The KVM_XEN_HVM_CONFIG_RUNSTATE flag indicates that the runstate-related
8341features KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR/_CURRENT/_DATA/_ADJUST are
8342supported by the KVM_XEN_VCPU_SET_ATTR/KVM_XEN_VCPU_GET_ATTR ioctls.
24e7475f 8343
14243b38
DW
8344The KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL flag indicates that IRQ routing entries
8345of the type KVM_IRQ_ROUTING_XEN_EVTCHN are supported, with the priority
8346field set to indicate 2 level event channel delivery.
8347
661a20fa
DW
8348The KVM_XEN_HVM_CONFIG_EVTCHN_SEND flag indicates that KVM supports
8349injecting event channel events directly into the guest with the
8350KVM_XEN_HVM_EVTCHN_SEND ioctl. It also indicates support for the
8351KVM_XEN_ATTR_TYPE_EVTCHN/XEN_VERSION HVM attributes and the
8352KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID/TIMER/UPCALL_VECTOR vCPU attributes.
8353related to event channel delivery, timers, and the XENVER_version
8354interception.
8355
d8ba8ba4
DW
8356The KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG flag indicates that KVM supports
8357the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute in the KVM_XEN_SET_ATTR
8358and KVM_XEN_GET_ATTR ioctls. This controls whether KVM will set the
8359XEN_RUNSTATE_UPDATE flag in guest memory mapped vcpu_runstate_info during
8360updates of the runstate information. Note that versions of KVM which support
d56b699d 8361the RUNSTATE feature above, but not the RUNSTATE_UPDATE_FLAG feature, will
d8ba8ba4
DW
8362always set the XEN_RUNSTATE_UPDATE flag when updating the guest structure,
8363which is perhaps counterintuitive. When this flag is advertised, KVM will
8364behave more correctly, not using the XEN_RUNSTATE_UPDATE flag until/unless
8365specifically enabled (by the guest making the hypercall, causing the VMM
8366to enable the KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG attribute).
8367
24e7475f
EGE
83688.31 KVM_CAP_PPC_MULTITCE
8369-------------------------
8370
8371:Capability: KVM_CAP_PPC_MULTITCE
8372:Architectures: ppc
8373:Type: vm
8374
8375This capability means the kernel is capable of handling hypercalls
8376H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
8377space. This significantly accelerates DMA operations for PPC KVM guests.
8378User space should expect that its handlers for these hypercalls
8379are not going to be called if user space previously registered LIOBN
8380in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
8381
8382In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
8383user space might have to advertise it for the guest. For example,
8384IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
8385present in the "ibm,hypertas-functions" device-tree property.
8386
8387The hypercalls mentioned above may or may not be processed successfully
8388in the kernel based fast path. If they can not be handled by the kernel,
8389they will get passed on to user space. So user space still has to have
8390an implementation for these despite the in kernel acceleration.
8391
54526d1f 8392This capability is always enabled.
c4f71901
PB
8393
83948.32 KVM_CAP_PTP_KVM
3bf72569
JW
8395--------------------
8396
8397:Architectures: arm64
8398
8399This capability indicates that the KVM virtual PTP service is
8400supported in the host. A VMM can check whether the service is
8401available to the guest on migration.
644f7067
VK
8402
84038.33 KVM_CAP_HYPERV_ENFORCE_CPUID
8b967164 8404---------------------------------
644f7067
VK
8405
8406Architectures: x86
8407
8408When enabled, KVM will disable emulated Hyper-V features provided to the
8409guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all
d56b699d 8410currently implemented Hyper-V features are provided unconditionally when
644f7067
VK
8411Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001)
8412leaf.
0dbb1123
AK
8413
84148.34 KVM_CAP_EXIT_HYPERCALL
8415---------------------------
8416
8417:Capability: KVM_CAP_EXIT_HYPERCALL
8418:Architectures: x86
8419:Type: vm
8420
8421This capability, if enabled, will cause KVM to exit to userspace
8422with KVM_EXIT_HYPERCALL exit reason to process some hypercalls.
8423
8424Calling KVM_CHECK_EXTENSION for this capability will return a bitmask
8425of hypercalls that can be configured to exit to userspace.
8426Right now, the only such hypercall is KVM_HC_MAP_GPA_RANGE.
8427
8428The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset
8429of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace
8430the hypercalls whose corresponding bit is in the argument, and return
8431ENOSYS for the others.
ba7bb663
DD
8432
84338.35 KVM_CAP_PMU_CAPABILITY
8434---------------------------
8435
fb5015bc 8436:Capability: KVM_CAP_PMU_CAPABILITY
ba7bb663
DD
8437:Architectures: x86
8438:Type: vm
8439:Parameters: arg[0] is bitmask of PMU virtualization capabilities.
fb5015bc 8440:Returns: 0 on success, -EINVAL when arg[0] contains invalid bits
ba7bb663
DD
8441
8442This capability alters PMU virtualization in KVM.
8443
8444Calling KVM_CHECK_EXTENSION for this capability returns a bitmask of
8445PMU virtualization capabilities that can be adjusted on a VM.
8446
8447The argument to KVM_ENABLE_CAP is also a bitmask and selects specific
8448PMU virtualization capabilities to be applied to the VM. This can
8449only be invoked on a VM prior to the creation of VCPUs.
8450
8451At this time, KVM_PMU_CAP_DISABLE is the only capability. Setting
8452this capability will disable PMU virtualization for that VM. Usermode
8453should adjust CPUID leaf 0xA to reflect that the PMU is disabled.
cde363ab 8454
bfbab445
OU
84558.36 KVM_CAP_ARM_SYSTEM_SUSPEND
8456-------------------------------
8457
8458:Capability: KVM_CAP_ARM_SYSTEM_SUSPEND
8459:Architectures: arm64
8460:Type: vm
8461
8462When enabled, KVM will exit to userspace with KVM_EXIT_SYSTEM_EVENT of
8463type KVM_SYSTEM_EVENT_SUSPEND to process the guest suspend request.
8464
437cfd71
JF
84658.37 KVM_CAP_S390_PROTECTED_DUMP
8466--------------------------------
8467
8468:Capability: KVM_CAP_S390_PROTECTED_DUMP
8469:Architectures: s390
8470:Type: vm
8471
8472This capability indicates that KVM and the Ultravisor support dumping
8473PV guests. The `KVM_PV_DUMP` command is available for the
8474`KVM_S390_PV_COMMAND` ioctl and the `KVM_PV_INFO` command provides
8475dump related UV data. Also the vcpu ioctl `KVM_S390_PV_CPU_COMMAND` is
8476available and supports the `KVM_PV_DUMP_CPU` subcommand.
8477
084cc29f 84788.38 KVM_CAP_VM_DISABLE_NX_HUGE_PAGES
b4aed4d8 8479-------------------------------------
084cc29f 8480
19a7cc81 8481:Capability: KVM_CAP_VM_DISABLE_NX_HUGE_PAGES
084cc29f
BG
8482:Architectures: x86
8483:Type: vm
8484:Parameters: arg[0] must be 0.
19a7cc81
BS
8485:Returns: 0 on success, -EPERM if the userspace process does not
8486 have CAP_SYS_BOOT, -EINVAL if args[0] is not 0 or any vCPUs have been
8487 created.
084cc29f
BG
8488
8489This capability disables the NX huge pages mitigation for iTLB MULTIHIT.
8490
8491The capability has no effect if the nx_huge_pages module parameter is not set.
8492
8493This capability may only be set before any vCPUs are created.
437cfd71 8494
f5ecfee9
PM
84958.39 KVM_CAP_S390_CPU_TOPOLOGY
8496------------------------------
8497
8498:Capability: KVM_CAP_S390_CPU_TOPOLOGY
8499:Architectures: s390
8500:Type: vm
8501
8502This capability indicates that KVM will provide the S390 CPU Topology
8503facility which consist of the interpretation of the PTF instruction for
8504the function code 2 along with interception and forwarding of both the
8505PTF instruction with function codes 0 or 1 and the STSI(15,1,x)
8506instruction to the userland hypervisor.
8507
8508The stfle facility 11, CPU Topology facility, should not be indicated
8509to the guest without this capability.
8510
8511When this capability is present, KVM provides a new attribute group
8512on vm fd, KVM_S390_VM_CPU_TOPOLOGY.
8513This new attribute allows to get, set or clear the Modified Change
8514Topology Report (MTCR) bit of the SCA through the kvm_device_attr
8515structure.
8516
8517When getting the Modified Change Topology Report value, the attr->addr
8518must point to a byte where the value will be stored or retrieved from.
8519
2f440b72
RK
85208.40 KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
8521---------------------------------------
8522
8523:Capability: KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
8524:Architectures: arm64
8525:Type: vm
8526:Parameters: arg[0] is the new split chunk size.
8527:Returns: 0 on success, -EINVAL if any memslot was already created.
8528
8529This capability sets the chunk size used in Eager Page Splitting.
8530
8531Eager Page Splitting improves the performance of dirty-logging (used
8532in live migrations) when guest memory is backed by huge-pages. It
8533avoids splitting huge-pages (into PAGE_SIZE pages) on fault, by doing
8534it eagerly when enabling dirty logging (with the
8535KVM_MEM_LOG_DIRTY_PAGES flag for a memory region), or when using
8536KVM_CLEAR_DIRTY_LOG.
8537
8538The chunk size specifies how many pages to break at a time, using a
8539single allocation for each chunk. Bigger the chunk size, more pages
8540need to be allocated ahead of time.
8541
8542The chunk size needs to be a valid block size. The list of acceptable
8543block sizes is exposed in KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES as a
854464-bit bitmap (each bit describing a block size). The default value is
85450, to disable the eager page splitting.
8546
cde363ab
PB
85479. Known KVM API problems
8548=========================
8549
8550In some cases, KVM's API has some inconsistencies or common pitfalls
8551that userspace need to be aware of. This section details some of
8552these issues.
8553
8554Most of them are architecture specific, so the section is split by
8555architecture.
8556
85579.1. x86
8558--------
8559
8560``KVM_GET_SUPPORTED_CPUID`` issues
8561^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8562
8563In general, ``KVM_GET_SUPPORTED_CPUID`` is designed so that it is possible
8564to take its result and pass it directly to ``KVM_SET_CPUID2``. This section
8565documents some cases in which that requires some care.
8566
8567Local APIC features
8568~~~~~~~~~~~~~~~~~~~
8569
8570CPU[EAX=1]:ECX[21] (X2APIC) is reported by ``KVM_GET_SUPPORTED_CPUID``,
8571but it can only be enabled if ``KVM_CREATE_IRQCHIP`` or
8572``KVM_ENABLE_CAP(KVM_CAP_IRQCHIP_SPLIT)`` are used to enable in-kernel emulation of
8573the local APIC.
8574
8575The same is true for the ``KVM_FEATURE_PV_UNHALT`` paravirtualized feature.
8576
8577CPU[EAX=1]:ECX[24] (TSC_DEADLINE) is not reported by ``KVM_GET_SUPPORTED_CPUID``.
8578It can be enabled if ``KVM_CAP_TSC_DEADLINE_TIMER`` is present and the kernel
8579has enabled in-kernel emulation of the local APIC.
8580
45e966fc
PB
8581CPU topology
8582~~~~~~~~~~~~
8583
8584Several CPUID values include topology information for the host CPU:
85850x0b and 0x1f for Intel systems, 0x8000001e for AMD systems. Different
8586versions of KVM return different values for this information and userspace
8587should not rely on it. Currently they return all zeroes.
8588
8589If userspace wishes to set up a guest topology, it should be careful that
8590the values of these three leaves differ for each CPU. In particular,
8591the APIC ID is found in EDX for all subleaves of 0x0b and 0x1f, and in EAX
8592for 0x8000001e; the latter also encodes the core id and node id in bits
85937:0 of EBX and ECX respectively.
8594
cde363ab
PB
8595Obsolete ioctls and capabilities
8596^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8597
8598KVM_CAP_DISABLE_QUIRKS does not let userspace know which quirks are actually
8599available. Use ``KVM_CHECK_EXTENSION(KVM_CAP_DISABLE_QUIRKS2)`` instead if
8600available.
8601
8602Ordering of KVM_GET_*/KVM_SET_* ioctls
8603^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8604
8605TBD