blob: b9ddce5638f5fc167f8ad52d4d843baf39a98438 [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
Steven Price04c02c22021-06-21 12:17:16 +010050424.130 KVM_ARM_MTE_COPY_TAGS
5043---------------------------
5044
5045:Capability: KVM_CAP_ARM_MTE
5046:Architectures: arm64
5047:Type: vm ioctl
5048:Parameters: struct kvm_arm_copy_mte_tags
5049:Returns: number of bytes copied, < 0 on error (-EINVAL for incorrect
5050 arguments, -EFAULT if memory cannot be accessed).
5051
5052::
5053
5054 struct kvm_arm_copy_mte_tags {
5055 __u64 guest_ipa;
5056 __u64 length;
5057 void __user *addr;
5058 __u64 flags;
5059 __u64 reserved[2];
5060 };
5061
5062Copies Memory Tagging Extension (MTE) tags to/from guest tag memory. The
5063``guest_ipa`` and ``length`` fields must be ``PAGE_SIZE`` aligned. The ``addr``
5064field must point to a buffer which the tags will be copied to or from.
5065
5066``flags`` specifies the direction of copy, either ``KVM_ARM_TAGS_TO_GUEST`` or
5067``KVM_ARM_TAGS_FROM_GUEST``.
5068
5069The size of the buffer to store the tags is ``(length / 16)`` bytes
5070(granules in MTE are 16 bytes long). Each byte contains a single tag
5071value. This matches the format of ``PTRACE_PEEKMTETAGS`` and
5072``PTRACE_POKEMTETAGS``.
5073
5074If an error occurs before any data is copied then a negative error code is
5075returned. If some tags have been copied before an error occurs then the number
5076of bytes successfully copied is returned. If the call completes successfully
5077then ``length`` is returned.
Maxim Levitsky6dba9402021-06-07 12:02:02 +03005078
50794.131 KVM_GET_SREGS2
5080------------------
5081
5082:Capability: KVM_CAP_SREGS2
5083:Architectures: x86
5084:Type: vcpu ioctl
5085:Parameters: struct kvm_sregs2 (out)
5086:Returns: 0 on success, -1 on error
5087
5088Reads special registers from the vcpu.
5089This ioctl (when supported) replaces the KVM_GET_SREGS.
5090
5091::
5092
5093struct kvm_sregs2 {
5094 /* out (KVM_GET_SREGS2) / in (KVM_SET_SREGS2) */
5095 struct kvm_segment cs, ds, es, fs, gs, ss;
5096 struct kvm_segment tr, ldt;
5097 struct kvm_dtable gdt, idt;
5098 __u64 cr0, cr2, cr3, cr4, cr8;
5099 __u64 efer;
5100 __u64 apic_base;
5101 __u64 flags;
5102 __u64 pdptrs[4];
5103};
5104
5105flags values for ``kvm_sregs2``:
5106
5107``KVM_SREGS2_FLAGS_PDPTRS_VALID``
5108
5109 Indicates thats the struct contain valid PDPTR values.
5110
5111
51124.132 KVM_SET_SREGS2
5113------------------
5114
5115:Capability: KVM_CAP_SREGS2
5116:Architectures: x86
5117:Type: vcpu ioctl
5118:Parameters: struct kvm_sregs2 (in)
5119:Returns: 0 on success, -1 on error
5120
5121Writes special registers into the vcpu.
5122See KVM_GET_SREGS2 for the data structures.
5123This ioctl (when supported) replaces the KVM_SET_SREGS.
5124
Jing Zhangfdc09dd2021-06-18 22:27:07 +000051254.133 KVM_GET_STATS_FD
5126----------------------
5127
5128:Capability: KVM_CAP_STATS_BINARY_FD
5129:Architectures: all
5130:Type: vm ioctl, vcpu ioctl
5131:Parameters: none
5132:Returns: statistics file descriptor on success, < 0 on error
5133
5134Errors:
5135
5136 ====== ======================================================
5137 ENOMEM if the fd could not be created due to lack of memory
5138 EMFILE if the number of opened files exceeds the limit
5139 ====== ======================================================
5140
5141The returned file descriptor can be used to read VM/vCPU statistics data in
5142binary format. The data in the file descriptor consists of four blocks
5143organized as follows:
5144
5145+-------------+
5146| Header |
5147+-------------+
5148| id string |
5149+-------------+
5150| Descriptors |
5151+-------------+
5152| Stats Data |
5153+-------------+
5154
5155Apart from the header starting at offset 0, please be aware that it is
5156not guaranteed that the four blocks are adjacent or in the above order;
5157the offsets of the id, descriptors and data blocks are found in the
5158header. However, all four blocks are aligned to 64 bit offsets in the
5159file and they do not overlap.
5160
5161All blocks except the data block are immutable. Userspace can read them
5162only one time after retrieving the file descriptor, and then use ``pread`` or
5163``lseek`` to read the statistics repeatedly.
5164
5165All data is in system endianness.
5166
5167The format of the header is as follows::
5168
5169 struct kvm_stats_header {
5170 __u32 flags;
5171 __u32 name_size;
5172 __u32 num_desc;
5173 __u32 id_offset;
5174 __u32 desc_offset;
5175 __u32 data_offset;
5176 };
5177
5178The ``flags`` field is not used at the moment. It is always read as 0.
5179
5180The ``name_size`` field is the size (in byte) of the statistics name string
5181(including trailing '\0') which is contained in the "id string" block and
5182appended at the end of every descriptor.
5183
5184The ``num_desc`` field is the number of descriptors that are included in the
5185descriptor block. (The actual number of values in the data block may be
5186larger, since each descriptor may comprise more than one value).
5187
5188The ``id_offset`` field is the offset of the id string from the start of the
5189file indicated by the file descriptor. It is a multiple of 8.
5190
5191The ``desc_offset`` field is the offset of the Descriptors block from the start
5192of the file indicated by the file descriptor. It is a multiple of 8.
5193
5194The ``data_offset`` field is the offset of the Stats Data block from the start
5195of the file indicated by the file descriptor. It is a multiple of 8.
5196
5197The id string block contains a string which identifies the file descriptor on
5198which KVM_GET_STATS_FD was invoked. The size of the block, including the
5199trailing ``'\0'``, is indicated by the ``name_size`` field in the header.
5200
5201The descriptors block is only needed to be read once for the lifetime of the
5202file descriptor contains a sequence of ``struct kvm_stats_desc``, each followed
5203by a string of size ``name_size``.
5204
5205 #define KVM_STATS_TYPE_SHIFT 0
5206 #define KVM_STATS_TYPE_MASK (0xF << KVM_STATS_TYPE_SHIFT)
5207 #define KVM_STATS_TYPE_CUMULATIVE (0x0 << KVM_STATS_TYPE_SHIFT)
5208 #define KVM_STATS_TYPE_INSTANT (0x1 << KVM_STATS_TYPE_SHIFT)
5209 #define KVM_STATS_TYPE_PEAK (0x2 << KVM_STATS_TYPE_SHIFT)
5210
5211 #define KVM_STATS_UNIT_SHIFT 4
5212 #define KVM_STATS_UNIT_MASK (0xF << KVM_STATS_UNIT_SHIFT)
5213 #define KVM_STATS_UNIT_NONE (0x0 << KVM_STATS_UNIT_SHIFT)
5214 #define KVM_STATS_UNIT_BYTES (0x1 << KVM_STATS_UNIT_SHIFT)
5215 #define KVM_STATS_UNIT_SECONDS (0x2 << KVM_STATS_UNIT_SHIFT)
5216 #define KVM_STATS_UNIT_CYCLES (0x3 << KVM_STATS_UNIT_SHIFT)
5217
5218 #define KVM_STATS_BASE_SHIFT 8
5219 #define KVM_STATS_BASE_MASK (0xF << KVM_STATS_BASE_SHIFT)
5220 #define KVM_STATS_BASE_POW10 (0x0 << KVM_STATS_BASE_SHIFT)
5221 #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT)
5222
5223 struct kvm_stats_desc {
5224 __u32 flags;
5225 __s16 exponent;
5226 __u16 size;
5227 __u32 offset;
5228 __u32 unused;
5229 char name[];
5230 };
5231
5232The ``flags`` field contains the type and unit of the statistics data described
5233by this descriptor. Its endianness is CPU native.
5234The following flags are supported:
5235
5236Bits 0-3 of ``flags`` encode the type:
5237 * ``KVM_STATS_TYPE_CUMULATIVE``
5238 The statistics data is cumulative. The value of data can only be increased.
5239 Most of the counters used in KVM are of this type.
5240 The corresponding ``size`` field for this type is always 1.
5241 All cumulative statistics data are read/write.
5242 * ``KVM_STATS_TYPE_INSTANT``
5243 The statistics data is instantaneous. Its value can be increased or
5244 decreased. This type is usually used as a measurement of some resources,
5245 like the number of dirty pages, the number of large pages, etc.
5246 All instant statistics are read only.
5247 The corresponding ``size`` field for this type is always 1.
5248 * ``KVM_STATS_TYPE_PEAK``
5249 The statistics data is peak. The value of data can only be increased, and
5250 represents a peak value for a measurement, for example the maximum number
5251 of items in a hash table bucket, the longest time waited and so on.
5252 The corresponding ``size`` field for this type is always 1.
5253
5254Bits 4-7 of ``flags`` encode the unit:
5255 * ``KVM_STATS_UNIT_NONE``
5256 There is no unit for the value of statistics data. This usually means that
5257 the value is a simple counter of an event.
5258 * ``KVM_STATS_UNIT_BYTES``
5259 It indicates that the statistics data is used to measure memory size, in the
5260 unit of Byte, KiByte, MiByte, GiByte, etc. The unit of the data is
5261 determined by the ``exponent`` field in the descriptor.
5262 * ``KVM_STATS_UNIT_SECONDS``
5263 It indicates that the statistics data is used to measure time or latency.
5264 * ``KVM_STATS_UNIT_CYCLES``
5265 It indicates that the statistics data is used to measure CPU clock cycles.
5266
5267Bits 8-11 of ``flags``, together with ``exponent``, encode the scale of the
5268unit:
5269 * ``KVM_STATS_BASE_POW10``
5270 The scale is based on power of 10. It is used for measurement of time and
5271 CPU clock cycles. For example, an exponent of -9 can be used with
5272 ``KVM_STATS_UNIT_SECONDS`` to express that the unit is nanoseconds.
5273 * ``KVM_STATS_BASE_POW2``
5274 The scale is based on power of 2. It is used for measurement of memory size.
5275 For example, an exponent of 20 can be used with ``KVM_STATS_UNIT_BYTES`` to
5276 express that the unit is MiB.
5277
5278The ``size`` field is the number of values of this statistics data. Its
5279value is usually 1 for most of simple statistics. 1 means it contains an
5280unsigned 64bit data.
5281
5282The ``offset`` field is the offset from the start of Data Block to the start of
5283the corresponding statistics data.
5284
5285The ``unused`` field is reserved for future support for other types of
5286statistics data, like log/linear histogram. Its value is always 0 for the types
5287defined above.
5288
5289The ``name`` field is the name string of the statistics data. The name string
5290starts at the end of ``struct kvm_stats_desc``. The maximum length including
5291the trailing ``'\0'``, is indicated by ``name_size`` in the header.
5292
5293The Stats Data block contains an array of 64-bit values in the same order
5294as the descriptors in Descriptors block.
Maxim Levitsky6dba9402021-06-07 12:02:02 +03005295
Avi Kivity9c1b96e2009-06-09 12:37:58 +030052965. The kvm_run structure
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005297========================
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005298
5299Application code obtains a pointer to the kvm_run structure by
5300mmap()ing a vcpu fd. From that point, application code can control
5301execution by changing fields in kvm_run prior to calling the KVM_RUN
5302ioctl, and obtain information about the reason KVM_RUN returned by
5303looking up structure members.
5304
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005305::
5306
5307 struct kvm_run {
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005308 /* in */
5309 __u8 request_interrupt_window;
5310
5311Request that KVM_RUN return when it becomes possible to inject external
5312interrupts into the guest. Useful in conjunction with KVM_INTERRUPT.
5313
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005314::
5315
Paolo Bonzini460df4c2017-02-08 11:50:15 +01005316 __u8 immediate_exit;
5317
5318This field is polled once when KVM_RUN starts; if non-zero, KVM_RUN
5319exits immediately, returning -EINTR. In the common scenario where a
5320signal is used to "kick" a VCPU out of KVM_RUN, this field can be used
5321to avoid usage of KVM_SET_SIGNAL_MASK, which has worse scalability.
5322Rather than blocking the signal outside KVM_RUN, userspace can set up
5323a signal handler that sets run->immediate_exit to a non-zero value.
5324
5325This field is ignored if KVM_CAP_IMMEDIATE_EXIT is not available.
5326
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005327::
5328
Paolo Bonzini460df4c2017-02-08 11:50:15 +01005329 __u8 padding1[6];
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005330
5331 /* out */
5332 __u32 exit_reason;
5333
5334When KVM_RUN has returned successfully (return value 0), this informs
5335application code why KVM_RUN has returned. Allowable values for this
5336field are detailed below.
5337
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005338::
5339
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005340 __u8 ready_for_interrupt_injection;
5341
5342If request_interrupt_window has been specified, this field indicates
5343an interrupt can be injected now with KVM_INTERRUPT.
5344
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005345::
5346
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005347 __u8 if_flag;
5348
5349The value of the current interrupt flag. Only valid if in-kernel
5350local APIC is not used.
5351
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005352::
5353
Paolo Bonzinif0778252015-04-01 15:06:40 +02005354 __u16 flags;
5355
5356More architecture-specific flags detailing state of the VCPU that may
Chenyi Qiang96564d72021-02-26 15:55:41 +08005357affect the device's behavior. Current defined flags::
5358
Chenyi Qiangc32b1b892020-11-06 17:03:15 +08005359 /* x86, set if the VCPU is in system management mode */
5360 #define KVM_RUN_X86_SMM (1 << 0)
5361 /* x86, set if bus lock detected in VM */
5362 #define KVM_RUN_BUS_LOCK (1 << 1)
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005363
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005364::
5365
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005366 /* in (pre_kvm_run), out (post_kvm_run) */
5367 __u64 cr8;
5368
5369The value of the cr8 register. Only valid if in-kernel local APIC is
5370not used. Both input and output.
5371
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005372::
5373
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005374 __u64 apic_base;
5375
5376The value of the APIC BASE msr. Only valid if in-kernel local
5377APIC is not used. Both input and output.
5378
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005379::
5380
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005381 union {
5382 /* KVM_EXIT_UNKNOWN */
5383 struct {
5384 __u64 hardware_exit_reason;
5385 } hw;
5386
5387If exit_reason is KVM_EXIT_UNKNOWN, the vcpu has exited due to unknown
5388reasons. Further architecture-specific information is available in
5389hardware_exit_reason.
5390
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005391::
5392
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005393 /* KVM_EXIT_FAIL_ENTRY */
5394 struct {
5395 __u64 hardware_entry_failure_reason;
Jim Mattson1aa561b2020-06-03 16:56:21 -07005396 __u32 cpu; /* if KVM_LAST_CPU */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005397 } fail_entry;
5398
5399If exit_reason is KVM_EXIT_FAIL_ENTRY, the vcpu could not be run due
5400to unknown reasons. Further architecture-specific information is
5401available in hardware_entry_failure_reason.
5402
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005403::
5404
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005405 /* KVM_EXIT_EXCEPTION */
5406 struct {
5407 __u32 exception;
5408 __u32 error_code;
5409 } ex;
5410
5411Unused.
5412
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005413::
5414
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005415 /* KVM_EXIT_IO */
5416 struct {
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005417 #define KVM_EXIT_IO_IN 0
5418 #define KVM_EXIT_IO_OUT 1
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005419 __u8 direction;
5420 __u8 size; /* bytes */
5421 __u16 port;
5422 __u32 count;
5423 __u64 data_offset; /* relative to kvm_run start */
5424 } io;
5425
Wu Fengguang2044892d2009-12-24 09:04:16 +08005426If exit_reason is KVM_EXIT_IO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005427executed a port I/O instruction which could not be satisfied by kvm.
5428data_offset describes where the data is located (KVM_EXIT_IO_OUT) or
5429where kvm expects application code to place the data for the next
Wu Fengguang2044892d2009-12-24 09:04:16 +08005430KVM_RUN invocation (KVM_EXIT_IO_IN). Data format is a packed array.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005431
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005432::
5433
Alex Bennée8ab30c12015-07-07 17:29:53 +01005434 /* KVM_EXIT_DEBUG */
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005435 struct {
5436 struct kvm_debug_exit_arch arch;
5437 } debug;
5438
Alex Bennée8ab30c12015-07-07 17:29:53 +01005439If the exit_reason is KVM_EXIT_DEBUG, then a vcpu is processing a debug event
5440for which architecture specific information is returned.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005441
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005442::
5443
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005444 /* KVM_EXIT_MMIO */
5445 struct {
5446 __u64 phys_addr;
5447 __u8 data[8];
5448 __u32 len;
5449 __u8 is_write;
5450 } mmio;
5451
Wu Fengguang2044892d2009-12-24 09:04:16 +08005452If exit_reason is KVM_EXIT_MMIO, then the vcpu has
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005453executed a memory-mapped I/O instruction which could not be satisfied
5454by kvm. The 'data' member contains the written data if 'is_write' is
5455true, and should be filled by application code otherwise.
5456
Christoffer Dall6acdb162014-01-28 08:28:42 -08005457The 'data' member contains, in its first 'len' bytes, the value as it would
5458appear if the VCPU performed a load or store of the appropriate width directly
5459to the byte array.
5460
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005461.. note::
5462
David Woodhousee1f68162020-12-04 09:03:56 +00005463 For KVM_EXIT_IO, KVM_EXIT_MMIO, KVM_EXIT_OSI, KVM_EXIT_PAPR, KVM_EXIT_XEN,
Alexander Graf1ae09952020-09-25 16:34:16 +02005464 KVM_EXIT_EPR, KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR the corresponding
5465 operations are complete (and guest state is consistent) only after userspace
5466 has re-entered the kernel with KVM_RUN. The kernel side will first finish
David Woodhousee1f68162020-12-04 09:03:56 +00005467 incomplete operations and then check for pending signals.
5468
5469 The pending state of the operation is not preserved in state which is
5470 visible to userspace, thus userspace should ensure that the operation is
5471 completed before performing a live migration. Userspace can re-enter the
5472 guest with an unmasked signal pending or with the immediate_exit field set
5473 to complete pending operations without allowing any further instructions
5474 to be executed.
Marcelo Tosatti67961342010-02-13 16:10:26 -02005475
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005476::
5477
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005478 /* KVM_EXIT_HYPERCALL */
5479 struct {
5480 __u64 nr;
5481 __u64 args[6];
5482 __u64 ret;
5483 __u32 longmode;
5484 __u32 pad;
5485 } hypercall;
5486
Avi Kivity647dc492010-04-01 14:39:21 +03005487Unused. This was once used for 'hypercall to userspace'. To implement
5488such functionality, use KVM_EXIT_IO (x86) or KVM_EXIT_MMIO (all except s390).
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005489
5490.. note:: KVM_EXIT_IO is significantly faster than KVM_EXIT_MMIO.
5491
5492::
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005493
5494 /* KVM_EXIT_TPR_ACCESS */
5495 struct {
5496 __u64 rip;
5497 __u32 is_write;
5498 __u32 pad;
5499 } tpr_access;
5500
5501To be documented (KVM_TPR_ACCESS_REPORTING).
5502
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005503::
5504
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005505 /* KVM_EXIT_S390_SIEIC */
5506 struct {
5507 __u8 icptcode;
5508 __u64 mask; /* psw upper half */
5509 __u64 addr; /* psw lower half */
5510 __u16 ipa;
5511 __u32 ipb;
5512 } s390_sieic;
5513
5514s390 specific.
5515
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005516::
5517
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005518 /* KVM_EXIT_S390_RESET */
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005519 #define KVM_S390_RESET_POR 1
5520 #define KVM_S390_RESET_CLEAR 2
5521 #define KVM_S390_RESET_SUBSYSTEM 4
5522 #define KVM_S390_RESET_CPU_INIT 8
5523 #define KVM_S390_RESET_IPL 16
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005524 __u64 s390_reset_flags;
5525
5526s390 specific.
5527
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005528::
5529
Carsten Ottee168bf82012-01-04 10:25:22 +01005530 /* KVM_EXIT_S390_UCONTROL */
5531 struct {
5532 __u64 trans_exc_code;
5533 __u32 pgm_code;
5534 } s390_ucontrol;
5535
5536s390 specific. A page fault has occurred for a user controlled virtual
5537machine (KVM_VM_S390_UNCONTROL) on it's host page table that cannot be
5538resolved by the kernel.
5539The program code and the translation exception code that were placed
5540in the cpu's lowcore are presented here as defined by the z Architecture
5541Principles of Operation Book in the Chapter for Dynamic Address Translation
5542(DAT)
5543
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005544::
5545
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005546 /* KVM_EXIT_DCR */
5547 struct {
5548 __u32 dcrn;
5549 __u32 data;
5550 __u8 is_write;
5551 } dcr;
5552
Alexander Grafce91ddc2014-07-28 19:29:13 +02005553Deprecated - was used for 440 KVM.
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005554
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005555::
5556
Alexander Grafad0a0482010-03-24 21:48:30 +01005557 /* KVM_EXIT_OSI */
5558 struct {
5559 __u64 gprs[32];
5560 } osi;
5561
5562MOL uses a special hypercall interface it calls 'OSI'. To enable it, we catch
5563hypercalls and exit with this exit struct that contains all the guest gprs.
5564
5565If exit_reason is KVM_EXIT_OSI, then the vcpu has triggered such a hypercall.
5566Userspace can now handle the hypercall and when it's done modify the gprs as
5567necessary. Upon guest entry all guest GPRs will then be replaced by the values
5568in this struct.
5569
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005570::
5571
Paul Mackerrasde56a942011-06-29 00:21:34 +00005572 /* KVM_EXIT_PAPR_HCALL */
5573 struct {
5574 __u64 nr;
5575 __u64 ret;
5576 __u64 args[9];
5577 } papr_hcall;
5578
5579This is used on 64-bit PowerPC when emulating a pSeries partition,
5580e.g. with the 'pseries' machine type in qemu. It occurs when the
5581guest does a hypercall using the 'sc 1' instruction. The 'nr' field
5582contains the hypercall number (from the guest R3), and 'args' contains
5583the arguments (from the guest R4 - R12). Userspace should put the
5584return code in 'ret' and any extra returned values in args[].
5585The possible hypercalls are defined in the Power Architecture Platform
5586Requirements (PAPR) document available from www.power.org (free
5587developer registration required to access it).
5588
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005589::
5590
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005591 /* KVM_EXIT_S390_TSCH */
5592 struct {
5593 __u16 subchannel_id;
5594 __u16 subchannel_nr;
5595 __u32 io_int_parm;
5596 __u32 io_int_word;
5597 __u32 ipb;
5598 __u8 dequeued;
5599 } s390_tsch;
5600
5601s390 specific. This exit occurs when KVM_CAP_S390_CSS_SUPPORT has been enabled
5602and TEST SUBCHANNEL was intercepted. If dequeued is set, a pending I/O
5603interrupt for the target subchannel has been dequeued and subchannel_id,
5604subchannel_nr, io_int_parm and io_int_word contain the parameters for that
5605interrupt. ipb is needed for instruction parameter decoding.
5606
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005607::
5608
Alexander Graf1c810632013-01-04 18:12:48 +01005609 /* KVM_EXIT_EPR */
5610 struct {
5611 __u32 epr;
5612 } epr;
5613
5614On FSL BookE PowerPC chips, the interrupt controller has a fast patch
5615interrupt acknowledge path to the core. When the core successfully
5616delivers an interrupt, it automatically populates the EPR register with
5617the interrupt vector number and acknowledges the interrupt inside
5618the interrupt controller.
5619
5620In case the interrupt controller lives in user space, we need to do
5621the interrupt acknowledge cycle through it to fetch the next to be
5622delivered interrupt vector using this exit.
5623
5624It gets triggered whenever both KVM_CAP_PPC_EPR are enabled and an
5625external interrupt has just been delivered into the guest. User space
5626should put the acknowledged interrupt vector into the 'epr' field.
5627
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005628::
5629
Anup Patel8ad6b632014-04-29 11:24:19 +05305630 /* KVM_EXIT_SYSTEM_EVENT */
5631 struct {
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005632 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
5633 #define KVM_SYSTEM_EVENT_RESET 2
5634 #define KVM_SYSTEM_EVENT_CRASH 3
Anup Patel8ad6b632014-04-29 11:24:19 +05305635 __u32 type;
5636 __u64 flags;
5637 } system_event;
5638
5639If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
5640a system-level event using some architecture specific mechanism (hypercall
5641or some special instruction). In case of ARM/ARM64, this is triggered using
5642HVC instruction based PSCI call from the vcpu. The 'type' field describes
5643the system-level event type. The 'flags' field describes architecture
5644specific flags for the system-level event.
5645
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005646Valid values for 'type' are:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005647
5648 - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005649 VM. Userspace is not obliged to honour this, and if it does honour
5650 this does not need to destroy the VM synchronously (ie it may call
5651 KVM_RUN again before shutdown finally occurs).
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005652 - KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005653 As with SHUTDOWN, userspace can choose to ignore the request, or
5654 to schedule the reset to occur in the future and may call KVM_RUN again.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005655 - KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
Andrey Smetanin2ce79182015-07-03 15:01:41 +03005656 has requested a crash condition maintenance. Userspace can choose
5657 to ignore the request, or to gather VM memory core dump and/or
5658 reset/shutdown of the VM.
Christoffer Dallcf5d31882014-10-16 17:00:18 +02005659
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005660::
5661
Steve Rutherford7543a632015-07-29 23:21:41 -07005662 /* KVM_EXIT_IOAPIC_EOI */
5663 struct {
5664 __u8 vector;
5665 } eoi;
5666
5667Indicates that the VCPU's in-kernel local APIC received an EOI for a
5668level-triggered IOAPIC interrupt. This exit only triggers when the
5669IOAPIC is implemented in userspace (i.e. KVM_CAP_SPLIT_IRQCHIP is enabled);
5670the userspace IOAPIC should process the EOI and retrigger the interrupt if
5671it is still asserted. Vector is the LAPIC interrupt vector for which the
5672EOI was received.
5673
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005674::
5675
Andrey Smetanindb3975712015-11-10 15:36:35 +03005676 struct kvm_hyperv_exit {
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005677 #define KVM_EXIT_HYPERV_SYNIC 1
5678 #define KVM_EXIT_HYPERV_HCALL 2
Jon Doronf97f5a52020-05-29 16:45:40 +03005679 #define KVM_EXIT_HYPERV_SYNDBG 3
Andrey Smetanindb3975712015-11-10 15:36:35 +03005680 __u32 type;
Jon Doronf7d31e62020-04-24 14:37:40 +03005681 __u32 pad1;
Andrey Smetanindb3975712015-11-10 15:36:35 +03005682 union {
5683 struct {
5684 __u32 msr;
Jon Doronf7d31e62020-04-24 14:37:40 +03005685 __u32 pad2;
Andrey Smetanindb3975712015-11-10 15:36:35 +03005686 __u64 control;
5687 __u64 evt_page;
5688 __u64 msg_page;
5689 } synic;
Andrey Smetanin83326e42016-02-11 16:45:01 +03005690 struct {
5691 __u64 input;
5692 __u64 result;
5693 __u64 params[2];
5694 } hcall;
Jon Doronf97f5a52020-05-29 16:45:40 +03005695 struct {
5696 __u32 msr;
5697 __u32 pad2;
5698 __u64 control;
5699 __u64 status;
5700 __u64 send_page;
5701 __u64 recv_page;
5702 __u64 pending_page;
5703 } syndbg;
Andrey Smetanindb3975712015-11-10 15:36:35 +03005704 } u;
5705 };
5706 /* KVM_EXIT_HYPERV */
5707 struct kvm_hyperv_exit hyperv;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005708
Andrey Smetanindb3975712015-11-10 15:36:35 +03005709Indicates that the VCPU exits into userspace to process some tasks
5710related to Hyper-V emulation.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005711
Andrey Smetanindb3975712015-11-10 15:36:35 +03005712Valid values for 'type' are:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005713
5714 - KVM_EXIT_HYPERV_SYNIC -- synchronously notify user-space about
5715
Andrey Smetanindb3975712015-11-10 15:36:35 +03005716Hyper-V SynIC state change. Notification is used to remap SynIC
5717event/message pages and to enable/disable SynIC messages/events processing
5718in userspace.
5719
Jon Doronf97f5a52020-05-29 16:45:40 +03005720 - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about
5721
5722Hyper-V Synthetic debugger state change. Notification is used to either update
5723the pending_page location or to send a control command (send the buffer located
5724in send_page or recv a buffer to recv_page).
5725
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005726::
5727
Christoffer Dallc7262002019-10-11 13:07:05 +02005728 /* KVM_EXIT_ARM_NISV */
5729 struct {
5730 __u64 esr_iss;
5731 __u64 fault_ipa;
5732 } arm_nisv;
5733
5734Used on arm and arm64 systems. If a guest accesses memory not in a memslot,
5735KVM will typically return to userspace and ask it to do MMIO emulation on its
5736behalf. However, for certain classes of instructions, no instruction decode
5737(direction, length of memory access) is provided, and fetching and decoding
5738the instruction from the VM is overly complicated to live in the kernel.
5739
5740Historically, when this situation occurred, KVM would print a warning and kill
5741the VM. KVM assumed that if the guest accessed non-memslot memory, it was
5742trying to do I/O, which just couldn't be emulated, and the warning message was
5743phrased accordingly. However, what happened more often was that a guest bug
5744caused access outside the guest memory areas which should lead to a more
5745meaningful warning message and an external abort in the guest, if the access
5746did not fall within an I/O window.
5747
5748Userspace implementations can query for KVM_CAP_ARM_NISV_TO_USER, and enable
5749this capability at VM creation. Once this is done, these types of errors will
5750instead return to userspace with KVM_EXIT_ARM_NISV, with the valid bits from
5751the HSR (arm) and ESR_EL2 (arm64) in the esr_iss field, and the faulting IPA
5752in the fault_ipa field. Userspace can either fix up the access if it's
5753actually an I/O access by decoding the instruction from guest memory (if it's
5754very brave) and continue executing the guest, or it can decide to suspend,
5755dump, or restart the guest.
5756
5757Note that KVM does not skip the faulting instruction as it does for
5758KVM_EXIT_MMIO, but userspace has to emulate any change to the processing state
5759if it decides to decode and emulate the instruction.
5760
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005761::
5762
Alexander Graf1ae09952020-09-25 16:34:16 +02005763 /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */
5764 struct {
5765 __u8 error; /* user -> kernel */
5766 __u8 pad[7];
5767 __u32 reason; /* kernel -> user */
5768 __u32 index; /* kernel -> user */
5769 __u64 data; /* kernel <-> user */
5770 } msr;
5771
5772Used on x86 systems. When the VM capability KVM_CAP_X86_USER_SPACE_MSR is
5773enabled, MSR accesses to registers that would invoke a #GP by KVM kernel code
5774will instead trigger a KVM_EXIT_X86_RDMSR exit for reads and KVM_EXIT_X86_WRMSR
5775exit for writes.
5776
5777The "reason" field specifies why the MSR trap occurred. User space will only
5778receive MSR exit traps when a particular reason was requested during through
5779ENABLE_CAP. Currently valid exit reasons are:
5780
5781 KVM_MSR_EXIT_REASON_UNKNOWN - access to MSR that is unknown to KVM
5782 KVM_MSR_EXIT_REASON_INVAL - access to invalid MSRs or reserved bits
Alexander Graf1a1552542020-09-25 16:34:21 +02005783 KVM_MSR_EXIT_REASON_FILTER - access blocked by KVM_X86_SET_MSR_FILTER
Alexander Graf1ae09952020-09-25 16:34:16 +02005784
5785For KVM_EXIT_X86_RDMSR, the "index" field tells user space which MSR the guest
5786wants to read. To respond to this request with a successful read, user space
5787writes the respective data into the "data" field and must continue guest
5788execution to ensure the read data is transferred into guest register state.
5789
5790If the RDMSR request was unsuccessful, user space indicates that with a "1" in
5791the "error" field. This will inject a #GP into the guest when the VCPU is
5792executed again.
5793
5794For KVM_EXIT_X86_WRMSR, the "index" field tells user space which MSR the guest
5795wants to write. Once finished processing the event, user space must continue
5796vCPU execution. If the MSR write was unsuccessful, user space also sets the
5797"error" field to "1".
5798
5799::
5800
David Woodhousee1f68162020-12-04 09:03:56 +00005801
5802 struct kvm_xen_exit {
5803 #define KVM_EXIT_XEN_HCALL 1
5804 __u32 type;
5805 union {
5806 struct {
5807 __u32 longmode;
5808 __u32 cpl;
5809 __u64 input;
5810 __u64 result;
5811 __u64 params[6];
5812 } hcall;
5813 } u;
5814 };
5815 /* KVM_EXIT_XEN */
5816 struct kvm_hyperv_exit xen;
5817
5818Indicates that the VCPU exits into userspace to process some tasks
5819related to Xen emulation.
5820
5821Valid values for 'type' are:
5822
5823 - KVM_EXIT_XEN_HCALL -- synchronously notify user-space about Xen hypercall.
5824 Userspace is expected to place the hypercall result into the appropriate
5825 field before invoking KVM_RUN again.
5826
5827::
5828
Avi Kivity9c1b96e2009-06-09 12:37:58 +03005829 /* Fix the size of the union. */
5830 char padding[256];
5831 };
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01005832
5833 /*
5834 * shared registers between kvm and userspace.
5835 * kvm_valid_regs specifies the register classes set by the host
5836 * kvm_dirty_regs specified the register classes dirtied by userspace
5837 * struct kvm_sync_regs is architecture specific, as well as the
5838 * bits for kvm_valid_regs and kvm_dirty_regs
5839 */
5840 __u64 kvm_valid_regs;
5841 __u64 kvm_dirty_regs;
5842 union {
5843 struct kvm_sync_regs regs;
Ken Hofsass7b7e3952018-01-31 16:03:35 -08005844 char padding[SYNC_REGS_SIZE_BYTES];
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01005845 } s;
5846
5847If KVM_CAP_SYNC_REGS is defined, these fields allow userspace to access
5848certain guest registers without having to call SET/GET_*REGS. Thus we can
5849avoid some system call overhead if userspace has to handle the exit.
5850Userspace can query the validity of the structure by checking
5851kvm_valid_regs for specific bits. These bits are architecture specific
5852and usually define the validity of a groups of registers. (e.g. one bit
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005853for general purpose registers)
Christian Borntraegerb9e5dc82012-01-11 11:20:30 +01005854
David Hildenbrandd8482c02014-07-29 08:19:26 +02005855Please note that the kernel is allowed to use the kvm_run structure as the
5856primary storage for certain register types. Therefore, the kernel may use the
5857values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
5858
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005859::
5860
5861 };
Alexander Graf821246a2011-08-31 10:58:55 +02005862
Jan Kiszka414fa982012-04-24 16:40:15 +02005863
Borislav Petkov9c15bb12013-09-22 16:44:50 +02005864
Paul Mackerras699a0ea2014-06-02 11:02:59 +100058656. Capabilities that can be enabled on vCPUs
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005866============================================
Alexander Graf821246a2011-08-31 10:58:55 +02005867
Cornelia Huck0907c852014-06-27 09:29:26 +02005868There are certain capabilities that change the behavior of the virtual CPU or
5869the virtual machine when enabled. To enable them, please see section 4.37.
5870Below you can find a list of capabilities and what their effect on the vCPU or
5871the virtual machine is when enabling them.
Alexander Graf821246a2011-08-31 10:58:55 +02005872
5873The following information is provided along with the description:
5874
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005875 Architectures:
5876 which instruction set architectures provide this ioctl.
Alexander Graf821246a2011-08-31 10:58:55 +02005877 x86 includes both i386 and x86_64.
5878
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005879 Target:
5880 whether this is a per-vcpu or per-vm capability.
Cornelia Huck0907c852014-06-27 09:29:26 +02005881
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005882 Parameters:
5883 what parameters are accepted by the capability.
Alexander Graf821246a2011-08-31 10:58:55 +02005884
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005885 Returns:
5886 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
Alexander Graf821246a2011-08-31 10:58:55 +02005887 are not detailed, but errors with specific meanings are.
5888
Jan Kiszka414fa982012-04-24 16:40:15 +02005889
Alexander Graf821246a2011-08-31 10:58:55 +020058906.1 KVM_CAP_PPC_OSI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005891-------------------
Alexander Graf821246a2011-08-31 10:58:55 +02005892
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005893:Architectures: ppc
5894:Target: vcpu
5895:Parameters: none
5896:Returns: 0 on success; -1 on error
Alexander Graf821246a2011-08-31 10:58:55 +02005897
5898This capability enables interception of OSI hypercalls that otherwise would
5899be treated as normal system calls to be injected into the guest. OSI hypercalls
5900were invented by Mac-on-Linux to have a standardized communication mechanism
5901between the guest and the host.
5902
5903When this capability is enabled, KVM_EXIT_OSI can occur.
5904
Jan Kiszka414fa982012-04-24 16:40:15 +02005905
Alexander Graf821246a2011-08-31 10:58:55 +020059066.2 KVM_CAP_PPC_PAPR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005907--------------------
Alexander Graf821246a2011-08-31 10:58:55 +02005908
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005909:Architectures: ppc
5910:Target: vcpu
5911:Parameters: none
5912:Returns: 0 on success; -1 on error
Alexander Graf821246a2011-08-31 10:58:55 +02005913
5914This capability enables interception of PAPR hypercalls. PAPR hypercalls are
5915done using the hypercall instruction "sc 1".
5916
5917It also sets the guest privilege level to "supervisor" mode. Usually the guest
5918runs in "hypervisor" privilege mode with a few missing features.
5919
5920In addition to the above, it changes the semantics of SDR1. In this mode, the
5921HTAB address part of SDR1 contains an HVA instead of a GPA, as PAPR keeps the
5922HTAB invisible to the guest.
5923
5924When this capability is enabled, KVM_EXIT_PAPR_HCALL can occur.
Scott Wooddc83b8b2011-08-18 15:25:21 -05005925
Jan Kiszka414fa982012-04-24 16:40:15 +02005926
Scott Wooddc83b8b2011-08-18 15:25:21 -050059276.3 KVM_CAP_SW_TLB
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005928------------------
Scott Wooddc83b8b2011-08-18 15:25:21 -05005929
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005930:Architectures: ppc
5931:Target: vcpu
5932:Parameters: args[0] is the address of a struct kvm_config_tlb
5933:Returns: 0 on success; -1 on error
Scott Wooddc83b8b2011-08-18 15:25:21 -05005934
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005935::
5936
5937 struct kvm_config_tlb {
Scott Wooddc83b8b2011-08-18 15:25:21 -05005938 __u64 params;
5939 __u64 array;
5940 __u32 mmu_type;
5941 __u32 array_len;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005942 };
Scott Wooddc83b8b2011-08-18 15:25:21 -05005943
5944Configures the virtual CPU's TLB array, establishing a shared memory area
5945between userspace and KVM. The "params" and "array" fields are userspace
5946addresses of mmu-type-specific data structures. The "array_len" field is an
5947safety mechanism, and should be set to the size in bytes of the memory that
5948userspace has reserved for the array. It must be at least the size dictated
5949by "mmu_type" and "params".
5950
5951While KVM_RUN is active, the shared region is under control of KVM. Its
5952contents are undefined, and any modification by userspace results in
5953boundedly undefined behavior.
5954
5955On return from KVM_RUN, the shared region will reflect the current state of
5956the guest's TLB. If userspace makes any changes, it must call KVM_DIRTY_TLB
5957to tell KVM which entries have been changed, prior to calling KVM_RUN again
5958on this vcpu.
5959
5960For mmu types KVM_MMU_FSL_BOOKE_NOHV and KVM_MMU_FSL_BOOKE_HV:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005961
Scott Wooddc83b8b2011-08-18 15:25:21 -05005962 - The "params" field is of type "struct kvm_book3e_206_tlb_params".
5963 - The "array" field points to an array of type "struct
5964 kvm_book3e_206_tlb_entry".
5965 - The array consists of all entries in the first TLB, followed by all
5966 entries in the second TLB.
5967 - Within a TLB, entries are ordered first by increasing set number. Within a
5968 set, entries are ordered by way (increasing ESEL).
5969 - The hash for determining set number in TLB0 is: (MAS2 >> 12) & (num_sets - 1)
5970 where "num_sets" is the tlb_sizes[] value divided by the tlb_ways[] value.
5971 - The tsize field of mas1 shall be set to 4K on TLB0, even though the
5972 hardware ignores this value for TLB0.
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005973
59746.4 KVM_CAP_S390_CSS_SUPPORT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005975----------------------------
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005976
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005977:Architectures: s390
5978:Target: vcpu
5979:Parameters: none
5980:Returns: 0 on success; -1 on error
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +01005981
5982This capability enables support for handling of channel I/O instructions.
5983
5984TEST PENDING INTERRUPTION and the interrupt portion of TEST SUBCHANNEL are
5985handled in-kernel, while the other I/O instructions are passed to userspace.
5986
5987When this capability is enabled, KVM_EXIT_S390_TSCH will occur on TEST
5988SUBCHANNEL intercepts.
Alexander Graf1c810632013-01-04 18:12:48 +01005989
Cornelia Huck0907c852014-06-27 09:29:26 +02005990Note that even though this capability is enabled per-vcpu, the complete
5991virtual machine is affected.
5992
Alexander Graf1c810632013-01-04 18:12:48 +010059936.5 KVM_CAP_PPC_EPR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005994-------------------
Alexander Graf1c810632013-01-04 18:12:48 +01005995
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01005996:Architectures: ppc
5997:Target: vcpu
5998:Parameters: args[0] defines whether the proxy facility is active
5999:Returns: 0 on success; -1 on error
Alexander Graf1c810632013-01-04 18:12:48 +01006000
6001This capability enables or disables the delivery of interrupts through the
6002external proxy facility.
6003
6004When enabled (args[0] != 0), every time the guest gets an external interrupt
6005delivered, it automatically exits into user space with a KVM_EXIT_EPR exit
6006to receive the topmost interrupt vector.
6007
6008When disabled (args[0] == 0), behavior is as if this facility is unsupported.
6009
6010When this capability is enabled, KVM_EXIT_EPR can occur.
Scott Woodeb1e4f42013-04-12 14:08:47 +00006011
60126.6 KVM_CAP_IRQ_MPIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006013--------------------
Scott Woodeb1e4f42013-04-12 14:08:47 +00006014
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006015:Architectures: ppc
6016:Parameters: args[0] is the MPIC device fd;
6017 args[1] is the MPIC CPU number for this vcpu
Scott Woodeb1e4f42013-04-12 14:08:47 +00006018
6019This capability connects the vcpu to an in-kernel MPIC device.
Paul Mackerras5975a2e2013-04-27 00:28:37 +00006020
60216.7 KVM_CAP_IRQ_XICS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006022--------------------
Paul Mackerras5975a2e2013-04-27 00:28:37 +00006023
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006024:Architectures: ppc
6025:Target: vcpu
6026:Parameters: args[0] is the XICS device fd;
6027 args[1] is the XICS CPU number (server ID) for this vcpu
Paul Mackerras5975a2e2013-04-27 00:28:37 +00006028
6029This capability connects the vcpu to an in-kernel XICS device.
Cornelia Huck8a366a42014-06-27 11:06:25 +02006030
60316.8 KVM_CAP_S390_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006032------------------------
Cornelia Huck8a366a42014-06-27 11:06:25 +02006033
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006034:Architectures: s390
6035:Target: vm
6036:Parameters: none
Cornelia Huck8a366a42014-06-27 11:06:25 +02006037
6038This capability enables the in-kernel irqchip for s390. Please refer to
6039"4.24 KVM_CREATE_IRQCHIP" for details.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006040
James Hogan5fafd8742014-12-08 23:07:56 +000060416.9 KVM_CAP_MIPS_FPU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006042--------------------
James Hogan5fafd8742014-12-08 23:07:56 +00006043
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006044:Architectures: mips
6045:Target: vcpu
6046:Parameters: args[0] is reserved for future use (should be 0).
James Hogan5fafd8742014-12-08 23:07:56 +00006047
6048This capability allows the use of the host Floating Point Unit by the guest. It
6049allows 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 +01006050done the ``KVM_REG_MIPS_FPR_*`` and ``KVM_REG_MIPS_FCR_*`` registers can be
6051accessed (depending on the current guest FPU register mode), and the Status.FR,
James Hogan5fafd8742014-12-08 23:07:56 +00006052Config5.FRE bits are accessible via the KVM API and also from the guest,
6053depending on them being supported by the FPU.
6054
James Hogand952bd02014-12-08 23:07:56 +000060556.10 KVM_CAP_MIPS_MSA
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006056---------------------
James Hogand952bd02014-12-08 23:07:56 +00006057
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006058:Architectures: mips
6059:Target: vcpu
6060:Parameters: args[0] is reserved for future use (should be 0).
James Hogand952bd02014-12-08 23:07:56 +00006061
6062This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
6063It 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 +01006064Once this is done the ``KVM_REG_MIPS_VEC_*`` and ``KVM_REG_MIPS_MSA_*``
6065registers can be accessed, and the Config5.MSAEn bit is accessible via the
6066KVM API and also from the guest.
James Hogand952bd02014-12-08 23:07:56 +00006067
Ken Hofsass01643c52018-01-31 16:03:36 -080060686.74 KVM_CAP_SYNC_REGS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006069----------------------
6070
6071:Architectures: s390, x86
6072:Target: s390: always enabled, x86: vcpu
6073:Parameters: none
6074:Returns: x86: KVM_CHECK_EXTENSION returns a bit-array indicating which register
6075 sets are supported
6076 (bitfields defined in arch/x86/include/uapi/asm/kvm.h).
Ken Hofsass01643c52018-01-31 16:03:36 -08006077
6078As described above in the kvm_sync_regs struct info in section 5 (kvm_run):
6079KVM_CAP_SYNC_REGS "allow[s] userspace to access certain guest registers
6080without having to call SET/GET_*REGS". This reduces overhead by eliminating
6081repeated ioctl calls for setting and/or getting register values. This is
6082particularly important when userspace is making synchronous guest state
6083modifications, e.g. when emulating and/or intercepting instructions in
6084userspace.
6085
6086For s390 specifics, please refer to the source code.
6087
6088For x86:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006089
Ken Hofsass01643c52018-01-31 16:03:36 -08006090- the register sets to be copied out to kvm_run are selectable
6091 by userspace (rather that all sets being copied out for every exit).
6092- vcpu_events are available in addition to regs and sregs.
6093
6094For x86, the 'kvm_valid_regs' field of struct kvm_run is overloaded to
6095function as an input bit-array field set by userspace to indicate the
6096specific register sets to be copied out on the next exit.
6097
6098To indicate when userspace has modified values that should be copied into
6099the vCPU, the all architecture bitarray field, 'kvm_dirty_regs' must be set.
6100This is done using the same bitflags as for the 'kvm_valid_regs' field.
6101If the dirty bit is not set, then the register set values will not be copied
6102into the vCPU even if they've been modified.
6103
6104Unused bitfields in the bitarrays must be set to zero.
6105
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006106::
6107
6108 struct kvm_sync_regs {
Ken Hofsass01643c52018-01-31 16:03:36 -08006109 struct kvm_regs regs;
6110 struct kvm_sregs sregs;
6111 struct kvm_vcpu_events events;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006112 };
Ken Hofsass01643c52018-01-31 16:03:36 -08006113
Cédric Le Goatereacc56b2019-04-18 12:39:28 +020061146.75 KVM_CAP_PPC_IRQ_XIVE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006115-------------------------
Cédric Le Goatereacc56b2019-04-18 12:39:28 +02006116
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006117:Architectures: ppc
6118:Target: vcpu
6119:Parameters: args[0] is the XIVE device fd;
6120 args[1] is the XIVE CPU number (server ID) for this vcpu
Cédric Le Goatereacc56b2019-04-18 12:39:28 +02006121
6122This capability connects the vcpu to an in-kernel XIVE device.
6123
Paul Mackerras699a0ea2014-06-02 11:02:59 +100061247. Capabilities that can be enabled on VMs
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006125==========================================
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006126
6127There are certain capabilities that change the behavior of the virtual
6128machine when enabled. To enable them, please see section 4.37. Below
6129you can find a list of capabilities and what their effect on the VM
6130is when enabling them.
6131
6132The following information is provided along with the description:
6133
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006134 Architectures:
6135 which instruction set architectures provide this ioctl.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006136 x86 includes both i386 and x86_64.
6137
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006138 Parameters:
6139 what parameters are accepted by the capability.
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006140
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006141 Returns:
6142 the return value. General error numbers (EBADF, ENOMEM, EINVAL)
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006143 are not detailed, but errors with specific meanings are.
6144
6145
61467.1 KVM_CAP_PPC_ENABLE_HCALL
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006147----------------------------
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006148
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006149:Architectures: ppc
6150:Parameters: args[0] is the sPAPR hcall number;
6151 args[1] is 0 to disable, 1 to enable in-kernel handling
Paul Mackerras699a0ea2014-06-02 11:02:59 +10006152
6153This capability controls whether individual sPAPR hypercalls (hcalls)
6154get handled by the kernel or not. Enabling or disabling in-kernel
6155handling of an hcall is effective across the VM. On creation, an
6156initial set of hcalls are enabled for in-kernel handling, which
6157consists of those hcalls for which in-kernel handlers were implemented
6158before this capability was implemented. If disabled, the kernel will
6159not to attempt to handle the hcall, but will always exit to userspace
6160to handle it. Note that it may not make sense to enable some and
6161disable others of a group of related hcalls, but KVM does not prevent
6162userspace from doing that.
Paul Mackerrasae2113a2014-06-02 11:03:00 +10006163
6164If the hcall number specified is not one that has an in-kernel
6165implementation, the KVM_ENABLE_CAP ioctl will fail with an EINVAL
6166error.
David Hildenbrand2444b352014-10-09 14:10:13 +02006167
61687.2 KVM_CAP_S390_USER_SIGP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006169--------------------------
David Hildenbrand2444b352014-10-09 14:10:13 +02006170
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006171:Architectures: s390
6172:Parameters: none
David Hildenbrand2444b352014-10-09 14:10:13 +02006173
6174This capability controls which SIGP orders will be handled completely in user
6175space. With this capability enabled, all fast orders will be handled completely
6176in the kernel:
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006177
David Hildenbrand2444b352014-10-09 14:10:13 +02006178- SENSE
6179- SENSE RUNNING
6180- EXTERNAL CALL
6181- EMERGENCY SIGNAL
6182- CONDITIONAL EMERGENCY SIGNAL
6183
6184All other orders will be handled completely in user space.
6185
6186Only privileged operation exceptions will be checked for in the kernel (or even
6187in the hardware prior to interception). If this capability is not enabled, the
6188old way of handling SIGP orders is used (partially in kernel and user space).
Eric Farman68c55752014-06-09 10:57:26 -04006189
61907.3 KVM_CAP_S390_VECTOR_REGISTERS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006191---------------------------------
Eric Farman68c55752014-06-09 10:57:26 -04006192
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006193:Architectures: s390
6194:Parameters: none
6195:Returns: 0 on success, negative value on error
Eric Farman68c55752014-06-09 10:57:26 -04006196
6197Allows use of the vector registers introduced with z13 processor, and
6198provides for the synchronization between host and user space. Will
6199return -EINVAL if the machine does not support vectors.
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006200
62017.4 KVM_CAP_S390_USER_STSI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006202--------------------------
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006203
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006204:Architectures: s390
6205:Parameters: none
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006206
6207This capability allows post-handlers for the STSI instruction. After
6208initial handling in the kernel, KVM exits to user space with
6209KVM_EXIT_S390_STSI to allow user space to insert further data.
6210
6211Before exiting to userspace, kvm handlers should fill in s390_stsi field of
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006212vcpu->run::
6213
6214 struct {
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006215 __u64 addr;
6216 __u8 ar;
6217 __u8 reserved;
6218 __u8 fc;
6219 __u8 sel1;
6220 __u16 sel2;
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006221 } s390_stsi;
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006222
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006223 @addr - guest address of STSI SYSIB
6224 @fc - function code
6225 @sel1 - selector 1
6226 @sel2 - selector 2
6227 @ar - access register number
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +01006228
6229KVM handlers should exit to userspace with rc = -EREMOTE.
Michael Ellermane928e9c2015-03-20 20:39:41 +11006230
Steve Rutherford49df6392015-07-29 23:21:40 -070062317.5 KVM_CAP_SPLIT_IRQCHIP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006232-------------------------
Steve Rutherford49df6392015-07-29 23:21:40 -07006233
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006234:Architectures: x86
6235:Parameters: args[0] - number of routes reserved for userspace IOAPICs
6236:Returns: 0 on success, -1 on error
Steve Rutherford49df6392015-07-29 23:21:40 -07006237
6238Create a local apic for each processor in the kernel. This can be used
6239instead of KVM_CREATE_IRQCHIP if the userspace VMM wishes to emulate the
6240IOAPIC and PIC (and also the PIT, even though this has to be enabled
6241separately).
6242
Steve Rutherfordb053b2a2015-07-29 23:32:35 -07006243This capability also enables in kernel routing of interrupt requests;
6244when KVM_CAP_SPLIT_IRQCHIP only routes of KVM_IRQ_ROUTING_MSI type are
6245used in the IRQ routing table. The first args[0] MSI routes are reserved
6246for the IOAPIC pins. Whenever the LAPIC receives an EOI for these routes,
6247a KVM_EXIT_IOAPIC_EOI vmexit will be reported to userspace.
Steve Rutherford49df6392015-07-29 23:21:40 -07006248
6249Fails if VCPU has already been created, or if the irqchip is already in the
6250kernel (i.e. KVM_CREATE_IRQCHIP has already been called).
6251
David Hildenbrand051c87f2016-04-19 13:13:40 +020062527.6 KVM_CAP_S390_RI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006253-------------------
David Hildenbrand051c87f2016-04-19 13:13:40 +02006254
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006255:Architectures: s390
6256:Parameters: none
David Hildenbrand051c87f2016-04-19 13:13:40 +02006257
6258Allows use of runtime-instrumentation introduced with zEC12 processor.
6259Will return -EINVAL if the machine does not support runtime-instrumentation.
6260Will return -EBUSY if a VCPU has already been created.
Michael Ellermane928e9c2015-03-20 20:39:41 +11006261
Radim Krčmář371313132016-07-12 22:09:27 +020062627.7 KVM_CAP_X2APIC_API
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006263----------------------
Radim Krčmář371313132016-07-12 22:09:27 +02006264
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006265:Architectures: x86
6266:Parameters: args[0] - features that should be enabled
6267:Returns: 0 on success, -EINVAL when args[0] contains invalid features
Radim Krčmář371313132016-07-12 22:09:27 +02006268
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006269Valid feature flags in args[0] are::
Radim Krčmář371313132016-07-12 22:09:27 +02006270
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006271 #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0)
6272 #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1)
Radim Krčmář371313132016-07-12 22:09:27 +02006273
6274Enabling KVM_X2APIC_API_USE_32BIT_IDS changes the behavior of
6275KVM_SET_GSI_ROUTING, KVM_SIGNAL_MSI, KVM_SET_LAPIC, and KVM_GET_LAPIC,
6276allowing the use of 32-bit APIC IDs. See KVM_CAP_X2APIC_API in their
6277respective sections.
6278
Radim Krčmářc5192652016-07-12 22:09:28 +02006279KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK must be enabled for x2APIC to work
6280in logical mode or with more than 255 VCPUs. Otherwise, KVM treats 0xff
6281as a broadcast even in x2APIC mode in order to support physical x2APIC
6282without interrupt remapping. This is undesirable in logical mode,
6283where 0xff represents CPUs 0-7 in cluster 0.
Radim Krčmář371313132016-07-12 22:09:27 +02006284
David Hildenbrand6502a342016-06-21 14:19:51 +020062857.8 KVM_CAP_S390_USER_INSTR0
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006286----------------------------
David Hildenbrand6502a342016-06-21 14:19:51 +02006287
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006288:Architectures: s390
6289:Parameters: none
David Hildenbrand6502a342016-06-21 14:19:51 +02006290
6291With this capability enabled, all illegal instructions 0x0000 (2 bytes) will
6292be intercepted and forwarded to user space. User space can use this
6293mechanism e.g. to realize 2-byte software breakpoints. The kernel will
6294not inject an operating exception for these instructions, user space has
6295to take care of that.
6296
6297This capability can be enabled dynamically even if VCPUs were already
6298created and are running.
Radim Krčmář371313132016-07-12 22:09:27 +02006299
Fan Zhang4e0b1ab2016-11-29 07:17:55 +010063007.9 KVM_CAP_S390_GS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006301-------------------
Fan Zhang4e0b1ab2016-11-29 07:17:55 +01006302
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006303:Architectures: s390
6304:Parameters: none
6305:Returns: 0 on success; -EINVAL if the machine does not support
6306 guarded storage; -EBUSY if a VCPU has already been created.
Fan Zhang4e0b1ab2016-11-29 07:17:55 +01006307
6308Allows use of guarded storage for the KVM guest.
6309
Yi Min Zhao47a46932017-03-10 09:29:38 +010063107.10 KVM_CAP_S390_AIS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006311---------------------
Yi Min Zhao47a46932017-03-10 09:29:38 +01006312
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006313:Architectures: s390
6314:Parameters: none
Yi Min Zhao47a46932017-03-10 09:29:38 +01006315
6316Allow use of adapter-interruption suppression.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006317:Returns: 0 on success; -EBUSY if a VCPU has already been created.
Yi Min Zhao47a46932017-03-10 09:29:38 +01006318
Paul Mackerras3c313522017-02-06 13:24:41 +110063197.11 KVM_CAP_PPC_SMT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006320--------------------
Paul Mackerras3c313522017-02-06 13:24:41 +11006321
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006322:Architectures: ppc
6323:Parameters: vsmt_mode, flags
Paul Mackerras3c313522017-02-06 13:24:41 +11006324
6325Enabling this capability on a VM provides userspace with a way to set
6326the desired virtual SMT mode (i.e. the number of virtual CPUs per
6327virtual core). The virtual SMT mode, vsmt_mode, must be a power of 2
6328between 1 and 8. On POWER8, vsmt_mode must also be no greater than
6329the number of threads per subcore for the host. Currently flags must
6330be 0. A successful call to enable this capability will result in
6331vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
6332subsequently queried for the VM. This capability is only supported by
6333HV KVM, and can only be set before any VCPUs have been created.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006334The KVM_CAP_PPC_SMT_POSSIBLE capability indicates which virtual SMT
6335modes are available.
Paul Mackerras3c313522017-02-06 13:24:41 +11006336
Aravinda Prasad134764e2017-05-11 16:32:48 +053063377.12 KVM_CAP_PPC_FWNMI
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006338----------------------
Aravinda Prasad134764e2017-05-11 16:32:48 +05306339
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006340:Architectures: ppc
6341:Parameters: none
Aravinda Prasad134764e2017-05-11 16:32:48 +05306342
6343With this capability a machine check exception in the guest address
6344space will cause KVM to exit the guest with NMI exit reason. This
6345enables QEMU to build error log and branch to guest kernel registered
6346machine check handling routine. Without this capability KVM will
6347branch to guests' 0x200 interrupt vector.
6348
Wanpeng Li4d5422c2018-03-12 04:53:02 -070063497.13 KVM_CAP_X86_DISABLE_EXITS
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006350------------------------------
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006351
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006352:Architectures: x86
6353:Parameters: args[0] defines which exits are disabled
6354:Returns: 0 on success, -EINVAL when args[0] contains invalid exits
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006355
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006356Valid bits in args[0] are::
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006357
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006358 #define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
6359 #define KVM_X86_DISABLE_EXITS_HLT (1 << 1)
6360 #define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
6361 #define KVM_X86_DISABLE_EXITS_CSTATE (1 << 3)
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006362
6363Enabling this capability on a VM provides userspace with a way to no
6364longer intercept some instructions for improved latency in some
6365workloads, and is suggested when vCPUs are associated to dedicated
6366physical CPUs. More bits can be added in the future; userspace can
6367just pass the KVM_CHECK_EXTENSION result to KVM_ENABLE_CAP to disable
6368all such vmexits.
6369
Wanpeng Licaa057a2018-03-12 04:53:03 -07006370Do not enable KVM_FEATURE_PV_UNHALT if you disable HLT exits.
Wanpeng Li4d5422c2018-03-12 04:53:02 -07006371
Janosch Franka4499382018-07-13 11:28:31 +010063727.14 KVM_CAP_S390_HPAGE_1M
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006373--------------------------
Janosch Franka4499382018-07-13 11:28:31 +01006374
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006375:Architectures: s390
6376:Parameters: none
6377:Returns: 0 on success, -EINVAL if hpage module parameter was not set
6378 or cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
6379 flag set
Janosch Franka4499382018-07-13 11:28:31 +01006380
6381With this capability the KVM support for memory backing with 1m pages
6382through hugetlbfs can be enabled for a VM. After the capability is
6383enabled, cmma can't be enabled anymore and pfmfi and the storage key
6384interpretation are disabled. If cmma has already been enabled or the
6385hpage module parameter is not set to 1, -EINVAL is returned.
6386
6387While it is generally possible to create a huge page backed VM without
6388this capability, the VM will not be able to run.
6389
Jim Mattsonc4f55192018-10-16 14:29:24 -070063907.15 KVM_CAP_MSR_PLATFORM_INFO
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006391------------------------------
Drew Schmitt6fbbde92018-08-20 10:32:15 -07006392
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006393:Architectures: x86
6394:Parameters: args[0] whether feature should be enabled or not
Drew Schmitt6fbbde92018-08-20 10:32:15 -07006395
6396With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
6397a #GP would be raised when the guest tries to access. Currently, this
6398capability does not enable write permissions of this MSR for the guest.
6399
Paul Mackerrasaa069a92018-09-21 20:02:01 +100064007.16 KVM_CAP_PPC_NESTED_HV
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006401--------------------------
Paul Mackerrasaa069a92018-09-21 20:02:01 +10006402
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006403:Architectures: ppc
6404:Parameters: none
6405:Returns: 0 on success, -EINVAL when the implementation doesn't support
6406 nested-HV virtualization.
Paul Mackerrasaa069a92018-09-21 20:02:01 +10006407
6408HV-KVM on POWER9 and later systems allows for "nested-HV"
6409virtualization, which provides a way for a guest VM to run guests that
6410can run using the CPU's supervisor mode (privileged non-hypervisor
6411state). Enabling this capability on a VM depends on the CPU having
6412the necessary functionality and on the facility being enabled with a
6413kvm-hv module parameter.
6414
Jim Mattsonc4f55192018-10-16 14:29:24 -070064157.17 KVM_CAP_EXCEPTION_PAYLOAD
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006416------------------------------
Jim Mattsonc4f55192018-10-16 14:29:24 -07006417
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006418:Architectures: x86
6419:Parameters: args[0] whether feature should be enabled or not
Jim Mattsonc4f55192018-10-16 14:29:24 -07006420
6421With this capability enabled, CR2 will not be modified prior to the
6422emulated VM-exit when L1 intercepts a #PF exception that occurs in
6423L2. Similarly, for kvm-intel only, DR6 will not be modified prior to
6424the emulated VM-exit when L1 intercepts a #DB exception that occurs in
6425L2. As a result, when KVM_GET_VCPU_EVENTS reports a pending #PF (or
6426#DB) exception for L2, exception.has_payload will be set and the
6427faulting address (or the new DR6 bits*) will be reported in the
6428exception_payload field. Similarly, when userspace injects a #PF (or
6429#DB) into L2 using KVM_SET_VCPU_EVENTS, it is expected to set
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006430exception.has_payload and to put the faulting address - or the new DR6
6431bits\ [#]_ - in the exception_payload field.
Jim Mattsonc4f55192018-10-16 14:29:24 -07006432
6433This capability also enables exception.pending in struct
6434kvm_vcpu_events, which allows userspace to distinguish between pending
6435and injected exceptions.
6436
6437
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006438.. [#] For the new DR6 bits, note that bit 16 is set iff the #DB exception
6439 will clear DR6.RTM.
Jim Mattsonc4f55192018-10-16 14:29:24 -07006440
Peter Xud7547c52019-05-08 17:15:47 +080064417.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006442
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006443:Architectures: x86, arm, arm64, mips
6444:Parameters: args[0] whether feature should be enabled or not
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006445
Jay Zhou3c9bd402020-02-27 09:32:27 +08006446Valid flags are::
6447
6448 #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0)
6449 #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1)
6450
6451With KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE is set, KVM_GET_DIRTY_LOG will not
6452automatically clear and write-protect all pages that are returned as dirty.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006453Rather, userspace will have to do this operation separately using
6454KVM_CLEAR_DIRTY_LOG.
6455
6456At the cost of a slightly more complicated operation, this provides better
6457scalability and responsiveness for two reasons. First,
6458KVM_CLEAR_DIRTY_LOG ioctl can operate on a 64-page granularity rather
6459than requiring to sync a full memslot; this ensures that KVM does not
6460take spinlocks for an extended period of time. Second, in some cases a
6461large amount of time can pass between a call to KVM_GET_DIRTY_LOG and
6462userspace actually using the data in the page. Pages can be modified
Jay Zhou3c9bd402020-02-27 09:32:27 +08006463during this time, which is inefficient for both the guest and userspace:
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006464the guest will incur a higher penalty due to write protection faults,
6465while userspace can see false reports of dirty pages. Manual reprotection
6466helps reducing this time, improving guest performance and reducing the
6467number of dirty log false positives.
6468
Jay Zhou3c9bd402020-02-27 09:32:27 +08006469With KVM_DIRTY_LOG_INITIALLY_SET set, all the bits of the dirty bitmap
6470will be initialized to 1 when created. This also improves performance because
6471dirty logging can be enabled gradually in small chunks on the first call
6472to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on
6473KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
Keqian Zhuc8626262020-04-13 20:20:23 +08006474x86 and arm64 for now).
Jay Zhou3c9bd402020-02-27 09:32:27 +08006475
Peter Xud7547c52019-05-08 17:15:47 +08006476KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
6477KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make
6478it hard or impossible to use it correctly. The availability of
6479KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed.
6480Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
Paolo Bonzini2a31b9d2018-10-23 02:36:47 +02006481
Paul Mackerras9a5788c2020-03-19 15:29:55 +110064827.19 KVM_CAP_PPC_SECURE_GUEST
6483------------------------------
6484
6485:Architectures: ppc
6486
6487This capability indicates that KVM is running on a host that has
6488ultravisor firmware and thus can support a secure guest. On such a
6489system, a guest can ask the ultravisor to make it a secure guest,
6490one whose memory is inaccessible to the host except for pages which
6491are explicitly requested to be shared with the host. The ultravisor
6492notifies KVM when a guest requests to become a secure guest, and KVM
6493has the opportunity to veto the transition.
6494
6495If present, this capability can be enabled for a VM, meaning that KVM
6496will allow the transition to secure guest mode. Otherwise KVM will
6497veto the transition.
6498
David Matlackacd05782020-04-17 15:14:46 -070064997.20 KVM_CAP_HALT_POLL
6500----------------------
6501
6502:Architectures: all
6503:Target: VM
6504:Parameters: args[0] is the maximum poll time in nanoseconds
6505:Returns: 0 on success; -1 on error
6506
6507This capability overrides the kvm module parameter halt_poll_ns for the
6508target VM.
6509
6510VCPU polling allows a VCPU to poll for wakeup events instead of immediately
6511scheduling during guest halts. The maximum time a VCPU can spend polling is
6512controlled by the kvm module parameter halt_poll_ns. This capability allows
6513the maximum halt time to specified on a per-VM basis, effectively overriding
6514the module parameter for the target VM.
6515
Alexander Graf1ae09952020-09-25 16:34:16 +020065167.21 KVM_CAP_X86_USER_SPACE_MSR
6517-------------------------------
6518
6519:Architectures: x86
6520:Target: VM
6521:Parameters: args[0] contains the mask of KVM_MSR_EXIT_REASON_* events to report
6522:Returns: 0 on success; -1 on error
6523
6524This capability enables trapping of #GP invoking RDMSR and WRMSR instructions
6525into user space.
6526
6527When a guest requests to read or write an MSR, KVM may not implement all MSRs
6528that are relevant to a respective system. It also does not differentiate by
6529CPU type.
6530
6531To allow more fine grained control over MSR handling, user space may enable
6532this capability. With it enabled, MSR accesses that match the mask specified in
6533args[0] and trigger a #GP event inside the guest by KVM will instead trigger
6534KVM_EXIT_X86_RDMSR and KVM_EXIT_X86_WRMSR exit notifications which user space
6535can then handle to implement model specific MSR handling and/or user notifications
6536to inform a user that an MSR was not handled.
6537
Chenyi Qiangc32b1b892020-11-06 17:03:15 +080065387.22 KVM_CAP_X86_BUS_LOCK_EXIT
6539-------------------------------
6540
6541:Architectures: x86
6542:Target: VM
6543:Parameters: args[0] defines the policy used when bus locks detected in guest
6544:Returns: 0 on success, -EINVAL when args[0] contains invalid bits
6545
6546Valid bits in args[0] are::
6547
6548 #define KVM_BUS_LOCK_DETECTION_OFF (1 << 0)
6549 #define KVM_BUS_LOCK_DETECTION_EXIT (1 << 1)
6550
6551Enabling this capability on a VM provides userspace with a way to select
6552a policy to handle the bus locks detected in guest. Userspace can obtain
6553the supported modes from the result of KVM_CHECK_EXTENSION and define it
6554through the KVM_ENABLE_CAP.
6555
6556KVM_BUS_LOCK_DETECTION_OFF and KVM_BUS_LOCK_DETECTION_EXIT are supported
6557currently and mutually exclusive with each other. More bits can be added in
6558the future.
6559
6560With KVM_BUS_LOCK_DETECTION_OFF set, bus locks in guest will not cause vm exits
6561so that no additional actions are needed. This is the default mode.
6562
6563With KVM_BUS_LOCK_DETECTION_EXIT set, vm exits happen when bus lock detected
6564in VM. KVM just exits to userspace when handling them. Userspace can enforce
6565its own throttling or other policy based mitigations.
6566
6567This capability is aimed to address the thread that VM can exploit bus locks to
6568degree the performance of the whole system. Once the userspace enable this
6569capability and select the KVM_BUS_LOCK_DETECTION_EXIT mode, KVM will set the
6570KVM_RUN_BUS_LOCK flag in vcpu-run->flags field and exit to userspace. Concerning
6571the bus lock vm exit can be preempted by a higher priority VM exit, the exit
6572notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
6573KVM_RUN_BUS_LOCK flag is used to distinguish between them.
6574
Kai Huang7d2cdad2021-02-26 22:48:32 +130065757.23 KVM_CAP_PPC_DAWR1
Ravi Bangoriad9a47ed2020-12-16 16:12:19 +05306576----------------------
6577
6578:Architectures: ppc
6579:Parameters: none
6580:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
6581
6582This capability can be used to check / enable 2nd DAWR feature provided
6583by POWER10 processor.
6584
Aaron Lewis19238e72021-05-10 07:48:33 -07006585
Nathan Tempelman54526d12021-04-08 22:32:14 +000065867.24 KVM_CAP_VM_COPY_ENC_CONTEXT_FROM
6587-------------------------------------
6588
6589Architectures: x86 SEV enabled
6590Type: vm
6591Parameters: args[0] is the fd of the source vm
6592Returns: 0 on success; ENOTTY on error
6593
6594This capability enables userspace to copy encryption context from the vm
6595indicated by the fd to the vm this is called on.
6596
6597This is intended to support in-guest workloads scheduled by the host. This
6598allows the in-guest workload to maintain its own NPTs and keeps the two vms
6599from accidentally clobbering each other with interrupts and the like (separate
6600APIC/MSRs/etc).
6601
Sean Christophersonfe7e9482021-04-12 16:21:43 +120066027.25 KVM_CAP_SGX_ATTRIBUTE
Paolo Bonzinif82762f2021-04-22 09:49:46 -04006603--------------------------
Sean Christophersonfe7e9482021-04-12 16:21:43 +12006604
6605:Architectures: x86
6606:Target: VM
6607:Parameters: args[0] is a file handle of a SGX attribute file in securityfs
6608:Returns: 0 on success, -EINVAL if the file handle is invalid or if a requested
6609 attribute is not supported by KVM.
6610
6611KVM_CAP_SGX_ATTRIBUTE enables a userspace VMM to grant a VM access to one or
6612more priveleged enclave attributes. args[0] must hold a file handle to a valid
6613SGX attribute file corresponding to an attribute that is supported/restricted
6614by KVM (currently only PROVISIONKEY).
6615
6616The SGX subsystem restricts access to a subset of enclave attributes to provide
6617additional security for an uncompromised kernel, e.g. use of the PROVISIONKEY
6618is restricted to deter malware from using the PROVISIONKEY to obtain a stable
6619system fingerprint. To prevent userspace from circumventing such restrictions
6620by running an enclave in a VM, KVM prevents access to privileged attributes by
6621default.
6622
6623See Documentation/x86/sgx/2.Kernel-internals.rst for more details.
6624
Bharata B Raob87cc112021-06-21 14:20:02 +053066257.26 KVM_CAP_PPC_RPT_INVALIDATE
6626-------------------------------
6627
6628:Capability: KVM_CAP_PPC_RPT_INVALIDATE
6629:Architectures: ppc
6630:Type: vm
6631
6632This capability indicates that the kernel is capable of handling
6633H_RPT_INVALIDATE hcall.
6634
6635In order to enable the use of H_RPT_INVALIDATE in the guest,
6636user space might have to advertise it for the guest. For example,
6637IBM pSeries (sPAPR) guest starts using it if "hcall-rpt-invalidate" is
6638present in the "ibm,hypertas-functions" device-tree property.
6639
6640This capability is enabled for hypervisors on platforms like POWER9
6641that support radix MMU.
6642
Aaron Lewis19238e72021-05-10 07:48:33 -070066437.27 KVM_CAP_EXIT_ON_EMULATION_FAILURE
6644--------------------------------------
6645
6646:Architectures: x86
6647:Parameters: args[0] whether the feature should be enabled or not
6648
6649When this capability is enabled, an emulation failure will result in an exit
6650to userspace with KVM_INTERNAL_ERROR (except when the emulator was invoked
6651to handle a VMware backdoor instruction). Furthermore, KVM will now provide up
6652to 15 instruction bytes for any exit to userspace resulting from an emulation
6653failure. When these exits to userspace occur use the emulation_failure struct
6654instead of the internal struct. They both have the same layout, but the
6655emulation_failure struct matches the content better. It also explicitly
6656defines the 'flags' field which is used to describe the fields in the struct
6657that are valid (ie: if KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES is
6658set in the 'flags' field then both 'insn_size' and 'insn_bytes' have valid data
6659in them.)
6660
Paolo Bonzinib8917b42021-06-25 11:24:24 -040066617.28 KVM_CAP_ARM_MTE
Steven Price04c02c22021-06-21 12:17:16 +01006662--------------------
6663
6664:Architectures: arm64
6665:Parameters: none
6666
6667This capability indicates that KVM (and the hardware) supports exposing the
6668Memory Tagging Extensions (MTE) to the guest. It must also be enabled by the
6669VMM before creating any VCPUs to allow the guest access. Note that MTE is only
6670available to a guest running in AArch64 mode and enabling this capability will
6671cause attempts to create AArch32 VCPUs to fail.
6672
6673When enabled the guest is able to access tags associated with any memory given
6674to the guest. KVM will ensure that the tags are maintained during swap or
6675hibernation of the host; however the VMM needs to manually save/restore the
6676tags as appropriate if the VM is migrated.
6677
6678When this capability is enabled all memory in memslots must be mapped as
6679not-shareable (no MAP_SHARED), attempts to create a memslot with a
6680MAP_SHARED mmap will result in an -EINVAL return.
6681
6682When enabled the VMM may make use of the ``KVM_ARM_MTE_COPY_TAGS`` ioctl to
6683perform a bulk copy of tags to/from the guest.
Aaron Lewis19238e72021-05-10 07:48:33 -07006684
Michael Ellermane928e9c2015-03-20 20:39:41 +110066858. Other capabilities.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006686======================
Michael Ellermane928e9c2015-03-20 20:39:41 +11006687
6688This section lists capabilities that give information about other
6689features of the KVM implementation.
6690
66918.1 KVM_CAP_PPC_HWRNG
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006692---------------------
Michael Ellermane928e9c2015-03-20 20:39:41 +11006693
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006694:Architectures: ppc
Michael Ellermane928e9c2015-03-20 20:39:41 +11006695
6696This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006697available, means that the kernel has an implementation of the
Michael Ellermane928e9c2015-03-20 20:39:41 +11006698H_RANDOM hypercall backed by a hardware random-number generator.
6699If present, the kernel H_RANDOM handler can be enabled for guest use
6700with the KVM_CAP_PPC_ENABLE_HCALL capability.
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006701
67028.2 KVM_CAP_HYPERV_SYNIC
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006703------------------------
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006704
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006705:Architectures: x86
6706
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006707This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006708available, means that the kernel has an implementation of the
Andrey Smetanin5c9194122015-11-10 15:36:34 +03006709Hyper-V Synthetic interrupt controller(SynIC). Hyper-V SynIC is
6710used to support Windows Hyper-V based guest paravirt drivers(VMBus).
6711
6712In order to use SynIC, it has to be activated by setting this
6713capability via KVM_ENABLE_CAP ioctl on the vcpu fd. Note that this
6714will disable the use of APIC hardware virtualization even if supported
6715by the CPU, as it's incompatible with SynIC auto-EOI behavior.
Paul Mackerrasc9270132017-01-30 21:21:41 +11006716
67178.3 KVM_CAP_PPC_RADIX_MMU
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006718-------------------------
Paul Mackerrasc9270132017-01-30 21:21:41 +11006719
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006720:Architectures: ppc
Paul Mackerrasc9270132017-01-30 21:21:41 +11006721
6722This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006723available, means that the kernel can support guests using the
Paul Mackerrasc9270132017-01-30 21:21:41 +11006724radix MMU defined in Power ISA V3.00 (as implemented in the POWER9
6725processor).
6726
67278.4 KVM_CAP_PPC_HASH_MMU_V3
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006728---------------------------
Paul Mackerrasc9270132017-01-30 21:21:41 +11006729
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006730:Architectures: ppc
Paul Mackerrasc9270132017-01-30 21:21:41 +11006731
6732This capability, if KVM_CHECK_EXTENSION indicates that it is
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006733available, means that the kernel can support guests using the
Paul Mackerrasc9270132017-01-30 21:21:41 +11006734hashed page table MMU defined in Power ISA V3.00 (as implemented in
6735the POWER9 processor), including in-memory segment tables.
James Hogana8a3c422017-03-14 10:15:19 +00006736
67378.5 KVM_CAP_MIPS_VZ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006738-------------------
James Hogana8a3c422017-03-14 10:15:19 +00006739
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006740:Architectures: mips
James Hogana8a3c422017-03-14 10:15:19 +00006741
6742This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
6743it is available, means that full hardware assisted virtualization capabilities
6744of the hardware are available for use through KVM. An appropriate
6745KVM_VM_MIPS_* type must be passed to KVM_CREATE_VM to create a VM which
6746utilises it.
6747
6748If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
6749available, it means that the VM is using full hardware assisted virtualization
6750capabilities of the hardware. This is useful to check after creating a VM with
6751KVM_VM_MIPS_DEFAULT.
6752
6753The value returned by KVM_CHECK_EXTENSION should be compared against known
6754values (see below). All other values are reserved. This is to allow for the
6755possibility of other hardware assisted virtualization implementations which
6756may be incompatible with the MIPS VZ ASE.
6757
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006758== ==========================================================================
6759 0 The trap & emulate implementation is in use to run guest code in user
James Hogana8a3c422017-03-14 10:15:19 +00006760 mode. Guest virtual memory segments are rearranged to fit the guest in the
6761 user mode address space.
6762
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006763 1 The MIPS VZ ASE is in use, providing full hardware assisted
James Hogana8a3c422017-03-14 10:15:19 +00006764 virtualization, including standard guest virtual memory segments.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006765== ==========================================================================
James Hogana8a3c422017-03-14 10:15:19 +00006766
67678.6 KVM_CAP_MIPS_TE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006768-------------------
James Hogana8a3c422017-03-14 10:15:19 +00006769
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006770:Architectures: mips
James Hogana8a3c422017-03-14 10:15:19 +00006771
6772This capability, if KVM_CHECK_EXTENSION on the main kvm handle indicates that
6773it is available, means that the trap & emulate implementation is available to
6774run guest code in user mode, even if KVM_CAP_MIPS_VZ indicates that hardware
6775assisted virtualisation is also available. KVM_VM_MIPS_TE (0) must be passed
6776to KVM_CREATE_VM to create a VM which utilises it.
6777
6778If KVM_CHECK_EXTENSION on a kvm VM handle indicates that this capability is
6779available, it means that the VM is using trap & emulate.
James Hogan578fd612017-03-14 10:15:20 +00006780
67818.7 KVM_CAP_MIPS_64BIT
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006782----------------------
James Hogan578fd612017-03-14 10:15:20 +00006783
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006784:Architectures: mips
James Hogan578fd612017-03-14 10:15:20 +00006785
6786This capability indicates the supported architecture type of the guest, i.e. the
6787supported register and address width.
6788
6789The values returned when this capability is checked by KVM_CHECK_EXTENSION on a
6790kvm VM handle correspond roughly to the CP0_Config.AT register field, and should
6791be checked specifically against known values (see below). All other values are
6792reserved.
6793
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006794== ========================================================================
6795 0 MIPS32 or microMIPS32.
James Hogan578fd612017-03-14 10:15:20 +00006796 Both registers and addresses are 32-bits wide.
6797 It will only be possible to run 32-bit guest code.
6798
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006799 1 MIPS64 or microMIPS64 with access only to 32-bit compatibility segments.
James Hogan578fd612017-03-14 10:15:20 +00006800 Registers are 64-bits wide, but addresses are 32-bits wide.
6801 64-bit guest code may run but cannot access MIPS64 memory segments.
6802 It will also be possible to run 32-bit guest code.
6803
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006804 2 MIPS64 or microMIPS64 with access to all address segments.
James Hogan578fd612017-03-14 10:15:20 +00006805 Both registers and addresses are 64-bits wide.
6806 It will be possible to run 64-bit or 32-bit guest code.
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006807== ========================================================================
Michael S. Tsirkin668fffa2017-04-21 12:27:17 +02006808
Paolo Bonzinic24a7be2017-04-27 17:33:14 +020068098.9 KVM_CAP_ARM_USER_IRQ
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006810------------------------
Alexander Graf3fe17e62016-09-27 21:08:05 +02006811
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006812:Architectures: arm, arm64
6813
Alexander Graf3fe17e62016-09-27 21:08:05 +02006814This capability, if KVM_CHECK_EXTENSION indicates that it is available, means
6815that if userspace creates a VM without an in-kernel interrupt controller, it
6816will be notified of changes to the output level of in-kernel emulated devices,
6817which can generate virtual interrupts, presented to the VM.
6818For such VMs, on every return to userspace, the kernel
6819updates the vcpu's run->s.regs.device_irq_level field to represent the actual
6820output level of the device.
6821
6822Whenever kvm detects a change in the device output level, kvm guarantees at
6823least one return to userspace before running the VM. This exit could either
6824be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way,
6825userspace can always sample the device output level and re-compute the state of
6826the userspace interrupt controller. Userspace should always check the state
6827of run->s.regs.device_irq_level on every kvm exit.
6828The value in run->s.regs.device_irq_level can represent both level and edge
6829triggered interrupt signals, depending on the device. Edge triggered interrupt
6830signals will exit to userspace with the bit in run->s.regs.device_irq_level
6831set exactly once per edge signal.
6832
6833The field run->s.regs.device_irq_level is available independent of
6834run->kvm_valid_regs or run->kvm_dirty_regs bits.
6835
6836If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a
6837number larger than 0 indicating the version of this capability is implemented
Randy Dunlap3747c5d2020-07-03 14:29:06 -07006838and thereby which bits in run->s.regs.device_irq_level can signal values.
Alexander Graf3fe17e62016-09-27 21:08:05 +02006839
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006840Currently the following bits are defined for the device_irq_level bitmap::
Alexander Graf3fe17e62016-09-27 21:08:05 +02006841
6842 KVM_CAP_ARM_USER_IRQ >= 1:
6843
6844 KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer
6845 KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer
6846 KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal
6847
6848Future versions of kvm may implement additional events. These will get
6849indicated by returning a higher number from KVM_CHECK_EXTENSION and will be
6850listed above.
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006851
68528.10 KVM_CAP_PPC_SMT_POSSIBLE
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006853-----------------------------
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006854
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006855:Architectures: ppc
Paul Mackerras2ed4f9d2017-06-21 16:01:27 +10006856
6857Querying this capability returns a bitmap indicating the possible
6858virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
6859(counting from the right) is set, then a virtual SMT mode of 2^N is
6860available.
Roman Kaganefc479e2017-06-22 16:51:01 +03006861
68628.11 KVM_CAP_HYPERV_SYNIC2
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006863--------------------------
Roman Kaganefc479e2017-06-22 16:51:01 +03006864
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006865:Architectures: x86
Roman Kaganefc479e2017-06-22 16:51:01 +03006866
6867This capability enables a newer version of Hyper-V Synthetic interrupt
6868controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
6869doesn't clear SynIC message and event flags pages when they are enabled by
6870writing to the respective MSRs.
Roman Kagand3457c82017-07-14 17:13:20 +03006871
68728.12 KVM_CAP_HYPERV_VP_INDEX
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006873----------------------------
Roman Kagand3457c82017-07-14 17:13:20 +03006874
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006875:Architectures: x86
Roman Kagand3457c82017-07-14 17:13:20 +03006876
6877This capability indicates that userspace can load HV_X64_MSR_VP_INDEX msr. Its
6878value is used to denote the target vcpu for a SynIC interrupt. For
6879compatibilty, KVM initializes this msr to KVM's internal vcpu index. When this
6880capability is absent, userspace can still query this msr's value.
Christian Borntraegerda9a1442017-11-09 10:00:45 +01006881
68828.13 KVM_CAP_S390_AIS_MIGRATION
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006883-------------------------------
Christian Borntraegerda9a1442017-11-09 10:00:45 +01006884
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006885:Architectures: s390
6886:Parameters: none
Christian Borntraegerda9a1442017-11-09 10:00:45 +01006887
6888This capability indicates if the flic device will be able to get/set the
6889AIS states for migration via the KVM_DEV_FLIC_AISM_ALL attribute and allows
6890to discover this without having to create a flic device.
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006891
68928.14 KVM_CAP_S390_PSW
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006893---------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006894
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006895:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006896
6897This capability indicates that the PSW is exposed via the kvm_run structure.
6898
68998.15 KVM_CAP_S390_GMAP
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006900----------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006901
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006902:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006903
6904This capability indicates that the user space memory used as guest mapping can
6905be anywhere in the user memory address space, as long as the memory slots are
6906aligned and sized to a segment (1MB) boundary.
6907
69088.16 KVM_CAP_S390_COW
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006909---------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006910
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006911:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006912
6913This capability indicates that the user space memory used as guest mapping can
6914use copy-on-write semantics as well as dirty pages tracking via read-only page
6915tables.
6916
69178.17 KVM_CAP_S390_BPB
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006918---------------------
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006919
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006920:Architectures: s390
Christian Borntraeger5c2b4d52018-02-22 13:40:04 +00006921
6922This capability indicates that kvm will implement the interfaces to handle
6923reset, migration and nested KVM for branch prediction blocking. The stfle
6924facility 82 should not be provided to the guest without this capability.
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02006925
Vitaly Kuznetsov2ddc6492018-06-22 16:56:14 +020069268.18 KVM_CAP_HYPERV_TLBFLUSH
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006927----------------------------
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02006928
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006929:Architectures: x86
Vitaly Kuznetsovc1aea912018-05-16 17:21:31 +02006930
6931This capability indicates that KVM supports paravirtualized Hyper-V TLB Flush
6932hypercalls:
6933HvFlushVirtualAddressSpace, HvFlushVirtualAddressSpaceEx,
6934HvFlushVirtualAddressList, HvFlushVirtualAddressListEx.
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01006935
Dongjiu Geng688e0582018-08-20 17:39:25 -040069368.19 KVM_CAP_ARM_INJECT_SERROR_ESR
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006937----------------------------------
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01006938
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +01006939:Architectures: arm, arm64
Dongjiu Gengbe26b3a2018-07-19 16:24:23 +01006940
6941This capability indicates that userspace can specify (via the
6942KVM_SET_VCPU_EVENTS ioctl) the syndrome value reported to the guest when it
6943takes a virtual SError interrupt exception.
6944If KVM advertises this capability, userspace can only specify the ISS field for
6945the ESR syndrome. Other parts of the ESR, such as the EC are generated by the
6946CPU when the exception is taken. If this virtual SError is taken to EL1 using
6947AArch64, this value will be reported in the ISS field of ESR_ELx.
6948
6949See KVM_CAP_VCPU_EVENTS for more details.
Vitaly Kuznetsov214ff832018-09-26 19:02:59 +02006950
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010069518.20 KVM_CAP_HYPERV_SEND_IPI
6952----------------------------
6953
6954:Architectures: x86
Vitaly Kuznetsov214ff832018-09-26 19:02:59 +02006955
6956This capability indicates that KVM supports paravirtualized Hyper-V IPI send
6957hypercalls:
6958HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx.
Tianyu Lan344c6c82019-08-22 22:30:20 +08006959
Mauro Carvalho Chehab106ee472020-02-10 07:02:55 +010069608.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH
6961-----------------------------------
6962
Andrew Jones739c7af2020-08-04 19:06:03 +02006963:Architectures: x86
Tianyu Lan344c6c82019-08-22 22:30:20 +08006964
6965This capability indicates that KVM running on top of Hyper-V hypervisor
6966enables Direct TLB flush for its guests meaning that TLB flush
6967hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM.
6968Due to the different ABI for hypercall parameters between Hyper-V and
6969KVM, enabling this capability effectively disables all hypercall
6970handling by KVM (as some KVM hypercall may be mistakenly treated as TLB
6971flush hypercalls by Hyper-V) so userspace should disable KVM identification
6972in CPUID and only exposes Hyper-V identification. In this case, guest
6973thinks it's running on Hyper-V and only use Hyper-V hypercalls.
Janosch Frank7de3f142020-01-31 05:02:02 -05006974
69758.22 KVM_CAP_S390_VCPU_RESETS
Andrew Jones739c7af2020-08-04 19:06:03 +02006976-----------------------------
Janosch Frank7de3f142020-01-31 05:02:02 -05006977
Andrew Jones739c7af2020-08-04 19:06:03 +02006978:Architectures: s390
Janosch Frank7de3f142020-01-31 05:02:02 -05006979
6980This capability indicates that the KVM_S390_NORMAL_RESET and
6981KVM_S390_CLEAR_RESET ioctls are available.
Janosch Frank04ed89d2019-11-08 05:05:26 -05006982
69838.23 KVM_CAP_S390_PROTECTED
Andrew Jones739c7af2020-08-04 19:06:03 +02006984---------------------------
Janosch Frank04ed89d2019-11-08 05:05:26 -05006985
Andrew Jones739c7af2020-08-04 19:06:03 +02006986:Architectures: s390
Janosch Frank04ed89d2019-11-08 05:05:26 -05006987
6988This capability indicates that the Ultravisor has been initialized and
6989KVM can therefore start protected VMs.
6990This capability governs the KVM_S390_PV_COMMAND ioctl and the
6991KVM_MP_STATE_LOAD MP_STATE. KVM_SET_MP_STATE can fail for protected
6992guests when the state change is invalid.
Andrew Jones004a0122020-08-04 19:06:04 +02006993
69948.24 KVM_CAP_STEAL_TIME
6995-----------------------
6996
6997:Architectures: arm64, x86
6998
6999This capability indicates that KVM supports steal time accounting.
7000When steal time accounting is supported it may be enabled with
7001architecture-specific interfaces. This capability and the architecture-
7002specific interfaces must be consistent, i.e. if one says the feature
7003is supported, than the other should as well and vice versa. For arm64
7004see Documentation/virt/kvm/devices/vcpu.rst "KVM_ARM_VCPU_PVTIME_CTRL".
7005For x86 see Documentation/virt/kvm/msr.rst "MSR_KVM_STEAL_TIME".
Collin Wallingf20d4e92020-06-25 11:07:23 -04007006
70078.25 KVM_CAP_S390_DIAG318
7008-------------------------
7009
7010:Architectures: s390
7011
7012This capability enables a guest to set information about its control program
7013(i.e. guest kernel type and version). The information is helpful during
7014system/firmware service events, providing additional data about the guest
7015environments running on the machine.
7016
7017The information is associated with the DIAGNOSE 0x318 instruction, which sets
7018an 8-byte value consisting of a one-byte Control Program Name Code (CPNC) and
7019a 7-byte Control Program Version Code (CPVC). The CPNC determines what
7020environment the control program is running in (e.g. Linux, z/VM...), and the
7021CPVC is used for information specific to OS (e.g. Linux version, Linux
7022distribution...)
7023
7024If this capability is available, then the CPNC and CPVC can be synchronized
7025between KVM and userspace via the sync regs mechanism (KVM_SYNC_DIAG318).
Alexander Graf1ae09952020-09-25 16:34:16 +02007026
70278.26 KVM_CAP_X86_USER_SPACE_MSR
7028-------------------------------
7029
7030:Architectures: x86
7031
7032This capability indicates that KVM supports deflection of MSR reads and
7033writes to user space. It can be enabled on a VM level. If enabled, MSR
7034accesses that would usually trigger a #GP by KVM into the guest will
7035instead get bounced to user space through the KVM_EXIT_X86_RDMSR and
7036KVM_EXIT_X86_WRMSR exit notifications.
Alexander Graf1a1552542020-09-25 16:34:21 +02007037
Siddharth Chandrasekaran46a63922021-05-03 14:00:58 +020070388.27 KVM_CAP_X86_MSR_FILTER
Alexander Graf1a1552542020-09-25 16:34:21 +02007039---------------------------
7040
7041:Architectures: x86
7042
7043This capability indicates that KVM supports that accesses to user defined MSRs
7044may be rejected. With this capability exposed, KVM exports new VM ioctl
7045KVM_X86_SET_MSR_FILTER which user space can call to specify bitmaps of MSR
7046ranges that KVM should reject access to.
7047
7048In combination with KVM_CAP_X86_USER_SPACE_MSR, this allows user space to
7049trap and emulate MSRs that are outside of the scope of KVM as well as
7050limit the attack surface on KVM's MSR emulation code.
Oliver Upton66570e92020-08-18 15:24:28 +00007051
Peter Xu177158e2020-10-23 14:33:46 -040070528.28 KVM_CAP_ENFORCE_PV_CPUID
Oliver Upton66570e92020-08-18 15:24:28 +00007053-----------------------------
7054
7055Architectures: x86
7056
7057When enabled, KVM will disable paravirtual features provided to the
7058guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
7059(0x40000001). Otherwise, a guest may use the paravirtual features
7060regardless of what has actually been exposed through the CPUID leaf.
Peter Xufb04a1e2020-09-30 21:22:22 -04007061
Peter Xufb04a1e2020-09-30 21:22:22 -040070628.29 KVM_CAP_DIRTY_LOG_RING
7063---------------------------
7064
7065:Architectures: x86
7066:Parameters: args[0] - size of the dirty log ring
7067
7068KVM is capable of tracking dirty memory using ring buffers that are
7069mmaped into userspace; there is one dirty ring per vcpu.
7070
7071The dirty ring is available to userspace as an array of
7072``struct kvm_dirty_gfn``. Each dirty entry it's defined as::
7073
7074 struct kvm_dirty_gfn {
7075 __u32 flags;
7076 __u32 slot; /* as_id | slot_id */
7077 __u64 offset;
7078 };
7079
7080The following values are defined for the flags field to define the
7081current state of the entry::
7082
7083 #define KVM_DIRTY_GFN_F_DIRTY BIT(0)
7084 #define KVM_DIRTY_GFN_F_RESET BIT(1)
7085 #define KVM_DIRTY_GFN_F_MASK 0x3
7086
7087Userspace should call KVM_ENABLE_CAP ioctl right after KVM_CREATE_VM
7088ioctl to enable this capability for the new guest and set the size of
7089the rings. Enabling the capability is only allowed before creating any
7090vCPU, and the size of the ring must be a power of two. The larger the
7091ring buffer, the less likely the ring is full and the VM is forced to
7092exit to userspace. The optimal size depends on the workload, but it is
7093recommended that it be at least 64 KiB (4096 entries).
7094
7095Just like for dirty page bitmaps, the buffer tracks writes to
7096all user memory regions for which the KVM_MEM_LOG_DIRTY_PAGES flag was
7097set in KVM_SET_USER_MEMORY_REGION. Once a memory region is registered
7098with the flag set, userspace can start harvesting dirty pages from the
7099ring buffer.
7100
7101An entry in the ring buffer can be unused (flag bits ``00``),
7102dirty (flag bits ``01``) or harvested (flag bits ``1X``). The
7103state machine for the entry is as follows::
7104
7105 dirtied harvested reset
7106 00 -----------> 01 -------------> 1X -------+
7107 ^ |
7108 | |
7109 +------------------------------------------+
7110
7111To harvest the dirty pages, userspace accesses the mmaped ring buffer
7112to read the dirty GFNs. If the flags has the DIRTY bit set (at this stage
7113the RESET bit must be cleared), then it means this GFN is a dirty GFN.
7114The userspace should harvest this GFN and mark the flags from state
7115``01b`` to ``1Xb`` (bit 0 will be ignored by KVM, but bit 1 must be set
7116to show that this GFN is harvested and waiting for a reset), and move
7117on to the next GFN. The userspace should continue to do this until the
7118flags of a GFN have the DIRTY bit cleared, meaning that it has harvested
7119all the dirty GFNs that were available.
7120
7121It's not necessary for userspace to harvest the all dirty GFNs at once.
7122However it must collect the dirty GFNs in sequence, i.e., the userspace
7123program cannot skip one dirty GFN to collect the one next to it.
7124
7125After processing one or more entries in the ring buffer, userspace
7126calls the VM ioctl KVM_RESET_DIRTY_RINGS to notify the kernel about
7127it, so that the kernel will reprotect those collected GFNs.
7128Therefore, the ioctl must be called *before* reading the content of
7129the dirty pages.
7130
7131The dirty ring can get full. When it happens, the KVM_RUN of the
7132vcpu will return with exit reason KVM_EXIT_DIRTY_LOG_FULL.
7133
7134The dirty ring interface has a major difference comparing to the
7135KVM_GET_DIRTY_LOG interface in that, when reading the dirty ring from
7136userspace, it's still possible that the kernel has not yet flushed the
7137processor's dirty page buffers into the kernel buffer (with dirty bitmaps, the
7138flushing is done by the KVM_GET_DIRTY_LOG ioctl). To achieve that, one
7139needs to kick the vcpu out of KVM_RUN using a signal. The resulting
7140vmexit ensures that all dirty GFNs are flushed to the dirty rings.
Peter Xub2cc64c2020-09-30 21:22:24 -04007141
7142NOTE: the capability KVM_CAP_DIRTY_LOG_RING and the corresponding
7143ioctl KVM_RESET_DIRTY_RINGS are mutual exclusive to the existing ioctls
7144KVM_GET_DIRTY_LOG and KVM_CLEAR_DIRTY_LOG. After enabling
7145KVM_CAP_DIRTY_LOG_RING with an acceptable dirty ring size, the virtual
7146machine will switch to ring-buffer dirty page tracking and further
7147KVM_GET_DIRTY_LOG or KVM_CLEAR_DIRTY_LOG ioctls will fail.
David Woodhousee1f68162020-12-04 09:03:56 +00007148
71498.30 KVM_CAP_XEN_HVM
7150--------------------
7151
7152:Architectures: x86
7153
7154This capability indicates the features that Xen supports for hosting Xen
7155PVHVM guests. Valid flags are::
7156
7157 #define KVM_XEN_HVM_CONFIG_HYPERCALL_MSR (1 << 0)
7158 #define KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL (1 << 1)
7159 #define KVM_XEN_HVM_CONFIG_SHARED_INFO (1 << 2)
David Woodhouse30b5c852021-03-01 12:53:09 +00007160 #define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 2)
David Woodhousee1f68162020-12-04 09:03:56 +00007161
7162The KVM_XEN_HVM_CONFIG_HYPERCALL_MSR flag indicates that the KVM_XEN_HVM_CONFIG
7163ioctl is available, for the guest to set its hypercall page.
7164
7165If KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL is also set, the same flag may also be
7166provided in the flags to KVM_XEN_HVM_CONFIG, without providing hypercall page
7167contents, to request that KVM generate hypercall page content automatically
7168and also enable interception of guest hypercalls with KVM_EXIT_XEN.
7169
7170The KVM_XEN_HVM_CONFIG_SHARED_INFO flag indicates the availability of the
7171KVM_XEN_HVM_SET_ATTR, KVM_XEN_HVM_GET_ATTR, KVM_XEN_VCPU_SET_ATTR and
7172KVM_XEN_VCPU_GET_ATTR ioctls, as well as the delivery of exception vectors
7173for event channel upcalls when the evtchn_upcall_pending field of a vcpu's
7174vcpu_info is set.
David Woodhouse30b5c852021-03-01 12:53:09 +00007175
7176The KVM_XEN_HVM_CONFIG_RUNSTATE flag indicates that the runstate-related
7177features KVM_XEN_VCPU_ATTR_TYPE_RUNSTATE_ADDR/_CURRENT/_DATA/_ADJUST are
7178supported by the KVM_XEN_VCPU_SET_ATTR/KVM_XEN_VCPU_GET_ATTR ioctls.
Emanuele Giuseppe Esposito24e74752021-03-16 18:08:14 +01007179
71808.31 KVM_CAP_PPC_MULTITCE
7181-------------------------
7182
7183:Capability: KVM_CAP_PPC_MULTITCE
7184:Architectures: ppc
7185:Type: vm
7186
7187This capability means the kernel is capable of handling hypercalls
7188H_PUT_TCE_INDIRECT and H_STUFF_TCE without passing those into the user
7189space. This significantly accelerates DMA operations for PPC KVM guests.
7190User space should expect that its handlers for these hypercalls
7191are not going to be called if user space previously registered LIOBN
7192in KVM (via KVM_CREATE_SPAPR_TCE or similar calls).
7193
7194In order to enable H_PUT_TCE_INDIRECT and H_STUFF_TCE use in the guest,
7195user space might have to advertise it for the guest. For example,
7196IBM pSeries (sPAPR) guest starts using them if "hcall-multi-tce" is
7197present in the "ibm,hypertas-functions" device-tree property.
7198
7199The hypercalls mentioned above may or may not be processed successfully
7200in the kernel based fast path. If they can not be handled by the kernel,
7201they will get passed on to user space. So user space still has to have
7202an implementation for these despite the in kernel acceleration.
7203
Nathan Tempelman54526d12021-04-08 22:32:14 +00007204This capability is always enabled.
Paolo Bonzinic4f71902021-04-23 07:41:17 -04007205
72068.32 KVM_CAP_PTP_KVM
Jianyong Wu3bf72562020-12-09 14:09:29 +08007207--------------------
7208
7209:Architectures: arm64
7210
7211This capability indicates that the KVM virtual PTP service is
7212supported in the host. A VMM can check whether the service is
7213available to the guest on migration.
Vitaly Kuznetsov644f7062021-05-21 11:51:36 +02007214
72158.33 KVM_CAP_HYPERV_ENFORCE_CPUID
7216-----------------------------
7217
7218Architectures: x86
7219
7220When enabled, KVM will disable emulated Hyper-V features provided to the
7221guest according to the bits Hyper-V CPUID feature leaves. Otherwise, all
7222currently implmented Hyper-V features are provided unconditionally when
7223Hyper-V identification is set in the HYPERV_CPUID_INTERFACE (0x40000001)
7224leaf.
Ashish Kalra0dbb1122021-06-08 18:05:43 +00007225
72268.34 KVM_CAP_EXIT_HYPERCALL
7227---------------------------
7228
7229:Capability: KVM_CAP_EXIT_HYPERCALL
7230:Architectures: x86
7231:Type: vm
7232
7233This capability, if enabled, will cause KVM to exit to userspace
7234with KVM_EXIT_HYPERCALL exit reason to process some hypercalls.
7235
7236Calling KVM_CHECK_EXTENSION for this capability will return a bitmask
7237of hypercalls that can be configured to exit to userspace.
7238Right now, the only such hypercall is KVM_HC_MAP_GPA_RANGE.
7239
7240The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset
7241of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace
7242the hypercalls whose corresponding bit is in the argument, and return
7243ENOSYS for the others.