blob: 32afe7f5c35af57b86b24705f629586fed4836b4 [file] [log] [blame]
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001The Definitive KVM (Kernel-based Virtual Machine) API Documentation
2===================================================================
3
41. General description
Jan Kiszka414fa982012-04-24 16:40:15 +02005----------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +03006
7The kvm API is a set of ioctls that are issued to control various aspects
8of a virtual machine. The ioctls belong to three classes
9
10 - System ioctls: These query and set global attributes which affect the
11 whole kvm subsystem. In addition a system ioctl is used to create
12 virtual machines
13
14 - VM ioctls: These query and set attributes that affect an entire virtual
15 machine, for example memory layout. In addition a VM ioctl is used to
16 create virtual cpus (vcpus).
17
18 Only run VM ioctls from the same process (address space) that was used
19 to create the VM.
20
21 - vcpu ioctls: These query and set attributes that control the operation
22 of a single virtual cpu.
23
24 Only run vcpu ioctls from the same thread that was used to create the
25 vcpu.
26
Jan Kiszka414fa982012-04-24 16:40:15 +020027
Wu Fengguang2044892d2009-12-24 09:04:16 +0800282. File descriptors
Jan Kiszka414fa982012-04-24 16:40:15 +020029-------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030030
31The kvm API is centered around file descriptors. An initial
32open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
33can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
Wu Fengguang2044892d2009-12-24 09:04:16 +080034handle will create a VM file descriptor which can be used to issue VM
Avi Kivity9c1b96e2009-06-09 12:37:58 +030035ioctls. A KVM_CREATE_VCPU ioctl on a VM fd will create a virtual cpu
36and return a file descriptor pointing to it. Finally, ioctls on a vcpu
37fd can be used to control the vcpu, including the important task of
38actually running guest code.
39
40In general file descriptors can be migrated among processes by means
41of fork() and the SCM_RIGHTS facility of unix domain socket. These
42kinds of tricks are explicitly not supported by kvm. While they will
43not cause harm to the host, their actual behavior is not guaranteed by
44the API. The only supported use is one virtual machine per process,
45and one vcpu per thread.
46
Jan Kiszka414fa982012-04-24 16:40:15 +020047
Sean Christophersoneca6be52019-02-15 12:48:40 -080048It is important to note that althought VM ioctls may only be issued from
49the process that created the VM, a VM's lifecycle is associated with its
50file descriptor, not its creator (process). In other words, the VM and
51its resources, *including the associated address space*, are not freed
52until the last reference to the VM's file descriptor has been released.
53For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
54not be freed until both the parent (original) process and its child have
55put their references to the VM's file descriptor.
56
57Because a VM's resources are not freed until the last reference to its
58file descriptor is released, creating additional references to a VM via
59via fork(), dup(), etc... without careful consideration is strongly
60discouraged and may have unwanted side effects, e.g. memory allocated
61by and on behalf of the VM's process may not be freed/unaccounted when
62the VM is shut down.
63
64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300653. Extensions
Jan Kiszka414fa982012-04-24 16:40:15 +020066-------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030067
68As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
69incompatible change are allowed. However, there is an extension
70facility that allows backward-compatible extensions to the API to be
71queried and used.
72
Masanari Iidac9f3f2d2013-07-18 01:29:12 +090073The extension mechanism is not based on the Linux version number.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030074Instead, kvm defines extension identifiers and a facility to query
75whether a particular extension identifier is available. If it is, a
76set of ioctls is available for application use.
77
Jan Kiszka414fa982012-04-24 16:40:15 +020078
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300794. API description
Jan Kiszka414fa982012-04-24 16:40:15 +020080------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +030081
82This section describes ioctls that can be used to control kvm guests.
83For each ioctl, the following information is provided along with a
84description:
85
86 Capability: which KVM extension provides this ioctl. Can be 'basic',
87 which means that is will be provided by any kernel that supports
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030088 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
Avi Kivity9c1b96e2009-06-09 12:37:58 +030089 means availability needs to be checked with KVM_CHECK_EXTENSION
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030090 (see section 4.4), or 'none' which means that while not all kernels
91 support this ioctl, there's no capability bit to check its
92 availability: for kernels that don't support the ioctl,
93 the ioctl returns -ENOTTY.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030094
95 Architectures: which instruction set architectures provide this ioctl.
96 x86 includes both i386 and x86_64.
97
98 Type: system, vm, or vcpu.
99
100 Parameters: what parameters are accepted by the ioctl.
101
102 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
103 are not detailed, but errors with specific meanings are.
104
Jan Kiszka414fa982012-04-24 16:40:15 +0200105
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001064.1 KVM_GET_API_VERSION
107
108Capability: basic
109Architectures: all
110Type: system ioctl
111Parameters: none
112Returns: the constant KVM_API_VERSION (=12)
113
114This identifies the API version as the stable kvm API. It is not
115expected that this number will change. However, Linux 2.6.20 and
1162.6.21 report earlier versions; these are not documented and not
117supported. Applications should refuse to run if KVM_GET_API_VERSION
118returns a value other than 12. If this check passes, all ioctls
119described as 'basic' will be available.
120
Jan Kiszka414fa982012-04-24 16:40:15 +0200121
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001224.2 KVM_CREATE_VM
123
124Capability: basic
125Architectures: all
126Type: system ioctl
Carsten Ottee08b9632012-01-04 10:25:20 +0100127Parameters: machine type identifier (KVM_VM_*)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300128Returns: a VM fd that can be used to control the new virtual machine.
129
Jann Hornbcb85c82017-04-24 11:16:49 +0200130The new VM has no virtual cpus and no memory.
James Hogana8a3c422017-03-14 10:15:19 +0000131You probably want to use 0 as machine type.
Carsten Ottee08b9632012-01-04 10:25:20 +0100132
133In order to create user controlled virtual machines on S390, check
134KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
135privileged user (CAP_SYS_ADMIN).
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300136
James Hogana8a3c422017-03-14 10:15:19 +0000137To use hardware assisted virtualization on MIPS (VZ ASE) rather than
138the default trap & emulate implementation (which changes the virtual
139memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the
140flag KVM_VM_MIPS_VZ.
141
Jan Kiszka414fa982012-04-24 16:40:15 +0200142
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100143On arm64, the physical address size for a VM (IPA Size limit) is limited
144to 40bits by default. The limit can be configured if the host supports the
145extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use
146KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type
147identifier, where IPA_Bits is the maximum width of any physical
148address used by the VM. The IPA_Bits is encoded in bits[7-0] of the
149machine type identifier.
150
151e.g, to configure a guest to use 48bit physical address size :
152
153 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48));
154
155The requested size (IPA_Bits) must be :
156 0 - Implies default size, 40bits (for backward compatibility)
157
158 or
159
160 N - Implies N bits, where N is a positive integer such that,
161 32 <= N <= Host_IPA_Limit
162
163Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and
164is dependent on the CPU capability and the kernel configuration. The limit can
165be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
166ioctl() at run-time.
167
168Please note that configuring the IPA size does not affect the capability
169exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
170size of the address translated by the stage2 level (guest physical to
171host physical address translations).
172
173
Tom Lendacky801e4592018-02-21 13:39:51 -06001744.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300175
Tom Lendacky801e4592018-02-21 13:39:51 -0600176Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300177Architectures: x86
Tom Lendacky801e4592018-02-21 13:39:51 -0600178Type: system ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300179Parameters: struct kvm_msr_list (in/out)
180Returns: 0 on success; -1 on error
181Errors:
Tom Lendacky801e4592018-02-21 13:39:51 -0600182 EFAULT: the msr index list cannot be read from or written to
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300183 E2BIG: the msr index list is to be to fit in the array specified by
184 the user.
185
186struct kvm_msr_list {
187 __u32 nmsrs; /* number of msrs in entries */
188 __u32 indices[0];
189};
190
Tom Lendacky801e4592018-02-21 13:39:51 -0600191The user fills in the size of the indices array in nmsrs, and in return
192kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
193indices array with their numbers.
194
195KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
196varies by kvm version and host processor, but does not change otherwise.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300197
Avi Kivity2e2602c2010-07-07 14:09:39 +0300198Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
199not returned in the MSR list, as different vcpus can have a different number
200of banks, as set via the KVM_X86_SETUP_MCE ioctl.
201
Tom Lendacky801e4592018-02-21 13:39:51 -0600202KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
203to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
204and processor features that are exposed via MSRs (e.g., VMX capabilities).
205This list also varies by kvm version and host processor, but does not change
206otherwise.
207
Jan Kiszka414fa982012-04-24 16:40:15 +0200208
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002094.4 KVM_CHECK_EXTENSION
210
Alexander Graf92b591a2014-07-14 18:33:08 +0200211Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300212Architectures: all
Alexander Graf92b591a2014-07-14 18:33:08 +0200213Type: system ioctl, vm ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300214Parameters: extension identifier (KVM_CAP_*)
215Returns: 0 if unsupported; 1 (or some other positive integer) if supported
216
217The API allows the application to query about extensions to the core
218kvm API. Userspace passes an extension identifier (an integer) and
219receives an integer that describes the extension availability.
220Generally 0 means no and 1 means yes, but some extensions may report
221additional information in the integer return value.
222
Alexander Graf92b591a2014-07-14 18:33:08 +0200223Based on their initialization different VMs may have different capabilities.
224It is thus encouraged to use the vm ioctl to query for capabilities (available
225with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
Jan Kiszka414fa982012-04-24 16:40:15 +0200226
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002274.5 KVM_GET_VCPU_MMAP_SIZE
228
229Capability: basic
230Architectures: all
231Type: system ioctl
232Parameters: none
233Returns: size of vcpu mmap area, in bytes
234
235The KVM_RUN ioctl (cf.) communicates with userspace via a shared
236memory region. This ioctl returns the size of that region. See the
237KVM_RUN documentation for details.
238
Jan Kiszka414fa982012-04-24 16:40:15 +0200239
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002404.6 KVM_SET_MEMORY_REGION
241
242Capability: basic
243Architectures: all
244Type: vm ioctl
245Parameters: struct kvm_memory_region (in)
246Returns: 0 on success, -1 on error
247
Avi Kivityb74a07b2010-06-21 11:48:05 +0300248This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300249
Jan Kiszka414fa982012-04-24 16:40:15 +0200250
Paul Bolle68ba6972011-02-15 00:05:59 +01002514.7 KVM_CREATE_VCPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300252
253Capability: basic
254Architectures: all
255Type: vm ioctl
256Parameters: vcpu id (apic id on x86)
257Returns: vcpu fd on success, -1 on error
258
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200259This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
260The vcpu id is an integer in the range [0, max_vcpu_id).
Sasha Levin8c3ba332011-07-18 17:17:15 +0300261
262The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
263the KVM_CHECK_EXTENSION ioctl() at run-time.
264The maximum possible value for max_vcpus can be retrieved using the
265KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
266
Pekka Enberg76d25402011-05-09 22:48:54 +0300267If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
268cpus max.
Sasha Levin8c3ba332011-07-18 17:17:15 +0300269If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
270same as the value returned from KVM_CAP_NR_VCPUS.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300271
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200272The maximum possible value for max_vcpu_id can be retrieved using the
273KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
274
275If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
276is the same as the value returned from KVM_CAP_MAX_VCPUS.
277
Paul Mackerras371fefd2011-06-29 00:23:08 +0000278On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
279threads in one or more virtual CPU cores. (This is because the
280hardware requires all the hardware threads in a CPU core to be in the
281same partition.) The KVM_CAP_PPC_SMT capability indicates the number
282of vcpus per virtual core (vcore). The vcore id is obtained by
283dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
284given vcore will always be in the same physical core as each other
285(though that might be a different physical core from time to time).
286Userspace can control the threading (SMT) mode of the guest by its
287allocation of vcpu ids. For example, if userspace wants
288single-threaded guest vcpus, it should make all vcpu ids be a multiple
289of the number of vcpus per vcore.
290
Carsten Otte5b1c1492012-01-04 10:25:23 +0100291For virtual cpus that have been created with S390 user controlled virtual
292machines, the resulting vcpu fd can be memory mapped at page offset
293KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
294cpu's hardware control block.
295
Jan Kiszka414fa982012-04-24 16:40:15 +0200296
Paul Bolle68ba6972011-02-15 00:05:59 +01002974.8 KVM_GET_DIRTY_LOG (vm ioctl)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300298
299Capability: basic
300Architectures: x86
301Type: vm ioctl
302Parameters: struct kvm_dirty_log (in/out)
303Returns: 0 on success, -1 on error
304
305/* for KVM_GET_DIRTY_LOG */
306struct kvm_dirty_log {
307 __u32 slot;
308 __u32 padding;
309 union {
310 void __user *dirty_bitmap; /* one bit per page */
311 __u64 padding;
312 };
313};
314
315Given a memory slot, return a bitmap containing any pages dirtied
316since the last call to this ioctl. Bit 0 is the first page in the
317memory slot. Ensure the entire structure is cleared to avoid padding
318issues.
319
Paolo Bonzinif481b062015-05-17 17:30:37 +0200320If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies
321the address space for which you want to return the dirty bitmap.
322They must be less than the value that KVM_CHECK_EXTENSION returns for
323the KVM_CAP_MULTI_ADDRESS_SPACE capability.
324
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +0200325The bits in the dirty bitmap are cleared before the ioctl returns, unless
326KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is enabled. For more information,
327see the description of the capability.
Jan Kiszka414fa982012-04-24 16:40:15 +0200328
Paul Bolle68ba6972011-02-15 00:05:59 +01003294.9 KVM_SET_MEMORY_ALIAS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300330
331Capability: basic
332Architectures: x86
333Type: vm ioctl
334Parameters: struct kvm_memory_alias (in)
335Returns: 0 (success), -1 (error)
336
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300337This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300338
Jan Kiszka414fa982012-04-24 16:40:15 +0200339
Paul Bolle68ba6972011-02-15 00:05:59 +01003404.10 KVM_RUN
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300341
342Capability: basic
343Architectures: all
344Type: vcpu ioctl
345Parameters: none
346Returns: 0 on success, -1 on error
347Errors:
348 EINTR: an unmasked signal is pending
349
350This ioctl is used to run a guest virtual cpu. While there are no
351explicit parameters, there is an implicit parameter block that can be
352obtained by mmap()ing the vcpu fd at offset 0, with the size given by
353KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
354kvm_run' (see below).
355
Jan Kiszka414fa982012-04-24 16:40:15 +0200356
Paul Bolle68ba6972011-02-15 00:05:59 +01003574.11 KVM_GET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300358
359Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +0100360Architectures: all except ARM, arm64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300361Type: vcpu ioctl
362Parameters: struct kvm_regs (out)
363Returns: 0 on success, -1 on error
364
365Reads the general purpose registers from the vcpu.
366
367/* x86 */
368struct kvm_regs {
369 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
370 __u64 rax, rbx, rcx, rdx;
371 __u64 rsi, rdi, rsp, rbp;
372 __u64 r8, r9, r10, r11;
373 __u64 r12, r13, r14, r15;
374 __u64 rip, rflags;
375};
376
James Hoganc2d2c212014-07-04 15:11:35 +0100377/* mips */
378struct kvm_regs {
379 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
380 __u64 gpr[32];
381 __u64 hi;
382 __u64 lo;
383 __u64 pc;
384};
385
Jan Kiszka414fa982012-04-24 16:40:15 +0200386
Paul Bolle68ba6972011-02-15 00:05:59 +01003874.12 KVM_SET_REGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300388
389Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +0100390Architectures: all except ARM, arm64
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300391Type: vcpu ioctl
392Parameters: struct kvm_regs (in)
393Returns: 0 on success, -1 on error
394
395Writes the general purpose registers into the vcpu.
396
397See KVM_GET_REGS for the data structure.
398
Jan Kiszka414fa982012-04-24 16:40:15 +0200399
Paul Bolle68ba6972011-02-15 00:05:59 +01004004.13 KVM_GET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300401
402Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500403Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300404Type: vcpu ioctl
405Parameters: struct kvm_sregs (out)
406Returns: 0 on success, -1 on error
407
408Reads special registers from the vcpu.
409
410/* x86 */
411struct kvm_sregs {
412 struct kvm_segment cs, ds, es, fs, gs, ss;
413 struct kvm_segment tr, ldt;
414 struct kvm_dtable gdt, idt;
415 __u64 cr0, cr2, cr3, cr4, cr8;
416 __u64 efer;
417 __u64 apic_base;
418 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
419};
420
Mihai Caraman68e2ffe2012-12-11 03:38:23 +0000421/* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
Scott Wood5ce941e2011-04-27 17:24:21 -0500422
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300423interrupt_bitmap is a bitmap of pending external interrupts. At most
424one bit may be set. This interrupt has been acknowledged by the APIC
425but not yet injected into the cpu core.
426
Jan Kiszka414fa982012-04-24 16:40:15 +0200427
Paul Bolle68ba6972011-02-15 00:05:59 +01004284.14 KVM_SET_SREGS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300429
430Capability: basic
Scott Wood5ce941e2011-04-27 17:24:21 -0500431Architectures: x86, ppc
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300432Type: vcpu ioctl
433Parameters: struct kvm_sregs (in)
434Returns: 0 on success, -1 on error
435
436Writes special registers into the vcpu. See KVM_GET_SREGS for the
437data structures.
438
Jan Kiszka414fa982012-04-24 16:40:15 +0200439
Paul Bolle68ba6972011-02-15 00:05:59 +01004404.15 KVM_TRANSLATE
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300441
442Capability: basic
443Architectures: x86
444Type: vcpu ioctl
445Parameters: struct kvm_translation (in/out)
446Returns: 0 on success, -1 on error
447
448Translates a virtual address according to the vcpu's current address
449translation mode.
450
451struct kvm_translation {
452 /* in */
453 __u64 linear_address;
454
455 /* out */
456 __u64 physical_address;
457 __u8 valid;
458 __u8 writeable;
459 __u8 usermode;
460 __u8 pad[5];
461};
462
Jan Kiszka414fa982012-04-24 16:40:15 +0200463
Paul Bolle68ba6972011-02-15 00:05:59 +01004644.16 KVM_INTERRUPT
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300465
466Capability: basic
James Hoganc2d2c212014-07-04 15:11:35 +0100467Architectures: x86, ppc, mips
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300468Type: vcpu ioctl
469Parameters: struct kvm_interrupt (in)
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200470Returns: 0 on success, negative on failure.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300471
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200472Queues a hardware interrupt vector to be injected.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300473
474/* for KVM_INTERRUPT */
475struct kvm_interrupt {
476 /* in */
477 __u32 irq;
478};
479
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200480X86:
481
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200482Returns: 0 on success,
483 -EEXIST if an interrupt is already enqueued
484 -EINVAL the the irq number is invalid
485 -ENXIO if the PIC is in the kernel
486 -EFAULT if the pointer is invalid
487
488Note 'irq' is an interrupt vector, not an interrupt pin or line. This
489ioctl is useful if the in-kernel PIC is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300490
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200491PPC:
492
493Queues an external interrupt to be injected. This ioctl is overleaded
494with 3 different irq values:
495
496a) KVM_INTERRUPT_SET
497
498 This injects an edge type external interrupt into the guest once it's ready
499 to receive interrupts. When injected, the interrupt is done.
500
501b) KVM_INTERRUPT_UNSET
502
503 This unsets any pending interrupt.
504
505 Only available with KVM_CAP_PPC_UNSET_IRQ.
506
507c) KVM_INTERRUPT_SET_LEVEL
508
509 This injects a level type external interrupt into the guest context. The
510 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
511 is triggered.
512
513 Only available with KVM_CAP_PPC_IRQ_LEVEL.
514
515Note that any value for 'irq' other than the ones stated above is invalid
516and incurs unexpected behavior.
517
James Hoganc2d2c212014-07-04 15:11:35 +0100518MIPS:
519
520Queues an external interrupt to be injected into the virtual CPU. A negative
521interrupt number dequeues the interrupt.
522
Jan Kiszka414fa982012-04-24 16:40:15 +0200523
Paul Bolle68ba6972011-02-15 00:05:59 +01005244.17 KVM_DEBUG_GUEST
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300525
526Capability: basic
527Architectures: none
528Type: vcpu ioctl
529Parameters: none)
530Returns: -1 on error
531
532Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
533
Jan Kiszka414fa982012-04-24 16:40:15 +0200534
Paul Bolle68ba6972011-02-15 00:05:59 +01005354.18 KVM_GET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300536
Tom Lendacky801e4592018-02-21 13:39:51 -0600537Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300538Architectures: x86
Tom Lendacky801e4592018-02-21 13:39:51 -0600539Type: system ioctl, vcpu ioctl
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300540Parameters: struct kvm_msrs (in/out)
Tom Lendacky801e4592018-02-21 13:39:51 -0600541Returns: number of msrs successfully returned;
542 -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300543
Tom Lendacky801e4592018-02-21 13:39:51 -0600544When used as a system ioctl:
545Reads the values of MSR-based features that are available for the VM. This
546is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
547The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
548in a system ioctl.
549
550When used as a vcpu ioctl:
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300551Reads model-specific registers from the vcpu. Supported msr indices can
Tom Lendacky801e4592018-02-21 13:39:51 -0600552be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300553
554struct kvm_msrs {
555 __u32 nmsrs; /* number of msrs in entries */
556 __u32 pad;
557
558 struct kvm_msr_entry entries[0];
559};
560
561struct kvm_msr_entry {
562 __u32 index;
563 __u32 reserved;
564 __u64 data;
565};
566
567Application code should set the 'nmsrs' member (which indicates the
568size of the entries array) and the 'index' member of each array entry.
569kvm will fill in the 'data' member.
570
Jan Kiszka414fa982012-04-24 16:40:15 +0200571
Paul Bolle68ba6972011-02-15 00:05:59 +01005724.19 KVM_SET_MSRS
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300573
574Capability: basic
575Architectures: x86
576Type: vcpu ioctl
577Parameters: struct kvm_msrs (in)
578Returns: 0 on success, -1 on error
579
580Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
581data structures.
582
583Application code should set the 'nmsrs' member (which indicates the
584size of the entries array), and the 'index' and 'data' members of each
585array entry.
586
Jan Kiszka414fa982012-04-24 16:40:15 +0200587
Paul Bolle68ba6972011-02-15 00:05:59 +01005884.20 KVM_SET_CPUID
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300589
590Capability: basic
591Architectures: x86
592Type: vcpu ioctl
593Parameters: struct kvm_cpuid (in)
594Returns: 0 on success, -1 on error
595
596Defines the vcpu responses to the cpuid instruction. Applications
597should use the KVM_SET_CPUID2 ioctl if available.
598
599
600struct kvm_cpuid_entry {
601 __u32 function;
602 __u32 eax;
603 __u32 ebx;
604 __u32 ecx;
605 __u32 edx;
606 __u32 padding;
607};
608
609/* for KVM_SET_CPUID */
610struct kvm_cpuid {
611 __u32 nent;
612 __u32 padding;
613 struct kvm_cpuid_entry entries[0];
614};
615
Jan Kiszka414fa982012-04-24 16:40:15 +0200616
Paul Bolle68ba6972011-02-15 00:05:59 +01006174.21 KVM_SET_SIGNAL_MASK
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300618
619Capability: basic
James Hogan572e0922014-07-04 15:11:33 +0100620Architectures: all
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300621Type: vcpu ioctl
622Parameters: struct kvm_signal_mask (in)
623Returns: 0 on success, -1 on error
624
625Defines which signals are blocked during execution of KVM_RUN. This
626signal mask temporarily overrides the threads signal mask. Any
627unblocked signal received (except SIGKILL and SIGSTOP, which retain
628their traditional behaviour) will cause KVM_RUN to return with -EINTR.
629
630Note the signal will only be delivered if not blocked by the original
631signal mask.
632
633/* for KVM_SET_SIGNAL_MASK */
634struct kvm_signal_mask {
635 __u32 len;
636 __u8 sigset[0];
637};
638
Jan Kiszka414fa982012-04-24 16:40:15 +0200639
Paul Bolle68ba6972011-02-15 00:05:59 +01006404.22 KVM_GET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300641
642Capability: basic
643Architectures: x86
644Type: vcpu ioctl
645Parameters: struct kvm_fpu (out)
646Returns: 0 on success, -1 on error
647
648Reads the floating point state from the vcpu.
649
650/* for KVM_GET_FPU and KVM_SET_FPU */
651struct kvm_fpu {
652 __u8 fpr[8][16];
653 __u16 fcw;
654 __u16 fsw;
655 __u8 ftwx; /* in fxsave format */
656 __u8 pad1;
657 __u16 last_opcode;
658 __u64 last_ip;
659 __u64 last_dp;
660 __u8 xmm[16][16];
661 __u32 mxcsr;
662 __u32 pad2;
663};
664
Jan Kiszka414fa982012-04-24 16:40:15 +0200665
Paul Bolle68ba6972011-02-15 00:05:59 +01006664.23 KVM_SET_FPU
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300667
668Capability: basic
669Architectures: x86
670Type: vcpu ioctl
671Parameters: struct kvm_fpu (in)
672Returns: 0 on success, -1 on error
673
674Writes the floating point state to the vcpu.
675
676/* for KVM_GET_FPU and KVM_SET_FPU */
677struct kvm_fpu {
678 __u8 fpr[8][16];
679 __u16 fcw;
680 __u16 fsw;
681 __u8 ftwx; /* in fxsave format */
682 __u8 pad1;
683 __u16 last_opcode;
684 __u64 last_ip;
685 __u64 last_dp;
686 __u8 xmm[16][16];
687 __u32 mxcsr;
688 __u32 pad2;
689};
690
Jan Kiszka414fa982012-04-24 16:40:15 +0200691
Paul Bolle68ba6972011-02-15 00:05:59 +01006924.24 KVM_CREATE_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300693
Cornelia Huck84223592013-07-15 13:36:01 +0200694Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
Tiejun Chenc32a4272014-11-20 11:07:18 +0100695Architectures: x86, ARM, arm64, s390
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300696Type: vm ioctl
697Parameters: none
698Returns: 0 on success, -1 on error
699
Andre Przywaraac3d3732014-06-03 10:26:30 +0200700Creates an interrupt controller model in the kernel.
701On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
702future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
703PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
704On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of
705KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
706KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
707On s390, a dummy irq routing table is created.
Cornelia Huck84223592013-07-15 13:36:01 +0200708
709Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
710before KVM_CREATE_IRQCHIP can be used.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300711
Jan Kiszka414fa982012-04-24 16:40:15 +0200712
Paul Bolle68ba6972011-02-15 00:05:59 +01007134.25 KVM_IRQ_LINE
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300714
715Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100716Architectures: x86, arm, arm64
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300717Type: vm ioctl
718Parameters: struct kvm_irq_level
719Returns: 0 on success, -1 on error
720
721Sets the level of a GSI input to the interrupt controller model in the kernel.
Christoffer Dall86ce8532013-01-20 18:28:08 -0500722On some architectures it is required that an interrupt controller model has
723been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
724interrupts require the level to be set to 1 and then back to 0.
725
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500726On real hardware, interrupt pins can be active-low or active-high. This
727does not matter for the level field of struct kvm_irq_level: 1 always
728means active (asserted), 0 means inactive (deasserted).
729
730x86 allows the operating system to program the interrupt polarity
731(active-low/active-high) for level-triggered interrupts, and KVM used
732to consider the polarity. However, due to bitrot in the handling of
733active-low interrupts, the above convention is now valid on x86 too.
734This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
735should not present interrupts to the guest as active-low unless this
736capability is present (or unless it is not using the in-kernel irqchip,
737of course).
738
739
Marc Zyngier379e04c72013-04-02 17:46:31 +0100740ARM/arm64 can signal an interrupt either at the CPU level, or at the
741in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
742use PPIs designated for specific cpus. The irq field is interpreted
743like this:
Christoffer Dall86ce8532013-01-20 18:28:08 -0500744
745  bits: | 31 ... 24 | 23 ... 16 | 15 ... 0 |
746 field: | irq_type | vcpu_index | irq_id |
747
748The irq_type field has the following values:
749- irq_type[0]: out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
750- irq_type[1]: in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
751 (the vcpu_index field is ignored)
752- irq_type[2]: in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
753
754(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
755
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500756In both cases, level is used to assert/deassert the line.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300757
758struct kvm_irq_level {
759 union {
760 __u32 irq; /* GSI */
761 __s32 status; /* not used for KVM_IRQ_LEVEL */
762 };
763 __u32 level; /* 0 or 1 */
764};
765
Jan Kiszka414fa982012-04-24 16:40:15 +0200766
Paul Bolle68ba6972011-02-15 00:05:59 +01007674.26 KVM_GET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300768
769Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100770Architectures: x86
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300771Type: vm ioctl
772Parameters: struct kvm_irqchip (in/out)
773Returns: 0 on success, -1 on error
774
775Reads the state of a kernel interrupt controller created with
776KVM_CREATE_IRQCHIP into a buffer provided by the caller.
777
778struct kvm_irqchip {
779 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
780 __u32 pad;
781 union {
782 char dummy[512]; /* reserving space */
783 struct kvm_pic_state pic;
784 struct kvm_ioapic_state ioapic;
785 } chip;
786};
787
Jan Kiszka414fa982012-04-24 16:40:15 +0200788
Paul Bolle68ba6972011-02-15 00:05:59 +01007894.27 KVM_SET_IRQCHIP
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300790
791Capability: KVM_CAP_IRQCHIP
Tiejun Chenc32a4272014-11-20 11:07:18 +0100792Architectures: x86
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300793Type: vm ioctl
794Parameters: struct kvm_irqchip (in)
795Returns: 0 on success, -1 on error
796
797Sets the state of a kernel interrupt controller created with
798KVM_CREATE_IRQCHIP from a buffer provided by the caller.
799
800struct kvm_irqchip {
801 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
802 __u32 pad;
803 union {
804 char dummy[512]; /* reserving space */
805 struct kvm_pic_state pic;
806 struct kvm_ioapic_state ioapic;
807 } chip;
808};
809
Jan Kiszka414fa982012-04-24 16:40:15 +0200810
Paul Bolle68ba6972011-02-15 00:05:59 +01008114.28 KVM_XEN_HVM_CONFIG
Ed Swierkffde22a2009-10-15 15:21:43 -0700812
813Capability: KVM_CAP_XEN_HVM
814Architectures: x86
815Type: vm ioctl
816Parameters: struct kvm_xen_hvm_config (in)
817Returns: 0 on success, -1 on error
818
819Sets the MSR that the Xen HVM guest uses to initialize its hypercall
820page, and provides the starting address and size of the hypercall
821blobs in userspace. When the guest writes the MSR, kvm copies one
822page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
823memory.
824
825struct kvm_xen_hvm_config {
826 __u32 flags;
827 __u32 msr;
828 __u64 blob_addr_32;
829 __u64 blob_addr_64;
830 __u8 blob_size_32;
831 __u8 blob_size_64;
832 __u8 pad2[30];
833};
834
Jan Kiszka414fa982012-04-24 16:40:15 +0200835
Paul Bolle68ba6972011-02-15 00:05:59 +01008364.29 KVM_GET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400837
838Capability: KVM_CAP_ADJUST_CLOCK
839Architectures: x86
840Type: vm ioctl
841Parameters: struct kvm_clock_data (out)
842Returns: 0 on success, -1 on error
843
844Gets the current timestamp of kvmclock as seen by the current guest. In
845conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
846such as migration.
847
Paolo Bonzinie3fd9a92016-11-09 17:48:15 +0100848When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
849set of bits that KVM can return in struct kvm_clock_data's flag member.
850
851The only flag defined now is KVM_CLOCK_TSC_STABLE. If set, the returned
852value is the exact kvmclock value seen by all VCPUs at the instant
853when KVM_GET_CLOCK was called. If clear, the returned value is simply
854CLOCK_MONOTONIC plus a constant offset; the offset can be modified
855with KVM_SET_CLOCK. KVM will try to make all VCPUs follow this clock,
856but the exact value read by each VCPU could differ, because the host
857TSC is not stable.
858
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400859struct kvm_clock_data {
860 __u64 clock; /* kvmclock current value */
861 __u32 flags;
862 __u32 pad[9];
863};
864
Jan Kiszka414fa982012-04-24 16:40:15 +0200865
Paul Bolle68ba6972011-02-15 00:05:59 +01008664.30 KVM_SET_CLOCK
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400867
868Capability: KVM_CAP_ADJUST_CLOCK
869Architectures: x86
870Type: vm ioctl
871Parameters: struct kvm_clock_data (in)
872Returns: 0 on success, -1 on error
873
Wu Fengguang2044892d2009-12-24 09:04:16 +0800874Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400875In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
876such as migration.
877
878struct kvm_clock_data {
879 __u64 clock; /* kvmclock current value */
880 __u32 flags;
881 __u32 pad[9];
882};
883
Jan Kiszka414fa982012-04-24 16:40:15 +0200884
Paul Bolle68ba6972011-02-15 00:05:59 +01008854.31 KVM_GET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100886
887Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100888Extended by: KVM_CAP_INTR_SHADOW
James Morseb0960b92018-07-19 16:24:25 +0100889Architectures: x86, arm, arm64
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100890Type: vcpu ioctl
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100891Parameters: struct kvm_vcpu_event (out)
892Returns: 0 on success, -1 on error
893
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100894X86:
895
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100896Gets currently pending exceptions, interrupts, and NMIs as well as related
897states of the vcpu.
898
899struct kvm_vcpu_events {
900 struct {
901 __u8 injected;
902 __u8 nr;
903 __u8 has_error_code;
Jim Mattson59073aa2018-10-16 14:29:20 -0700904 __u8 pending;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100905 __u32 error_code;
906 } exception;
907 struct {
908 __u8 injected;
909 __u8 nr;
910 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +0100911 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100912 } interrupt;
913 struct {
914 __u8 injected;
915 __u8 pending;
916 __u8 masked;
917 __u8 pad;
918 } nmi;
919 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +0100920 __u32 flags;
Paolo Bonzinif0778252015-04-01 15:06:40 +0200921 struct {
922 __u8 smm;
923 __u8 pending;
924 __u8 smm_inside_nmi;
925 __u8 latched_init;
926 } smi;
Jim Mattson59073aa2018-10-16 14:29:20 -0700927 __u8 reserved[27];
928 __u8 exception_has_payload;
929 __u64 exception_payload;
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100930};
931
Jim Mattson59073aa2018-10-16 14:29:20 -0700932The following bits are defined in the flags field:
Jan Kiszka48005f62010-02-19 19:38:07 +0100933
Jim Mattson59073aa2018-10-16 14:29:20 -0700934- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that
Paolo Bonzinif0778252015-04-01 15:06:40 +0200935 interrupt.shadow contains a valid state.
936
Jim Mattson59073aa2018-10-16 14:29:20 -0700937- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a
938 valid state.
939
940- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the
941 exception_has_payload, exception_payload, and exception.pending
942 fields contain a valid state. This bit will be set whenever
943 KVM_CAP_EXCEPTION_PAYLOAD is enabled.
Jan Kiszka414fa982012-04-24 16:40:15 +0200944
James Morseb0960b92018-07-19 16:24:25 +0100945ARM/ARM64:
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100946
947If the guest accesses a device that is being emulated by the host kernel in
948such a way that a real device would generate a physical SError, KVM may make
949a virtual SError pending for that VCPU. This system error interrupt remains
950pending until the guest takes the exception by unmasking PSTATE.A.
951
952Running the VCPU may cause it to take a pending SError, or make an access that
953causes an SError to become pending. The event's description is only valid while
954the VPCU is not running.
955
956This API provides a way to read and write the pending 'event' state that is not
957visible to the guest. To save, restore or migrate a VCPU the struct representing
958the state can be read then written using this GET/SET API, along with the other
959guest-visible registers. It is not possible to 'cancel' an SError that has been
960made pending.
961
962A device being emulated in user-space may also wish to generate an SError. To do
963this the events structure can be populated by user-space. The current state
964should be read first, to ensure no existing SError is pending. If an existing
965SError is pending, the architecture's 'Multiple SError interrupts' rules should
966be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
967Serviceability (RAS) Specification").
968
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +0100969SError exceptions always have an ESR value. Some CPUs have the ability to
970specify what the virtual SError's ESR value should be. These systems will
Dongjiu Geng688e0582018-08-20 17:39:25 -0400971advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +0100972always have a non-zero value when read, and the agent making an SError pending
973should specify the ISS field in the lower 24 bits of exception.serror_esr. If
Dongjiu Geng688e0582018-08-20 17:39:25 -0400974the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +0100975with exception.has_esr as zero, KVM will choose an ESR.
976
977Specifying exception.has_esr on a system that does not support it will return
978-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
979will return -EINVAL.
980
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100981struct kvm_vcpu_events {
982 struct {
983 __u8 serror_pending;
984 __u8 serror_has_esr;
985 /* Align it to 8 bytes */
986 __u8 pad[6];
987 __u64 serror_esr;
988 } exception;
989 __u32 reserved[12];
990};
991
Paul Bolle68ba6972011-02-15 00:05:59 +01009924.32 KVM_SET_VCPU_EVENTS
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100993
994Capability: KVM_CAP_VCPU_EVENTS
Jan Kiszka48005f62010-02-19 19:38:07 +0100995Extended by: KVM_CAP_INTR_SHADOW
James Morseb0960b92018-07-19 16:24:25 +0100996Architectures: x86, arm, arm64
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +0100997Type: vcpu ioctl
Jan Kiszka3cfc3092009-11-12 01:04:25 +0100998Parameters: struct kvm_vcpu_event (in)
999Returns: 0 on success, -1 on error
1000
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001001X86:
1002
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001003Set pending exceptions, interrupts, and NMIs as well as related states of the
1004vcpu.
1005
1006See KVM_GET_VCPU_EVENTS for the data structure.
1007
Jan Kiszkadab4b912009-12-06 18:24:15 +01001008Fields that may be modified asynchronously by running VCPUs can be excluded
Paolo Bonzinif0778252015-04-01 15:06:40 +02001009from the update. These fields are nmi.pending, sipi_vector, smi.smm,
1010smi.pending. Keep the corresponding bits in the flags field cleared to
1011suppress overwriting the current in-kernel state. The bits are:
Jan Kiszkadab4b912009-12-06 18:24:15 +01001012
1013KVM_VCPUEVENT_VALID_NMI_PENDING - transfer nmi.pending to the kernel
1014KVM_VCPUEVENT_VALID_SIPI_VECTOR - transfer sipi_vector
Paolo Bonzinif0778252015-04-01 15:06:40 +02001015KVM_VCPUEVENT_VALID_SMM - transfer the smi sub-struct.
Jan Kiszkadab4b912009-12-06 18:24:15 +01001016
Jan Kiszka48005f62010-02-19 19:38:07 +01001017If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
1018the flags field to signal that interrupt.shadow contains a valid state and
1019shall be written into the VCPU.
1020
Paolo Bonzinif0778252015-04-01 15:06:40 +02001021KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
1022
Jim Mattson59073aa2018-10-16 14:29:20 -07001023If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD
1024can be set in the flags field to signal that the
1025exception_has_payload, exception_payload, and exception.pending fields
1026contain a valid state and shall be written into the VCPU.
1027
James Morseb0960b92018-07-19 16:24:25 +01001028ARM/ARM64:
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001029
1030Set the pending SError exception state for this VCPU. It is not possible to
1031'cancel' an Serror that has been made pending.
1032
1033See KVM_GET_VCPU_EVENTS for the data structure.
1034
Jan Kiszka414fa982012-04-24 16:40:15 +02001035
Paul Bolle68ba6972011-02-15 00:05:59 +010010364.33 KVM_GET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001037
1038Capability: KVM_CAP_DEBUGREGS
1039Architectures: x86
1040Type: vm ioctl
1041Parameters: struct kvm_debugregs (out)
1042Returns: 0 on success, -1 on error
1043
1044Reads debug registers from the vcpu.
1045
1046struct kvm_debugregs {
1047 __u64 db[4];
1048 __u64 dr6;
1049 __u64 dr7;
1050 __u64 flags;
1051 __u64 reserved[9];
1052};
1053
Jan Kiszka414fa982012-04-24 16:40:15 +02001054
Paul Bolle68ba6972011-02-15 00:05:59 +010010554.34 KVM_SET_DEBUGREGS
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001056
1057Capability: KVM_CAP_DEBUGREGS
1058Architectures: x86
1059Type: vm ioctl
1060Parameters: struct kvm_debugregs (in)
1061Returns: 0 on success, -1 on error
1062
1063Writes debug registers into the vcpu.
1064
1065See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
1066yet and must be cleared on entry.
1067
Jan Kiszka414fa982012-04-24 16:40:15 +02001068
Paul Bolle68ba6972011-02-15 00:05:59 +010010694.35 KVM_SET_USER_MEMORY_REGION
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001070
1071Capability: KVM_CAP_USER_MEM
1072Architectures: all
1073Type: vm ioctl
1074Parameters: struct kvm_userspace_memory_region (in)
1075Returns: 0 on success, -1 on error
1076
1077struct kvm_userspace_memory_region {
1078 __u32 slot;
1079 __u32 flags;
1080 __u64 guest_phys_addr;
1081 __u64 memory_size; /* bytes */
1082 __u64 userspace_addr; /* start of the userspace allocated memory */
1083};
1084
1085/* for kvm_memory_region::flags */
Xiao Guangrong4d8b81a2012-08-21 11:02:51 +08001086#define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
1087#define KVM_MEM_READONLY (1UL << 1)
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001088
1089This ioctl allows the user to create or modify a guest physical memory
1090slot. When changing an existing slot, it may be moved in the guest
1091physical memory space, or its flags may be modified. It may not be
1092resized. Slots may not overlap in guest physical address space.
Linu Cheriana677e702017-03-08 11:38:32 +05301093Bits 0-15 of "slot" specifies the slot id and this value should be
1094less than the maximum number of user memory slots supported per VM.
1095The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS,
1096if this capability is supported by the architecture.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001097
Paolo Bonzinif481b062015-05-17 17:30:37 +02001098If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1099specifies the address space which is being modified. They must be
1100less than the value that KVM_CHECK_EXTENSION returns for the
1101KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
1102are unrelated; the restriction on overlapping slots only applies within
1103each address space.
1104
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001105Memory for the region is taken starting at the address denoted by the
1106field userspace_addr, which must point at user addressable memory for
1107the entire memory slot size. Any object may back this memory, including
1108anonymous memory, ordinary files, and hugetlbfs.
1109
1110It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1111be identical. This allows large pages in the guest to be backed by large
1112pages in the host.
1113
Takuya Yoshikawa75d61fb2013-01-30 19:40:41 +09001114The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1115KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
1116writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
1117use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1118to make a new slot read-only. In this case, writes to this memory will be
1119posted to userspace as KVM_EXIT_MMIO exits.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001120
Jan Kiszka7efd8fa2012-09-07 13:17:47 +02001121When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1122the memory region are automatically reflected into the guest. For example, an
1123mmap() that affects the region will be made visible immediately. Another
1124example is madvise(MADV_DROP).
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001125
1126It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
1127The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
1128allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001129
Jan Kiszka414fa982012-04-24 16:40:15 +02001130
Paul Bolle68ba6972011-02-15 00:05:59 +010011314.36 KVM_SET_TSS_ADDR
Avi Kivity8a5416d2010-03-25 12:27:30 +02001132
1133Capability: KVM_CAP_SET_TSS_ADDR
1134Architectures: x86
1135Type: vm ioctl
1136Parameters: unsigned long tss_address (in)
1137Returns: 0 on success, -1 on error
1138
1139This ioctl defines the physical address of a three-page region in the guest
1140physical address space. The region must be within the first 4GB of the
1141guest physical address space and must not conflict with any memory slot
1142or any mmio address. The guest may malfunction if it accesses this memory
1143region.
1144
1145This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1146because of a quirk in the virtualization implementation (see the internals
1147documentation when it pops into existence).
1148
Jan Kiszka414fa982012-04-24 16:40:15 +02001149
Paul Bolle68ba6972011-02-15 00:05:59 +010011504.37 KVM_ENABLE_CAP
Alexander Graf71fbfd52010-03-24 21:48:29 +01001151
Paolo Bonzinie5d83c72017-02-16 10:40:56 +01001152Capability: KVM_CAP_ENABLE_CAP
1153Architectures: mips, ppc, s390
1154Type: vcpu ioctl
1155Parameters: struct kvm_enable_cap (in)
1156Returns: 0 on success; -1 on error
1157
1158Capability: KVM_CAP_ENABLE_CAP_VM
1159Architectures: all
1160Type: vcpu ioctl
Alexander Graf71fbfd52010-03-24 21:48:29 +01001161Parameters: struct kvm_enable_cap (in)
1162Returns: 0 on success; -1 on error
1163
1164+Not all extensions are enabled by default. Using this ioctl the application
1165can enable an extension, making it available to the guest.
1166
1167On systems that do not support this ioctl, it always fails. On systems that
1168do support it, it only works for extensions that are supported for enablement.
1169
1170To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1171be used.
1172
1173struct kvm_enable_cap {
1174 /* in */
1175 __u32 cap;
1176
1177The capability that is supposed to get enabled.
1178
1179 __u32 flags;
1180
1181A bitfield indicating future enhancements. Has to be 0 for now.
1182
1183 __u64 args[4];
1184
1185Arguments for enabling a feature. If a feature needs initial values to
1186function properly, this is the place to put them.
1187
1188 __u8 pad[64];
1189};
1190
Cornelia Huckd938dc52013-10-23 18:26:34 +02001191The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1192for vm-wide capabilities.
Jan Kiszka414fa982012-04-24 16:40:15 +02001193
Paul Bolle68ba6972011-02-15 00:05:59 +010011944.38 KVM_GET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +03001195
1196Capability: KVM_CAP_MP_STATE
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001197Architectures: x86, s390, arm, arm64
Avi Kivityb843f062010-04-25 15:51:46 +03001198Type: vcpu ioctl
1199Parameters: struct kvm_mp_state (out)
1200Returns: 0 on success; -1 on error
1201
1202struct kvm_mp_state {
1203 __u32 mp_state;
1204};
1205
1206Returns the vcpu's current "multiprocessing state" (though also valid on
1207uniprocessor guests).
1208
1209Possible values are:
1210
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001211 - KVM_MP_STATE_RUNNABLE: the vcpu is currently running [x86,arm/arm64]
Avi Kivityb843f062010-04-25 15:51:46 +03001212 - KVM_MP_STATE_UNINITIALIZED: the vcpu is an application processor (AP)
Tiejun Chenc32a4272014-11-20 11:07:18 +01001213 which has not yet received an INIT signal [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001214 - KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
Tiejun Chenc32a4272014-11-20 11:07:18 +01001215 now ready for a SIPI [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001216 - KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
Tiejun Chenc32a4272014-11-20 11:07:18 +01001217 is waiting for an interrupt [x86]
Avi Kivityb843f062010-04-25 15:51:46 +03001218 - KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
Tiejun Chenc32a4272014-11-20 11:07:18 +01001219 accessible via KVM_GET_VCPU_EVENTS) [x86]
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001220 - KVM_MP_STATE_STOPPED: the vcpu is stopped [s390,arm/arm64]
David Hildenbrand6352e4d2014-04-10 17:35:00 +02001221 - KVM_MP_STATE_CHECK_STOP: the vcpu is in a special error state [s390]
1222 - KVM_MP_STATE_OPERATING: the vcpu is operating (running or halted)
1223 [s390]
1224 - KVM_MP_STATE_LOAD: the vcpu is in a special load/startup state
1225 [s390]
Avi Kivityb843f062010-04-25 15:51:46 +03001226
Tiejun Chenc32a4272014-11-20 11:07:18 +01001227On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001228in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1229these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001230
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001231For arm/arm64:
1232
1233The only states that are valid are KVM_MP_STATE_STOPPED and
1234KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001235
Paul Bolle68ba6972011-02-15 00:05:59 +010012364.39 KVM_SET_MP_STATE
Avi Kivityb843f062010-04-25 15:51:46 +03001237
1238Capability: KVM_CAP_MP_STATE
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001239Architectures: x86, s390, arm, arm64
Avi Kivityb843f062010-04-25 15:51:46 +03001240Type: vcpu ioctl
1241Parameters: struct kvm_mp_state (in)
1242Returns: 0 on success; -1 on error
1243
1244Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1245arguments.
1246
Tiejun Chenc32a4272014-11-20 11:07:18 +01001247On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001248in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1249these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001250
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001251For arm/arm64:
1252
1253The only states that are valid are KVM_MP_STATE_STOPPED and
1254KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001255
Paul Bolle68ba6972011-02-15 00:05:59 +010012564.40 KVM_SET_IDENTITY_MAP_ADDR
Avi Kivity47dbb842010-04-29 12:08:56 +03001257
1258Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1259Architectures: x86
1260Type: vm ioctl
1261Parameters: unsigned long identity (in)
1262Returns: 0 on success, -1 on error
1263
1264This ioctl defines the physical address of a one-page region in the guest
1265physical address space. The region must be within the first 4GB of the
1266guest physical address space and must not conflict with any memory slot
1267or any mmio address. The guest may malfunction if it accesses this memory
1268region.
1269
David Hildenbrand726b99c2017-08-24 20:51:35 +02001270Setting the address to 0 will result in resetting the address to its default
1271(0xfffbc000).
1272
Avi Kivity47dbb842010-04-29 12:08:56 +03001273This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1274because of a quirk in the virtualization implementation (see the internals
1275documentation when it pops into existence).
1276
David Hildenbrand1af1ac92017-08-24 20:51:36 +02001277Fails if any VCPU has already been created.
Jan Kiszka414fa982012-04-24 16:40:15 +02001278
Paul Bolle68ba6972011-02-15 00:05:59 +010012794.41 KVM_SET_BOOT_CPU_ID
Avi Kivity57bc24c2010-04-29 12:12:57 +03001280
1281Capability: KVM_CAP_SET_BOOT_CPU_ID
Tiejun Chenc32a4272014-11-20 11:07:18 +01001282Architectures: x86
Avi Kivity57bc24c2010-04-29 12:12:57 +03001283Type: vm ioctl
1284Parameters: unsigned long vcpu_id
1285Returns: 0 on success, -1 on error
1286
1287Define which vcpu is the Bootstrap Processor (BSP). Values are the same
1288as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
1289is vcpu 0.
1290
Jan Kiszka414fa982012-04-24 16:40:15 +02001291
Paul Bolle68ba6972011-02-15 00:05:59 +010012924.42 KVM_GET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001293
1294Capability: KVM_CAP_XSAVE
1295Architectures: x86
1296Type: vcpu ioctl
1297Parameters: struct kvm_xsave (out)
1298Returns: 0 on success, -1 on error
1299
1300struct kvm_xsave {
1301 __u32 region[1024];
1302};
1303
1304This ioctl would copy current vcpu's xsave struct to the userspace.
1305
Jan Kiszka414fa982012-04-24 16:40:15 +02001306
Paul Bolle68ba6972011-02-15 00:05:59 +010013074.43 KVM_SET_XSAVE
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001308
1309Capability: KVM_CAP_XSAVE
1310Architectures: x86
1311Type: vcpu ioctl
1312Parameters: struct kvm_xsave (in)
1313Returns: 0 on success, -1 on error
1314
1315struct kvm_xsave {
1316 __u32 region[1024];
1317};
1318
1319This ioctl would copy userspace's xsave struct to the kernel.
1320
Jan Kiszka414fa982012-04-24 16:40:15 +02001321
Paul Bolle68ba6972011-02-15 00:05:59 +010013224.44 KVM_GET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001323
1324Capability: KVM_CAP_XCRS
1325Architectures: x86
1326Type: vcpu ioctl
1327Parameters: struct kvm_xcrs (out)
1328Returns: 0 on success, -1 on error
1329
1330struct kvm_xcr {
1331 __u32 xcr;
1332 __u32 reserved;
1333 __u64 value;
1334};
1335
1336struct kvm_xcrs {
1337 __u32 nr_xcrs;
1338 __u32 flags;
1339 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1340 __u64 padding[16];
1341};
1342
1343This ioctl would copy current vcpu's xcrs to the userspace.
1344
Jan Kiszka414fa982012-04-24 16:40:15 +02001345
Paul Bolle68ba6972011-02-15 00:05:59 +010013464.45 KVM_SET_XCRS
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001347
1348Capability: KVM_CAP_XCRS
1349Architectures: x86
1350Type: vcpu ioctl
1351Parameters: struct kvm_xcrs (in)
1352Returns: 0 on success, -1 on error
1353
1354struct kvm_xcr {
1355 __u32 xcr;
1356 __u32 reserved;
1357 __u64 value;
1358};
1359
1360struct kvm_xcrs {
1361 __u32 nr_xcrs;
1362 __u32 flags;
1363 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1364 __u64 padding[16];
1365};
1366
1367This ioctl would set vcpu's xcr to the value userspace specified.
1368
Jan Kiszka414fa982012-04-24 16:40:15 +02001369
Paul Bolle68ba6972011-02-15 00:05:59 +010013704.46 KVM_GET_SUPPORTED_CPUID
Avi Kivityd1535132010-07-14 09:45:21 +03001371
1372Capability: KVM_CAP_EXT_CPUID
1373Architectures: x86
1374Type: system ioctl
1375Parameters: struct kvm_cpuid2 (in/out)
1376Returns: 0 on success, -1 on error
1377
1378struct kvm_cpuid2 {
1379 __u32 nent;
1380 __u32 padding;
1381 struct kvm_cpuid_entry2 entries[0];
1382};
1383
Borislav Petkov9c15bb12013-09-22 16:44:50 +02001384#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
1385#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
1386#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
Avi Kivityd1535132010-07-14 09:45:21 +03001387
1388struct kvm_cpuid_entry2 {
1389 __u32 function;
1390 __u32 index;
1391 __u32 flags;
1392 __u32 eax;
1393 __u32 ebx;
1394 __u32 ecx;
1395 __u32 edx;
1396 __u32 padding[3];
1397};
1398
Jim Mattsondf9cb9c2018-05-24 11:59:54 -07001399This ioctl returns x86 cpuid features which are supported by both the
1400hardware and kvm in its default configuration. Userspace can use the
1401information returned by this ioctl to construct cpuid information (for
1402KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1403userspace capabilities, and with user requirements (for example, the
1404user may wish to constrain cpuid to emulate older hardware, or for
1405feature consistency across a cluster).
1406
1407Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1408expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1409its default configuration. If userspace enables such capabilities, it
1410is responsible for modifying the results of this ioctl appropriately.
Avi Kivityd1535132010-07-14 09:45:21 +03001411
1412Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1413with the 'nent' field indicating the number of entries in the variable-size
1414array 'entries'. If the number of entries is too low to describe the cpu
1415capabilities, an error (E2BIG) is returned. If the number is too high,
1416the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1417number is just right, the 'nent' field is adjusted to the number of valid
1418entries in the 'entries' array, which is then filled.
1419
1420The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001421with unknown or unsupported features masked out. Some features (for example,
1422x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1423emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001424
1425 function: the eax value used to obtain the entry
1426 index: the ecx value used to obtain the entry (for entries that are
1427 affected by ecx)
1428 flags: an OR of zero or more of the following:
1429 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1430 if the index field is valid
1431 KVM_CPUID_FLAG_STATEFUL_FUNC:
1432 if cpuid for this function returns different values for successive
1433 invocations; there will be several entries with the same function,
1434 all with this flag set
1435 KVM_CPUID_FLAG_STATE_READ_NEXT:
1436 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
1437 the first entry to be read by a cpu
1438 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
1439 this function/index combination
1440
Jan Kiszka4d25a0662011-12-21 12:28:29 +01001441The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1442as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1443support. Instead it is reported via
1444
1445 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1446
1447if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1448feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1449
Jan Kiszka414fa982012-04-24 16:40:15 +02001450
Paul Bolle68ba6972011-02-15 00:05:59 +010014514.47 KVM_PPC_GET_PVINFO
Alexander Graf15711e92010-07-29 14:48:08 +02001452
1453Capability: KVM_CAP_PPC_GET_PVINFO
1454Architectures: ppc
1455Type: vm ioctl
1456Parameters: struct kvm_ppc_pvinfo (out)
1457Returns: 0 on success, !0 on error
1458
1459struct kvm_ppc_pvinfo {
1460 __u32 flags;
1461 __u32 hcall[4];
1462 __u8 pad[108];
1463};
1464
1465This ioctl fetches PV specific information that need to be passed to the guest
1466using the device tree or other means from vm context.
1467
Liu Yu-B132019202e072012-07-03 05:48:52 +00001468The hcall array defines 4 instructions that make up a hypercall.
Alexander Graf15711e92010-07-29 14:48:08 +02001469
1470If any additional field gets added to this structure later on, a bit for that
1471additional piece of information will be set in the flags bitmap.
1472
Liu Yu-B132019202e072012-07-03 05:48:52 +00001473The flags bitmap is defined as:
1474
1475 /* the host supports the ePAPR idle hcall
1476 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
Jan Kiszka414fa982012-04-24 16:40:15 +02001477
Paul Bolle68ba6972011-02-15 00:05:59 +010014784.52 KVM_SET_GSI_ROUTING
Jan Kiszka49f48172010-11-16 22:30:07 +01001479
1480Capability: KVM_CAP_IRQ_ROUTING
Eric Auger180ae7b2016-07-22 16:20:41 +00001481Architectures: x86 s390 arm arm64
Jan Kiszka49f48172010-11-16 22:30:07 +01001482Type: vm ioctl
1483Parameters: struct kvm_irq_routing (in)
1484Returns: 0 on success, -1 on error
1485
1486Sets the GSI routing table entries, overwriting any previously set entries.
1487
Eric Auger180ae7b2016-07-22 16:20:41 +00001488On arm/arm64, GSI routing has the following limitation:
1489- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1490
Jan Kiszka49f48172010-11-16 22:30:07 +01001491struct kvm_irq_routing {
1492 __u32 nr;
1493 __u32 flags;
1494 struct kvm_irq_routing_entry entries[0];
1495};
1496
1497No flags are specified so far, the corresponding field must be set to zero.
1498
1499struct kvm_irq_routing_entry {
1500 __u32 gsi;
1501 __u32 type;
1502 __u32 flags;
1503 __u32 pad;
1504 union {
1505 struct kvm_irq_routing_irqchip irqchip;
1506 struct kvm_irq_routing_msi msi;
Cornelia Huck84223592013-07-15 13:36:01 +02001507 struct kvm_irq_routing_s390_adapter adapter;
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001508 struct kvm_irq_routing_hv_sint hv_sint;
Jan Kiszka49f48172010-11-16 22:30:07 +01001509 __u32 pad[8];
1510 } u;
1511};
1512
1513/* gsi routing entry types */
1514#define KVM_IRQ_ROUTING_IRQCHIP 1
1515#define KVM_IRQ_ROUTING_MSI 2
Cornelia Huck84223592013-07-15 13:36:01 +02001516#define KVM_IRQ_ROUTING_S390_ADAPTER 3
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001517#define KVM_IRQ_ROUTING_HV_SINT 4
Jan Kiszka49f48172010-11-16 22:30:07 +01001518
Eric Auger76a10b82016-07-22 16:20:37 +00001519flags:
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001520- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1521 type, specifies that the devid field contains a valid value. The per-VM
1522 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1523 the device ID. If this capability is not available, userspace should
1524 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Eric Auger76a10b82016-07-22 16:20:37 +00001525- zero otherwise
Jan Kiszka49f48172010-11-16 22:30:07 +01001526
1527struct kvm_irq_routing_irqchip {
1528 __u32 irqchip;
1529 __u32 pin;
1530};
1531
1532struct kvm_irq_routing_msi {
1533 __u32 address_lo;
1534 __u32 address_hi;
1535 __u32 data;
Eric Auger76a10b82016-07-22 16:20:37 +00001536 union {
1537 __u32 pad;
1538 __u32 devid;
1539 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001540};
1541
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001542If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1543for the device that wrote the MSI message. For PCI, this is usually a
1544BFD identifier in the lower 16 bits.
Eric Auger76a10b82016-07-22 16:20:37 +00001545
Radim Krčmář371313132016-07-12 22:09:27 +02001546On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1547feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
1548address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
1549address_hi must be zero.
1550
Cornelia Huck84223592013-07-15 13:36:01 +02001551struct kvm_irq_routing_s390_adapter {
1552 __u64 ind_addr;
1553 __u64 summary_addr;
1554 __u64 ind_offset;
1555 __u32 summary_offset;
1556 __u32 adapter_id;
1557};
1558
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001559struct kvm_irq_routing_hv_sint {
1560 __u32 vcpu;
1561 __u32 sint;
1562};
Jan Kiszka414fa982012-04-24 16:40:15 +02001563
Jan Kiszka414fa982012-04-24 16:40:15 +02001564
15654.55 KVM_SET_TSC_KHZ
Joerg Roedel92a1f122011-03-25 09:44:51 +01001566
1567Capability: KVM_CAP_TSC_CONTROL
1568Architectures: x86
1569Type: vcpu ioctl
1570Parameters: virtual tsc_khz
1571Returns: 0 on success, -1 on error
1572
1573Specifies the tsc frequency for the virtual machine. The unit of the
1574frequency is KHz.
1575
Jan Kiszka414fa982012-04-24 16:40:15 +02001576
15774.56 KVM_GET_TSC_KHZ
Joerg Roedel92a1f122011-03-25 09:44:51 +01001578
1579Capability: KVM_CAP_GET_TSC_KHZ
1580Architectures: x86
1581Type: vcpu ioctl
1582Parameters: none
1583Returns: virtual tsc-khz on success, negative value on error
1584
1585Returns the tsc frequency of the guest. The unit of the return value is
1586KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1587error.
1588
Jan Kiszka414fa982012-04-24 16:40:15 +02001589
15904.57 KVM_GET_LAPIC
Avi Kivitye7677932011-05-11 08:30:51 -04001591
1592Capability: KVM_CAP_IRQCHIP
1593Architectures: x86
1594Type: vcpu ioctl
1595Parameters: struct kvm_lapic_state (out)
1596Returns: 0 on success, -1 on error
1597
1598#define KVM_APIC_REG_SIZE 0x400
1599struct kvm_lapic_state {
1600 char regs[KVM_APIC_REG_SIZE];
1601};
1602
1603Reads the Local APIC registers and copies them into the input argument. The
1604data format and layout are the same as documented in the architecture manual.
1605
Radim Krčmář371313132016-07-12 22:09:27 +02001606If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
1607enabled, then the format of APIC_ID register depends on the APIC mode
1608(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in
1609the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID
1610which is stored in bits 31-24 of the APIC register, or equivalently in
1611byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then
1612be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
1613
1614If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
1615always uses xAPIC format.
1616
Jan Kiszka414fa982012-04-24 16:40:15 +02001617
16184.58 KVM_SET_LAPIC
Avi Kivitye7677932011-05-11 08:30:51 -04001619
1620Capability: KVM_CAP_IRQCHIP
1621Architectures: x86
1622Type: vcpu ioctl
1623Parameters: struct kvm_lapic_state (in)
1624Returns: 0 on success, -1 on error
1625
1626#define KVM_APIC_REG_SIZE 0x400
1627struct kvm_lapic_state {
1628 char regs[KVM_APIC_REG_SIZE];
1629};
1630
Masanari Iidadf5cbb22014-03-21 10:04:30 +09001631Copies the input argument into the Local APIC registers. The data format
Avi Kivitye7677932011-05-11 08:30:51 -04001632and layout are the same as documented in the architecture manual.
1633
Radim Krčmář371313132016-07-12 22:09:27 +02001634The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
1635regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
1636See the note in KVM_GET_LAPIC.
1637
Jan Kiszka414fa982012-04-24 16:40:15 +02001638
16394.59 KVM_IOEVENTFD
Sasha Levin55399a02011-05-28 14:12:30 +03001640
1641Capability: KVM_CAP_IOEVENTFD
1642Architectures: all
1643Type: vm ioctl
1644Parameters: struct kvm_ioeventfd (in)
1645Returns: 0 on success, !0 on error
1646
1647This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1648within the guest. A guest write in the registered address will signal the
1649provided event instead of triggering an exit.
1650
1651struct kvm_ioeventfd {
1652 __u64 datamatch;
1653 __u64 addr; /* legal pio/mmio address */
Jason Wange9ea5062015-09-15 14:41:59 +08001654 __u32 len; /* 0, 1, 2, 4, or 8 bytes */
Sasha Levin55399a02011-05-28 14:12:30 +03001655 __s32 fd;
1656 __u32 flags;
1657 __u8 pad[36];
1658};
1659
Cornelia Huck2b834512013-02-28 12:33:20 +01001660For the special case of virtio-ccw devices on s390, the ioevent is matched
1661to a subchannel/virtqueue tuple instead.
1662
Sasha Levin55399a02011-05-28 14:12:30 +03001663The following flags are defined:
1664
1665#define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1666#define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1667#define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
Cornelia Huck2b834512013-02-28 12:33:20 +01001668#define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
1669 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
Sasha Levin55399a02011-05-28 14:12:30 +03001670
1671If datamatch flag is set, the event will be signaled only if the written value
1672to the registered address is equal to datamatch in struct kvm_ioeventfd.
1673
Cornelia Huck2b834512013-02-28 12:33:20 +01001674For virtio-ccw devices, addr contains the subchannel id and datamatch the
1675virtqueue index.
1676
Jason Wange9ea5062015-09-15 14:41:59 +08001677With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
1678the kernel will ignore the length of guest write and may get a faster vmexit.
1679The speedup may only apply to specific architectures, but the ioeventfd will
1680work anyway.
Jan Kiszka414fa982012-04-24 16:40:15 +02001681
16824.60 KVM_DIRTY_TLB
Scott Wooddc83b8b2011-08-18 15:25:21 -05001683
1684Capability: KVM_CAP_SW_TLB
1685Architectures: ppc
1686Type: vcpu ioctl
1687Parameters: struct kvm_dirty_tlb (in)
1688Returns: 0 on success, -1 on error
1689
1690struct kvm_dirty_tlb {
1691 __u64 bitmap;
1692 __u32 num_dirty;
1693};
1694
1695This must be called whenever userspace has changed an entry in the shared
1696TLB, prior to calling KVM_RUN on the associated vcpu.
1697
1698The "bitmap" field is the userspace address of an array. This array
1699consists of a number of bits, equal to the total number of TLB entries as
1700determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
1701nearest multiple of 64.
1702
1703Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
1704array.
1705
1706The array is little-endian: the bit 0 is the least significant bit of the
1707first byte, bit 8 is the least significant bit of the second byte, etc.
1708This avoids any complications with differing word sizes.
1709
1710The "num_dirty" field is a performance hint for KVM to determine whether it
1711should skip processing the bitmap and just invalidate everything. It must
1712be set to the number of set bits in the bitmap.
1713
Jan Kiszka414fa982012-04-24 16:40:15 +02001714
David Gibson54738c02011-06-29 00:22:41 +000017154.62 KVM_CREATE_SPAPR_TCE
1716
1717Capability: KVM_CAP_SPAPR_TCE
1718Architectures: powerpc
1719Type: vm ioctl
1720Parameters: struct kvm_create_spapr_tce (in)
1721Returns: file descriptor for manipulating the created TCE table
1722
1723This creates a virtual TCE (translation control entry) table, which
1724is an IOMMU for PAPR-style virtual I/O. It is used to translate
1725logical addresses used in virtual I/O into guest physical addresses,
1726and provides a scatter/gather capability for PAPR virtual I/O.
1727
1728/* for KVM_CAP_SPAPR_TCE */
1729struct kvm_create_spapr_tce {
1730 __u64 liobn;
1731 __u32 window_size;
1732};
1733
1734The liobn field gives the logical IO bus number for which to create a
1735TCE table. The window_size field specifies the size of the DMA window
1736which this TCE table will translate - the table will contain one 64
1737bit TCE entry for every 4kiB of the DMA window.
1738
1739When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
1740table has been created using this ioctl(), the kernel will handle it
1741in real mode, updating the TCE table. H_PUT_TCE calls for other
1742liobns will cause a vm exit and must be handled by userspace.
1743
1744The return value is a file descriptor which can be passed to mmap(2)
1745to map the created TCE table into userspace. This lets userspace read
1746the entries written by kernel-handled H_PUT_TCE calls, and also lets
1747userspace update the TCE table directly which is useful in some
1748circumstances.
1749
Jan Kiszka414fa982012-04-24 16:40:15 +02001750
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +000017514.63 KVM_ALLOCATE_RMA
1752
1753Capability: KVM_CAP_PPC_RMA
1754Architectures: powerpc
1755Type: vm ioctl
1756Parameters: struct kvm_allocate_rma (out)
1757Returns: file descriptor for mapping the allocated RMA
1758
1759This allocates a Real Mode Area (RMA) from the pool allocated at boot
1760time by the kernel. An RMA is a physically-contiguous, aligned region
1761of memory used on older POWER processors to provide the memory which
1762will be accessed by real-mode (MMU off) accesses in a KVM guest.
1763POWER processors support a set of sizes for the RMA that usually
1764includes 64MB, 128MB, 256MB and some larger powers of two.
1765
1766/* for KVM_ALLOCATE_RMA */
1767struct kvm_allocate_rma {
1768 __u64 rma_size;
1769};
1770
1771The return value is a file descriptor which can be passed to mmap(2)
1772to map the allocated RMA into userspace. The mapped area can then be
1773passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
1774RMA for a virtual machine. The size of the RMA in bytes (which is
1775fixed at host kernel boot time) is returned in the rma_size field of
1776the argument structure.
1777
1778The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
1779is supported; 2 if the processor requires all virtual machines to have
1780an RMA, or 1 if the processor can use an RMA but doesn't require it,
1781because it supports the Virtual RMA (VRMA) facility.
1782
Jan Kiszka414fa982012-04-24 16:40:15 +02001783
Avi Kivity3f745f12011-12-07 12:42:47 +020017844.64 KVM_NMI
1785
1786Capability: KVM_CAP_USER_NMI
1787Architectures: x86
1788Type: vcpu ioctl
1789Parameters: none
1790Returns: 0 on success, -1 on error
1791
1792Queues an NMI on the thread's vcpu. Note this is well defined only
1793when KVM_CREATE_IRQCHIP has not been called, since this is an interface
1794between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
1795has been called, this interface is completely emulated within the kernel.
1796
1797To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
1798following algorithm:
1799
Masanari Iida5d4f6f32015-10-04 00:46:21 +09001800 - pause the vcpu
Avi Kivity3f745f12011-12-07 12:42:47 +02001801 - read the local APIC's state (KVM_GET_LAPIC)
1802 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
1803 - if so, issue KVM_NMI
1804 - resume the vcpu
1805
1806Some guests configure the LINT1 NMI input to cause a panic, aiding in
1807debugging.
1808
Jan Kiszka414fa982012-04-24 16:40:15 +02001809
Alexander Grafe24ed812011-09-14 10:02:41 +020018104.65 KVM_S390_UCAS_MAP
Carsten Otte27e03932012-01-04 10:25:21 +01001811
1812Capability: KVM_CAP_S390_UCONTROL
1813Architectures: s390
1814Type: vcpu ioctl
1815Parameters: struct kvm_s390_ucas_mapping (in)
1816Returns: 0 in case of success
1817
1818The parameter is defined like this:
1819 struct kvm_s390_ucas_mapping {
1820 __u64 user_addr;
1821 __u64 vcpu_addr;
1822 __u64 length;
1823 };
1824
1825This ioctl maps the memory at "user_addr" with the length "length" to
1826the vcpu's address space starting at "vcpu_addr". All parameters need to
Anatol Pomozovf884ab12013-05-08 16:56:16 -07001827be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01001828
Jan Kiszka414fa982012-04-24 16:40:15 +02001829
Alexander Grafe24ed812011-09-14 10:02:41 +020018304.66 KVM_S390_UCAS_UNMAP
Carsten Otte27e03932012-01-04 10:25:21 +01001831
1832Capability: KVM_CAP_S390_UCONTROL
1833Architectures: s390
1834Type: vcpu ioctl
1835Parameters: struct kvm_s390_ucas_mapping (in)
1836Returns: 0 in case of success
1837
1838The parameter is defined like this:
1839 struct kvm_s390_ucas_mapping {
1840 __u64 user_addr;
1841 __u64 vcpu_addr;
1842 __u64 length;
1843 };
1844
1845This ioctl unmaps the memory in the vcpu's address space starting at
1846"vcpu_addr" with the length "length". The field "user_addr" is ignored.
Anatol Pomozovf884ab12013-05-08 16:56:16 -07001847All parameters need to be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01001848
Jan Kiszka414fa982012-04-24 16:40:15 +02001849
Alexander Grafe24ed812011-09-14 10:02:41 +020018504.67 KVM_S390_VCPU_FAULT
Carsten Otteccc79102012-01-04 10:25:26 +01001851
1852Capability: KVM_CAP_S390_UCONTROL
1853Architectures: s390
1854Type: vcpu ioctl
1855Parameters: vcpu absolute address (in)
1856Returns: 0 in case of success
1857
1858This call creates a page table entry on the virtual cpu's address space
1859(for user controlled virtual machines) or the virtual machine's address
1860space (for regular virtual machines). This only works for minor faults,
1861thus it's recommended to access subject memory page via the user page
1862table upfront. This is useful to handle validity intercepts for user
1863controlled virtual machines to fault in the virtual cpu's lowcore pages
1864prior to calling the KVM_RUN ioctl.
1865
Jan Kiszka414fa982012-04-24 16:40:15 +02001866
Alexander Grafe24ed812011-09-14 10:02:41 +020018674.68 KVM_SET_ONE_REG
1868
1869Capability: KVM_CAP_ONE_REG
1870Architectures: all
1871Type: vcpu ioctl
1872Parameters: struct kvm_one_reg (in)
1873Returns: 0 on success, negative value on failure
Dave Martin395f5622019-01-15 17:02:08 +00001874Errors:
1875  ENOENT:   no such register
Dave Martinfe365b42019-04-12 12:59:47 +01001876  EINVAL:   invalid register ID, or no such register
1877  EPERM:    (arm64) register access not allowed before vcpu finalization
1878(These error codes are indicative only: do not rely on a specific error
1879code being returned in a specific situation.)
Alexander Grafe24ed812011-09-14 10:02:41 +02001880
1881struct kvm_one_reg {
1882 __u64 id;
1883 __u64 addr;
1884};
1885
1886Using this ioctl, a single vcpu register can be set to a specific value
1887defined by user space with the passed in struct kvm_one_reg, where id
1888refers to the register identifier as described below and addr is a pointer
1889to a variable with the respective size. There can be architecture agnostic
1890and architecture specific registers. Each have their own range of operation
1891and their own constants and width. To keep track of the implemented
1892registers, find a list below:
1893
James Hoganbf5590f2014-07-04 15:11:34 +01001894 Arch | Register | Width (bits)
1895 | |
1896 PPC | KVM_REG_PPC_HIOR | 64
1897 PPC | KVM_REG_PPC_IAC1 | 64
1898 PPC | KVM_REG_PPC_IAC2 | 64
1899 PPC | KVM_REG_PPC_IAC3 | 64
1900 PPC | KVM_REG_PPC_IAC4 | 64
1901 PPC | KVM_REG_PPC_DAC1 | 64
1902 PPC | KVM_REG_PPC_DAC2 | 64
1903 PPC | KVM_REG_PPC_DABR | 64
1904 PPC | KVM_REG_PPC_DSCR | 64
1905 PPC | KVM_REG_PPC_PURR | 64
1906 PPC | KVM_REG_PPC_SPURR | 64
1907 PPC | KVM_REG_PPC_DAR | 64
1908 PPC | KVM_REG_PPC_DSISR | 32
1909 PPC | KVM_REG_PPC_AMR | 64
1910 PPC | KVM_REG_PPC_UAMOR | 64
1911 PPC | KVM_REG_PPC_MMCR0 | 64
1912 PPC | KVM_REG_PPC_MMCR1 | 64
1913 PPC | KVM_REG_PPC_MMCRA | 64
1914 PPC | KVM_REG_PPC_MMCR2 | 64
1915 PPC | KVM_REG_PPC_MMCRS | 64
1916 PPC | KVM_REG_PPC_SIAR | 64
1917 PPC | KVM_REG_PPC_SDAR | 64
1918 PPC | KVM_REG_PPC_SIER | 64
1919 PPC | KVM_REG_PPC_PMC1 | 32
1920 PPC | KVM_REG_PPC_PMC2 | 32
1921 PPC | KVM_REG_PPC_PMC3 | 32
1922 PPC | KVM_REG_PPC_PMC4 | 32
1923 PPC | KVM_REG_PPC_PMC5 | 32
1924 PPC | KVM_REG_PPC_PMC6 | 32
1925 PPC | KVM_REG_PPC_PMC7 | 32
1926 PPC | KVM_REG_PPC_PMC8 | 32
1927 PPC | KVM_REG_PPC_FPR0 | 64
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001928 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001929 PPC | KVM_REG_PPC_FPR31 | 64
1930 PPC | KVM_REG_PPC_VR0 | 128
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001931 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001932 PPC | KVM_REG_PPC_VR31 | 128
1933 PPC | KVM_REG_PPC_VSR0 | 128
Paul Mackerrasa8bd19e2012-09-25 20:32:30 +00001934 ...
James Hoganbf5590f2014-07-04 15:11:34 +01001935 PPC | KVM_REG_PPC_VSR31 | 128
1936 PPC | KVM_REG_PPC_FPSCR | 64
1937 PPC | KVM_REG_PPC_VSCR | 32
1938 PPC | KVM_REG_PPC_VPA_ADDR | 64
1939 PPC | KVM_REG_PPC_VPA_SLB | 128
1940 PPC | KVM_REG_PPC_VPA_DTL | 128
1941 PPC | KVM_REG_PPC_EPCR | 32
1942 PPC | KVM_REG_PPC_EPR | 32
1943 PPC | KVM_REG_PPC_TCR | 32
1944 PPC | KVM_REG_PPC_TSR | 32
1945 PPC | KVM_REG_PPC_OR_TSR | 32
1946 PPC | KVM_REG_PPC_CLEAR_TSR | 32
1947 PPC | KVM_REG_PPC_MAS0 | 32
1948 PPC | KVM_REG_PPC_MAS1 | 32
1949 PPC | KVM_REG_PPC_MAS2 | 64
1950 PPC | KVM_REG_PPC_MAS7_3 | 64
1951 PPC | KVM_REG_PPC_MAS4 | 32
1952 PPC | KVM_REG_PPC_MAS6 | 32
1953 PPC | KVM_REG_PPC_MMUCFG | 32
1954 PPC | KVM_REG_PPC_TLB0CFG | 32
1955 PPC | KVM_REG_PPC_TLB1CFG | 32
1956 PPC | KVM_REG_PPC_TLB2CFG | 32
1957 PPC | KVM_REG_PPC_TLB3CFG | 32
1958 PPC | KVM_REG_PPC_TLB0PS | 32
1959 PPC | KVM_REG_PPC_TLB1PS | 32
1960 PPC | KVM_REG_PPC_TLB2PS | 32
1961 PPC | KVM_REG_PPC_TLB3PS | 32
1962 PPC | KVM_REG_PPC_EPTCFG | 32
1963 PPC | KVM_REG_PPC_ICP_STATE | 64
1964 PPC | KVM_REG_PPC_TB_OFFSET | 64
1965 PPC | KVM_REG_PPC_SPMC1 | 32
1966 PPC | KVM_REG_PPC_SPMC2 | 32
1967 PPC | KVM_REG_PPC_IAMR | 64
1968 PPC | KVM_REG_PPC_TFHAR | 64
1969 PPC | KVM_REG_PPC_TFIAR | 64
1970 PPC | KVM_REG_PPC_TEXASR | 64
1971 PPC | KVM_REG_PPC_FSCR | 64
1972 PPC | KVM_REG_PPC_PSPB | 32
1973 PPC | KVM_REG_PPC_EBBHR | 64
1974 PPC | KVM_REG_PPC_EBBRR | 64
1975 PPC | KVM_REG_PPC_BESCR | 64
1976 PPC | KVM_REG_PPC_TAR | 64
1977 PPC | KVM_REG_PPC_DPDES | 64
1978 PPC | KVM_REG_PPC_DAWR | 64
1979 PPC | KVM_REG_PPC_DAWRX | 64
1980 PPC | KVM_REG_PPC_CIABR | 64
1981 PPC | KVM_REG_PPC_IC | 64
1982 PPC | KVM_REG_PPC_VTB | 64
1983 PPC | KVM_REG_PPC_CSIGR | 64
1984 PPC | KVM_REG_PPC_TACR | 64
1985 PPC | KVM_REG_PPC_TCSCR | 64
1986 PPC | KVM_REG_PPC_PID | 64
1987 PPC | KVM_REG_PPC_ACOP | 64
1988 PPC | KVM_REG_PPC_VRSAVE | 32
Paolo Bonzinicc568ea2014-08-05 09:55:22 +02001989 PPC | KVM_REG_PPC_LPCR | 32
1990 PPC | KVM_REG_PPC_LPCR_64 | 64
James Hoganbf5590f2014-07-04 15:11:34 +01001991 PPC | KVM_REG_PPC_PPR | 64
1992 PPC | KVM_REG_PPC_ARCH_COMPAT | 32
1993 PPC | KVM_REG_PPC_DABRX | 32
1994 PPC | KVM_REG_PPC_WORT | 64
Bharat Bhushanbc8a4e52014-08-13 14:40:06 +05301995 PPC | KVM_REG_PPC_SPRG9 | 64
1996 PPC | KVM_REG_PPC_DBSR | 32
Paul Mackerrase9cf1e02016-11-18 13:11:42 +11001997 PPC | KVM_REG_PPC_TIDR | 64
1998 PPC | KVM_REG_PPC_PSSCR | 64
Paul Mackerras58555642018-01-12 20:55:20 +11001999 PPC | KVM_REG_PPC_DEC_EXPIRY | 64
Paul Mackerras30323412018-10-08 16:31:13 +11002000 PPC | KVM_REG_PPC_PTCR | 64
James Hoganbf5590f2014-07-04 15:11:34 +01002001 PPC | KVM_REG_PPC_TM_GPR0 | 64
Michael Neuling3b783472013-09-03 11:13:12 +10002002 ...
James Hoganbf5590f2014-07-04 15:11:34 +01002003 PPC | KVM_REG_PPC_TM_GPR31 | 64
2004 PPC | KVM_REG_PPC_TM_VSR0 | 128
Michael Neuling3b783472013-09-03 11:13:12 +10002005 ...
James Hoganbf5590f2014-07-04 15:11:34 +01002006 PPC | KVM_REG_PPC_TM_VSR63 | 128
2007 PPC | KVM_REG_PPC_TM_CR | 64
2008 PPC | KVM_REG_PPC_TM_LR | 64
2009 PPC | KVM_REG_PPC_TM_CTR | 64
2010 PPC | KVM_REG_PPC_TM_FPSCR | 64
2011 PPC | KVM_REG_PPC_TM_AMR | 64
2012 PPC | KVM_REG_PPC_TM_PPR | 64
2013 PPC | KVM_REG_PPC_TM_VRSAVE | 64
2014 PPC | KVM_REG_PPC_TM_VSCR | 32
2015 PPC | KVM_REG_PPC_TM_DSCR | 64
2016 PPC | KVM_REG_PPC_TM_TAR | 64
Paul Mackerras0d808df2016-11-07 15:09:58 +11002017 PPC | KVM_REG_PPC_TM_XER | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002018 | |
2019 MIPS | KVM_REG_MIPS_R0 | 64
2020 ...
2021 MIPS | KVM_REG_MIPS_R31 | 64
2022 MIPS | KVM_REG_MIPS_HI | 64
2023 MIPS | KVM_REG_MIPS_LO | 64
2024 MIPS | KVM_REG_MIPS_PC | 64
2025 MIPS | KVM_REG_MIPS_CP0_INDEX | 32
James Hogan013044c2016-12-07 17:16:37 +00002026 MIPS | KVM_REG_MIPS_CP0_ENTRYLO0 | 64
2027 MIPS | KVM_REG_MIPS_CP0_ENTRYLO1 | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002028 MIPS | KVM_REG_MIPS_CP0_CONTEXT | 64
James Hogandffe0422017-03-14 10:15:34 +00002029 MIPS | KVM_REG_MIPS_CP0_CONTEXTCONFIG| 32
James Hoganc2d2c212014-07-04 15:11:35 +01002030 MIPS | KVM_REG_MIPS_CP0_USERLOCAL | 64
James Hogandffe0422017-03-14 10:15:34 +00002031 MIPS | KVM_REG_MIPS_CP0_XCONTEXTCONFIG| 64
James Hoganc2d2c212014-07-04 15:11:35 +01002032 MIPS | KVM_REG_MIPS_CP0_PAGEMASK | 32
James Hoganc992a4f2017-03-14 10:15:31 +00002033 MIPS | KVM_REG_MIPS_CP0_PAGEGRAIN | 32
James Hogan4b7de022017-03-14 10:15:35 +00002034 MIPS | KVM_REG_MIPS_CP0_SEGCTL0 | 64
2035 MIPS | KVM_REG_MIPS_CP0_SEGCTL1 | 64
2036 MIPS | KVM_REG_MIPS_CP0_SEGCTL2 | 64
James Hogan5a2f3522017-03-14 10:15:36 +00002037 MIPS | KVM_REG_MIPS_CP0_PWBASE | 64
2038 MIPS | KVM_REG_MIPS_CP0_PWFIELD | 64
2039 MIPS | KVM_REG_MIPS_CP0_PWSIZE | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002040 MIPS | KVM_REG_MIPS_CP0_WIRED | 32
James Hogan5a2f3522017-03-14 10:15:36 +00002041 MIPS | KVM_REG_MIPS_CP0_PWCTL | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002042 MIPS | KVM_REG_MIPS_CP0_HWRENA | 32
2043 MIPS | KVM_REG_MIPS_CP0_BADVADDR | 64
James Hoganedc89262017-03-14 10:15:33 +00002044 MIPS | KVM_REG_MIPS_CP0_BADINSTR | 32
2045 MIPS | KVM_REG_MIPS_CP0_BADINSTRP | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002046 MIPS | KVM_REG_MIPS_CP0_COUNT | 32
2047 MIPS | KVM_REG_MIPS_CP0_ENTRYHI | 64
2048 MIPS | KVM_REG_MIPS_CP0_COMPARE | 32
2049 MIPS | KVM_REG_MIPS_CP0_STATUS | 32
James Hoganad58d4d2015-02-02 22:55:17 +00002050 MIPS | KVM_REG_MIPS_CP0_INTCTL | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002051 MIPS | KVM_REG_MIPS_CP0_CAUSE | 32
2052 MIPS | KVM_REG_MIPS_CP0_EPC | 64
James Hogan1068eaa2014-06-26 13:56:52 +01002053 MIPS | KVM_REG_MIPS_CP0_PRID | 32
James Hogan7801bbe2016-11-14 23:59:27 +00002054 MIPS | KVM_REG_MIPS_CP0_EBASE | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002055 MIPS | KVM_REG_MIPS_CP0_CONFIG | 32
2056 MIPS | KVM_REG_MIPS_CP0_CONFIG1 | 32
2057 MIPS | KVM_REG_MIPS_CP0_CONFIG2 | 32
2058 MIPS | KVM_REG_MIPS_CP0_CONFIG3 | 32
James Hoganc7716072014-06-26 15:11:29 +01002059 MIPS | KVM_REG_MIPS_CP0_CONFIG4 | 32
2060 MIPS | KVM_REG_MIPS_CP0_CONFIG5 | 32
James Hoganc2d2c212014-07-04 15:11:35 +01002061 MIPS | KVM_REG_MIPS_CP0_CONFIG7 | 32
James Hoganc992a4f2017-03-14 10:15:31 +00002062 MIPS | KVM_REG_MIPS_CP0_XCONTEXT | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002063 MIPS | KVM_REG_MIPS_CP0_ERROREPC | 64
James Hogan05108702016-06-15 19:29:56 +01002064 MIPS | KVM_REG_MIPS_CP0_KSCRATCH1 | 64
2065 MIPS | KVM_REG_MIPS_CP0_KSCRATCH2 | 64
2066 MIPS | KVM_REG_MIPS_CP0_KSCRATCH3 | 64
2067 MIPS | KVM_REG_MIPS_CP0_KSCRATCH4 | 64
2068 MIPS | KVM_REG_MIPS_CP0_KSCRATCH5 | 64
2069 MIPS | KVM_REG_MIPS_CP0_KSCRATCH6 | 64
James Hogand42a0082017-03-14 10:15:38 +00002070 MIPS | KVM_REG_MIPS_CP0_MAAR(0..63) | 64
James Hoganc2d2c212014-07-04 15:11:35 +01002071 MIPS | KVM_REG_MIPS_COUNT_CTL | 64
2072 MIPS | KVM_REG_MIPS_COUNT_RESUME | 64
2073 MIPS | KVM_REG_MIPS_COUNT_HZ | 64
James Hogan379245c2014-12-02 15:48:24 +00002074 MIPS | KVM_REG_MIPS_FPR_32(0..31) | 32
2075 MIPS | KVM_REG_MIPS_FPR_64(0..31) | 64
James Hoganab86bd62014-12-02 15:48:24 +00002076 MIPS | KVM_REG_MIPS_VEC_128(0..31) | 128
James Hogan379245c2014-12-02 15:48:24 +00002077 MIPS | KVM_REG_MIPS_FCR_IR | 32
2078 MIPS | KVM_REG_MIPS_FCR_CSR | 32
James Hoganab86bd62014-12-02 15:48:24 +00002079 MIPS | KVM_REG_MIPS_MSA_IR | 32
2080 MIPS | KVM_REG_MIPS_MSA_CSR | 32
Jan Kiszka414fa982012-04-24 16:40:15 +02002081
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002082ARM registers are mapped using the lower 32 bits. The upper 16 of that
2083is the register group type, or coprocessor number:
2084
2085ARM core registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002086 0x4020 0000 0010 <index into the kvm_regs struct:16>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002087
Christoffer Dall11382452013-01-20 18:28:10 -05002088ARM 32-bit CP15 registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002089 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
Christoffer Dall11382452013-01-20 18:28:10 -05002090
2091ARM 64-bit CP15 registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002092 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002093
Christoffer Dallc27581e2013-01-20 18:28:10 -05002094ARM CCSIDR registers are demultiplexed by CSSELR value:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002095 0x4020 0000 0011 00 <csselr:8>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002096
Rusty Russell4fe21e42013-01-20 18:28:11 -05002097ARM 32-bit VFP control registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002098 0x4020 0000 0012 1 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002099
2100ARM 64-bit FP registers have the following id bit patterns:
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002101 0x4030 0000 0012 0 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002102
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002103ARM firmware pseudo-registers have the following bit pattern:
2104 0x4030 0000 0014 <regno:16>
2105
Marc Zyngier379e04c72013-04-02 17:46:31 +01002106
2107arm64 registers are mapped using the lower 32 bits. The upper 16 of
2108that is the register group type, or coprocessor number:
2109
2110arm64 core/FP-SIMD registers have the following id bit patterns. Note
2111that the size of the access is variable, as the kvm_regs structure
2112contains elements ranging from 32 to 128 bits. The index is a 32bit
2113value in the kvm_regs structure seen as a 32bit array.
2114 0x60x0 0000 0010 <index into the kvm_regs struct:16>
2115
Dave Martinfd3bc912018-09-28 14:39:26 +01002116Specifically:
2117 Encoding Register Bits kvm_regs member
2118----------------------------------------------------------------
2119 0x6030 0000 0010 0000 X0 64 regs.regs[0]
2120 0x6030 0000 0010 0002 X1 64 regs.regs[1]
2121 ...
2122 0x6030 0000 0010 003c X30 64 regs.regs[30]
2123 0x6030 0000 0010 003e SP 64 regs.sp
2124 0x6030 0000 0010 0040 PC 64 regs.pc
2125 0x6030 0000 0010 0042 PSTATE 64 regs.pstate
2126 0x6030 0000 0010 0044 SP_EL1 64 sp_el1
2127 0x6030 0000 0010 0046 ELR_EL1 64 elr_el1
2128 0x6030 0000 0010 0048 SPSR_EL1 64 spsr[KVM_SPSR_EL1] (alias SPSR_SVC)
2129 0x6030 0000 0010 004a SPSR_ABT 64 spsr[KVM_SPSR_ABT]
2130 0x6030 0000 0010 004c SPSR_UND 64 spsr[KVM_SPSR_UND]
2131 0x6030 0000 0010 004e SPSR_IRQ 64 spsr[KVM_SPSR_IRQ]
2132 0x6060 0000 0010 0050 SPSR_FIQ 64 spsr[KVM_SPSR_FIQ]
Dave Martin50036ad2018-09-28 14:39:27 +01002133 0x6040 0000 0010 0054 V0 128 fp_regs.vregs[0] (*)
2134 0x6040 0000 0010 0058 V1 128 fp_regs.vregs[1] (*)
Dave Martinfd3bc912018-09-28 14:39:26 +01002135 ...
Dave Martin50036ad2018-09-28 14:39:27 +01002136 0x6040 0000 0010 00d0 V31 128 fp_regs.vregs[31] (*)
Dave Martinfd3bc912018-09-28 14:39:26 +01002137 0x6020 0000 0010 00d4 FPSR 32 fp_regs.fpsr
2138 0x6020 0000 0010 00d5 FPCR 32 fp_regs.fpcr
2139
Dave Martin50036ad2018-09-28 14:39:27 +01002140(*) These encodings are not accepted for SVE-enabled vcpus. See
2141 KVM_ARM_VCPU_INIT.
2142
2143 The equivalent register content can be accessed via bits [127:0] of
2144 the corresponding SVE Zn registers instead for vcpus that have SVE
2145 enabled (see below).
2146
Marc Zyngier379e04c72013-04-02 17:46:31 +01002147arm64 CCSIDR registers are demultiplexed by CSSELR value:
2148 0x6020 0000 0011 00 <csselr:8>
2149
2150arm64 system registers have the following id bit patterns:
2151 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2152
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002153arm64 firmware pseudo-registers have the following bit pattern:
2154 0x6030 0000 0014 <regno:16>
2155
Dave Martin50036ad2018-09-28 14:39:27 +01002156arm64 SVE registers have the following bit patterns:
2157 0x6080 0000 0015 00 <n:5> <slice:5> Zn bits[2048*slice + 2047 : 2048*slice]
2158 0x6050 0000 0015 04 <n:4> <slice:5> Pn bits[256*slice + 255 : 256*slice]
2159 0x6050 0000 0015 060 <slice:5> FFR bits[256*slice + 255 : 256*slice]
2160 0x6060 0000 0015 ffff KVM_REG_ARM64_SVE_VLS pseudo-register
2161
Dave Martin43b8e1f2019-04-12 13:25:38 +01002162Access to register IDs where 2048 * slice >= 128 * max_vq will fail with
2163ENOENT. max_vq is the vcpu's maximum supported vector length in 128-bit
2164quadwords: see (**) below.
Dave Martin50036ad2018-09-28 14:39:27 +01002165
2166These registers are only accessible on vcpus for which SVE is enabled.
2167See KVM_ARM_VCPU_INIT for details.
2168
2169In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not
2170accessible until the vcpu's SVE configuration has been finalized
2171using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). See KVM_ARM_VCPU_INIT
2172and KVM_ARM_VCPU_FINALIZE for more information about this procedure.
2173
2174KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector
2175lengths supported by the vcpu to be discovered and configured by
2176userspace. When transferred to or from user memory via KVM_GET_ONE_REG
Dave Martin4bd774e2019-04-11 17:09:59 +01002177or KVM_SET_ONE_REG, the value of this register is of type
2178__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as
2179follows:
Dave Martin50036ad2018-09-28 14:39:27 +01002180
Dave Martin4bd774e2019-04-11 17:09:59 +01002181__u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS];
Dave Martin50036ad2018-09-28 14:39:27 +01002182
2183if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX &&
Dave Martin4bd774e2019-04-11 17:09:59 +01002184 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >>
2185 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1))
Dave Martin50036ad2018-09-28 14:39:27 +01002186 /* Vector length vq * 16 bytes supported */
2187else
2188 /* Vector length vq * 16 bytes not supported */
2189
2190(**) The maximum value vq for which the above condition is true is
2191max_vq. This is the maximum vector length available to the guest on
2192this vcpu, and determines which register slices are visible through
2193this ioctl interface.
2194
2195(See Documentation/arm64/sve.txt for an explanation of the "vq"
2196nomenclature.)
2197
2198KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT.
2199KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that
2200the host supports.
2201
2202Userspace may subsequently modify it if desired until the vcpu's SVE
2203configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE).
2204
2205Apart from simply removing all vector lengths from the host set that
2206exceed some value, support for arbitrarily chosen sets of vector lengths
2207is hardware-dependent and may not be available. Attempting to configure
2208an invalid set of vector lengths via KVM_SET_ONE_REG will fail with
2209EINVAL.
2210
2211After the vcpu's SVE configuration is finalized, further attempts to
2212write this register will fail with EPERM.
2213
James Hoganc2d2c212014-07-04 15:11:35 +01002214
2215MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
2216the register group type:
2217
2218MIPS core registers (see above) have the following id bit patterns:
2219 0x7030 0000 0000 <reg:16>
2220
2221MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
2222patterns depending on whether they're 32-bit or 64-bit registers:
2223 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
2224 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2225
James Hogan013044c2016-12-07 17:16:37 +00002226Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2227versions of the EntryLo registers regardless of the word size of the host
2228hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2229with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2230the PFNX field starting at bit 30.
2231
James Hogand42a0082017-03-14 10:15:38 +00002232MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
2233patterns:
2234 0x7030 0000 0001 01 <reg:8>
2235
James Hoganc2d2c212014-07-04 15:11:35 +01002236MIPS KVM control registers (see above) have the following id bit patterns:
2237 0x7030 0000 0002 <reg:16>
2238
James Hogan379245c2014-12-02 15:48:24 +00002239MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2240id bit patterns depending on the size of the register being accessed. They are
2241always accessed according to the current guest FPU mode (Status.FR and
2242Config5.FRE), i.e. as the guest would see them, and they become unpredictable
James Hoganab86bd62014-12-02 15:48:24 +00002243if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2244registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
2245overlap the FPU registers:
James Hogan379245c2014-12-02 15:48:24 +00002246 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2247 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
James Hoganab86bd62014-12-02 15:48:24 +00002248 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
James Hogan379245c2014-12-02 15:48:24 +00002249
2250MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
2251following id bit patterns:
2252 0x7020 0000 0003 01 <0:3> <reg:5>
2253
James Hoganab86bd62014-12-02 15:48:24 +00002254MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
2255following id bit patterns:
2256 0x7020 0000 0003 02 <0:3> <reg:5>
2257
James Hoganc2d2c212014-07-04 15:11:35 +01002258
Alexander Grafe24ed812011-09-14 10:02:41 +020022594.69 KVM_GET_ONE_REG
2260
2261Capability: KVM_CAP_ONE_REG
2262Architectures: all
2263Type: vcpu ioctl
2264Parameters: struct kvm_one_reg (in and out)
2265Returns: 0 on success, negative value on failure
Dave Martinfe365b42019-04-12 12:59:47 +01002266Errors include:
Dave Martin395f5622019-01-15 17:02:08 +00002267  ENOENT:   no such register
Dave Martinfe365b42019-04-12 12:59:47 +01002268  EINVAL:   invalid register ID, or no such register
2269  EPERM:    (arm64) register access not allowed before vcpu finalization
2270(These error codes are indicative only: do not rely on a specific error
2271code being returned in a specific situation.)
Alexander Grafe24ed812011-09-14 10:02:41 +02002272
2273This ioctl allows to receive the value of a single register implemented
2274in a vcpu. The register to read is indicated by the "id" field of the
2275kvm_one_reg struct passed in. On success, the register value can be found
2276at the memory location pointed to by "addr".
2277
2278The list of registers accessible using this interface is identical to the
Bharat Bhushan2e232702012-08-15 17:37:13 +00002279list in 4.68.
Alexander Grafe24ed812011-09-14 10:02:41 +02002280
Jan Kiszka414fa982012-04-24 16:40:15 +02002281
Eric B Munson1c0b28c2012-03-10 14:37:27 -050022824.70 KVM_KVMCLOCK_CTRL
2283
2284Capability: KVM_CAP_KVMCLOCK_CTRL
2285Architectures: Any that implement pvclocks (currently x86 only)
2286Type: vcpu ioctl
2287Parameters: None
2288Returns: 0 on success, -1 on error
2289
2290This signals to the host kernel that the specified guest is being paused by
2291userspace. The host will set a flag in the pvclock structure that is checked
2292from the soft lockup watchdog. The flag is part of the pvclock structure that
2293is shared between guest and host, specifically the second bit of the flags
2294field of the pvclock_vcpu_time_info structure. It will be set exclusively by
2295the host and read/cleared exclusively by the guest. The guest operation of
2296checking and clearing the flag must an atomic operation so
2297load-link/store-conditional, or equivalent must be used. There are two cases
2298where the guest will clear the flag: when the soft lockup watchdog timer resets
2299itself or when a soft lockup is detected. This ioctl can be called any time
2300after pausing the vcpu, but before it is resumed.
2301
Jan Kiszka414fa982012-04-24 16:40:15 +02002302
Jan Kiszka07975ad2012-03-29 21:14:12 +020023034.71 KVM_SIGNAL_MSI
2304
2305Capability: KVM_CAP_SIGNAL_MSI
Vladimir Murzin29885092016-11-02 11:55:34 +00002306Architectures: x86 arm arm64
Jan Kiszka07975ad2012-03-29 21:14:12 +02002307Type: vm ioctl
2308Parameters: struct kvm_msi (in)
2309Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
2310
2311Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2312MSI messages.
2313
2314struct kvm_msi {
2315 __u32 address_lo;
2316 __u32 address_hi;
2317 __u32 data;
2318 __u32 flags;
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002319 __u32 devid;
2320 __u8 pad[12];
Jan Kiszka07975ad2012-03-29 21:14:12 +02002321};
2322
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002323flags: KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM
2324 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2325 the device ID. If this capability is not available, userspace
2326 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002327
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002328If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2329for the device that wrote the MSI message. For PCI, this is usually a
2330BFD identifier in the lower 16 bits.
Jan Kiszka07975ad2012-03-29 21:14:12 +02002331
Paolo Bonzini055b6ae2016-08-04 14:01:05 +02002332On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2333feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
2334address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
2335address_hi must be zero.
Radim Krčmář371313132016-07-12 22:09:27 +02002336
Jan Kiszka414fa982012-04-24 16:40:15 +02002337
Jan Kiszka0589ff62012-04-24 16:40:16 +020023384.71 KVM_CREATE_PIT2
2339
2340Capability: KVM_CAP_PIT2
2341Architectures: x86
2342Type: vm ioctl
2343Parameters: struct kvm_pit_config (in)
2344Returns: 0 on success, -1 on error
2345
2346Creates an in-kernel device model for the i8254 PIT. This call is only valid
2347after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
2348parameters have to be passed:
2349
2350struct kvm_pit_config {
2351 __u32 flags;
2352 __u32 pad[15];
2353};
2354
2355Valid flags are:
2356
2357#define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
2358
Jan Kiszkab6ddf052012-04-24 16:40:17 +02002359PIT timer interrupts may use a per-VM kernel thread for injection. If it
2360exists, this thread will have a name of the following pattern:
2361
2362kvm-pit/<owner-process-pid>
2363
2364When running a guest with elevated priorities, the scheduling parameters of
2365this thread may have to be adjusted accordingly.
2366
Jan Kiszka0589ff62012-04-24 16:40:16 +02002367This IOCTL replaces the obsolete KVM_CREATE_PIT.
2368
2369
23704.72 KVM_GET_PIT2
2371
2372Capability: KVM_CAP_PIT_STATE2
2373Architectures: x86
2374Type: vm ioctl
2375Parameters: struct kvm_pit_state2 (out)
2376Returns: 0 on success, -1 on error
2377
2378Retrieves the state of the in-kernel PIT model. Only valid after
2379KVM_CREATE_PIT2. The state is returned in the following structure:
2380
2381struct kvm_pit_state2 {
2382 struct kvm_pit_channel_state channels[3];
2383 __u32 flags;
2384 __u32 reserved[9];
2385};
2386
2387Valid flags are:
2388
2389/* disable PIT in HPET legacy mode */
2390#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
2391
2392This IOCTL replaces the obsolete KVM_GET_PIT.
2393
2394
23954.73 KVM_SET_PIT2
2396
2397Capability: KVM_CAP_PIT_STATE2
2398Architectures: x86
2399Type: vm ioctl
2400Parameters: struct kvm_pit_state2 (in)
2401Returns: 0 on success, -1 on error
2402
2403Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
2404See KVM_GET_PIT2 for details on struct kvm_pit_state2.
2405
2406This IOCTL replaces the obsolete KVM_SET_PIT.
2407
2408
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000024094.74 KVM_PPC_GET_SMMU_INFO
2410
2411Capability: KVM_CAP_PPC_GET_SMMU_INFO
2412Architectures: powerpc
2413Type: vm ioctl
2414Parameters: None
2415Returns: 0 on success, -1 on error
2416
2417This populates and returns a structure describing the features of
2418the "Server" class MMU emulation supported by KVM.
Stefan Hubercc22c352013-06-05 12:24:37 +02002419This can in turn be used by userspace to generate the appropriate
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002420device-tree properties for the guest operating system.
2421
Carlos Garciac98be0c2014-04-04 22:31:00 -04002422The structure contains some global information, followed by an
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002423array of supported segment page sizes:
2424
2425 struct kvm_ppc_smmu_info {
2426 __u64 flags;
2427 __u32 slb_size;
2428 __u32 pad;
2429 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
2430 };
2431
2432The supported flags are:
2433
2434 - KVM_PPC_PAGE_SIZES_REAL:
2435 When that flag is set, guest page sizes must "fit" the backing
2436 store page sizes. When not set, any page size in the list can
2437 be used regardless of how they are backed by userspace.
2438
2439 - KVM_PPC_1T_SEGMENTS
2440 The emulated MMU supports 1T segments in addition to the
2441 standard 256M ones.
2442
Paul Mackerras901f8c32018-10-08 14:24:30 +11002443 - KVM_PPC_NO_HASH
2444 This flag indicates that HPT guests are not supported by KVM,
2445 thus all guests must use radix MMU mode.
2446
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002447The "slb_size" field indicates how many SLB entries are supported
2448
2449The "sps" array contains 8 entries indicating the supported base
2450page sizes for a segment in increasing order. Each entry is defined
2451as follow:
2452
2453 struct kvm_ppc_one_seg_page_size {
2454 __u32 page_shift; /* Base page shift of segment (or 0) */
2455 __u32 slb_enc; /* SLB encoding for BookS */
2456 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
2457 };
2458
2459An entry with a "page_shift" of 0 is unused. Because the array is
2460organized in increasing order, a lookup can stop when encoutering
2461such an entry.
2462
2463The "slb_enc" field provides the encoding to use in the SLB for the
2464page size. The bits are in positions such as the value can directly
2465be OR'ed into the "vsid" argument of the slbmte instruction.
2466
2467The "enc" array is a list which for each of those segment base page
2468size provides the list of supported actual page sizes (which can be
2469only larger or equal to the base page size), along with the
Anatol Pomozovf884ab12013-05-08 16:56:16 -07002470corresponding encoding in the hash PTE. Similarly, the array is
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000024718 entries sorted by increasing sizes and an entry with a "0" shift
2472is an empty entry and a terminator:
2473
2474 struct kvm_ppc_one_page_size {
2475 __u32 page_shift; /* Page shift (or 0) */
2476 __u32 pte_enc; /* Encoding in the HPTE (>>12) */
2477 };
2478
2479The "pte_enc" field provides a value that can OR'ed into the hash
2480PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
2481into the hash PTE second double word).
2482
Alex Williamsonf36992e2012-06-29 09:56:16 -060024834.75 KVM_IRQFD
2484
2485Capability: KVM_CAP_IRQFD
Eric Auger174178f2015-03-04 11:14:36 +01002486Architectures: x86 s390 arm arm64
Alex Williamsonf36992e2012-06-29 09:56:16 -06002487Type: vm ioctl
2488Parameters: struct kvm_irqfd (in)
2489Returns: 0 on success, -1 on error
2490
2491Allows setting an eventfd to directly trigger a guest interrupt.
2492kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
2493kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
Masanari Iida17180032013-12-22 01:21:23 +09002494an event is triggered on the eventfd, an interrupt is injected into
Alex Williamsonf36992e2012-06-29 09:56:16 -06002495the guest using the specified gsi pin. The irqfd is removed using
2496the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
2497and kvm_irqfd.gsi.
2498
Alex Williamson7a844282012-09-21 11:58:03 -06002499With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
2500mechanism allowing emulation of level-triggered, irqfd-based
2501interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
2502additional eventfd in the kvm_irqfd.resamplefd field. When operating
2503in resample mode, posting of an interrupt through kvm_irq.fd asserts
2504the specified gsi in the irqchip. When the irqchip is resampled, such
Masanari Iida17180032013-12-22 01:21:23 +09002505as from an EOI, the gsi is de-asserted and the user is notified via
Alex Williamson7a844282012-09-21 11:58:03 -06002506kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
2507the interrupt if the device making use of it still requires service.
2508Note that closing the resamplefd is not sufficient to disable the
2509irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
2510and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
2511
Eric Auger180ae7b2016-07-22 16:20:41 +00002512On arm/arm64, gsi routing being supported, the following can happen:
2513- in case no routing entry is associated to this gsi, injection fails
2514- in case the gsi is associated to an irqchip routing entry,
2515 irqchip.pin + 32 corresponds to the injected SPI ID.
Eric Auger995a0ee2016-07-22 16:20:42 +00002516- in case the gsi is associated to an MSI routing entry, the MSI
2517 message and device ID are translated into an LPI (support restricted
2518 to GICv3 ITS in-kernel emulation).
Eric Auger174178f2015-03-04 11:14:36 +01002519
Linus Torvalds5fecc9d2012-07-24 12:01:20 -070025204.76 KVM_PPC_ALLOCATE_HTAB
Paul Mackerras32fad282012-05-04 02:32:53 +00002521
2522Capability: KVM_CAP_PPC_ALLOC_HTAB
2523Architectures: powerpc
2524Type: vm ioctl
2525Parameters: Pointer to u32 containing hash table order (in/out)
2526Returns: 0 on success, -1 on error
2527
2528This requests the host kernel to allocate an MMU hash table for a
2529guest using the PAPR paravirtualization interface. This only does
2530anything if the kernel is configured to use the Book 3S HV style of
2531virtualization. Otherwise the capability doesn't exist and the ioctl
2532returns an ENOTTY error. The rest of this description assumes Book 3S
2533HV.
2534
2535There must be no vcpus running when this ioctl is called; if there
2536are, it will do nothing and return an EBUSY error.
2537
2538The parameter is a pointer to a 32-bit unsigned integer variable
2539containing the order (log base 2) of the desired size of the hash
2540table, which must be between 18 and 46. On successful return from the
David Gibsonf98a8bf2016-12-20 16:49:03 +11002541ioctl, the value will not be changed by the kernel.
Paul Mackerras32fad282012-05-04 02:32:53 +00002542
2543If no hash table has been allocated when any vcpu is asked to run
2544(with the KVM_RUN ioctl), the host kernel will allocate a
2545default-sized hash table (16 MB).
2546
2547If this ioctl is called when a hash table has already been allocated,
David Gibsonf98a8bf2016-12-20 16:49:03 +11002548with a different order from the existing hash table, the existing hash
2549table will be freed and a new one allocated. If this is ioctl is
2550called when a hash table has already been allocated of the same order
2551as specified, the kernel will clear out the existing hash table (zero
2552all HPTEs). In either case, if the guest is using the virtualized
2553real-mode area (VRMA) facility, the kernel will re-create the VMRA
2554HPTEs on the next KVM_RUN of any vcpu.
Paul Mackerras32fad282012-05-04 02:32:53 +00002555
Cornelia Huck416ad652012-10-02 16:25:37 +020025564.77 KVM_S390_INTERRUPT
2557
2558Capability: basic
2559Architectures: s390
2560Type: vm ioctl, vcpu ioctl
2561Parameters: struct kvm_s390_interrupt (in)
2562Returns: 0 on success, -1 on error
2563
2564Allows to inject an interrupt to the guest. Interrupts can be floating
2565(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
2566
2567Interrupt parameters are passed via kvm_s390_interrupt:
2568
2569struct kvm_s390_interrupt {
2570 __u32 type;
2571 __u32 parm;
2572 __u64 parm64;
2573};
2574
2575type can be one of the following:
2576
David Hildenbrand28225452014-10-15 16:48:16 +02002577KVM_S390_SIGP_STOP (vcpu) - sigp stop; optional flags in parm
Cornelia Huck416ad652012-10-02 16:25:37 +02002578KVM_S390_PROGRAM_INT (vcpu) - program check; code in parm
2579KVM_S390_SIGP_SET_PREFIX (vcpu) - sigp set prefix; prefix address in parm
2580KVM_S390_RESTART (vcpu) - restart
Thomas Huthe029ae52014-03-26 16:11:54 +01002581KVM_S390_INT_CLOCK_COMP (vcpu) - clock comparator interrupt
2582KVM_S390_INT_CPU_TIMER (vcpu) - CPU timer interrupt
Cornelia Huck416ad652012-10-02 16:25:37 +02002583KVM_S390_INT_VIRTIO (vm) - virtio external interrupt; external interrupt
2584 parameters in parm and parm64
2585KVM_S390_INT_SERVICE (vm) - sclp external interrupt; sclp parameter in parm
2586KVM_S390_INT_EMERGENCY (vcpu) - sigp emergency; source cpu in parm
2587KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
Cornelia Huckd8346b72012-12-20 15:32:08 +01002588KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm) - compound value to indicate an
2589 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
2590 I/O interruption parameters in parm (subchannel) and parm64 (intparm,
2591 interruption subclass)
Cornelia Huck48a3e952012-12-20 15:32:09 +01002592KVM_S390_MCHK (vm, vcpu) - machine check interrupt; cr 14 bits in parm,
2593 machine check interrupt code in parm64 (note that
2594 machine checks needing further payload are not
2595 supported by this ioctl)
Cornelia Huck416ad652012-10-02 16:25:37 +02002596
2597Note that the vcpu ioctl is asynchronous to vcpu execution.
2598
Paul Mackerrasa2932922012-11-19 22:57:20 +000025994.78 KVM_PPC_GET_HTAB_FD
2600
2601Capability: KVM_CAP_PPC_HTAB_FD
2602Architectures: powerpc
2603Type: vm ioctl
2604Parameters: Pointer to struct kvm_get_htab_fd (in)
2605Returns: file descriptor number (>= 0) on success, -1 on error
2606
2607This returns a file descriptor that can be used either to read out the
2608entries in the guest's hashed page table (HPT), or to write entries to
2609initialize the HPT. The returned fd can only be written to if the
2610KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
2611can only be read if that bit is clear. The argument struct looks like
2612this:
2613
2614/* For KVM_PPC_GET_HTAB_FD */
2615struct kvm_get_htab_fd {
2616 __u64 flags;
2617 __u64 start_index;
2618 __u64 reserved[2];
2619};
2620
2621/* Values for kvm_get_htab_fd.flags */
2622#define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
2623#define KVM_GET_HTAB_WRITE ((__u64)0x2)
2624
2625The `start_index' field gives the index in the HPT of the entry at
2626which to start reading. It is ignored when writing.
2627
2628Reads on the fd will initially supply information about all
2629"interesting" HPT entries. Interesting entries are those with the
2630bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
2631all entries. When the end of the HPT is reached, the read() will
2632return. If read() is called again on the fd, it will start again from
2633the beginning of the HPT, but will only return HPT entries that have
2634changed since they were last read.
2635
2636Data read or written is structured as a header (8 bytes) followed by a
2637series of valid HPT entries (16 bytes) each. The header indicates how
2638many valid HPT entries there are and how many invalid entries follow
2639the valid entries. The invalid entries are not represented explicitly
2640in the stream. The header format is:
2641
2642struct kvm_get_htab_header {
2643 __u32 index;
2644 __u16 n_valid;
2645 __u16 n_invalid;
2646};
2647
2648Writes to the fd create HPT entries starting at the index given in the
2649header; first `n_valid' valid entries with contents from the data
2650written, then `n_invalid' invalid entries, invalidating any previously
2651valid entries found.
2652
Scott Wood852b6d52013-04-12 14:08:42 +000026534.79 KVM_CREATE_DEVICE
2654
2655Capability: KVM_CAP_DEVICE_CTRL
2656Type: vm ioctl
2657Parameters: struct kvm_create_device (in/out)
2658Returns: 0 on success, -1 on error
2659Errors:
2660 ENODEV: The device type is unknown or unsupported
2661 EEXIST: Device already created, and this type of device may not
2662 be instantiated multiple times
2663
2664 Other error conditions may be defined by individual device types or
2665 have their standard meanings.
2666
2667Creates an emulated device in the kernel. The file descriptor returned
2668in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
2669
2670If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
2671device type is supported (not necessarily whether it can be created
2672in the current vm).
2673
2674Individual devices should not define flags. Attributes should be used
2675for specifying any behavior that is not implied by the device type
2676number.
2677
2678struct kvm_create_device {
2679 __u32 type; /* in: KVM_DEV_TYPE_xxx */
2680 __u32 fd; /* out: device handle */
2681 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
2682};
2683
26844.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
2685
Shannon Zhaof577f6c2016-01-11 20:56:17 +08002686Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
2687 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
2688Type: device ioctl, vm ioctl, vcpu ioctl
Scott Wood852b6d52013-04-12 14:08:42 +00002689Parameters: struct kvm_device_attr
2690Returns: 0 on success, -1 on error
2691Errors:
2692 ENXIO: The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01002693 or hardware support is missing.
Scott Wood852b6d52013-04-12 14:08:42 +00002694 EPERM: The attribute cannot (currently) be accessed this way
2695 (e.g. read-only attribute, or attribute that only makes
2696 sense when the device is in a different state)
2697
2698 Other error conditions may be defined by individual device types.
2699
2700Gets/sets a specified piece of device configuration and/or state. The
2701semantics are device-specific. See individual device documentation in
2702the "devices" directory. As with ONE_REG, the size of the data
2703transferred is defined by the particular attribute.
2704
2705struct kvm_device_attr {
2706 __u32 flags; /* no flags currently defined */
2707 __u32 group; /* device-defined */
2708 __u64 attr; /* group-defined */
2709 __u64 addr; /* userspace address of attr data */
2710};
2711
27124.81 KVM_HAS_DEVICE_ATTR
2713
Shannon Zhaof577f6c2016-01-11 20:56:17 +08002714Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
2715 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
2716Type: device ioctl, vm ioctl, vcpu ioctl
Scott Wood852b6d52013-04-12 14:08:42 +00002717Parameters: struct kvm_device_attr
2718Returns: 0 on success, -1 on error
2719Errors:
2720 ENXIO: The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01002721 or hardware support is missing.
Scott Wood852b6d52013-04-12 14:08:42 +00002722
2723Tests whether a device supports a particular attribute. A successful
2724return indicates the attribute is implemented. It does not necessarily
2725indicate that the attribute can be read or written in the device's
2726current state. "addr" is ignored.
Alex Williamsonf36992e2012-06-29 09:56:16 -06002727
Alexey Kardashevskiyd8968f12013-06-19 11:42:07 +100027284.82 KVM_ARM_VCPU_INIT
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002729
2730Capability: basic
Marc Zyngier379e04c72013-04-02 17:46:31 +01002731Architectures: arm, arm64
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002732Type: vcpu ioctl
Anup Patelbeb11fc2013-12-12 21:42:24 +05302733Parameters: struct kvm_vcpu_init (in)
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002734Returns: 0 on success; -1 on error
2735Errors:
2736  EINVAL:    the target is unknown, or the combination of features is invalid.
2737  ENOENT:    a features bit specified is unknown.
2738
2739This tells KVM what type of CPU to present to the guest, and what
2740optional features it should have.  This will cause a reset of the cpu
2741registers to their initial values.  If this is not called, KVM_RUN will
2742return ENOEXEC for that vcpu.
2743
2744Note that because some registers reflect machine topology, all vcpus
2745should be created before this ioctl is invoked.
2746
Christoffer Dallf7fa034d2014-10-16 16:40:53 +02002747Userspace can call this function multiple times for a given vcpu, including
2748after the vcpu has been run. This will reset the vcpu to its initial
2749state. All calls to this function after the initial call must use the same
2750target and same set of feature flags, otherwise EINVAL will be returned.
2751
Marc Zyngieraa024c22013-01-20 18:28:13 -05002752Possible features:
2753 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
Christoffer Dall3ad8b3d2014-10-16 16:14:43 +02002754 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
2755 and execute guest code when KVM_RUN is called.
Marc Zyngier379e04c72013-04-02 17:46:31 +01002756 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
2757 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002758 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
2759 backward compatible with v0.2) for the CPU.
Anup Patel50bb0c92014-04-29 11:24:17 +05302760 Depends on KVM_CAP_ARM_PSCI_0_2.
Shannon Zhao808e7382016-01-11 22:46:15 +08002761 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
2762 Depends on KVM_CAP_ARM_PMU_V3.
Marc Zyngieraa024c22013-01-20 18:28:13 -05002763
Amit Daniel Kachhapa22fa322019-04-23 10:12:36 +05302764 - KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication
2765 for arm64 only.
2766 Both KVM_ARM_VCPU_PTRAUTH_ADDRESS and KVM_ARM_VCPU_PTRAUTH_GENERIC
2767 must be requested or neither must be requested.
2768
2769 - KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication
2770 for arm64 only.
2771 Both KVM_ARM_VCPU_PTRAUTH_ADDRESS and KVM_ARM_VCPU_PTRAUTH_GENERIC
2772 must be requested or neither must be requested.
2773
Dave Martin50036ad2018-09-28 14:39:27 +01002774 - KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only).
2775 Depends on KVM_CAP_ARM_SVE.
2776 Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
2777
2778 * After KVM_ARM_VCPU_INIT:
2779
2780 - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the
2781 initial value of this pseudo-register indicates the best set of
2782 vector lengths possible for a vcpu on this host.
2783
2784 * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
2785
2786 - KVM_RUN and KVM_GET_REG_LIST are not available;
2787
2788 - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access
2789 the scalable archietctural SVE registers
2790 KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or
2791 KVM_REG_ARM64_SVE_FFR;
2792
2793 - KVM_REG_ARM64_SVE_VLS may optionally be written using
2794 KVM_SET_ONE_REG, to modify the set of vector lengths available
2795 for the vcpu.
2796
2797 * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
2798
2799 - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can
2800 no longer be written using KVM_SET_ONE_REG.
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002801
Anup Patel740edfc2013-09-30 14:20:08 +053028024.83 KVM_ARM_PREFERRED_TARGET
2803
2804Capability: basic
2805Architectures: arm, arm64
2806Type: vm ioctl
2807Parameters: struct struct kvm_vcpu_init (out)
2808Returns: 0 on success; -1 on error
2809Errors:
Christoffer Dalla7265fb2013-10-15 17:43:00 -07002810 ENODEV: no preferred target available for the host
Anup Patel740edfc2013-09-30 14:20:08 +05302811
2812This queries KVM for preferred CPU target type which can be emulated
2813by KVM on underlying host.
2814
2815The ioctl returns struct kvm_vcpu_init instance containing information
2816about preferred CPU target type and recommended features for it. The
2817kvm_vcpu_init->features bitmap returned will have feature bits set if
2818the preferred target recommends setting these features, but this is
2819not mandatory.
2820
2821The information returned by this ioctl can be used to prepare an instance
2822of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
2823in VCPU matching underlying host.
2824
2825
28264.84 KVM_GET_REG_LIST
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002827
2828Capability: basic
James Hoganc2d2c212014-07-04 15:11:35 +01002829Architectures: arm, arm64, mips
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002830Type: vcpu ioctl
2831Parameters: struct kvm_reg_list (in/out)
2832Returns: 0 on success; -1 on error
2833Errors:
2834  E2BIG:     the reg index list is too big to fit in the array specified by
2835             the user (the number required will be written into n).
2836
2837struct kvm_reg_list {
2838 __u64 n; /* number of registers in reg[] */
2839 __u64 reg[0];
2840};
2841
2842This ioctl returns the guest registers that are supported for the
2843KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
2844
Christoffer Dallce01e4e2013-09-23 14:55:56 -07002845
28464.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
Christoffer Dall3401d5462013-01-23 13:18:04 -05002847
2848Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
Marc Zyngier379e04c72013-04-02 17:46:31 +01002849Architectures: arm, arm64
Christoffer Dall3401d5462013-01-23 13:18:04 -05002850Type: vm ioctl
2851Parameters: struct kvm_arm_device_address (in)
2852Returns: 0 on success, -1 on error
2853Errors:
2854 ENODEV: The device id is unknown
2855 ENXIO: Device not supported on current system
2856 EEXIST: Address already set
2857 E2BIG: Address outside guest physical address space
Christoffer Dall330690c2013-01-21 19:36:13 -05002858 EBUSY: Address overlaps with other device range
Christoffer Dall3401d5462013-01-23 13:18:04 -05002859
2860struct kvm_arm_device_addr {
2861 __u64 id;
2862 __u64 addr;
2863};
2864
2865Specify a device address in the guest's physical address space where guests
2866can access emulated or directly exposed devices, which the host kernel needs
2867to know about. The id field is an architecture specific identifier for a
2868specific device.
2869
Marc Zyngier379e04c72013-04-02 17:46:31 +01002870ARM/arm64 divides the id field into two parts, a device id and an
2871address type id specific to the individual device.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002872
2873  bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
2874 field: | 0x00000000 | device id | addr type id |
2875
Marc Zyngier379e04c72013-04-02 17:46:31 +01002876ARM/arm64 currently only require this when using the in-kernel GIC
2877support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
2878as the device id. When setting the base address for the guest's
2879mapping of the VGIC virtual CPU and distributor interface, the ioctl
2880must be called after calling KVM_CREATE_IRQCHIP, but before calling
2881KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
2882base addresses will return -EEXIST.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002883
Christoffer Dallce01e4e2013-09-23 14:55:56 -07002884Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
2885should be used instead.
2886
2887
Anup Patel740edfc2013-09-30 14:20:08 +053028884.86 KVM_PPC_RTAS_DEFINE_TOKEN
Michael Ellerman8e591cb2013-04-17 20:30:00 +00002889
2890Capability: KVM_CAP_PPC_RTAS
2891Architectures: ppc
2892Type: vm ioctl
2893Parameters: struct kvm_rtas_token_args
2894Returns: 0 on success, -1 on error
2895
2896Defines a token value for a RTAS (Run Time Abstraction Services)
2897service in order to allow it to be handled in the kernel. The
2898argument struct gives the name of the service, which must be the name
2899of a service that has a kernel-side implementation. If the token
2900value is non-zero, it will be associated with that service, and
2901subsequent RTAS calls by the guest specifying that token will be
2902handled by the kernel. If the token value is 0, then any token
2903associated with the service will be forgotten, and subsequent RTAS
2904calls by the guest for that service will be passed to userspace to be
2905handled.
2906
Alex Bennée4bd9d342014-09-09 17:27:18 +010029074.87 KVM_SET_GUEST_DEBUG
2908
2909Capability: KVM_CAP_SET_GUEST_DEBUG
Alex Bennée0e6f07f2015-07-07 17:29:55 +01002910Architectures: x86, s390, ppc, arm64
Alex Bennée4bd9d342014-09-09 17:27:18 +01002911Type: vcpu ioctl
2912Parameters: struct kvm_guest_debug (in)
2913Returns: 0 on success; -1 on error
2914
2915struct kvm_guest_debug {
2916 __u32 control;
2917 __u32 pad;
2918 struct kvm_guest_debug_arch arch;
2919};
2920
2921Set up the processor specific debug registers and configure vcpu for
2922handling guest debug events. There are two parts to the structure, the
2923first a control bitfield indicates the type of debug events to handle
2924when running. Common control bits are:
2925
2926 - KVM_GUESTDBG_ENABLE: guest debugging is enabled
2927 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
2928
2929The top 16 bits of the control field are architecture specific control
2930flags which can include the following:
2931
Alex Bennée4bd611c2015-07-07 17:29:57 +01002932 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
Alex Bennée834bf882015-07-07 17:30:02 +01002933 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390, arm64]
Alex Bennée4bd9d342014-09-09 17:27:18 +01002934 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
2935 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
2936 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
2937
2938For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
2939are enabled in memory so we need to ensure breakpoint exceptions are
2940correctly trapped and the KVM run loop exits at the breakpoint and not
2941running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
2942we need to ensure the guest vCPUs architecture specific registers are
2943updated to the correct (supplied) values.
2944
2945The second part of the structure is architecture specific and
2946typically contains a set of debug registers.
2947
Alex Bennée834bf882015-07-07 17:30:02 +01002948For arm64 the number of debug registers is implementation defined and
2949can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
2950KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
2951indicating the number of supported registers.
2952
Alex Bennée4bd9d342014-09-09 17:27:18 +01002953When debug events exit the main run loop with the reason
2954KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
2955structure containing architecture specific debug information.
Christoffer Dall3401d5462013-01-23 13:18:04 -05002956
Alex Bennée209cf192014-09-09 17:27:19 +010029574.88 KVM_GET_EMULATED_CPUID
2958
2959Capability: KVM_CAP_EXT_EMUL_CPUID
2960Architectures: x86
2961Type: system ioctl
2962Parameters: struct kvm_cpuid2 (in/out)
2963Returns: 0 on success, -1 on error
2964
2965struct kvm_cpuid2 {
2966 __u32 nent;
2967 __u32 flags;
2968 struct kvm_cpuid_entry2 entries[0];
2969};
2970
2971The member 'flags' is used for passing flags from userspace.
2972
2973#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
2974#define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1)
2975#define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2)
2976
2977struct kvm_cpuid_entry2 {
2978 __u32 function;
2979 __u32 index;
2980 __u32 flags;
2981 __u32 eax;
2982 __u32 ebx;
2983 __u32 ecx;
2984 __u32 edx;
2985 __u32 padding[3];
2986};
2987
2988This ioctl returns x86 cpuid features which are emulated by
2989kvm.Userspace can use the information returned by this ioctl to query
2990which features are emulated by kvm instead of being present natively.
2991
2992Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
2993structure with the 'nent' field indicating the number of entries in
2994the variable-size array 'entries'. If the number of entries is too low
2995to describe the cpu capabilities, an error (E2BIG) is returned. If the
2996number is too high, the 'nent' field is adjusted and an error (ENOMEM)
2997is returned. If the number is just right, the 'nent' field is adjusted
2998to the number of valid entries in the 'entries' array, which is then
2999filled.
3000
3001The entries returned are the set CPUID bits of the respective features
3002which kvm emulates, as returned by the CPUID instruction, with unknown
3003or unsupported feature bits cleared.
3004
3005Features like x2apic, for example, may not be present in the host cpu
3006but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
3007emulated efficiently and thus not included here.
3008
3009The fields in each entry are defined as follows:
3010
3011 function: the eax value used to obtain the entry
3012 index: the ecx value used to obtain the entry (for entries that are
3013 affected by ecx)
3014 flags: an OR of zero or more of the following:
3015 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
3016 if the index field is valid
3017 KVM_CPUID_FLAG_STATEFUL_FUNC:
3018 if cpuid for this function returns different values for successive
3019 invocations; there will be several entries with the same function,
3020 all with this flag set
3021 KVM_CPUID_FLAG_STATE_READ_NEXT:
3022 for KVM_CPUID_FLAG_STATEFUL_FUNC entries, set if this entry is
3023 the first entry to be read by a cpu
3024 eax, ebx, ecx, edx: the values returned by the cpuid instruction for
3025 this function/index combination
3026
Thomas Huth41408c282015-02-06 15:01:21 +010030274.89 KVM_S390_MEM_OP
3028
3029Capability: KVM_CAP_S390_MEM_OP
3030Architectures: s390
3031Type: vcpu ioctl
3032Parameters: struct kvm_s390_mem_op (in)
3033Returns: = 0 on success,
3034 < 0 on generic error (e.g. -EFAULT or -ENOMEM),
3035 > 0 if an exception occurred while walking the page tables
3036
Masanari Iida5d4f6f32015-10-04 00:46:21 +09003037Read or write data from/to the logical (virtual) memory of a VCPU.
Thomas Huth41408c282015-02-06 15:01:21 +01003038
3039Parameters are specified via the following structure:
3040
3041struct kvm_s390_mem_op {
3042 __u64 gaddr; /* the guest address */
3043 __u64 flags; /* flags */
3044 __u32 size; /* amount of bytes */
3045 __u32 op; /* type of operation */
3046 __u64 buf; /* buffer in userspace */
3047 __u8 ar; /* the access register number */
3048 __u8 reserved[31]; /* should be set to 0 */
3049};
3050
3051The type of operation is specified in the "op" field. It is either
3052KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or
3053KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The
3054KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check
3055whether the corresponding memory access would create an access exception
3056(without touching the data in the memory at the destination). In case an
3057access exception occurred while walking the MMU tables of the guest, the
3058ioctl returns a positive error number to indicate the type of exception.
3059This exception is also raised directly at the corresponding VCPU if the
3060flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field.
3061
3062The start address of the memory region has to be specified in the "gaddr"
3063field, and the length of the region in the "size" field. "buf" is the buffer
3064supplied by the userspace application where the read data should be written
3065to for KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written
3066is stored for a KVM_S390_MEMOP_LOGICAL_WRITE. "buf" is unused and can be NULL
3067when KVM_S390_MEMOP_F_CHECK_ONLY is specified. "ar" designates the access
3068register number to be used.
3069
3070The "reserved" field is meant for future extensions. It is not used by
3071KVM with the currently defined set of flags.
3072
Jason J. Herne30ee2a92014-09-23 09:23:01 -040030734.90 KVM_S390_GET_SKEYS
3074
3075Capability: KVM_CAP_S390_SKEYS
3076Architectures: s390
3077Type: vm ioctl
3078Parameters: struct kvm_s390_skeys
3079Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
3080 keys, negative value on error
3081
3082This ioctl is used to get guest storage key values on the s390
3083architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
3084
3085struct kvm_s390_skeys {
3086 __u64 start_gfn;
3087 __u64 count;
3088 __u64 skeydata_addr;
3089 __u32 flags;
3090 __u32 reserved[9];
3091};
3092
3093The start_gfn field is the number of the first guest frame whose storage keys
3094you want to get.
3095
3096The count field is the number of consecutive frames (starting from start_gfn)
3097whose storage keys to get. The count field must be at least 1 and the maximum
3098allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
3099will cause the ioctl to return -EINVAL.
3100
3101The skeydata_addr field is the address to a buffer large enough to hold count
3102bytes. This buffer will be filled with storage key data by the ioctl.
3103
31044.91 KVM_S390_SET_SKEYS
3105
3106Capability: KVM_CAP_S390_SKEYS
3107Architectures: s390
3108Type: vm ioctl
3109Parameters: struct kvm_s390_skeys
3110Returns: 0 on success, negative value on error
3111
3112This ioctl is used to set guest storage key values on the s390
3113architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
3114See section on KVM_S390_GET_SKEYS for struct definition.
3115
3116The start_gfn field is the number of the first guest frame whose storage keys
3117you want to set.
3118
3119The count field is the number of consecutive frames (starting from start_gfn)
3120whose storage keys to get. The count field must be at least 1 and the maximum
3121allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
3122will cause the ioctl to return -EINVAL.
3123
3124The skeydata_addr field is the address to a buffer containing count bytes of
3125storage keys. Each byte in the buffer will be set as the storage key for a
3126single frame starting at start_gfn for count frames.
3127
3128Note: If any architecturally invalid key value is found in the given data then
3129the ioctl will return -EINVAL.
3130
Jens Freimann47b43c52014-11-11 20:57:06 +010031314.92 KVM_S390_IRQ
3132
3133Capability: KVM_CAP_S390_INJECT_IRQ
3134Architectures: s390
3135Type: vcpu ioctl
3136Parameters: struct kvm_s390_irq (in)
3137Returns: 0 on success, -1 on error
3138Errors:
3139 EINVAL: interrupt type is invalid
3140 type is KVM_S390_SIGP_STOP and flag parameter is invalid value
3141 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
3142 than the maximum of VCPUs
3143 EBUSY: type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped
3144 type is KVM_S390_SIGP_STOP and a stop irq is already pending
3145 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
3146 is already pending
3147
3148Allows to inject an interrupt to the guest.
3149
3150Using struct kvm_s390_irq as a parameter allows
3151to inject additional payload which is not
3152possible via KVM_S390_INTERRUPT.
3153
3154Interrupt parameters are passed via kvm_s390_irq:
3155
3156struct kvm_s390_irq {
3157 __u64 type;
3158 union {
3159 struct kvm_s390_io_info io;
3160 struct kvm_s390_ext_info ext;
3161 struct kvm_s390_pgm_info pgm;
3162 struct kvm_s390_emerg_info emerg;
3163 struct kvm_s390_extcall_info extcall;
3164 struct kvm_s390_prefix_info prefix;
3165 struct kvm_s390_stop_info stop;
3166 struct kvm_s390_mchk_info mchk;
3167 char reserved[64];
3168 } u;
3169};
3170
3171type can be one of the following:
3172
3173KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
3174KVM_S390_PROGRAM_INT - program check; parameters in .pgm
3175KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
3176KVM_S390_RESTART - restart; no parameters
3177KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
3178KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
3179KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
3180KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
3181KVM_S390_MCHK - machine check interrupt; parameters in .mchk
3182
3183
3184Note that the vcpu ioctl is asynchronous to vcpu execution.
3185
Jens Freimann816c7662014-11-24 17:13:46 +010031864.94 KVM_S390_GET_IRQ_STATE
3187
3188Capability: KVM_CAP_S390_IRQ_STATE
3189Architectures: s390
3190Type: vcpu ioctl
3191Parameters: struct kvm_s390_irq_state (out)
3192Returns: >= number of bytes copied into buffer,
3193 -EINVAL if buffer size is 0,
3194 -ENOBUFS if buffer size is too small to fit all pending interrupts,
3195 -EFAULT if the buffer address was invalid
3196
3197This ioctl allows userspace to retrieve the complete state of all currently
3198pending interrupts in a single buffer. Use cases include migration
3199and introspection. The parameter structure contains the address of a
3200userspace buffer and its length:
3201
3202struct kvm_s390_irq_state {
3203 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003204 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003205 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003206 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003207};
3208
3209Userspace passes in the above struct and for each pending interrupt a
3210struct kvm_s390_irq is copied to the provided buffer.
3211
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003212The structure contains a flags and a reserved field for future extensions. As
3213the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
3214reserved, these fields can not be used in the future without breaking
3215compatibility.
3216
Jens Freimann816c7662014-11-24 17:13:46 +01003217If -ENOBUFS is returned the buffer provided was too small and userspace
3218may retry with a bigger buffer.
3219
32204.95 KVM_S390_SET_IRQ_STATE
3221
3222Capability: KVM_CAP_S390_IRQ_STATE
3223Architectures: s390
3224Type: vcpu ioctl
3225Parameters: struct kvm_s390_irq_state (in)
3226Returns: 0 on success,
3227 -EFAULT if the buffer address was invalid,
3228 -EINVAL for an invalid buffer length (see below),
3229 -EBUSY if there were already interrupts pending,
3230 errors occurring when actually injecting the
3231 interrupt. See KVM_S390_IRQ.
3232
3233This ioctl allows userspace to set the complete state of all cpu-local
3234interrupts currently pending for the vcpu. It is intended for restoring
3235interrupt state after a migration. The input parameter is a userspace buffer
3236containing a struct kvm_s390_irq_state:
3237
3238struct kvm_s390_irq_state {
3239 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003240 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003241 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003242 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003243};
3244
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003245The restrictions for flags and reserved apply as well.
3246(see KVM_S390_GET_IRQ_STATE)
3247
Jens Freimann816c7662014-11-24 17:13:46 +01003248The userspace memory referenced by buf contains a struct kvm_s390_irq
3249for each interrupt to be injected into the guest.
3250If one of the interrupts could not be injected for some reason the
3251ioctl aborts.
3252
3253len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
3254and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
3255which is the maximum number of possibly pending cpu-local interrupts.
Jens Freimann47b43c52014-11-11 20:57:06 +01003256
Alexey Kardashevskiyed8e5a22016-01-19 16:12:28 +110032574.96 KVM_SMI
Paolo Bonzinif0778252015-04-01 15:06:40 +02003258
3259Capability: KVM_CAP_X86_SMM
3260Architectures: x86
3261Type: vcpu ioctl
3262Parameters: none
3263Returns: 0 on success, -1 on error
3264
3265Queues an SMI on the thread's vcpu.
3266
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +110032674.97 KVM_CAP_PPC_MULTITCE
3268
3269Capability: KVM_CAP_PPC_MULTITCE
3270Architectures: ppc
3271Type: vm
3272
3273This capability means the kernel is capable of handling hypercalls
3274H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
3275space. This significantly accelerates DMA operations for PPC KVM guests.
3276User space should expect that its handlers for these hypercalls
3277are not going to be called if user space previously registered LIOBN
3278in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
3279
3280In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
3281user space might have to advertise it for the guest. For example,
3282IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
3283present in the "ibm,hypertas-functions" device-tree property.
3284
3285The hypercalls mentioned above may or may not be processed successfully
3286in the kernel based fast path. If they can not be handled by the kernel,
3287they will get passed on to user space. So user space still has to have
3288an implementation for these despite the in kernel acceleration.
3289
3290This capability is always enabled.
3291
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +110032924.98 KVM_CREATE_SPAPR_TCE_64
3293
3294Capability: KVM_CAP_SPAPR_TCE_64
3295Architectures: powerpc
3296Type: vm ioctl
3297Parameters: struct kvm_create_spapr_tce_64 (in)
3298Returns: file descriptor for manipulating the created TCE table
3299
3300This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
3301windows, described in 4.62 KVM_CREATE_SPAPR_TCE
3302
3303This capability uses extended struct in ioctl interface:
3304
3305/* for KVM_CAP_SPAPR_TCE_64 */
3306struct kvm_create_spapr_tce_64 {
3307 __u64 liobn;
3308 __u32 page_shift;
3309 __u32 flags;
3310 __u64 offset; /* in pages */
3311 __u64 size; /* in pages */
3312};
3313
3314The aim of extension is to support an additional bigger DMA window with
3315a variable page size.
3316KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
3317a bus offset of the corresponding DMA window, @size and @offset are numbers
3318of IOMMU pages.
3319
3320@flags are not used at the moment.
3321
3322The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
3323
David Gibsonccc4df42016-12-20 16:48:57 +110033244.99 KVM_REINJECT_CONTROL
Radim Krčmář107d44a22016-03-02 22:56:53 +01003325
3326Capability: KVM_CAP_REINJECT_CONTROL
3327Architectures: x86
3328Type: vm ioctl
3329Parameters: struct kvm_reinject_control (in)
3330Returns: 0 on success,
3331 -EFAULT if struct kvm_reinject_control cannot be read,
3332 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
3333
3334i8254 (PIT) has two modes, reinject and !reinject. The default is reinject,
3335where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
3336vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its
3337interrupt whenever there isn't a pending interrupt from i8254.
3338!reinject mode injects an interrupt as soon as a tick arrives.
3339
3340struct kvm_reinject_control {
3341 __u8 pit_reinject;
3342 __u8 reserved[31];
3343};
3344
3345pit_reinject = 0 (!reinject mode) is recommended, unless running an old
3346operating system that uses the PIT for timing (e.g. Linux 2.4.x).
3347
David Gibsonccc4df42016-12-20 16:48:57 +110033484.100 KVM_PPC_CONFIGURE_V3_MMU
Paul Mackerrasc9270132017-01-30 21:21:41 +11003349
3350Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
3351Architectures: ppc
3352Type: vm ioctl
3353Parameters: struct kvm_ppc_mmuv3_cfg (in)
3354Returns: 0 on success,
3355 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
3356 -EINVAL if the configuration is invalid
3357
3358This ioctl controls whether the guest will use radix or HPT (hashed
3359page table) translation, and sets the pointer to the process table for
3360the guest.
3361
3362struct kvm_ppc_mmuv3_cfg {
3363 __u64 flags;
3364 __u64 process_table;
3365};
3366
3367There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
3368KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest
3369to use radix tree translation, and if clear, to use HPT translation.
3370KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
3371to be able to use the global TLB and SLB invalidation instructions;
3372if clear, the guest may not use these instructions.
3373
3374The process_table field specifies the address and size of the guest
3375process table, which is in the guest's space. This field is formatted
3376as the second doubleword of the partition table entry, as defined in
3377the Power ISA V3.00, Book III section 5.7.6.1.
3378
David Gibsonccc4df42016-12-20 16:48:57 +110033794.101 KVM_PPC_GET_RMMU_INFO
Paul Mackerrasc9270132017-01-30 21:21:41 +11003380
3381Capability: KVM_CAP_PPC_RADIX_MMU
3382Architectures: ppc
3383Type: vm ioctl
3384Parameters: struct kvm_ppc_rmmu_info (out)
3385Returns: 0 on success,
3386 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
3387 -EINVAL if no useful information can be returned
3388
3389This ioctl returns a structure containing two things: (a) a list
3390containing supported radix tree geometries, and (b) a list that maps
3391page sizes to put in the "AP" (actual page size) field for the tlbie
3392(TLB invalidate entry) instruction.
3393
3394struct kvm_ppc_rmmu_info {
3395 struct kvm_ppc_radix_geom {
3396 __u8 page_shift;
3397 __u8 level_bits[4];
3398 __u8 pad[3];
3399 } geometries[8];
3400 __u32 ap_encodings[8];
3401};
3402
3403The geometries[] field gives up to 8 supported geometries for the
3404radix page table, in terms of the log base 2 of the smallest page
3405size, and the number of bits indexed at each level of the tree, from
3406the PTE level up to the PGD level in that order. Any unused entries
3407will have 0 in the page_shift field.
3408
3409The ap_encodings gives the supported page sizes and their AP field
3410encodings, encoded with the AP value in the top 3 bits and the log
3411base 2 of the page size in the bottom 6 bits.
3412
David Gibsonef1ead02016-12-20 16:48:58 +110034134.102 KVM_PPC_RESIZE_HPT_PREPARE
3414
3415Capability: KVM_CAP_SPAPR_RESIZE_HPT
3416Architectures: powerpc
3417Type: vm ioctl
3418Parameters: struct kvm_ppc_resize_hpt (in)
3419Returns: 0 on successful completion,
3420 >0 if a new HPT is being prepared, the value is an estimated
3421 number of milliseconds until preparation is complete
3422 -EFAULT if struct kvm_reinject_control cannot be read,
3423 -EINVAL if the supplied shift or flags are invalid
3424 -ENOMEM if unable to allocate the new HPT
3425 -ENOSPC if there was a hash collision when moving existing
3426 HPT entries to the new HPT
3427 -EIO on other error conditions
3428
3429Used to implement the PAPR extension for runtime resizing of a guest's
3430Hashed Page Table (HPT). Specifically this starts, stops or monitors
3431the preparation of a new potential HPT for the guest, essentially
3432implementing the H_RESIZE_HPT_PREPARE hypercall.
3433
3434If called with shift > 0 when there is no pending HPT for the guest,
3435this begins preparation of a new pending HPT of size 2^(shift) bytes.
3436It then returns a positive integer with the estimated number of
3437milliseconds until preparation is complete.
3438
3439If called when there is a pending HPT whose size does not match that
3440requested in the parameters, discards the existing pending HPT and
3441creates a new one as above.
3442
3443If called when there is a pending HPT of the size requested, will:
3444 * If preparation of the pending HPT is already complete, return 0
3445 * If preparation of the pending HPT has failed, return an error
3446 code, then discard the pending HPT.
3447 * If preparation of the pending HPT is still in progress, return an
3448 estimated number of milliseconds until preparation is complete.
3449
3450If called with shift == 0, discards any currently pending HPT and
3451returns 0 (i.e. cancels any in-progress preparation).
3452
3453flags is reserved for future expansion, currently setting any bits in
3454flags will result in an -EINVAL.
3455
3456Normally this will be called repeatedly with the same parameters until
3457it returns <= 0. The first call will initiate preparation, subsequent
3458ones will monitor preparation until it completes or fails.
3459
3460struct kvm_ppc_resize_hpt {
3461 __u64 flags;
3462 __u32 shift;
3463 __u32 pad;
3464};
3465
34664.103 KVM_PPC_RESIZE_HPT_COMMIT
3467
3468Capability: KVM_CAP_SPAPR_RESIZE_HPT
3469Architectures: powerpc
3470Type: vm ioctl
3471Parameters: struct kvm_ppc_resize_hpt (in)
3472Returns: 0 on successful completion,
3473 -EFAULT if struct kvm_reinject_control cannot be read,
3474 -EINVAL if the supplied shift or flags are invalid
3475 -ENXIO is there is no pending HPT, or the pending HPT doesn't
3476 have the requested size
3477 -EBUSY if the pending HPT is not fully prepared
3478 -ENOSPC if there was a hash collision when moving existing
3479 HPT entries to the new HPT
3480 -EIO on other error conditions
3481
3482Used to implement the PAPR extension for runtime resizing of a guest's
3483Hashed Page Table (HPT). Specifically this requests that the guest be
3484transferred to working with the new HPT, essentially implementing the
3485H_RESIZE_HPT_COMMIT hypercall.
3486
3487This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
3488returned 0 with the same parameters. In other cases
3489KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
3490-EBUSY, though others may be possible if the preparation was started,
3491but failed).
3492
3493This will have undefined effects on the guest if it has not already
3494placed itself in a quiescent state where no vcpu will make MMU enabled
3495memory accesses.
3496
3497On succsful completion, the pending HPT will become the guest's active
3498HPT and the previous HPT will be discarded.
3499
3500On failure, the guest will still be operating on its previous HPT.
3501
3502struct kvm_ppc_resize_hpt {
3503 __u64 flags;
3504 __u32 shift;
3505 __u32 pad;
3506};
3507
Luiz Capitulino3aa53852017-03-13 09:08:20 -040035084.104 KVM_X86_GET_MCE_CAP_SUPPORTED
3509
3510Capability: KVM_CAP_MCE
3511Architectures: x86
3512Type: system ioctl
3513Parameters: u64 mce_cap (out)
3514Returns: 0 on success, -1 on error
3515
3516Returns supported MCE capabilities. The u64 mce_cap parameter
3517has the same format as the MSR_IA32_MCG_CAP register. Supported
3518capabilities will have the corresponding bits set.
3519
35204.105 KVM_X86_SETUP_MCE
3521
3522Capability: KVM_CAP_MCE
3523Architectures: x86
3524Type: vcpu ioctl
3525Parameters: u64 mcg_cap (in)
3526Returns: 0 on success,
3527 -EFAULT if u64 mcg_cap cannot be read,
3528 -EINVAL if the requested number of banks is invalid,
3529 -EINVAL if requested MCE capability is not supported.
3530
3531Initializes MCE support for use. The u64 mcg_cap parameter
3532has the same format as the MSR_IA32_MCG_CAP register and
3533specifies which capabilities should be enabled. The maximum
3534supported number of error-reporting banks can be retrieved when
3535checking for KVM_CAP_MCE. The supported capabilities can be
3536retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
3537
35384.106 KVM_X86_SET_MCE
3539
3540Capability: KVM_CAP_MCE
3541Architectures: x86
3542Type: vcpu ioctl
3543Parameters: struct kvm_x86_mce (in)
3544Returns: 0 on success,
3545 -EFAULT if struct kvm_x86_mce cannot be read,
3546 -EINVAL if the bank number is invalid,
3547 -EINVAL if VAL bit is not set in status field.
3548
3549Inject a machine check error (MCE) into the guest. The input
3550parameter is:
3551
3552struct kvm_x86_mce {
3553 __u64 status;
3554 __u64 addr;
3555 __u64 misc;
3556 __u64 mcg_status;
3557 __u8 bank;
3558 __u8 pad1[7];
3559 __u64 pad2[3];
3560};
3561
3562If the MCE being reported is an uncorrected error, KVM will
3563inject it as an MCE exception into the guest. If the guest
3564MCG_STATUS register reports that an MCE is in progress, KVM
3565causes an KVM_EXIT_SHUTDOWN vmexit.
3566
3567Otherwise, if the MCE is a corrected error, KVM will just
3568store it in the corresponding bank (provided this bank is
3569not holding a previously reported uncorrected error).
3570
Claudio Imbrenda4036e382016-08-04 17:58:47 +020035714.107 KVM_S390_GET_CMMA_BITS
3572
3573Capability: KVM_CAP_S390_CMMA_MIGRATION
3574Architectures: s390
3575Type: vm ioctl
3576Parameters: struct kvm_s390_cmma_log (in, out)
3577Returns: 0 on success, a negative value on error
3578
3579This ioctl is used to get the values of the CMMA bits on the s390
3580architecture. It is meant to be used in two scenarios:
3581- During live migration to save the CMMA values. Live migration needs
3582 to be enabled via the KVM_REQ_START_MIGRATION VM property.
3583- To non-destructively peek at the CMMA values, with the flag
3584 KVM_S390_CMMA_PEEK set.
3585
3586The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
3587values are written to a buffer whose location is indicated via the "values"
3588member in the kvm_s390_cmma_log struct. The values in the input struct are
3589also updated as needed.
3590Each CMMA value takes up one byte.
3591
3592struct kvm_s390_cmma_log {
3593 __u64 start_gfn;
3594 __u32 count;
3595 __u32 flags;
3596 union {
3597 __u64 remaining;
3598 __u64 mask;
3599 };
3600 __u64 values;
3601};
3602
3603start_gfn is the number of the first guest frame whose CMMA values are
3604to be retrieved,
3605
3606count is the length of the buffer in bytes,
3607
3608values points to the buffer where the result will be written to.
3609
3610If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
3611KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
3612other ioctls.
3613
3614The result is written in the buffer pointed to by the field values, and
3615the values of the input parameter are updated as follows.
3616
3617Depending on the flags, different actions are performed. The only
3618supported flag so far is KVM_S390_CMMA_PEEK.
3619
3620The default behaviour if KVM_S390_CMMA_PEEK is not set is:
3621start_gfn will indicate the first page frame whose CMMA bits were dirty.
3622It is not necessarily the same as the one passed as input, as clean pages
3623are skipped.
3624
3625count will indicate the number of bytes actually written in the buffer.
3626It can (and very often will) be smaller than the input value, since the
3627buffer is only filled until 16 bytes of clean values are found (which
3628are then not copied in the buffer). Since a CMMA migration block needs
3629the base address and the length, for a total of 16 bytes, we will send
3630back some clean data if there is some dirty data afterwards, as long as
3631the size of the clean data does not exceed the size of the header. This
3632allows to minimize the amount of data to be saved or transferred over
3633the network at the expense of more roundtrips to userspace. The next
3634invocation of the ioctl will skip over all the clean values, saving
3635potentially more than just the 16 bytes we found.
3636
3637If KVM_S390_CMMA_PEEK is set:
3638the existing storage attributes are read even when not in migration
3639mode, and no other action is performed;
3640
3641the output start_gfn will be equal to the input start_gfn,
3642
3643the output count will be equal to the input count, except if the end of
3644memory has been reached.
3645
3646In both cases:
3647the field "remaining" will indicate the total number of dirty CMMA values
3648still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
3649not enabled.
3650
3651mask is unused.
3652
3653values points to the userspace buffer where the result will be stored.
3654
3655This ioctl can fail with -ENOMEM if not enough memory can be allocated to
3656complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
3657KVM_S390_CMMA_PEEK is not set but migration mode was not enabled, with
3658-EFAULT if the userspace address is invalid or if no page table is
3659present for the addresses (e.g. when using hugepages).
3660
36614.108 KVM_S390_SET_CMMA_BITS
3662
3663Capability: KVM_CAP_S390_CMMA_MIGRATION
3664Architectures: s390
3665Type: vm ioctl
3666Parameters: struct kvm_s390_cmma_log (in)
3667Returns: 0 on success, a negative value on error
3668
3669This ioctl is used to set the values of the CMMA bits on the s390
3670architecture. It is meant to be used during live migration to restore
3671the CMMA values, but there are no restrictions on its use.
3672The ioctl takes parameters via the kvm_s390_cmma_values struct.
3673Each CMMA value takes up one byte.
3674
3675struct kvm_s390_cmma_log {
3676 __u64 start_gfn;
3677 __u32 count;
3678 __u32 flags;
3679 union {
3680 __u64 remaining;
3681 __u64 mask;
3682 };
3683 __u64 values;
3684};
3685
3686start_gfn indicates the starting guest frame number,
3687
3688count indicates how many values are to be considered in the buffer,
3689
3690flags is not used and must be 0.
3691
3692mask indicates which PGSTE bits are to be considered.
3693
3694remaining is not used.
3695
3696values points to the buffer in userspace where to store the values.
3697
3698This ioctl can fail with -ENOMEM if not enough memory can be allocated to
3699complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
3700the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
3701if the flags field was not 0, with -EFAULT if the userspace address is
3702invalid, if invalid pages are written to (e.g. after the end of memory)
3703or if no page table is present for the addresses (e.g. when using
3704hugepages).
3705
Radim Krčmář7bf14c22018-02-01 15:04:17 +010037064.109 KVM_PPC_GET_CPU_CHAR
Paul Mackerras3214d012018-01-15 16:06:47 +11003707
3708Capability: KVM_CAP_PPC_GET_CPU_CHAR
3709Architectures: powerpc
3710Type: vm ioctl
3711Parameters: struct kvm_ppc_cpu_char (out)
3712Returns: 0 on successful completion
3713 -EFAULT if struct kvm_ppc_cpu_char cannot be written
3714
3715This ioctl gives userspace information about certain characteristics
3716of the CPU relating to speculative execution of instructions and
3717possible information leakage resulting from speculative execution (see
3718CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is
3719returned in struct kvm_ppc_cpu_char, which looks like this:
3720
3721struct kvm_ppc_cpu_char {
3722 __u64 character; /* characteristics of the CPU */
3723 __u64 behaviour; /* recommended software behaviour */
3724 __u64 character_mask; /* valid bits in character */
3725 __u64 behaviour_mask; /* valid bits in behaviour */
3726};
3727
3728For extensibility, the character_mask and behaviour_mask fields
3729indicate which bits of character and behaviour have been filled in by
3730the kernel. If the set of defined bits is extended in future then
3731userspace will be able to tell whether it is running on a kernel that
3732knows about the new bits.
3733
3734The character field describes attributes of the CPU which can help
3735with preventing inadvertent information disclosure - specifically,
3736whether there is an instruction to flash-invalidate the L1 data cache
3737(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
3738to a mode where entries can only be used by the thread that created
3739them, whether the bcctr[l] instruction prevents speculation, and
3740whether a speculation barrier instruction (ori 31,31,0) is provided.
3741
3742The behaviour field describes actions that software should take to
3743prevent inadvertent information disclosure, and thus describes which
3744vulnerabilities the hardware is subject to; specifically whether the
3745L1 data cache should be flushed when returning to user mode from the
3746kernel, and whether a speculation barrier should be placed between an
3747array bounds check and the array access.
3748
3749These fields use the same bit definitions as the new
3750H_GET_CPU_CHARACTERISTICS hypercall.
3751
Radim Krčmář7bf14c22018-02-01 15:04:17 +010037524.110 KVM_MEMORY_ENCRYPT_OP
Brijesh Singh5acc5c02017-12-04 10:57:26 -06003753
3754Capability: basic
3755Architectures: x86
3756Type: system
3757Parameters: an opaque platform specific structure (in/out)
3758Returns: 0 on success; -1 on error
3759
3760If the platform supports creating encrypted VMs then this ioctl can be used
3761for issuing platform-specific memory encryption commands to manage those
3762encrypted VMs.
3763
3764Currently, this ioctl is used for issuing Secure Encrypted Virtualization
3765(SEV) commands on AMD Processors. The SEV commands are defined in
Andrew Jones21e94ac2018-03-26 14:38:02 +02003766Documentation/virtual/kvm/amd-memory-encryption.rst.
Brijesh Singh5acc5c02017-12-04 10:57:26 -06003767
Radim Krčmář7bf14c22018-02-01 15:04:17 +010037684.111 KVM_MEMORY_ENCRYPT_REG_REGION
Brijesh Singh69eaede2017-12-04 10:57:26 -06003769
3770Capability: basic
3771Architectures: x86
3772Type: system
3773Parameters: struct kvm_enc_region (in)
3774Returns: 0 on success; -1 on error
3775
3776This ioctl can be used to register a guest memory region which may
3777contain encrypted data (e.g. guest RAM, SMRAM etc).
3778
3779It is used in the SEV-enabled guest. When encryption is enabled, a guest
3780memory region may contain encrypted data. The SEV memory encryption
3781engine uses a tweak such that two identical plaintext pages, each at
3782different locations will have differing ciphertexts. So swapping or
3783moving ciphertext of those pages will not result in plaintext being
3784swapped. So relocating (or migrating) physical backing pages for the SEV
3785guest will require some additional steps.
3786
3787Note: The current SEV key management spec does not provide commands to
3788swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
3789memory region registered with the ioctl.
3790
Radim Krčmář7bf14c22018-02-01 15:04:17 +010037914.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
Brijesh Singh69eaede2017-12-04 10:57:26 -06003792
3793Capability: basic
3794Architectures: x86
3795Type: system
3796Parameters: struct kvm_enc_region (in)
3797Returns: 0 on success; -1 on error
3798
3799This ioctl can be used to unregister the guest memory region registered
3800with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
3801
Roman Kaganfaeb7832018-02-01 16:48:32 +030038024.113 KVM_HYPERV_EVENTFD
3803
3804Capability: KVM_CAP_HYPERV_EVENTFD
3805Architectures: x86
3806Type: vm ioctl
3807Parameters: struct kvm_hyperv_eventfd (in)
3808
3809This ioctl (un)registers an eventfd to receive notifications from the guest on
3810the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
3811causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
3812(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
3813
3814struct kvm_hyperv_eventfd {
3815 __u32 conn_id;
3816 __s32 fd;
3817 __u32 flags;
3818 __u32 padding[3];
3819};
3820
3821The conn_id field should fit within 24 bits:
3822
3823#define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
3824
3825The acceptable values for the flags field are:
3826
3827#define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
3828
3829Returns: 0 on success,
3830 -EINVAL if conn_id or flags is outside the allowed range
3831 -ENOENT on deassign if the conn_id isn't registered
3832 -EEXIST on assign if the conn_id is already registered
3833
Jim Mattson8fcc4b52018-07-10 11:27:20 +020038344.114 KVM_GET_NESTED_STATE
3835
3836Capability: KVM_CAP_NESTED_STATE
3837Architectures: x86
3838Type: vcpu ioctl
3839Parameters: struct kvm_nested_state (in/out)
3840Returns: 0 on success, -1 on error
3841Errors:
3842 E2BIG: the total state size (including the fixed-size part of struct
3843 kvm_nested_state) exceeds the value of 'size' specified by
3844 the user; the size required will be written into size.
3845
3846struct kvm_nested_state {
3847 __u16 flags;
3848 __u16 format;
3849 __u32 size;
3850 union {
3851 struct kvm_vmx_nested_state vmx;
3852 struct kvm_svm_nested_state svm;
3853 __u8 pad[120];
3854 };
3855 __u8 data[0];
3856};
3857
3858#define KVM_STATE_NESTED_GUEST_MODE 0x00000001
3859#define KVM_STATE_NESTED_RUN_PENDING 0x00000002
3860
3861#define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001
3862#define KVM_STATE_NESTED_SMM_VMXON 0x00000002
3863
3864struct kvm_vmx_nested_state {
3865 __u64 vmxon_pa;
3866 __u64 vmcs_pa;
3867
3868 struct {
3869 __u16 flags;
3870 } smm;
3871};
3872
3873This ioctl copies the vcpu's nested virtualization state from the kernel to
3874userspace.
3875
3876The maximum size of the state, including the fixed-size part of struct
3877kvm_nested_state, can be retrieved by passing KVM_CAP_NESTED_STATE to
3878the KVM_CHECK_EXTENSION ioctl().
3879
38804.115 KVM_SET_NESTED_STATE
3881
3882Capability: KVM_CAP_NESTED_STATE
3883Architectures: x86
3884Type: vcpu ioctl
3885Parameters: struct kvm_nested_state (in)
3886Returns: 0 on success, -1 on error
3887
3888This copies the vcpu's kvm_nested_state struct from userspace to the kernel. For
3889the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
Radim Krčmář7bf14c22018-02-01 15:04:17 +01003890
Peng Hao99434502018-10-14 07:09:56 +080038914.116 KVM_(UN)REGISTER_COALESCED_MMIO
3892
Peng Hao0804c842018-10-14 07:09:55 +08003893Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio)
3894 KVM_CAP_COALESCED_PIO (for coalesced pio)
Peng Hao99434502018-10-14 07:09:56 +08003895Architectures: all
3896Type: vm ioctl
3897Parameters: struct kvm_coalesced_mmio_zone
3898Returns: 0 on success, < 0 on error
3899
Peng Hao0804c842018-10-14 07:09:55 +08003900Coalesced I/O is a performance optimization that defers hardware
Peng Hao99434502018-10-14 07:09:56 +08003901register write emulation so that userspace exits are avoided. It is
3902typically used to reduce the overhead of emulating frequently accessed
3903hardware registers.
3904
Peng Hao0804c842018-10-14 07:09:55 +08003905When a hardware register is configured for coalesced I/O, write accesses
Peng Hao99434502018-10-14 07:09:56 +08003906do not exit to userspace and their value is recorded in a ring buffer
3907that is shared between kernel and userspace.
3908
Peng Hao0804c842018-10-14 07:09:55 +08003909Coalesced I/O is used if one or more write accesses to a hardware
Peng Hao99434502018-10-14 07:09:56 +08003910register can be deferred until a read or a write to another hardware
3911register on the same device. This last access will cause a vmexit and
3912userspace will process accesses from the ring buffer before emulating
Peng Hao0804c842018-10-14 07:09:55 +08003913it. That will avoid exiting to userspace on repeated writes.
3914
3915Coalesced pio is based on coalesced mmio. There is little difference
3916between coalesced mmio and pio except that coalesced pio records accesses
3917to I/O ports.
Peng Hao99434502018-10-14 07:09:56 +08003918
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020039194.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
3920
3921Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
3922Architectures: x86
3923Type: vm ioctl
3924Parameters: struct kvm_dirty_log (in)
3925Returns: 0 on success, -1 on error
3926
3927/* for KVM_CLEAR_DIRTY_LOG */
3928struct kvm_clear_dirty_log {
3929 __u32 slot;
3930 __u32 num_pages;
3931 __u64 first_page;
3932 union {
3933 void __user *dirty_bitmap; /* one bit per page */
3934 __u64 padding;
3935 };
3936};
3937
3938The ioctl clears the dirty status of pages in a memory slot, according to
3939the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap
3940field. Bit 0 of the bitmap corresponds to page "first_page" in the
3941memory slot, and num_pages is the size in bits of the input bitmap.
3942Both first_page and num_pages must be a multiple of 64. For each bit
3943that is set in the input bitmap, the corresponding page is marked "clean"
3944in KVM's dirty bitmap, and dirty tracking is re-enabled for that page
3945(for example via write-protection, or by clearing the dirty bit in
3946a page table entry).
3947
3948If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 specifies
3949the address space for which you want to return the dirty bitmap.
3950They must be less than the value that KVM_CHECK_EXTENSION returns for
3951the KVM_CAP_MULTI_ADDRESS_SPACE capability.
3952
3953This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
3954is enabled; for more information, see the description of the capability.
3955However, it can always be used as long as KVM_CHECK_EXTENSION confirms
3956that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is present.
3957
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +010039584.118 KVM_GET_SUPPORTED_HV_CPUID
3959
3960Capability: KVM_CAP_HYPERV_CPUID
3961Architectures: x86
3962Type: vcpu ioctl
3963Parameters: struct kvm_cpuid2 (in/out)
3964Returns: 0 on success, -1 on error
3965
3966struct kvm_cpuid2 {
3967 __u32 nent;
3968 __u32 padding;
3969 struct kvm_cpuid_entry2 entries[0];
3970};
3971
3972struct kvm_cpuid_entry2 {
3973 __u32 function;
3974 __u32 index;
3975 __u32 flags;
3976 __u32 eax;
3977 __u32 ebx;
3978 __u32 ecx;
3979 __u32 edx;
3980 __u32 padding[3];
3981};
3982
3983This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in
3984KVM. Userspace can use the information returned by this ioctl to construct
3985cpuid information presented to guests consuming Hyper-V enlightenments (e.g.
3986Windows or Hyper-V guests).
3987
3988CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level
3989Functional Specification (TLFS). These leaves can't be obtained with
3990KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature
3991leaves (0x40000000, 0x40000001).
3992
3993Currently, the following list of CPUID leaves are returned:
3994 HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS
3995 HYPERV_CPUID_INTERFACE
3996 HYPERV_CPUID_VERSION
3997 HYPERV_CPUID_FEATURES
3998 HYPERV_CPUID_ENLIGHTMENT_INFO
3999 HYPERV_CPUID_IMPLEMENT_LIMITS
4000 HYPERV_CPUID_NESTED_FEATURES
4001
4002HYPERV_CPUID_NESTED_FEATURES leaf is only exposed when Enlightened VMCS was
4003enabled on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
4004
4005Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
4006with the 'nent' field indicating the number of entries in the variable-size
4007array 'entries'. If the number of entries is too low to describe all Hyper-V
4008feature leaves, an error (E2BIG) is returned. If the number is more or equal
4009to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the
4010number of valid entries in the 'entries' array, which is then filled.
4011
4012'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved,
4013userspace should not expect to get any particular value there.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004014
Dave Martin50036ad2018-09-28 14:39:27 +010040154.119 KVM_ARM_VCPU_FINALIZE
4016
Dave Martin50036ad2018-09-28 14:39:27 +01004017Architectures: arm, arm64
4018Type: vcpu ioctl
4019Parameters: int feature (in)
4020Returns: 0 on success, -1 on error
4021Errors:
4022 EPERM: feature not enabled, needs configuration, or already finalized
Dave Martin9df2d662019-04-12 13:28:05 +01004023 EINVAL: feature unknown or not present
Dave Martin50036ad2018-09-28 14:39:27 +01004024
4025Recognised values for feature:
Dave Martin9df2d662019-04-12 13:28:05 +01004026 arm64 KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE)
Dave Martin50036ad2018-09-28 14:39:27 +01004027
4028Finalizes the configuration of the specified vcpu feature.
4029
4030The vcpu must already have been initialised, enabling the affected feature, by
4031means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in
4032features[].
4033
4034For affected vcpu features, this is a mandatory step that must be performed
4035before the vcpu is fully usable.
4036
4037Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be
4038configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration
4039that should be performaned and how to do it are feature-dependent.
4040
4041Other calls that depend on a particular feature being finalized, such as
4042KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with
4043-EPERM unless the feature has already been finalized by means of a
4044KVM_ARM_VCPU_FINALIZE call.
4045
4046See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization
4047using this ioctl.
4048
Avi Kivity9c1b96e2009-06-09 12:37:58 +030040495. The kvm_run structure
Jan Kiszka414fa982012-04-24 16:40:15 +02004050------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004051
4052Application code obtains a pointer to the kvm_run structure by
4053mmap()ing a vcpu fd. From that point, application code can control
4054execution by changing fields in kvm_run prior to calling the KVM_RUN
4055ioctl, and obtain information about the reason KVM_RUN returned by
4056looking up structure members.
4057
4058struct kvm_run {
4059 /* in */
4060 __u8 request_interrupt_window;
4061
4062Request that KVM_RUN return when it becomes possible to inject external
4063interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
4064
Paolo Bonzini460df4c2017-02-08 11:50:15 +01004065 __u8 immediate_exit;
4066
4067This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
4068exits immediately, returning -EINTR. In the common scenario where a
4069signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
4070to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
4071Rather than blocking the signal outside KVM_RUN, userspace can set up
4072a signal handler that sets run->immediate_exit to a non-zero value.
4073
4074This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
4075
4076 __u8 padding1[6];
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004077
4078 /* out */
4079 __u32 exit_reason;
4080
4081When KVM_RUN has returned successfully (return value 0), this informs
4082application code why KVM_RUN has returned. Allowable values for this
4083field are detailed below.
4084
4085 __u8 ready_for_interrupt_injection;
4086
4087If request_interrupt_window has been specified, this field indicates
4088an interrupt can be injected now with KVM_INTERRUPT.
4089
4090 __u8 if_flag;
4091
4092The value of the current interrupt flag. Only valid if in-kernel
4093local APIC is not used.
4094
Paolo Bonzinif0778252015-04-01 15:06:40 +02004095 __u16 flags;
4096
4097More architecture-specific flags detailing state of the VCPU that may
4098affect the device's behavior. The only currently defined flag is
4099KVM_RUN_X86_SMM, which is valid on x86 machines and is set if the
4100VCPU is in system management mode.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004101
4102 /* in (pre_kvm_run), out (post_kvm_run) */
4103 __u64 cr8;
4104
4105The value of the cr8 register. Only valid if in-kernel local APIC is
4106not used. Both input and output.
4107
4108 __u64 apic_base;
4109
4110The value of the APIC BASE msr. Only valid if in-kernel local
4111APIC is not used. Both input and output.
4112
4113 union {
4114 /* KVM_EXIT_UNKNOWN */
4115 struct {
4116 __u64 hardware_exit_reason;
4117 } hw;
4118
4119If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
4120reasons. Further architecture-specific information is available in
4121hardware_exit_reason.
4122
4123 /* KVM_EXIT_FAIL_ENTRY */
4124 struct {
4125 __u64 hardware_entry_failure_reason;
4126 } fail_entry;
4127
4128If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
4129to unknown reasons. Further architecture-specific information is
4130available in hardware_entry_failure_reason.
4131
4132 /* KVM_EXIT_EXCEPTION */
4133 struct {
4134 __u32 exception;
4135 __u32 error_code;
4136 } ex;
4137
4138Unused.
4139
4140 /* KVM_EXIT_IO */
4141 struct {
4142#define KVM_EXIT_IO_IN 0
4143#define KVM_EXIT_IO_OUT 1
4144 __u8 direction;
4145 __u8 size; /* bytes */
4146 __u16 port;
4147 __u32 count;
4148 __u64 data_offset; /* relative to kvm_run start */
4149 } io;
4150
Wu Fengguang2044892d2009-12-24 09:04:16 +08004151If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004152executed a port I/O instruction which could not be satisfied by kvm.
4153data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
4154where kvm expects application code to place the data for the next
Wu Fengguang2044892d2009-12-24 09:04:16 +08004155KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004156
Alex Bennée8ab30c12015-07-07 17:29:53 +01004157 /* KVM_EXIT_DEBUG */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004158 struct {
4159 struct kvm_debug_exit_arch arch;
4160 } debug;
4161
Alex Bennée8ab30c12015-07-07 17:29:53 +01004162If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
4163for which architecture specific information is returned.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004164
4165 /* KVM_EXIT_MMIO */
4166 struct {
4167 __u64 phys_addr;
4168 __u8 data[8];
4169 __u32 len;
4170 __u8 is_write;
4171 } mmio;
4172
Wu Fengguang2044892d2009-12-24 09:04:16 +08004173If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004174executed a memory-mapped I/O instruction which could not be satisfied
4175by kvm. The 'data' member contains the written data if 'is_write' is
4176true, and should be filled by application code otherwise.
4177
Christoffer Dall6acdb162014-01-28 08:28:42 -08004178The 'data' member contains, in its first 'len' bytes, the value as it would
4179appear if the VCPU performed a load or store of the appropriate width directly
4180to the byte array.
4181
Paolo Bonzinicc568ea2014-08-05 09:55:22 +02004182NOTE: For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR and
Alexander Grafce91ddc2014-07-28 19:29:13 +02004183 KVM_EXIT_EPR the corresponding
Alexander Grafad0a0482010-03-24 21:48:30 +01004184operations are complete (and guest state is consistent) only after userspace
4185has re-entered the kernel with KVM_RUN. The kernel side will first finish
Marcelo Tosatti67961342010-02-13 16:10:26 -02004186incomplete operations and then check for pending signals. Userspace
4187can re-enter the guest with an unmasked signal pending to complete
4188pending operations.
4189
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004190 /* KVM_EXIT_HYPERCALL */
4191 struct {
4192 __u64 nr;
4193 __u64 args[6];
4194 __u64 ret;
4195 __u32 longmode;
4196 __u32 pad;
4197 } hypercall;
4198
Avi Kivity647dc492010-04-01 14:39:21 +03004199Unused. This was once used for 'hypercall to userspace'. To implement
4200such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
4201Note KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004202
4203 /* KVM_EXIT_TPR_ACCESS */
4204 struct {
4205 __u64 rip;
4206 __u32 is_write;
4207 __u32 pad;
4208 } tpr_access;
4209
4210To be documented (KVM_TPR_ACCESS_REPORTING).
4211
4212 /* KVM_EXIT_S390_SIEIC */
4213 struct {
4214 __u8 icptcode;
4215 __u64 mask; /* psw upper half */
4216 __u64 addr; /* psw lower half */
4217 __u16 ipa;
4218 __u32 ipb;
4219 } s390_sieic;
4220
4221s390 specific.
4222
4223 /* KVM_EXIT_S390_RESET */
4224#define KVM_S390_RESET_POR 1
4225#define KVM_S390_RESET_CLEAR 2
4226#define KVM_S390_RESET_SUBSYSTEM 4
4227#define KVM_S390_RESET_CPU_INIT 8
4228#define KVM_S390_RESET_IPL 16
4229 __u64 s390_reset_flags;
4230
4231s390 specific.
4232
Carsten Ottee168bf82012-01-04 10:25:22 +01004233 /* KVM_EXIT_S390_UCONTROL */
4234 struct {
4235 __u64 trans_exc_code;
4236 __u32 pgm_code;
4237 } s390_ucontrol;
4238
4239s390 specific. A page fault has occurred for a user controlled virtual
4240machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
4241resolved by the kernel.
4242The program code and the translation exception code that were placed
4243in the cpu's lowcore are presented here as defined by the z Architecture
4244Principles of Operation Book in the Chapter for Dynamic Address Translation
4245(DAT)
4246
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004247 /* KVM_EXIT_DCR */
4248 struct {
4249 __u32 dcrn;
4250 __u32 data;
4251 __u8 is_write;
4252 } dcr;
4253
Alexander Grafce91ddc2014-07-28 19:29:13 +02004254Deprecated - was used for 440 KVM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004255
Alexander Grafad0a0482010-03-24 21:48:30 +01004256 /* KVM_EXIT_OSI */
4257 struct {
4258 __u64 gprs[32];
4259 } osi;
4260
4261MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
4262hypercalls and exit with this exit struct that contains all the guest gprs.
4263
4264If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
4265Userspace can now handle the hypercall and when it's done modify the gprs as
4266necessary. Upon guest entry all guest GPRs will then be replaced by the values
4267in this struct.
4268
Paul Mackerrasde56a942011-06-29 00:21:34 +00004269 /* KVM_EXIT_PAPR_HCALL */
4270 struct {
4271 __u64 nr;
4272 __u64 ret;
4273 __u64 args[9];
4274 } papr_hcall;
4275
4276This is used on 64-bit PowerPC when emulating a pSeries partition,
4277e.g. with the 'pseries' machine type in qemu. It occurs when the
4278guest does a hypercall using the 'sc 1' instruction. The 'nr' field
4279contains the hypercall number (from the guest R3), and 'args' contains
4280the arguments (from the guest R4 - R12). Userspace should put the
4281return code in 'ret' and any extra returned values in args[].
4282The possible hypercalls are defined in the Power Architecture Platform
4283Requirements (PAPR) document available from www.power.org (free
4284developer registration required to access it).
4285
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004286 /* KVM_EXIT_S390_TSCH */
4287 struct {
4288 __u16 subchannel_id;
4289 __u16 subchannel_nr;
4290 __u32 io_int_parm;
4291 __u32 io_int_word;
4292 __u32 ipb;
4293 __u8 dequeued;
4294 } s390_tsch;
4295
4296s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
4297and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
4298interrupt for the target subchannel has been dequeued and subchannel_id,
4299subchannel_nr, io_int_parm and io_int_word contain the parameters for that
4300interrupt. ipb is needed for instruction parameter decoding.
4301
Alexander Graf1c810632013-01-04 18:12:48 +01004302 /* KVM_EXIT_EPR */
4303 struct {
4304 __u32 epr;
4305 } epr;
4306
4307On FSL BookE PowerPC chips, the interrupt controller has a fast patch
4308interrupt acknowledge path to the core. When the core successfully
4309delivers an interrupt, it automatically populates the EPR register with
4310the interrupt vector number and acknowledges the interrupt inside
4311the interrupt controller.
4312
4313In case the interrupt controller lives in user space, we need to do
4314the interrupt acknowledge cycle through it to fetch the next to be
4315delivered interrupt vector using this exit.
4316
4317It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
4318external interrupt has just been delivered into the guest. User space
4319should put the acknowledged interrupt vector into the 'epr' field.
4320
Anup Patel8ad6b632014-04-29 11:24:19 +05304321 /* KVM_EXIT_SYSTEM_EVENT */
4322 struct {
4323#define KVM_SYSTEM_EVENT_SHUTDOWN 1
4324#define KVM_SYSTEM_EVENT_RESET 2
Andrey Smetanin2ce79182015-07-03 15:01:41 +03004325#define KVM_SYSTEM_EVENT_CRASH 3
Anup Patel8ad6b632014-04-29 11:24:19 +05304326 __u32 type;
4327 __u64 flags;
4328 } system_event;
4329
4330If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
4331a system-level event using some architecture specific mechanism (hypercall
4332or some special instruction). In case of ARM/ARM64, this is triggered using
4333HVC instruction based PSCI call from the vcpu. The 'type' field describes
4334the system-level event type. The 'flags' field describes architecture
4335specific flags for the system-level event.
4336
Christoffer Dallcf5d31882014-10-16 17:00:18 +02004337Valid values for 'type' are:
4338 KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
4339 VM. Userspace is not obliged to honour this, and if it does honour
4340 this does not need to destroy the VM synchronously (ie it may call
4341 KVM_RUN again before shutdown finally occurs).
4342 KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
4343 As with SHUTDOWN, userspace can choose to ignore the request, or
4344 to schedule the reset to occur in the future and may call KVM_RUN again.
Andrey Smetanin2ce79182015-07-03 15:01:41 +03004345 KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
4346 has requested a crash condition maintenance. Userspace can choose
4347 to ignore the request, or to gather VM memory core dump and/or
4348 reset/shutdown of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02004349
Steve Rutherford7543a632015-07-29 23:21:41 -07004350 /* KVM_EXIT_IOAPIC_EOI */
4351 struct {
4352 __u8 vector;
4353 } eoi;
4354
4355Indicates that the VCPU's in-kernel local APIC received an EOI for a
4356level-triggered IOAPIC interrupt. This exit only triggers when the
4357IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
4358the userspace IOAPIC should process the EOI and retrigger the interrupt if
4359it is still asserted. Vector is the LAPIC interrupt vector for which the
4360EOI was received.
4361
Andrey Smetanindb3975712015-11-10 15:36:35 +03004362 struct kvm_hyperv_exit {
4363#define KVM_EXIT_HYPERV_SYNIC 1
Andrey Smetanin83326e42016-02-11 16:45:01 +03004364#define KVM_EXIT_HYPERV_HCALL 2
Andrey Smetanindb3975712015-11-10 15:36:35 +03004365 __u32 type;
4366 union {
4367 struct {
4368 __u32 msr;
4369 __u64 control;
4370 __u64 evt_page;
4371 __u64 msg_page;
4372 } synic;
Andrey Smetanin83326e42016-02-11 16:45:01 +03004373 struct {
4374 __u64 input;
4375 __u64 result;
4376 __u64 params[2];
4377 } hcall;
Andrey Smetanindb3975712015-11-10 15:36:35 +03004378 } u;
4379 };
4380 /* KVM_EXIT_HYPERV */
4381 struct kvm_hyperv_exit hyperv;
4382Indicates that the VCPU exits into userspace to process some tasks
4383related to Hyper-V emulation.
4384Valid values for 'type' are:
4385 KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
4386Hyper-V SynIC state change. Notification is used to remap SynIC
4387event/message pages and to enable/disable SynIC messages/events processing
4388in userspace.
4389
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004390 /* Fix the size of the union. */
4391 char padding[256];
4392 };
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01004393
4394 /*
4395 * shared registers between kvm and userspace.
4396 * kvm_valid_regs specifies the register classes set by the host
4397 * kvm_dirty_regs specified the register classes dirtied by userspace
4398 * struct kvm_sync_regs is architecture specific, as well as the
4399 * bits for kvm_valid_regs and kvm_dirty_regs
4400 */
4401 __u64 kvm_valid_regs;
4402 __u64 kvm_dirty_regs;
4403 union {
4404 struct kvm_sync_regs regs;
Ken Hofsass7b7e3952018-01-31 16:03:35 -08004405 char padding[SYNC_REGS_SIZE_BYTES];
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01004406 } s;
4407
4408If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
4409certain guest registers without having to call SET/GET_*REGS. Thus we can
4410avoid some system call overhead if userspace has to handle the exit.
4411Userspace can query the validity of the structure by checking
4412kvm_valid_regs for specific bits. These bits are architecture specific
4413and usually define the validity of a groups of registers. (e.g. one bit
4414 for general purpose registers)
4415
David Hildenbrandd8482c02014-07-29 08:19:26 +02004416Please note that the kernel is allowed to use the kvm_run structure as the
4417primary storage for certain register types. Therefore, the kernel may use the
4418values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
4419
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004420};
Alexander Graf821246a2011-08-31 10:58:55 +02004421
Jan Kiszka414fa982012-04-24 16:40:15 +02004422
Borislav Petkov9c15bb12013-09-22 16:44:50 +02004423
Paul Mackerras699a0ea2014-06-02 11:02:59 +100044246. Capabilities that can be enabled on vCPUs
4425--------------------------------------------
Alexander Graf821246a2011-08-31 10:58:55 +02004426
Cornelia Huck0907c852014-06-27 09:29:26 +02004427There are certain capabilities that change the behavior of the virtual CPU or
4428the virtual machine when enabled. To enable them, please see section 4.37.
4429Below you can find a list of capabilities and what their effect on the vCPU or
4430the virtual machine is when enabling them.
Alexander Graf821246a2011-08-31 10:58:55 +02004431
4432The following information is provided along with the description:
4433
4434 Architectures: which instruction set architectures provide this ioctl.
4435 x86 includes both i386 and x86_64.
4436
Cornelia Huck0907c852014-06-27 09:29:26 +02004437 Target: whether this is a per-vcpu or per-vm capability.
4438
Alexander Graf821246a2011-08-31 10:58:55 +02004439 Parameters: what parameters are accepted by the capability.
4440
4441 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
4442 are not detailed, but errors with specific meanings are.
4443
Jan Kiszka414fa982012-04-24 16:40:15 +02004444
Alexander Graf821246a2011-08-31 10:58:55 +020044456.1 KVM_CAP_PPC_OSI
4446
4447Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004448Target: vcpu
Alexander Graf821246a2011-08-31 10:58:55 +02004449Parameters: none
4450Returns: 0 on success; -1 on error
4451
4452This capability enables interception of OSI hypercalls that otherwise would
4453be treated as normal system calls to be injected into the guest. OSI hypercalls
4454were invented by Mac-on-Linux to have a standardized communication mechanism
4455between the guest and the host.
4456
4457When this capability is enabled, KVM_EXIT_OSI can occur.
4458
Jan Kiszka414fa982012-04-24 16:40:15 +02004459
Alexander Graf821246a2011-08-31 10:58:55 +020044606.2 KVM_CAP_PPC_PAPR
4461
4462Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004463Target: vcpu
Alexander Graf821246a2011-08-31 10:58:55 +02004464Parameters: none
4465Returns: 0 on success; -1 on error
4466
4467This capability enables interception of PAPR hypercalls. PAPR hypercalls are
4468done using the hypercall instruction "sc 1".
4469
4470It also sets the guest privilege level to "supervisor" mode. Usually the guest
4471runs in "hypervisor" privilege mode with a few missing features.
4472
4473In addition to the above, it changes the semantics of SDR1. In this mode, the
4474HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
4475HTAB invisible to the guest.
4476
4477When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
Scott Wooddc83b8b2011-08-18 15:25:21 -05004478
Jan Kiszka414fa982012-04-24 16:40:15 +02004479
Scott Wooddc83b8b2011-08-18 15:25:21 -050044806.3 KVM_CAP_SW_TLB
4481
4482Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004483Target: vcpu
Scott Wooddc83b8b2011-08-18 15:25:21 -05004484Parameters: args[0] is the address of a struct kvm_config_tlb
4485Returns: 0 on success; -1 on error
4486
4487struct kvm_config_tlb {
4488 __u64 params;
4489 __u64 array;
4490 __u32 mmu_type;
4491 __u32 array_len;
4492};
4493
4494Configures the virtual CPU's TLB array, establishing a shared memory area
4495between userspace and KVM. The "params" and "array" fields are userspace
4496addresses of mmu-type-specific data structures. The "array_len" field is an
4497safety mechanism, and should be set to the size in bytes of the memory that
4498userspace has reserved for the array. It must be at least the size dictated
4499by "mmu_type" and "params".
4500
4501While KVM_RUN is active, the shared region is under control of KVM. Its
4502contents are undefined, and any modification by userspace results in
4503boundedly undefined behavior.
4504
4505On return from KVM_RUN, the shared region will reflect the current state of
4506the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
4507to tell KVM which entries have been changed, prior to calling KVM_RUN again
4508on this vcpu.
4509
4510For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
4511 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
4512 - The "array" field points to an array of type "struct
4513 kvm_book3e_206_tlb_entry".
4514 - The array consists of all entries in the first TLB, followed by all
4515 entries in the second TLB.
4516 - Within a TLB, entries are ordered first by increasing set number. Within a
4517 set, entries are ordered by way (increasing ESEL).
4518 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
4519 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
4520 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
4521 hardware ignores this value for TLB0.
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004522
45236.4 KVM_CAP_S390_CSS_SUPPORT
4524
4525Architectures: s390
Cornelia Huck0907c852014-06-27 09:29:26 +02004526Target: vcpu
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01004527Parameters: none
4528Returns: 0 on success; -1 on error
4529
4530This capability enables support for handling of channel I/O instructions.
4531
4532TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
4533handled in-kernel, while the other I/O instructions are passed to userspace.
4534
4535When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
4536SUBCHANNEL intercepts.
Alexander Graf1c810632013-01-04 18:12:48 +01004537
Cornelia Huck0907c852014-06-27 09:29:26 +02004538Note that even though this capability is enabled per-vcpu, the complete
4539virtual machine is affected.
4540
Alexander Graf1c810632013-01-04 18:12:48 +010045416.5 KVM_CAP_PPC_EPR
4542
4543Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004544Target: vcpu
Alexander Graf1c810632013-01-04 18:12:48 +01004545Parameters: args[0] defines whether the proxy facility is active
4546Returns: 0 on success; -1 on error
4547
4548This capability enables or disables the delivery of interrupts through the
4549external proxy facility.
4550
4551When enabled (args[0] != 0), every time the guest gets an external interrupt
4552delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
4553to receive the topmost interrupt vector.
4554
4555When disabled (args[0] == 0), behavior is as if this facility is unsupported.
4556
4557When this capability is enabled, KVM_EXIT_EPR can occur.
Scott Woodeb1e4f42013-04-12 14:08:47 +00004558
45596.6 KVM_CAP_IRQ_MPIC
4560
4561Architectures: ppc
4562Parameters: args[0] is the MPIC device fd
4563 args[1] is the MPIC CPU number for this vcpu
4564
4565This capability connects the vcpu to an in-kernel MPIC device.
Paul Mackerras5975a2e2013-04-27 00:28:37 +00004566
45676.7 KVM_CAP_IRQ_XICS
4568
4569Architectures: ppc
Cornelia Huck0907c852014-06-27 09:29:26 +02004570Target: vcpu
Paul Mackerras5975a2e2013-04-27 00:28:37 +00004571Parameters: args[0] is the XICS device fd
4572 args[1] is the XICS CPU number (server ID) for this vcpu
4573
4574This capability connects the vcpu to an in-kernel XICS device.
Cornelia Huck8a366a42014-06-27 11:06:25 +02004575
45766.8 KVM_CAP_S390_IRQCHIP
4577
4578Architectures: s390
4579Target: vm
4580Parameters: none
4581
4582This capability enables the in-kernel irqchip for s390. Please refer to
4583"4.24 KVM_CREATE_IRQCHIP" for details.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10004584
James Hogan5fafd8742014-12-08 23:07:56 +000045856.9 KVM_CAP_MIPS_FPU
4586
4587Architectures: mips
4588Target: vcpu
4589Parameters: args[0] is reserved for future use (should be 0).
4590
4591This capability allows the use of the host Floating Point Unit by the guest. It
4592allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
4593done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed
4594(depending on the current guest FPU register mode), and the Status.FR,
4595Config5.FRE bits are accessible via the KVM API and also from the guest,
4596depending on them being supported by the FPU.
4597
James Hogand952bd02014-12-08 23:07:56 +000045986.10 KVM_CAP_MIPS_MSA
4599
4600Architectures: mips
4601Target: vcpu
4602Parameters: args[0] is reserved for future use (should be 0).
4603
4604This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
4605It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
4606Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be
4607accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from
4608the guest.
4609
Ken Hofsass01643c52018-01-31 16:03:36 -080046106.74 KVM_CAP_SYNC_REGS
4611Architectures: s390, x86
4612Target: s390: always enabled, x86: vcpu
4613Parameters: none
4614Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
4615sets are supported (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
4616
4617As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
4618KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
4619without having to call SET/GET_*REGS". This reduces overhead by eliminating
4620repeated ioctl calls for setting and/or getting register values. This is
4621particularly important when userspace is making synchronous guest state
4622modifications, e.g. when emulating and/or intercepting instructions in
4623userspace.
4624
4625For s390 specifics, please refer to the source code.
4626
4627For x86:
4628- the register sets to be copied out to kvm_run are selectable
4629 by userspace (rather that all sets being copied out for every exit).
4630- vcpu_events are available in addition to regs and sregs.
4631
4632For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
4633function as an input bit-array field set by userspace to indicate the
4634specific register sets to be copied out on the next exit.
4635
4636To indicate when userspace has modified values that should be copied into
4637the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
4638This is done using the same bitflags as for the 'kvm_valid_regs' field.
4639If the dirty bit is not set, then the register set values will not be copied
4640into the vCPU even if they've been modified.
4641
4642Unused bitfields in the bitarrays must be set to zero.
4643
4644struct kvm_sync_regs {
4645 struct kvm_regs regs;
4646 struct kvm_sregs sregs;
4647 struct kvm_vcpu_events events;
4648};
4649
Paul Mackerras699a0ea2014-06-02 11:02:59 +100046507. Capabilities that can be enabled on VMs
4651------------------------------------------
4652
4653There are certain capabilities that change the behavior of the virtual
4654machine when enabled. To enable them, please see section 4.37. Below
4655you can find a list of capabilities and what their effect on the VM
4656is when enabling them.
4657
4658The following information is provided along with the description:
4659
4660 Architectures: which instruction set architectures provide this ioctl.
4661 x86 includes both i386 and x86_64.
4662
4663 Parameters: what parameters are accepted by the capability.
4664
4665 Returns: the return value. General error numbers (EBADF, ENOMEM, EINVAL)
4666 are not detailed, but errors with specific meanings are.
4667
4668
46697.1 KVM_CAP_PPC_ENABLE_HCALL
4670
4671Architectures: ppc
4672Parameters: args[0] is the sPAPR hcall number
4673 args[1] is 0 to disable, 1 to enable in-kernel handling
4674
4675This capability controls whether individual sPAPR hypercalls (hcalls)
4676get handled by the kernel or not. Enabling or disabling in-kernel
4677handling of an hcall is effective across the VM. On creation, an
4678initial set of hcalls are enabled for in-kernel handling, which
4679consists of those hcalls for which in-kernel handlers were implemented
4680before this capability was implemented. If disabled, the kernel will
4681not to attempt to handle the hcall, but will always exit to userspace
4682to handle it. Note that it may not make sense to enable some and
4683disable others of a group of related hcalls, but KVM does not prevent
4684userspace from doing that.
Paul Mackerrasae2113a2014-06-02 11:03:00 +10004685
4686If the hcall number specified is not one that has an in-kernel
4687implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
4688error.
David Hildenbrand2444b352014-10-09 14:10:13 +02004689
46907.2 KVM_CAP_S390_USER_SIGP
4691
4692Architectures: s390
4693Parameters: none
4694
4695This capability controls which SIGP orders will be handled completely in user
4696space. With this capability enabled, all fast orders will be handled completely
4697in the kernel:
4698- SENSE
4699- SENSE RUNNING
4700- EXTERNAL CALL
4701- EMERGENCY SIGNAL
4702- CONDITIONAL EMERGENCY SIGNAL
4703
4704All other orders will be handled completely in user space.
4705
4706Only privileged operation exceptions will be checked for in the kernel (or even
4707in the hardware prior to interception). If this capability is not enabled, the
4708old way of handling SIGP orders is used (partially in kernel and user space).
Eric Farman68c55752014-06-09 10:57:26 -04004709
47107.3 KVM_CAP_S390_VECTOR_REGISTERS
4711
4712Architectures: s390
4713Parameters: none
4714Returns: 0 on success, negative value on error
4715
4716Allows use of the vector registers introduced with z13 processor, and
4717provides for the synchronization between host and user space. Will
4718return -EINVAL if the machine does not support vectors.
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01004719
47207.4 KVM_CAP_S390_USER_STSI
4721
4722Architectures: s390
4723Parameters: none
4724
4725This capability allows post-handlers for the STSI instruction. After
4726initial handling in the kernel, KVM exits to user space with
4727KVM_EXIT_S390_STSI to allow user space to insert further data.
4728
4729Before exiting to userspace, kvm handlers should fill in s390_stsi field of
4730vcpu->run:
4731struct {
4732 __u64 addr;
4733 __u8 ar;
4734 __u8 reserved;
4735 __u8 fc;
4736 __u8 sel1;
4737 __u16 sel2;
4738} s390_stsi;
4739
4740@addr - guest address of STSI SYSIB
4741@fc - function code
4742@sel1 - selector 1
4743@sel2 - selector 2
4744@ar - access register number
4745
4746KVM handlers should exit to userspace with rc = -EREMOTE.
Michael Ellermane928e9c2015-03-20 20:39:41 +11004747
Steve Rutherford49df6392015-07-29 23:21:40 -070047487.5 KVM_CAP_SPLIT_IRQCHIP
4749
4750Architectures: x86
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07004751Parameters: args[0] - number of routes reserved for userspace IOAPICs
Steve Rutherford49df6392015-07-29 23:21:40 -07004752Returns: 0 on success, -1 on error
4753
4754Create a local apic for each processor in the kernel. This can be used
4755instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
4756IOAPIC and PIC (and also the PIT, even though this has to be enabled
4757separately).
4758
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07004759This capability also enables in kernel routing of interrupt requests;
4760when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
4761used in the IRQ routing table. The first args[0] MSI routes are reserved
4762for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
4763a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
Steve Rutherford49df6392015-07-29 23:21:40 -07004764
4765Fails if VCPU has already been created, or if the irqchip is already in the
4766kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
4767
David Hildenbrand051c87f2016-04-19 13:13:40 +020047687.6 KVM_CAP_S390_RI
4769
4770Architectures: s390
4771Parameters: none
4772
4773Allows use of runtime-instrumentation introduced with zEC12 processor.
4774Will return -EINVAL if the machine does not support runtime-instrumentation.
4775Will return -EBUSY if a VCPU has already been created.
Michael Ellermane928e9c2015-03-20 20:39:41 +11004776
Radim Krčmář371313132016-07-12 22:09:27 +020047777.7 KVM_CAP_X2APIC_API
4778
4779Architectures: x86
4780Parameters: args[0] - features that should be enabled
4781Returns: 0 on success, -EINVAL when args[0] contains invalid features
4782
4783Valid feature flags in args[0] are
4784
4785#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
Radim Krčmářc5192652016-07-12 22:09:28 +02004786#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
Radim Krčmář371313132016-07-12 22:09:27 +02004787
4788Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
4789KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
4790allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
4791respective sections.
4792
Radim Krčmářc5192652016-07-12 22:09:28 +02004793KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
4794in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
4795as a broadcast even in x2APIC mode in order to support physical x2APIC
4796without interrupt remapping. This is undesirable in logical mode,
4797where 0xff represents CPUs 0-7 in cluster 0.
Radim Krčmář371313132016-07-12 22:09:27 +02004798
David Hildenbrand6502a342016-06-21 14:19:51 +020047997.8 KVM_CAP_S390_USER_INSTR0
4800
4801Architectures: s390
4802Parameters: none
4803
4804With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
4805be intercepted and forwarded to user space. User space can use this
4806mechanism e.g. to realize 2-byte software breakpoints. The kernel will
4807not inject an operating exception for these instructions, user space has
4808to take care of that.
4809
4810This capability can be enabled dynamically even if VCPUs were already
4811created and are running.
Radim Krčmář371313132016-07-12 22:09:27 +02004812
Fan Zhang4e0b1ab2016-11-29 07:17:55 +010048137.9 KVM_CAP_S390_GS
4814
4815Architectures: s390
4816Parameters: none
4817Returns: 0 on success; -EINVAL if the machine does not support
4818 guarded storage; -EBUSY if a VCPU has already been created.
4819
4820Allows use of guarded storage for the KVM guest.
4821
Yi Min Zhao47a46932017-03-10 09:29:38 +010048227.10 KVM_CAP_S390_AIS
4823
4824Architectures: s390
4825Parameters: none
4826
4827Allow use of adapter-interruption suppression.
4828Returns: 0 on success; -EBUSY if a VCPU has already been created.
4829
Paul Mackerras3c313522017-02-06 13:24:41 +110048307.11 KVM_CAP_PPC_SMT
4831
4832Architectures: ppc
4833Parameters: vsmt_mode, flags
4834
4835Enabling this capability on a VM provides userspace with a way to set
4836the desired virtual SMT mode (i.e. the number of virtual CPUs per
4837virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
4838between 1 and 8. On POWER8, vsmt_mode must also be no greater than
4839the number of threads per subcore for the host. Currently flags must
4840be 0. A successful call to enable this capability will result in
4841vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
4842subsequently queried for the VM. This capability is only supported by
4843HV KVM, and can only be set before any VCPUs have been created.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10004844The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
4845modes are available.
Paul Mackerras3c313522017-02-06 13:24:41 +11004846
Aravinda Prasad134764e2017-05-11 16:32:48 +053048477.12 KVM_CAP_PPC_FWNMI
4848
4849Architectures: ppc
4850Parameters: none
4851
4852With this capability a machine check exception in the guest address
4853space will cause KVM to exit the guest with NMI exit reason. This
4854enables QEMU to build error log and branch to guest kernel registered
4855machine check handling routine. Without this capability KVM will
4856branch to guests' 0x200 interrupt vector.
4857
Wanpeng Li4d5422c2018-03-12 04:53:02 -070048587.13 KVM_CAP_X86_DISABLE_EXITS
4859
4860Architectures: x86
4861Parameters: args[0] defines which exits are disabled
4862Returns: 0 on success, -EINVAL when args[0] contains invalid exits
4863
4864Valid bits in args[0] are
4865
4866#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
Wanpeng Licaa057a2018-03-12 04:53:03 -07004867#define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
Wanpeng Li4d5422c2018-03-12 04:53:02 -07004868
4869Enabling this capability on a VM provides userspace with a way to no
4870longer intercept some instructions for improved latency in some
4871workloads, and is suggested when vCPUs are associated to dedicated
4872physical CPUs. More bits can be added in the future; userspace can
4873just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
4874all such vmexits.
4875
Wanpeng Licaa057a2018-03-12 04:53:03 -07004876Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
Wanpeng Li4d5422c2018-03-12 04:53:02 -07004877
Janosch Franka4499382018-07-13 11:28:31 +010048787.14 KVM_CAP_S390_HPAGE_1M
4879
4880Architectures: s390
4881Parameters: none
4882Returns: 0 on success, -EINVAL if hpage module parameter was not set
Janosch Frank40ebdb82018-08-01 11:48:28 +01004883 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
4884 flag set
Janosch Franka4499382018-07-13 11:28:31 +01004885
4886With this capability the KVM support for memory backing with 1m pages
4887through hugetlbfs can be enabled for a VM. After the capability is
4888enabled, cmma can't be enabled anymore and pfmfi and the storage key
4889interpretation are disabled. If cmma has already been enabled or the
4890hpage module parameter is not set to 1, -EINVAL is returned.
4891
4892While it is generally possible to create a huge page backed VM without
4893this capability, the VM will not be able to run.
4894
Jim Mattsonc4f55192018-10-16 14:29:24 -070048957.15 KVM_CAP_MSR_PLATFORM_INFO
Drew Schmitt6fbbde92018-08-20 10:32:15 -07004896
4897Architectures: x86
4898Parameters: args[0] whether feature should be enabled or not
4899
4900With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
4901a #GP would be raised when the guest tries to access. Currently, this
4902capability does not enable write permissions of this MSR for the guest.
4903
Paul Mackerrasaa069a92018-09-21 20:02:01 +100049047.16 KVM_CAP_PPC_NESTED_HV
4905
4906Architectures: ppc
4907Parameters: none
4908Returns: 0 on success, -EINVAL when the implementation doesn't support
4909 nested-HV virtualization.
4910
4911HV-KVM on POWER9 and later systems allows for "nested-HV"
4912virtualization, which provides a way for a guest VM to run guests that
4913can run using the CPU's supervisor mode (privileged non-hypervisor
4914state). Enabling this capability on a VM depends on the CPU having
4915the necessary functionality and on the facility being enabled with a
4916kvm-hv module parameter.
4917
Jim Mattsonc4f55192018-10-16 14:29:24 -070049187.17 KVM_CAP_EXCEPTION_PAYLOAD
4919
4920Architectures: x86
4921Parameters: args[0] whether feature should be enabled or not
4922
4923With this capability enabled, CR2 will not be modified prior to the
4924emulated VM-exit when L1 intercepts a #PF exception that occurs in
4925L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
4926the emulated VM-exit when L1 intercepts a #DB exception that occurs in
4927L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
4928#DB) exception for L2, exception.has_payload will be set and the
4929faulting address (or the new DR6 bits*) will be reported in the
4930exception_payload field. Similarly, when userspace injects a #PF (or
4931#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
4932exception.has_payload and to put the faulting address (or the new DR6
4933bits*) in the exception_payload field.
4934
4935This capability also enables exception.pending in struct
4936kvm_vcpu_events, which allows userspace to distinguish between pending
4937and injected exceptions.
4938
4939
4940* For the new DR6 bits, note that bit 16 is set iff the #DB exception
4941 will clear DR6.RTM.
4942
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020049437.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
4944
4945Architectures: all
4946Parameters: args[0] whether feature should be enabled or not
4947
4948With this capability enabled, KVM_GET_DIRTY_LOG will not automatically
4949clear and write-protect all pages that are returned as dirty.
4950Rather, userspace will have to do this operation separately using
4951KVM_CLEAR_DIRTY_LOG.
4952
4953At the cost of a slightly more complicated operation, this provides better
4954scalability and responsiveness for two reasons. First,
4955KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
4956than requiring to sync a full memslot; this ensures that KVM does not
4957take spinlocks for an extended period of time. Second, in some cases a
4958large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
4959userspace actually using the data in the page. Pages can be modified
4960during this time, which is inefficint for both the guest and userspace:
4961the guest will incur a higher penalty due to write protection faults,
4962while userspace can see false reports of dirty pages. Manual reprotection
4963helps reducing this time, improving guest performance and reducing the
4964number of dirty log false positives.
4965
4966
Michael Ellermane928e9c2015-03-20 20:39:41 +110049678. Other capabilities.
4968----------------------
4969
4970This section lists capabilities that give information about other
4971features of the KVM implementation.
4972
49738.1 KVM_CAP_PPC_HWRNG
4974
4975Architectures: ppc
4976
4977This capability, if KVM_CHECK_EXTENSION indicates that it is
4978available, means that that the kernel has an implementation of the
4979H_RANDOM hypercall backed by a hardware random-number generator.
4980If present, the kernel H_RANDOM handler can be enabled for guest use
4981with the KVM_CAP_PPC_ENABLE_HCALL capability.
Andrey Smetanin5c9194122015-11-10 15:36:34 +03004982
49838.2 KVM_CAP_HYPERV_SYNIC
4984
4985Architectures: x86
4986This capability, if KVM_CHECK_EXTENSION indicates that it is
4987available, means that that the kernel has an implementation of the
4988Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
4989used to support Windows Hyper-V based guest paravirt drivers(VMBus).
4990
4991In order to use SynIC, it has to be activated by setting this
4992capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
4993will disable the use of APIC hardware virtualization even if supported
4994by the CPU, as it's incompatible with SynIC auto-EOI behavior.
Paul Mackerrasc9270132017-01-30 21:21:41 +11004995
49968.3 KVM_CAP_PPC_RADIX_MMU
4997
4998Architectures: ppc
4999
5000This capability, if KVM_CHECK_EXTENSION indicates that it is
5001available, means that that the kernel can support guests using the
5002radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
5003processor).
5004
50058.4 KVM_CAP_PPC_HASH_MMU_V3
5006
5007Architectures: ppc
5008
5009This capability, if KVM_CHECK_EXTENSION indicates that it is
5010available, means that that the kernel can support guests using the
5011hashed page table MMU defined in Power ISA V3.00 (as implemented in
5012the POWER9 processor), including in-memory segment tables.
James Hogana8a3c422017-03-14 10:15:19 +00005013
50148.5 KVM_CAP_MIPS_VZ
5015
5016Architectures: mips
5017
5018This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
5019it is available, means that full hardware assisted virtualization capabilities
5020of the hardware are available for use through KVM. An appropriate
5021KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
5022utilises it.
5023
5024If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
5025available, it means that the VM is using full hardware assisted virtualization
5026capabilities of the hardware. This is useful to check after creating a VM with
5027KVM_VM_MIPS_DEFAULT.
5028
5029The value returned by KVM_CHECK_EXTENSION should be compared against known
5030values (see below). All other values are reserved. This is to allow for the
5031possibility of other hardware assisted virtualization implementations which
5032may be incompatible with the MIPS VZ ASE.
5033
5034 0: The trap & emulate implementation is in use to run guest code in user
5035 mode. Guest virtual memory segments are rearranged to fit the guest in the
5036 user mode address space.
5037
5038 1: The MIPS VZ ASE is in use, providing full hardware assisted
5039 virtualization, including standard guest virtual memory segments.
5040
50418.6 KVM_CAP_MIPS_TE
5042
5043Architectures: mips
5044
5045This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
5046it is available, means that the trap & emulate implementation is available to
5047run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
5048assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
5049to KVM_CREATE_VM to create a VM which utilises it.
5050
5051If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
5052available, it means that the VM is using trap & emulate.
James Hogan578fd612017-03-14 10:15:20 +00005053
50548.7 KVM_CAP_MIPS_64BIT
5055
5056Architectures: mips
5057
5058This capability indicates the supported architecture type of the guest, i.e. the
5059supported register and address width.
5060
5061The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
5062kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
5063be checked specifically against known values (see below). All other values are
5064reserved.
5065
5066 0: MIPS32 or microMIPS32.
5067 Both registers and addresses are 32-bits wide.
5068 It will only be possible to run 32-bit guest code.
5069
5070 1: MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
5071 Registers are 64-bits wide, but addresses are 32-bits wide.
5072 64-bit guest code may run but cannot access MIPS64 memory segments.
5073 It will also be possible to run 32-bit guest code.
5074
5075 2: MIPS64 or microMIPS64 with access to all address segments.
5076 Both registers and addresses are 64-bits wide.
5077 It will be possible to run 64-bit or 32-bit guest code.
Michael S. Tsirkin668fffa2017-04-21 12:27:17 +02005078
Paolo Bonzinic24a7be2017-04-27 17:33:14 +020050798.9 KVM_CAP_ARM_USER_IRQ
Alexander Graf3fe17e62016-09-27 21:08:05 +02005080
5081Architectures: arm, arm64
5082This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
5083that if userspace creates a VM without an in-kernel interrupt controller, it
5084will be notified of changes to the output level of in-kernel emulated devices,
5085which can generate virtual interrupts, presented to the VM.
5086For such VMs, on every return to userspace, the kernel
5087updates the vcpu's run->s.regs.device_irq_level field to represent the actual
5088output level of the device.
5089
5090Whenever kvm detects a change in the device output level, kvm guarantees at
5091least one return to userspace before running the VM. This exit could either
5092be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
5093userspace can always sample the device output level and re-compute the state of
5094the userspace interrupt controller. Userspace should always check the state
5095of run->s.regs.device_irq_level on every kvm exit.
5096The value in run->s.regs.device_irq_level can represent both level and edge
5097triggered interrupt signals, depending on the device. Edge triggered interrupt
5098signals will exit to userspace with the bit in run->s.regs.device_irq_level
5099set exactly once per edge signal.
5100
5101The field run->s.regs.device_irq_level is available independent of
5102run->kvm_valid_regs or run->kvm_dirty_regs bits.
5103
5104If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
5105number larger than 0 indicating the version of this capability is implemented
5106and thereby which bits in in run->s.regs.device_irq_level can signal values.
5107
5108Currently the following bits are defined for the device_irq_level bitmap:
5109
5110 KVM_CAP_ARM_USER_IRQ >= 1:
5111
5112 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
5113 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
5114 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
5115
5116Future versions of kvm may implement additional events. These will get
5117indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
5118listed above.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10005119
51208.10 KVM_CAP_PPC_SMT_POSSIBLE
5121
5122Architectures: ppc
5123
5124Querying this capability returns a bitmap indicating the possible
5125virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
5126(counting from the right) is set, then a virtual SMT mode of 2^N is
5127available.
Roman Kaganefc479e2017-06-22 16:51:01 +03005128
51298.11 KVM_CAP_HYPERV_SYNIC2
5130
5131Architectures: x86
5132
5133This capability enables a newer version of Hyper-V Synthetic interrupt
5134controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
5135doesn't clear SynIC message and event flags pages when they are enabled by
5136writing to the respective MSRs.
Roman Kagand3457c82017-07-14 17:13:20 +03005137
51388.12 KVM_CAP_HYPERV_VP_INDEX
5139
5140Architectures: x86
5141
5142This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
5143value is used to denote the target vcpu for a SynIC interrupt. For
5144compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this
5145capability is absent, userspace can still query this msr's value.
Christian Borntraegerda9a1442017-11-09 10:00:45 +01005146
51478.13 KVM_CAP_S390_AIS_MIGRATION
5148
5149Architectures: s390
5150Parameters: none
5151
5152This capability indicates if the flic device will be able to get/set the
5153AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
5154to discover this without having to create a flic device.
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00005155
51568.14 KVM_CAP_S390_PSW
5157
5158Architectures: s390
5159
5160This capability indicates that the PSW is exposed via the kvm_run structure.
5161
51628.15 KVM_CAP_S390_GMAP
5163
5164Architectures: s390
5165
5166This capability indicates that the user space memory used as guest mapping can
5167be anywhere in the user memory address space, as long as the memory slots are
5168aligned and sized to a segment (1MB) boundary.
5169
51708.16 KVM_CAP_S390_COW
5171
5172Architectures: s390
5173
5174This capability indicates that the user space memory used as guest mapping can
5175use copy-on-write semantics as well as dirty pages tracking via read-only page
5176tables.
5177
51788.17 KVM_CAP_S390_BPB
5179
5180Architectures: s390
5181
5182This capability indicates that kvm will implement the interfaces to handle
5183reset, migration and nested KVM for branch prediction blocking. The stfle
5184facility 82 should not be provided to the guest without this capability.
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02005185
Vitaly Kuznetsov2ddc6492018-06-22 16:56:14 +020051868.18 KVM_CAP_HYPERV_TLBFLUSH
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02005187
5188Architectures: x86
5189
5190This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
5191hypercalls:
5192HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
5193HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01005194
Dongjiu Geng688e0582018-08-20 17:39:25 -040051958.19 KVM_CAP_ARM_INJECT_SERROR_ESR
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01005196
5197Architectures: arm, arm64
5198
5199This capability indicates that userspace can specify (via the
5200KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
5201takes a virtual SError interrupt exception.
5202If KVM advertises this capability, userspace can only specify the ISS field for
5203the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
5204CPU when the exception is taken. If this virtual SError is taken to EL1 using
5205AArch64, this value will be reported in the ISS field of ESR_ELx.
5206
5207See KVM_CAP_VCPU_EVENTS for more details.
Vitaly Kuznetsov214ff832018-09-26 19:02:59 +020052088.20 KVM_CAP_HYPERV_SEND_IPI
5209
5210Architectures: x86
5211
5212This capability indicates that KVM supports paravirtualized Hyper-V IPI send
5213hypercalls:
5214HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.