blob: 5d8db4922df6a843d2d6cbd4191dd8a282805d54 [file] [log] [blame]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001.. SPDX-License-Identifier: GPL-2.0
2
3===================================================================
Avi Kivity9c1b96e2009-06-09 12:37:58 +03004The Definitive KVM (Kernel-based Virtual Machine) API Documentation
5===================================================================
6
71. General description
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01008======================
Avi Kivity9c1b96e2009-06-09 12:37:58 +03009
10The kvm API is a set of ioctls that are issued to control various aspects
Wainer dos Santos Moschetta80b10aa2019-11-29 13:17:30 -050011of a virtual machine. The ioctls belong to the following classes:
Avi Kivity9c1b96e2009-06-09 12:37:58 +030012
13 - System ioctls: These query and set global attributes which affect the
14 whole kvm subsystem. In addition a system ioctl is used to create
Sean Christopherson5e124902019-02-15 12:48:38 -080015 virtual machines.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030016
17 - VM ioctls: These query and set attributes that affect an entire virtual
18 machine, for example memory layout. In addition a VM ioctl is used to
Sean Christophersonddba9182019-02-15 12:48:39 -080019 create virtual cpus (vcpus) and devices.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030020
Sean Christopherson5e124902019-02-15 12:48:38 -080021 VM ioctls must be issued from the same process (address space) that was
22 used to create the VM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030023
24 - vcpu ioctls: These query and set attributes that control the operation
25 of a single virtual cpu.
26
Sean Christopherson5e124902019-02-15 12:48:38 -080027 vcpu ioctls should be issued from the same thread that was used to create
28 the vcpu, except for asynchronous vcpu ioctl that are marked as such in
29 the documentation. Otherwise, the first ioctl after switching threads
30 could see a performance impact.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030031
Sean Christophersonddba9182019-02-15 12:48:39 -080032 - device ioctls: These query and set attributes that control the operation
33 of a single device.
34
35 device ioctls must be issued from the same process (address space) that
36 was used to create the VM.
Jan Kiszka414fa982012-04-24 16:40:15 +020037
Wu Fengguang2044892d2009-12-24 09:04:16 +0800382. File descriptors
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010039===================
Avi Kivity9c1b96e2009-06-09 12:37:58 +030040
41The kvm API is centered around file descriptors. An initial
42open("/dev/kvm") obtains a handle to the kvm subsystem; this handle
43can be used to issue system ioctls. A KVM_CREATE_VM ioctl on this
Wu Fengguang2044892d2009-12-24 09:04:16 +080044handle will create a VM file descriptor which can be used to issue VM
Sean Christophersonddba9182019-02-15 12:48:39 -080045ioctls. A KVM_CREATE_VCPU or KVM_CREATE_DEVICE ioctl on a VM fd will
46create a virtual cpu or device and return a file descriptor pointing to
47the new resource. Finally, ioctls on a vcpu or device fd can be used
48to control the vcpu or device. For vcpus, this includes the important
49task of actually running guest code.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030050
51In general file descriptors can be migrated among processes by means
52of fork() and the SCM_RIGHTS facility of unix domain socket. These
53kinds of tricks are explicitly not supported by kvm. While they will
54not cause harm to the host, their actual behavior is not guaranteed by
Sean Christopherson5e124902019-02-15 12:48:38 -080055the API. See "General description" for details on the ioctl usage
56model that is supported by KVM.
Jan Kiszka414fa982012-04-24 16:40:15 +020057
Jonathan Neuschäferc44456f2021-03-01 22:47:21 +010058It is important to note that although VM ioctls may only be issued from
Sean Christophersoneca6be52019-02-15 12:48:40 -080059the process that created the VM, a VM's lifecycle is associated with its
60file descriptor, not its creator (process). In other words, the VM and
61its resources, *including the associated address space*, are not freed
62until the last reference to the VM's file descriptor has been released.
63For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
64not be freed until both the parent (original) process and its child have
65put their references to the VM's file descriptor.
66
67Because a VM's resources are not freed until the last reference to its
Randy Dunlap3747c5d2020-07-03 14:29:06 -070068file descriptor is released, creating additional references to a VM
Sean Christophersoneca6be52019-02-15 12:48:40 -080069via fork(), dup(), etc... without careful consideration is strongly
70discouraged and may have unwanted side effects, e.g. memory allocated
71by and on behalf of the VM's process may not be freed/unaccounted when
72the VM is shut down.
73
74
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300753. Extensions
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010076=============
Avi Kivity9c1b96e2009-06-09 12:37:58 +030077
78As of Linux 2.6.22, the KVM ABI has been stabilized: no backward
79incompatible change are allowed. However, there is an extension
80facility that allows backward-compatible extensions to the API to be
81queried and used.
82
Masanari Iidac9f3f2d2013-07-18 01:29:12 +090083The extension mechanism is not based on the Linux version number.
Avi Kivity9c1b96e2009-06-09 12:37:58 +030084Instead, kvm defines extension identifiers and a facility to query
85whether a particular extension identifier is available. If it is, a
86set of ioctls is available for application use.
87
Jan Kiszka414fa982012-04-24 16:40:15 +020088
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300894. API description
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010090==================
Avi Kivity9c1b96e2009-06-09 12:37:58 +030091
92This section describes ioctls that can be used to control kvm guests.
93For each ioctl, the following information is provided along with a
94description:
95
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010096 Capability:
97 which KVM extension provides this ioctl. Can be 'basic',
Avi Kivity9c1b96e2009-06-09 12:37:58 +030098 which means that is will be provided by any kernel that supports
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +030099 API version 12 (see section 4.1), a KVM_CAP_xyz constant, which
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300100 means availability needs to be checked with KVM_CHECK_EXTENSION
Michael S. Tsirkin7f05db62014-10-12 11:34:00 +0300101 (see section 4.4), or 'none' which means that while not all kernels
102 support this ioctl, there's no capability bit to check its
103 availability: for kernels that don't support the ioctl,
104 the ioctl returns -ENOTTY.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300105
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100106 Architectures:
107 which instruction set architectures provide this ioctl.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300108 x86 includes both i386 and x86_64.
109
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100110 Type:
111 system, vm, or vcpu.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300112
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100113 Parameters:
114 what parameters are accepted by the ioctl.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300115
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100116 Returns:
117 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300118 are not detailed, but errors with specific meanings are.
119
Jan Kiszka414fa982012-04-24 16:40:15 +0200120
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001214.1 KVM_GET_API_VERSION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100122-----------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300123
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100124:Capability: basic
125:Architectures: all
126:Type: system ioctl
127:Parameters: none
128:Returns: the constant KVM_API_VERSION (=12)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300129
130This identifies the API version as the stable kvm API. It is not
131expected that this number will change. However, Linux 2.6.20 and
1322.6.21 report earlier versions; these are not documented and not
133supported. Applications should refuse to run if KVM_GET_API_VERSION
134returns a value other than 12. If this check passes, all ioctls
135described as 'basic' will be available.
136
Jan Kiszka414fa982012-04-24 16:40:15 +0200137
Avi Kivity9c1b96e2009-06-09 12:37:58 +03001384.2 KVM_CREATE_VM
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100139-----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300140
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100141:Capability: basic
142:Architectures: all
143:Type: system ioctl
144:Parameters: machine type identifier (KVM_VM_*)
145:Returns: a VM fd that can be used to control the new virtual machine.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300146
Jann Hornbcb85c82017-04-24 11:16:49 +0200147The new VM has no virtual cpus and no memory.
James Hogana8a3c422017-03-14 10:15:19 +0000148You probably want to use 0 as machine type.
Carsten Ottee08b9632012-01-04 10:25:20 +0100149
150In order to create user controlled virtual machines on S390, check
151KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as
152privileged user (CAP_SYS_ADMIN).
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300153
James Hogana8a3c422017-03-14 10:15:19 +0000154To use hardware assisted virtualization on MIPS (VZ ASE) rather than
155the default trap & emulate implementation (which changes the virtual
156memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the
157flag KVM_VM_MIPS_VZ.
158
Jan Kiszka414fa982012-04-24 16:40:15 +0200159
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100160On arm64, the physical address size for a VM (IPA Size limit) is limited
161to 40bits by default. The limit can be configured if the host supports the
162extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use
163KVM_VM_TYPE_ARM_IPA_SIZE(IPA_Bits) to set the size in the machine type
164identifier, where IPA_Bits is the maximum width of any physical
165address used by the VM. The IPA_Bits is encoded in bits[7-0] of the
166machine type identifier.
167
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100168e.g, to configure a guest to use 48bit physical address size::
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100169
170 vm_fd = ioctl(dev_fd, KVM_CREATE_VM, KVM_VM_TYPE_ARM_IPA_SIZE(48));
171
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100172The requested size (IPA_Bits) must be:
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100173
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100174 == =========================================================
175 0 Implies default size, 40bits (for backward compatibility)
176 N Implies N bits, where N is a positive integer such that,
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100177 32 <= N <= Host_IPA_Limit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100178 == =========================================================
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100179
180Host_IPA_Limit is the maximum possible value for IPA_Bits on the host and
181is dependent on the CPU capability and the kernel configuration. The limit can
182be retrieved using KVM_CAP_ARM_VM_IPA_SIZE of the KVM_CHECK_EXTENSION
183ioctl() at run-time.
184
Marc Zyngier7d717552021-03-11 10:00:15 +0000185Creation of the VM will fail if the requested IPA size (whether it is
186implicit or explicit) is unsupported on the host.
187
Suzuki K Poulose233a7cb2018-09-26 17:32:54 +0100188Please note that configuring the IPA size does not affect the capability
189exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects
190size of the address translated by the stage2 level (guest physical to
191host physical address translations).
192
193
Tom Lendacky801e4592018-02-21 13:39:51 -06001944.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100195----------------------------------------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300196
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100197:Capability: basic, KVM_CAP_GET_MSR_FEATURES for KVM_GET_MSR_FEATURE_INDEX_LIST
198:Architectures: x86
199:Type: system ioctl
200:Parameters: struct kvm_msr_list (in/out)
201:Returns: 0 on success; -1 on error
202
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300203Errors:
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300204
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100205 ====== ============================================================
206 EFAULT the msr index list cannot be read from or written to
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +0100207 E2BIG the msr index list is too big to fit in the array specified by
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100208 the user.
209 ====== ============================================================
210
211::
212
213 struct kvm_msr_list {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300214 __u32 nmsrs; /* number of msrs in entries */
215 __u32 indices[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100216 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300217
Tom Lendacky801e4592018-02-21 13:39:51 -0600218The user fills in the size of the indices array in nmsrs, and in return
219kvm adjusts nmsrs to reflect the actual number of msrs and fills in the
220indices array with their numbers.
221
222KVM_GET_MSR_INDEX_LIST returns the guest msrs that are supported. The list
223varies by kvm version and host processor, but does not change otherwise.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300224
Avi Kivity2e2602c2010-07-07 14:09:39 +0300225Note: if kvm indicates supports MCE (KVM_CAP_MCE), then the MCE bank MSRs are
226not returned in the MSR list, as different vcpus can have a different number
227of banks, as set via the KVM_X86_SETUP_MCE ioctl.
228
Tom Lendacky801e4592018-02-21 13:39:51 -0600229KVM_GET_MSR_FEATURE_INDEX_LIST returns the list of MSRs that can be passed
230to the KVM_GET_MSRS system ioctl. This lets userspace probe host capabilities
231and processor features that are exposed via MSRs (e.g., VMX capabilities).
232This list also varies by kvm version and host processor, but does not change
233otherwise.
234
Jan Kiszka414fa982012-04-24 16:40:15 +0200235
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002364.4 KVM_CHECK_EXTENSION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100237-----------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300238
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100239:Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
240:Architectures: all
241:Type: system ioctl, vm ioctl
242:Parameters: extension identifier (KVM_CAP_*)
243:Returns: 0 if unsupported; 1 (or some other positive integer) if supported
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300244
245The API allows the application to query about extensions to the core
246kvm API. Userspace passes an extension identifier (an integer) and
247receives an integer that describes the extension availability.
248Generally 0 means no and 1 means yes, but some extensions may report
249additional information in the integer return value.
250
Alexander Graf92b591a2014-07-14 18:33:08 +0200251Based on their initialization different VMs may have different capabilities.
252It is thus encouraged to use the vm ioctl to query for capabilities (available
253with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
Jan Kiszka414fa982012-04-24 16:40:15 +0200254
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002554.5 KVM_GET_VCPU_MMAP_SIZE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100256--------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300257
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100258:Capability: basic
259:Architectures: all
260:Type: system ioctl
261:Parameters: none
262:Returns: size of vcpu mmap area, in bytes
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300263
264The KVM_RUN ioctl (cf.) communicates with userspace via a shared
265memory region. This ioctl returns the size of that region. See the
266KVM_RUN documentation for details.
267
Peter Xufb04a1e2020-09-30 21:22:22 -0400268Besides the size of the KVM_RUN communication region, other areas of
269the VCPU file descriptor can be mmap-ed, including:
270
271- if KVM_CAP_COALESCED_MMIO is available, a page at
272 KVM_COALESCED_MMIO_PAGE_OFFSET * PAGE_SIZE; for historical reasons,
273 this page is included in the result of KVM_GET_VCPU_MMAP_SIZE.
274 KVM_CAP_COALESCED_MMIO is not documented yet.
275
276- if KVM_CAP_DIRTY_LOG_RING is available, a number of pages at
277 KVM_DIRTY_LOG_PAGE_OFFSET * PAGE_SIZE. For more information on
278 KVM_CAP_DIRTY_LOG_RING, see section 8.3.
279
Jan Kiszka414fa982012-04-24 16:40:15 +0200280
Avi Kivity9c1b96e2009-06-09 12:37:58 +03002814.6 KVM_SET_MEMORY_REGION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100282-------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300283
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100284:Capability: basic
285:Architectures: all
286:Type: vm ioctl
287:Parameters: struct kvm_memory_region (in)
288:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300289
Avi Kivityb74a07b2010-06-21 11:48:05 +0300290This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300291
Jan Kiszka414fa982012-04-24 16:40:15 +0200292
Paul Bolle68ba6972011-02-15 00:05:59 +01002934.7 KVM_CREATE_VCPU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100294-------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300295
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100296:Capability: basic
297:Architectures: all
298:Type: vm ioctl
299:Parameters: vcpu id (apic id on x86)
300:Returns: vcpu fd on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300301
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200302This API adds a vcpu to a virtual machine. No more than max_vcpus may be added.
303The vcpu id is an integer in the range [0, max_vcpu_id).
Sasha Levin8c3ba332011-07-18 17:17:15 +0300304
305The recommended max_vcpus value can be retrieved using the KVM_CAP_NR_VCPUS of
306the KVM_CHECK_EXTENSION ioctl() at run-time.
307The maximum possible value for max_vcpus can be retrieved using the
308KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
309
Pekka Enberg76d25402011-05-09 22:48:54 +0300310If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
311cpus max.
Sasha Levin8c3ba332011-07-18 17:17:15 +0300312If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
313same as the value returned from KVM_CAP_NR_VCPUS.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300314
Greg Kurz0b1b1df2016-05-09 18:13:37 +0200315The maximum possible value for max_vcpu_id can be retrieved using the
316KVM_CAP_MAX_VCPU_ID of the KVM_CHECK_EXTENSION ioctl() at run-time.
317
318If the KVM_CAP_MAX_VCPU_ID does not exist, you should assume that max_vcpu_id
319is the same as the value returned from KVM_CAP_MAX_VCPUS.
320
Paul Mackerras371fefd2011-06-29 00:23:08 +0000321On powerpc using book3s_hv mode, the vcpus are mapped onto virtual
322threads in one or more virtual CPU cores. (This is because the
323hardware requires all the hardware threads in a CPU core to be in the
324same partition.) The KVM_CAP_PPC_SMT capability indicates the number
325of vcpus per virtual core (vcore). The vcore id is obtained by
326dividing the vcpu id by the number of vcpus per vcore. The vcpus in a
327given vcore will always be in the same physical core as each other
328(though that might be a different physical core from time to time).
329Userspace can control the threading (SMT) mode of the guest by its
330allocation of vcpu ids. For example, if userspace wants
331single-threaded guest vcpus, it should make all vcpu ids be a multiple
332of the number of vcpus per vcore.
333
Carsten Otte5b1c1492012-01-04 10:25:23 +0100334For virtual cpus that have been created with S390 user controlled virtual
335machines, the resulting vcpu fd can be memory mapped at page offset
336KVM_S390_SIE_PAGE_OFFSET in order to obtain a memory map of the virtual
337cpu's hardware control block.
338
Jan Kiszka414fa982012-04-24 16:40:15 +0200339
Paul Bolle68ba6972011-02-15 00:05:59 +01003404.8 KVM_GET_DIRTY_LOG (vm ioctl)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100341--------------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300342
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100343:Capability: basic
344:Architectures: all
345:Type: vm ioctl
346:Parameters: struct kvm_dirty_log (in/out)
347:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300348
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100349::
350
351 /* for KVM_GET_DIRTY_LOG */
352 struct kvm_dirty_log {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300353 __u32 slot;
354 __u32 padding;
355 union {
356 void __user *dirty_bitmap; /* one bit per page */
357 __u64 padding;
358 };
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100359 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300360
361Given a memory slot, return a bitmap containing any pages dirtied
362since the last call to this ioctl. Bit 0 is the first page in the
363memory slot. Ensure the entire structure is cleared to avoid padding
364issues.
365
Zenghui Yu01ead842020-12-08 12:34:39 +0800366If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
367the address space for which you want to return the dirty bitmap. See
368KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
Paolo Bonzinif481b062015-05-17 17:30:37 +0200369
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +0200370The bits in the dirty bitmap are cleared before the ioctl returns, unless
Peter Xud7547c52019-05-08 17:15:47 +0800371KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information,
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +0200372see the description of the capability.
Jan Kiszka414fa982012-04-24 16:40:15 +0200373
Paul Bolle68ba6972011-02-15 00:05:59 +01003744.9 KVM_SET_MEMORY_ALIAS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100375------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300376
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100377:Capability: basic
378:Architectures: x86
379:Type: vm ioctl
380:Parameters: struct kvm_memory_alias (in)
381:Returns: 0 (success), -1 (error)
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300382
Avi Kivitya1f4d3952010-06-21 11:44:20 +0300383This ioctl is obsolete and has been removed.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300384
Jan Kiszka414fa982012-04-24 16:40:15 +0200385
Paul Bolle68ba6972011-02-15 00:05:59 +01003864.10 KVM_RUN
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100387------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300388
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100389:Capability: basic
390:Architectures: all
391:Type: vcpu ioctl
392:Parameters: none
393:Returns: 0 on success, -1 on error
394
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300395Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100396
Alexandru Elisei3557ae12020-12-01 15:01:53 +0000397 ======= ==============================================================
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100398 EINTR an unmasked signal is pending
Alexandru Elisei3557ae12020-12-01 15:01:53 +0000399 ENOEXEC the vcpu hasn't been initialized or the guest tried to execute
400 instructions from device memory (arm64)
401 ENOSYS data abort outside memslots with no syndrome info and
402 KVM_CAP_ARM_NISV_TO_USER not enabled (arm64)
403 EPERM SVE feature set but not finalized (arm64)
404 ======= ==============================================================
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300405
406This ioctl is used to run a guest virtual cpu. While there are no
407explicit parameters, there is an implicit parameter block that can be
408obtained by mmap()ing the vcpu fd at offset 0, with the size given by
409KVM_GET_VCPU_MMAP_SIZE. The parameter block is formatted as a 'struct
410kvm_run' (see below).
411
Jan Kiszka414fa982012-04-24 16:40:15 +0200412
Paul Bolle68ba6972011-02-15 00:05:59 +01004134.11 KVM_GET_REGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100414-----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300415
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100416:Capability: basic
417:Architectures: all except ARM, arm64
418:Type: vcpu ioctl
419:Parameters: struct kvm_regs (out)
420:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300421
422Reads the general purpose registers from the vcpu.
423
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100424::
425
426 /* x86 */
427 struct kvm_regs {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300428 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
429 __u64 rax, rbx, rcx, rdx;
430 __u64 rsi, rdi, rsp, rbp;
431 __u64 r8, r9, r10, r11;
432 __u64 r12, r13, r14, r15;
433 __u64 rip, rflags;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100434 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300435
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100436 /* mips */
437 struct kvm_regs {
James Hoganc2d2c212014-07-04 15:11:35 +0100438 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
439 __u64 gpr[32];
440 __u64 hi;
441 __u64 lo;
442 __u64 pc;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100443 };
James Hoganc2d2c212014-07-04 15:11:35 +0100444
Jan Kiszka414fa982012-04-24 16:40:15 +0200445
Paul Bolle68ba6972011-02-15 00:05:59 +01004464.12 KVM_SET_REGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100447-----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300448
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100449:Capability: basic
450:Architectures: all except ARM, arm64
451:Type: vcpu ioctl
452:Parameters: struct kvm_regs (in)
453:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300454
455Writes the general purpose registers into the vcpu.
456
457See KVM_GET_REGS for the data structure.
458
Jan Kiszka414fa982012-04-24 16:40:15 +0200459
Paul Bolle68ba6972011-02-15 00:05:59 +01004604.13 KVM_GET_SREGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100461------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300462
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100463:Capability: basic
464:Architectures: x86, ppc
465:Type: vcpu ioctl
466:Parameters: struct kvm_sregs (out)
467:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300468
469Reads special registers from the vcpu.
470
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100471::
472
473 /* x86 */
474 struct kvm_sregs {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300475 struct kvm_segment cs, ds, es, fs, gs, ss;
476 struct kvm_segment tr, ldt;
477 struct kvm_dtable gdt, idt;
478 __u64 cr0, cr2, cr3, cr4, cr8;
479 __u64 efer;
480 __u64 apic_base;
481 __u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100482 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300483
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100484 /* ppc -- see arch/powerpc/include/uapi/asm/kvm.h */
Scott Wood5ce941e2011-04-27 17:24:21 -0500485
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300486interrupt_bitmap is a bitmap of pending external interrupts. At most
487one bit may be set. This interrupt has been acknowledged by the APIC
488but not yet injected into the cpu core.
489
Jan Kiszka414fa982012-04-24 16:40:15 +0200490
Paul Bolle68ba6972011-02-15 00:05:59 +01004914.14 KVM_SET_SREGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100492------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300493
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100494:Capability: basic
495:Architectures: x86, ppc
496:Type: vcpu ioctl
497:Parameters: struct kvm_sregs (in)
498:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300499
500Writes special registers into the vcpu. See KVM_GET_SREGS for the
501data structures.
502
Jan Kiszka414fa982012-04-24 16:40:15 +0200503
Paul Bolle68ba6972011-02-15 00:05:59 +01005044.15 KVM_TRANSLATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100505------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300506
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100507:Capability: basic
508:Architectures: x86
509:Type: vcpu ioctl
510:Parameters: struct kvm_translation (in/out)
511:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300512
513Translates a virtual address according to the vcpu's current address
514translation mode.
515
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100516::
517
518 struct kvm_translation {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300519 /* in */
520 __u64 linear_address;
521
522 /* out */
523 __u64 physical_address;
524 __u8 valid;
525 __u8 writeable;
526 __u8 usermode;
527 __u8 pad[5];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100528 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300529
Jan Kiszka414fa982012-04-24 16:40:15 +0200530
Paul Bolle68ba6972011-02-15 00:05:59 +01005314.16 KVM_INTERRUPT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100532------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300533
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100534:Capability: basic
535:Architectures: x86, ppc, mips
536:Type: vcpu ioctl
537:Parameters: struct kvm_interrupt (in)
538:Returns: 0 on success, negative on failure.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300539
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200540Queues a hardware interrupt vector to be injected.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300541
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100542::
543
544 /* for KVM_INTERRUPT */
545 struct kvm_interrupt {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300546 /* in */
547 __u32 irq;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100548 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300549
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200550X86:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100551^^^^
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200552
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100553:Returns:
554
555 ========= ===================================
556 0 on success,
557 -EEXIST if an interrupt is already enqueued
Randy Dunlap3747c5d2020-07-03 14:29:06 -0700558 -EINVAL the irq number is invalid
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100559 -ENXIO if the PIC is in the kernel
560 -EFAULT if the pointer is invalid
561 ========= ===================================
Steve Rutherford1c1a9ce2015-07-30 11:27:16 +0200562
563Note 'irq' is an interrupt vector, not an interrupt pin or line. This
564ioctl is useful if the in-kernel PIC is not used.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300565
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200566PPC:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100567^^^^
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200568
569Queues an external interrupt to be injected. This ioctl is overleaded
570with 3 different irq values:
571
572a) KVM_INTERRUPT_SET
573
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100574 This injects an edge type external interrupt into the guest once it's ready
575 to receive interrupts. When injected, the interrupt is done.
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200576
577b) KVM_INTERRUPT_UNSET
578
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100579 This unsets any pending interrupt.
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200580
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100581 Only available with KVM_CAP_PPC_UNSET_IRQ.
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200582
583c) KVM_INTERRUPT_SET_LEVEL
584
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100585 This injects a level type external interrupt into the guest context. The
586 interrupt stays pending until a specific ioctl with KVM_INTERRUPT_UNSET
587 is triggered.
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200588
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100589 Only available with KVM_CAP_PPC_IRQ_LEVEL.
Alexander Graf6f7a2bd2010-08-31 02:03:32 +0200590
591Note that any value for 'irq' other than the ones stated above is invalid
592and incurs unexpected behavior.
593
Sean Christopherson5e124902019-02-15 12:48:38 -0800594This is an asynchronous vcpu ioctl and can be invoked from any thread.
595
James Hoganc2d2c212014-07-04 15:11:35 +0100596MIPS:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100597^^^^^
James Hoganc2d2c212014-07-04 15:11:35 +0100598
599Queues an external interrupt to be injected into the virtual CPU. A negative
600interrupt number dequeues the interrupt.
601
Sean Christopherson5e124902019-02-15 12:48:38 -0800602This is an asynchronous vcpu ioctl and can be invoked from any thread.
603
Jan Kiszka414fa982012-04-24 16:40:15 +0200604
Paul Bolle68ba6972011-02-15 00:05:59 +01006054.17 KVM_DEBUG_GUEST
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100606--------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300607
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100608:Capability: basic
609:Architectures: none
610:Type: vcpu ioctl
611:Parameters: none)
612:Returns: -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300613
614Support for this has been removed. Use KVM_SET_GUEST_DEBUG instead.
615
Jan Kiszka414fa982012-04-24 16:40:15 +0200616
Paul Bolle68ba6972011-02-15 00:05:59 +01006174.18 KVM_GET_MSRS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100618-----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300619
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100620:Capability: basic (vcpu), KVM_CAP_GET_MSR_FEATURES (system)
621:Architectures: x86
622:Type: system ioctl, vcpu ioctl
623:Parameters: struct kvm_msrs (in/out)
624:Returns: number of msrs successfully returned;
625 -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300626
Tom Lendacky801e4592018-02-21 13:39:51 -0600627When used as a system ioctl:
628Reads the values of MSR-based features that are available for the VM. This
629is similar to KVM_GET_SUPPORTED_CPUID, but it returns MSR indices and values.
630The list of msr-based features can be obtained using KVM_GET_MSR_FEATURE_INDEX_LIST
631in a system ioctl.
632
633When used as a vcpu ioctl:
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300634Reads model-specific registers from the vcpu. Supported msr indices can
Tom Lendacky801e4592018-02-21 13:39:51 -0600635be obtained using KVM_GET_MSR_INDEX_LIST in a system ioctl.
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300636
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100637::
638
639 struct kvm_msrs {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300640 __u32 nmsrs; /* number of msrs in entries */
641 __u32 pad;
642
643 struct kvm_msr_entry entries[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100644 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300645
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100646 struct kvm_msr_entry {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300647 __u32 index;
648 __u32 reserved;
649 __u64 data;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100650 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300651
652Application code should set the 'nmsrs' member (which indicates the
653size of the entries array) and the 'index' member of each array entry.
654kvm will fill in the 'data' member.
655
Jan Kiszka414fa982012-04-24 16:40:15 +0200656
Paul Bolle68ba6972011-02-15 00:05:59 +01006574.19 KVM_SET_MSRS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100658-----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300659
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100660:Capability: basic
661:Architectures: x86
662:Type: vcpu ioctl
663:Parameters: struct kvm_msrs (in)
664:Returns: number of msrs successfully set (see below), -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300665
666Writes model-specific registers to the vcpu. See KVM_GET_MSRS for the
667data structures.
668
669Application code should set the 'nmsrs' member (which indicates the
670size of the entries array), and the 'index' and 'data' members of each
671array entry.
672
Xiaoyao Lib274a292019-09-05 08:57:37 +0800673It tries to set the MSRs in array entries[] one by one. If setting an MSR
674fails, e.g., due to setting reserved bits, the MSR isn't supported/emulated
675by KVM, etc..., it stops processing the MSR list and returns the number of
676MSRs that have been set successfully.
677
Jan Kiszka414fa982012-04-24 16:40:15 +0200678
Paul Bolle68ba6972011-02-15 00:05:59 +01006794.20 KVM_SET_CPUID
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100680------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300681
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100682:Capability: basic
683:Architectures: x86
684:Type: vcpu ioctl
685:Parameters: struct kvm_cpuid (in)
686:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300687
688Defines the vcpu responses to the cpuid instruction. Applications
689should use the KVM_SET_CPUID2 ioctl if available.
690
Sean Christopherson63f5a192021-06-22 10:56:52 -0700691Caveat emptor:
692 - If this IOCTL fails, KVM gives no guarantees that previous valid CPUID
693 configuration (if there is) is not corrupted. Userspace can get a copy
694 of the resulting CPUID configuration through KVM_GET_CPUID2 in case.
695 - Using KVM_SET_CPUID{,2} after KVM_RUN, i.e. changing the guest vCPU model
696 after running the guest, may cause guest instability.
697 - Using heterogeneous CPUID configurations, modulo APIC IDs, topology, etc...
698 may cause guest instability.
Xiaoyao Li18964092020-07-08 14:50:47 +0800699
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100700::
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300701
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100702 struct kvm_cpuid_entry {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300703 __u32 function;
704 __u32 eax;
705 __u32 ebx;
706 __u32 ecx;
707 __u32 edx;
708 __u32 padding;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100709 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300710
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100711 /* for KVM_SET_CPUID */
712 struct kvm_cpuid {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300713 __u32 nent;
714 __u32 padding;
715 struct kvm_cpuid_entry entries[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100716 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300717
Jan Kiszka414fa982012-04-24 16:40:15 +0200718
Paul Bolle68ba6972011-02-15 00:05:59 +01007194.21 KVM_SET_SIGNAL_MASK
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100720------------------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300721
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100722:Capability: basic
723:Architectures: all
724:Type: vcpu ioctl
725:Parameters: struct kvm_signal_mask (in)
726:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300727
728Defines which signals are blocked during execution of KVM_RUN. This
729signal mask temporarily overrides the threads signal mask. Any
730unblocked signal received (except SIGKILL and SIGSTOP, which retain
731their traditional behaviour) will cause KVM_RUN to return with -EINTR.
732
733Note the signal will only be delivered if not blocked by the original
734signal mask.
735
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100736::
737
738 /* for KVM_SET_SIGNAL_MASK */
739 struct kvm_signal_mask {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300740 __u32 len;
741 __u8 sigset[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100742 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300743
Jan Kiszka414fa982012-04-24 16:40:15 +0200744
Paul Bolle68ba6972011-02-15 00:05:59 +01007454.22 KVM_GET_FPU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100746----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300747
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100748:Capability: basic
749:Architectures: x86
750:Type: vcpu ioctl
751:Parameters: struct kvm_fpu (out)
752:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300753
754Reads the floating point state from the vcpu.
755
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100756::
757
758 /* for KVM_GET_FPU and KVM_SET_FPU */
759 struct kvm_fpu {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300760 __u8 fpr[8][16];
761 __u16 fcw;
762 __u16 fsw;
763 __u8 ftwx; /* in fxsave format */
764 __u8 pad1;
765 __u16 last_opcode;
766 __u64 last_ip;
767 __u64 last_dp;
768 __u8 xmm[16][16];
769 __u32 mxcsr;
770 __u32 pad2;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100771 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300772
Jan Kiszka414fa982012-04-24 16:40:15 +0200773
Paul Bolle68ba6972011-02-15 00:05:59 +01007744.23 KVM_SET_FPU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100775----------------
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300776
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100777:Capability: basic
778:Architectures: x86
779:Type: vcpu ioctl
780:Parameters: struct kvm_fpu (in)
781:Returns: 0 on success, -1 on error
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300782
783Writes the floating point state to the vcpu.
784
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100785::
786
787 /* for KVM_GET_FPU and KVM_SET_FPU */
788 struct kvm_fpu {
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300789 __u8 fpr[8][16];
790 __u16 fcw;
791 __u16 fsw;
792 __u8 ftwx; /* in fxsave format */
793 __u8 pad1;
794 __u16 last_opcode;
795 __u64 last_ip;
796 __u64 last_dp;
797 __u8 xmm[16][16];
798 __u32 mxcsr;
799 __u32 pad2;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100800 };
Avi Kivity9c1b96e2009-06-09 12:37:58 +0300801
Jan Kiszka414fa982012-04-24 16:40:15 +0200802
Paul Bolle68ba6972011-02-15 00:05:59 +01008034.24 KVM_CREATE_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100804-----------------------
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300805
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100806:Capability: KVM_CAP_IRQCHIP, KVM_CAP_S390_IRQCHIP (s390)
807:Architectures: x86, ARM, arm64, s390
808:Type: vm ioctl
809:Parameters: none
810:Returns: 0 on success, -1 on error
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300811
Andre Przywaraac3d3732014-06-03 10:26:30 +0200812Creates an interrupt controller model in the kernel.
813On x86, creates a virtual ioapic, a virtual PIC (two PICs, nested), and sets up
814future vcpus to have a local APIC. IRQ routing for GSIs 0-15 is set to both
815PIC and IOAPIC; GSI 16-23 only go to the IOAPIC.
816On ARM/arm64, a GICv2 is created. Any other GIC versions require the usage of
817KVM_CREATE_DEVICE, which also supports creating a GICv2. Using
818KVM_CREATE_DEVICE is preferred over KVM_CREATE_IRQCHIP for GICv2.
819On s390, a dummy irq routing table is created.
Cornelia Huck84223592013-07-15 13:36:01 +0200820
821Note that on s390 the KVM_CAP_S390_IRQCHIP vm capability needs to be enabled
822before KVM_CREATE_IRQCHIP can be used.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300823
Jan Kiszka414fa982012-04-24 16:40:15 +0200824
Paul Bolle68ba6972011-02-15 00:05:59 +01008254.25 KVM_IRQ_LINE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100826-----------------
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300827
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100828:Capability: KVM_CAP_IRQCHIP
829:Architectures: x86, arm, arm64
830:Type: vm ioctl
831:Parameters: struct kvm_irq_level
832:Returns: 0 on success, -1 on error
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300833
834Sets the level of a GSI input to the interrupt controller model in the kernel.
Christoffer Dall86ce8532013-01-20 18:28:08 -0500835On some architectures it is required that an interrupt controller model has
836been previously created with KVM_CREATE_IRQCHIP. Note that edge-triggered
837interrupts require the level to be set to 1 and then back to 0.
838
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500839On real hardware, interrupt pins can be active-low or active-high. This
840does not matter for the level field of struct kvm_irq_level: 1 always
841means active (asserted), 0 means inactive (deasserted).
842
843x86 allows the operating system to program the interrupt polarity
844(active-low/active-high) for level-triggered interrupts, and KVM used
845to consider the polarity. However, due to bitrot in the handling of
846active-low interrupts, the above convention is now valid on x86 too.
847This is signaled by KVM_CAP_X86_IOAPIC_POLARITY_IGNORED. Userspace
848should not present interrupts to the guest as active-low unless this
849capability is present (or unless it is not using the in-kernel irqchip,
850of course).
851
852
Marc Zyngier379e04c72013-04-02 17:46:31 +0100853ARM/arm64 can signal an interrupt either at the CPU level, or at the
854in-kernel irqchip (GIC), and for in-kernel irqchip can tell the GIC to
855use PPIs designated for specific cpus. The irq field is interpreted
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100856like this::
Christoffer Dall86ce8532013-01-20 18:28:08 -0500857
Marc Zyngier92f35b72019-08-18 14:09:47 +0100858  bits: | 31 ... 28 | 27 ... 24 | 23 ... 16 | 15 ... 0 |
859 field: | vcpu2_index | irq_type | vcpu_index | irq_id |
Christoffer Dall86ce8532013-01-20 18:28:08 -0500860
861The irq_type field has the following values:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100862
863- irq_type[0]:
864 out-of-kernel GIC: irq_id 0 is IRQ, irq_id 1 is FIQ
865- irq_type[1]:
866 in-kernel GIC: SPI, irq_id between 32 and 1019 (incl.)
Christoffer Dall86ce8532013-01-20 18:28:08 -0500867 (the vcpu_index field is ignored)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100868- irq_type[2]:
869 in-kernel GIC: PPI, irq_id between 16 and 31 (incl.)
Christoffer Dall86ce8532013-01-20 18:28:08 -0500870
871(The irq_id field thus corresponds nicely to the IRQ ID in the ARM GIC specs)
872
Gabriel L. Somlo100943c2014-02-27 23:06:17 -0500873In both cases, level is used to assert/deassert the line.
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300874
Marc Zyngier92f35b72019-08-18 14:09:47 +0100875When KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 is supported, the target vcpu is
876identified as (256 * vcpu2_index + vcpu_index). Otherwise, vcpu2_index
877must be zero.
878
879Note that on arm/arm64, the KVM_CAP_IRQCHIP capability only conditions
880injection of interrupts for the in-kernel irqchip. KVM_IRQ_LINE can always
881be used for a userspace interrupt controller.
882
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100883::
884
885 struct kvm_irq_level {
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300886 union {
887 __u32 irq; /* GSI */
888 __s32 status; /* not used for KVM_IRQ_LEVEL */
889 };
890 __u32 level; /* 0 or 1 */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100891 };
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300892
Jan Kiszka414fa982012-04-24 16:40:15 +0200893
Paul Bolle68ba6972011-02-15 00:05:59 +01008944.26 KVM_GET_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100895--------------------
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300896
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100897:Capability: KVM_CAP_IRQCHIP
898:Architectures: x86
899:Type: vm ioctl
900:Parameters: struct kvm_irqchip (in/out)
901:Returns: 0 on success, -1 on error
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300902
903Reads the state of a kernel interrupt controller created with
904KVM_CREATE_IRQCHIP into a buffer provided by the caller.
905
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100906::
907
908 struct kvm_irqchip {
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300909 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
910 __u32 pad;
911 union {
912 char dummy[512]; /* reserving space */
913 struct kvm_pic_state pic;
914 struct kvm_ioapic_state ioapic;
915 } chip;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100916 };
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300917
Jan Kiszka414fa982012-04-24 16:40:15 +0200918
Paul Bolle68ba6972011-02-15 00:05:59 +01009194.27 KVM_SET_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100920--------------------
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300921
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100922:Capability: KVM_CAP_IRQCHIP
923:Architectures: x86
924:Type: vm ioctl
925:Parameters: struct kvm_irqchip (in)
926:Returns: 0 on success, -1 on error
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300927
928Sets the state of a kernel interrupt controller created with
929KVM_CREATE_IRQCHIP from a buffer provided by the caller.
930
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100931::
932
933 struct kvm_irqchip {
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300934 __u32 chip_id; /* 0 = PIC1, 1 = PIC2, 2 = IOAPIC */
935 __u32 pad;
936 union {
937 char dummy[512]; /* reserving space */
938 struct kvm_pic_state pic;
939 struct kvm_ioapic_state ioapic;
940 } chip;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100941 };
Avi Kivity5dadbfd2009-08-23 17:08:04 +0300942
Jan Kiszka414fa982012-04-24 16:40:15 +0200943
Paul Bolle68ba6972011-02-15 00:05:59 +01009444.28 KVM_XEN_HVM_CONFIG
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100945-----------------------
Ed Swierkffde22a2009-10-15 15:21:43 -0700946
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100947:Capability: KVM_CAP_XEN_HVM
948:Architectures: x86
949:Type: vm ioctl
950:Parameters: struct kvm_xen_hvm_config (in)
951:Returns: 0 on success, -1 on error
Ed Swierkffde22a2009-10-15 15:21:43 -0700952
953Sets the MSR that the Xen HVM guest uses to initialize its hypercall
954page, and provides the starting address and size of the hypercall
955blobs in userspace. When the guest writes the MSR, kvm copies one
956page of a blob (32- or 64-bit, depending on the vcpu mode) to guest
957memory.
958
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100959::
960
961 struct kvm_xen_hvm_config {
Ed Swierkffde22a2009-10-15 15:21:43 -0700962 __u32 flags;
963 __u32 msr;
964 __u64 blob_addr_32;
965 __u64 blob_addr_64;
966 __u8 blob_size_32;
967 __u8 blob_size_64;
968 __u8 pad2[30];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100969 };
Ed Swierkffde22a2009-10-15 15:21:43 -0700970
David Woodhousee1f68162020-12-04 09:03:56 +0000971If the KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL flag is returned from the
972KVM_CAP_XEN_HVM check, it may be set in the flags field of this ioctl.
973This requests KVM to generate the contents of the hypercall page
974automatically; hypercalls will be intercepted and passed to userspace
975through KVM_EXIT_XEN. In this case, all of the blob size and address
976fields must be zero.
977
978No other flags are currently valid in the struct kvm_xen_hvm_config.
Jan Kiszka414fa982012-04-24 16:40:15 +0200979
Paul Bolle68ba6972011-02-15 00:05:59 +01009804.29 KVM_GET_CLOCK
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100981------------------
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400982
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +0100983:Capability: KVM_CAP_ADJUST_CLOCK
984:Architectures: x86
985:Type: vm ioctl
986:Parameters: struct kvm_clock_data (out)
987:Returns: 0 on success, -1 on error
Glauber Costaafbcf7a2009-10-16 15:28:36 -0400988
989Gets the current timestamp of kvmclock as seen by the current guest. In
990conjunction with KVM_SET_CLOCK, it is used to ensure monotonicity on scenarios
991such as migration.
992
Paolo Bonzinie3fd9a92016-11-09 17:48:15 +0100993When KVM_CAP_ADJUST_CLOCK is passed to KVM_CHECK_EXTENSION, it returns the
994set of bits that KVM can return in struct kvm_clock_data's flag member.
995
996The only flag defined now is KVM_CLOCK_TSC_STABLE. If set, the returned
997value is the exact kvmclock value seen by all VCPUs at the instant
998when KVM_GET_CLOCK was called. If clear, the returned value is simply
999CLOCK_MONOTONIC plus a constant offset; the offset can be modified
1000with KVM_SET_CLOCK. KVM will try to make all VCPUs follow this clock,
1001but the exact value read by each VCPU could differ, because the host
1002TSC is not stable.
1003
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001004::
1005
1006 struct kvm_clock_data {
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001007 __u64 clock; /* kvmclock current value */
1008 __u32 flags;
1009 __u32 pad[9];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001010 };
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001011
Jan Kiszka414fa982012-04-24 16:40:15 +02001012
Paul Bolle68ba6972011-02-15 00:05:59 +010010134.30 KVM_SET_CLOCK
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001014------------------
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001015
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001016:Capability: KVM_CAP_ADJUST_CLOCK
1017:Architectures: x86
1018:Type: vm ioctl
1019:Parameters: struct kvm_clock_data (in)
1020:Returns: 0 on success, -1 on error
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001021
Wu Fengguang2044892d2009-12-24 09:04:16 +08001022Sets the current timestamp of kvmclock to the value specified in its parameter.
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001023In conjunction with KVM_GET_CLOCK, it is used to ensure monotonicity on scenarios
1024such as migration.
1025
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001026::
1027
1028 struct kvm_clock_data {
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001029 __u64 clock; /* kvmclock current value */
1030 __u32 flags;
1031 __u32 pad[9];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001032 };
Glauber Costaafbcf7a2009-10-16 15:28:36 -04001033
Jan Kiszka414fa982012-04-24 16:40:15 +02001034
Paul Bolle68ba6972011-02-15 00:05:59 +010010354.31 KVM_GET_VCPU_EVENTS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001036------------------------
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001037
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001038:Capability: KVM_CAP_VCPU_EVENTS
1039:Extended by: KVM_CAP_INTR_SHADOW
1040:Architectures: x86, arm, arm64
1041:Type: vcpu ioctl
1042:Parameters: struct kvm_vcpu_event (out)
1043:Returns: 0 on success, -1 on error
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001044
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001045X86:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001046^^^^
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001047
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001048Gets currently pending exceptions, interrupts, and NMIs as well as related
1049states of the vcpu.
1050
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001051::
1052
1053 struct kvm_vcpu_events {
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001054 struct {
1055 __u8 injected;
1056 __u8 nr;
1057 __u8 has_error_code;
Jim Mattson59073aa2018-10-16 14:29:20 -07001058 __u8 pending;
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001059 __u32 error_code;
1060 } exception;
1061 struct {
1062 __u8 injected;
1063 __u8 nr;
1064 __u8 soft;
Jan Kiszka48005f62010-02-19 19:38:07 +01001065 __u8 shadow;
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001066 } interrupt;
1067 struct {
1068 __u8 injected;
1069 __u8 pending;
1070 __u8 masked;
1071 __u8 pad;
1072 } nmi;
1073 __u32 sipi_vector;
Jan Kiszkadab4b912009-12-06 18:24:15 +01001074 __u32 flags;
Paolo Bonzinif0778252015-04-01 15:06:40 +02001075 struct {
1076 __u8 smm;
1077 __u8 pending;
1078 __u8 smm_inside_nmi;
1079 __u8 latched_init;
1080 } smi;
Jim Mattson59073aa2018-10-16 14:29:20 -07001081 __u8 reserved[27];
1082 __u8 exception_has_payload;
1083 __u64 exception_payload;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001084 };
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001085
Jim Mattson59073aa2018-10-16 14:29:20 -07001086The following bits are defined in the flags field:
Jan Kiszka48005f62010-02-19 19:38:07 +01001087
Jim Mattson59073aa2018-10-16 14:29:20 -07001088- KVM_VCPUEVENT_VALID_SHADOW may be set to signal that
Paolo Bonzinif0778252015-04-01 15:06:40 +02001089 interrupt.shadow contains a valid state.
1090
Jim Mattson59073aa2018-10-16 14:29:20 -07001091- KVM_VCPUEVENT_VALID_SMM may be set to signal that smi contains a
1092 valid state.
1093
1094- KVM_VCPUEVENT_VALID_PAYLOAD may be set to signal that the
1095 exception_has_payload, exception_payload, and exception.pending
1096 fields contain a valid state. This bit will be set whenever
1097 KVM_CAP_EXCEPTION_PAYLOAD is enabled.
Jan Kiszka414fa982012-04-24 16:40:15 +02001098
James Morseb0960b92018-07-19 16:24:25 +01001099ARM/ARM64:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001100^^^^^^^^^^
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001101
1102If the guest accesses a device that is being emulated by the host kernel in
1103such a way that a real device would generate a physical SError, KVM may make
1104a virtual SError pending for that VCPU. This system error interrupt remains
1105pending until the guest takes the exception by unmasking PSTATE.A.
1106
1107Running the VCPU may cause it to take a pending SError, or make an access that
1108causes an SError to become pending. The event's description is only valid while
1109the VPCU is not running.
1110
1111This API provides a way to read and write the pending 'event' state that is not
1112visible to the guest. To save, restore or migrate a VCPU the struct representing
1113the state can be read then written using this GET/SET API, along with the other
1114guest-visible registers. It is not possible to 'cancel' an SError that has been
1115made pending.
1116
1117A device being emulated in user-space may also wish to generate an SError. To do
1118this the events structure can be populated by user-space. The current state
1119should be read first, to ensure no existing SError is pending. If an existing
1120SError is pending, the architecture's 'Multiple SError interrupts' rules should
1121be followed. (2.5.3 of DDI0587.a "ARM Reliability, Availability, and
1122Serviceability (RAS) Specification").
1123
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01001124SError exceptions always have an ESR value. Some CPUs have the ability to
1125specify what the virtual SError's ESR value should be. These systems will
Dongjiu Geng688e0582018-08-20 17:39:25 -04001126advertise KVM_CAP_ARM_INJECT_SERROR_ESR. In this case exception.has_esr will
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01001127always have a non-zero value when read, and the agent making an SError pending
1128should specify the ISS field in the lower 24 bits of exception.serror_esr. If
Dongjiu Geng688e0582018-08-20 17:39:25 -04001129the system supports KVM_CAP_ARM_INJECT_SERROR_ESR, but user-space sets the events
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01001130with exception.has_esr as zero, KVM will choose an ESR.
1131
1132Specifying exception.has_esr on a system that does not support it will return
1133-EINVAL. Setting anything other than the lower 24bits of exception.serror_esr
1134will return -EINVAL.
1135
Christoffer Dallda345172019-10-11 13:07:06 +02001136It is not possible to read back a pending external abort (injected via
1137KVM_SET_VCPU_EVENTS or otherwise) because such an exception is always delivered
1138directly to the virtual CPU).
1139
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001140::
Christoffer Dallda345172019-10-11 13:07:06 +02001141
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001142 struct kvm_vcpu_events {
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001143 struct {
1144 __u8 serror_pending;
1145 __u8 serror_has_esr;
Christoffer Dallda345172019-10-11 13:07:06 +02001146 __u8 ext_dabt_pending;
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001147 /* Align it to 8 bytes */
Christoffer Dallda345172019-10-11 13:07:06 +02001148 __u8 pad[5];
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001149 __u64 serror_esr;
1150 } exception;
1151 __u32 reserved[12];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001152 };
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001153
Paul Bolle68ba6972011-02-15 00:05:59 +010011544.32 KVM_SET_VCPU_EVENTS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001155------------------------
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001156
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001157:Capability: KVM_CAP_VCPU_EVENTS
1158:Extended by: KVM_CAP_INTR_SHADOW
1159:Architectures: x86, arm, arm64
1160:Type: vcpu ioctl
1161:Parameters: struct kvm_vcpu_event (in)
1162:Returns: 0 on success, -1 on error
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001163
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001164X86:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001165^^^^
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001166
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001167Set pending exceptions, interrupts, and NMIs as well as related states of the
1168vcpu.
1169
1170See KVM_GET_VCPU_EVENTS for the data structure.
1171
Jan Kiszkadab4b912009-12-06 18:24:15 +01001172Fields that may be modified asynchronously by running VCPUs can be excluded
Paolo Bonzinif0778252015-04-01 15:06:40 +02001173from the update. These fields are nmi.pending, sipi_vector, smi.smm,
1174smi.pending. Keep the corresponding bits in the flags field cleared to
1175suppress overwriting the current in-kernel state. The bits are:
Jan Kiszkadab4b912009-12-06 18:24:15 +01001176
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001177=============================== ==================================
1178KVM_VCPUEVENT_VALID_NMI_PENDING transfer nmi.pending to the kernel
1179KVM_VCPUEVENT_VALID_SIPI_VECTOR transfer sipi_vector
1180KVM_VCPUEVENT_VALID_SMM transfer the smi sub-struct.
1181=============================== ==================================
Jan Kiszkadab4b912009-12-06 18:24:15 +01001182
Jan Kiszka48005f62010-02-19 19:38:07 +01001183If KVM_CAP_INTR_SHADOW is available, KVM_VCPUEVENT_VALID_SHADOW can be set in
1184the flags field to signal that interrupt.shadow contains a valid state and
1185shall be written into the VCPU.
1186
Paolo Bonzinif0778252015-04-01 15:06:40 +02001187KVM_VCPUEVENT_VALID_SMM can only be set if KVM_CAP_X86_SMM is available.
1188
Jim Mattson59073aa2018-10-16 14:29:20 -07001189If KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_VCPUEVENT_VALID_PAYLOAD
1190can be set in the flags field to signal that the
1191exception_has_payload, exception_payload, and exception.pending fields
1192contain a valid state and shall be written into the VCPU.
1193
James Morseb0960b92018-07-19 16:24:25 +01001194ARM/ARM64:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001195^^^^^^^^^^
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001196
Christoffer Dallda345172019-10-11 13:07:06 +02001197User space may need to inject several types of events to the guest.
1198
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001199Set the pending SError exception state for this VCPU. It is not possible to
1200'cancel' an Serror that has been made pending.
1201
Christoffer Dallda345172019-10-11 13:07:06 +02001202If the guest performed an access to I/O memory which could not be handled by
1203userspace, for example because of missing instruction syndrome decode
1204information or because there is no device mapped at the accessed IPA, then
1205userspace can ask the kernel to inject an external abort using the address
1206from the exiting fault on the VCPU. It is a programming error to set
1207ext_dabt_pending after an exit which was not either KVM_EXIT_MMIO or
1208KVM_EXIT_ARM_NISV. This feature is only available if the system supports
1209KVM_CAP_ARM_INJECT_EXT_DABT. This is a helper which provides commonality in
1210how userspace reports accesses for the above cases to guests, across different
1211userspace implementations. Nevertheless, userspace can still emulate all Arm
1212exceptions by manipulating individual registers using the KVM_SET_ONE_REG API.
1213
Dongjiu Gengb7b27fa2018-07-19 16:24:22 +01001214See KVM_GET_VCPU_EVENTS for the data structure.
1215
Jan Kiszka414fa982012-04-24 16:40:15 +02001216
Paul Bolle68ba6972011-02-15 00:05:59 +010012174.33 KVM_GET_DEBUGREGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001218----------------------
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001219
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001220:Capability: KVM_CAP_DEBUGREGS
1221:Architectures: x86
1222:Type: vm ioctl
1223:Parameters: struct kvm_debugregs (out)
1224:Returns: 0 on success, -1 on error
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001225
1226Reads debug registers from the vcpu.
1227
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001228::
1229
1230 struct kvm_debugregs {
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001231 __u64 db[4];
1232 __u64 dr6;
1233 __u64 dr7;
1234 __u64 flags;
1235 __u64 reserved[9];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001236 };
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001237
Jan Kiszka414fa982012-04-24 16:40:15 +02001238
Paul Bolle68ba6972011-02-15 00:05:59 +010012394.34 KVM_SET_DEBUGREGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001240----------------------
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001241
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001242:Capability: KVM_CAP_DEBUGREGS
1243:Architectures: x86
1244:Type: vm ioctl
1245:Parameters: struct kvm_debugregs (in)
1246:Returns: 0 on success, -1 on error
Jan Kiszkaa1efbe72010-02-15 10:45:43 +01001247
1248Writes debug registers into the vcpu.
1249
1250See KVM_GET_DEBUGREGS for the data structure. The flags field is unused
1251yet and must be cleared on entry.
1252
Jan Kiszka414fa982012-04-24 16:40:15 +02001253
Paul Bolle68ba6972011-02-15 00:05:59 +010012544.35 KVM_SET_USER_MEMORY_REGION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001255-------------------------------
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001256
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001257:Capability: KVM_CAP_USER_MEMORY
1258:Architectures: all
1259:Type: vm ioctl
1260:Parameters: struct kvm_userspace_memory_region (in)
1261:Returns: 0 on success, -1 on error
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001262
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001263::
1264
1265 struct kvm_userspace_memory_region {
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001266 __u32 slot;
1267 __u32 flags;
1268 __u64 guest_phys_addr;
1269 __u64 memory_size; /* bytes */
1270 __u64 userspace_addr; /* start of the userspace allocated memory */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001271 };
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001272
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001273 /* for kvm_memory_region::flags */
1274 #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
1275 #define KVM_MEM_READONLY (1UL << 1)
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001276
Paolo Bonzinie2788c42019-03-28 17:22:31 +01001277This ioctl allows the user to create, modify or delete a guest physical
1278memory slot. Bits 0-15 of "slot" specify the slot id and this value
1279should be less than the maximum number of user memory slots supported per
Paolo Bonzinic110ae52019-03-28 17:24:03 +01001280VM. The maximum allowed slots can be queried using KVM_CAP_NR_MEMSLOTS.
1281Slots may not overlap in guest physical address space.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001282
Paolo Bonzinif481b062015-05-17 17:30:37 +02001283If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of "slot"
1284specifies the address space which is being modified. They must be
1285less than the value that KVM_CHECK_EXTENSION returns for the
1286KVM_CAP_MULTI_ADDRESS_SPACE capability. Slots in separate address spaces
1287are unrelated; the restriction on overlapping slots only applies within
1288each address space.
1289
Paolo Bonzinie2788c42019-03-28 17:22:31 +01001290Deleting a slot is done by passing zero for memory_size. When changing
1291an existing slot, it may be moved in the guest physical memory space,
1292or its flags may be modified, but it may not be resized.
1293
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001294Memory for the region is taken starting at the address denoted by the
1295field userspace_addr, which must point at user addressable memory for
1296the entire memory slot size. Any object may back this memory, including
1297anonymous memory, ordinary files, and hugetlbfs.
1298
Marc Zyngier139bc8a2021-01-21 12:08:15 +00001299On architectures that support a form of address tagging, userspace_addr must
1300be an untagged address.
1301
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001302It is recommended that the lower 21 bits of guest_phys_addr and userspace_addr
1303be identical. This allows large pages in the guest to be backed by large
1304pages in the host.
1305
Takuya Yoshikawa75d61fb2013-01-30 19:40:41 +09001306The flags field supports two flags: KVM_MEM_LOG_DIRTY_PAGES and
1307KVM_MEM_READONLY. The former can be set to instruct KVM to keep track of
1308writes to memory within the slot. See KVM_GET_DIRTY_LOG ioctl to know how to
1309use it. The latter can be set, if KVM_CAP_READONLY_MEM capability allows it,
1310to make a new slot read-only. In this case, writes to this memory will be
1311posted to userspace as KVM_EXIT_MMIO exits.
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001312
Jan Kiszka7efd8fa2012-09-07 13:17:47 +02001313When the KVM_CAP_SYNC_MMU capability is available, changes in the backing of
1314the memory region are automatically reflected into the guest. For example, an
1315mmap() that affects the region will be made visible immediately. Another
1316example is madvise(MADV_DROP).
Avi Kivity0f2d8f42010-03-25 12:16:48 +02001317
1318It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl.
1319The KVM_SET_MEMORY_REGION does not allow fine grained control over memory
1320allocation and is deprecated.
Jan Kiszka3cfc3092009-11-12 01:04:25 +01001321
Jan Kiszka414fa982012-04-24 16:40:15 +02001322
Paul Bolle68ba6972011-02-15 00:05:59 +010013234.36 KVM_SET_TSS_ADDR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001324---------------------
Avi Kivity8a5416d2010-03-25 12:27:30 +02001325
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001326:Capability: KVM_CAP_SET_TSS_ADDR
1327:Architectures: x86
1328:Type: vm ioctl
1329:Parameters: unsigned long tss_address (in)
1330:Returns: 0 on success, -1 on error
Avi Kivity8a5416d2010-03-25 12:27:30 +02001331
1332This ioctl defines the physical address of a three-page region in the guest
1333physical address space. The region must be within the first 4GB of the
1334guest physical address space and must not conflict with any memory slot
1335or any mmio address. The guest may malfunction if it accesses this memory
1336region.
1337
1338This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1339because of a quirk in the virtualization implementation (see the internals
1340documentation when it pops into existence).
1341
Jan Kiszka414fa982012-04-24 16:40:15 +02001342
Paul Bolle68ba6972011-02-15 00:05:59 +010013434.37 KVM_ENABLE_CAP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001344-------------------
Alexander Graf71fbfd52010-03-24 21:48:29 +01001345
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001346:Capability: KVM_CAP_ENABLE_CAP
1347:Architectures: mips, ppc, s390
1348:Type: vcpu ioctl
1349:Parameters: struct kvm_enable_cap (in)
1350:Returns: 0 on success; -1 on error
Paolo Bonzinie5d83c72017-02-16 10:40:56 +01001351
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001352:Capability: KVM_CAP_ENABLE_CAP_VM
1353:Architectures: all
Quentin Perreta10f3732021-01-08 16:53:49 +00001354:Type: vm ioctl
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001355:Parameters: struct kvm_enable_cap (in)
1356:Returns: 0 on success; -1 on error
Alexander Graf71fbfd52010-03-24 21:48:29 +01001357
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001358.. note::
1359
1360 Not all extensions are enabled by default. Using this ioctl the application
1361 can enable an extension, making it available to the guest.
Alexander Graf71fbfd52010-03-24 21:48:29 +01001362
1363On systems that do not support this ioctl, it always fails. On systems that
1364do support it, it only works for extensions that are supported for enablement.
1365
1366To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
1367be used.
1368
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001369::
1370
1371 struct kvm_enable_cap {
Alexander Graf71fbfd52010-03-24 21:48:29 +01001372 /* in */
1373 __u32 cap;
1374
1375The capability that is supposed to get enabled.
1376
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001377::
1378
Alexander Graf71fbfd52010-03-24 21:48:29 +01001379 __u32 flags;
1380
1381A bitfield indicating future enhancements. Has to be 0 for now.
1382
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001383::
1384
Alexander Graf71fbfd52010-03-24 21:48:29 +01001385 __u64 args[4];
1386
1387Arguments for enabling a feature. If a feature needs initial values to
1388function properly, this is the place to put them.
1389
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001390::
1391
Alexander Graf71fbfd52010-03-24 21:48:29 +01001392 __u8 pad[64];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001393 };
Alexander Graf71fbfd52010-03-24 21:48:29 +01001394
Cornelia Huckd938dc52013-10-23 18:26:34 +02001395The vcpu ioctl should be used for vcpu-specific capabilities, the vm ioctl
1396for vm-wide capabilities.
Jan Kiszka414fa982012-04-24 16:40:15 +02001397
Paul Bolle68ba6972011-02-15 00:05:59 +010013984.38 KVM_GET_MP_STATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001399---------------------
Avi Kivityb843f062010-04-25 15:51:46 +03001400
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001401:Capability: KVM_CAP_MP_STATE
1402:Architectures: x86, s390, arm, arm64
1403:Type: vcpu ioctl
1404:Parameters: struct kvm_mp_state (out)
1405:Returns: 0 on success; -1 on error
Avi Kivityb843f062010-04-25 15:51:46 +03001406
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001407::
1408
1409 struct kvm_mp_state {
Avi Kivityb843f062010-04-25 15:51:46 +03001410 __u32 mp_state;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001411 };
Avi Kivityb843f062010-04-25 15:51:46 +03001412
1413Returns the vcpu's current "multiprocessing state" (though also valid on
1414uniprocessor guests).
1415
1416Possible values are:
1417
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001418 ========================== ===============================================
1419 KVM_MP_STATE_RUNNABLE the vcpu is currently running [x86,arm/arm64]
1420 KVM_MP_STATE_UNINITIALIZED the vcpu is an application processor (AP)
Tiejun Chenc32a4272014-11-20 11:07:18 +01001421 which has not yet received an INIT signal [x86]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001422 KVM_MP_STATE_INIT_RECEIVED the vcpu has received an INIT signal, and is
Tiejun Chenc32a4272014-11-20 11:07:18 +01001423 now ready for a SIPI [x86]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001424 KVM_MP_STATE_HALTED the vcpu has executed a HLT instruction and
Tiejun Chenc32a4272014-11-20 11:07:18 +01001425 is waiting for an interrupt [x86]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001426 KVM_MP_STATE_SIPI_RECEIVED the vcpu has just received a SIPI (vector
Tiejun Chenc32a4272014-11-20 11:07:18 +01001427 accessible via KVM_GET_VCPU_EVENTS) [x86]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001428 KVM_MP_STATE_STOPPED the vcpu is stopped [s390,arm/arm64]
1429 KVM_MP_STATE_CHECK_STOP the vcpu is in a special error state [s390]
1430 KVM_MP_STATE_OPERATING the vcpu is operating (running or halted)
David Hildenbrand6352e4d2014-04-10 17:35:00 +02001431 [s390]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001432 KVM_MP_STATE_LOAD the vcpu is in a special load/startup state
David Hildenbrand6352e4d2014-04-10 17:35:00 +02001433 [s390]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001434 ========================== ===============================================
Avi Kivityb843f062010-04-25 15:51:46 +03001435
Tiejun Chenc32a4272014-11-20 11:07:18 +01001436On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001437in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1438these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001439
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001440For arm/arm64:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001441^^^^^^^^^^^^^^
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001442
1443The only states that are valid are KVM_MP_STATE_STOPPED and
1444KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001445
Paul Bolle68ba6972011-02-15 00:05:59 +010014464.39 KVM_SET_MP_STATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001447---------------------
Avi Kivityb843f062010-04-25 15:51:46 +03001448
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001449:Capability: KVM_CAP_MP_STATE
1450:Architectures: x86, s390, arm, arm64
1451:Type: vcpu ioctl
1452:Parameters: struct kvm_mp_state (in)
1453:Returns: 0 on success; -1 on error
Avi Kivityb843f062010-04-25 15:51:46 +03001454
1455Sets the vcpu's current "multiprocessing state"; see KVM_GET_MP_STATE for
1456arguments.
1457
Tiejun Chenc32a4272014-11-20 11:07:18 +01001458On x86, this ioctl is only useful after KVM_CREATE_IRQCHIP. Without an
David Hildenbrand0b4820d2014-05-12 16:05:13 +02001459in-kernel irqchip, the multiprocessing state must be maintained by userspace on
1460these architectures.
Avi Kivityb843f062010-04-25 15:51:46 +03001461
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001462For arm/arm64:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001463^^^^^^^^^^^^^^
Alex Bennéeecccf0c2015-03-13 17:02:52 +00001464
1465The only states that are valid are KVM_MP_STATE_STOPPED and
1466KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
Jan Kiszka414fa982012-04-24 16:40:15 +02001467
Paul Bolle68ba6972011-02-15 00:05:59 +010014684.40 KVM_SET_IDENTITY_MAP_ADDR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001469------------------------------
Avi Kivity47dbb842010-04-29 12:08:56 +03001470
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001471:Capability: KVM_CAP_SET_IDENTITY_MAP_ADDR
1472:Architectures: x86
1473:Type: vm ioctl
1474:Parameters: unsigned long identity (in)
1475:Returns: 0 on success, -1 on error
Avi Kivity47dbb842010-04-29 12:08:56 +03001476
1477This ioctl defines the physical address of a one-page region in the guest
1478physical address space. The region must be within the first 4GB of the
1479guest physical address space and must not conflict with any memory slot
1480or any mmio address. The guest may malfunction if it accesses this memory
1481region.
1482
David Hildenbrand726b99c2017-08-24 20:51:35 +02001483Setting the address to 0 will result in resetting the address to its default
1484(0xfffbc000).
1485
Avi Kivity47dbb842010-04-29 12:08:56 +03001486This ioctl is required on Intel-based hosts. This is needed on Intel hardware
1487because of a quirk in the virtualization implementation (see the internals
1488documentation when it pops into existence).
1489
David Hildenbrand1af1ac92017-08-24 20:51:36 +02001490Fails if any VCPU has already been created.
Jan Kiszka414fa982012-04-24 16:40:15 +02001491
Paul Bolle68ba6972011-02-15 00:05:59 +010014924.41 KVM_SET_BOOT_CPU_ID
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001493------------------------
Avi Kivity57bc24c2010-04-29 12:12:57 +03001494
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001495:Capability: KVM_CAP_SET_BOOT_CPU_ID
1496:Architectures: x86
1497:Type: vm ioctl
1498:Parameters: unsigned long vcpu_id
1499:Returns: 0 on success, -1 on error
Avi Kivity57bc24c2010-04-29 12:12:57 +03001500
1501Define which vcpu is the Bootstrap Processor (BSP). Values are the same
1502as the vcpu id in KVM_CREATE_VCPU. If this ioctl is not called, the default
Emanuele Giuseppe Esposito9ce37462021-03-19 10:16:50 +01001503is vcpu 0. This ioctl has to be called before vcpu creation,
1504otherwise it will return EBUSY error.
Avi Kivity57bc24c2010-04-29 12:12:57 +03001505
Jan Kiszka414fa982012-04-24 16:40:15 +02001506
Paul Bolle68ba6972011-02-15 00:05:59 +010015074.42 KVM_GET_XSAVE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001508------------------
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001509
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001510:Capability: KVM_CAP_XSAVE
1511:Architectures: x86
1512:Type: vcpu ioctl
1513:Parameters: struct kvm_xsave (out)
1514:Returns: 0 on success, -1 on error
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001515
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001516
1517::
1518
1519 struct kvm_xsave {
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001520 __u32 region[1024];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001521 };
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001522
1523This ioctl would copy current vcpu's xsave struct to the userspace.
1524
Jan Kiszka414fa982012-04-24 16:40:15 +02001525
Paul Bolle68ba6972011-02-15 00:05:59 +010015264.43 KVM_SET_XSAVE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001527------------------
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001528
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001529:Capability: KVM_CAP_XSAVE
1530:Architectures: x86
1531:Type: vcpu ioctl
1532:Parameters: struct kvm_xsave (in)
1533:Returns: 0 on success, -1 on error
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001534
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001535::
1536
1537
1538 struct kvm_xsave {
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001539 __u32 region[1024];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001540 };
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001541
1542This ioctl would copy userspace's xsave struct to the kernel.
1543
Jan Kiszka414fa982012-04-24 16:40:15 +02001544
Paul Bolle68ba6972011-02-15 00:05:59 +010015454.44 KVM_GET_XCRS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001546-----------------
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001547
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001548:Capability: KVM_CAP_XCRS
1549:Architectures: x86
1550:Type: vcpu ioctl
1551:Parameters: struct kvm_xcrs (out)
1552:Returns: 0 on success, -1 on error
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001553
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001554::
1555
1556 struct kvm_xcr {
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001557 __u32 xcr;
1558 __u32 reserved;
1559 __u64 value;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001560 };
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001561
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001562 struct kvm_xcrs {
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001563 __u32 nr_xcrs;
1564 __u32 flags;
1565 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1566 __u64 padding[16];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001567 };
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001568
1569This ioctl would copy current vcpu's xcrs to the userspace.
1570
Jan Kiszka414fa982012-04-24 16:40:15 +02001571
Paul Bolle68ba6972011-02-15 00:05:59 +010015724.45 KVM_SET_XCRS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001573-----------------
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001574
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001575:Capability: KVM_CAP_XCRS
1576:Architectures: x86
1577:Type: vcpu ioctl
1578:Parameters: struct kvm_xcrs (in)
1579:Returns: 0 on success, -1 on error
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001580
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001581::
1582
1583 struct kvm_xcr {
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001584 __u32 xcr;
1585 __u32 reserved;
1586 __u64 value;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001587 };
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001588
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001589 struct kvm_xcrs {
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001590 __u32 nr_xcrs;
1591 __u32 flags;
1592 struct kvm_xcr xcrs[KVM_MAX_XCRS];
1593 __u64 padding[16];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001594 };
Sheng Yang2d5b5a62010-06-13 17:29:39 +08001595
1596This ioctl would set vcpu's xcr to the value userspace specified.
1597
Jan Kiszka414fa982012-04-24 16:40:15 +02001598
Paul Bolle68ba6972011-02-15 00:05:59 +010015994.46 KVM_GET_SUPPORTED_CPUID
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001600----------------------------
Avi Kivityd1535132010-07-14 09:45:21 +03001601
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001602:Capability: KVM_CAP_EXT_CPUID
1603:Architectures: x86
1604:Type: system ioctl
1605:Parameters: struct kvm_cpuid2 (in/out)
1606:Returns: 0 on success, -1 on error
Avi Kivityd1535132010-07-14 09:45:21 +03001607
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001608::
1609
1610 struct kvm_cpuid2 {
Avi Kivityd1535132010-07-14 09:45:21 +03001611 __u32 nent;
1612 __u32 padding;
1613 struct kvm_cpuid_entry2 entries[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001614 };
Avi Kivityd1535132010-07-14 09:45:21 +03001615
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001616 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
Sean Christopherson7ff6c032020-03-02 15:56:51 -08001617 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */
1618 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */
Avi Kivityd1535132010-07-14 09:45:21 +03001619
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001620 struct kvm_cpuid_entry2 {
Avi Kivityd1535132010-07-14 09:45:21 +03001621 __u32 function;
1622 __u32 index;
1623 __u32 flags;
1624 __u32 eax;
1625 __u32 ebx;
1626 __u32 ecx;
1627 __u32 edx;
1628 __u32 padding[3];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001629 };
Avi Kivityd1535132010-07-14 09:45:21 +03001630
Jim Mattsondf9cb9c2018-05-24 11:59:54 -07001631This ioctl returns x86 cpuid features which are supported by both the
1632hardware and kvm in its default configuration. Userspace can use the
1633information returned by this ioctl to construct cpuid information (for
1634KVM_SET_CPUID2) that is consistent with hardware, kernel, and
1635userspace capabilities, and with user requirements (for example, the
1636user may wish to constrain cpuid to emulate older hardware, or for
1637feature consistency across a cluster).
1638
1639Note that certain capabilities, such as KVM_CAP_X86_DISABLE_EXITS, may
1640expose cpuid features (e.g. MONITOR) which are not supported by kvm in
1641its default configuration. If userspace enables such capabilities, it
1642is responsible for modifying the results of this ioctl appropriately.
Avi Kivityd1535132010-07-14 09:45:21 +03001643
1644Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
1645with the 'nent' field indicating the number of entries in the variable-size
1646array 'entries'. If the number of entries is too low to describe the cpu
1647capabilities, an error (E2BIG) is returned. If the number is too high,
1648the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
1649number is just right, the 'nent' field is adjusted to the number of valid
1650entries in the 'entries' array, which is then filled.
1651
1652The entries returned are the host cpuid as returned by the cpuid instruction,
Avi Kivityc39cbd22010-09-12 16:39:11 +02001653with unknown or unsupported features masked out. Some features (for example,
1654x2apic), may not be present in the host cpu, but are exposed by kvm if it can
1655emulate them efficiently. The fields in each entry are defined as follows:
Avi Kivityd1535132010-07-14 09:45:21 +03001656
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001657 function:
1658 the eax value used to obtain the entry
1659
1660 index:
1661 the ecx value used to obtain the entry (for entries that are
Avi Kivityd1535132010-07-14 09:45:21 +03001662 affected by ecx)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001663
1664 flags:
1665 an OR of zero or more of the following:
1666
Avi Kivityd1535132010-07-14 09:45:21 +03001667 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
1668 if the index field is valid
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001669
1670 eax, ebx, ecx, edx:
1671 the values returned by the cpuid instruction for
Avi Kivityd1535132010-07-14 09:45:21 +03001672 this function/index combination
1673
Jan Kiszka4d25a0662011-12-21 12:28:29 +01001674The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1675as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001676support. Instead it is reported via::
Jan Kiszka4d25a0662011-12-21 12:28:29 +01001677
1678 ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
1679
1680if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
1681feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
1682
Jan Kiszka414fa982012-04-24 16:40:15 +02001683
Paul Bolle68ba6972011-02-15 00:05:59 +010016844.47 KVM_PPC_GET_PVINFO
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001685-----------------------
Alexander Graf15711e92010-07-29 14:48:08 +02001686
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001687:Capability: KVM_CAP_PPC_GET_PVINFO
1688:Architectures: ppc
1689:Type: vm ioctl
1690:Parameters: struct kvm_ppc_pvinfo (out)
1691:Returns: 0 on success, !0 on error
Alexander Graf15711e92010-07-29 14:48:08 +02001692
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001693::
1694
1695 struct kvm_ppc_pvinfo {
Alexander Graf15711e92010-07-29 14:48:08 +02001696 __u32 flags;
1697 __u32 hcall[4];
1698 __u8 pad[108];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001699 };
Alexander Graf15711e92010-07-29 14:48:08 +02001700
1701This ioctl fetches PV specific information that need to be passed to the guest
1702using the device tree or other means from vm context.
1703
Liu Yu-B132019202e072012-07-03 05:48:52 +00001704The hcall array defines 4 instructions that make up a hypercall.
Alexander Graf15711e92010-07-29 14:48:08 +02001705
1706If any additional field gets added to this structure later on, a bit for that
1707additional piece of information will be set in the flags bitmap.
1708
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001709The flags bitmap is defined as::
Liu Yu-B132019202e072012-07-03 05:48:52 +00001710
1711 /* the host supports the ePAPR idle hcall
1712 #define KVM_PPC_PVINFO_FLAGS_EV_IDLE (1<<0)
Jan Kiszka414fa982012-04-24 16:40:15 +02001713
Paul Bolle68ba6972011-02-15 00:05:59 +010017144.52 KVM_SET_GSI_ROUTING
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001715------------------------
Jan Kiszka49f48172010-11-16 22:30:07 +01001716
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001717:Capability: KVM_CAP_IRQ_ROUTING
1718:Architectures: x86 s390 arm arm64
1719:Type: vm ioctl
1720:Parameters: struct kvm_irq_routing (in)
1721:Returns: 0 on success, -1 on error
Jan Kiszka49f48172010-11-16 22:30:07 +01001722
1723Sets the GSI routing table entries, overwriting any previously set entries.
1724
Eric Auger180ae7b2016-07-22 16:20:41 +00001725On arm/arm64, GSI routing has the following limitation:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001726
Eric Auger180ae7b2016-07-22 16:20:41 +00001727- GSI routing does not apply to KVM_IRQ_LINE but only to KVM_IRQFD.
1728
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001729::
1730
1731 struct kvm_irq_routing {
Jan Kiszka49f48172010-11-16 22:30:07 +01001732 __u32 nr;
1733 __u32 flags;
1734 struct kvm_irq_routing_entry entries[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001735 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001736
1737No flags are specified so far, the corresponding field must be set to zero.
1738
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001739::
1740
1741 struct kvm_irq_routing_entry {
Jan Kiszka49f48172010-11-16 22:30:07 +01001742 __u32 gsi;
1743 __u32 type;
1744 __u32 flags;
1745 __u32 pad;
1746 union {
1747 struct kvm_irq_routing_irqchip irqchip;
1748 struct kvm_irq_routing_msi msi;
Cornelia Huck84223592013-07-15 13:36:01 +02001749 struct kvm_irq_routing_s390_adapter adapter;
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001750 struct kvm_irq_routing_hv_sint hv_sint;
Jan Kiszka49f48172010-11-16 22:30:07 +01001751 __u32 pad[8];
1752 } u;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001753 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001754
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001755 /* gsi routing entry types */
1756 #define KVM_IRQ_ROUTING_IRQCHIP 1
1757 #define KVM_IRQ_ROUTING_MSI 2
1758 #define KVM_IRQ_ROUTING_S390_ADAPTER 3
1759 #define KVM_IRQ_ROUTING_HV_SINT 4
Jan Kiszka49f48172010-11-16 22:30:07 +01001760
Eric Auger76a10b82016-07-22 16:20:37 +00001761flags:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001762
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001763- KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
1764 type, specifies that the devid field contains a valid value. The per-VM
1765 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
1766 the device ID. If this capability is not available, userspace should
1767 never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Eric Auger76a10b82016-07-22 16:20:37 +00001768- zero otherwise
Jan Kiszka49f48172010-11-16 22:30:07 +01001769
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001770::
1771
1772 struct kvm_irq_routing_irqchip {
Jan Kiszka49f48172010-11-16 22:30:07 +01001773 __u32 irqchip;
1774 __u32 pin;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001775 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001776
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001777 struct kvm_irq_routing_msi {
Jan Kiszka49f48172010-11-16 22:30:07 +01001778 __u32 address_lo;
1779 __u32 address_hi;
1780 __u32 data;
Eric Auger76a10b82016-07-22 16:20:37 +00001781 union {
1782 __u32 pad;
1783 __u32 devid;
1784 };
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001785 };
Jan Kiszka49f48172010-11-16 22:30:07 +01001786
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02001787If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
1788for the device that wrote the MSI message. For PCI, this is usually a
1789BFD identifier in the lower 16 bits.
Eric Auger76a10b82016-07-22 16:20:37 +00001790
Radim Krčmář371313132016-07-12 22:09:27 +02001791On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
1792feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
1793address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
1794address_hi must be zero.
1795
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001796::
1797
1798 struct kvm_irq_routing_s390_adapter {
Cornelia Huck84223592013-07-15 13:36:01 +02001799 __u64 ind_addr;
1800 __u64 summary_addr;
1801 __u64 ind_offset;
1802 __u32 summary_offset;
1803 __u32 adapter_id;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001804 };
Cornelia Huck84223592013-07-15 13:36:01 +02001805
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001806 struct kvm_irq_routing_hv_sint {
Andrey Smetanin5c9194122015-11-10 15:36:34 +03001807 __u32 vcpu;
1808 __u32 sint;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001809 };
Jan Kiszka414fa982012-04-24 16:40:15 +02001810
Jan Kiszka414fa982012-04-24 16:40:15 +02001811
18124.55 KVM_SET_TSC_KHZ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001813--------------------
Joerg Roedel92a1f122011-03-25 09:44:51 +01001814
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001815:Capability: KVM_CAP_TSC_CONTROL
1816:Architectures: x86
1817:Type: vcpu ioctl
1818:Parameters: virtual tsc_khz
1819:Returns: 0 on success, -1 on error
Joerg Roedel92a1f122011-03-25 09:44:51 +01001820
1821Specifies the tsc frequency for the virtual machine. The unit of the
1822frequency is KHz.
1823
Jan Kiszka414fa982012-04-24 16:40:15 +02001824
18254.56 KVM_GET_TSC_KHZ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001826--------------------
Joerg Roedel92a1f122011-03-25 09:44:51 +01001827
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001828:Capability: KVM_CAP_GET_TSC_KHZ
1829:Architectures: x86
1830:Type: vcpu ioctl
1831:Parameters: none
1832:Returns: virtual tsc-khz on success, negative value on error
Joerg Roedel92a1f122011-03-25 09:44:51 +01001833
1834Returns the tsc frequency of the guest. The unit of the return value is
1835KHz. If the host has unstable tsc this ioctl returns -EIO instead as an
1836error.
1837
Jan Kiszka414fa982012-04-24 16:40:15 +02001838
18394.57 KVM_GET_LAPIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001840------------------
Avi Kivitye7677932011-05-11 08:30:51 -04001841
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001842:Capability: KVM_CAP_IRQCHIP
1843:Architectures: x86
1844:Type: vcpu ioctl
1845:Parameters: struct kvm_lapic_state (out)
1846:Returns: 0 on success, -1 on error
Avi Kivitye7677932011-05-11 08:30:51 -04001847
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001848::
1849
1850 #define KVM_APIC_REG_SIZE 0x400
1851 struct kvm_lapic_state {
Avi Kivitye7677932011-05-11 08:30:51 -04001852 char regs[KVM_APIC_REG_SIZE];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001853 };
Avi Kivitye7677932011-05-11 08:30:51 -04001854
1855Reads the Local APIC registers and copies them into the input argument. The
1856data format and layout are the same as documented in the architecture manual.
1857
Radim Krčmář371313132016-07-12 22:09:27 +02001858If KVM_X2APIC_API_USE_32BIT_IDS feature of KVM_CAP_X2APIC_API is
1859enabled, then the format of APIC_ID register depends on the APIC mode
1860(reported by MSR_IA32_APICBASE) of its VCPU. x2APIC stores APIC ID in
1861the APIC_ID register (bytes 32-35). xAPIC only allows an 8-bit APIC ID
1862which is stored in bits 31-24 of the APIC register, or equivalently in
1863byte 35 of struct kvm_lapic_state's regs field. KVM_GET_LAPIC must then
1864be called after MSR_IA32_APICBASE has been set with KVM_SET_MSR.
1865
1866If KVM_X2APIC_API_USE_32BIT_IDS feature is disabled, struct kvm_lapic_state
1867always uses xAPIC format.
1868
Jan Kiszka414fa982012-04-24 16:40:15 +02001869
18704.58 KVM_SET_LAPIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001871------------------
Avi Kivitye7677932011-05-11 08:30:51 -04001872
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001873:Capability: KVM_CAP_IRQCHIP
1874:Architectures: x86
1875:Type: vcpu ioctl
1876:Parameters: struct kvm_lapic_state (in)
1877:Returns: 0 on success, -1 on error
Avi Kivitye7677932011-05-11 08:30:51 -04001878
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001879::
1880
1881 #define KVM_APIC_REG_SIZE 0x400
1882 struct kvm_lapic_state {
Avi Kivitye7677932011-05-11 08:30:51 -04001883 char regs[KVM_APIC_REG_SIZE];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001884 };
Avi Kivitye7677932011-05-11 08:30:51 -04001885
Masanari Iidadf5cbb22014-03-21 10:04:30 +09001886Copies the input argument into the Local APIC registers. The data format
Avi Kivitye7677932011-05-11 08:30:51 -04001887and layout are the same as documented in the architecture manual.
1888
Radim Krčmář371313132016-07-12 22:09:27 +02001889The format of the APIC ID register (bytes 32-35 of struct kvm_lapic_state's
1890regs field) depends on the state of the KVM_CAP_X2APIC_API capability.
1891See the note in KVM_GET_LAPIC.
1892
Jan Kiszka414fa982012-04-24 16:40:15 +02001893
18944.59 KVM_IOEVENTFD
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001895------------------
Sasha Levin55399a02011-05-28 14:12:30 +03001896
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001897:Capability: KVM_CAP_IOEVENTFD
1898:Architectures: all
1899:Type: vm ioctl
1900:Parameters: struct kvm_ioeventfd (in)
1901:Returns: 0 on success, !0 on error
Sasha Levin55399a02011-05-28 14:12:30 +03001902
1903This ioctl attaches or detaches an ioeventfd to a legal pio/mmio address
1904within the guest. A guest write in the registered address will signal the
1905provided event instead of triggering an exit.
1906
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001907::
1908
1909 struct kvm_ioeventfd {
Sasha Levin55399a02011-05-28 14:12:30 +03001910 __u64 datamatch;
1911 __u64 addr; /* legal pio/mmio address */
Jason Wange9ea5062015-09-15 14:41:59 +08001912 __u32 len; /* 0, 1, 2, 4, or 8 bytes */
Sasha Levin55399a02011-05-28 14:12:30 +03001913 __s32 fd;
1914 __u32 flags;
1915 __u8 pad[36];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001916 };
Sasha Levin55399a02011-05-28 14:12:30 +03001917
Cornelia Huck2b834512013-02-28 12:33:20 +01001918For the special case of virtio-ccw devices on s390, the ioevent is matched
1919to a subchannel/virtqueue tuple instead.
1920
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001921The following flags are defined::
Sasha Levin55399a02011-05-28 14:12:30 +03001922
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001923 #define KVM_IOEVENTFD_FLAG_DATAMATCH (1 << kvm_ioeventfd_flag_nr_datamatch)
1924 #define KVM_IOEVENTFD_FLAG_PIO (1 << kvm_ioeventfd_flag_nr_pio)
1925 #define KVM_IOEVENTFD_FLAG_DEASSIGN (1 << kvm_ioeventfd_flag_nr_deassign)
1926 #define KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY \
Cornelia Huck2b834512013-02-28 12:33:20 +01001927 (1 << kvm_ioeventfd_flag_nr_virtio_ccw_notify)
Sasha Levin55399a02011-05-28 14:12:30 +03001928
1929If datamatch flag is set, the event will be signaled only if the written value
1930to the registered address is equal to datamatch in struct kvm_ioeventfd.
1931
Cornelia Huck2b834512013-02-28 12:33:20 +01001932For virtio-ccw devices, addr contains the subchannel id and datamatch the
1933virtqueue index.
1934
Jason Wange9ea5062015-09-15 14:41:59 +08001935With KVM_CAP_IOEVENTFD_ANY_LENGTH, a zero length ioeventfd is allowed, and
1936the kernel will ignore the length of guest write and may get a faster vmexit.
1937The speedup may only apply to specific architectures, but the ioeventfd will
1938work anyway.
Jan Kiszka414fa982012-04-24 16:40:15 +02001939
19404.60 KVM_DIRTY_TLB
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001941------------------
Scott Wooddc83b8b2011-08-18 15:25:21 -05001942
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001943:Capability: KVM_CAP_SW_TLB
1944:Architectures: ppc
1945:Type: vcpu ioctl
1946:Parameters: struct kvm_dirty_tlb (in)
1947:Returns: 0 on success, -1 on error
Scott Wooddc83b8b2011-08-18 15:25:21 -05001948
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001949::
1950
1951 struct kvm_dirty_tlb {
Scott Wooddc83b8b2011-08-18 15:25:21 -05001952 __u64 bitmap;
1953 __u32 num_dirty;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001954 };
Scott Wooddc83b8b2011-08-18 15:25:21 -05001955
1956This must be called whenever userspace has changed an entry in the shared
1957TLB, prior to calling KVM_RUN on the associated vcpu.
1958
1959The "bitmap" field is the userspace address of an array. This array
1960consists of a number of bits, equal to the total number of TLB entries as
1961determined by the last successful call to KVM_CONFIG_TLB, rounded up to the
1962nearest multiple of 64.
1963
1964Each bit corresponds to one TLB entry, ordered the same as in the shared TLB
1965array.
1966
1967The array is little-endian: the bit 0 is the least significant bit of the
1968first byte, bit 8 is the least significant bit of the second byte, etc.
1969This avoids any complications with differing word sizes.
1970
1971The "num_dirty" field is a performance hint for KVM to determine whether it
1972should skip processing the bitmap and just invalidate everything. It must
1973be set to the number of set bits in the bitmap.
1974
Jan Kiszka414fa982012-04-24 16:40:15 +02001975
David Gibson54738c02011-06-29 00:22:41 +000019764.62 KVM_CREATE_SPAPR_TCE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001977-------------------------
David Gibson54738c02011-06-29 00:22:41 +00001978
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001979:Capability: KVM_CAP_SPAPR_TCE
1980:Architectures: powerpc
1981:Type: vm ioctl
1982:Parameters: struct kvm_create_spapr_tce (in)
1983:Returns: file descriptor for manipulating the created TCE table
David Gibson54738c02011-06-29 00:22:41 +00001984
1985This creates a virtual TCE (translation control entry) table, which
1986is an IOMMU for PAPR-style virtual I/O. It is used to translate
1987logical addresses used in virtual I/O into guest physical addresses,
1988and provides a scatter/gather capability for PAPR virtual I/O.
1989
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001990::
1991
1992 /* for KVM_CAP_SPAPR_TCE */
1993 struct kvm_create_spapr_tce {
David Gibson54738c02011-06-29 00:22:41 +00001994 __u64 liobn;
1995 __u32 window_size;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01001996 };
David Gibson54738c02011-06-29 00:22:41 +00001997
1998The liobn field gives the logical IO bus number for which to create a
1999TCE table. The window_size field specifies the size of the DMA window
2000which this TCE table will translate - the table will contain one 64
2001bit TCE entry for every 4kiB of the DMA window.
2002
2003When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE
2004table has been created using this ioctl(), the kernel will handle it
2005in real mode, updating the TCE table. H_PUT_TCE calls for other
2006liobns will cause a vm exit and must be handled by userspace.
2007
2008The return value is a file descriptor which can be passed to mmap(2)
2009to map the created TCE table into userspace. This lets userspace read
2010the entries written by kernel-handled H_PUT_TCE calls, and also lets
2011userspace update the TCE table directly which is useful in some
2012circumstances.
2013
Jan Kiszka414fa982012-04-24 16:40:15 +02002014
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +000020154.63 KVM_ALLOCATE_RMA
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002016---------------------
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +00002017
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002018:Capability: KVM_CAP_PPC_RMA
2019:Architectures: powerpc
2020:Type: vm ioctl
2021:Parameters: struct kvm_allocate_rma (out)
2022:Returns: file descriptor for mapping the allocated RMA
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +00002023
2024This allocates a Real Mode Area (RMA) from the pool allocated at boot
2025time by the kernel. An RMA is a physically-contiguous, aligned region
2026of memory used on older POWER processors to provide the memory which
2027will be accessed by real-mode (MMU off) accesses in a KVM guest.
2028POWER processors support a set of sizes for the RMA that usually
2029includes 64MB, 128MB, 256MB and some larger powers of two.
2030
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002031::
2032
2033 /* for KVM_ALLOCATE_RMA */
2034 struct kvm_allocate_rma {
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +00002035 __u64 rma_size;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002036 };
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +00002037
2038The return value is a file descriptor which can be passed to mmap(2)
2039to map the allocated RMA into userspace. The mapped area can then be
2040passed to the KVM_SET_USER_MEMORY_REGION ioctl to establish it as the
2041RMA for a virtual machine. The size of the RMA in bytes (which is
2042fixed at host kernel boot time) is returned in the rma_size field of
2043the argument structure.
2044
2045The KVM_CAP_PPC_RMA capability is 1 or 2 if the KVM_ALLOCATE_RMA ioctl
2046is supported; 2 if the processor requires all virtual machines to have
2047an RMA, or 1 if the processor can use an RMA but doesn't require it,
2048because it supports the Virtual RMA (VRMA) facility.
2049
Jan Kiszka414fa982012-04-24 16:40:15 +02002050
Avi Kivity3f745f12011-12-07 12:42:47 +020020514.64 KVM_NMI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002052------------
Avi Kivity3f745f12011-12-07 12:42:47 +02002053
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002054:Capability: KVM_CAP_USER_NMI
2055:Architectures: x86
2056:Type: vcpu ioctl
2057:Parameters: none
2058:Returns: 0 on success, -1 on error
Avi Kivity3f745f12011-12-07 12:42:47 +02002059
2060Queues an NMI on the thread's vcpu. Note this is well defined only
2061when KVM_CREATE_IRQCHIP has not been called, since this is an interface
2062between the virtual cpu core and virtual local APIC. After KVM_CREATE_IRQCHIP
2063has been called, this interface is completely emulated within the kernel.
2064
2065To use this to emulate the LINT1 input with KVM_CREATE_IRQCHIP, use the
2066following algorithm:
2067
Masanari Iida5d4f6f32015-10-04 00:46:21 +09002068 - pause the vcpu
Avi Kivity3f745f12011-12-07 12:42:47 +02002069 - read the local APIC's state (KVM_GET_LAPIC)
2070 - check whether changing LINT1 will queue an NMI (see the LVT entry for LINT1)
2071 - if so, issue KVM_NMI
2072 - resume the vcpu
2073
2074Some guests configure the LINT1 NMI input to cause a panic, aiding in
2075debugging.
2076
Jan Kiszka414fa982012-04-24 16:40:15 +02002077
Alexander Grafe24ed812011-09-14 10:02:41 +020020784.65 KVM_S390_UCAS_MAP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002079----------------------
Carsten Otte27e03932012-01-04 10:25:21 +01002080
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002081:Capability: KVM_CAP_S390_UCONTROL
2082:Architectures: s390
2083:Type: vcpu ioctl
2084:Parameters: struct kvm_s390_ucas_mapping (in)
2085:Returns: 0 in case of success
Carsten Otte27e03932012-01-04 10:25:21 +01002086
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002087The parameter is defined like this::
2088
Carsten Otte27e03932012-01-04 10:25:21 +01002089 struct kvm_s390_ucas_mapping {
2090 __u64 user_addr;
2091 __u64 vcpu_addr;
2092 __u64 length;
2093 };
2094
2095This ioctl maps the memory at "user_addr" with the length "length" to
2096the vcpu's address space starting at "vcpu_addr". All parameters need to
Anatol Pomozovf884ab12013-05-08 16:56:16 -07002097be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01002098
Jan Kiszka414fa982012-04-24 16:40:15 +02002099
Alexander Grafe24ed812011-09-14 10:02:41 +020021004.66 KVM_S390_UCAS_UNMAP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002101------------------------
Carsten Otte27e03932012-01-04 10:25:21 +01002102
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002103:Capability: KVM_CAP_S390_UCONTROL
2104:Architectures: s390
2105:Type: vcpu ioctl
2106:Parameters: struct kvm_s390_ucas_mapping (in)
2107:Returns: 0 in case of success
Carsten Otte27e03932012-01-04 10:25:21 +01002108
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002109The parameter is defined like this::
2110
Carsten Otte27e03932012-01-04 10:25:21 +01002111 struct kvm_s390_ucas_mapping {
2112 __u64 user_addr;
2113 __u64 vcpu_addr;
2114 __u64 length;
2115 };
2116
2117This ioctl unmaps the memory in the vcpu's address space starting at
2118"vcpu_addr" with the length "length". The field "user_addr" is ignored.
Anatol Pomozovf884ab12013-05-08 16:56:16 -07002119All parameters need to be aligned by 1 megabyte.
Carsten Otte27e03932012-01-04 10:25:21 +01002120
Jan Kiszka414fa982012-04-24 16:40:15 +02002121
Alexander Grafe24ed812011-09-14 10:02:41 +020021224.67 KVM_S390_VCPU_FAULT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002123------------------------
Carsten Otteccc79102012-01-04 10:25:26 +01002124
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002125:Capability: KVM_CAP_S390_UCONTROL
2126:Architectures: s390
2127:Type: vcpu ioctl
2128:Parameters: vcpu absolute address (in)
2129:Returns: 0 in case of success
Carsten Otteccc79102012-01-04 10:25:26 +01002130
2131This call creates a page table entry on the virtual cpu's address space
2132(for user controlled virtual machines) or the virtual machine's address
2133space (for regular virtual machines). This only works for minor faults,
2134thus it's recommended to access subject memory page via the user page
2135table upfront. This is useful to handle validity intercepts for user
2136controlled virtual machines to fault in the virtual cpu's lowcore pages
2137prior to calling the KVM_RUN ioctl.
2138
Jan Kiszka414fa982012-04-24 16:40:15 +02002139
Alexander Grafe24ed812011-09-14 10:02:41 +020021404.68 KVM_SET_ONE_REG
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002141--------------------
Alexander Grafe24ed812011-09-14 10:02:41 +02002142
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002143:Capability: KVM_CAP_ONE_REG
2144:Architectures: all
2145:Type: vcpu ioctl
2146:Parameters: struct kvm_one_reg (in)
2147:Returns: 0 on success, negative value on failure
2148
Dave Martin395f5622019-01-15 17:02:08 +00002149Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002150
2151 ====== ============================================================
2152  ENOENT   no such register
Janosch Frank68cf7b12019-06-14 13:11:21 +02002153  EINVAL   invalid register ID, or no such register or used with VMs in
2154 protected virtualization mode on s390
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002155  EPERM    (arm64) register access not allowed before vcpu finalization
2156 ====== ============================================================
2157
Dave Martinfe365b42019-04-12 12:59:47 +01002158(These error codes are indicative only: do not rely on a specific error
2159code being returned in a specific situation.)
Alexander Grafe24ed812011-09-14 10:02:41 +02002160
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002161::
2162
2163 struct kvm_one_reg {
Alexander Grafe24ed812011-09-14 10:02:41 +02002164 __u64 id;
2165 __u64 addr;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002166 };
Alexander Grafe24ed812011-09-14 10:02:41 +02002167
2168Using this ioctl, a single vcpu register can be set to a specific value
2169defined by user space with the passed in struct kvm_one_reg, where id
2170refers to the register identifier as described below and addr is a pointer
2171to a variable with the respective size. There can be architecture agnostic
2172and architecture specific registers. Each have their own range of operation
2173and their own constants and width. To keep track of the implemented
2174registers, find a list below:
2175
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002176 ======= =============================== ============
2177 Arch Register Width (bits)
2178 ======= =============================== ============
2179 PPC KVM_REG_PPC_HIOR 64
2180 PPC KVM_REG_PPC_IAC1 64
2181 PPC KVM_REG_PPC_IAC2 64
2182 PPC KVM_REG_PPC_IAC3 64
2183 PPC KVM_REG_PPC_IAC4 64
2184 PPC KVM_REG_PPC_DAC1 64
2185 PPC KVM_REG_PPC_DAC2 64
2186 PPC KVM_REG_PPC_DABR 64
2187 PPC KVM_REG_PPC_DSCR 64
2188 PPC KVM_REG_PPC_PURR 64
2189 PPC KVM_REG_PPC_SPURR 64
2190 PPC KVM_REG_PPC_DAR 64
2191 PPC KVM_REG_PPC_DSISR 32
2192 PPC KVM_REG_PPC_AMR 64
2193 PPC KVM_REG_PPC_UAMOR 64
2194 PPC KVM_REG_PPC_MMCR0 64
2195 PPC KVM_REG_PPC_MMCR1 64
2196 PPC KVM_REG_PPC_MMCRA 64
2197 PPC KVM_REG_PPC_MMCR2 64
2198 PPC KVM_REG_PPC_MMCRS 64
Athira Rajeev5752fe02020-07-17 10:38:17 -04002199 PPC KVM_REG_PPC_MMCR3 64
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002200 PPC KVM_REG_PPC_SIAR 64
2201 PPC KVM_REG_PPC_SDAR 64
2202 PPC KVM_REG_PPC_SIER 64
Athira Rajeev5752fe02020-07-17 10:38:17 -04002203 PPC KVM_REG_PPC_SIER2 64
2204 PPC KVM_REG_PPC_SIER3 64
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002205 PPC KVM_REG_PPC_PMC1 32
2206 PPC KVM_REG_PPC_PMC2 32
2207 PPC KVM_REG_PPC_PMC3 32
2208 PPC KVM_REG_PPC_PMC4 32
2209 PPC KVM_REG_PPC_PMC5 32
2210 PPC KVM_REG_PPC_PMC6 32
2211 PPC KVM_REG_PPC_PMC7 32
2212 PPC KVM_REG_PPC_PMC8 32
2213 PPC KVM_REG_PPC_FPR0 64
2214 ...
2215 PPC KVM_REG_PPC_FPR31 64
2216 PPC KVM_REG_PPC_VR0 128
2217 ...
2218 PPC KVM_REG_PPC_VR31 128
2219 PPC KVM_REG_PPC_VSR0 128
2220 ...
2221 PPC KVM_REG_PPC_VSR31 128
2222 PPC KVM_REG_PPC_FPSCR 64
2223 PPC KVM_REG_PPC_VSCR 32
2224 PPC KVM_REG_PPC_VPA_ADDR 64
2225 PPC KVM_REG_PPC_VPA_SLB 128
2226 PPC KVM_REG_PPC_VPA_DTL 128
2227 PPC KVM_REG_PPC_EPCR 32
2228 PPC KVM_REG_PPC_EPR 32
2229 PPC KVM_REG_PPC_TCR 32
2230 PPC KVM_REG_PPC_TSR 32
2231 PPC KVM_REG_PPC_OR_TSR 32
2232 PPC KVM_REG_PPC_CLEAR_TSR 32
2233 PPC KVM_REG_PPC_MAS0 32
2234 PPC KVM_REG_PPC_MAS1 32
2235 PPC KVM_REG_PPC_MAS2 64
2236 PPC KVM_REG_PPC_MAS7_3 64
2237 PPC KVM_REG_PPC_MAS4 32
2238 PPC KVM_REG_PPC_MAS6 32
2239 PPC KVM_REG_PPC_MMUCFG 32
2240 PPC KVM_REG_PPC_TLB0CFG 32
2241 PPC KVM_REG_PPC_TLB1CFG 32
2242 PPC KVM_REG_PPC_TLB2CFG 32
2243 PPC KVM_REG_PPC_TLB3CFG 32
2244 PPC KVM_REG_PPC_TLB0PS 32
2245 PPC KVM_REG_PPC_TLB1PS 32
2246 PPC KVM_REG_PPC_TLB2PS 32
2247 PPC KVM_REG_PPC_TLB3PS 32
2248 PPC KVM_REG_PPC_EPTCFG 32
2249 PPC KVM_REG_PPC_ICP_STATE 64
2250 PPC KVM_REG_PPC_VP_STATE 128
2251 PPC KVM_REG_PPC_TB_OFFSET 64
2252 PPC KVM_REG_PPC_SPMC1 32
2253 PPC KVM_REG_PPC_SPMC2 32
2254 PPC KVM_REG_PPC_IAMR 64
2255 PPC KVM_REG_PPC_TFHAR 64
2256 PPC KVM_REG_PPC_TFIAR 64
2257 PPC KVM_REG_PPC_TEXASR 64
2258 PPC KVM_REG_PPC_FSCR 64
2259 PPC KVM_REG_PPC_PSPB 32
2260 PPC KVM_REG_PPC_EBBHR 64
2261 PPC KVM_REG_PPC_EBBRR 64
2262 PPC KVM_REG_PPC_BESCR 64
2263 PPC KVM_REG_PPC_TAR 64
2264 PPC KVM_REG_PPC_DPDES 64
2265 PPC KVM_REG_PPC_DAWR 64
2266 PPC KVM_REG_PPC_DAWRX 64
2267 PPC KVM_REG_PPC_CIABR 64
2268 PPC KVM_REG_PPC_IC 64
2269 PPC KVM_REG_PPC_VTB 64
2270 PPC KVM_REG_PPC_CSIGR 64
2271 PPC KVM_REG_PPC_TACR 64
2272 PPC KVM_REG_PPC_TCSCR 64
2273 PPC KVM_REG_PPC_PID 64
2274 PPC KVM_REG_PPC_ACOP 64
2275 PPC KVM_REG_PPC_VRSAVE 32
2276 PPC KVM_REG_PPC_LPCR 32
2277 PPC KVM_REG_PPC_LPCR_64 64
2278 PPC KVM_REG_PPC_PPR 64
2279 PPC KVM_REG_PPC_ARCH_COMPAT 32
2280 PPC KVM_REG_PPC_DABRX 32
2281 PPC KVM_REG_PPC_WORT 64
2282 PPC KVM_REG_PPC_SPRG9 64
2283 PPC KVM_REG_PPC_DBSR 32
2284 PPC KVM_REG_PPC_TIDR 64
2285 PPC KVM_REG_PPC_PSSCR 64
2286 PPC KVM_REG_PPC_DEC_EXPIRY 64
2287 PPC KVM_REG_PPC_PTCR 64
Ravi Bangoriabd1de1a2020-12-16 16:12:18 +05302288 PPC KVM_REG_PPC_DAWR1 64
2289 PPC KVM_REG_PPC_DAWRX1 64
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002290 PPC KVM_REG_PPC_TM_GPR0 64
2291 ...
2292 PPC KVM_REG_PPC_TM_GPR31 64
2293 PPC KVM_REG_PPC_TM_VSR0 128
2294 ...
2295 PPC KVM_REG_PPC_TM_VSR63 128
2296 PPC KVM_REG_PPC_TM_CR 64
2297 PPC KVM_REG_PPC_TM_LR 64
2298 PPC KVM_REG_PPC_TM_CTR 64
2299 PPC KVM_REG_PPC_TM_FPSCR 64
2300 PPC KVM_REG_PPC_TM_AMR 64
2301 PPC KVM_REG_PPC_TM_PPR 64
2302 PPC KVM_REG_PPC_TM_VRSAVE 64
2303 PPC KVM_REG_PPC_TM_VSCR 32
2304 PPC KVM_REG_PPC_TM_DSCR 64
2305 PPC KVM_REG_PPC_TM_TAR 64
2306 PPC KVM_REG_PPC_TM_XER 64
2307
2308 MIPS KVM_REG_MIPS_R0 64
2309 ...
2310 MIPS KVM_REG_MIPS_R31 64
2311 MIPS KVM_REG_MIPS_HI 64
2312 MIPS KVM_REG_MIPS_LO 64
2313 MIPS KVM_REG_MIPS_PC 64
2314 MIPS KVM_REG_MIPS_CP0_INDEX 32
2315 MIPS KVM_REG_MIPS_CP0_ENTRYLO0 64
2316 MIPS KVM_REG_MIPS_CP0_ENTRYLO1 64
2317 MIPS KVM_REG_MIPS_CP0_CONTEXT 64
2318 MIPS KVM_REG_MIPS_CP0_CONTEXTCONFIG 32
2319 MIPS KVM_REG_MIPS_CP0_USERLOCAL 64
2320 MIPS KVM_REG_MIPS_CP0_XCONTEXTCONFIG 64
2321 MIPS KVM_REG_MIPS_CP0_PAGEMASK 32
2322 MIPS KVM_REG_MIPS_CP0_PAGEGRAIN 32
2323 MIPS KVM_REG_MIPS_CP0_SEGCTL0 64
2324 MIPS KVM_REG_MIPS_CP0_SEGCTL1 64
2325 MIPS KVM_REG_MIPS_CP0_SEGCTL2 64
2326 MIPS KVM_REG_MIPS_CP0_PWBASE 64
2327 MIPS KVM_REG_MIPS_CP0_PWFIELD 64
2328 MIPS KVM_REG_MIPS_CP0_PWSIZE 64
2329 MIPS KVM_REG_MIPS_CP0_WIRED 32
2330 MIPS KVM_REG_MIPS_CP0_PWCTL 32
2331 MIPS KVM_REG_MIPS_CP0_HWRENA 32
2332 MIPS KVM_REG_MIPS_CP0_BADVADDR 64
2333 MIPS KVM_REG_MIPS_CP0_BADINSTR 32
2334 MIPS KVM_REG_MIPS_CP0_BADINSTRP 32
2335 MIPS KVM_REG_MIPS_CP0_COUNT 32
2336 MIPS KVM_REG_MIPS_CP0_ENTRYHI 64
2337 MIPS KVM_REG_MIPS_CP0_COMPARE 32
2338 MIPS KVM_REG_MIPS_CP0_STATUS 32
2339 MIPS KVM_REG_MIPS_CP0_INTCTL 32
2340 MIPS KVM_REG_MIPS_CP0_CAUSE 32
2341 MIPS KVM_REG_MIPS_CP0_EPC 64
2342 MIPS KVM_REG_MIPS_CP0_PRID 32
2343 MIPS KVM_REG_MIPS_CP0_EBASE 64
2344 MIPS KVM_REG_MIPS_CP0_CONFIG 32
2345 MIPS KVM_REG_MIPS_CP0_CONFIG1 32
2346 MIPS KVM_REG_MIPS_CP0_CONFIG2 32
2347 MIPS KVM_REG_MIPS_CP0_CONFIG3 32
2348 MIPS KVM_REG_MIPS_CP0_CONFIG4 32
2349 MIPS KVM_REG_MIPS_CP0_CONFIG5 32
2350 MIPS KVM_REG_MIPS_CP0_CONFIG7 32
2351 MIPS KVM_REG_MIPS_CP0_XCONTEXT 64
2352 MIPS KVM_REG_MIPS_CP0_ERROREPC 64
2353 MIPS KVM_REG_MIPS_CP0_KSCRATCH1 64
2354 MIPS KVM_REG_MIPS_CP0_KSCRATCH2 64
2355 MIPS KVM_REG_MIPS_CP0_KSCRATCH3 64
2356 MIPS KVM_REG_MIPS_CP0_KSCRATCH4 64
2357 MIPS KVM_REG_MIPS_CP0_KSCRATCH5 64
2358 MIPS KVM_REG_MIPS_CP0_KSCRATCH6 64
2359 MIPS KVM_REG_MIPS_CP0_MAAR(0..63) 64
2360 MIPS KVM_REG_MIPS_COUNT_CTL 64
2361 MIPS KVM_REG_MIPS_COUNT_RESUME 64
2362 MIPS KVM_REG_MIPS_COUNT_HZ 64
2363 MIPS KVM_REG_MIPS_FPR_32(0..31) 32
2364 MIPS KVM_REG_MIPS_FPR_64(0..31) 64
2365 MIPS KVM_REG_MIPS_VEC_128(0..31) 128
2366 MIPS KVM_REG_MIPS_FCR_IR 32
2367 MIPS KVM_REG_MIPS_FCR_CSR 32
2368 MIPS KVM_REG_MIPS_MSA_IR 32
2369 MIPS KVM_REG_MIPS_MSA_CSR 32
2370 ======= =============================== ============
Jan Kiszka414fa982012-04-24 16:40:15 +02002371
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002372ARM registers are mapped using the lower 32 bits. The upper 16 of that
2373is the register group type, or coprocessor number:
2374
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002375ARM core registers have the following id bit patterns::
2376
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002377 0x4020 0000 0010 <index into the kvm_regs struct:16>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002378
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002379ARM 32-bit CP15 registers have the following id bit patterns::
2380
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002381 0x4020 0000 000F <zero:1> <crn:4> <crm:4> <opc1:4> <opc2:3>
Christoffer Dall11382452013-01-20 18:28:10 -05002382
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002383ARM 64-bit CP15 registers have the following id bit patterns::
2384
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002385 0x4030 0000 000F <zero:1> <zero:4> <crm:4> <opc1:4> <zero:3>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002386
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002387ARM CCSIDR registers are demultiplexed by CSSELR value::
2388
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002389 0x4020 0000 0011 00 <csselr:8>
Christoffer Dall749cf76c2013-01-20 18:28:06 -05002390
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002391ARM 32-bit VFP control registers have the following id bit patterns::
2392
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002393 0x4020 0000 0012 1 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002394
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002395ARM 64-bit FP registers have the following id bit patterns::
2396
Christoffer Dallaa404dd2013-04-22 18:57:46 -07002397 0x4030 0000 0012 0 <regno:12>
Rusty Russell4fe21e42013-01-20 18:28:11 -05002398
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002399ARM firmware pseudo-registers have the following bit pattern::
2400
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002401 0x4030 0000 0014 <regno:16>
2402
Marc Zyngier379e04c72013-04-02 17:46:31 +01002403
2404arm64 registers are mapped using the lower 32 bits. The upper 16 of
2405that is the register group type, or coprocessor number:
2406
2407arm64 core/FP-SIMD registers have the following id bit patterns. Note
2408that the size of the access is variable, as the kvm_regs structure
2409contains elements ranging from 32 to 128 bits. The index is a 32bit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002410value in the kvm_regs structure seen as a 32bit array::
2411
Marc Zyngier379e04c72013-04-02 17:46:31 +01002412 0x60x0 0000 0010 <index into the kvm_regs struct:16>
2413
Dave Martinfd3bc912018-09-28 14:39:26 +01002414Specifically:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002415
2416======================= ========= ===== =======================================
Dave Martinfd3bc912018-09-28 14:39:26 +01002417 Encoding Register Bits kvm_regs member
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002418======================= ========= ===== =======================================
Dave Martinfd3bc912018-09-28 14:39:26 +01002419 0x6030 0000 0010 0000 X0 64 regs.regs[0]
2420 0x6030 0000 0010 0002 X1 64 regs.regs[1]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002421 ...
Dave Martinfd3bc912018-09-28 14:39:26 +01002422 0x6030 0000 0010 003c X30 64 regs.regs[30]
2423 0x6030 0000 0010 003e SP 64 regs.sp
2424 0x6030 0000 0010 0040 PC 64 regs.pc
2425 0x6030 0000 0010 0042 PSTATE 64 regs.pstate
2426 0x6030 0000 0010 0044 SP_EL1 64 sp_el1
2427 0x6030 0000 0010 0046 ELR_EL1 64 elr_el1
2428 0x6030 0000 0010 0048 SPSR_EL1 64 spsr[KVM_SPSR_EL1] (alias SPSR_SVC)
2429 0x6030 0000 0010 004a SPSR_ABT 64 spsr[KVM_SPSR_ABT]
2430 0x6030 0000 0010 004c SPSR_UND 64 spsr[KVM_SPSR_UND]
2431 0x6030 0000 0010 004e SPSR_IRQ 64 spsr[KVM_SPSR_IRQ]
2432 0x6060 0000 0010 0050 SPSR_FIQ 64 spsr[KVM_SPSR_FIQ]
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002433 0x6040 0000 0010 0054 V0 128 fp_regs.vregs[0] [1]_
2434 0x6040 0000 0010 0058 V1 128 fp_regs.vregs[1] [1]_
2435 ...
2436 0x6040 0000 0010 00d0 V31 128 fp_regs.vregs[31] [1]_
Dave Martinfd3bc912018-09-28 14:39:26 +01002437 0x6020 0000 0010 00d4 FPSR 32 fp_regs.fpsr
2438 0x6020 0000 0010 00d5 FPCR 32 fp_regs.fpcr
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002439======================= ========= ===== =======================================
Dave Martinfd3bc912018-09-28 14:39:26 +01002440
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002441.. [1] These encodings are not accepted for SVE-enabled vcpus. See
2442 KVM_ARM_VCPU_INIT.
Dave Martin50036ad2018-09-28 14:39:27 +01002443
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002444 The equivalent register content can be accessed via bits [127:0] of
2445 the corresponding SVE Zn registers instead for vcpus that have SVE
2446 enabled (see below).
Dave Martin50036ad2018-09-28 14:39:27 +01002447
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002448arm64 CCSIDR registers are demultiplexed by CSSELR value::
2449
Marc Zyngier379e04c72013-04-02 17:46:31 +01002450 0x6020 0000 0011 00 <csselr:8>
2451
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002452arm64 system registers have the following id bit patterns::
2453
Marc Zyngier379e04c72013-04-02 17:46:31 +01002454 0x6030 0000 0013 <op0:2> <op1:3> <crn:4> <crm:4> <op2:3>
2455
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002456.. warning::
2457
Andrew Jones290a6bb2020-01-20 14:08:25 +01002458 Two system register IDs do not follow the specified pattern. These
2459 are KVM_REG_ARM_TIMER_CVAL and KVM_REG_ARM_TIMER_CNT, which map to
2460 system registers CNTV_CVAL_EL0 and CNTVCT_EL0 respectively. These
2461 two had their values accidentally swapped, which means TIMER_CVAL is
2462 derived from the register encoding for CNTVCT_EL0 and TIMER_CNT is
2463 derived from the register encoding for CNTV_CVAL_EL0. As this is
2464 API, it must remain this way.
2465
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002466arm64 firmware pseudo-registers have the following bit pattern::
2467
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00002468 0x6030 0000 0014 <regno:16>
2469
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002470arm64 SVE registers have the following bit patterns::
2471
Dave Martin50036ad2018-09-28 14:39:27 +01002472 0x6080 0000 0015 00 <n:5> <slice:5> Zn bits[2048*slice + 2047 : 2048*slice]
2473 0x6050 0000 0015 04 <n:4> <slice:5> Pn bits[256*slice + 255 : 256*slice]
2474 0x6050 0000 0015 060 <slice:5> FFR bits[256*slice + 255 : 256*slice]
2475 0x6060 0000 0015 ffff KVM_REG_ARM64_SVE_VLS pseudo-register
2476
Dave Martin43b8e1f2019-04-12 13:25:38 +01002477Access to register IDs where 2048 * slice >= 128 * max_vq will fail with
2478ENOENT. max_vq is the vcpu's maximum supported vector length in 128-bit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002479quadwords: see [2]_ below.
Dave Martin50036ad2018-09-28 14:39:27 +01002480
2481These registers are only accessible on vcpus for which SVE is enabled.
2482See KVM_ARM_VCPU_INIT for details.
2483
2484In addition, except for KVM_REG_ARM64_SVE_VLS, these registers are not
2485accessible until the vcpu's SVE configuration has been finalized
2486using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE). See KVM_ARM_VCPU_INIT
2487and KVM_ARM_VCPU_FINALIZE for more information about this procedure.
2488
2489KVM_REG_ARM64_SVE_VLS is a pseudo-register that allows the set of vector
2490lengths supported by the vcpu to be discovered and configured by
2491userspace. When transferred to or from user memory via KVM_GET_ONE_REG
Dave Martin4bd774e2019-04-11 17:09:59 +01002492or KVM_SET_ONE_REG, the value of this register is of type
2493__u64[KVM_ARM64_SVE_VLS_WORDS], and encodes the set of vector lengths as
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002494follows::
Dave Martin50036ad2018-09-28 14:39:27 +01002495
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002496 __u64 vector_lengths[KVM_ARM64_SVE_VLS_WORDS];
Dave Martin50036ad2018-09-28 14:39:27 +01002497
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002498 if (vq >= SVE_VQ_MIN && vq <= SVE_VQ_MAX &&
2499 ((vector_lengths[(vq - KVM_ARM64_SVE_VQ_MIN) / 64] >>
Dave Martin4bd774e2019-04-11 17:09:59 +01002500 ((vq - KVM_ARM64_SVE_VQ_MIN) % 64)) & 1))
Dave Martin50036ad2018-09-28 14:39:27 +01002501 /* Vector length vq * 16 bytes supported */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002502 else
Dave Martin50036ad2018-09-28 14:39:27 +01002503 /* Vector length vq * 16 bytes not supported */
2504
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002505.. [2] The maximum value vq for which the above condition is true is
2506 max_vq. This is the maximum vector length available to the guest on
2507 this vcpu, and determines which register slices are visible through
2508 this ioctl interface.
Dave Martin50036ad2018-09-28 14:39:27 +01002509
Mauro Carvalho Chehabb693d0b2019-06-12 14:52:38 -03002510(See Documentation/arm64/sve.rst for an explanation of the "vq"
Dave Martin50036ad2018-09-28 14:39:27 +01002511nomenclature.)
2512
2513KVM_REG_ARM64_SVE_VLS is only accessible after KVM_ARM_VCPU_INIT.
2514KVM_ARM_VCPU_INIT initialises it to the best set of vector lengths that
2515the host supports.
2516
2517Userspace may subsequently modify it if desired until the vcpu's SVE
2518configuration is finalized using KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE).
2519
2520Apart from simply removing all vector lengths from the host set that
2521exceed some value, support for arbitrarily chosen sets of vector lengths
2522is hardware-dependent and may not be available. Attempting to configure
2523an invalid set of vector lengths via KVM_SET_ONE_REG will fail with
2524EINVAL.
2525
2526After the vcpu's SVE configuration is finalized, further attempts to
2527write this register will fail with EPERM.
2528
James Hoganc2d2c212014-07-04 15:11:35 +01002529
2530MIPS registers are mapped using the lower 32 bits. The upper 16 of that is
2531the register group type:
2532
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002533MIPS core registers (see above) have the following id bit patterns::
2534
James Hoganc2d2c212014-07-04 15:11:35 +01002535 0x7030 0000 0000 <reg:16>
2536
2537MIPS CP0 registers (see KVM_REG_MIPS_CP0_* above) have the following id bit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002538patterns depending on whether they're 32-bit or 64-bit registers::
2539
James Hoganc2d2c212014-07-04 15:11:35 +01002540 0x7020 0000 0001 00 <reg:5> <sel:3> (32-bit)
2541 0x7030 0000 0001 00 <reg:5> <sel:3> (64-bit)
2542
James Hogan013044c2016-12-07 17:16:37 +00002543Note: KVM_REG_MIPS_CP0_ENTRYLO0 and KVM_REG_MIPS_CP0_ENTRYLO1 are the MIPS64
2544versions of the EntryLo registers regardless of the word size of the host
2545hardware, host kernel, guest, and whether XPA is present in the guest, i.e.
2546with the RI and XI bits (if they exist) in bits 63 and 62 respectively, and
2547the PFNX field starting at bit 30.
2548
James Hogand42a0082017-03-14 10:15:38 +00002549MIPS MAARs (see KVM_REG_MIPS_CP0_MAAR(*) above) have the following id bit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002550patterns::
2551
James Hogand42a0082017-03-14 10:15:38 +00002552 0x7030 0000 0001 01 <reg:8>
2553
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002554MIPS KVM control registers (see above) have the following id bit patterns::
2555
James Hoganc2d2c212014-07-04 15:11:35 +01002556 0x7030 0000 0002 <reg:16>
2557
James Hogan379245c2014-12-02 15:48:24 +00002558MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
2559id bit patterns depending on the size of the register being accessed. They are
2560always accessed according to the current guest FPU mode (Status.FR and
2561Config5.FRE), i.e. as the guest would see them, and they become unpredictable
James Hoganab86bd62014-12-02 15:48:24 +00002562if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
2563registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002564overlap the FPU registers::
2565
James Hogan379245c2014-12-02 15:48:24 +00002566 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
2567 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
James Hoganab86bd62014-12-02 15:48:24 +00002568 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
James Hogan379245c2014-12-02 15:48:24 +00002569
2570MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002571following id bit patterns::
2572
James Hogan379245c2014-12-02 15:48:24 +00002573 0x7020 0000 0003 01 <0:3> <reg:5>
2574
James Hoganab86bd62014-12-02 15:48:24 +00002575MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002576following id bit patterns::
2577
James Hoganab86bd62014-12-02 15:48:24 +00002578 0x7020 0000 0003 02 <0:3> <reg:5>
2579
James Hoganc2d2c212014-07-04 15:11:35 +01002580
Alexander Grafe24ed812011-09-14 10:02:41 +020025814.69 KVM_GET_ONE_REG
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002582--------------------
Alexander Grafe24ed812011-09-14 10:02:41 +02002583
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002584:Capability: KVM_CAP_ONE_REG
2585:Architectures: all
2586:Type: vcpu ioctl
2587:Parameters: struct kvm_one_reg (in and out)
2588:Returns: 0 on success, negative value on failure
2589
Dave Martinfe365b42019-04-12 12:59:47 +01002590Errors include:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002591
2592 ======== ============================================================
2593  ENOENT   no such register
Janosch Frank68cf7b12019-06-14 13:11:21 +02002594  EINVAL   invalid register ID, or no such register or used with VMs in
2595 protected virtualization mode on s390
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002596  EPERM    (arm64) register access not allowed before vcpu finalization
2597 ======== ============================================================
2598
Dave Martinfe365b42019-04-12 12:59:47 +01002599(These error codes are indicative only: do not rely on a specific error
2600code being returned in a specific situation.)
Alexander Grafe24ed812011-09-14 10:02:41 +02002601
2602This ioctl allows to receive the value of a single register implemented
2603in a vcpu. The register to read is indicated by the "id" field of the
2604kvm_one_reg struct passed in. On success, the register value can be found
2605at the memory location pointed to by "addr".
2606
2607The list of registers accessible using this interface is identical to the
Bharat Bhushan2e232702012-08-15 17:37:13 +00002608list in 4.68.
Alexander Grafe24ed812011-09-14 10:02:41 +02002609
Jan Kiszka414fa982012-04-24 16:40:15 +02002610
Eric B Munson1c0b28c2012-03-10 14:37:27 -050026114.70 KVM_KVMCLOCK_CTRL
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002612----------------------
Eric B Munson1c0b28c2012-03-10 14:37:27 -05002613
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002614:Capability: KVM_CAP_KVMCLOCK_CTRL
2615:Architectures: Any that implement pvclocks (currently x86 only)
2616:Type: vcpu ioctl
2617:Parameters: None
2618:Returns: 0 on success, -1 on error
Eric B Munson1c0b28c2012-03-10 14:37:27 -05002619
Joshua Abraham35c59992020-05-01 18:36:24 -04002620This ioctl sets a flag accessible to the guest indicating that the specified
2621vCPU has been paused by the host userspace.
2622
2623The host will set a flag in the pvclock structure that is checked from the
2624soft lockup watchdog. The flag is part of the pvclock structure that is
2625shared between guest and host, specifically the second bit of the flags
Eric B Munson1c0b28c2012-03-10 14:37:27 -05002626field of the pvclock_vcpu_time_info structure. It will be set exclusively by
2627the host and read/cleared exclusively by the guest. The guest operation of
Joshua Abraham35c59992020-05-01 18:36:24 -04002628checking and clearing the flag must be an atomic operation so
Eric B Munson1c0b28c2012-03-10 14:37:27 -05002629load-link/store-conditional, or equivalent must be used. There are two cases
2630where the guest will clear the flag: when the soft lockup watchdog timer resets
2631itself or when a soft lockup is detected. This ioctl can be called any time
2632after pausing the vcpu, but before it is resumed.
2633
Jan Kiszka414fa982012-04-24 16:40:15 +02002634
Jan Kiszka07975ad2012-03-29 21:14:12 +020026354.71 KVM_SIGNAL_MSI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002636-------------------
Jan Kiszka07975ad2012-03-29 21:14:12 +02002637
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002638:Capability: KVM_CAP_SIGNAL_MSI
2639:Architectures: x86 arm arm64
2640:Type: vm ioctl
2641:Parameters: struct kvm_msi (in)
2642:Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error
Jan Kiszka07975ad2012-03-29 21:14:12 +02002643
2644Directly inject a MSI message. Only valid with in-kernel irqchip that handles
2645MSI messages.
2646
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002647::
2648
2649 struct kvm_msi {
Jan Kiszka07975ad2012-03-29 21:14:12 +02002650 __u32 address_lo;
2651 __u32 address_hi;
2652 __u32 data;
2653 __u32 flags;
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002654 __u32 devid;
2655 __u8 pad[12];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002656 };
Jan Kiszka07975ad2012-03-29 21:14:12 +02002657
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002658flags:
2659 KVM_MSI_VALID_DEVID: devid contains a valid value. The per-VM
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002660 KVM_CAP_MSI_DEVID capability advertises the requirement to provide
2661 the device ID. If this capability is not available, userspace
2662 should never set the KVM_MSI_VALID_DEVID flag as the ioctl might fail.
Andre Przywara2b8ddd92016-07-15 12:43:24 +01002663
Paolo Bonzini6f49b2f2016-08-04 13:59:56 +02002664If KVM_MSI_VALID_DEVID is set, devid contains a unique device identifier
2665for the device that wrote the MSI message. For PCI, this is usually a
2666BFD identifier in the lower 16 bits.
Jan Kiszka07975ad2012-03-29 21:14:12 +02002667
Paolo Bonzini055b6ae2016-08-04 14:01:05 +02002668On x86, address_hi is ignored unless the KVM_X2APIC_API_USE_32BIT_IDS
2669feature of KVM_CAP_X2APIC_API capability is enabled. If it is enabled,
2670address_hi bits 31-8 provide bits 31-8 of the destination id. Bits 7-0 of
2671address_hi must be zero.
Radim Krčmář371313132016-07-12 22:09:27 +02002672
Jan Kiszka414fa982012-04-24 16:40:15 +02002673
Jan Kiszka0589ff62012-04-24 16:40:16 +020026744.71 KVM_CREATE_PIT2
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002675--------------------
Jan Kiszka0589ff62012-04-24 16:40:16 +02002676
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002677:Capability: KVM_CAP_PIT2
2678:Architectures: x86
2679:Type: vm ioctl
2680:Parameters: struct kvm_pit_config (in)
2681:Returns: 0 on success, -1 on error
Jan Kiszka0589ff62012-04-24 16:40:16 +02002682
2683Creates an in-kernel device model for the i8254 PIT. This call is only valid
2684after enabling in-kernel irqchip support via KVM_CREATE_IRQCHIP. The following
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002685parameters have to be passed::
Jan Kiszka0589ff62012-04-24 16:40:16 +02002686
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002687 struct kvm_pit_config {
Jan Kiszka0589ff62012-04-24 16:40:16 +02002688 __u32 flags;
2689 __u32 pad[15];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002690 };
Jan Kiszka0589ff62012-04-24 16:40:16 +02002691
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002692Valid flags are::
Jan Kiszka0589ff62012-04-24 16:40:16 +02002693
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002694 #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */
Jan Kiszka0589ff62012-04-24 16:40:16 +02002695
Jan Kiszkab6ddf052012-04-24 16:40:17 +02002696PIT timer interrupts may use a per-VM kernel thread for injection. If it
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002697exists, this thread will have a name of the following pattern::
Jan Kiszkab6ddf052012-04-24 16:40:17 +02002698
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002699 kvm-pit/<owner-process-pid>
Jan Kiszkab6ddf052012-04-24 16:40:17 +02002700
2701When running a guest with elevated priorities, the scheduling parameters of
2702this thread may have to be adjusted accordingly.
2703
Jan Kiszka0589ff62012-04-24 16:40:16 +02002704This IOCTL replaces the obsolete KVM_CREATE_PIT.
2705
2706
27074.72 KVM_GET_PIT2
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002708-----------------
Jan Kiszka0589ff62012-04-24 16:40:16 +02002709
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002710:Capability: KVM_CAP_PIT_STATE2
2711:Architectures: x86
2712:Type: vm ioctl
2713:Parameters: struct kvm_pit_state2 (out)
2714:Returns: 0 on success, -1 on error
Jan Kiszka0589ff62012-04-24 16:40:16 +02002715
2716Retrieves the state of the in-kernel PIT model. Only valid after
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002717KVM_CREATE_PIT2. The state is returned in the following structure::
Jan Kiszka0589ff62012-04-24 16:40:16 +02002718
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002719 struct kvm_pit_state2 {
Jan Kiszka0589ff62012-04-24 16:40:16 +02002720 struct kvm_pit_channel_state channels[3];
2721 __u32 flags;
2722 __u32 reserved[9];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002723 };
Jan Kiszka0589ff62012-04-24 16:40:16 +02002724
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002725Valid flags are::
Jan Kiszka0589ff62012-04-24 16:40:16 +02002726
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002727 /* disable PIT in HPET legacy mode */
2728 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
Jan Kiszka0589ff62012-04-24 16:40:16 +02002729
2730This IOCTL replaces the obsolete KVM_GET_PIT.
2731
2732
27334.73 KVM_SET_PIT2
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002734-----------------
Jan Kiszka0589ff62012-04-24 16:40:16 +02002735
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002736:Capability: KVM_CAP_PIT_STATE2
2737:Architectures: x86
2738:Type: vm ioctl
2739:Parameters: struct kvm_pit_state2 (in)
2740:Returns: 0 on success, -1 on error
Jan Kiszka0589ff62012-04-24 16:40:16 +02002741
2742Sets the state of the in-kernel PIT model. Only valid after KVM_CREATE_PIT2.
2743See KVM_GET_PIT2 for details on struct kvm_pit_state2.
2744
2745This IOCTL replaces the obsolete KVM_SET_PIT.
2746
2747
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000027484.74 KVM_PPC_GET_SMMU_INFO
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002749--------------------------
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002750
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002751:Capability: KVM_CAP_PPC_GET_SMMU_INFO
2752:Architectures: powerpc
2753:Type: vm ioctl
2754:Parameters: None
2755:Returns: 0 on success, -1 on error
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002756
2757This populates and returns a structure describing the features of
2758the "Server" class MMU emulation supported by KVM.
Stefan Hubercc22c352013-06-05 12:24:37 +02002759This can in turn be used by userspace to generate the appropriate
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002760device-tree properties for the guest operating system.
2761
Carlos Garciac98be0c2014-04-04 22:31:00 -04002762The structure contains some global information, followed by an
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002763array of supported segment page sizes::
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002764
2765 struct kvm_ppc_smmu_info {
2766 __u64 flags;
2767 __u32 slb_size;
2768 __u32 pad;
2769 struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
2770 };
2771
2772The supported flags are:
2773
2774 - KVM_PPC_PAGE_SIZES_REAL:
2775 When that flag is set, guest page sizes must "fit" the backing
2776 store page sizes. When not set, any page size in the list can
2777 be used regardless of how they are backed by userspace.
2778
2779 - KVM_PPC_1T_SEGMENTS
2780 The emulated MMU supports 1T segments in addition to the
2781 standard 256M ones.
2782
Paul Mackerras901f8c32018-10-08 14:24:30 +11002783 - KVM_PPC_NO_HASH
2784 This flag indicates that HPT guests are not supported by KVM,
2785 thus all guests must use radix MMU mode.
2786
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002787The "slb_size" field indicates how many SLB entries are supported
2788
2789The "sps" array contains 8 entries indicating the supported base
2790page sizes for a segment in increasing order. Each entry is defined
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002791as follow::
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002792
2793 struct kvm_ppc_one_seg_page_size {
2794 __u32 page_shift; /* Base page shift of segment (or 0) */
2795 __u32 slb_enc; /* SLB encoding for BookS */
2796 struct kvm_ppc_one_page_size enc[KVM_PPC_PAGE_SIZES_MAX_SZ];
2797 };
2798
2799An entry with a "page_shift" of 0 is unused. Because the array is
2800organized in increasing order, a lookup can stop when encoutering
2801such an entry.
2802
2803The "slb_enc" field provides the encoding to use in the SLB for the
2804page size. The bits are in positions such as the value can directly
2805be OR'ed into the "vsid" argument of the slbmte instruction.
2806
2807The "enc" array is a list which for each of those segment base page
2808size provides the list of supported actual page sizes (which can be
2809only larger or equal to the base page size), along with the
Anatol Pomozovf884ab12013-05-08 16:56:16 -07002810corresponding encoding in the hash PTE. Similarly, the array is
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +000028118 entries sorted by increasing sizes and an entry with a "0" shift
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002812is an empty entry and a terminator::
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +00002813
2814 struct kvm_ppc_one_page_size {
2815 __u32 page_shift; /* Page shift (or 0) */
2816 __u32 pte_enc; /* Encoding in the HPTE (>>12) */
2817 };
2818
2819The "pte_enc" field provides a value that can OR'ed into the hash
2820PTE's RPN field (ie, it needs to be shifted left by 12 to OR it
2821into the hash PTE second double word).
2822
Alex Williamsonf36992e2012-06-29 09:56:16 -060028234.75 KVM_IRQFD
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002824--------------
Alex Williamsonf36992e2012-06-29 09:56:16 -06002825
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002826:Capability: KVM_CAP_IRQFD
2827:Architectures: x86 s390 arm arm64
2828:Type: vm ioctl
2829:Parameters: struct kvm_irqfd (in)
2830:Returns: 0 on success, -1 on error
Alex Williamsonf36992e2012-06-29 09:56:16 -06002831
2832Allows setting an eventfd to directly trigger a guest interrupt.
2833kvm_irqfd.fd specifies the file descriptor to use as the eventfd and
2834kvm_irqfd.gsi specifies the irqchip pin toggled by this event. When
Masanari Iida17180032013-12-22 01:21:23 +09002835an event is triggered on the eventfd, an interrupt is injected into
Alex Williamsonf36992e2012-06-29 09:56:16 -06002836the guest using the specified gsi pin. The irqfd is removed using
2837the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
2838and kvm_irqfd.gsi.
2839
Alex Williamson7a844282012-09-21 11:58:03 -06002840With KVM_CAP_IRQFD_RESAMPLE, KVM_IRQFD supports a de-assert and notify
2841mechanism allowing emulation of level-triggered, irqfd-based
2842interrupts. When KVM_IRQFD_FLAG_RESAMPLE is set the user must pass an
2843additional eventfd in the kvm_irqfd.resamplefd field. When operating
2844in resample mode, posting of an interrupt through kvm_irq.fd asserts
2845the specified gsi in the irqchip. When the irqchip is resampled, such
Masanari Iida17180032013-12-22 01:21:23 +09002846as from an EOI, the gsi is de-asserted and the user is notified via
Alex Williamson7a844282012-09-21 11:58:03 -06002847kvm_irqfd.resamplefd. It is the user's responsibility to re-queue
2848the interrupt if the device making use of it still requires service.
2849Note that closing the resamplefd is not sufficient to disable the
2850irqfd. The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
2851and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
2852
Eric Auger180ae7b2016-07-22 16:20:41 +00002853On arm/arm64, gsi routing being supported, the following can happen:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002854
Eric Auger180ae7b2016-07-22 16:20:41 +00002855- in case no routing entry is associated to this gsi, injection fails
2856- in case the gsi is associated to an irqchip routing entry,
2857 irqchip.pin + 32 corresponds to the injected SPI ID.
Eric Auger995a0ee2016-07-22 16:20:42 +00002858- in case the gsi is associated to an MSI routing entry, the MSI
2859 message and device ID are translated into an LPI (support restricted
2860 to GICv3 ITS in-kernel emulation).
Eric Auger174178f2015-03-04 11:14:36 +01002861
Linus Torvalds5fecc9d2012-07-24 12:01:20 -070028624.76 KVM_PPC_ALLOCATE_HTAB
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002863--------------------------
Paul Mackerras32fad282012-05-04 02:32:53 +00002864
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002865:Capability: KVM_CAP_PPC_ALLOC_HTAB
2866:Architectures: powerpc
2867:Type: vm ioctl
2868:Parameters: Pointer to u32 containing hash table order (in/out)
2869:Returns: 0 on success, -1 on error
Paul Mackerras32fad282012-05-04 02:32:53 +00002870
2871This requests the host kernel to allocate an MMU hash table for a
2872guest using the PAPR paravirtualization interface. This only does
2873anything if the kernel is configured to use the Book 3S HV style of
2874virtualization. Otherwise the capability doesn't exist and the ioctl
2875returns an ENOTTY error. The rest of this description assumes Book 3S
2876HV.
2877
2878There must be no vcpus running when this ioctl is called; if there
2879are, it will do nothing and return an EBUSY error.
2880
2881The parameter is a pointer to a 32-bit unsigned integer variable
2882containing the order (log base 2) of the desired size of the hash
2883table, which must be between 18 and 46. On successful return from the
David Gibsonf98a8bf2016-12-20 16:49:03 +11002884ioctl, the value will not be changed by the kernel.
Paul Mackerras32fad282012-05-04 02:32:53 +00002885
2886If no hash table has been allocated when any vcpu is asked to run
2887(with the KVM_RUN ioctl), the host kernel will allocate a
2888default-sized hash table (16 MB).
2889
2890If this ioctl is called when a hash table has already been allocated,
David Gibsonf98a8bf2016-12-20 16:49:03 +11002891with a different order from the existing hash table, the existing hash
2892table will be freed and a new one allocated. If this is ioctl is
2893called when a hash table has already been allocated of the same order
2894as specified, the kernel will clear out the existing hash table (zero
2895all HPTEs). In either case, if the guest is using the virtualized
2896real-mode area (VRMA) facility, the kernel will re-create the VMRA
2897HPTEs on the next KVM_RUN of any vcpu.
Paul Mackerras32fad282012-05-04 02:32:53 +00002898
Cornelia Huck416ad652012-10-02 16:25:37 +020028994.77 KVM_S390_INTERRUPT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002900-----------------------
Cornelia Huck416ad652012-10-02 16:25:37 +02002901
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002902:Capability: basic
2903:Architectures: s390
2904:Type: vm ioctl, vcpu ioctl
2905:Parameters: struct kvm_s390_interrupt (in)
2906:Returns: 0 on success, -1 on error
Cornelia Huck416ad652012-10-02 16:25:37 +02002907
2908Allows to inject an interrupt to the guest. Interrupts can be floating
2909(vm ioctl) or per cpu (vcpu ioctl), depending on the interrupt type.
2910
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002911Interrupt parameters are passed via kvm_s390_interrupt::
Cornelia Huck416ad652012-10-02 16:25:37 +02002912
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002913 struct kvm_s390_interrupt {
Cornelia Huck416ad652012-10-02 16:25:37 +02002914 __u32 type;
2915 __u32 parm;
2916 __u64 parm64;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002917 };
Cornelia Huck416ad652012-10-02 16:25:37 +02002918
2919type can be one of the following:
2920
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002921KVM_S390_SIGP_STOP (vcpu)
2922 - sigp stop; optional flags in parm
2923KVM_S390_PROGRAM_INT (vcpu)
2924 - program check; code in parm
2925KVM_S390_SIGP_SET_PREFIX (vcpu)
2926 - sigp set prefix; prefix address in parm
2927KVM_S390_RESTART (vcpu)
2928 - restart
2929KVM_S390_INT_CLOCK_COMP (vcpu)
2930 - clock comparator interrupt
2931KVM_S390_INT_CPU_TIMER (vcpu)
2932 - CPU timer interrupt
2933KVM_S390_INT_VIRTIO (vm)
2934 - virtio external interrupt; external interrupt
2935 parameters in parm and parm64
2936KVM_S390_INT_SERVICE (vm)
2937 - sclp external interrupt; sclp parameter in parm
2938KVM_S390_INT_EMERGENCY (vcpu)
2939 - sigp emergency; source cpu in parm
2940KVM_S390_INT_EXTERNAL_CALL (vcpu)
2941 - sigp external call; source cpu in parm
2942KVM_S390_INT_IO(ai,cssid,ssid,schid) (vm)
2943 - compound value to indicate an
2944 I/O interrupt (ai - adapter interrupt; cssid,ssid,schid - subchannel);
2945 I/O interruption parameters in parm (subchannel) and parm64 (intparm,
2946 interruption subclass)
2947KVM_S390_MCHK (vm, vcpu)
2948 - machine check interrupt; cr 14 bits in parm, machine check interrupt
2949 code in parm64 (note that machine checks needing further payload are not
2950 supported by this ioctl)
Cornelia Huck416ad652012-10-02 16:25:37 +02002951
Sean Christopherson5e124902019-02-15 12:48:38 -08002952This is an asynchronous vcpu ioctl and can be invoked from any thread.
Cornelia Huck416ad652012-10-02 16:25:37 +02002953
Paul Mackerrasa2932922012-11-19 22:57:20 +000029544.78 KVM_PPC_GET_HTAB_FD
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002955------------------------
Paul Mackerrasa2932922012-11-19 22:57:20 +00002956
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002957:Capability: KVM_CAP_PPC_HTAB_FD
2958:Architectures: powerpc
2959:Type: vm ioctl
2960:Parameters: Pointer to struct kvm_get_htab_fd (in)
2961:Returns: file descriptor number (>= 0) on success, -1 on error
Paul Mackerrasa2932922012-11-19 22:57:20 +00002962
2963This returns a file descriptor that can be used either to read out the
2964entries in the guest's hashed page table (HPT), or to write entries to
2965initialize the HPT. The returned fd can only be written to if the
2966KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
2967can only be read if that bit is clear. The argument struct looks like
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002968this::
Paul Mackerrasa2932922012-11-19 22:57:20 +00002969
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002970 /* For KVM_PPC_GET_HTAB_FD */
2971 struct kvm_get_htab_fd {
Paul Mackerrasa2932922012-11-19 22:57:20 +00002972 __u64 flags;
2973 __u64 start_index;
2974 __u64 reserved[2];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002975 };
Paul Mackerrasa2932922012-11-19 22:57:20 +00002976
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002977 /* Values for kvm_get_htab_fd.flags */
2978 #define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
2979 #define KVM_GET_HTAB_WRITE ((__u64)0x2)
Paul Mackerrasa2932922012-11-19 22:57:20 +00002980
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002981The 'start_index' field gives the index in the HPT of the entry at
Paul Mackerrasa2932922012-11-19 22:57:20 +00002982which to start reading. It is ignored when writing.
2983
2984Reads on the fd will initially supply information about all
2985"interesting" HPT entries. Interesting entries are those with the
2986bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
2987all entries. When the end of the HPT is reached, the read() will
2988return. If read() is called again on the fd, it will start again from
2989the beginning of the HPT, but will only return HPT entries that have
2990changed since they were last read.
2991
2992Data read or written is structured as a header (8 bytes) followed by a
2993series of valid HPT entries (16 bytes) each. The header indicates how
2994many valid HPT entries there are and how many invalid entries follow
2995the valid entries. The invalid entries are not represented explicitly
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002996in the stream. The header format is::
Paul Mackerrasa2932922012-11-19 22:57:20 +00002997
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01002998 struct kvm_get_htab_header {
Paul Mackerrasa2932922012-11-19 22:57:20 +00002999 __u32 index;
3000 __u16 n_valid;
3001 __u16 n_invalid;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003002 };
Paul Mackerrasa2932922012-11-19 22:57:20 +00003003
3004Writes to the fd create HPT entries starting at the index given in the
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003005header; first 'n_valid' valid entries with contents from the data
3006written, then 'n_invalid' invalid entries, invalidating any previously
Paul Mackerrasa2932922012-11-19 22:57:20 +00003007valid entries found.
3008
Scott Wood852b6d52013-04-12 14:08:42 +000030094.79 KVM_CREATE_DEVICE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003010----------------------
Scott Wood852b6d52013-04-12 14:08:42 +00003011
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003012:Capability: KVM_CAP_DEVICE_CTRL
3013:Type: vm ioctl
3014:Parameters: struct kvm_create_device (in/out)
3015:Returns: 0 on success, -1 on error
3016
Scott Wood852b6d52013-04-12 14:08:42 +00003017Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003018
3019 ====== =======================================================
3020 ENODEV The device type is unknown or unsupported
3021 EEXIST Device already created, and this type of device may not
Scott Wood852b6d52013-04-12 14:08:42 +00003022 be instantiated multiple times
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003023 ====== =======================================================
Scott Wood852b6d52013-04-12 14:08:42 +00003024
3025 Other error conditions may be defined by individual device types or
3026 have their standard meanings.
3027
3028Creates an emulated device in the kernel. The file descriptor returned
3029in fd can be used with KVM_SET/GET/HAS_DEVICE_ATTR.
3030
3031If the KVM_CREATE_DEVICE_TEST flag is set, only test whether the
3032device type is supported (not necessarily whether it can be created
3033in the current vm).
3034
3035Individual devices should not define flags. Attributes should be used
3036for specifying any behavior that is not implied by the device type
3037number.
3038
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003039::
3040
3041 struct kvm_create_device {
Scott Wood852b6d52013-04-12 14:08:42 +00003042 __u32 type; /* in: KVM_DEV_TYPE_xxx */
3043 __u32 fd; /* out: device handle */
3044 __u32 flags; /* in: KVM_CREATE_DEVICE_xxx */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003045 };
Scott Wood852b6d52013-04-12 14:08:42 +00003046
30474.80 KVM_SET_DEVICE_ATTR/KVM_GET_DEVICE_ATTR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003048--------------------------------------------
Scott Wood852b6d52013-04-12 14:08:42 +00003049
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003050:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3051 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3052:Type: device ioctl, vm ioctl, vcpu ioctl
3053:Parameters: struct kvm_device_attr
3054:Returns: 0 on success, -1 on error
3055
Scott Wood852b6d52013-04-12 14:08:42 +00003056Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003057
3058 ===== =============================================================
3059 ENXIO The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01003060 or hardware support is missing.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003061 EPERM The attribute cannot (currently) be accessed this way
Scott Wood852b6d52013-04-12 14:08:42 +00003062 (e.g. read-only attribute, or attribute that only makes
3063 sense when the device is in a different state)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003064 ===== =============================================================
Scott Wood852b6d52013-04-12 14:08:42 +00003065
3066 Other error conditions may be defined by individual device types.
3067
3068Gets/sets a specified piece of device configuration and/or state. The
3069semantics are device-specific. See individual device documentation in
3070the "devices" directory. As with ONE_REG, the size of the data
3071transferred is defined by the particular attribute.
3072
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003073::
3074
3075 struct kvm_device_attr {
Scott Wood852b6d52013-04-12 14:08:42 +00003076 __u32 flags; /* no flags currently defined */
3077 __u32 group; /* device-defined */
3078 __u64 attr; /* group-defined */
3079 __u64 addr; /* userspace address of attr data */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003080 };
Scott Wood852b6d52013-04-12 14:08:42 +00003081
30824.81 KVM_HAS_DEVICE_ATTR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003083------------------------
Scott Wood852b6d52013-04-12 14:08:42 +00003084
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003085:Capability: KVM_CAP_DEVICE_CTRL, KVM_CAP_VM_ATTRIBUTES for vm device,
3086 KVM_CAP_VCPU_ATTRIBUTES for vcpu device
3087:Type: device ioctl, vm ioctl, vcpu ioctl
3088:Parameters: struct kvm_device_attr
3089:Returns: 0 on success, -1 on error
3090
Scott Wood852b6d52013-04-12 14:08:42 +00003091Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003092
3093 ===== =============================================================
3094 ENXIO The group or attribute is unknown/unsupported for this device
David Hildenbrandf9cbd9b2016-03-03 09:48:47 +01003095 or hardware support is missing.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003096 ===== =============================================================
Scott Wood852b6d52013-04-12 14:08:42 +00003097
3098Tests whether a device supports a particular attribute. A successful
3099return indicates the attribute is implemented. It does not necessarily
3100indicate that the attribute can be read or written in the device's
3101current state. "addr" is ignored.
Alex Williamsonf36992e2012-06-29 09:56:16 -06003102
Alexey Kardashevskiyd8968f12013-06-19 11:42:07 +100031034.82 KVM_ARM_VCPU_INIT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003104----------------------
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003105
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003106:Capability: basic
3107:Architectures: arm, arm64
3108:Type: vcpu ioctl
3109:Parameters: struct kvm_vcpu_init (in)
3110:Returns: 0 on success; -1 on error
3111
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003112Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003113
3114 ====== =================================================================
3115  EINVAL    the target is unknown, or the combination of features is invalid.
3116  ENOENT    a features bit specified is unknown.
3117 ====== =================================================================
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003118
3119This tells KVM what type of CPU to present to the guest, and what
3120optional features it should have.  This will cause a reset of the cpu
3121registers to their initial values.  If this is not called, KVM_RUN will
3122return ENOEXEC for that vcpu.
3123
Marc Zyngier5b32a532021-04-06 13:46:42 +01003124The initial values are defined as:
3125 - Processor state:
3126 * AArch64: EL1h, D, A, I and F bits set. All other bits
3127 are cleared.
3128 * AArch32: SVC, A, I and F bits set. All other bits are
3129 cleared.
3130 - General Purpose registers, including PC and SP: set to 0
3131 - FPSIMD/NEON registers: set to 0
3132 - SVE registers: set to 0
3133 - System registers: Reset to their architecturally defined
3134 values as for a warm reset to EL1 (resp. SVC)
3135
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003136Note that because some registers reflect machine topology, all vcpus
3137should be created before this ioctl is invoked.
3138
Christoffer Dallf7fa034d2014-10-16 16:40:53 +02003139Userspace can call this function multiple times for a given vcpu, including
3140after the vcpu has been run. This will reset the vcpu to its initial
3141state. All calls to this function after the initial call must use the same
3142target and same set of feature flags, otherwise EINVAL will be returned.
3143
Marc Zyngieraa024c22013-01-20 18:28:13 -05003144Possible features:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003145
Marc Zyngieraa024c22013-01-20 18:28:13 -05003146 - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state.
Christoffer Dall3ad8b3d2014-10-16 16:14:43 +02003147 Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on
3148 and execute guest code when KVM_RUN is called.
Marc Zyngier379e04c72013-04-02 17:46:31 +01003149 - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode.
3150 Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
Marc Zyngier85bd0ba2018-01-21 16:42:56 +00003151 - KVM_ARM_VCPU_PSCI_0_2: Emulate PSCI v0.2 (or a future revision
3152 backward compatible with v0.2) for the CPU.
Anup Patel50bb0c92014-04-29 11:24:17 +05303153 Depends on KVM_CAP_ARM_PSCI_0_2.
Shannon Zhao808e7382016-01-11 22:46:15 +08003154 - KVM_ARM_VCPU_PMU_V3: Emulate PMUv3 for the CPU.
3155 Depends on KVM_CAP_ARM_PMU_V3.
Marc Zyngieraa024c22013-01-20 18:28:13 -05003156
Amit Daniel Kachhapa22fa322019-04-23 10:12:36 +05303157 - KVM_ARM_VCPU_PTRAUTH_ADDRESS: Enables Address Pointer authentication
3158 for arm64 only.
Amit Daniel Kachhapa243c162019-04-23 10:12:37 +05303159 Depends on KVM_CAP_ARM_PTRAUTH_ADDRESS.
3160 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3161 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3162 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3163 requested.
Amit Daniel Kachhapa22fa322019-04-23 10:12:36 +05303164
3165 - KVM_ARM_VCPU_PTRAUTH_GENERIC: Enables Generic Pointer authentication
3166 for arm64 only.
Amit Daniel Kachhapa243c162019-04-23 10:12:37 +05303167 Depends on KVM_CAP_ARM_PTRAUTH_GENERIC.
3168 If KVM_CAP_ARM_PTRAUTH_ADDRESS and KVM_CAP_ARM_PTRAUTH_GENERIC are
3169 both present, then both KVM_ARM_VCPU_PTRAUTH_ADDRESS and
3170 KVM_ARM_VCPU_PTRAUTH_GENERIC must be requested or neither must be
3171 requested.
Amit Daniel Kachhapa22fa322019-04-23 10:12:36 +05303172
Dave Martin50036ad2018-09-28 14:39:27 +01003173 - KVM_ARM_VCPU_SVE: Enables SVE for the CPU (arm64 only).
3174 Depends on KVM_CAP_ARM_SVE.
3175 Requires KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3176
3177 * After KVM_ARM_VCPU_INIT:
3178
3179 - KVM_REG_ARM64_SVE_VLS may be read using KVM_GET_ONE_REG: the
3180 initial value of this pseudo-register indicates the best set of
3181 vector lengths possible for a vcpu on this host.
3182
3183 * Before KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3184
3185 - KVM_RUN and KVM_GET_REG_LIST are not available;
3186
3187 - KVM_GET_ONE_REG and KVM_SET_ONE_REG cannot be used to access
3188 the scalable archietctural SVE registers
3189 KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() or
3190 KVM_REG_ARM64_SVE_FFR;
3191
3192 - KVM_REG_ARM64_SVE_VLS may optionally be written using
3193 KVM_SET_ONE_REG, to modify the set of vector lengths available
3194 for the vcpu.
3195
3196 * After KVM_ARM_VCPU_FINALIZE(KVM_ARM_VCPU_SVE):
3197
3198 - the KVM_REG_ARM64_SVE_VLS pseudo-register is immutable, and can
3199 no longer be written using KVM_SET_ONE_REG.
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003200
Anup Patel740edfc2013-09-30 14:20:08 +053032014.83 KVM_ARM_PREFERRED_TARGET
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003202-----------------------------
Anup Patel740edfc2013-09-30 14:20:08 +05303203
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003204:Capability: basic
3205:Architectures: arm, arm64
3206:Type: vm ioctl
Randy Dunlapa84b7572020-07-07 11:04:14 -07003207:Parameters: struct kvm_vcpu_init (out)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003208:Returns: 0 on success; -1 on error
3209
Anup Patel740edfc2013-09-30 14:20:08 +05303210Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003211
3212 ====== ==========================================
3213 ENODEV no preferred target available for the host
3214 ====== ==========================================
Anup Patel740edfc2013-09-30 14:20:08 +05303215
3216This queries KVM for preferred CPU target type which can be emulated
3217by KVM on underlying host.
3218
3219The ioctl returns struct kvm_vcpu_init instance containing information
3220about preferred CPU target type and recommended features for it. The
3221kvm_vcpu_init->features bitmap returned will have feature bits set if
3222the preferred target recommends setting these features, but this is
3223not mandatory.
3224
3225The information returned by this ioctl can be used to prepare an instance
3226of struct kvm_vcpu_init for KVM_ARM_VCPU_INIT ioctl which will result in
Randy Dunlap3747c5d2020-07-03 14:29:06 -07003227VCPU matching underlying host.
Anup Patel740edfc2013-09-30 14:20:08 +05303228
3229
32304.84 KVM_GET_REG_LIST
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003231---------------------
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003232
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003233:Capability: basic
3234:Architectures: arm, arm64, mips
3235:Type: vcpu ioctl
3236:Parameters: struct kvm_reg_list (in/out)
3237:Returns: 0 on success; -1 on error
3238
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003239Errors:
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003240
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003241 ===== ==============================================================
3242  E2BIG     the reg index list is too big to fit in the array specified by
3243             the user (the number required will be written into n).
3244 ===== ==============================================================
3245
3246::
3247
3248 struct kvm_reg_list {
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003249 __u64 n; /* number of registers in reg[] */
3250 __u64 reg[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003251 };
Christoffer Dall749cf76c2013-01-20 18:28:06 -05003252
3253This ioctl returns the guest registers that are supported for the
3254KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
3255
Christoffer Dallce01e4e2013-09-23 14:55:56 -07003256
32574.85 KVM_ARM_SET_DEVICE_ADDR (deprecated)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003258-----------------------------------------
Christoffer Dall3401d5462013-01-23 13:18:04 -05003259
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003260:Capability: KVM_CAP_ARM_SET_DEVICE_ADDR
3261:Architectures: arm, arm64
3262:Type: vm ioctl
3263:Parameters: struct kvm_arm_device_address (in)
3264:Returns: 0 on success, -1 on error
3265
Christoffer Dall3401d5462013-01-23 13:18:04 -05003266Errors:
Christoffer Dall3401d5462013-01-23 13:18:04 -05003267
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003268 ====== ============================================
3269 ENODEV The device id is unknown
3270 ENXIO Device not supported on current system
3271 EEXIST Address already set
3272 E2BIG Address outside guest physical address space
3273 EBUSY Address overlaps with other device range
3274 ====== ============================================
3275
3276::
3277
3278 struct kvm_arm_device_addr {
Christoffer Dall3401d5462013-01-23 13:18:04 -05003279 __u64 id;
3280 __u64 addr;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003281 };
Christoffer Dall3401d5462013-01-23 13:18:04 -05003282
3283Specify a device address in the guest's physical address space where guests
3284can access emulated or directly exposed devices, which the host kernel needs
3285to know about. The id field is an architecture specific identifier for a
3286specific device.
3287
Marc Zyngier379e04c72013-04-02 17:46:31 +01003288ARM/arm64 divides the id field into two parts, a device id and an
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003289address type id specific to the individual device::
Christoffer Dall3401d5462013-01-23 13:18:04 -05003290
3291  bits: | 63 ... 32 | 31 ... 16 | 15 ... 0 |
3292 field: | 0x00000000 | device id | addr type id |
3293
Marc Zyngier379e04c72013-04-02 17:46:31 +01003294ARM/arm64 currently only require this when using the in-kernel GIC
3295support for the hardware VGIC features, using KVM_ARM_DEVICE_VGIC_V2
3296as the device id. When setting the base address for the guest's
3297mapping of the VGIC virtual CPU and distributor interface, the ioctl
3298must be called after calling KVM_CREATE_IRQCHIP, but before calling
3299KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the
3300base addresses will return -EEXIST.
Christoffer Dall3401d5462013-01-23 13:18:04 -05003301
Christoffer Dallce01e4e2013-09-23 14:55:56 -07003302Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API
3303should be used instead.
3304
3305
Anup Patel740edfc2013-09-30 14:20:08 +053033064.86 KVM_PPC_RTAS_DEFINE_TOKEN
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003307------------------------------
Michael Ellerman8e591cb2013-04-17 20:30:00 +00003308
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003309:Capability: KVM_CAP_PPC_RTAS
3310:Architectures: ppc
3311:Type: vm ioctl
3312:Parameters: struct kvm_rtas_token_args
3313:Returns: 0 on success, -1 on error
Michael Ellerman8e591cb2013-04-17 20:30:00 +00003314
3315Defines a token value for a RTAS (Run Time Abstraction Services)
3316service in order to allow it to be handled in the kernel. The
3317argument struct gives the name of the service, which must be the name
3318of a service that has a kernel-side implementation. If the token
3319value is non-zero, it will be associated with that service, and
3320subsequent RTAS calls by the guest specifying that token will be
3321handled by the kernel. If the token value is 0, then any token
3322associated with the service will be forgotten, and subsequent RTAS
3323calls by the guest for that service will be passed to userspace to be
3324handled.
3325
Alex Bennée4bd9d342014-09-09 17:27:18 +010033264.87 KVM_SET_GUEST_DEBUG
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003327------------------------
Alex Bennée4bd9d342014-09-09 17:27:18 +01003328
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003329:Capability: KVM_CAP_SET_GUEST_DEBUG
3330:Architectures: x86, s390, ppc, arm64
3331:Type: vcpu ioctl
3332:Parameters: struct kvm_guest_debug (in)
3333:Returns: 0 on success; -1 on error
Alex Bennée4bd9d342014-09-09 17:27:18 +01003334
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003335::
3336
3337 struct kvm_guest_debug {
Alex Bennée4bd9d342014-09-09 17:27:18 +01003338 __u32 control;
3339 __u32 pad;
3340 struct kvm_guest_debug_arch arch;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003341 };
Alex Bennée4bd9d342014-09-09 17:27:18 +01003342
3343Set up the processor specific debug registers and configure vcpu for
3344handling guest debug events. There are two parts to the structure, the
3345first a control bitfield indicates the type of debug events to handle
3346when running. Common control bits are:
3347
3348 - KVM_GUESTDBG_ENABLE: guest debugging is enabled
3349 - KVM_GUESTDBG_SINGLESTEP: the next run should single-step
3350
3351The top 16 bits of the control field are architecture specific control
3352flags which can include the following:
3353
Alex Bennée4bd611c2015-07-07 17:29:57 +01003354 - KVM_GUESTDBG_USE_SW_BP: using software breakpoints [x86, arm64]
Alexandru Eliseifeb5dc32021-04-07 15:48:56 +01003355 - KVM_GUESTDBG_USE_HW_BP: using hardware breakpoints [x86, s390]
3356 - KVM_GUESTDBG_USE_HW: using hardware debug events [arm64]
Alex Bennée4bd9d342014-09-09 17:27:18 +01003357 - KVM_GUESTDBG_INJECT_DB: inject DB type exception [x86]
3358 - KVM_GUESTDBG_INJECT_BP: inject BP type exception [x86]
3359 - KVM_GUESTDBG_EXIT_PENDING: trigger an immediate guest exit [s390]
3360
3361For example KVM_GUESTDBG_USE_SW_BP indicates that software breakpoints
3362are enabled in memory so we need to ensure breakpoint exceptions are
3363correctly trapped and the KVM run loop exits at the breakpoint and not
3364running off into the normal guest vector. For KVM_GUESTDBG_USE_HW_BP
3365we need to ensure the guest vCPUs architecture specific registers are
3366updated to the correct (supplied) values.
3367
3368The second part of the structure is architecture specific and
3369typically contains a set of debug registers.
3370
Alex Bennée834bf882015-07-07 17:30:02 +01003371For arm64 the number of debug registers is implementation defined and
3372can be determined by querying the KVM_CAP_GUEST_DEBUG_HW_BPS and
3373KVM_CAP_GUEST_DEBUG_HW_WPS capabilities which return a positive number
3374indicating the number of supported registers.
3375
Fabiano Rosas1a9167a2019-06-19 13:01:27 -03003376For ppc, the KVM_CAP_PPC_GUEST_DEBUG_SSTEP capability indicates whether
3377the single-step debug event (KVM_GUESTDBG_SINGLESTEP) is supported.
3378
Paolo Bonzini8b13c362021-04-06 10:24:07 -04003379Also when supported, KVM_CAP_SET_GUEST_DEBUG2 capability indicates the
3380supported KVM_GUESTDBG_* bits in the control field.
3381
Alex Bennée4bd9d342014-09-09 17:27:18 +01003382When debug events exit the main run loop with the reason
3383KVM_EXIT_DEBUG with the kvm_debug_exit_arch part of the kvm_run
3384structure containing architecture specific debug information.
Christoffer Dall3401d5462013-01-23 13:18:04 -05003385
Alex Bennée209cf192014-09-09 17:27:19 +010033864.88 KVM_GET_EMULATED_CPUID
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003387---------------------------
Alex Bennée209cf192014-09-09 17:27:19 +01003388
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003389:Capability: KVM_CAP_EXT_EMUL_CPUID
3390:Architectures: x86
3391:Type: system ioctl
3392:Parameters: struct kvm_cpuid2 (in/out)
3393:Returns: 0 on success, -1 on error
Alex Bennée209cf192014-09-09 17:27:19 +01003394
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003395::
3396
3397 struct kvm_cpuid2 {
Alex Bennée209cf192014-09-09 17:27:19 +01003398 __u32 nent;
3399 __u32 flags;
3400 struct kvm_cpuid_entry2 entries[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003401 };
Alex Bennée209cf192014-09-09 17:27:19 +01003402
3403The member 'flags' is used for passing flags from userspace.
3404
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003405::
Alex Bennée209cf192014-09-09 17:27:19 +01003406
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003407 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX BIT(0)
Sean Christopherson7ff6c032020-03-02 15:56:51 -08003408 #define KVM_CPUID_FLAG_STATEFUL_FUNC BIT(1) /* deprecated */
3409 #define KVM_CPUID_FLAG_STATE_READ_NEXT BIT(2) /* deprecated */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003410
3411 struct kvm_cpuid_entry2 {
Alex Bennée209cf192014-09-09 17:27:19 +01003412 __u32 function;
3413 __u32 index;
3414 __u32 flags;
3415 __u32 eax;
3416 __u32 ebx;
3417 __u32 ecx;
3418 __u32 edx;
3419 __u32 padding[3];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003420 };
Alex Bennée209cf192014-09-09 17:27:19 +01003421
3422This ioctl returns x86 cpuid features which are emulated by
3423kvm.Userspace can use the information returned by this ioctl to query
3424which features are emulated by kvm instead of being present natively.
3425
3426Userspace invokes KVM_GET_EMULATED_CPUID by passing a kvm_cpuid2
3427structure with the 'nent' field indicating the number of entries in
3428the variable-size array 'entries'. If the number of entries is too low
3429to describe the cpu capabilities, an error (E2BIG) is returned. If the
3430number is too high, the 'nent' field is adjusted and an error (ENOMEM)
3431is returned. If the number is just right, the 'nent' field is adjusted
3432to the number of valid entries in the 'entries' array, which is then
3433filled.
3434
3435The entries returned are the set CPUID bits of the respective features
3436which kvm emulates, as returned by the CPUID instruction, with unknown
3437or unsupported feature bits cleared.
3438
3439Features like x2apic, for example, may not be present in the host cpu
3440but are exposed by kvm in KVM_GET_SUPPORTED_CPUID because they can be
3441emulated efficiently and thus not included here.
3442
3443The fields in each entry are defined as follows:
3444
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003445 function:
3446 the eax value used to obtain the entry
3447 index:
3448 the ecx value used to obtain the entry (for entries that are
Alex Bennée209cf192014-09-09 17:27:19 +01003449 affected by ecx)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003450 flags:
3451 an OR of zero or more of the following:
3452
Alex Bennée209cf192014-09-09 17:27:19 +01003453 KVM_CPUID_FLAG_SIGNIFCANT_INDEX:
3454 if the index field is valid
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003455
3456 eax, ebx, ecx, edx:
3457
3458 the values returned by the cpuid instruction for
Alex Bennée209cf192014-09-09 17:27:19 +01003459 this function/index combination
3460
Thomas Huth41408c282015-02-06 15:01:21 +010034614.89 KVM_S390_MEM_OP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003462--------------------
Thomas Huth41408c282015-02-06 15:01:21 +01003463
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003464:Capability: KVM_CAP_S390_MEM_OP
3465:Architectures: s390
3466:Type: vcpu ioctl
3467:Parameters: struct kvm_s390_mem_op (in)
3468:Returns: = 0 on success,
3469 < 0 on generic error (e.g. -EFAULT or -ENOMEM),
3470 > 0 if an exception occurred while walking the page tables
Thomas Huth41408c282015-02-06 15:01:21 +01003471
Masanari Iida5d4f6f32015-10-04 00:46:21 +09003472Read or write data from/to the logical (virtual) memory of a VCPU.
Thomas Huth41408c282015-02-06 15:01:21 +01003473
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003474Parameters are specified via the following structure::
Thomas Huth41408c282015-02-06 15:01:21 +01003475
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003476 struct kvm_s390_mem_op {
Thomas Huth41408c282015-02-06 15:01:21 +01003477 __u64 gaddr; /* the guest address */
3478 __u64 flags; /* flags */
3479 __u32 size; /* amount of bytes */
3480 __u32 op; /* type of operation */
3481 __u64 buf; /* buffer in userspace */
3482 __u8 ar; /* the access register number */
3483 __u8 reserved[31]; /* should be set to 0 */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003484 };
Thomas Huth41408c282015-02-06 15:01:21 +01003485
3486The type of operation is specified in the "op" field. It is either
3487KVM_S390_MEMOP_LOGICAL_READ for reading from logical memory space or
3488KVM_S390_MEMOP_LOGICAL_WRITE for writing to logical memory space. The
3489KVM_S390_MEMOP_F_CHECK_ONLY flag can be set in the "flags" field to check
3490whether the corresponding memory access would create an access exception
3491(without touching the data in the memory at the destination). In case an
3492access exception occurred while walking the MMU tables of the guest, the
3493ioctl returns a positive error number to indicate the type of exception.
3494This exception is also raised directly at the corresponding VCPU if the
3495flag KVM_S390_MEMOP_F_INJECT_EXCEPTION is set in the "flags" field.
3496
3497The start address of the memory region has to be specified in the "gaddr"
Cornelia Huckb4d863c2019-08-29 14:47:46 +02003498field, and the length of the region in the "size" field (which must not
3499be 0). The maximum value for "size" can be obtained by checking the
3500KVM_CAP_S390_MEM_OP capability. "buf" is the buffer supplied by the
3501userspace application where the read data should be written to for
3502KVM_S390_MEMOP_LOGICAL_READ, or where the data that should be written is
3503stored for a KVM_S390_MEMOP_LOGICAL_WRITE. When KVM_S390_MEMOP_F_CHECK_ONLY
3504is specified, "buf" is unused and can be NULL. "ar" designates the access
3505register number to be used; the valid range is 0..15.
Thomas Huth41408c282015-02-06 15:01:21 +01003506
3507The "reserved" field is meant for future extensions. It is not used by
3508KVM with the currently defined set of flags.
3509
Jason J. Herne30ee2a92014-09-23 09:23:01 -040035104.90 KVM_S390_GET_SKEYS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003511-----------------------
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003512
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003513:Capability: KVM_CAP_S390_SKEYS
3514:Architectures: s390
3515:Type: vm ioctl
3516:Parameters: struct kvm_s390_skeys
3517:Returns: 0 on success, KVM_S390_GET_KEYS_NONE if guest is not using storage
3518 keys, negative value on error
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003519
3520This ioctl is used to get guest storage key values on the s390
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003521architecture. The ioctl takes parameters via the kvm_s390_skeys struct::
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003522
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003523 struct kvm_s390_skeys {
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003524 __u64 start_gfn;
3525 __u64 count;
3526 __u64 skeydata_addr;
3527 __u32 flags;
3528 __u32 reserved[9];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003529 };
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003530
3531The start_gfn field is the number of the first guest frame whose storage keys
3532you want to get.
3533
3534The count field is the number of consecutive frames (starting from start_gfn)
3535whose storage keys to get. The count field must be at least 1 and the maximum
3536allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
3537will cause the ioctl to return -EINVAL.
3538
3539The skeydata_addr field is the address to a buffer large enough to hold count
3540bytes. This buffer will be filled with storage key data by the ioctl.
3541
35424.91 KVM_S390_SET_SKEYS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003543-----------------------
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003544
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003545:Capability: KVM_CAP_S390_SKEYS
3546:Architectures: s390
3547:Type: vm ioctl
3548:Parameters: struct kvm_s390_skeys
3549:Returns: 0 on success, negative value on error
Jason J. Herne30ee2a92014-09-23 09:23:01 -04003550
3551This ioctl is used to set guest storage key values on the s390
3552architecture. The ioctl takes parameters via the kvm_s390_skeys struct.
3553See section on KVM_S390_GET_SKEYS for struct definition.
3554
3555The start_gfn field is the number of the first guest frame whose storage keys
3556you want to set.
3557
3558The count field is the number of consecutive frames (starting from start_gfn)
3559whose storage keys to get. The count field must be at least 1 and the maximum
3560allowed value is defined as KVM_S390_SKEYS_ALLOC_MAX. Values outside this range
3561will cause the ioctl to return -EINVAL.
3562
3563The skeydata_addr field is the address to a buffer containing count bytes of
3564storage keys. Each byte in the buffer will be set as the storage key for a
3565single frame starting at start_gfn for count frames.
3566
3567Note: If any architecturally invalid key value is found in the given data then
3568the ioctl will return -EINVAL.
3569
Jens Freimann47b43c52014-11-11 20:57:06 +010035704.92 KVM_S390_IRQ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003571-----------------
Jens Freimann47b43c52014-11-11 20:57:06 +01003572
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003573:Capability: KVM_CAP_S390_INJECT_IRQ
3574:Architectures: s390
3575:Type: vcpu ioctl
3576:Parameters: struct kvm_s390_irq (in)
3577:Returns: 0 on success, -1 on error
3578
Jens Freimann47b43c52014-11-11 20:57:06 +01003579Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003580
3581
3582 ====== =================================================================
3583 EINVAL interrupt type is invalid
3584 type is KVM_S390_SIGP_STOP and flag parameter is invalid value,
Jens Freimann47b43c52014-11-11 20:57:06 +01003585 type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003586 than the maximum of VCPUs
3587 EBUSY type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped,
3588 type is KVM_S390_SIGP_STOP and a stop irq is already pending,
Jens Freimann47b43c52014-11-11 20:57:06 +01003589 type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003590 is already pending
3591 ====== =================================================================
Jens Freimann47b43c52014-11-11 20:57:06 +01003592
3593Allows to inject an interrupt to the guest.
3594
3595Using struct kvm_s390_irq as a parameter allows
3596to inject additional payload which is not
3597possible via KVM_S390_INTERRUPT.
3598
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003599Interrupt parameters are passed via kvm_s390_irq::
Jens Freimann47b43c52014-11-11 20:57:06 +01003600
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003601 struct kvm_s390_irq {
Jens Freimann47b43c52014-11-11 20:57:06 +01003602 __u64 type;
3603 union {
3604 struct kvm_s390_io_info io;
3605 struct kvm_s390_ext_info ext;
3606 struct kvm_s390_pgm_info pgm;
3607 struct kvm_s390_emerg_info emerg;
3608 struct kvm_s390_extcall_info extcall;
3609 struct kvm_s390_prefix_info prefix;
3610 struct kvm_s390_stop_info stop;
3611 struct kvm_s390_mchk_info mchk;
3612 char reserved[64];
3613 } u;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003614 };
Jens Freimann47b43c52014-11-11 20:57:06 +01003615
3616type can be one of the following:
3617
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003618- KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
3619- KVM_S390_PROGRAM_INT - program check; parameters in .pgm
3620- KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
3621- KVM_S390_RESTART - restart; no parameters
3622- KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
3623- KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
3624- KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
3625- KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
3626- KVM_S390_MCHK - machine check interrupt; parameters in .mchk
Jens Freimann47b43c52014-11-11 20:57:06 +01003627
Sean Christopherson5e124902019-02-15 12:48:38 -08003628This is an asynchronous vcpu ioctl and can be invoked from any thread.
Jens Freimann47b43c52014-11-11 20:57:06 +01003629
Jens Freimann816c7662014-11-24 17:13:46 +010036304.94 KVM_S390_GET_IRQ_STATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003631---------------------------
Jens Freimann816c7662014-11-24 17:13:46 +01003632
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003633:Capability: KVM_CAP_S390_IRQ_STATE
3634:Architectures: s390
3635:Type: vcpu ioctl
3636:Parameters: struct kvm_s390_irq_state (out)
3637:Returns: >= number of bytes copied into buffer,
3638 -EINVAL if buffer size is 0,
3639 -ENOBUFS if buffer size is too small to fit all pending interrupts,
3640 -EFAULT if the buffer address was invalid
Jens Freimann816c7662014-11-24 17:13:46 +01003641
3642This ioctl allows userspace to retrieve the complete state of all currently
3643pending interrupts in a single buffer. Use cases include migration
3644and introspection. The parameter structure contains the address of a
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003645userspace buffer and its length::
Jens Freimann816c7662014-11-24 17:13:46 +01003646
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003647 struct kvm_s390_irq_state {
Jens Freimann816c7662014-11-24 17:13:46 +01003648 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003649 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003650 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003651 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003652 };
Jens Freimann816c7662014-11-24 17:13:46 +01003653
3654Userspace passes in the above struct and for each pending interrupt a
3655struct kvm_s390_irq is copied to the provided buffer.
3656
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003657The structure contains a flags and a reserved field for future extensions. As
3658the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
3659reserved, these fields can not be used in the future without breaking
3660compatibility.
3661
Jens Freimann816c7662014-11-24 17:13:46 +01003662If -ENOBUFS is returned the buffer provided was too small and userspace
3663may retry with a bigger buffer.
3664
36654.95 KVM_S390_SET_IRQ_STATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003666---------------------------
Jens Freimann816c7662014-11-24 17:13:46 +01003667
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003668:Capability: KVM_CAP_S390_IRQ_STATE
3669:Architectures: s390
3670:Type: vcpu ioctl
3671:Parameters: struct kvm_s390_irq_state (in)
3672:Returns: 0 on success,
3673 -EFAULT if the buffer address was invalid,
3674 -EINVAL for an invalid buffer length (see below),
3675 -EBUSY if there were already interrupts pending,
3676 errors occurring when actually injecting the
Jens Freimann816c7662014-11-24 17:13:46 +01003677 interrupt. See KVM_S390_IRQ.
3678
3679This ioctl allows userspace to set the complete state of all cpu-local
3680interrupts currently pending for the vcpu. It is intended for restoring
3681interrupt state after a migration. The input parameter is a userspace buffer
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003682containing a struct kvm_s390_irq_state::
Jens Freimann816c7662014-11-24 17:13:46 +01003683
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003684 struct kvm_s390_irq_state {
Jens Freimann816c7662014-11-24 17:13:46 +01003685 __u64 buf;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003686 __u32 flags; /* will stay unused for compatibility reasons */
Jens Freimann816c7662014-11-24 17:13:46 +01003687 __u32 len;
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003688 __u32 reserved[4]; /* will stay unused for compatibility reasons */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003689 };
Jens Freimann816c7662014-11-24 17:13:46 +01003690
Christian Borntraegerbb64da92017-11-21 16:02:52 +01003691The restrictions for flags and reserved apply as well.
3692(see KVM_S390_GET_IRQ_STATE)
3693
Jens Freimann816c7662014-11-24 17:13:46 +01003694The userspace memory referenced by buf contains a struct kvm_s390_irq
3695for each interrupt to be injected into the guest.
3696If one of the interrupts could not be injected for some reason the
3697ioctl aborts.
3698
3699len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
3700and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
3701which is the maximum number of possibly pending cpu-local interrupts.
Jens Freimann47b43c52014-11-11 20:57:06 +01003702
Alexey Kardashevskiyed8e5a22016-01-19 16:12:28 +110037034.96 KVM_SMI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003704------------
Paolo Bonzinif0778252015-04-01 15:06:40 +02003705
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003706:Capability: KVM_CAP_X86_SMM
3707:Architectures: x86
3708:Type: vcpu ioctl
3709:Parameters: none
3710:Returns: 0 on success, -1 on error
Paolo Bonzinif0778252015-04-01 15:06:40 +02003711
3712Queues an SMI on the thread's vcpu.
3713
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +010037144.97 KVM_X86_SET_MSR_FILTER
3715----------------------------
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +11003716
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01003717:Capability: KVM_X86_SET_MSR_FILTER
3718:Architectures: x86
3719:Type: vm ioctl
3720:Parameters: struct kvm_msr_filter
3721:Returns: 0 on success, < 0 on error
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +11003722
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01003723::
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +11003724
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01003725 struct kvm_msr_filter_range {
3726 #define KVM_MSR_FILTER_READ (1 << 0)
3727 #define KVM_MSR_FILTER_WRITE (1 << 1)
3728 __u32 flags;
3729 __u32 nmsrs; /* number of msrs in bitmap */
3730 __u32 base; /* MSR index the bitmap starts at */
3731 __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
3732 };
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +11003733
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01003734 #define KVM_MSR_FILTER_MAX_RANGES 16
3735 struct kvm_msr_filter {
3736 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
3737 #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0)
3738 __u32 flags;
3739 struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
3740 };
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +11003741
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01003742flags values for ``struct kvm_msr_filter_range``:
3743
3744``KVM_MSR_FILTER_READ``
3745
3746 Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap
3747 indicates that a read should immediately fail, while a 1 indicates that
3748 a read for a particular MSR should be handled regardless of the default
3749 filter action.
3750
3751``KVM_MSR_FILTER_WRITE``
3752
3753 Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap
3754 indicates that a write should immediately fail, while a 1 indicates that
3755 a write for a particular MSR should be handled regardless of the default
3756 filter action.
3757
3758``KVM_MSR_FILTER_READ | KVM_MSR_FILTER_WRITE``
3759
3760 Filter both read and write accesses to MSRs using the given bitmap. A 0
3761 in the bitmap indicates that both reads and writes should immediately fail,
3762 while a 1 indicates that reads and writes for a particular MSR are not
3763 filtered by this range.
3764
3765flags values for ``struct kvm_msr_filter``:
3766
3767``KVM_MSR_FILTER_DEFAULT_ALLOW``
3768
3769 If no filter range matches an MSR index that is getting accessed, KVM will
3770 fall back to allowing access to the MSR.
3771
3772``KVM_MSR_FILTER_DEFAULT_DENY``
3773
3774 If no filter range matches an MSR index that is getting accessed, KVM will
3775 fall back to rejecting access to the MSR. In this mode, all MSRs that should
3776 be processed by KVM need to explicitly be marked as allowed in the bitmaps.
3777
3778This ioctl allows user space to define up to 16 bitmaps of MSR ranges to
3779specify whether a certain MSR access should be explicitly filtered for or not.
3780
3781If this ioctl has never been invoked, MSR accesses are not guarded and the
3782default KVM in-kernel emulation behavior is fully preserved.
3783
3784Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR
3785filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes
3786an error.
3787
3788As soon as the filtering is in place, every MSR access is processed through
3789the filtering except for accesses to the x2APIC MSRs (from 0x800 to 0x8ff);
3790x2APIC MSRs are always allowed, independent of the ``default_allow`` setting,
3791and their behavior depends on the ``X2APIC_ENABLE`` bit of the APIC base
3792register.
3793
3794If a bit is within one of the defined ranges, read and write accesses are
3795guarded by the bitmap's value for the MSR index if the kind of access
3796is included in the ``struct kvm_msr_filter_range`` flags. If no range
3797cover this particular access, the behavior is determined by the flags
3798field in the kvm_msr_filter struct: ``KVM_MSR_FILTER_DEFAULT_ALLOW``
3799and ``KVM_MSR_FILTER_DEFAULT_DENY``.
3800
3801Each bitmap range specifies a range of MSRs to potentially allow access on.
3802The range goes from MSR index [base .. base+nmsrs]. The flags field
3803indicates whether reads, writes or both reads and writes are filtered
3804by setting a 1 bit in the bitmap for the corresponding MSR index.
3805
3806If an MSR access is not permitted through the filtering, it generates a
3807#GP inside the guest. When combined with KVM_CAP_X86_USER_SPACE_MSR, that
3808allows user space to deflect and potentially handle various MSR accesses
3809into user space.
3810
3811If a vCPU is in running state while this ioctl is invoked, the vCPU may
3812experience inconsistent filtering behavior on MSR accesses.
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +11003813
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +110038144.98 KVM_CREATE_SPAPR_TCE_64
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003815----------------------------
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +11003816
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003817:Capability: KVM_CAP_SPAPR_TCE_64
3818:Architectures: powerpc
3819:Type: vm ioctl
3820:Parameters: struct kvm_create_spapr_tce_64 (in)
3821:Returns: file descriptor for manipulating the created TCE table
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +11003822
3823This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
3824windows, described in 4.62 KVM_CREATE_SPAPR_TCE
3825
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003826This capability uses extended struct in ioctl interface::
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +11003827
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003828 /* for KVM_CAP_SPAPR_TCE_64 */
3829 struct kvm_create_spapr_tce_64 {
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +11003830 __u64 liobn;
3831 __u32 page_shift;
3832 __u32 flags;
3833 __u64 offset; /* in pages */
3834 __u64 size; /* in pages */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003835 };
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +11003836
3837The aim of extension is to support an additional bigger DMA window with
3838a variable page size.
3839KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
3840a bus offset of the corresponding DMA window, @size and @offset are numbers
3841of IOMMU pages.
3842
3843@flags are not used at the moment.
3844
3845The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
3846
David Gibsonccc4df42016-12-20 16:48:57 +110038474.99 KVM_REINJECT_CONTROL
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003848-------------------------
Radim Krčmář107d44a22016-03-02 22:56:53 +01003849
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003850:Capability: KVM_CAP_REINJECT_CONTROL
3851:Architectures: x86
3852:Type: vm ioctl
3853:Parameters: struct kvm_reinject_control (in)
3854:Returns: 0 on success,
Radim Krčmář107d44a22016-03-02 22:56:53 +01003855 -EFAULT if struct kvm_reinject_control cannot be read,
3856 -ENXIO if KVM_CREATE_PIT or KVM_CREATE_PIT2 didn't succeed earlier.
3857
3858i8254 (PIT) has two modes, reinject and !reinject. The default is reinject,
3859where KVM queues elapsed i8254 ticks and monitors completion of interrupt from
3860vector(s) that i8254 injects. Reinject mode dequeues a tick and injects its
3861interrupt whenever there isn't a pending interrupt from i8254.
3862!reinject mode injects an interrupt as soon as a tick arrives.
3863
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003864::
3865
3866 struct kvm_reinject_control {
Radim Krčmář107d44a22016-03-02 22:56:53 +01003867 __u8 pit_reinject;
3868 __u8 reserved[31];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003869 };
Radim Krčmář107d44a22016-03-02 22:56:53 +01003870
3871pit_reinject = 0 (!reinject mode) is recommended, unless running an old
3872operating system that uses the PIT for timing (e.g. Linux 2.4.x).
3873
David Gibsonccc4df42016-12-20 16:48:57 +110038744.100 KVM_PPC_CONFIGURE_V3_MMU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003875------------------------------
Paul Mackerrasc9270132017-01-30 21:21:41 +11003876
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003877:Capability: KVM_CAP_PPC_RADIX_MMU or KVM_CAP_PPC_HASH_MMU_V3
3878:Architectures: ppc
3879:Type: vm ioctl
3880:Parameters: struct kvm_ppc_mmuv3_cfg (in)
3881:Returns: 0 on success,
Paul Mackerrasc9270132017-01-30 21:21:41 +11003882 -EFAULT if struct kvm_ppc_mmuv3_cfg cannot be read,
3883 -EINVAL if the configuration is invalid
3884
3885This ioctl controls whether the guest will use radix or HPT (hashed
3886page table) translation, and sets the pointer to the process table for
3887the guest.
3888
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003889::
3890
3891 struct kvm_ppc_mmuv3_cfg {
Paul Mackerrasc9270132017-01-30 21:21:41 +11003892 __u64 flags;
3893 __u64 process_table;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003894 };
Paul Mackerrasc9270132017-01-30 21:21:41 +11003895
3896There are two bits that can be set in flags; KVM_PPC_MMUV3_RADIX and
3897KVM_PPC_MMUV3_GTSE. KVM_PPC_MMUV3_RADIX, if set, configures the guest
3898to use radix tree translation, and if clear, to use HPT translation.
3899KVM_PPC_MMUV3_GTSE, if set and if KVM permits it, configures the guest
3900to be able to use the global TLB and SLB invalidation instructions;
3901if clear, the guest may not use these instructions.
3902
3903The process_table field specifies the address and size of the guest
3904process table, which is in the guest's space. This field is formatted
3905as the second doubleword of the partition table entry, as defined in
3906the Power ISA V3.00, Book III section 5.7.6.1.
3907
David Gibsonccc4df42016-12-20 16:48:57 +110039084.101 KVM_PPC_GET_RMMU_INFO
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003909---------------------------
Paul Mackerrasc9270132017-01-30 21:21:41 +11003910
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003911:Capability: KVM_CAP_PPC_RADIX_MMU
3912:Architectures: ppc
3913:Type: vm ioctl
3914:Parameters: struct kvm_ppc_rmmu_info (out)
3915:Returns: 0 on success,
Paul Mackerrasc9270132017-01-30 21:21:41 +11003916 -EFAULT if struct kvm_ppc_rmmu_info cannot be written,
3917 -EINVAL if no useful information can be returned
3918
3919This ioctl returns a structure containing two things: (a) a list
3920containing supported radix tree geometries, and (b) a list that maps
3921page sizes to put in the "AP" (actual page size) field for the tlbie
3922(TLB invalidate entry) instruction.
3923
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003924::
3925
3926 struct kvm_ppc_rmmu_info {
Paul Mackerrasc9270132017-01-30 21:21:41 +11003927 struct kvm_ppc_radix_geom {
3928 __u8 page_shift;
3929 __u8 level_bits[4];
3930 __u8 pad[3];
3931 } geometries[8];
3932 __u32 ap_encodings[8];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003933 };
Paul Mackerrasc9270132017-01-30 21:21:41 +11003934
3935The geometries[] field gives up to 8 supported geometries for the
3936radix page table, in terms of the log base 2 of the smallest page
3937size, and the number of bits indexed at each level of the tree, from
3938the PTE level up to the PGD level in that order. Any unused entries
3939will have 0 in the page_shift field.
3940
3941The ap_encodings gives the supported page sizes and their AP field
3942encodings, encoded with the AP value in the top 3 bits and the log
3943base 2 of the page size in the bottom 6 bits.
3944
David Gibsonef1ead02016-12-20 16:48:58 +110039454.102 KVM_PPC_RESIZE_HPT_PREPARE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003946--------------------------------
David Gibsonef1ead02016-12-20 16:48:58 +11003947
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003948:Capability: KVM_CAP_SPAPR_RESIZE_HPT
3949:Architectures: powerpc
3950:Type: vm ioctl
3951:Parameters: struct kvm_ppc_resize_hpt (in)
3952:Returns: 0 on successful completion,
David Gibsonef1ead02016-12-20 16:48:58 +11003953 >0 if a new HPT is being prepared, the value is an estimated
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003954 number of milliseconds until preparation is complete,
David Gibsonef1ead02016-12-20 16:48:58 +11003955 -EFAULT if struct kvm_reinject_control cannot be read,
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003956 -EINVAL if the supplied shift or flags are invalid,
3957 -ENOMEM if unable to allocate the new HPT,
David Gibsonef1ead02016-12-20 16:48:58 +11003958
3959Used to implement the PAPR extension for runtime resizing of a guest's
3960Hashed Page Table (HPT). Specifically this starts, stops or monitors
3961the preparation of a new potential HPT for the guest, essentially
3962implementing the H_RESIZE_HPT_PREPARE hypercall.
3963
Paolo Bonzinie2a0fca2021-02-25 08:37:01 -05003964::
3965
3966 struct kvm_ppc_resize_hpt {
3967 __u64 flags;
3968 __u32 shift;
3969 __u32 pad;
3970 };
3971
David Gibsonef1ead02016-12-20 16:48:58 +11003972If called with shift > 0 when there is no pending HPT for the guest,
3973this begins preparation of a new pending HPT of size 2^(shift) bytes.
3974It then returns a positive integer with the estimated number of
3975milliseconds until preparation is complete.
3976
3977If called when there is a pending HPT whose size does not match that
3978requested in the parameters, discards the existing pending HPT and
3979creates a new one as above.
3980
3981If called when there is a pending HPT of the size requested, will:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01003982
David Gibsonef1ead02016-12-20 16:48:58 +11003983 * If preparation of the pending HPT is already complete, return 0
3984 * If preparation of the pending HPT has failed, return an error
3985 code, then discard the pending HPT.
3986 * If preparation of the pending HPT is still in progress, return an
3987 estimated number of milliseconds until preparation is complete.
3988
3989If called with shift == 0, discards any currently pending HPT and
3990returns 0 (i.e. cancels any in-progress preparation).
3991
3992flags is reserved for future expansion, currently setting any bits in
3993flags will result in an -EINVAL.
3994
3995Normally this will be called repeatedly with the same parameters until
3996it returns <= 0. The first call will initiate preparation, subsequent
3997ones will monitor preparation until it completes or fails.
3998
David Gibsonef1ead02016-12-20 16:48:58 +110039994.103 KVM_PPC_RESIZE_HPT_COMMIT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004000-------------------------------
David Gibsonef1ead02016-12-20 16:48:58 +11004001
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004002:Capability: KVM_CAP_SPAPR_RESIZE_HPT
4003:Architectures: powerpc
4004:Type: vm ioctl
4005:Parameters: struct kvm_ppc_resize_hpt (in)
4006:Returns: 0 on successful completion,
David Gibsonef1ead02016-12-20 16:48:58 +11004007 -EFAULT if struct kvm_reinject_control cannot be read,
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004008 -EINVAL if the supplied shift or flags are invalid,
David Gibsonef1ead02016-12-20 16:48:58 +11004009 -ENXIO is there is no pending HPT, or the pending HPT doesn't
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004010 have the requested size,
4011 -EBUSY if the pending HPT is not fully prepared,
David Gibsonef1ead02016-12-20 16:48:58 +11004012 -ENOSPC if there was a hash collision when moving existing
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004013 HPT entries to the new HPT,
David Gibsonef1ead02016-12-20 16:48:58 +11004014 -EIO on other error conditions
4015
4016Used to implement the PAPR extension for runtime resizing of a guest's
4017Hashed Page Table (HPT). Specifically this requests that the guest be
4018transferred to working with the new HPT, essentially implementing the
4019H_RESIZE_HPT_COMMIT hypercall.
4020
Paolo Bonzinie2a0fca2021-02-25 08:37:01 -05004021::
4022
4023 struct kvm_ppc_resize_hpt {
4024 __u64 flags;
4025 __u32 shift;
4026 __u32 pad;
4027 };
4028
David Gibsonef1ead02016-12-20 16:48:58 +11004029This should only be called after KVM_PPC_RESIZE_HPT_PREPARE has
4030returned 0 with the same parameters. In other cases
4031KVM_PPC_RESIZE_HPT_COMMIT will return an error (usually -ENXIO or
4032-EBUSY, though others may be possible if the preparation was started,
4033but failed).
4034
4035This will have undefined effects on the guest if it has not already
4036placed itself in a quiescent state where no vcpu will make MMU enabled
4037memory accesses.
4038
4039On succsful completion, the pending HPT will become the guest's active
4040HPT and the previous HPT will be discarded.
4041
4042On failure, the guest will still be operating on its previous HPT.
4043
Luiz Capitulino3aa53852017-03-13 09:08:20 -040040444.104 KVM_X86_GET_MCE_CAP_SUPPORTED
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004045-----------------------------------
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004046
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004047:Capability: KVM_CAP_MCE
4048:Architectures: x86
4049:Type: system ioctl
4050:Parameters: u64 mce_cap (out)
4051:Returns: 0 on success, -1 on error
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004052
4053Returns supported MCE capabilities. The u64 mce_cap parameter
4054has the same format as the MSR_IA32_MCG_CAP register. Supported
4055capabilities will have the corresponding bits set.
4056
40574.105 KVM_X86_SETUP_MCE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004058-----------------------
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004059
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004060:Capability: KVM_CAP_MCE
4061:Architectures: x86
4062:Type: vcpu ioctl
4063:Parameters: u64 mcg_cap (in)
4064:Returns: 0 on success,
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004065 -EFAULT if u64 mcg_cap cannot be read,
4066 -EINVAL if the requested number of banks is invalid,
4067 -EINVAL if requested MCE capability is not supported.
4068
4069Initializes MCE support for use. The u64 mcg_cap parameter
4070has the same format as the MSR_IA32_MCG_CAP register and
4071specifies which capabilities should be enabled. The maximum
4072supported number of error-reporting banks can be retrieved when
4073checking for KVM_CAP_MCE. The supported capabilities can be
4074retrieved with KVM_X86_GET_MCE_CAP_SUPPORTED.
4075
40764.106 KVM_X86_SET_MCE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004077---------------------
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004078
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004079:Capability: KVM_CAP_MCE
4080:Architectures: x86
4081:Type: vcpu ioctl
4082:Parameters: struct kvm_x86_mce (in)
4083:Returns: 0 on success,
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004084 -EFAULT if struct kvm_x86_mce cannot be read,
4085 -EINVAL if the bank number is invalid,
4086 -EINVAL if VAL bit is not set in status field.
4087
4088Inject a machine check error (MCE) into the guest. The input
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004089parameter is::
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004090
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004091 struct kvm_x86_mce {
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004092 __u64 status;
4093 __u64 addr;
4094 __u64 misc;
4095 __u64 mcg_status;
4096 __u8 bank;
4097 __u8 pad1[7];
4098 __u64 pad2[3];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004099 };
Luiz Capitulino3aa53852017-03-13 09:08:20 -04004100
4101If the MCE being reported is an uncorrected error, KVM will
4102inject it as an MCE exception into the guest. If the guest
4103MCG_STATUS register reports that an MCE is in progress, KVM
4104causes an KVM_EXIT_SHUTDOWN vmexit.
4105
4106Otherwise, if the MCE is a corrected error, KVM will just
4107store it in the corresponding bank (provided this bank is
4108not holding a previously reported uncorrected error).
4109
Claudio Imbrenda4036e382016-08-04 17:58:47 +020041104.107 KVM_S390_GET_CMMA_BITS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004111----------------------------
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004112
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004113:Capability: KVM_CAP_S390_CMMA_MIGRATION
4114:Architectures: s390
4115:Type: vm ioctl
4116:Parameters: struct kvm_s390_cmma_log (in, out)
4117:Returns: 0 on success, a negative value on error
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004118
4119This ioctl is used to get the values of the CMMA bits on the s390
4120architecture. It is meant to be used in two scenarios:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004121
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004122- During live migration to save the CMMA values. Live migration needs
4123 to be enabled via the KVM_REQ_START_MIGRATION VM property.
4124- To non-destructively peek at the CMMA values, with the flag
4125 KVM_S390_CMMA_PEEK set.
4126
4127The ioctl takes parameters via the kvm_s390_cmma_log struct. The desired
4128values are written to a buffer whose location is indicated via the "values"
4129member in the kvm_s390_cmma_log struct. The values in the input struct are
4130also updated as needed.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004131
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004132Each CMMA value takes up one byte.
4133
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004134::
4135
4136 struct kvm_s390_cmma_log {
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004137 __u64 start_gfn;
4138 __u32 count;
4139 __u32 flags;
4140 union {
4141 __u64 remaining;
4142 __u64 mask;
4143 };
4144 __u64 values;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004145 };
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004146
4147start_gfn is the number of the first guest frame whose CMMA values are
4148to be retrieved,
4149
4150count is the length of the buffer in bytes,
4151
4152values points to the buffer where the result will be written to.
4153
4154If count is greater than KVM_S390_SKEYS_MAX, then it is considered to be
4155KVM_S390_SKEYS_MAX. KVM_S390_SKEYS_MAX is re-used for consistency with
4156other ioctls.
4157
4158The result is written in the buffer pointed to by the field values, and
4159the values of the input parameter are updated as follows.
4160
4161Depending on the flags, different actions are performed. The only
4162supported flag so far is KVM_S390_CMMA_PEEK.
4163
4164The default behaviour if KVM_S390_CMMA_PEEK is not set is:
4165start_gfn will indicate the first page frame whose CMMA bits were dirty.
4166It is not necessarily the same as the one passed as input, as clean pages
4167are skipped.
4168
4169count will indicate the number of bytes actually written in the buffer.
4170It can (and very often will) be smaller than the input value, since the
4171buffer is only filled until 16 bytes of clean values are found (which
4172are then not copied in the buffer). Since a CMMA migration block needs
4173the base address and the length, for a total of 16 bytes, we will send
4174back some clean data if there is some dirty data afterwards, as long as
4175the size of the clean data does not exceed the size of the header. This
4176allows to minimize the amount of data to be saved or transferred over
4177the network at the expense of more roundtrips to userspace. The next
4178invocation of the ioctl will skip over all the clean values, saving
4179potentially more than just the 16 bytes we found.
4180
4181If KVM_S390_CMMA_PEEK is set:
4182the existing storage attributes are read even when not in migration
4183mode, and no other action is performed;
4184
4185the output start_gfn will be equal to the input start_gfn,
4186
4187the output count will be equal to the input count, except if the end of
4188memory has been reached.
4189
4190In both cases:
4191the field "remaining" will indicate the total number of dirty CMMA values
4192still remaining, or 0 if KVM_S390_CMMA_PEEK is set and migration mode is
4193not enabled.
4194
4195mask is unused.
4196
4197values points to the userspace buffer where the result will be stored.
4198
4199This ioctl can fail with -ENOMEM if not enough memory can be allocated to
4200complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
4201KVM_S390_CMMA_PEEK is not set but migration mode was not enabled, with
4202-EFAULT if the userspace address is invalid or if no page table is
4203present for the addresses (e.g. when using hugepages).
4204
42054.108 KVM_S390_SET_CMMA_BITS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004206----------------------------
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004207
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004208:Capability: KVM_CAP_S390_CMMA_MIGRATION
4209:Architectures: s390
4210:Type: vm ioctl
4211:Parameters: struct kvm_s390_cmma_log (in)
4212:Returns: 0 on success, a negative value on error
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004213
4214This ioctl is used to set the values of the CMMA bits on the s390
4215architecture. It is meant to be used during live migration to restore
4216the CMMA values, but there are no restrictions on its use.
4217The ioctl takes parameters via the kvm_s390_cmma_values struct.
4218Each CMMA value takes up one byte.
4219
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004220::
4221
4222 struct kvm_s390_cmma_log {
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004223 __u64 start_gfn;
4224 __u32 count;
4225 __u32 flags;
4226 union {
4227 __u64 remaining;
4228 __u64 mask;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004229 };
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004230 __u64 values;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004231 };
Claudio Imbrenda4036e382016-08-04 17:58:47 +02004232
4233start_gfn indicates the starting guest frame number,
4234
4235count indicates how many values are to be considered in the buffer,
4236
4237flags is not used and must be 0.
4238
4239mask indicates which PGSTE bits are to be considered.
4240
4241remaining is not used.
4242
4243values points to the buffer in userspace where to store the values.
4244
4245This ioctl can fail with -ENOMEM if not enough memory can be allocated to
4246complete the task, with -ENXIO if CMMA is not enabled, with -EINVAL if
4247the count field is too large (e.g. more than KVM_S390_CMMA_SIZE_MAX) or
4248if the flags field was not 0, with -EFAULT if the userspace address is
4249invalid, if invalid pages are written to (e.g. after the end of memory)
4250or if no page table is present for the addresses (e.g. when using
4251hugepages).
4252
Radim Krčmář7bf14c22018-02-01 15:04:17 +010042534.109 KVM_PPC_GET_CPU_CHAR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004254--------------------------
Paul Mackerras3214d012018-01-15 16:06:47 +11004255
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004256:Capability: KVM_CAP_PPC_GET_CPU_CHAR
4257:Architectures: powerpc
4258:Type: vm ioctl
4259:Parameters: struct kvm_ppc_cpu_char (out)
4260:Returns: 0 on successful completion,
Paul Mackerras3214d012018-01-15 16:06:47 +11004261 -EFAULT if struct kvm_ppc_cpu_char cannot be written
4262
4263This ioctl gives userspace information about certain characteristics
4264of the CPU relating to speculative execution of instructions and
4265possible information leakage resulting from speculative execution (see
4266CVE-2017-5715, CVE-2017-5753 and CVE-2017-5754). The information is
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004267returned in struct kvm_ppc_cpu_char, which looks like this::
Paul Mackerras3214d012018-01-15 16:06:47 +11004268
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004269 struct kvm_ppc_cpu_char {
Paul Mackerras3214d012018-01-15 16:06:47 +11004270 __u64 character; /* characteristics of the CPU */
4271 __u64 behaviour; /* recommended software behaviour */
4272 __u64 character_mask; /* valid bits in character */
4273 __u64 behaviour_mask; /* valid bits in behaviour */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004274 };
Paul Mackerras3214d012018-01-15 16:06:47 +11004275
4276For extensibility, the character_mask and behaviour_mask fields
4277indicate which bits of character and behaviour have been filled in by
4278the kernel. If the set of defined bits is extended in future then
4279userspace will be able to tell whether it is running on a kernel that
4280knows about the new bits.
4281
4282The character field describes attributes of the CPU which can help
4283with preventing inadvertent information disclosure - specifically,
4284whether there is an instruction to flash-invalidate the L1 data cache
4285(ori 30,30,0 or mtspr SPRN_TRIG2,rN), whether the L1 data cache is set
4286to a mode where entries can only be used by the thread that created
4287them, whether the bcctr[l] instruction prevents speculation, and
4288whether a speculation barrier instruction (ori 31,31,0) is provided.
4289
4290The behaviour field describes actions that software should take to
4291prevent inadvertent information disclosure, and thus describes which
4292vulnerabilities the hardware is subject to; specifically whether the
4293L1 data cache should be flushed when returning to user mode from the
4294kernel, and whether a speculation barrier should be placed between an
4295array bounds check and the array access.
4296
4297These fields use the same bit definitions as the new
4298H_GET_CPU_CHARACTERISTICS hypercall.
4299
Radim Krčmář7bf14c22018-02-01 15:04:17 +010043004.110 KVM_MEMORY_ENCRYPT_OP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004301---------------------------
Brijesh Singh5acc5c02017-12-04 10:57:26 -06004302
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004303:Capability: basic
4304:Architectures: x86
Connor Kuehl46ca9ee2020-08-19 16:19:52 -05004305:Type: vm
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004306:Parameters: an opaque platform specific structure (in/out)
4307:Returns: 0 on success; -1 on error
Brijesh Singh5acc5c02017-12-04 10:57:26 -06004308
4309If the platform supports creating encrypted VMs then this ioctl can be used
4310for issuing platform-specific memory encryption commands to manage those
4311encrypted VMs.
4312
4313Currently, this ioctl is used for issuing Secure Encrypted Virtualization
4314(SEV) commands on AMD Processors. The SEV commands are defined in
Christoph Hellwig2f5947d2019-07-24 09:24:49 +02004315Documentation/virt/kvm/amd-memory-encryption.rst.
Brijesh Singh5acc5c02017-12-04 10:57:26 -06004316
Radim Krčmář7bf14c22018-02-01 15:04:17 +010043174.111 KVM_MEMORY_ENCRYPT_REG_REGION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004318-----------------------------------
Brijesh Singh69eaede2017-12-04 10:57:26 -06004319
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004320:Capability: basic
4321:Architectures: x86
4322:Type: system
4323:Parameters: struct kvm_enc_region (in)
4324:Returns: 0 on success; -1 on error
Brijesh Singh69eaede2017-12-04 10:57:26 -06004325
4326This ioctl can be used to register a guest memory region which may
4327contain encrypted data (e.g. guest RAM, SMRAM etc).
4328
4329It is used in the SEV-enabled guest. When encryption is enabled, a guest
4330memory region may contain encrypted data. The SEV memory encryption
4331engine uses a tweak such that two identical plaintext pages, each at
4332different locations will have differing ciphertexts. So swapping or
4333moving ciphertext of those pages will not result in plaintext being
4334swapped. So relocating (or migrating) physical backing pages for the SEV
4335guest will require some additional steps.
4336
4337Note: The current SEV key management spec does not provide commands to
4338swap or migrate (move) ciphertext pages. Hence, for now we pin the guest
4339memory region registered with the ioctl.
4340
Radim Krčmář7bf14c22018-02-01 15:04:17 +010043414.112 KVM_MEMORY_ENCRYPT_UNREG_REGION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004342-------------------------------------
Brijesh Singh69eaede2017-12-04 10:57:26 -06004343
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004344:Capability: basic
4345:Architectures: x86
4346:Type: system
4347:Parameters: struct kvm_enc_region (in)
4348:Returns: 0 on success; -1 on error
Brijesh Singh69eaede2017-12-04 10:57:26 -06004349
4350This ioctl can be used to unregister the guest memory region registered
4351with KVM_MEMORY_ENCRYPT_REG_REGION ioctl above.
4352
Roman Kaganfaeb7832018-02-01 16:48:32 +030043534.113 KVM_HYPERV_EVENTFD
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004354------------------------
Roman Kaganfaeb7832018-02-01 16:48:32 +03004355
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004356:Capability: KVM_CAP_HYPERV_EVENTFD
4357:Architectures: x86
4358:Type: vm ioctl
4359:Parameters: struct kvm_hyperv_eventfd (in)
Roman Kaganfaeb7832018-02-01 16:48:32 +03004360
4361This ioctl (un)registers an eventfd to receive notifications from the guest on
4362the specified Hyper-V connection id through the SIGNAL_EVENT hypercall, without
4363causing a user exit. SIGNAL_EVENT hypercall with non-zero event flag number
4364(bits 24-31) still triggers a KVM_EXIT_HYPERV_HCALL user exit.
4365
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004366::
4367
4368 struct kvm_hyperv_eventfd {
Roman Kaganfaeb7832018-02-01 16:48:32 +03004369 __u32 conn_id;
4370 __s32 fd;
4371 __u32 flags;
4372 __u32 padding[3];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004373 };
Roman Kaganfaeb7832018-02-01 16:48:32 +03004374
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004375The conn_id field should fit within 24 bits::
Roman Kaganfaeb7832018-02-01 16:48:32 +03004376
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004377 #define KVM_HYPERV_CONN_ID_MASK 0x00ffffff
Roman Kaganfaeb7832018-02-01 16:48:32 +03004378
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004379The acceptable values for the flags field are::
Roman Kaganfaeb7832018-02-01 16:48:32 +03004380
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004381 #define KVM_HYPERV_EVENTFD_DEASSIGN (1 << 0)
Roman Kaganfaeb7832018-02-01 16:48:32 +03004382
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004383:Returns: 0 on success,
4384 -EINVAL if conn_id or flags is outside the allowed range,
4385 -ENOENT on deassign if the conn_id isn't registered,
4386 -EEXIST on assign if the conn_id is already registered
Roman Kaganfaeb7832018-02-01 16:48:32 +03004387
Jim Mattson8fcc4b52018-07-10 11:27:20 +020043884.114 KVM_GET_NESTED_STATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004389--------------------------
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004390
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004391:Capability: KVM_CAP_NESTED_STATE
4392:Architectures: x86
4393:Type: vcpu ioctl
4394:Parameters: struct kvm_nested_state (in/out)
4395:Returns: 0 on success, -1 on error
4396
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004397Errors:
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004398
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004399 ===== =============================================================
4400 E2BIG the total state size exceeds the value of 'size' specified by
4401 the user; the size required will be written into size.
4402 ===== =============================================================
4403
4404::
4405
4406 struct kvm_nested_state {
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004407 __u16 flags;
4408 __u16 format;
4409 __u32 size;
Liran Alon6ca00df2019-06-16 15:03:10 +03004410
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004411 union {
Liran Alon6ca00df2019-06-16 15:03:10 +03004412 struct kvm_vmx_nested_state_hdr vmx;
4413 struct kvm_svm_nested_state_hdr svm;
4414
4415 /* Pad the header to 128 bytes. */
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004416 __u8 pad[120];
Liran Alon6ca00df2019-06-16 15:03:10 +03004417 } hdr;
4418
4419 union {
4420 struct kvm_vmx_nested_state_data vmx[0];
4421 struct kvm_svm_nested_state_data svm[0];
4422 } data;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004423 };
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004424
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004425 #define KVM_STATE_NESTED_GUEST_MODE 0x00000001
4426 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002
4427 #define KVM_STATE_NESTED_EVMCS 0x00000004
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004428
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004429 #define KVM_STATE_NESTED_FORMAT_VMX 0
4430 #define KVM_STATE_NESTED_FORMAT_SVM 1
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004431
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004432 #define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000
Liran Alon6ca00df2019-06-16 15:03:10 +03004433
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004434 #define KVM_STATE_NESTED_VMX_SMM_GUEST_MODE 0x00000001
4435 #define KVM_STATE_NESTED_VMX_SMM_VMXON 0x00000002
Liran Alon6ca00df2019-06-16 15:03:10 +03004436
Mauro Carvalho Chehab3c97f032020-09-09 16:10:48 +02004437 #define KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE 0x00000001
Peter Shier850448f2020-05-26 14:51:06 -07004438
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004439 struct kvm_vmx_nested_state_hdr {
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004440 __u64 vmxon_pa;
Liran Alon6ca00df2019-06-16 15:03:10 +03004441 __u64 vmcs12_pa;
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004442
4443 struct {
4444 __u16 flags;
4445 } smm;
Paolo Bonzini83d31e52020-07-09 13:12:09 -04004446
4447 __u32 flags;
4448 __u64 preemption_timer_deadline;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004449 };
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004450
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004451 struct kvm_vmx_nested_state_data {
Liran Alon6ca00df2019-06-16 15:03:10 +03004452 __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
4453 __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004454 };
Liran Alon6ca00df2019-06-16 15:03:10 +03004455
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004456This ioctl copies the vcpu's nested virtualization state from the kernel to
4457userspace.
4458
Liran Alon6ca00df2019-06-16 15:03:10 +03004459The maximum size of the state can be retrieved by passing KVM_CAP_NESTED_STATE
4460to the KVM_CHECK_EXTENSION ioctl().
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004461
44624.115 KVM_SET_NESTED_STATE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004463--------------------------
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004464
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004465:Capability: KVM_CAP_NESTED_STATE
4466:Architectures: x86
4467:Type: vcpu ioctl
4468:Parameters: struct kvm_nested_state (in)
4469:Returns: 0 on success, -1 on error
Jim Mattson8fcc4b52018-07-10 11:27:20 +02004470
Liran Alon6ca00df2019-06-16 15:03:10 +03004471This copies the vcpu's kvm_nested_state struct from userspace to the kernel.
4472For the definition of struct kvm_nested_state, see KVM_GET_NESTED_STATE.
Radim Krčmář7bf14c22018-02-01 15:04:17 +01004473
Peng Hao99434502018-10-14 07:09:56 +080044744.116 KVM_(UN)REGISTER_COALESCED_MMIO
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004475-------------------------------------
Peng Hao99434502018-10-14 07:09:56 +08004476
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004477:Capability: KVM_CAP_COALESCED_MMIO (for coalesced mmio)
4478 KVM_CAP_COALESCED_PIO (for coalesced pio)
4479:Architectures: all
4480:Type: vm ioctl
4481:Parameters: struct kvm_coalesced_mmio_zone
4482:Returns: 0 on success, < 0 on error
Peng Hao99434502018-10-14 07:09:56 +08004483
Peng Hao0804c842018-10-14 07:09:55 +08004484Coalesced I/O is a performance optimization that defers hardware
Peng Hao99434502018-10-14 07:09:56 +08004485register write emulation so that userspace exits are avoided. It is
4486typically used to reduce the overhead of emulating frequently accessed
4487hardware registers.
4488
Peng Hao0804c842018-10-14 07:09:55 +08004489When a hardware register is configured for coalesced I/O, write accesses
Peng Hao99434502018-10-14 07:09:56 +08004490do not exit to userspace and their value is recorded in a ring buffer
4491that is shared between kernel and userspace.
4492
Peng Hao0804c842018-10-14 07:09:55 +08004493Coalesced I/O is used if one or more write accesses to a hardware
Peng Hao99434502018-10-14 07:09:56 +08004494register can be deferred until a read or a write to another hardware
4495register on the same device. This last access will cause a vmexit and
4496userspace will process accesses from the ring buffer before emulating
Peng Hao0804c842018-10-14 07:09:55 +08004497it. That will avoid exiting to userspace on repeated writes.
4498
4499Coalesced pio is based on coalesced mmio. There is little difference
4500between coalesced mmio and pio except that coalesced pio records accesses
4501to I/O ports.
Peng Hao99434502018-10-14 07:09:56 +08004502
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +020045034.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004504------------------------------------
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004505
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004506:Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
4507:Architectures: x86, arm, arm64, mips
4508:Type: vm ioctl
Zenghui Yu01ead842020-12-08 12:34:39 +08004509:Parameters: struct kvm_clear_dirty_log (in)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004510:Returns: 0 on success, -1 on error
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004511
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004512::
4513
4514 /* for KVM_CLEAR_DIRTY_LOG */
4515 struct kvm_clear_dirty_log {
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004516 __u32 slot;
4517 __u32 num_pages;
4518 __u64 first_page;
4519 union {
4520 void __user *dirty_bitmap; /* one bit per page */
4521 __u64 padding;
4522 };
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004523 };
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004524
4525The ioctl clears the dirty status of pages in a memory slot, according to
4526the bitmap that is passed in struct kvm_clear_dirty_log's dirty_bitmap
4527field. Bit 0 of the bitmap corresponds to page "first_page" in the
4528memory slot, and num_pages is the size in bits of the input bitmap.
Paolo Bonzini76d58e02019-04-17 15:28:44 +02004529first_page must be a multiple of 64; num_pages must also be a multiple of
453064 unless first_page + num_pages is the size of the memory slot. For each
4531bit that is set in the input bitmap, the corresponding page is marked "clean"
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004532in KVM's dirty bitmap, and dirty tracking is re-enabled for that page
4533(for example via write-protection, or by clearing the dirty bit in
4534a page table entry).
4535
Zenghui Yu01ead842020-12-08 12:34:39 +08004536If KVM_CAP_MULTI_ADDRESS_SPACE is available, bits 16-31 of slot field specifies
4537the address space for which you want to clear the dirty status. See
4538KVM_SET_USER_MEMORY_REGION for details on the usage of slot field.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004539
Peter Xud7547c52019-05-08 17:15:47 +08004540This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004541is enabled; for more information, see the description of the capability.
4542However, it can always be used as long as KVM_CHECK_EXTENSION confirms
Peter Xud7547c52019-05-08 17:15:47 +08004543that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004544
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +010045454.118 KVM_GET_SUPPORTED_HV_CPUID
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004546--------------------------------
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004547
Vitaly Kuznetsovc21d54f2020-09-29 17:09:43 +02004548:Capability: KVM_CAP_HYPERV_CPUID (vcpu), KVM_CAP_SYS_HYPERV_CPUID (system)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004549:Architectures: x86
Vitaly Kuznetsovc21d54f2020-09-29 17:09:43 +02004550:Type: system ioctl, vcpu ioctl
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004551:Parameters: struct kvm_cpuid2 (in/out)
4552:Returns: 0 on success, -1 on error
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004553
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004554::
4555
4556 struct kvm_cpuid2 {
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004557 __u32 nent;
4558 __u32 padding;
4559 struct kvm_cpuid_entry2 entries[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004560 };
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004561
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004562 struct kvm_cpuid_entry2 {
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004563 __u32 function;
4564 __u32 index;
4565 __u32 flags;
4566 __u32 eax;
4567 __u32 ebx;
4568 __u32 ecx;
4569 __u32 edx;
4570 __u32 padding[3];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004571 };
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004572
4573This ioctl returns x86 cpuid features leaves related to Hyper-V emulation in
4574KVM. Userspace can use the information returned by this ioctl to construct
4575cpuid information presented to guests consuming Hyper-V enlightenments (e.g.
4576Windows or Hyper-V guests).
4577
4578CPUID feature leaves returned by this ioctl are defined by Hyper-V Top Level
4579Functional Specification (TLFS). These leaves can't be obtained with
4580KVM_GET_SUPPORTED_CPUID ioctl because some of them intersect with KVM feature
4581leaves (0x40000000, 0x40000001).
4582
4583Currently, the following list of CPUID leaves are returned:
Lukas Bulwahn356c7552021-01-04 10:59:38 +01004584
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004585 - HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS
4586 - HYPERV_CPUID_INTERFACE
4587 - HYPERV_CPUID_VERSION
4588 - HYPERV_CPUID_FEATURES
4589 - HYPERV_CPUID_ENLIGHTMENT_INFO
4590 - HYPERV_CPUID_IMPLEMENT_LIMITS
4591 - HYPERV_CPUID_NESTED_FEATURES
Vitaly Kuznetsovb44f50d2020-09-24 16:57:51 +02004592 - HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS
4593 - HYPERV_CPUID_SYNDBG_INTERFACE
4594 - HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004595
Vitaly Kuznetsovb44f50d2020-09-24 16:57:51 +02004596Userspace invokes KVM_GET_SUPPORTED_HV_CPUID by passing a kvm_cpuid2 structure
Vitaly Kuznetsov2bc39972018-12-10 18:21:56 +01004597with the 'nent' field indicating the number of entries in the variable-size
4598array 'entries'. If the number of entries is too low to describe all Hyper-V
4599feature leaves, an error (E2BIG) is returned. If the number is more or equal
4600to the number of Hyper-V feature leaves, the 'nent' field is adjusted to the
4601number of valid entries in the 'entries' array, which is then filled.
4602
4603'index' and 'flags' fields in 'struct kvm_cpuid_entry2' are currently reserved,
4604userspace should not expect to get any particular value there.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02004605
Vitaly Kuznetsovc21d54f2020-09-29 17:09:43 +02004606Note, vcpu version of KVM_GET_SUPPORTED_HV_CPUID is currently deprecated. Unlike
4607system ioctl which exposes all supported feature bits unconditionally, vcpu
4608version has the following quirks:
Lukas Bulwahn356c7552021-01-04 10:59:38 +01004609
Vitaly Kuznetsovc21d54f2020-09-29 17:09:43 +02004610- HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED
4611 feature bit are only exposed when Enlightened VMCS was previously enabled
4612 on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS).
4613- HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC.
4614 (presumes KVM_CREATE_IRQCHIP has already been called).
4615
Dave Martin50036ad2018-09-28 14:39:27 +010046164.119 KVM_ARM_VCPU_FINALIZE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004617---------------------------
Dave Martin50036ad2018-09-28 14:39:27 +01004618
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004619:Architectures: arm, arm64
4620:Type: vcpu ioctl
4621:Parameters: int feature (in)
4622:Returns: 0 on success, -1 on error
4623
Dave Martin50036ad2018-09-28 14:39:27 +01004624Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004625
4626 ====== ==============================================================
4627 EPERM feature not enabled, needs configuration, or already finalized
4628 EINVAL feature unknown or not present
4629 ====== ==============================================================
Dave Martin50036ad2018-09-28 14:39:27 +01004630
4631Recognised values for feature:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004632
4633 ===== ===========================================
Dave Martin9df2d662019-04-12 13:28:05 +01004634 arm64 KVM_ARM_VCPU_SVE (requires KVM_CAP_ARM_SVE)
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004635 ===== ===========================================
Dave Martin50036ad2018-09-28 14:39:27 +01004636
4637Finalizes the configuration of the specified vcpu feature.
4638
4639The vcpu must already have been initialised, enabling the affected feature, by
4640means of a successful KVM_ARM_VCPU_INIT call with the appropriate flag set in
4641features[].
4642
4643For affected vcpu features, this is a mandatory step that must be performed
4644before the vcpu is fully usable.
4645
4646Between KVM_ARM_VCPU_INIT and KVM_ARM_VCPU_FINALIZE, the feature may be
4647configured by use of ioctls such as KVM_SET_ONE_REG. The exact configuration
4648that should be performaned and how to do it are feature-dependent.
4649
4650Other calls that depend on a particular feature being finalized, such as
4651KVM_RUN, KVM_GET_REG_LIST, KVM_GET_ONE_REG and KVM_SET_ONE_REG, will fail with
4652-EPERM unless the feature has already been finalized by means of a
4653KVM_ARM_VCPU_FINALIZE call.
4654
4655See KVM_ARM_VCPU_INIT for details of vcpu features that require finalization
4656using this ioctl.
4657
Eric Hankland66bb8a02019-07-10 18:25:15 -070046584.120 KVM_SET_PMU_EVENT_FILTER
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004659------------------------------
Eric Hankland66bb8a02019-07-10 18:25:15 -07004660
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004661:Capability: KVM_CAP_PMU_EVENT_FILTER
4662:Architectures: x86
4663:Type: vm ioctl
4664:Parameters: struct kvm_pmu_event_filter (in)
4665:Returns: 0 on success, -1 on error
Eric Hankland66bb8a02019-07-10 18:25:15 -07004666
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004667::
4668
4669 struct kvm_pmu_event_filter {
Eric Hankland30cd8602019-07-18 11:38:18 -07004670 __u32 action;
4671 __u32 nevents;
4672 __u32 fixed_counter_bitmap;
4673 __u32 flags;
4674 __u32 pad[4];
4675 __u64 events[0];
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004676 };
Eric Hankland66bb8a02019-07-10 18:25:15 -07004677
4678This ioctl restricts the set of PMU events that the guest can program.
4679The argument holds a list of events which will be allowed or denied.
4680The eventsel+umask of each event the guest attempts to program is compared
4681against the events field to determine whether the guest should have access.
Eric Hankland30cd8602019-07-18 11:38:18 -07004682The events field only controls general purpose counters; fixed purpose
4683counters are controlled by the fixed_counter_bitmap.
4684
4685No flags are defined yet, the field must be zero.
Eric Hankland66bb8a02019-07-10 18:25:15 -07004686
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004687Valid values for 'action'::
4688
4689 #define KVM_PMU_EVENT_ALLOW 0
4690 #define KVM_PMU_EVENT_DENY 1
Eric Hankland66bb8a02019-07-10 18:25:15 -07004691
Bharata B Rao22945682019-11-25 08:36:30 +053046924.121 KVM_PPC_SVM_OFF
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004693---------------------
Bharata B Rao22945682019-11-25 08:36:30 +05304694
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004695:Capability: basic
4696:Architectures: powerpc
4697:Type: vm ioctl
4698:Parameters: none
4699:Returns: 0 on successful completion,
4700
Bharata B Rao22945682019-11-25 08:36:30 +05304701Errors:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01004702
4703 ====== ================================================================
4704 EINVAL if ultravisor failed to terminate the secure guest
4705 ENOMEM if hypervisor failed to allocate new radix page tables for guest
4706 ====== ================================================================
Bharata B Rao22945682019-11-25 08:36:30 +05304707
4708This ioctl is used to turn off the secure mode of the guest or transition
4709the guest from secure mode to normal mode. This is invoked when the guest
4710is reset. This has no effect if called for a normal guest.
4711
4712This ioctl issues an ultravisor call to terminate the secure guest,
4713unpins the VPA pages and releases all the device pages that are used to
4714track the secure pages by hypervisor.
Eric Hankland66bb8a02019-07-10 18:25:15 -07004715
Janosch Frank7de3f142020-01-31 05:02:02 -050047164.122 KVM_S390_NORMAL_RESET
Christian Borntraegera93236f2020-02-24 11:15:59 +01004717---------------------------
Janosch Frank7de3f142020-01-31 05:02:02 -05004718
Christian Borntraegera93236f2020-02-24 11:15:59 +01004719:Capability: KVM_CAP_S390_VCPU_RESETS
4720:Architectures: s390
4721:Type: vcpu ioctl
4722:Parameters: none
4723:Returns: 0
Janosch Frank7de3f142020-01-31 05:02:02 -05004724
4725This ioctl resets VCPU registers and control structures according to
4726the cpu reset definition in the POP (Principles Of Operation).
4727
47284.123 KVM_S390_INITIAL_RESET
Christian Borntraegera93236f2020-02-24 11:15:59 +01004729----------------------------
Janosch Frank7de3f142020-01-31 05:02:02 -05004730
Christian Borntraegera93236f2020-02-24 11:15:59 +01004731:Capability: none
4732:Architectures: s390
4733:Type: vcpu ioctl
4734:Parameters: none
4735:Returns: 0
Janosch Frank7de3f142020-01-31 05:02:02 -05004736
4737This ioctl resets VCPU registers and control structures according to
4738the initial cpu reset definition in the POP. However, the cpu is not
4739put into ESA mode. This reset is a superset of the normal reset.
4740
47414.124 KVM_S390_CLEAR_RESET
Christian Borntraegera93236f2020-02-24 11:15:59 +01004742--------------------------
Janosch Frank7de3f142020-01-31 05:02:02 -05004743
Christian Borntraegera93236f2020-02-24 11:15:59 +01004744:Capability: KVM_CAP_S390_VCPU_RESETS
4745:Architectures: s390
4746:Type: vcpu ioctl
4747:Parameters: none
4748:Returns: 0
Janosch Frank7de3f142020-01-31 05:02:02 -05004749
4750This ioctl resets VCPU registers and control structures according to
4751the clear cpu reset definition in the POP. However, the cpu is not put
4752into ESA mode. This reset is a superset of the initial reset.
4753
4754
Janosch Frank04ed89d2019-11-08 05:05:26 -050047554.125 KVM_S390_PV_COMMAND
4756-------------------------
4757
4758:Capability: KVM_CAP_S390_PROTECTED
4759:Architectures: s390
4760:Type: vm ioctl
4761:Parameters: struct kvm_pv_cmd
4762:Returns: 0 on success, < 0 on error
4763
4764::
4765
4766 struct kvm_pv_cmd {
4767 __u32 cmd; /* Command to be executed */
4768 __u16 rc; /* Ultravisor return code */
4769 __u16 rrc; /* Ultravisor return reason code */
4770 __u64 data; /* Data or address */
4771 __u32 flags; /* flags for future extensions. Must be 0 for now */
4772 __u32 reserved[3];
4773 };
4774
4775cmd values:
4776
4777KVM_PV_ENABLE
4778 Allocate memory and register the VM with the Ultravisor, thereby
4779 donating memory to the Ultravisor that will become inaccessible to
4780 KVM. All existing CPUs are converted to protected ones. After this
4781 command has succeeded, any CPU added via hotplug will become
4782 protected during its creation as well.
4783
Christian Borntraeger7a265362020-03-27 08:06:42 +01004784 Errors:
4785
4786 ===== =============================
4787 EINTR an unmasked signal is pending
4788 ===== =============================
4789
Janosch Frank04ed89d2019-11-08 05:05:26 -05004790KVM_PV_DISABLE
4791
4792 Deregister the VM from the Ultravisor and reclaim the memory that
4793 had been donated to the Ultravisor, making it usable by the kernel
4794 again. All registered VCPUs are converted back to non-protected
4795 ones.
4796
4797KVM_PV_VM_SET_SEC_PARMS
4798 Pass the image header from VM memory to the Ultravisor in
4799 preparation of image unpacking and verification.
4800
4801KVM_PV_VM_UNPACK
4802 Unpack (protect and decrypt) a page of the encrypted boot image.
4803
4804KVM_PV_VM_VERIFY
4805 Verify the integrity of the unpacked image. Only if this succeeds,
4806 KVM is allowed to start protected VCPUs.
4807
Alexander Graf1a1552542020-09-25 16:34:21 +020048084.126 KVM_X86_SET_MSR_FILTER
4809----------------------------
4810
Siddharth Chandrasekaran46a63922021-05-03 14:00:58 +02004811:Capability: KVM_CAP_X86_MSR_FILTER
Alexander Graf1a1552542020-09-25 16:34:21 +02004812:Architectures: x86
4813:Type: vm ioctl
4814:Parameters: struct kvm_msr_filter
4815:Returns: 0 on success, < 0 on error
4816
4817::
4818
4819 struct kvm_msr_filter_range {
4820 #define KVM_MSR_FILTER_READ (1 << 0)
4821 #define KVM_MSR_FILTER_WRITE (1 << 1)
4822 __u32 flags;
4823 __u32 nmsrs; /* number of msrs in bitmap */
4824 __u32 base; /* MSR index the bitmap starts at */
4825 __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */
4826 };
4827
4828 #define KVM_MSR_FILTER_MAX_RANGES 16
4829 struct kvm_msr_filter {
4830 #define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)
4831 #define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0)
4832 __u32 flags;
4833 struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES];
4834 };
4835
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004836flags values for ``struct kvm_msr_filter_range``:
Alexander Graf1a1552542020-09-25 16:34:21 +02004837
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004838``KVM_MSR_FILTER_READ``
Alexander Graf1a1552542020-09-25 16:34:21 +02004839
4840 Filter read accesses to MSRs using the given bitmap. A 0 in the bitmap
4841 indicates that a read should immediately fail, while a 1 indicates that
4842 a read for a particular MSR should be handled regardless of the default
4843 filter action.
4844
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004845``KVM_MSR_FILTER_WRITE``
Alexander Graf1a1552542020-09-25 16:34:21 +02004846
4847 Filter write accesses to MSRs using the given bitmap. A 0 in the bitmap
4848 indicates that a write should immediately fail, while a 1 indicates that
4849 a write for a particular MSR should be handled regardless of the default
4850 filter action.
4851
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004852``KVM_MSR_FILTER_READ | KVM_MSR_FILTER_WRITE``
Alexander Graf1a1552542020-09-25 16:34:21 +02004853
4854 Filter both read and write accesses to MSRs using the given bitmap. A 0
4855 in the bitmap indicates that both reads and writes should immediately fail,
4856 while a 1 indicates that reads and writes for a particular MSR are not
4857 filtered by this range.
4858
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004859flags values for ``struct kvm_msr_filter``:
Alexander Graf1a1552542020-09-25 16:34:21 +02004860
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004861``KVM_MSR_FILTER_DEFAULT_ALLOW``
Alexander Graf1a1552542020-09-25 16:34:21 +02004862
4863 If no filter range matches an MSR index that is getting accessed, KVM will
4864 fall back to allowing access to the MSR.
4865
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004866``KVM_MSR_FILTER_DEFAULT_DENY``
Alexander Graf1a1552542020-09-25 16:34:21 +02004867
4868 If no filter range matches an MSR index that is getting accessed, KVM will
4869 fall back to rejecting access to the MSR. In this mode, all MSRs that should
4870 be processed by KVM need to explicitly be marked as allowed in the bitmaps.
4871
4872This ioctl allows user space to define up to 16 bitmaps of MSR ranges to
4873specify whether a certain MSR access should be explicitly filtered for or not.
4874
4875If this ioctl has never been invoked, MSR accesses are not guarded and the
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004876default KVM in-kernel emulation behavior is fully preserved.
Alexander Graf1a1552542020-09-25 16:34:21 +02004877
Paolo Bonzini043248b2020-10-20 10:57:01 -04004878Calling this ioctl with an empty set of ranges (all nmsrs == 0) disables MSR
4879filtering. In that mode, ``KVM_MSR_FILTER_DEFAULT_DENY`` is invalid and causes
4880an error.
4881
Alexander Graf1a1552542020-09-25 16:34:21 +02004882As soon as the filtering is in place, every MSR access is processed through
Sean Christopherson9389b9d2020-10-05 12:55:32 -07004883the filtering except for accesses to the x2APIC MSRs (from 0x800 to 0x8ff);
4884x2APIC MSRs are always allowed, independent of the ``default_allow`` setting,
4885and their behavior depends on the ``X2APIC_ENABLE`` bit of the APIC base
4886register.
4887
Paolo Bonzini043248b2020-10-20 10:57:01 -04004888If a bit is within one of the defined ranges, read and write accesses are
4889guarded by the bitmap's value for the MSR index if the kind of access
4890is included in the ``struct kvm_msr_filter_range`` flags. If no range
4891cover this particular access, the behavior is determined by the flags
4892field in the kvm_msr_filter struct: ``KVM_MSR_FILTER_DEFAULT_ALLOW``
4893and ``KVM_MSR_FILTER_DEFAULT_DENY``.
Alexander Graf1a1552542020-09-25 16:34:21 +02004894
4895Each bitmap range specifies a range of MSRs to potentially allow access on.
4896The range goes from MSR index [base .. base+nmsrs]. The flags field
4897indicates whether reads, writes or both reads and writes are filtered
4898by setting a 1 bit in the bitmap for the corresponding MSR index.
4899
4900If an MSR access is not permitted through the filtering, it generates a
4901#GP inside the guest. When combined with KVM_CAP_X86_USER_SPACE_MSR, that
4902allows user space to deflect and potentially handle various MSR accesses
4903into user space.
4904
Sean Christophersonb318e8d2021-03-16 11:44:33 -07004905Note, invoking this ioctl with a vCPU is running is inherently racy. However,
4906KVM does guarantee that vCPUs will see either the previous filter or the new
4907filter, e.g. MSRs with identical settings in both the old and new filter will
4908have deterministic behavior.
Alexander Graf1a1552542020-09-25 16:34:21 +02004909
David Woodhousee1f68162020-12-04 09:03:56 +000049104.127 KVM_XEN_HVM_SET_ATTR
4911--------------------------
4912
4913:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4914:Architectures: x86
4915:Type: vm ioctl
4916:Parameters: struct kvm_xen_hvm_attr
4917:Returns: 0 on success, < 0 on error
4918
4919::
4920
4921 struct kvm_xen_hvm_attr {
4922 __u16 type;
4923 __u16 pad[3];
4924 union {
4925 __u8 long_mode;
4926 __u8 vector;
4927 struct {
4928 __u64 gfn;
4929 } shared_info;
4930 __u64 pad[4];
4931 } u;
4932 };
4933
4934type values:
4935
4936KVM_XEN_ATTR_TYPE_LONG_MODE
4937 Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This
4938 determines the layout of the shared info pages exposed to the VM.
4939
4940KVM_XEN_ATTR_TYPE_SHARED_INFO
4941 Sets the guest physical frame number at which the Xen "shared info"
4942 page resides. Note that although Xen places vcpu_info for the first
4943 32 vCPUs in the shared_info page, KVM does not automatically do so
4944 and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used
4945 explicitly even when the vcpu_info for a given vCPU resides at the
4946 "default" location in the shared_info page. This is because KVM is
4947 not aware of the Xen CPU id which is used as the index into the
4948 vcpu_info[] array, so cannot know the correct default location.
4949
4950KVM_XEN_ATTR_TYPE_UPCALL_VECTOR
4951 Sets the exception vector used to deliver Xen event channel upcalls.
4952
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +010049534.127 KVM_XEN_HVM_GET_ATTR
David Woodhousee1f68162020-12-04 09:03:56 +00004954--------------------------
4955
4956:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4957:Architectures: x86
4958:Type: vm ioctl
4959:Parameters: struct kvm_xen_hvm_attr
4960:Returns: 0 on success, < 0 on error
4961
4962Allows Xen VM attributes to be read. For the structure and types,
4963see KVM_XEN_HVM_SET_ATTR above.
4964
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +010049654.128 KVM_XEN_VCPU_SET_ATTR
David Woodhousee1f68162020-12-04 09:03:56 +00004966---------------------------
4967
4968:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
4969:Architectures: x86
4970:Type: vcpu ioctl
4971:Parameters: struct kvm_xen_vcpu_attr
4972:Returns: 0 on success, < 0 on error
4973
4974::
4975
4976 struct kvm_xen_vcpu_attr {
4977 __u16 type;
4978 __u16 pad[3];
4979 union {
4980 __u64 gpa;
4981 __u64 pad[4];
David Woodhouse30b5c852021-03-01 12:53:09 +00004982 struct {
4983 __u64 state;
4984 __u64 state_entry_time;
4985 __u64 time_running;
4986 __u64 time_runnable;
4987 __u64 time_blocked;
4988 __u64 time_offline;
4989 } runstate;
David Woodhousee1f68162020-12-04 09:03:56 +00004990 } u;
4991 };
4992
4993type values:
4994
4995KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO
4996 Sets the guest physical address of the vcpu_info for a given vCPU.
4997
4998KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO
4999 Sets the guest physical address of an additional pvclock structure
5000 for a given vCPU. This is typically used for guest vsyscall support.
5001
David Woodhouse30b5c852021-03-01 12:53:09 +00005002KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR
5003 Sets the guest physical address of the vcpu_runstate_info for a given
5004 vCPU. This is how a Xen guest tracks CPU state such as steal time.
5005
5006KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_CURRENT
5007 Sets the runstate (RUNSTATE_running/_runnable/_blocked/_offline) of
5008 the given vCPU from the .u.runstate.state member of the structure.
5009 KVM automatically accounts running and runnable time but blocked
5010 and offline states are only entered explicitly.
5011
5012KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_DATA
5013 Sets all fields of the vCPU runstate data from the .u.runstate member
5014 of the structure, including the current runstate. The state_entry_time
5015 must equal the sum of the other four times.
5016
5017KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST
5018 This *adds* the contents of the .u.runstate members of the structure
5019 to the corresponding members of the given vCPU's runstate data, thus
5020 permitting atomic adjustments to the runstate times. The adjustment
5021 to the state_entry_time must equal the sum of the adjustments to the
5022 other four times. The state field must be set to -1, or to a valid
5023 runstate value (RUNSTATE_running, RUNSTATE_runnable, RUNSTATE_blocked
5024 or RUNSTATE_offline) to set the current accounted state as of the
5025 adjusted state_entry_time.
5026
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +010050274.129 KVM_XEN_VCPU_GET_ATTR
Paolo Bonzini9294b8a2021-02-09 05:07:45 -05005028---------------------------
David Woodhousee1f68162020-12-04 09:03:56 +00005029
5030:Capability: KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO
5031:Architectures: x86
5032:Type: vcpu ioctl
5033:Parameters: struct kvm_xen_vcpu_attr
5034:Returns: 0 on success, < 0 on error
5035
5036Allows Xen vCPU attributes to be read. For the structure and types,
5037see KVM_XEN_VCPU_SET_ATTR above.
Janosch Frank04ed89d2019-11-08 05:05:26 -05005038
David Woodhouse30b5c852021-03-01 12:53:09 +00005039The KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADJUST type may not be used
5040with the KVM_XEN_VCPU_GET_ATTR ioctl.
5041
Maxim Levitsky6dba9402021-06-07 12:02:02 +03005042
50434.131 KVM_GET_SREGS2
5044------------------
5045
5046:Capability: KVM_CAP_SREGS2
5047:Architectures: x86
5048:Type: vcpu ioctl
5049:Parameters: struct kvm_sregs2 (out)
5050:Returns: 0 on success, -1 on error
5051
5052Reads special registers from the vcpu.
5053This ioctl (when supported) replaces the KVM_GET_SREGS.
5054
5055::
5056
5057struct kvm_sregs2 {
5058 /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */
5059 struct kvm_segment cs, ds, es, fs, gs, ss;
5060 struct kvm_segment tr, ldt;
5061 struct kvm_dtable gdt, idt;
5062 __u64 cr0, cr2, cr3, cr4, cr8;
5063 __u64 efer;
5064 __u64 apic_base;
5065 __u64 flags;
5066 __u64 pdptrs[4];
5067};
5068
5069flags values for ``kvm_sregs2``:
5070
5071``KVM_SREGS2_FLAGS_PDPTRS_VALID``
5072
5073 Indicates thats the struct contain valid PDPTR values.
5074
5075
50764.132 KVM_SET_SREGS2
5077------------------
5078
5079:Capability: KVM_CAP_SREGS2
5080:Architectures: x86
5081:Type: vcpu ioctl
5082:Parameters: struct kvm_sregs2 (in)
5083:Returns: 0 on success, -1 on error
5084
5085Writes special registers into the vcpu.
5086See KVM_GET_SREGS2 for the data structures.
5087This ioctl (when supported) replaces the KVM_SET_SREGS.
5088
Jing Zhangfdc09dd2021-06-18 22:27:07 +000050894.133 KVM_GET_STATS_FD
5090----------------------
5091
5092:Capability: KVM_CAP_STATS_BINARY_FD
5093:Architectures: all
5094:Type: vm ioctl, vcpu ioctl
5095:Parameters: none
5096:Returns: statistics file descriptor on success, < 0 on error
5097
5098Errors:
5099
5100 ====== ======================================================
5101 ENOMEM if the fd could not be created due to lack of memory
5102 EMFILE if the number of opened files exceeds the limit
5103 ====== ======================================================
5104
5105The returned file descriptor can be used to read VM/vCPU statistics data in
5106binary format. The data in the file descriptor consists of four blocks
5107organized as follows:
5108
5109+-------------+
5110| Header |
5111+-------------+
5112| id string |
5113+-------------+
5114| Descriptors |
5115+-------------+
5116| Stats Data |
5117+-------------+
5118
5119Apart from the header starting at offset 0, please be aware that it is
5120not guaranteed that the four blocks are adjacent or in the above order;
5121the offsets of the id, descriptors and data blocks are found in the
5122header. However, all four blocks are aligned to 64 bit offsets in the
5123file and they do not overlap.
5124
5125All blocks except the data block are immutable. Userspace can read them
5126only one time after retrieving the file descriptor, and then use ``pread`` or
5127``lseek`` to read the statistics repeatedly.
5128
5129All data is in system endianness.
5130
5131The format of the header is as follows::
5132
5133 struct kvm_stats_header {
5134 __u32 flags;
5135 __u32 name_size;
5136 __u32 num_desc;
5137 __u32 id_offset;
5138 __u32 desc_offset;
5139 __u32 data_offset;
5140 };
5141
5142The ``flags`` field is not used at the moment. It is always read as 0.
5143
5144The ``name_size`` field is the size (in byte) of the statistics name string
5145(including trailing '\0') which is contained in the "id string" block and
5146appended at the end of every descriptor.
5147
5148The ``num_desc`` field is the number of descriptors that are included in the
5149descriptor block. (The actual number of values in the data block may be
5150larger, since each descriptor may comprise more than one value).
5151
5152The ``id_offset`` field is the offset of the id string from the start of the
5153file indicated by the file descriptor. It is a multiple of 8.
5154
5155The ``desc_offset`` field is the offset of the Descriptors block from the start
5156of the file indicated by the file descriptor. It is a multiple of 8.
5157
5158The ``data_offset`` field is the offset of the Stats Data block from the start
5159of the file indicated by the file descriptor. It is a multiple of 8.
5160
5161The id string block contains a string which identifies the file descriptor on
5162which KVM_GET_STATS_FD was invoked. The size of the block, including the
5163trailing ``'\0'``, is indicated by the ``name_size`` field in the header.
5164
5165The descriptors block is only needed to be read once for the lifetime of the
5166file descriptor contains a sequence of ``struct kvm_stats_desc``, each followed
5167by a string of size ``name_size``.
5168
5169 #define KVM_STATS_TYPE_SHIFT 0
5170 #define KVM_STATS_TYPE_MASK (0xF << KVM_STATS_TYPE_SHIFT)
5171 #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT)
5172 #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT)
5173 #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT)
5174
5175 #define KVM_STATS_UNIT_SHIFT 4
5176 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT)
5177 #define KVM_STATS_UNIT_NONE (0x0 << KVM_STATS_UNIT_SHIFT)
5178 #define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT)
5179 #define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT)
5180 #define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT)
5181
5182 #define KVM_STATS_BASE_SHIFT 8
5183 #define KVM_STATS_BASE_MASK (0xF << KVM_STATS_BASE_SHIFT)
5184 #define KVM_STATS_BASE_POW10 (0x0 << KVM_STATS_BASE_SHIFT)
5185 #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT)
5186
5187 struct kvm_stats_desc {
5188 __u32 flags;
5189 __s16 exponent;
5190 __u16 size;
5191 __u32 offset;
5192 __u32 unused;
5193 char name[];
5194 };
5195
5196The ``flags`` field contains the type and unit of the statistics data described
5197by this descriptor. Its endianness is CPU native.
5198The following flags are supported:
5199
5200Bits 0-3 of ``flags`` encode the type:
5201 * ``KVM_STATS_TYPE_CUMULATIVE``
5202 The statistics data is cumulative. The value of data can only be increased.
5203 Most of the counters used in KVM are of this type.
5204 The corresponding ``size`` field for this type is always 1.
5205 All cumulative statistics data are read/write.
5206 * ``KVM_STATS_TYPE_INSTANT``
5207 The statistics data is instantaneous. Its value can be increased or
5208 decreased. This type is usually used as a measurement of some resources,
5209 like the number of dirty pages, the number of large pages, etc.
5210 All instant statistics are read only.
5211 The corresponding ``size`` field for this type is always 1.
5212 * ``KVM_STATS_TYPE_PEAK``
5213 The statistics data is peak. The value of data can only be increased, and
5214 represents a peak value for a measurement, for example the maximum number
5215 of items in a hash table bucket, the longest time waited and so on.
5216 The corresponding ``size`` field for this type is always 1.
5217
5218Bits 4-7 of ``flags`` encode the unit:
5219 * ``KVM_STATS_UNIT_NONE``
5220 There is no unit for the value of statistics data. This usually means that
5221 the value is a simple counter of an event.
5222 * ``KVM_STATS_UNIT_BYTES``
5223 It indicates that the statistics data is used to measure memory size, in the
5224 unit of Byte, KiByte, MiByte, GiByte, etc. The unit of the data is
5225 determined by the ``exponent`` field in the descriptor.
5226 * ``KVM_STATS_UNIT_SECONDS``
5227 It indicates that the statistics data is used to measure time or latency.
5228 * ``KVM_STATS_UNIT_CYCLES``
5229 It indicates that the statistics data is used to measure CPU clock cycles.
5230
5231Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the
5232unit:
5233 * ``KVM_STATS_BASE_POW10``
5234 The scale is based on power of 10. It is used for measurement of time and
5235 CPU clock cycles. For example, an exponent of -9 can be used with
5236 ``KVM_STATS_UNIT_SECONDS`` to express that the unit is nanoseconds.
5237 * ``KVM_STATS_BASE_POW2``
5238 The scale is based on power of 2. It is used for measurement of memory size.
5239 For example, an exponent of 20 can be used with ``KVM_STATS_UNIT_BYTES`` to
5240 express that the unit is MiB.
5241
5242The ``size`` field is the number of values of this statistics data. Its
5243value is usually 1 for most of simple statistics. 1 means it contains an
5244unsigned 64bit data.
5245
5246The ``offset`` field is the offset from the start of Data Block to the start of
5247the corresponding statistics data.
5248
5249The ``unused`` field is reserved for future support for other types of
5250statistics data, like log/linear histogram. Its value is always 0 for the types
5251defined above.
5252
5253The ``name`` field is the name string of the statistics data. The name string
5254starts at the end of ``struct kvm_stats_desc``. The maximum length including
5255the trailing ``'\0'``, is indicated by ``name_size`` in the header.
5256
5257The Stats Data block contains an array of 64-bit values in the same order
5258as the descriptors in Descriptors block.
Maxim Levitsky6dba9402021-06-07 12:02:02 +03005259
Avi Kivity9c1b96e2009-06-09 12:37:58 +030052605. The kvm_run structure
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005261========================
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005262
5263Application code obtains a pointer to the kvm_run structure by
5264mmap()ing a vcpu fd. From that point, application code can control
5265execution by changing fields in kvm_run prior to calling the KVM_RUN
5266ioctl, and obtain information about the reason KVM_RUN returned by
5267looking up structure members.
5268
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005269::
5270
5271 struct kvm_run {
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005272 /* in */
5273 __u8 request_interrupt_window;
5274
5275Request that KVM_RUN return when it becomes possible to inject external
5276interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
5277
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005278::
5279
Paolo Bonzini460df4c2017-02-08 11:50:15 +01005280 __u8 immediate_exit;
5281
5282This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
5283exits immediately, returning -EINTR. In the common scenario where a
5284signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
5285to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
5286Rather than blocking the signal outside KVM_RUN, userspace can set up
5287a signal handler that sets run->immediate_exit to a non-zero value.
5288
5289This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
5290
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005291::
5292
Paolo Bonzini460df4c2017-02-08 11:50:15 +01005293 __u8 padding1[6];
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005294
5295 /* out */
5296 __u32 exit_reason;
5297
5298When KVM_RUN has returned successfully (return value 0), this informs
5299application code why KVM_RUN has returned. Allowable values for this
5300field are detailed below.
5301
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005302::
5303
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005304 __u8 ready_for_interrupt_injection;
5305
5306If request_interrupt_window has been specified, this field indicates
5307an interrupt can be injected now with KVM_INTERRUPT.
5308
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005309::
5310
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005311 __u8 if_flag;
5312
5313The value of the current interrupt flag. Only valid if in-kernel
5314local APIC is not used.
5315
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005316::
5317
Paolo Bonzinif0778252015-04-01 15:06:40 +02005318 __u16 flags;
5319
5320More architecture-specific flags detailing state of the VCPU that may
Chenyi Qiang96564d72021-02-26 15:55:41 +08005321affect the device's behavior. Current defined flags::
5322
Chenyi Qiangc32b1b892020-11-06 17:03:15 +08005323 /* x86, set if the VCPU is in system management mode */
5324 #define KVM_RUN_X86_SMM (1 << 0)
5325 /* x86, set if bus lock detected in VM */
5326 #define KVM_RUN_BUS_LOCK (1 << 1)
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005327
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005328::
5329
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005330 /* in (pre_kvm_run), out (post_kvm_run) */
5331 __u64 cr8;
5332
5333The value of the cr8 register. Only valid if in-kernel local APIC is
5334not used. Both input and output.
5335
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005336::
5337
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005338 __u64 apic_base;
5339
5340The value of the APIC BASE msr. Only valid if in-kernel local
5341APIC is not used. Both input and output.
5342
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005343::
5344
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005345 union {
5346 /* KVM_EXIT_UNKNOWN */
5347 struct {
5348 __u64 hardware_exit_reason;
5349 } hw;
5350
5351If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
5352reasons. Further architecture-specific information is available in
5353hardware_exit_reason.
5354
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005355::
5356
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005357 /* KVM_EXIT_FAIL_ENTRY */
5358 struct {
5359 __u64 hardware_entry_failure_reason;
Jim Mattson1aa561b2020-06-03 16:56:21 -07005360 __u32 cpu; /* if KVM_LAST_CPU */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005361 } fail_entry;
5362
5363If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
5364to unknown reasons. Further architecture-specific information is
5365available in hardware_entry_failure_reason.
5366
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005367::
5368
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005369 /* KVM_EXIT_EXCEPTION */
5370 struct {
5371 __u32 exception;
5372 __u32 error_code;
5373 } ex;
5374
5375Unused.
5376
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005377::
5378
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005379 /* KVM_EXIT_IO */
5380 struct {
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005381 #define KVM_EXIT_IO_IN 0
5382 #define KVM_EXIT_IO_OUT 1
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005383 __u8 direction;
5384 __u8 size; /* bytes */
5385 __u16 port;
5386 __u32 count;
5387 __u64 data_offset; /* relative to kvm_run start */
5388 } io;
5389
Wu Fengguang2044892d2009-12-24 09:04:16 +08005390If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005391executed a port I/O instruction which could not be satisfied by kvm.
5392data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
5393where kvm expects application code to place the data for the next
Wu Fengguang2044892d2009-12-24 09:04:16 +08005394KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005395
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005396::
5397
Alex Bennée8ab30c12015-07-07 17:29:53 +01005398 /* KVM_EXIT_DEBUG */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005399 struct {
5400 struct kvm_debug_exit_arch arch;
5401 } debug;
5402
Alex Bennée8ab30c12015-07-07 17:29:53 +01005403If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
5404for which architecture specific information is returned.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005405
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005406::
5407
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005408 /* KVM_EXIT_MMIO */
5409 struct {
5410 __u64 phys_addr;
5411 __u8 data[8];
5412 __u32 len;
5413 __u8 is_write;
5414 } mmio;
5415
Wu Fengguang2044892d2009-12-24 09:04:16 +08005416If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005417executed a memory-mapped I/O instruction which could not be satisfied
5418by kvm. The 'data' member contains the written data if 'is_write' is
5419true, and should be filled by application code otherwise.
5420
Christoffer Dall6acdb162014-01-28 08:28:42 -08005421The 'data' member contains, in its first 'len' bytes, the value as it would
5422appear if the VCPU performed a load or store of the appropriate width directly
5423to the byte array.
5424
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005425.. note::
5426
David Woodhousee1f68162020-12-04 09:03:56 +00005427 For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN,
Alexander Graf1ae09952020-09-25 16:34:16 +02005428 KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding
5429 operations are complete (and guest state is consistent) only after userspace
5430 has re-entered the kernel with KVM_RUN. The kernel side will first finish
David Woodhousee1f68162020-12-04 09:03:56 +00005431 incomplete operations and then check for pending signals.
5432
5433 The pending state of the operation is not preserved in state which is
5434 visible to userspace, thus userspace should ensure that the operation is
5435 completed before performing a live migration. Userspace can re-enter the
5436 guest with an unmasked signal pending or with the immediate_exit field set
5437 to complete pending operations without allowing any further instructions
5438 to be executed.
Marcelo Tosatti67961342010-02-13 16:10:26 -02005439
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005440::
5441
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005442 /* KVM_EXIT_HYPERCALL */
5443 struct {
5444 __u64 nr;
5445 __u64 args[6];
5446 __u64 ret;
5447 __u32 longmode;
5448 __u32 pad;
5449 } hypercall;
5450
Avi Kivity647dc492010-04-01 14:39:21 +03005451Unused. This was once used for 'hypercall to userspace'. To implement
5452such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005453
5454.. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
5455
5456::
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005457
5458 /* KVM_EXIT_TPR_ACCESS */
5459 struct {
5460 __u64 rip;
5461 __u32 is_write;
5462 __u32 pad;
5463 } tpr_access;
5464
5465To be documented (KVM_TPR_ACCESS_REPORTING).
5466
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005467::
5468
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005469 /* KVM_EXIT_S390_SIEIC */
5470 struct {
5471 __u8 icptcode;
5472 __u64 mask; /* psw upper half */
5473 __u64 addr; /* psw lower half */
5474 __u16 ipa;
5475 __u32 ipb;
5476 } s390_sieic;
5477
5478s390 specific.
5479
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005480::
5481
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005482 /* KVM_EXIT_S390_RESET */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005483 #define KVM_S390_RESET_POR 1
5484 #define KVM_S390_RESET_CLEAR 2
5485 #define KVM_S390_RESET_SUBSYSTEM 4
5486 #define KVM_S390_RESET_CPU_INIT 8
5487 #define KVM_S390_RESET_IPL 16
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005488 __u64 s390_reset_flags;
5489
5490s390 specific.
5491
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005492::
5493
Carsten Ottee168bf82012-01-04 10:25:22 +01005494 /* KVM_EXIT_S390_UCONTROL */
5495 struct {
5496 __u64 trans_exc_code;
5497 __u32 pgm_code;
5498 } s390_ucontrol;
5499
5500s390 specific. A page fault has occurred for a user controlled virtual
5501machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
5502resolved by the kernel.
5503The program code and the translation exception code that were placed
5504in the cpu's lowcore are presented here as defined by the z Architecture
5505Principles of Operation Book in the Chapter for Dynamic Address Translation
5506(DAT)
5507
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005508::
5509
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005510 /* KVM_EXIT_DCR */
5511 struct {
5512 __u32 dcrn;
5513 __u32 data;
5514 __u8 is_write;
5515 } dcr;
5516
Alexander Grafce91ddc2014-07-28 19:29:13 +02005517Deprecated - was used for 440 KVM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005518
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005519::
5520
Alexander Grafad0a0482010-03-24 21:48:30 +01005521 /* KVM_EXIT_OSI */
5522 struct {
5523 __u64 gprs[32];
5524 } osi;
5525
5526MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
5527hypercalls and exit with this exit struct that contains all the guest gprs.
5528
5529If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
5530Userspace can now handle the hypercall and when it's done modify the gprs as
5531necessary. Upon guest entry all guest GPRs will then be replaced by the values
5532in this struct.
5533
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005534::
5535
Paul Mackerrasde56a942011-06-29 00:21:34 +00005536 /* KVM_EXIT_PAPR_HCALL */
5537 struct {
5538 __u64 nr;
5539 __u64 ret;
5540 __u64 args[9];
5541 } papr_hcall;
5542
5543This is used on 64-bit PowerPC when emulating a pSeries partition,
5544e.g. with the 'pseries' machine type in qemu. It occurs when the
5545guest does a hypercall using the 'sc 1' instruction. The 'nr' field
5546contains the hypercall number (from the guest R3), and 'args' contains
5547the arguments (from the guest R4 - R12). Userspace should put the
5548return code in 'ret' and any extra returned values in args[].
5549The possible hypercalls are defined in the Power Architecture Platform
5550Requirements (PAPR) document available from www.power.org (free
5551developer registration required to access it).
5552
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005553::
5554
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005555 /* KVM_EXIT_S390_TSCH */
5556 struct {
5557 __u16 subchannel_id;
5558 __u16 subchannel_nr;
5559 __u32 io_int_parm;
5560 __u32 io_int_word;
5561 __u32 ipb;
5562 __u8 dequeued;
5563 } s390_tsch;
5564
5565s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
5566and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
5567interrupt for the target subchannel has been dequeued and subchannel_id,
5568subchannel_nr, io_int_parm and io_int_word contain the parameters for that
5569interrupt. ipb is needed for instruction parameter decoding.
5570
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005571::
5572
Alexander Graf1c810632013-01-04 18:12:48 +01005573 /* KVM_EXIT_EPR */
5574 struct {
5575 __u32 epr;
5576 } epr;
5577
5578On FSL BookE PowerPC chips, the interrupt controller has a fast patch
5579interrupt acknowledge path to the core. When the core successfully
5580delivers an interrupt, it automatically populates the EPR register with
5581the interrupt vector number and acknowledges the interrupt inside
5582the interrupt controller.
5583
5584In case the interrupt controller lives in user space, we need to do
5585the interrupt acknowledge cycle through it to fetch the next to be
5586delivered interrupt vector using this exit.
5587
5588It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
5589external interrupt has just been delivered into the guest. User space
5590should put the acknowledged interrupt vector into the 'epr' field.
5591
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005592::
5593
Anup Patel8ad6b632014-04-29 11:24:19 +05305594 /* KVM_EXIT_SYSTEM_EVENT */
5595 struct {
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005596 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
5597 #define KVM_SYSTEM_EVENT_RESET 2
5598 #define KVM_SYSTEM_EVENT_CRASH 3
Anup Patel8ad6b632014-04-29 11:24:19 +05305599 __u32 type;
5600 __u64 flags;
5601 } system_event;
5602
5603If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
5604a system-level event using some architecture specific mechanism (hypercall
5605or some special instruction). In case of ARM/ARM64, this is triggered using
5606HVC instruction based PSCI call from the vcpu. The 'type' field describes
5607the system-level event type. The 'flags' field describes architecture
5608specific flags for the system-level event.
5609
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005610Valid values for 'type' are:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005611
5612 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005613 VM. Userspace is not obliged to honour this, and if it does honour
5614 this does not need to destroy the VM synchronously (ie it may call
5615 KVM_RUN again before shutdown finally occurs).
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005616 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005617 As with SHUTDOWN, userspace can choose to ignore the request, or
5618 to schedule the reset to occur in the future and may call KVM_RUN again.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005619 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
Andrey Smetanin2ce79182015-07-03 15:01:41 +03005620 has requested a crash condition maintenance. Userspace can choose
5621 to ignore the request, or to gather VM memory core dump and/or
5622 reset/shutdown of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005623
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005624::
5625
Steve Rutherford7543a632015-07-29 23:21:41 -07005626 /* KVM_EXIT_IOAPIC_EOI */
5627 struct {
5628 __u8 vector;
5629 } eoi;
5630
5631Indicates that the VCPU's in-kernel local APIC received an EOI for a
5632level-triggered IOAPIC interrupt. This exit only triggers when the
5633IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
5634the userspace IOAPIC should process the EOI and retrigger the interrupt if
5635it is still asserted. Vector is the LAPIC interrupt vector for which the
5636EOI was received.
5637
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005638::
5639
Andrey Smetanindb3975712015-11-10 15:36:35 +03005640 struct kvm_hyperv_exit {
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005641 #define KVM_EXIT_HYPERV_SYNIC 1
5642 #define KVM_EXIT_HYPERV_HCALL 2
Jon Doronf97f5a52020-05-29 16:45:40 +03005643 #define KVM_EXIT_HYPERV_SYNDBG 3
Andrey Smetanindb3975712015-11-10 15:36:35 +03005644 __u32 type;
Jon Doronf7d31e62020-04-24 14:37:40 +03005645 __u32 pad1;
Andrey Smetanindb3975712015-11-10 15:36:35 +03005646 union {
5647 struct {
5648 __u32 msr;
Jon Doronf7d31e62020-04-24 14:37:40 +03005649 __u32 pad2;
Andrey Smetanindb3975712015-11-10 15:36:35 +03005650 __u64 control;
5651 __u64 evt_page;
5652 __u64 msg_page;
5653 } synic;
Andrey Smetanin83326e42016-02-11 16:45:01 +03005654 struct {
5655 __u64 input;
5656 __u64 result;
5657 __u64 params[2];
5658 } hcall;
Jon Doronf97f5a52020-05-29 16:45:40 +03005659 struct {
5660 __u32 msr;
5661 __u32 pad2;
5662 __u64 control;
5663 __u64 status;
5664 __u64 send_page;
5665 __u64 recv_page;
5666 __u64 pending_page;
5667 } syndbg;
Andrey Smetanindb3975712015-11-10 15:36:35 +03005668 } u;
5669 };
5670 /* KVM_EXIT_HYPERV */
5671 struct kvm_hyperv_exit hyperv;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005672
Andrey Smetanindb3975712015-11-10 15:36:35 +03005673Indicates that the VCPU exits into userspace to process some tasks
5674related to Hyper-V emulation.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005675
Andrey Smetanindb3975712015-11-10 15:36:35 +03005676Valid values for 'type' are:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005677
5678 - KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
5679
Andrey Smetanindb3975712015-11-10 15:36:35 +03005680Hyper-V SynIC state change. Notification is used to remap SynIC
5681event/message pages and to enable/disable SynIC messages/events processing
5682in userspace.
5683
Jon Doronf97f5a52020-05-29 16:45:40 +03005684 - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about
5685
5686Hyper-V Synthetic debugger state change. Notification is used to either update
5687the pending_page location or to send a control command (send the buffer located
5688in send_page or recv a buffer to recv_page).
5689
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005690::
5691
Christoffer Dallc7262002019-10-11 13:07:05 +02005692 /* KVM_EXIT_ARM_NISV */
5693 struct {
5694 __u64 esr_iss;
5695 __u64 fault_ipa;
5696 } arm_nisv;
5697
5698Used on arm and arm64 systems. If a guest accesses memory not in a memslot,
5699KVM will typically return to userspace and ask it to do MMIO emulation on its
5700behalf. However, for certain classes of instructions, no instruction decode
5701(direction, length of memory access) is provided, and fetching and decoding
5702the instruction from the VM is overly complicated to live in the kernel.
5703
5704Historically, when this situation occurred, KVM would print a warning and kill
5705the VM. KVM assumed that if the guest accessed non-memslot memory, it was
5706trying to do I/O, which just couldn't be emulated, and the warning message was
5707phrased accordingly. However, what happened more often was that a guest bug
5708caused access outside the guest memory areas which should lead to a more
5709meaningful warning message and an external abort in the guest, if the access
5710did not fall within an I/O window.
5711
5712Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable
5713this capability at VM creation. Once this is done, these types of errors will
5714instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from
5715the HSR (arm) and ESR_EL2 (arm64) in the esr_iss field, and the faulting IPA
5716in the fault_ipa field. Userspace can either fix up the access if it's
5717actually an I/O access by decoding the instruction from guest memory (if it's
5718very brave) and continue executing the guest, or it can decide to suspend,
5719dump, or restart the guest.
5720
5721Note that KVM does not skip the faulting instruction as it does for
5722KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state
5723if it decides to decode and emulate the instruction.
5724
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005725::
5726
Alexander Graf1ae09952020-09-25 16:34:16 +02005727 /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */
5728 struct {
5729 __u8 error; /* user -> kernel */
5730 __u8 pad[7];
5731 __u32 reason; /* kernel -> user */
5732 __u32 index; /* kernel -> user */
5733 __u64 data; /* kernel <-> user */
5734 } msr;
5735
5736Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is
5737enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code
5738will instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR
5739exit for writes.
5740
5741The "reason" field specifies why the MSR trap occurred. User space will only
5742receive MSR exit traps when a particular reason was requested during through
5743ENABLE_CAP. Currently valid exit reasons are:
5744
5745 KVM_MSR_EXIT_REASON_UNKNOWN - access to MSR that is unknown to KVM
5746 KVM_MSR_EXIT_REASON_INVAL - access to invalid MSRs or reserved bits
Alexander Graf1a1552542020-09-25 16:34:21 +02005747 KVM_MSR_EXIT_REASON_FILTER - access blocked by KVM_X86_SET_MSR_FILTER
Alexander Graf1ae09952020-09-25 16:34:16 +02005748
5749For KVM_EXIT_X86_RDMSR, the "index" field tells user space which MSR the guest
5750wants to read. To respond to this request with a successful read, user space
5751writes the respective data into the "data" field and must continue guest
5752execution to ensure the read data is transferred into guest register state.
5753
5754If the RDMSR request was unsuccessful, user space indicates that with a "1" in
5755the "error" field. This will inject a #GP into the guest when the VCPU is
5756executed again.
5757
5758For KVM_EXIT_X86_WRMSR, the "index" field tells user space which MSR the guest
5759wants to write. Once finished processing the event, user space must continue
5760vCPU execution. If the MSR write was unsuccessful, user space also sets the
5761"error" field to "1".
5762
5763::
5764
David Woodhousee1f68162020-12-04 09:03:56 +00005765
5766 struct kvm_xen_exit {
5767 #define KVM_EXIT_XEN_HCALL 1
5768 __u32 type;
5769 union {
5770 struct {
5771 __u32 longmode;
5772 __u32 cpl;
5773 __u64 input;
5774 __u64 result;
5775 __u64 params[6];
5776 } hcall;
5777 } u;
5778 };
5779 /* KVM_EXIT_XEN */
5780 struct kvm_hyperv_exit xen;
5781
5782Indicates that the VCPU exits into userspace to process some tasks
5783related to Xen emulation.
5784
5785Valid values for 'type' are:
5786
5787 - KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall.
5788 Userspace is expected to place the hypercall result into the appropriate
5789 field before invoking KVM_RUN again.
5790
5791::
5792
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005793 /* Fix the size of the union. */
5794 char padding[256];
5795 };
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01005796
5797 /*
5798 * shared registers between kvm and userspace.
5799 * kvm_valid_regs specifies the register classes set by the host
5800 * kvm_dirty_regs specified the register classes dirtied by userspace
5801 * struct kvm_sync_regs is architecture specific, as well as the
5802 * bits for kvm_valid_regs and kvm_dirty_regs
5803 */
5804 __u64 kvm_valid_regs;
5805 __u64 kvm_dirty_regs;
5806 union {
5807 struct kvm_sync_regs regs;
Ken Hofsass7b7e3952018-01-31 16:03:35 -08005808 char padding[SYNC_REGS_SIZE_BYTES];
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01005809 } s;
5810
5811If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
5812certain guest registers without having to call SET/GET_*REGS. Thus we can
5813avoid some system call overhead if userspace has to handle the exit.
5814Userspace can query the validity of the structure by checking
5815kvm_valid_regs for specific bits. These bits are architecture specific
5816and usually define the validity of a groups of registers. (e.g. one bit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005817for general purpose registers)
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01005818
David Hildenbrandd8482c02014-07-29 08:19:26 +02005819Please note that the kernel is allowed to use the kvm_run structure as the
5820primary storage for certain register types. Therefore, the kernel may use the
5821values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
5822
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005823::
5824
5825 };
Alexander Graf821246a2011-08-31 10:58:55 +02005826
Jan Kiszka414fa982012-04-24 16:40:15 +02005827
Borislav Petkov9c15bb12013-09-22 16:44:50 +02005828
Paul Mackerras699a0ea2014-06-02 11:02:59 +100058296. Capabilities that can be enabled on vCPUs
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005830============================================
Alexander Graf821246a2011-08-31 10:58:55 +02005831
Cornelia Huck0907c852014-06-27 09:29:26 +02005832There are certain capabilities that change the behavior of the virtual CPU or
5833the virtual machine when enabled. To enable them, please see section 4.37.
5834Below you can find a list of capabilities and what their effect on the vCPU or
5835the virtual machine is when enabling them.
Alexander Graf821246a2011-08-31 10:58:55 +02005836
5837The following information is provided along with the description:
5838
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005839 Architectures:
5840 which instruction set architectures provide this ioctl.
Alexander Graf821246a2011-08-31 10:58:55 +02005841 x86 includes both i386 and x86_64.
5842
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005843 Target:
5844 whether this is a per-vcpu or per-vm capability.
Cornelia Huck0907c852014-06-27 09:29:26 +02005845
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005846 Parameters:
5847 what parameters are accepted by the capability.
Alexander Graf821246a2011-08-31 10:58:55 +02005848
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005849 Returns:
5850 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
Alexander Graf821246a2011-08-31 10:58:55 +02005851 are not detailed, but errors with specific meanings are.
5852
Jan Kiszka414fa982012-04-24 16:40:15 +02005853
Alexander Graf821246a2011-08-31 10:58:55 +020058546.1 KVM_CAP_PPC_OSI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005855-------------------
Alexander Graf821246a2011-08-31 10:58:55 +02005856
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005857:Architectures: ppc
5858:Target: vcpu
5859:Parameters: none
5860:Returns: 0 on success; -1 on error
Alexander Graf821246a2011-08-31 10:58:55 +02005861
5862This capability enables interception of OSI hypercalls that otherwise would
5863be treated as normal system calls to be injected into the guest. OSI hypercalls
5864were invented by Mac-on-Linux to have a standardized communication mechanism
5865between the guest and the host.
5866
5867When this capability is enabled, KVM_EXIT_OSI can occur.
5868
Jan Kiszka414fa982012-04-24 16:40:15 +02005869
Alexander Graf821246a2011-08-31 10:58:55 +020058706.2 KVM_CAP_PPC_PAPR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005871--------------------
Alexander Graf821246a2011-08-31 10:58:55 +02005872
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005873:Architectures: ppc
5874:Target: vcpu
5875:Parameters: none
5876:Returns: 0 on success; -1 on error
Alexander Graf821246a2011-08-31 10:58:55 +02005877
5878This capability enables interception of PAPR hypercalls. PAPR hypercalls are
5879done using the hypercall instruction "sc 1".
5880
5881It also sets the guest privilege level to "supervisor" mode. Usually the guest
5882runs in "hypervisor" privilege mode with a few missing features.
5883
5884In addition to the above, it changes the semantics of SDR1. In this mode, the
5885HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
5886HTAB invisible to the guest.
5887
5888When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
Scott Wooddc83b8b2011-08-18 15:25:21 -05005889
Jan Kiszka414fa982012-04-24 16:40:15 +02005890
Scott Wooddc83b8b2011-08-18 15:25:21 -050058916.3 KVM_CAP_SW_TLB
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005892------------------
Scott Wooddc83b8b2011-08-18 15:25:21 -05005893
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005894:Architectures: ppc
5895:Target: vcpu
5896:Parameters: args[0] is the address of a struct kvm_config_tlb
5897:Returns: 0 on success; -1 on error
Scott Wooddc83b8b2011-08-18 15:25:21 -05005898
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005899::
5900
5901 struct kvm_config_tlb {
Scott Wooddc83b8b2011-08-18 15:25:21 -05005902 __u64 params;
5903 __u64 array;
5904 __u32 mmu_type;
5905 __u32 array_len;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005906 };
Scott Wooddc83b8b2011-08-18 15:25:21 -05005907
5908Configures the virtual CPU's TLB array, establishing a shared memory area
5909between userspace and KVM. The "params" and "array" fields are userspace
5910addresses of mmu-type-specific data structures. The "array_len" field is an
5911safety mechanism, and should be set to the size in bytes of the memory that
5912userspace has reserved for the array. It must be at least the size dictated
5913by "mmu_type" and "params".
5914
5915While KVM_RUN is active, the shared region is under control of KVM. Its
5916contents are undefined, and any modification by userspace results in
5917boundedly undefined behavior.
5918
5919On return from KVM_RUN, the shared region will reflect the current state of
5920the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
5921to tell KVM which entries have been changed, prior to calling KVM_RUN again
5922on this vcpu.
5923
5924For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005925
Scott Wooddc83b8b2011-08-18 15:25:21 -05005926 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
5927 - The "array" field points to an array of type "struct
5928 kvm_book3e_206_tlb_entry".
5929 - The array consists of all entries in the first TLB, followed by all
5930 entries in the second TLB.
5931 - Within a TLB, entries are ordered first by increasing set number. Within a
5932 set, entries are ordered by way (increasing ESEL).
5933 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
5934 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
5935 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
5936 hardware ignores this value for TLB0.
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005937
59386.4 KVM_CAP_S390_CSS_SUPPORT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005939----------------------------
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005940
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005941:Architectures: s390
5942:Target: vcpu
5943:Parameters: none
5944:Returns: 0 on success; -1 on error
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005945
5946This capability enables support for handling of channel I/O instructions.
5947
5948TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
5949handled in-kernel, while the other I/O instructions are passed to userspace.
5950
5951When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
5952SUBCHANNEL intercepts.
Alexander Graf1c810632013-01-04 18:12:48 +01005953
Cornelia Huck0907c852014-06-27 09:29:26 +02005954Note that even though this capability is enabled per-vcpu, the complete
5955virtual machine is affected.
5956
Alexander Graf1c810632013-01-04 18:12:48 +010059576.5 KVM_CAP_PPC_EPR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005958-------------------
Alexander Graf1c810632013-01-04 18:12:48 +01005959
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005960:Architectures: ppc
5961:Target: vcpu
5962:Parameters: args[0] defines whether the proxy facility is active
5963:Returns: 0 on success; -1 on error
Alexander Graf1c810632013-01-04 18:12:48 +01005964
5965This capability enables or disables the delivery of interrupts through the
5966external proxy facility.
5967
5968When enabled (args[0] != 0), every time the guest gets an external interrupt
5969delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
5970to receive the topmost interrupt vector.
5971
5972When disabled (args[0] == 0), behavior is as if this facility is unsupported.
5973
5974When this capability is enabled, KVM_EXIT_EPR can occur.
Scott Woodeb1e4f42013-04-12 14:08:47 +00005975
59766.6 KVM_CAP_IRQ_MPIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005977--------------------
Scott Woodeb1e4f42013-04-12 14:08:47 +00005978
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005979:Architectures: ppc
5980:Parameters: args[0] is the MPIC device fd;
5981 args[1] is the MPIC CPU number for this vcpu
Scott Woodeb1e4f42013-04-12 14:08:47 +00005982
5983This capability connects the vcpu to an in-kernel MPIC device.
Paul Mackerras5975a2e2013-04-27 00:28:37 +00005984
59856.7 KVM_CAP_IRQ_XICS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005986--------------------
Paul Mackerras5975a2e2013-04-27 00:28:37 +00005987
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005988:Architectures: ppc
5989:Target: vcpu
5990:Parameters: args[0] is the XICS device fd;
5991 args[1] is the XICS CPU number (server ID) for this vcpu
Paul Mackerras5975a2e2013-04-27 00:28:37 +00005992
5993This capability connects the vcpu to an in-kernel XICS device.
Cornelia Huck8a366a42014-06-27 11:06:25 +02005994
59956.8 KVM_CAP_S390_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005996------------------------
Cornelia Huck8a366a42014-06-27 11:06:25 +02005997
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005998:Architectures: s390
5999:Target: vm
6000:Parameters: none
Cornelia Huck8a366a42014-06-27 11:06:25 +02006001
6002This capability enables the in-kernel irqchip for s390. Please refer to
6003"4.24 KVM_CREATE_IRQCHIP" for details.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006004
James Hogan5fafd8742014-12-08 23:07:56 +000060056.9 KVM_CAP_MIPS_FPU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006006--------------------
James Hogan5fafd8742014-12-08 23:07:56 +00006007
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006008:Architectures: mips
6009:Target: vcpu
6010:Parameters: args[0] is reserved for future use (should be 0).
James Hogan5fafd8742014-12-08 23:07:56 +00006011
6012This capability allows the use of the host Floating Point Unit by the guest. It
6013allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006014done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be
6015accessed (depending on the current guest FPU register mode), and the Status.FR,
James Hogan5fafd8742014-12-08 23:07:56 +00006016Config5.FRE bits are accessible via the KVM API and also from the guest,
6017depending on them being supported by the FPU.
6018
James Hogand952bd02014-12-08 23:07:56 +000060196.10 KVM_CAP_MIPS_MSA
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006020---------------------
James Hogand952bd02014-12-08 23:07:56 +00006021
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006022:Architectures: mips
6023:Target: vcpu
6024:Parameters: args[0] is reserved for future use (should be 0).
James Hogand952bd02014-12-08 23:07:56 +00006025
6026This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
6027It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006028Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*``
6029registers can be accessed, and the Config5.MSAEn bit is accessible via the
6030KVM API and also from the guest.
James Hogand952bd02014-12-08 23:07:56 +00006031
Ken Hofsass01643c52018-01-31 16:03:36 -080060326.74 KVM_CAP_SYNC_REGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006033----------------------
6034
6035:Architectures: s390, x86
6036:Target: s390: always enabled, x86: vcpu
6037:Parameters: none
6038:Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
6039 sets are supported
6040 (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
Ken Hofsass01643c52018-01-31 16:03:36 -08006041
6042As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
6043KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
6044without having to call SET/GET_*REGS". This reduces overhead by eliminating
6045repeated ioctl calls for setting and/or getting register values. This is
6046particularly important when userspace is making synchronous guest state
6047modifications, e.g. when emulating and/or intercepting instructions in
6048userspace.
6049
6050For s390 specifics, please refer to the source code.
6051
6052For x86:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006053
Ken Hofsass01643c52018-01-31 16:03:36 -08006054- the register sets to be copied out to kvm_run are selectable
6055 by userspace (rather that all sets being copied out for every exit).
6056- vcpu_events are available in addition to regs and sregs.
6057
6058For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
6059function as an input bit-array field set by userspace to indicate the
6060specific register sets to be copied out on the next exit.
6061
6062To indicate when userspace has modified values that should be copied into
6063the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
6064This is done using the same bitflags as for the 'kvm_valid_regs' field.
6065If the dirty bit is not set, then the register set values will not be copied
6066into the vCPU even if they've been modified.
6067
6068Unused bitfields in the bitarrays must be set to zero.
6069
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006070::
6071
6072 struct kvm_sync_regs {
Ken Hofsass01643c52018-01-31 16:03:36 -08006073 struct kvm_regs regs;
6074 struct kvm_sregs sregs;
6075 struct kvm_vcpu_events events;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006076 };
Ken Hofsass01643c52018-01-31 16:03:36 -08006077
Cédric Le Goatereacc56b2019-04-18 12:39:28 +020060786.75 KVM_CAP_PPC_IRQ_XIVE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006079-------------------------
Cédric Le Goatereacc56b2019-04-18 12:39:28 +02006080
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006081:Architectures: ppc
6082:Target: vcpu
6083:Parameters: args[0] is the XIVE device fd;
6084 args[1] is the XIVE CPU number (server ID) for this vcpu
Cédric Le Goatereacc56b2019-04-18 12:39:28 +02006085
6086This capability connects the vcpu to an in-kernel XIVE device.
6087
Paul Mackerras699a0ea2014-06-02 11:02:59 +100060887. Capabilities that can be enabled on VMs
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006089==========================================
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006090
6091There are certain capabilities that change the behavior of the virtual
6092machine when enabled. To enable them, please see section 4.37. Below
6093you can find a list of capabilities and what their effect on the VM
6094is when enabling them.
6095
6096The following information is provided along with the description:
6097
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006098 Architectures:
6099 which instruction set architectures provide this ioctl.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006100 x86 includes both i386 and x86_64.
6101
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006102 Parameters:
6103 what parameters are accepted by the capability.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006104
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006105 Returns:
6106 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006107 are not detailed, but errors with specific meanings are.
6108
6109
61107.1 KVM_CAP_PPC_ENABLE_HCALL
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006111----------------------------
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006112
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006113:Architectures: ppc
6114:Parameters: args[0] is the sPAPR hcall number;
6115 args[1] is 0 to disable, 1 to enable in-kernel handling
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006116
6117This capability controls whether individual sPAPR hypercalls (hcalls)
6118get handled by the kernel or not. Enabling or disabling in-kernel
6119handling of an hcall is effective across the VM. On creation, an
6120initial set of hcalls are enabled for in-kernel handling, which
6121consists of those hcalls for which in-kernel handlers were implemented
6122before this capability was implemented. If disabled, the kernel will
6123not to attempt to handle the hcall, but will always exit to userspace
6124to handle it. Note that it may not make sense to enable some and
6125disable others of a group of related hcalls, but KVM does not prevent
6126userspace from doing that.
Paul Mackerrasae2113a2014-06-02 11:03:00 +10006127
6128If the hcall number specified is not one that has an in-kernel
6129implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
6130error.
David Hildenbrand2444b352014-10-09 14:10:13 +02006131
61327.2 KVM_CAP_S390_USER_SIGP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006133--------------------------
David Hildenbrand2444b352014-10-09 14:10:13 +02006134
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006135:Architectures: s390
6136:Parameters: none
David Hildenbrand2444b352014-10-09 14:10:13 +02006137
6138This capability controls which SIGP orders will be handled completely in user
6139space. With this capability enabled, all fast orders will be handled completely
6140in the kernel:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006141
David Hildenbrand2444b352014-10-09 14:10:13 +02006142- SENSE
6143- SENSE RUNNING
6144- EXTERNAL CALL
6145- EMERGENCY SIGNAL
6146- CONDITIONAL EMERGENCY SIGNAL
6147
6148All other orders will be handled completely in user space.
6149
6150Only privileged operation exceptions will be checked for in the kernel (or even
6151in the hardware prior to interception). If this capability is not enabled, the
6152old way of handling SIGP orders is used (partially in kernel and user space).
Eric Farman68c55752014-06-09 10:57:26 -04006153
61547.3 KVM_CAP_S390_VECTOR_REGISTERS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006155---------------------------------
Eric Farman68c55752014-06-09 10:57:26 -04006156
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006157:Architectures: s390
6158:Parameters: none
6159:Returns: 0 on success, negative value on error
Eric Farman68c55752014-06-09 10:57:26 -04006160
6161Allows use of the vector registers introduced with z13 processor, and
6162provides for the synchronization between host and user space. Will
6163return -EINVAL if the machine does not support vectors.
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006164
61657.4 KVM_CAP_S390_USER_STSI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006166--------------------------
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006167
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006168:Architectures: s390
6169:Parameters: none
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006170
6171This capability allows post-handlers for the STSI instruction. After
6172initial handling in the kernel, KVM exits to user space with
6173KVM_EXIT_S390_STSI to allow user space to insert further data.
6174
6175Before exiting to userspace, kvm handlers should fill in s390_stsi field of
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006176vcpu->run::
6177
6178 struct {
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006179 __u64 addr;
6180 __u8 ar;
6181 __u8 reserved;
6182 __u8 fc;
6183 __u8 sel1;
6184 __u16 sel2;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006185 } s390_stsi;
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006186
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006187 @addr - guest address of STSI SYSIB
6188 @fc - function code
6189 @sel1 - selector 1
6190 @sel2 - selector 2
6191 @ar - access register number
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006192
6193KVM handlers should exit to userspace with rc = -EREMOTE.
Michael Ellermane928e9c2015-03-20 20:39:41 +11006194
Steve Rutherford49df6392015-07-29 23:21:40 -070061957.5 KVM_CAP_SPLIT_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006196-------------------------
Steve Rutherford49df6392015-07-29 23:21:40 -07006197
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006198:Architectures: x86
6199:Parameters: args[0] - number of routes reserved for userspace IOAPICs
6200:Returns: 0 on success, -1 on error
Steve Rutherford49df6392015-07-29 23:21:40 -07006201
6202Create a local apic for each processor in the kernel. This can be used
6203instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
6204IOAPIC and PIC (and also the PIT, even though this has to be enabled
6205separately).
6206
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07006207This capability also enables in kernel routing of interrupt requests;
6208when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
6209used in the IRQ routing table. The first args[0] MSI routes are reserved
6210for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
6211a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
Steve Rutherford49df6392015-07-29 23:21:40 -07006212
6213Fails if VCPU has already been created, or if the irqchip is already in the
6214kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
6215
David Hildenbrand051c87f2016-04-19 13:13:40 +020062167.6 KVM_CAP_S390_RI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006217-------------------
David Hildenbrand051c87f2016-04-19 13:13:40 +02006218
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006219:Architectures: s390
6220:Parameters: none
David Hildenbrand051c87f2016-04-19 13:13:40 +02006221
6222Allows use of runtime-instrumentation introduced with zEC12 processor.
6223Will return -EINVAL if the machine does not support runtime-instrumentation.
6224Will return -EBUSY if a VCPU has already been created.
Michael Ellermane928e9c2015-03-20 20:39:41 +11006225
Radim Krčmář371313132016-07-12 22:09:27 +020062267.7 KVM_CAP_X2APIC_API
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006227----------------------
Radim Krčmář371313132016-07-12 22:09:27 +02006228
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006229:Architectures: x86
6230:Parameters: args[0] - features that should be enabled
6231:Returns: 0 on success, -EINVAL when args[0] contains invalid features
Radim Krčmář371313132016-07-12 22:09:27 +02006232
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006233Valid feature flags in args[0] are::
Radim Krčmář371313132016-07-12 22:09:27 +02006234
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006235 #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
6236 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
Radim Krčmář371313132016-07-12 22:09:27 +02006237
6238Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
6239KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
6240allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
6241respective sections.
6242
Radim Krčmářc5192652016-07-12 22:09:28 +02006243KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
6244in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
6245as a broadcast even in x2APIC mode in order to support physical x2APIC
6246without interrupt remapping. This is undesirable in logical mode,
6247where 0xff represents CPUs 0-7 in cluster 0.
Radim Krčmář371313132016-07-12 22:09:27 +02006248
David Hildenbrand6502a342016-06-21 14:19:51 +020062497.8 KVM_CAP_S390_USER_INSTR0
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006250----------------------------
David Hildenbrand6502a342016-06-21 14:19:51 +02006251
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006252:Architectures: s390
6253:Parameters: none
David Hildenbrand6502a342016-06-21 14:19:51 +02006254
6255With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
6256be intercepted and forwarded to user space. User space can use this
6257mechanism e.g. to realize 2-byte software breakpoints. The kernel will
6258not inject an operating exception for these instructions, user space has
6259to take care of that.
6260
6261This capability can be enabled dynamically even if VCPUs were already
6262created and are running.
Radim Krčmář371313132016-07-12 22:09:27 +02006263
Fan Zhang4e0b1ab2016-11-29 07:17:55 +010062647.9 KVM_CAP_S390_GS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006265-------------------
Fan Zhang4e0b1ab2016-11-29 07:17:55 +01006266
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006267:Architectures: s390
6268:Parameters: none
6269:Returns: 0 on success; -EINVAL if the machine does not support
6270 guarded storage; -EBUSY if a VCPU has already been created.
Fan Zhang4e0b1ab2016-11-29 07:17:55 +01006271
6272Allows use of guarded storage for the KVM guest.
6273
Yi Min Zhao47a46932017-03-10 09:29:38 +010062747.10 KVM_CAP_S390_AIS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006275---------------------
Yi Min Zhao47a46932017-03-10 09:29:38 +01006276
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006277:Architectures: s390
6278:Parameters: none
Yi Min Zhao47a46932017-03-10 09:29:38 +01006279
6280Allow use of adapter-interruption suppression.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006281:Returns: 0 on success; -EBUSY if a VCPU has already been created.
Yi Min Zhao47a46932017-03-10 09:29:38 +01006282
Paul Mackerras3c313522017-02-06 13:24:41 +110062837.11 KVM_CAP_PPC_SMT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006284--------------------
Paul Mackerras3c313522017-02-06 13:24:41 +11006285
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006286:Architectures: ppc
6287:Parameters: vsmt_mode, flags
Paul Mackerras3c313522017-02-06 13:24:41 +11006288
6289Enabling this capability on a VM provides userspace with a way to set
6290the desired virtual SMT mode (i.e. the number of virtual CPUs per
6291virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
6292between 1 and 8. On POWER8, vsmt_mode must also be no greater than
6293the number of threads per subcore for the host. Currently flags must
6294be 0. A successful call to enable this capability will result in
6295vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
6296subsequently queried for the VM. This capability is only supported by
6297HV KVM, and can only be set before any VCPUs have been created.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006298The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
6299modes are available.
Paul Mackerras3c313522017-02-06 13:24:41 +11006300
Aravinda Prasad134764e2017-05-11 16:32:48 +053063017.12 KVM_CAP_PPC_FWNMI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006302----------------------
Aravinda Prasad134764e2017-05-11 16:32:48 +05306303
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006304:Architectures: ppc
6305:Parameters: none
Aravinda Prasad134764e2017-05-11 16:32:48 +05306306
6307With this capability a machine check exception in the guest address
6308space will cause KVM to exit the guest with NMI exit reason. This
6309enables QEMU to build error log and branch to guest kernel registered
6310machine check handling routine. Without this capability KVM will
6311branch to guests' 0x200 interrupt vector.
6312
Wanpeng Li4d5422c2018-03-12 04:53:02 -070063137.13 KVM_CAP_X86_DISABLE_EXITS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006314------------------------------
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006315
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006316:Architectures: x86
6317:Parameters: args[0] defines which exits are disabled
6318:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006319
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006320Valid bits in args[0] are::
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006321
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006322 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
6323 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
6324 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
6325 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006326
6327Enabling this capability on a VM provides userspace with a way to no
6328longer intercept some instructions for improved latency in some
6329workloads, and is suggested when vCPUs are associated to dedicated
6330physical CPUs. More bits can be added in the future; userspace can
6331just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
6332all such vmexits.
6333
Wanpeng Licaa057a2018-03-12 04:53:03 -07006334Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006335
Janosch Franka4499382018-07-13 11:28:31 +010063367.14 KVM_CAP_S390_HPAGE_1M
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006337--------------------------
Janosch Franka4499382018-07-13 11:28:31 +01006338
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006339:Architectures: s390
6340:Parameters: none
6341:Returns: 0 on success, -EINVAL if hpage module parameter was not set
6342 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
6343 flag set
Janosch Franka4499382018-07-13 11:28:31 +01006344
6345With this capability the KVM support for memory backing with 1m pages
6346through hugetlbfs can be enabled for a VM. After the capability is
6347enabled, cmma can't be enabled anymore and pfmfi and the storage key
6348interpretation are disabled. If cmma has already been enabled or the
6349hpage module parameter is not set to 1, -EINVAL is returned.
6350
6351While it is generally possible to create a huge page backed VM without
6352this capability, the VM will not be able to run.
6353
Jim Mattsonc4f55192018-10-16 14:29:24 -070063547.15 KVM_CAP_MSR_PLATFORM_INFO
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006355------------------------------
Drew Schmitt6fbbde92018-08-20 10:32:15 -07006356
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006357:Architectures: x86
6358:Parameters: args[0] whether feature should be enabled or not
Drew Schmitt6fbbde92018-08-20 10:32:15 -07006359
6360With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
6361a #GP would be raised when the guest tries to access. Currently, this
6362capability does not enable write permissions of this MSR for the guest.
6363
Paul Mackerrasaa069a92018-09-21 20:02:01 +100063647.16 KVM_CAP_PPC_NESTED_HV
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006365--------------------------
Paul Mackerrasaa069a92018-09-21 20:02:01 +10006366
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006367:Architectures: ppc
6368:Parameters: none
6369:Returns: 0 on success, -EINVAL when the implementation doesn't support
6370 nested-HV virtualization.
Paul Mackerrasaa069a92018-09-21 20:02:01 +10006371
6372HV-KVM on POWER9 and later systems allows for "nested-HV"
6373virtualization, which provides a way for a guest VM to run guests that
6374can run using the CPU's supervisor mode (privileged non-hypervisor
6375state). Enabling this capability on a VM depends on the CPU having
6376the necessary functionality and on the facility being enabled with a
6377kvm-hv module parameter.
6378
Jim Mattsonc4f55192018-10-16 14:29:24 -070063797.17 KVM_CAP_EXCEPTION_PAYLOAD
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006380------------------------------
Jim Mattsonc4f55192018-10-16 14:29:24 -07006381
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006382:Architectures: x86
6383:Parameters: args[0] whether feature should be enabled or not
Jim Mattsonc4f55192018-10-16 14:29:24 -07006384
6385With this capability enabled, CR2 will not be modified prior to the
6386emulated VM-exit when L1 intercepts a #PF exception that occurs in
6387L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
6388the emulated VM-exit when L1 intercepts a #DB exception that occurs in
6389L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
6390#DB) exception for L2, exception.has_payload will be set and the
6391faulting address (or the new DR6 bits*) will be reported in the
6392exception_payload field. Similarly, when userspace injects a #PF (or
6393#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006394exception.has_payload and to put the faulting address - or the new DR6
6395bits\ [#]_ - in the exception_payload field.
Jim Mattsonc4f55192018-10-16 14:29:24 -07006396
6397This capability also enables exception.pending in struct
6398kvm_vcpu_events, which allows userspace to distinguish between pending
6399and injected exceptions.
6400
6401
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006402.. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception
6403 will clear DR6.RTM.
Jim Mattsonc4f55192018-10-16 14:29:24 -07006404
Peter Xud7547c52019-05-08 17:15:47 +080064057.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006406
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006407:Architectures: x86, arm, arm64, mips
6408:Parameters: args[0] whether feature should be enabled or not
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006409
Jay Zhou3c9bd402020-02-27 09:32:27 +08006410Valid flags are::
6411
6412 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0)
6413 #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1)
6414
6415With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not
6416automatically clear and write-protect all pages that are returned as dirty.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006417Rather, userspace will have to do this operation separately using
6418KVM_CLEAR_DIRTY_LOG.
6419
6420At the cost of a slightly more complicated operation, this provides better
6421scalability and responsiveness for two reasons. First,
6422KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
6423than requiring to sync a full memslot; this ensures that KVM does not
6424take spinlocks for an extended period of time. Second, in some cases a
6425large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
6426userspace actually using the data in the page. Pages can be modified
Jay Zhou3c9bd402020-02-27 09:32:27 +08006427during this time, which is inefficient for both the guest and userspace:
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006428the guest will incur a higher penalty due to write protection faults,
6429while userspace can see false reports of dirty pages. Manual reprotection
6430helps reducing this time, improving guest performance and reducing the
6431number of dirty log false positives.
6432
Jay Zhou3c9bd402020-02-27 09:32:27 +08006433With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap
6434will be initialized to 1 when created. This also improves performance because
6435dirty logging can be enabled gradually in small chunks on the first call
6436to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on
6437KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
Keqian Zhuc8626262020-04-13 20:20:23 +08006438x86 and arm64 for now).
Jay Zhou3c9bd402020-02-27 09:32:27 +08006439
Peter Xud7547c52019-05-08 17:15:47 +08006440KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
6441KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make
6442it hard or impossible to use it correctly. The availability of
6443KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed.
6444Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006445
Paul Mackerras9a5788c2020-03-19 15:29:55 +110064467.19 KVM_CAP_PPC_SECURE_GUEST
6447------------------------------
6448
6449:Architectures: ppc
6450
6451This capability indicates that KVM is running on a host that has
6452ultravisor firmware and thus can support a secure guest. On such a
6453system, a guest can ask the ultravisor to make it a secure guest,
6454one whose memory is inaccessible to the host except for pages which
6455are explicitly requested to be shared with the host. The ultravisor
6456notifies KVM when a guest requests to become a secure guest, and KVM
6457has the opportunity to veto the transition.
6458
6459If present, this capability can be enabled for a VM, meaning that KVM
6460will allow the transition to secure guest mode. Otherwise KVM will
6461veto the transition.
6462
David Matlackacd05782020-04-17 15:14:46 -070064637.20 KVM_CAP_HALT_POLL
6464----------------------
6465
6466:Architectures: all
6467:Target: VM
6468:Parameters: args[0] is the maximum poll time in nanoseconds
6469:Returns: 0 on success; -1 on error
6470
6471This capability overrides the kvm module parameter halt_poll_ns for the
6472target VM.
6473
6474VCPU polling allows a VCPU to poll for wakeup events instead of immediately
6475scheduling during guest halts. The maximum time a VCPU can spend polling is
6476controlled by the kvm module parameter halt_poll_ns. This capability allows
6477the maximum halt time to specified on a per-VM basis, effectively overriding
6478the module parameter for the target VM.
6479
Alexander Graf1ae09952020-09-25 16:34:16 +020064807.21 KVM_CAP_X86_USER_SPACE_MSR
6481-------------------------------
6482
6483:Architectures: x86
6484:Target: VM
6485:Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report
6486:Returns: 0 on success; -1 on error
6487
6488This capability enables trapping of #GP invoking RDMSR and WRMSR instructions
6489into user space.
6490
6491When a guest requests to read or write an MSR, KVM may not implement all MSRs
6492that are relevant to a respective system. It also does not differentiate by
6493CPU type.
6494
6495To allow more fine grained control over MSR handling, user space may enable
6496this capability. With it enabled, MSR accesses that match the mask specified in
6497args[0] and trigger a #GP event inside the guest by KVM will instead trigger
6498KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications which user space
6499can then handle to implement model specific MSR handling and/or user notifications
6500to inform a user that an MSR was not handled.
6501
Chenyi Qiangc32b1b892020-11-06 17:03:15 +080065027.22 KVM_CAP_X86_BUS_LOCK_EXIT
6503-------------------------------
6504
6505:Architectures: x86
6506:Target: VM
6507:Parameters: args[0] defines the policy used when bus locks detected in guest
6508:Returns: 0 on success, -EINVAL when args[0] contains invalid bits
6509
6510Valid bits in args[0] are::
6511
6512 #define KVM_BUS_LOCK_DETECTION_OFF (1 << 0)
6513 #define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1)
6514
6515Enabling this capability on a VM provides userspace with a way to select
6516a policy to handle the bus locks detected in guest. Userspace can obtain
6517the supported modes from the result of KVM_CHECK_EXTENSION and define it
6518through the KVM_ENABLE_CAP.
6519
6520KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
6521currently and mutually exclusive with each other. More bits can be added in
6522the future.
6523
6524With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
6525so that no additional actions are needed. This is the default mode.
6526
6527With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
6528in VM. KVM just exits to userspace when handling them. Userspace can enforce
6529its own throttling or other policy based mitigations.
6530
6531This capability is aimed to address the thread that VM can exploit bus locks to
6532degree the performance of the whole system. Once the userspace enable this
6533capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
6534KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
6535the bus lock vm exit can be preempted by a higher priority VM exit, the exit
6536notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
6537KVM_RUN_BUS_LOCK flag is used to distinguish between them.
6538
Kai Huang7d2cdad2021-02-26 22:48:32 +130065397.23 KVM_CAP_PPC_DAWR1
Ravi Bangoriad9a47ed2020-12-16 16:12:19 +05306540----------------------
6541
6542:Architectures: ppc
6543:Parameters: none
6544:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
6545
6546This capability can be used to check / enable 2nd DAWR feature provided
6547by POWER10 processor.
6548
Nathan Tempelman54526d12021-04-08 22:32:14 +000065497.24 KVM_CAP_VM_COPY_ENC_CONTEXT_FROM
6550-------------------------------------
6551
6552Architectures: x86 SEV enabled
6553Type: vm
6554Parameters: args[0] is the fd of the source vm
6555Returns: 0 on success; ENOTTY on error
6556
6557This capability enables userspace to copy encryption context from the vm
6558indicated by the fd to the vm this is called on.
6559
6560This is intended to support in-guest workloads scheduled by the host. This
6561allows the in-guest workload to maintain its own NPTs and keeps the two vms
6562from accidentally clobbering each other with interrupts and the like (separate
6563APIC/MSRs/etc).
6564
Sean Christophersonfe7e9482021-04-12 16:21:43 +120065657.25 KVM_CAP_SGX_ATTRIBUTE
Paolo Bonzinif82762f2021-04-22 09:49:46 -04006566--------------------------
Sean Christophersonfe7e9482021-04-12 16:21:43 +12006567
6568:Architectures: x86
6569:Target: VM
6570:Parameters: args[0] is a file handle of a SGX attribute file in securityfs
6571:Returns: 0 on success, -EINVAL if the file handle is invalid or if a requested
6572 attribute is not supported by KVM.
6573
6574KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or
6575more priveleged enclave attributes. args[0] must hold a file handle to a valid
6576SGX attribute file corresponding to an attribute that is supported/restricted
6577by KVM (currently only PROVISIONKEY).
6578
6579The SGX subsystem restricts access to a subset of enclave attributes to provide
6580additional security for an uncompromised kernel, e.g. use of the PROVISIONKEY
6581is restricted to deter malware from using the PROVISIONKEY to obtain a stable
6582system fingerprint. To prevent userspace from circumventing such restrictions
6583by running an enclave in a VM, KVM prevents access to privileged attributes by
6584default.
6585
6586See Documentation/x86/sgx/2.Kernel-internals.rst for more details.
6587
Bharata B Raob87cc112021-06-21 14:20:02 +053065887.26 KVM_CAP_PPC_RPT_INVALIDATE
6589-------------------------------
6590
6591:Capability: KVM_CAP_PPC_RPT_INVALIDATE
6592:Architectures: ppc
6593:Type: vm
6594
6595This capability indicates that the kernel is capable of handling
6596H_RPT_INVALIDATE hcall.
6597
6598In order to enable the use of H_RPT_INVALIDATE in the guest,
6599user space might have to advertise it for the guest. For example,
6600IBM pSeries (sPAPR) guest starts using it if "hcall-rpt-invalidate" is
6601present in the "ibm,hypertas-functions" device-tree property.
6602
6603This capability is enabled for hypervisors on platforms like POWER9
6604that support radix MMU.
6605
Michael Ellermane928e9c2015-03-20 20:39:41 +110066068. Other capabilities.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006607======================
Michael Ellermane928e9c2015-03-20 20:39:41 +11006608
6609This section lists capabilities that give information about other
6610features of the KVM implementation.
6611
66128.1 KVM_CAP_PPC_HWRNG
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006613---------------------
Michael Ellermane928e9c2015-03-20 20:39:41 +11006614
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006615:Architectures: ppc
Michael Ellermane928e9c2015-03-20 20:39:41 +11006616
6617This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006618available, means that the kernel has an implementation of the
Michael Ellermane928e9c2015-03-20 20:39:41 +11006619H_RANDOM hypercall backed by a hardware random-number generator.
6620If present, the kernel H_RANDOM handler can be enabled for guest use
6621with the KVM_CAP_PPC_ENABLE_HCALL capability.
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006622
66238.2 KVM_CAP_HYPERV_SYNIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006624------------------------
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006625
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006626:Architectures: x86
6627
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006628This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006629available, means that the kernel has an implementation of the
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006630Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
6631used to support Windows Hyper-V based guest paravirt drivers(VMBus).
6632
6633In order to use SynIC, it has to be activated by setting this
6634capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
6635will disable the use of APIC hardware virtualization even if supported
6636by the CPU, as it's incompatible with SynIC auto-EOI behavior.
Paul Mackerrasc9270132017-01-30 21:21:41 +11006637
66388.3 KVM_CAP_PPC_RADIX_MMU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006639-------------------------
Paul Mackerrasc9270132017-01-30 21:21:41 +11006640
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006641:Architectures: ppc
Paul Mackerrasc9270132017-01-30 21:21:41 +11006642
6643This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006644available, means that the kernel can support guests using the
Paul Mackerrasc9270132017-01-30 21:21:41 +11006645radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
6646processor).
6647
66488.4 KVM_CAP_PPC_HASH_MMU_V3
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006649---------------------------
Paul Mackerrasc9270132017-01-30 21:21:41 +11006650
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006651:Architectures: ppc
Paul Mackerrasc9270132017-01-30 21:21:41 +11006652
6653This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006654available, means that the kernel can support guests using the
Paul Mackerrasc9270132017-01-30 21:21:41 +11006655hashed page table MMU defined in Power ISA V3.00 (as implemented in
6656the POWER9 processor), including in-memory segment tables.
James Hogana8a3c422017-03-14 10:15:19 +00006657
66588.5 KVM_CAP_MIPS_VZ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006659-------------------
James Hogana8a3c422017-03-14 10:15:19 +00006660
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006661:Architectures: mips
James Hogana8a3c422017-03-14 10:15:19 +00006662
6663This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
6664it is available, means that full hardware assisted virtualization capabilities
6665of the hardware are available for use through KVM. An appropriate
6666KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
6667utilises it.
6668
6669If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
6670available, it means that the VM is using full hardware assisted virtualization
6671capabilities of the hardware. This is useful to check after creating a VM with
6672KVM_VM_MIPS_DEFAULT.
6673
6674The value returned by KVM_CHECK_EXTENSION should be compared against known
6675values (see below). All other values are reserved. This is to allow for the
6676possibility of other hardware assisted virtualization implementations which
6677may be incompatible with the MIPS VZ ASE.
6678
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006679== ==========================================================================
6680 0 The trap & emulate implementation is in use to run guest code in user
James Hogana8a3c422017-03-14 10:15:19 +00006681 mode. Guest virtual memory segments are rearranged to fit the guest in the
6682 user mode address space.
6683
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006684 1 The MIPS VZ ASE is in use, providing full hardware assisted
James Hogana8a3c422017-03-14 10:15:19 +00006685 virtualization, including standard guest virtual memory segments.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006686== ==========================================================================
James Hogana8a3c422017-03-14 10:15:19 +00006687
66888.6 KVM_CAP_MIPS_TE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006689-------------------
James Hogana8a3c422017-03-14 10:15:19 +00006690
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006691:Architectures: mips
James Hogana8a3c422017-03-14 10:15:19 +00006692
6693This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
6694it is available, means that the trap & emulate implementation is available to
6695run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
6696assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
6697to KVM_CREATE_VM to create a VM which utilises it.
6698
6699If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
6700available, it means that the VM is using trap & emulate.
James Hogan578fd612017-03-14 10:15:20 +00006701
67028.7 KVM_CAP_MIPS_64BIT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006703----------------------
James Hogan578fd612017-03-14 10:15:20 +00006704
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006705:Architectures: mips
James Hogan578fd612017-03-14 10:15:20 +00006706
6707This capability indicates the supported architecture type of the guest, i.e. the
6708supported register and address width.
6709
6710The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
6711kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
6712be checked specifically against known values (see below). All other values are
6713reserved.
6714
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006715== ========================================================================
6716 0 MIPS32 or microMIPS32.
James Hogan578fd612017-03-14 10:15:20 +00006717 Both registers and addresses are 32-bits wide.
6718 It will only be possible to run 32-bit guest code.
6719
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006720 1 MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
James Hogan578fd612017-03-14 10:15:20 +00006721 Registers are 64-bits wide, but addresses are 32-bits wide.
6722 64-bit guest code may run but cannot access MIPS64 memory segments.
6723 It will also be possible to run 32-bit guest code.
6724
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006725 2 MIPS64 or microMIPS64 with access to all address segments.
James Hogan578fd612017-03-14 10:15:20 +00006726 Both registers and addresses are 64-bits wide.
6727 It will be possible to run 64-bit or 32-bit guest code.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006728== ========================================================================
Michael S. Tsirkin668fffa2017-04-21 12:27:17 +02006729
Paolo Bonzinic24a7be2017-04-27 17:33:14 +020067308.9 KVM_CAP_ARM_USER_IRQ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006731------------------------
Alexander Graf3fe17e62016-09-27 21:08:05 +02006732
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006733:Architectures: arm, arm64
6734
Alexander Graf3fe17e62016-09-27 21:08:05 +02006735This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
6736that if userspace creates a VM without an in-kernel interrupt controller, it
6737will be notified of changes to the output level of in-kernel emulated devices,
6738which can generate virtual interrupts, presented to the VM.
6739For such VMs, on every return to userspace, the kernel
6740updates the vcpu's run->s.regs.device_irq_level field to represent the actual
6741output level of the device.
6742
6743Whenever kvm detects a change in the device output level, kvm guarantees at
6744least one return to userspace before running the VM. This exit could either
6745be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
6746userspace can always sample the device output level and re-compute the state of
6747the userspace interrupt controller. Userspace should always check the state
6748of run->s.regs.device_irq_level on every kvm exit.
6749The value in run->s.regs.device_irq_level can represent both level and edge
6750triggered interrupt signals, depending on the device. Edge triggered interrupt
6751signals will exit to userspace with the bit in run->s.regs.device_irq_level
6752set exactly once per edge signal.
6753
6754The field run->s.regs.device_irq_level is available independent of
6755run->kvm_valid_regs or run->kvm_dirty_regs bits.
6756
6757If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
6758number larger than 0 indicating the version of this capability is implemented
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006759and thereby which bits in run->s.regs.device_irq_level can signal values.
Alexander Graf3fe17e62016-09-27 21:08:05 +02006760
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006761Currently the following bits are defined for the device_irq_level bitmap::
Alexander Graf3fe17e62016-09-27 21:08:05 +02006762
6763 KVM_CAP_ARM_USER_IRQ >= 1:
6764
6765 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
6766 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
6767 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
6768
6769Future versions of kvm may implement additional events. These will get
6770indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
6771listed above.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006772
67738.10 KVM_CAP_PPC_SMT_POSSIBLE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006774-----------------------------
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006775
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006776:Architectures: ppc
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006777
6778Querying this capability returns a bitmap indicating the possible
6779virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
6780(counting from the right) is set, then a virtual SMT mode of 2^N is
6781available.
Roman Kaganefc479e2017-06-22 16:51:01 +03006782
67838.11 KVM_CAP_HYPERV_SYNIC2
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006784--------------------------
Roman Kaganefc479e2017-06-22 16:51:01 +03006785
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006786:Architectures: x86
Roman Kaganefc479e2017-06-22 16:51:01 +03006787
6788This capability enables a newer version of Hyper-V Synthetic interrupt
6789controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
6790doesn't clear SynIC message and event flags pages when they are enabled by
6791writing to the respective MSRs.
Roman Kagand3457c82017-07-14 17:13:20 +03006792
67938.12 KVM_CAP_HYPERV_VP_INDEX
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006794----------------------------
Roman Kagand3457c82017-07-14 17:13:20 +03006795
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006796:Architectures: x86
Roman Kagand3457c82017-07-14 17:13:20 +03006797
6798This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
6799value is used to denote the target vcpu for a SynIC interrupt. For
6800compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this
6801capability is absent, userspace can still query this msr's value.
Christian Borntraegerda9a1442017-11-09 10:00:45 +01006802
68038.13 KVM_CAP_S390_AIS_MIGRATION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006804-------------------------------
Christian Borntraegerda9a1442017-11-09 10:00:45 +01006805
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006806:Architectures: s390
6807:Parameters: none
Christian Borntraegerda9a1442017-11-09 10:00:45 +01006808
6809This capability indicates if the flic device will be able to get/set the
6810AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
6811to discover this without having to create a flic device.
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006812
68138.14 KVM_CAP_S390_PSW
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006814---------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006815
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006816:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006817
6818This capability indicates that the PSW is exposed via the kvm_run structure.
6819
68208.15 KVM_CAP_S390_GMAP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006821----------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006822
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006823:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006824
6825This capability indicates that the user space memory used as guest mapping can
6826be anywhere in the user memory address space, as long as the memory slots are
6827aligned and sized to a segment (1MB) boundary.
6828
68298.16 KVM_CAP_S390_COW
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006830---------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006831
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006832:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006833
6834This capability indicates that the user space memory used as guest mapping can
6835use copy-on-write semantics as well as dirty pages tracking via read-only page
6836tables.
6837
68388.17 KVM_CAP_S390_BPB
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006839---------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006840
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006841:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006842
6843This capability indicates that kvm will implement the interfaces to handle
6844reset, migration and nested KVM for branch prediction blocking. The stfle
6845facility 82 should not be provided to the guest without this capability.
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02006846
Vitaly Kuznetsov2ddc6492018-06-22 16:56:14 +020068478.18 KVM_CAP_HYPERV_TLBFLUSH
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006848----------------------------
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02006849
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006850:Architectures: x86
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02006851
6852This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
6853hypercalls:
6854HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
6855HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01006856
Dongjiu Geng688e0582018-08-20 17:39:25 -040068578.19 KVM_CAP_ARM_INJECT_SERROR_ESR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006858----------------------------------
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01006859
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006860:Architectures: arm, arm64
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01006861
6862This capability indicates that userspace can specify (via the
6863KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
6864takes a virtual SError interrupt exception.
6865If KVM advertises this capability, userspace can only specify the ISS field for
6866the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
6867CPU when the exception is taken. If this virtual SError is taken to EL1 using
6868AArch64, this value will be reported in the ISS field of ESR_ELx.
6869
6870See KVM_CAP_VCPU_EVENTS for more details.
Vitaly Kuznetsov214ff832018-09-26 19:02:59 +02006871
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010068728.20 KVM_CAP_HYPERV_SEND_IPI
6873----------------------------
6874
6875:Architectures: x86
Vitaly Kuznetsov214ff832018-09-26 19:02:59 +02006876
6877This capability indicates that KVM supports paravirtualized Hyper-V IPI send
6878hypercalls:
6879HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.
Tianyu Lan344c6c82019-08-22 22:30:20 +08006880
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010068818.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH
6882-----------------------------------
6883
Andrew Jones739c7af2020-08-04 19:06:03 +02006884:Architectures: x86
Tianyu Lan344c6c82019-08-22 22:30:20 +08006885
6886This capability indicates that KVM running on top of Hyper-V hypervisor
6887enables Direct TLB flush for its guests meaning that TLB flush
6888hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM.
6889Due to the different ABI for hypercall parameters between Hyper-V and
6890KVM, enabling this capability effectively disables all hypercall
6891handling by KVM (as some KVM hypercall may be mistakenly treated as TLB
6892flush hypercalls by Hyper-V) so userspace should disable KVM identification
6893in CPUID and only exposes Hyper-V identification. In this case, guest
6894thinks it's running on Hyper-V and only use Hyper-V hypercalls.
Janosch Frank7de3f142020-01-31 05:02:02 -05006895
68968.22 KVM_CAP_S390_VCPU_RESETS
Andrew Jones739c7af2020-08-04 19:06:03 +02006897-----------------------------
Janosch Frank7de3f142020-01-31 05:02:02 -05006898
Andrew Jones739c7af2020-08-04 19:06:03 +02006899:Architectures: s390
Janosch Frank7de3f142020-01-31 05:02:02 -05006900
6901This capability indicates that the KVM_S390_NORMAL_RESET and
6902KVM_S390_CLEAR_RESET ioctls are available.
Janosch Frank04ed89d2019-11-08 05:05:26 -05006903
69048.23 KVM_CAP_S390_PROTECTED
Andrew Jones739c7af2020-08-04 19:06:03 +02006905---------------------------
Janosch Frank04ed89d2019-11-08 05:05:26 -05006906
Andrew Jones739c7af2020-08-04 19:06:03 +02006907:Architectures: s390
Janosch Frank04ed89d2019-11-08 05:05:26 -05006908
6909This capability indicates that the Ultravisor has been initialized and
6910KVM can therefore start protected VMs.
6911This capability governs the KVM_S390_PV_COMMAND ioctl and the
6912KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
6913guests when the state change is invalid.
Andrew Jones004a0122020-08-04 19:06:04 +02006914
69158.24 KVM_CAP_STEAL_TIME
6916-----------------------
6917
6918:Architectures: arm64, x86
6919
6920This capability indicates that KVM supports steal time accounting.
6921When steal time accounting is supported it may be enabled with
6922architecture-specific interfaces. This capability and the architecture-
6923specific interfaces must be consistent, i.e. if one says the feature
6924is supported, than the other should as well and vice versa. For arm64
6925see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
6926For x86 see Documentation/virt/kvm/msr.rst "MSR_KVM_STEAL_TIME".
Collin Wallingf20d4e92020-06-25 11:07:23 -04006927
69288.25 KVM_CAP_S390_DIAG318
6929-------------------------
6930
6931:Architectures: s390
6932
6933This capability enables a guest to set information about its control program
6934(i.e. guest kernel type and version). The information is helpful during
6935system/firmware service events, providing additional data about the guest
6936environments running on the machine.
6937
6938The information is associated with the DIAGNOSE 0x318 instruction, which sets
6939an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and
6940a 7-byte Control Program Version Code (CPVC). The CPNC determines what
6941environment the control program is running in (e.g. Linux, z/VM...), and the
6942CPVC is used for information specific to OS (e.g. Linux version, Linux
6943distribution...)
6944
6945If this capability is available, then the CPNC and CPVC can be synchronized
6946between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318).
Alexander Graf1ae09952020-09-25 16:34:16 +02006947
69488.26 KVM_CAP_X86_USER_SPACE_MSR
6949-------------------------------
6950
6951:Architectures: x86
6952
6953This capability indicates that KVM supports deflection of MSR reads and
6954writes to user space. It can be enabled on a VM level. If enabled, MSR
6955accesses that would usually trigger a #GP by KVM into the guest will
6956instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
6957KVM_EXIT_X86_WRMSR exit notifications.
Alexander Graf1a1552542020-09-25 16:34:21 +02006958
Siddharth Chandrasekaran46a63922021-05-03 14:00:58 +020069598.27 KVM_CAP_X86_MSR_FILTER
Alexander Graf1a1552542020-09-25 16:34:21 +02006960---------------------------
6961
6962:Architectures: x86
6963
6964This capability indicates that KVM supports that accesses to user defined MSRs
6965may be rejected. With this capability exposed, KVM exports new VM ioctl
6966KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR
6967ranges that KVM should reject access to.
6968
6969In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
6970trap and emulate MSRs that are outside of the scope of KVM as well as
6971limit the attack surface on KVM's MSR emulation code.
Oliver Upton66570e92020-08-18 15:24:28 +00006972
Peter Xu177158e2020-10-23 14:33:46 -040069738.28 KVM_CAP_ENFORCE_PV_CPUID
Oliver Upton66570e92020-08-18 15:24:28 +00006974-----------------------------
6975
6976Architectures: x86
6977
6978When enabled, KVM will disable paravirtual features provided to the
6979guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
6980(0x40000001). Otherwise, a guest may use the paravirtual features
6981regardless of what has actually been exposed through the CPUID leaf.
Peter Xufb04a1e2020-09-30 21:22:22 -04006982
Peter Xufb04a1e2020-09-30 21:22:22 -040069838.29 KVM_CAP_DIRTY_LOG_RING
6984---------------------------
6985
6986:Architectures: x86
6987:Parameters: args[0] - size of the dirty log ring
6988
6989KVM is capable of tracking dirty memory using ring buffers that are
6990mmaped into userspace; there is one dirty ring per vcpu.
6991
6992The dirty ring is available to userspace as an array of
6993``struct kvm_dirty_gfn``. Each dirty entry it's defined as::
6994
6995 struct kvm_dirty_gfn {
6996 __u32 flags;
6997 __u32 slot; /* as_id | slot_id */
6998 __u64 offset;
6999 };
7000
7001The following values are defined for the flags field to define the
7002current state of the entry::
7003
7004 #define KVM_DIRTY_GFN_F_DIRTY BIT(0)
7005 #define KVM_DIRTY_GFN_F_RESET BIT(1)
7006 #define KVM_DIRTY_GFN_F_MASK 0x3
7007
7008Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM
7009ioctl to enable this capability for the new guest and set the size of
7010the rings. Enabling the capability is only allowed before creating any
7011vCPU, and the size of the ring must be a power of two. The larger the
7012ring buffer, the less likely the ring is full and the VM is forced to
7013exit to userspace. The optimal size depends on the workload, but it is
7014recommended that it be at least 64 KiB (4096 entries).
7015
7016Just like for dirty page bitmaps, the buffer tracks writes to
7017all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was
7018set in KVM_SET_USER_MEMORY_REGION. Once a memory region is registered
7019with the flag set, userspace can start harvesting dirty pages from the
7020ring buffer.
7021
7022An entry in the ring buffer can be unused (flag bits ``00``),
7023dirty (flag bits ``01``) or harvested (flag bits ``1X``). The
7024state machine for the entry is as follows::
7025
7026 dirtied harvested reset
7027 00 -----------> 01 -------------> 1X -------+
7028 ^ |
7029 | |
7030 +------------------------------------------+
7031
7032To harvest the dirty pages, userspace accesses the mmaped ring buffer
7033to read the dirty GFNs. If the flags has the DIRTY bit set (at this stage
7034the RESET bit must be cleared), then it means this GFN is a dirty GFN.
7035The userspace should harvest this GFN and mark the flags from state
7036``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set
7037to show that this GFN is harvested and waiting for a reset), and move
7038on to the next GFN. The userspace should continue to do this until the
7039flags of a GFN have the DIRTY bit cleared, meaning that it has harvested
7040all the dirty GFNs that were available.
7041
7042It's not necessary for userspace to harvest the all dirty GFNs at once.
7043However it must collect the dirty GFNs in sequence, i.e., the userspace
7044program cannot skip one dirty GFN to collect the one next to it.
7045
7046After processing one or more entries in the ring buffer, userspace
7047calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about
7048it, so that the kernel will reprotect those collected GFNs.
7049Therefore, the ioctl must be called *before* reading the content of
7050the dirty pages.
7051
7052The dirty ring can get full. When it happens, the KVM_RUN of the
7053vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL.
7054
7055The dirty ring interface has a major difference comparing to the
7056KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from
7057userspace, it's still possible that the kernel has not yet flushed the
7058processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the
7059flushing is done by the KVM_GET_DIRTY_LOG ioctl). To achieve that, one
7060needs to kick the vcpu out of KVM_RUN using a signal. The resulting
7061vmexit ensures that all dirty GFNs are flushed to the dirty rings.
Peter Xub2cc64c2020-09-30 21:22:24 -04007062
7063NOTE: the capability KVM_CAP_DIRTY_LOG_RING and the corresponding
7064ioctl KVM_RESET_DIRTY_RINGS are mutual exclusive to the existing ioctls
7065KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG. After enabling
7066KVM_CAP_DIRTY_LOG_RING with an acceptable dirty ring size, the virtual
7067machine will switch to ring-buffer dirty page tracking and further
7068KVM_GET_DIRTY_LOG or KVM_CLEAR_DIRTY_LOG ioctls will fail.
David Woodhousee1f68162020-12-04 09:03:56 +00007069
70708.30 KVM_CAP_XEN_HVM
7071--------------------
7072
7073:Architectures: x86
7074
7075This capability indicates the features that Xen supports for hosting Xen
7076PVHVM guests. Valid flags are::
7077
7078 #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR (1 << 0)
7079 #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL (1 << 1)
7080 #define KVM_XEN_HVM_CONFIG_SHARED_INFO (1 << 2)
David Woodhouse30b5c852021-03-01 12:53:09 +00007081 #define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 2)
David Woodhousee1f68162020-12-04 09:03:56 +00007082
7083The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
7084ioctl is available, for the guest to set its hypercall page.
7085
7086If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be
7087provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page
7088contents, to request that KVM generate hypercall page content automatically
7089and also enable interception of guest hypercalls with KVM_EXIT_XEN.
7090
7091The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the
7092KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and
7093KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors
7094for event channel upcalls when the evtchn_upcall_pending field of a vcpu's
7095vcpu_info is set.
David Woodhouse30b5c852021-03-01 12:53:09 +00007096
7097The KVM_XEN_HVM_CONFIG_RUNSTATE flag indicates that the runstate-related
7098features KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR/_CURRENT/_DATA/_ADJUST are
7099supported by the KVM_XEN_VCPU_SET_ATTR/KVM_XEN_VCPU_GET_ATTR ioctls.
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01007100
71018.31 KVM_CAP_PPC_MULTITCE
7102-------------------------
7103
7104:Capability: KVM_CAP_PPC_MULTITCE
7105:Architectures: ppc
7106:Type: vm
7107
7108This capability means the kernel is capable of handling hypercalls
7109H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
7110space. This significantly accelerates DMA operations for PPC KVM guests.
7111User space should expect that its handlers for these hypercalls
7112are not going to be called if user space previously registered LIOBN
7113in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
7114
7115In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
7116user space might have to advertise it for the guest. For example,
7117IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
7118present in the "ibm,hypertas-functions" device-tree property.
7119
7120The hypercalls mentioned above may or may not be processed successfully
7121in the kernel based fast path. If they can not be handled by the kernel,
7122they will get passed on to user space. So user space still has to have
7123an implementation for these despite the in kernel acceleration.
7124
Nathan Tempelman54526d12021-04-08 22:32:14 +00007125This capability is always enabled.
Paolo Bonzinic4f71902021-04-23 07:41:17 -04007126
71278.32 KVM_CAP_PTP_KVM
Jianyong Wu3bf72562020-12-09 14:09:29 +08007128--------------------
7129
7130:Architectures: arm64
7131
7132This capability indicates that the KVM virtual PTP service is
7133supported in the host. A VMM can check whether the service is
7134available to the guest on migration.
Vitaly Kuznetsov644f7062021-05-21 11:51:36 +02007135
71368.33 KVM_CAP_HYPERV_ENFORCE_CPUID
7137-----------------------------
7138
7139Architectures: x86
7140
7141When enabled, KVM will disable emulated Hyper-V features provided to the
7142guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all
7143currently implmented Hyper-V features are provided unconditionally when
7144Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001)
7145leaf.
Ashish Kalra0dbb1122021-06-08 18:05:43 +00007146
71478.34 KVM_CAP_EXIT_HYPERCALL
7148---------------------------
7149
7150:Capability: KVM_CAP_EXIT_HYPERCALL
7151:Architectures: x86
7152:Type: vm
7153
7154This capability, if enabled, will cause KVM to exit to userspace
7155with KVM_EXIT_HYPERCALL exit reason to process some hypercalls.
7156
7157Calling KVM_CHECK_EXTENSION for this capability will return a bitmask
7158of hypercalls that can be configured to exit to userspace.
7159Right now, the only such hypercall is KVM_HC_MAP_GPA_RANGE.
7160
7161The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset
7162of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace
7163the hypercalls whose corresponding bit is in the argument, and return
7164ENOSYS for the others.