xref: /OK3568_Linux_fs/kernel/Documentation/virt/kvm/devices/vm.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun====================
4*4882a593SmuzhiyunGeneric vm interface
5*4882a593Smuzhiyun====================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe virtual machine "device" also accepts the ioctls KVM_SET_DEVICE_ATTR,
8*4882a593SmuzhiyunKVM_GET_DEVICE_ATTR, and KVM_HAS_DEVICE_ATTR. The interface uses the same
9*4882a593Smuzhiyunstruct kvm_device_attr as other devices, but targets VM-wide settings
10*4882a593Smuzhiyunand controls.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunThe groups and attributes per virtual machine, if any, are architecture
13*4882a593Smuzhiyunspecific.
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun1. GROUP: KVM_S390_VM_MEM_CTRL
16*4882a593Smuzhiyun==============================
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun:Architectures: s390
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun1.1. ATTRIBUTE: KVM_S390_VM_MEM_ENABLE_CMMA
21*4882a593Smuzhiyun-------------------------------------------
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun:Parameters: none
24*4882a593Smuzhiyun:Returns: -EBUSY if a vcpu is already defined, otherwise 0
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunEnables Collaborative Memory Management Assist (CMMA) for the virtual machine.
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun1.2. ATTRIBUTE: KVM_S390_VM_MEM_CLR_CMMA
29*4882a593Smuzhiyun----------------------------------------
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun:Parameters: none
32*4882a593Smuzhiyun:Returns: -EINVAL if CMMA was not enabled;
33*4882a593Smuzhiyun	  0 otherwise
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunClear the CMMA status for all guest pages, so any pages the guest marked
36*4882a593Smuzhiyunas unused are again used any may not be reclaimed by the host.
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun1.3. ATTRIBUTE KVM_S390_VM_MEM_LIMIT_SIZE
39*4882a593Smuzhiyun-----------------------------------------
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun:Parameters: in attr->addr the address for the new limit of guest memory
42*4882a593Smuzhiyun:Returns: -EFAULT if the given address is not accessible;
43*4882a593Smuzhiyun	  -EINVAL if the virtual machine is of type UCONTROL;
44*4882a593Smuzhiyun	  -E2BIG if the given guest memory is to big for that machine;
45*4882a593Smuzhiyun	  -EBUSY if a vcpu is already defined;
46*4882a593Smuzhiyun	  -ENOMEM if not enough memory is available for a new shadow guest mapping;
47*4882a593Smuzhiyun	  0 otherwise.
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunAllows userspace to query the actual limit and set a new limit for
50*4882a593Smuzhiyunthe maximum guest memory size. The limit will be rounded up to
51*4882a593Smuzhiyun2048 MB, 4096 GB, 8192 TB respectively, as this limit is governed by
52*4882a593Smuzhiyunthe number of page table levels. In the case that there is no limit we will set
53*4882a593Smuzhiyunthe limit to KVM_S390_NO_MEM_LIMIT (U64_MAX).
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun2. GROUP: KVM_S390_VM_CPU_MODEL
56*4882a593Smuzhiyun===============================
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun:Architectures: s390
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun2.1. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE (r/o)
61*4882a593Smuzhiyun---------------------------------------------
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunAllows user space to retrieve machine and kvm specific cpu related information::
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun  struct kvm_s390_vm_cpu_machine {
66*4882a593Smuzhiyun       __u64 cpuid;           # CPUID of host
67*4882a593Smuzhiyun       __u32 ibc;             # IBC level range offered by host
68*4882a593Smuzhiyun       __u8  pad[4];
69*4882a593Smuzhiyun       __u64 fac_mask[256];   # set of cpu facilities enabled by KVM
70*4882a593Smuzhiyun       __u64 fac_list[256];   # set of cpu facilities offered by host
71*4882a593Smuzhiyun  }
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun:Parameters: address of buffer to store the machine related cpu data
74*4882a593Smuzhiyun	     of type struct kvm_s390_vm_cpu_machine*
75*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
76*4882a593Smuzhiyun	    -ENOMEM if not enough memory is available to process the ioctl;
77*4882a593Smuzhiyun	    0 in case of success.
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun2.2. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR (r/w)
80*4882a593Smuzhiyun===============================================
81*4882a593Smuzhiyun
82*4882a593SmuzhiyunAllows user space to retrieve or request to change cpu related information for a vcpu::
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun  struct kvm_s390_vm_cpu_processor {
85*4882a593Smuzhiyun       __u64 cpuid;           # CPUID currently (to be) used by this vcpu
86*4882a593Smuzhiyun       __u16 ibc;             # IBC level currently (to be) used by this vcpu
87*4882a593Smuzhiyun       __u8  pad[6];
88*4882a593Smuzhiyun       __u64 fac_list[256];   # set of cpu facilities currently (to be) used
89*4882a593Smuzhiyun			      # by this vcpu
90*4882a593Smuzhiyun  }
91*4882a593Smuzhiyun
92*4882a593SmuzhiyunKVM does not enforce or limit the cpu model data in any form. Take the information
93*4882a593Smuzhiyunretrieved by means of KVM_S390_VM_CPU_MACHINE as hint for reasonable configuration
94*4882a593Smuzhiyunsetups. Instruction interceptions triggered by additionally set facility bits that
95*4882a593Smuzhiyunare not handled by KVM need to by imlemented in the VM driver code.
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun:Parameters: address of buffer to store/set the processor related cpu
98*4882a593Smuzhiyun	     data of type struct kvm_s390_vm_cpu_processor*.
99*4882a593Smuzhiyun:Returns:  -EBUSY in case 1 or more vcpus are already activated (only in write case);
100*4882a593Smuzhiyun	   -EFAULT if the given address is not accessible from kernel space;
101*4882a593Smuzhiyun	   -ENOMEM if not enough memory is available to process the ioctl;
102*4882a593Smuzhiyun	   0 in case of success.
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun.. _KVM_S390_VM_CPU_MACHINE_FEAT:
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun2.3. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_FEAT (r/o)
107*4882a593Smuzhiyun--------------------------------------------------
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunAllows user space to retrieve available cpu features. A feature is available if
110*4882a593Smuzhiyunprovided by the hardware and supported by kvm. In theory, cpu features could
111*4882a593Smuzhiyuneven be completely emulated by kvm.
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun::
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun  struct kvm_s390_vm_cpu_feat {
116*4882a593Smuzhiyun	__u64 feat[16]; # Bitmap (1 = feature available), MSB 0 bit numbering
117*4882a593Smuzhiyun  };
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun:Parameters: address of a buffer to load the feature list from.
120*4882a593Smuzhiyun:Returns:  -EFAULT if the given address is not accessible from kernel space;
121*4882a593Smuzhiyun	   0 in case of success.
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun2.4. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_FEAT (r/w)
124*4882a593Smuzhiyun----------------------------------------------------
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunAllows user space to retrieve or change enabled cpu features for all VCPUs of a
127*4882a593SmuzhiyunVM. Features that are not available cannot be enabled.
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunSee :ref:`KVM_S390_VM_CPU_MACHINE_FEAT` for
130*4882a593Smuzhiyuna description of the parameter struct.
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun:Parameters: address of a buffer to store/load the feature list from.
133*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
134*4882a593Smuzhiyun	    -EINVAL if a cpu feature that is not available is to be enabled;
135*4882a593Smuzhiyun	    -EBUSY if at least one VCPU has already been defined;
136*4882a593Smuzhiyun	    0 in case of success.
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun.. _KVM_S390_VM_CPU_MACHINE_SUBFUNC:
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun2.5. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_SUBFUNC (r/o)
141*4882a593Smuzhiyun-----------------------------------------------------
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunAllows user space to retrieve available cpu subfunctions without any filtering
144*4882a593Smuzhiyundone by a set IBC. These subfunctions are indicated to the guest VCPU via
145*4882a593Smuzhiyunquery or "test bit" subfunctions and used e.g. by cpacf functions, plo and ptff.
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunA subfunction block is only valid if KVM_S390_VM_CPU_MACHINE contains the
148*4882a593SmuzhiyunSTFL(E) bit introducing the affected instruction. If the affected instruction
149*4882a593Smuzhiyunindicates subfunctions via a "query subfunction", the response block is
150*4882a593Smuzhiyuncontained in the returned struct. If the affected instruction
151*4882a593Smuzhiyunindicates subfunctions via a "test bit" mechanism, the subfunction codes are
152*4882a593Smuzhiyuncontained in the returned struct in MSB 0 bit numbering.
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun::
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun  struct kvm_s390_vm_cpu_subfunc {
157*4882a593Smuzhiyun       u8 plo[32];           # always valid (ESA/390 feature)
158*4882a593Smuzhiyun       u8 ptff[16];          # valid with TOD-clock steering
159*4882a593Smuzhiyun       u8 kmac[16];          # valid with Message-Security-Assist
160*4882a593Smuzhiyun       u8 kmc[16];           # valid with Message-Security-Assist
161*4882a593Smuzhiyun       u8 km[16];            # valid with Message-Security-Assist
162*4882a593Smuzhiyun       u8 kimd[16];          # valid with Message-Security-Assist
163*4882a593Smuzhiyun       u8 klmd[16];          # valid with Message-Security-Assist
164*4882a593Smuzhiyun       u8 pckmo[16];         # valid with Message-Security-Assist-Extension 3
165*4882a593Smuzhiyun       u8 kmctr[16];         # valid with Message-Security-Assist-Extension 4
166*4882a593Smuzhiyun       u8 kmf[16];           # valid with Message-Security-Assist-Extension 4
167*4882a593Smuzhiyun       u8 kmo[16];           # valid with Message-Security-Assist-Extension 4
168*4882a593Smuzhiyun       u8 pcc[16];           # valid with Message-Security-Assist-Extension 4
169*4882a593Smuzhiyun       u8 ppno[16];          # valid with Message-Security-Assist-Extension 5
170*4882a593Smuzhiyun       u8 kma[16];           # valid with Message-Security-Assist-Extension 8
171*4882a593Smuzhiyun       u8 kdsa[16];          # valid with Message-Security-Assist-Extension 9
172*4882a593Smuzhiyun       u8 reserved[1792];    # reserved for future instructions
173*4882a593Smuzhiyun  };
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun:Parameters: address of a buffer to load the subfunction blocks from.
176*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
177*4882a593Smuzhiyun	    0 in case of success.
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun2.6. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_SUBFUNC (r/w)
180*4882a593Smuzhiyun-------------------------------------------------------
181*4882a593Smuzhiyun
182*4882a593SmuzhiyunAllows user space to retrieve or change cpu subfunctions to be indicated for
183*4882a593Smuzhiyunall VCPUs of a VM. This attribute will only be available if kernel and
184*4882a593Smuzhiyunhardware support are in place.
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunThe kernel uses the configured subfunction blocks for indication to
187*4882a593Smuzhiyunthe guest. A subfunction block will only be used if the associated STFL(E) bit
188*4882a593Smuzhiyunhas not been disabled by user space (so the instruction to be queried is
189*4882a593Smuzhiyunactually available for the guest).
190*4882a593Smuzhiyun
191*4882a593SmuzhiyunAs long as no data has been written, a read will fail. The IBC will be used
192*4882a593Smuzhiyunto determine available subfunctions in this case, this will guarantee backward
193*4882a593Smuzhiyuncompatibility.
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunSee :ref:`KVM_S390_VM_CPU_MACHINE_SUBFUNC` for a
196*4882a593Smuzhiyundescription of the parameter struct.
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun:Parameters: address of a buffer to store/load the subfunction blocks from.
199*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
200*4882a593Smuzhiyun	    -EINVAL when reading, if there was no write yet;
201*4882a593Smuzhiyun	    -EBUSY if at least one VCPU has already been defined;
202*4882a593Smuzhiyun	    0 in case of success.
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun3. GROUP: KVM_S390_VM_TOD
205*4882a593Smuzhiyun=========================
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun:Architectures: s390
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun3.1. ATTRIBUTE: KVM_S390_VM_TOD_HIGH
210*4882a593Smuzhiyun------------------------------------
211*4882a593Smuzhiyun
212*4882a593SmuzhiyunAllows user space to set/get the TOD clock extension (u8) (superseded by
213*4882a593SmuzhiyunKVM_S390_VM_TOD_EXT).
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun:Parameters: address of a buffer in user space to store the data (u8) to
216*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
217*4882a593Smuzhiyun	    -EINVAL if setting the TOD clock extension to != 0 is not supported
218*4882a593Smuzhiyun	    -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun3.2. ATTRIBUTE: KVM_S390_VM_TOD_LOW
221*4882a593Smuzhiyun-----------------------------------
222*4882a593Smuzhiyun
223*4882a593SmuzhiyunAllows user space to set/get bits 0-63 of the TOD clock register as defined in
224*4882a593Smuzhiyunthe POP (u64).
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun:Parameters: address of a buffer in user space to store the data (u64) to
227*4882a593Smuzhiyun:Returns:    -EFAULT if the given address is not accessible from kernel space
228*4882a593Smuzhiyun	     -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun3.3. ATTRIBUTE: KVM_S390_VM_TOD_EXT
231*4882a593Smuzhiyun-----------------------------------
232*4882a593Smuzhiyun
233*4882a593SmuzhiyunAllows user space to set/get bits 0-63 of the TOD clock register as defined in
234*4882a593Smuzhiyunthe POP (u64). If the guest CPU model supports the TOD clock extension (u8), it
235*4882a593Smuzhiyunalso allows user space to get/set it. If the guest CPU model does not support
236*4882a593Smuzhiyunit, it is stored as 0 and not allowed to be set to a value != 0.
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun:Parameters: address of a buffer in user space to store the data
239*4882a593Smuzhiyun	     (kvm_s390_vm_tod_clock) to
240*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
241*4882a593Smuzhiyun	    -EINVAL if setting the TOD clock extension to != 0 is not supported
242*4882a593Smuzhiyun	    -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun4. GROUP: KVM_S390_VM_CRYPTO
245*4882a593Smuzhiyun============================
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun:Architectures: s390
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun4.1. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_AES_KW (w/o)
250*4882a593Smuzhiyun------------------------------------------------------
251*4882a593Smuzhiyun
252*4882a593SmuzhiyunAllows user space to enable aes key wrapping, including generating a new
253*4882a593Smuzhiyunwrapping key.
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun:Parameters: none
256*4882a593Smuzhiyun:Returns:    0
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun4.2. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_DEA_KW (w/o)
259*4882a593Smuzhiyun------------------------------------------------------
260*4882a593Smuzhiyun
261*4882a593SmuzhiyunAllows user space to enable dea key wrapping, including generating a new
262*4882a593Smuzhiyunwrapping key.
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun:Parameters: none
265*4882a593Smuzhiyun:Returns:    0
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun4.3. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_AES_KW (w/o)
268*4882a593Smuzhiyun-------------------------------------------------------
269*4882a593Smuzhiyun
270*4882a593SmuzhiyunAllows user space to disable aes key wrapping, clearing the wrapping key.
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun:Parameters: none
273*4882a593Smuzhiyun:Returns:    0
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun4.4. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_DEA_KW (w/o)
276*4882a593Smuzhiyun-------------------------------------------------------
277*4882a593Smuzhiyun
278*4882a593SmuzhiyunAllows user space to disable dea key wrapping, clearing the wrapping key.
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun:Parameters: none
281*4882a593Smuzhiyun:Returns:    0
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun5. GROUP: KVM_S390_VM_MIGRATION
284*4882a593Smuzhiyun===============================
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun:Architectures: s390
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun5.1. ATTRIBUTE: KVM_S390_VM_MIGRATION_STOP (w/o)
289*4882a593Smuzhiyun------------------------------------------------
290*4882a593Smuzhiyun
291*4882a593SmuzhiyunAllows userspace to stop migration mode, needed for PGSTE migration.
292*4882a593SmuzhiyunSetting this attribute when migration mode is not active will have no
293*4882a593Smuzhiyuneffects.
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun:Parameters: none
296*4882a593Smuzhiyun:Returns:    0
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun5.2. ATTRIBUTE: KVM_S390_VM_MIGRATION_START (w/o)
299*4882a593Smuzhiyun-------------------------------------------------
300*4882a593Smuzhiyun
301*4882a593SmuzhiyunAllows userspace to start migration mode, needed for PGSTE migration.
302*4882a593SmuzhiyunSetting this attribute when migration mode is already active will have
303*4882a593Smuzhiyunno effects.
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun:Parameters: none
306*4882a593Smuzhiyun:Returns:   -ENOMEM if there is not enough free memory to start migration mode;
307*4882a593Smuzhiyun	    -EINVAL if the state of the VM is invalid (e.g. no memory defined);
308*4882a593Smuzhiyun	    0 in case of success.
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun5.3. ATTRIBUTE: KVM_S390_VM_MIGRATION_STATUS (r/o)
311*4882a593Smuzhiyun--------------------------------------------------
312*4882a593Smuzhiyun
313*4882a593SmuzhiyunAllows userspace to query the status of migration mode.
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun:Parameters: address of a buffer in user space to store the data (u64) to;
316*4882a593Smuzhiyun	     the data itself is either 0 if migration mode is disabled or 1
317*4882a593Smuzhiyun	     if it is enabled
318*4882a593Smuzhiyun:Returns:   -EFAULT if the given address is not accessible from kernel space;
319*4882a593Smuzhiyun	    0 in case of success.
320