← Documents Documentation/virt/kvm/devices/vm.rst GitHub 원문 ↗

Linux 6.18.37 · 가상화 / KVM / Device

Generic VM device interface

s390 memory·CPU model·TOD·crypto·migration과 arm64 SMCCC filter를 다루는 VM-wide device ABI입니다.

Source pathDocumentation/virt/kvm/devices/vm.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

vm.rst:1-402

s390 memory·CPU model·TOD·crypto·migration과 arm64 SMCCC filter를 다루는 VM-wide device ABI입니다.

구조체, register field, priority, error code와 migration 순서는 원문 표기를 유지했습니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ====================
4 Generic vm interface
5 ====================
6
7 The virtual machine "device" also accepts the ioctls KVM_SET_DEVICE_ATTR,
8 KVM_GET_DEVICE_ATTR, and KVM_HAS_DEVICE_ATTR. The interface uses the same
9 struct kvm_device_attr as other devices, but targets VM-wide settings
10 and controls.
11
12 The groups and attributes per virtual machine, if any, are architecture
13 specific.
14
15 1. GROUP: KVM_S390_VM_MEM_CTRL
16 ==============================
17
18 :Architectures: s390
19
20 1.1. ATTRIBUTE: KVM_S390_VM_MEM_ENABLE_CMMA
21 -------------------------------------------
22
23 :Parameters: none
24 :Returns: -EBUSY if a vcpu is already defined, otherwise 0
25
26 Enables Collaborative Memory Management Assist (CMMA) for the virtual machine.
27
28 1.2. ATTRIBUTE: KVM_S390_VM_MEM_CLR_CMMA
29 ----------------------------------------
30
31 :Parameters: none
32 :Returns: -EINVAL if CMMA was not enabled;
33 0 otherwise
34
35 Clear the CMMA status for all guest pages, so any pages the guest marked
36 as unused are again used any may not be reclaimed by the host.
37
38 1.3. ATTRIBUTE KVM_S390_VM_MEM_LIMIT_SIZE
39 -----------------------------------------
40
41 :Parameters: in attr->addr the address for the new limit of guest memory
42 :Returns: -EFAULT if the given address is not accessible;
43 -EINVAL if the virtual machine is of type UCONTROL;
44 -E2BIG if the given guest memory is to big for that machine;
45 -EBUSY if a vcpu is already defined;
46 -ENOMEM if not enough memory is available for a new shadow guest mapping;
47 0 otherwise.
48
49 Allows userspace to query the actual limit and set a new limit for
50 the maximum guest memory size. The limit will be rounded up to
51 2048 MB, 4096 GB, 8192 TB respectively, as this limit is governed by
52 the number of page table levels. In the case that there is no limit we will set
53 the limit to KVM_S390_NO_MEM_LIMIT (U64_MAX).
54
55 2. GROUP: KVM_S390_VM_CPU_MODEL
56 ===============================
57
58 :Architectures: s390
59
60 2.1. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE (r/o)
61 ---------------------------------------------
62
63 Allows user space to retrieve machine and kvm specific cpu related information::
64
65 struct kvm_s390_vm_cpu_machine {
66 __u64 cpuid; # CPUID of host
67 __u32 ibc; # IBC level range offered by host
68 __u8 pad[4];
69 __u64 fac_mask[256]; # set of cpu facilities enabled by KVM
70 __u64 fac_list[256]; # set of cpu facilities offered by host
71 }
72
73 :Parameters: address of buffer to store the machine related cpu data
74 of type struct kvm_s390_vm_cpu_machine*
75 :Returns: -EFAULT if the given address is not accessible from kernel space;
76 -ENOMEM if not enough memory is available to process the ioctl;
77 0 in case of success.
78
79 2.2. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR (r/w)
80 ===============================================
81
82 Allows user space to retrieve or request to change cpu related information for a vcpu::
83
84 struct kvm_s390_vm_cpu_processor {
85 __u64 cpuid; # CPUID currently (to be) used by this vcpu
86 __u16 ibc; # IBC level currently (to be) used by this vcpu
87 __u8 pad[6];
88 __u64 fac_list[256]; # set of cpu facilities currently (to be) used
89 # by this vcpu
90 }
91
92 KVM does not enforce or limit the cpu model data in any form. Take the information
93 retrieved by means of KVM_S390_VM_CPU_MACHINE as hint for reasonable configuration
94 setups. Instruction interceptions triggered by additionally set facility bits that
95 are not handled by KVM need to by implemented in the VM driver code.
96
97 :Parameters: address of buffer to store/set the processor related cpu
98 data of type struct kvm_s390_vm_cpu_processor*.
99 :Returns: -EBUSY in case 1 or more vcpus are already activated (only in write case);
100 -EFAULT if the given address is not accessible from kernel space;
101 -ENOMEM if not enough memory is available to process the ioctl;
102 0 in case of success.
103
104 .. _KVM_S390_VM_CPU_MACHINE_FEAT:
105
106 2.3. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_FEAT (r/o)
107 --------------------------------------------------
108
109 Allows user space to retrieve available cpu features. A feature is available if
110 provided by the hardware and supported by kvm. In theory, cpu features could
111 even be completely emulated by kvm.
112
113 ::
114
115 struct kvm_s390_vm_cpu_feat {
116 __u64 feat[16]; # Bitmap (1 = feature available), MSB 0 bit numbering
117 };
118
119 :Parameters: address of a buffer to load the feature list from.
120 :Returns: -EFAULT if the given address is not accessible from kernel space;
121 0 in case of success.
122
123 2.4. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_FEAT (r/w)
124 ----------------------------------------------------
125
126 Allows user space to retrieve or change enabled cpu features for all VCPUs of a
127 VM. Features that are not available cannot be enabled.
128
129 See :ref:`KVM_S390_VM_CPU_MACHINE_FEAT` for
130 a description of the parameter struct.
131
132 :Parameters: address of a buffer to store/load the feature list from.
133 :Returns: -EFAULT if the given address is not accessible from kernel space;
134 -EINVAL if a cpu feature that is not available is to be enabled;
135 -EBUSY if at least one VCPU has already been defined;
136 0 in case of success.
137
138 .. _KVM_S390_VM_CPU_MACHINE_SUBFUNC:
139
140 2.5. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_SUBFUNC (r/o)
141 -----------------------------------------------------
142
143 Allows user space to retrieve available cpu subfunctions without any filtering
144 done by a set IBC. These subfunctions are indicated to the guest VCPU via
145 query or "test bit" subfunctions and used e.g. by cpacf functions, plo and ptff.
146
147 A subfunction block is only valid if KVM_S390_VM_CPU_MACHINE contains the
148 STFL(E) bit introducing the affected instruction. If the affected instruction
149 indicates subfunctions via a "query subfunction", the response block is
150 contained in the returned struct. If the affected instruction
151 indicates subfunctions via a "test bit" mechanism, the subfunction codes are
152 contained in the returned struct in MSB 0 bit numbering.
153
154 ::
155
156 struct kvm_s390_vm_cpu_subfunc {
157 u8 plo[32]; # always valid (ESA/390 feature)
158 u8 ptff[16]; # valid with TOD-clock steering
159 u8 kmac[16]; # valid with Message-Security-Assist
160 u8 kmc[16]; # valid with Message-Security-Assist
161 u8 km[16]; # valid with Message-Security-Assist
162 u8 kimd[16]; # valid with Message-Security-Assist
163 u8 klmd[16]; # valid with Message-Security-Assist
164 u8 pckmo[16]; # valid with Message-Security-Assist-Extension 3
165 u8 kmctr[16]; # valid with Message-Security-Assist-Extension 4
166 u8 kmf[16]; # valid with Message-Security-Assist-Extension 4
167 u8 kmo[16]; # valid with Message-Security-Assist-Extension 4
168 u8 pcc[16]; # valid with Message-Security-Assist-Extension 4
169 u8 ppno[16]; # valid with Message-Security-Assist-Extension 5
170 u8 kma[16]; # valid with Message-Security-Assist-Extension 8
171 u8 kdsa[16]; # valid with Message-Security-Assist-Extension 9
172 u8 reserved[1792]; # reserved for future instructions
173 };
174
175 :Parameters: address of a buffer to load the subfunction blocks from.
176 :Returns: -EFAULT if the given address is not accessible from kernel space;
177 0 in case of success.
178
179 2.6. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_SUBFUNC (r/w)
180 -------------------------------------------------------
181
182 Allows user space to retrieve or change cpu subfunctions to be indicated for
183 all VCPUs of a VM. This attribute will only be available if kernel and
184 hardware support are in place.
185
186 The kernel uses the configured subfunction blocks for indication to
187 the guest. A subfunction block will only be used if the associated STFL(E) bit
188 has not been disabled by user space (so the instruction to be queried is
189 actually available for the guest).
190
191 As long as no data has been written, a read will fail. The IBC will be used
192 to determine available subfunctions in this case, this will guarantee backward
193 compatibility.
194
195 See :ref:`KVM_S390_VM_CPU_MACHINE_SUBFUNC` for a
196 description of the parameter struct.
197
198 :Parameters: address of a buffer to store/load the subfunction blocks from.
199 :Returns: -EFAULT if the given address is not accessible from kernel space;
200 -EINVAL when reading, if there was no write yet;
201 -EBUSY if at least one VCPU has already been defined;
202 0 in case of success.
203
204 3. GROUP: KVM_S390_VM_TOD
205 =========================
206
207 :Architectures: s390
208
209 3.1. ATTRIBUTE: KVM_S390_VM_TOD_HIGH
210 ------------------------------------
211
212 Allows user space to set/get the TOD clock extension (u8) (superseded by
213 KVM_S390_VM_TOD_EXT).
214
215 :Parameters: address of a buffer in user space to store the data (u8) to
216 :Returns: -EFAULT if the given address is not accessible from kernel space;
217 -EINVAL if setting the TOD clock extension to != 0 is not supported
218 -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
219
220 3.2. ATTRIBUTE: KVM_S390_VM_TOD_LOW
221 -----------------------------------
222
223 Allows user space to set/get bits 0-63 of the TOD clock register as defined in
224 the POP (u64).
225
226 :Parameters: address of a buffer in user space to store the data (u64) to
227 :Returns: -EFAULT if the given address is not accessible from kernel space
228 -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
229
230 3.3. ATTRIBUTE: KVM_S390_VM_TOD_EXT
231 -----------------------------------
232
233 Allows user space to set/get bits 0-63 of the TOD clock register as defined in
234 the POP (u64). If the guest CPU model supports the TOD clock extension (u8), it
235 also allows user space to get/set it. If the guest CPU model does not support
236 it, it is stored as 0 and not allowed to be set to a value != 0.
237
238 :Parameters: address of a buffer in user space to store the data
239 (kvm_s390_vm_tod_clock) to
240 :Returns: -EFAULT if the given address is not accessible from kernel space;
241 -EINVAL if setting the TOD clock extension to != 0 is not supported
242 -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)
243
244 4. GROUP: KVM_S390_VM_CRYPTO
245 ============================
246
247 :Architectures: s390
248
249 4.1. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_AES_KW (w/o)
250 ------------------------------------------------------
251
252 Allows user space to enable aes key wrapping, including generating a new
253 wrapping key.
254
255 :Parameters: none
256 :Returns: 0
257
258 4.2. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_DEA_KW (w/o)
259 ------------------------------------------------------
260
261 Allows user space to enable dea key wrapping, including generating a new
262 wrapping key.
263
264 :Parameters: none
265 :Returns: 0
266
267 4.3. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_AES_KW (w/o)
268 -------------------------------------------------------
269
270 Allows user space to disable aes key wrapping, clearing the wrapping key.
271
272 :Parameters: none
273 :Returns: 0
274
275 4.4. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_DEA_KW (w/o)
276 -------------------------------------------------------
277
278 Allows user space to disable dea key wrapping, clearing the wrapping key.
279
280 :Parameters: none
281 :Returns: 0
282
283 5. GROUP: KVM_S390_VM_MIGRATION
284 ===============================
285
286 :Architectures: s390
287
288 5.1. ATTRIBUTE: KVM_S390_VM_MIGRATION_STOP (w/o)
289 ------------------------------------------------
290
291 Allows userspace to stop migration mode, needed for PGSTE migration.
292 Setting this attribute when migration mode is not active will have no
293 effects.
294
295 :Parameters: none
296 :Returns: 0
297
298 5.2. ATTRIBUTE: KVM_S390_VM_MIGRATION_START (w/o)
299 -------------------------------------------------
300
301 Allows userspace to start migration mode, needed for PGSTE migration.
302 Setting this attribute when migration mode is already active will have
303 no effects.
304
305 Dirty tracking must be enabled on all memslots, else -EINVAL is returned. When
306 dirty tracking is disabled on any memslot, migration mode is automatically
307 stopped.
308
309 :Parameters: none
310 :Returns: -ENOMEM if there is not enough free memory to start migration mode;
311 -EINVAL if the state of the VM is invalid (e.g. no memory defined);
312 0 in case of success.
313
314 5.3. ATTRIBUTE: KVM_S390_VM_MIGRATION_STATUS (r/o)
315 --------------------------------------------------
316
317 Allows userspace to query the status of migration mode.
318
319 :Parameters: address of a buffer in user space to store the data (u64) to;
320 the data itself is either 0 if migration mode is disabled or 1
321 if it is enabled
322 :Returns: -EFAULT if the given address is not accessible from kernel space;
323 0 in case of success.
324
325 6. GROUP: KVM_ARM_VM_SMCCC_CTRL
326 ===============================
327
328 :Architectures: arm64
329
330 6.1. ATTRIBUTE: KVM_ARM_VM_SMCCC_FILTER (w/o)
331 ---------------------------------------------
332
333 :Parameters: Pointer to a ``struct kvm_smccc_filter``
334
335 :Returns:
336
337 ====== ===========================================
338 EEXIST Range intersects with a previously inserted
339 or reserved range
340 EBUSY A vCPU in the VM has already run
341 EINVAL Invalid filter configuration
342 ENOMEM Failed to allocate memory for the in-kernel
343 representation of the SMCCC filter
344 ====== ===========================================
345
346 Requests the installation of an SMCCC call filter described as follows::
347
348 enum kvm_smccc_filter_action {
349 KVM_SMCCC_FILTER_HANDLE = 0,
350 KVM_SMCCC_FILTER_DENY,
351 KVM_SMCCC_FILTER_FWD_TO_USER,
352 };
353
354 struct kvm_smccc_filter {
355 __u32 base;
356 __u32 nr_functions;
357 __u8 action;
358 __u8 pad[15];
359 };
360
361 The filter is defined as a set of non-overlapping ranges. Each
362 range defines an action to be applied to SMCCC calls within the range.
363 Userspace can insert multiple ranges into the filter by using
364 successive calls to this attribute.
365
366 The default configuration of KVM is such that all implemented SMCCC
367 calls are allowed. Thus, the SMCCC filter can be defined sparsely
368 by userspace, only describing ranges that modify the default behavior.
369
370 The range expressed by ``struct kvm_smccc_filter`` is
371 [``base``, ``base + nr_functions``). The range is not allowed to wrap,
372 i.e. userspace cannot rely on ``base + nr_functions`` overflowing.
373
374 The SMCCC filter applies to both SMC and HVC calls initiated by the
375 guest. The SMCCC filter gates the in-kernel emulation of SMCCC calls
376 and as such takes effect before other interfaces that interact with
377 SMCCC calls (e.g. hypercall bitmap registers).
378
379 Actions:
380
381 - ``KVM_SMCCC_FILTER_HANDLE``: Allows the guest SMCCC call to be
382 handled in-kernel. It is strongly recommended that userspace *not*
383 explicitly describe the allowed SMCCC call ranges.
384
385 - ``KVM_SMCCC_FILTER_DENY``: Rejects the guest SMCCC call in-kernel
386 and returns to the guest.
387
388 - ``KVM_SMCCC_FILTER_FWD_TO_USER``: The guest SMCCC call is forwarded
389 to userspace with an exit reason of ``KVM_EXIT_HYPERCALL``.
390
391 The ``pad`` field is reserved for future use and must be zero. KVM may
392 return ``-EINVAL`` if the field is nonzero.
393
394 KVM reserves the 'Arm Architecture Calls' range of function IDs and
395 will reject attempts to define a filter for any portion of these ranges:
396
397 =========== ===============
398 Start End (inclusive)
399 =========== ===============
400 0x8000_0000 0x8000_FFFF
401 0xC000_0000 0xC000_FFFF
402 =========== ===============
403

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

s390 VM memory control

1-54

Virtual machine device도 `struct kvm_device_attr`으로 `KVM_SET_DEVICE_ATTR`, `KVM_GET_DEVICE_ATTR`, `KVM_HAS_DEVICE_ATTR`을 받으며 VM 전체의 architecture-specific 설정을 제어합니다.

s390 memory-control attribute
Attribute동작·오류
`KVM_S390_VM_MEM_ENABLE_CMMA`Collaborative Memory Management Assist enable. vCPU가 이미 정의됐으면 `-EBUSY`
`KVM_S390_VM_MEM_CLR_CMMA`모든 guest page의 CMMA status clear. CMMA 미활성은 `-EINVAL`
`KVM_S390_VM_MEM_LIMIT_SIZE`최대 guest memory 실제 limit 조회·설정. 새 shadow guest mapping에 memory가 부족하면 `-ENOMEM`

CMMA와 최대 guest memory size를 관리합니다.

CMMA status를 clear하면 guest가 unused로 표시했던 page도 다시 used 상태가 되어 host가 reclaim할 수 없게 됩니다.

Memory limit은 page-table level에 따라 각각 2048MiB, 4096GiB, 8192TiB 경계로 올림됩니다. 제한이 없으면 `KVM_S390_NO_MEM_LIMIT (U64_MAX)`입니다.

MEM_LIMIT_SIZE는 inaccessible pointer에 `-EFAULT`, UCONTROL VM에 `-EINVAL`, machine 범위를 넘는 memory에 `-E2BIG`, vCPU 정의 뒤 `-EBUSY`를 반환합니다.

.. SPDX-License-Identifier: GPL-2.0

====================
Generic vm interface
====================

The virtual machine "device" also accepts the ioctls KVM_SET_DEVICE_ATTR,
KVM_GET_DEVICE_ATTR, and KVM_HAS_DEVICE_ATTR. The interface uses the same
struct kvm_device_attr as other devices, but targets VM-wide settings
and controls.

The groups and attributes per virtual machine, if any, are architecture
specific.

1. GROUP: KVM_S390_VM_MEM_CTRL
==============================

:Architectures: s390

1.1. ATTRIBUTE: KVM_S390_VM_MEM_ENABLE_CMMA
-------------------------------------------

:Parameters: none
:Returns: -EBUSY if a vcpu is already defined, otherwise 0

Enables Collaborative Memory Management Assist (CMMA) for the virtual machine.

1.2. ATTRIBUTE: KVM_S390_VM_MEM_CLR_CMMA
----------------------------------------

:Parameters: none
:Returns: -EINVAL if CMMA was not enabled;
	  0 otherwise

Clear the CMMA status for all guest pages, so any pages the guest marked
as unused are again used any may not be reclaimed by the host.

1.3. ATTRIBUTE KVM_S390_VM_MEM_LIMIT_SIZE
-----------------------------------------

:Parameters: in attr->addr the address for the new limit of guest memory
:Returns: -EFAULT if the given address is not accessible;
	  -EINVAL if the virtual machine is of type UCONTROL;
	  -E2BIG if the given guest memory is to big for that machine;
	  -EBUSY if a vcpu is already defined;
	  -ENOMEM if not enough memory is available for a new shadow guest mapping;
	  0 otherwise.

Allows userspace to query the actual limit and set a new limit for
the maximum guest memory size. The limit will be rounded up to
2048 MB, 4096 GB, 8192 TB respectively, as this limit is governed by
the number of page table levels. In the case that there is no limit we will set
the limit to KVM_S390_NO_MEM_LIMIT (U64_MAX).

s390 VM CPU model과 subfunction

55-203

`KVM_S390_VM_CPU_MACHINE`은 host CPUID, 제공 IBC level range, KVM이 enable한 facility mask와 host가 제공한 facility list를 read-only로 반환합니다. CPU model을 구성할 때 합리적 상한을 정하는 참고값입니다.

s390 CPU model attribute
Attribute내용
`KVM_S390_VM_CPU_MACHINE`Host `cpuid`, `ibc`, `fac_mask[256]`, `fac_list[256]` read-only
`KVM_S390_VM_CPU_PROCESSOR`VM vCPU가 사용할 `cpuid`, `ibc`, `fac_list[256]` read/write
`KVM_S390_VM_CPU_MACHINE_FEAT`Hardware와 KVM이 함께 지원하는 feature의 MSB0 `feat[16]` bitmap
`KVM_S390_VM_CPU_PROCESSOR_FEAT`모든 VM vCPU에 enable할 feature bitmap read/write

Machine capability와 VM에 선택한 processor state를 구분합니다.

KVM은 `CPU_PROCESSOR`의 CPU model data를 강제 제한하지 않습니다. `CPU_MACHINE`을 참고하되 KVM이 처리하지 못하는 추가 facility bit로 생기는 instruction interception은 VM driver가 구현해야 합니다. Write는 vCPU가 activate되기 전이어야 하며 그렇지 않으면 `-EBUSY`입니다.

PROCESSOR_FEAT로 available하지 않은 feature를 enable하면 `-EINVAL`, vCPU가 하나라도 정의된 뒤 변경하면 `-EBUSY`입니다.

`KVM_S390_VM_CPU_MACHINE_SUBFUNC`은 IBC filtering 전의 available CPU subfunction을 반환합니다. Associated instruction을 도입하는 STFL(E) bit가 `CPU_MACHINE`에 있을 때만 해당 block이 유효합니다.

s390 subfunction block
Field크기·조건
`plo`32 byte, ESA/390 feature라 항상 유효
`ptff`16 byte, TOD-clock steering
`kmac`, `kmc`, `km`, `kimd`, `klmd`각 16 byte, Message-Security-Assist
`pckmo`16 byte, MSA Extension 3
`kmctr`, `kmf`, `kmo`, `pcc`각 16 byte, MSA Extension 4
`ppno`16 byte, MSA Extension 5
`kma`16 byte, MSA Extension 8
`kdsa`16 byte, MSA Extension 9
`reserved`미래 instruction용 1792 byte

Query 또는 test-bit 방식 instruction의 subfunction state입니다.

`KVM_S390_VM_CPU_PROCESSOR_SUBFUNC`은 모든 vCPU에 보일 subfunction block을 설정합니다. 관련 STFL(E) bit가 userspace에 의해 disable되면 해당 block은 사용하지 않습니다.

PROCESSOR_SUBFUNC에 한 번도 쓰지 않은 상태에서 read하면 `-EINVAL`입니다. 이 경우 IBC로 available subfunction을 결정하는 기존 동작이 backward compatibility를 보장합니다. vCPU 정의 뒤 write는 `-EBUSY`입니다.

2. GROUP: KVM_S390_VM_CPU_MODEL
===============================

:Architectures: s390

2.1. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE (r/o)
---------------------------------------------

Allows user space to retrieve machine and kvm specific cpu related information::

  struct kvm_s390_vm_cpu_machine {
       __u64 cpuid;           # CPUID of host
       __u32 ibc;             # IBC level range offered by host
       __u8  pad[4];
       __u64 fac_mask[256];   # set of cpu facilities enabled by KVM
       __u64 fac_list[256];   # set of cpu facilities offered by host
  }

:Parameters: address of buffer to store the machine related cpu data
	     of type struct kvm_s390_vm_cpu_machine*
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    -ENOMEM if not enough memory is available to process the ioctl;
	    0 in case of success.

2.2. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR (r/w)
===============================================

Allows user space to retrieve or request to change cpu related information for a vcpu::

  struct kvm_s390_vm_cpu_processor {
       __u64 cpuid;           # CPUID currently (to be) used by this vcpu
       __u16 ibc;             # IBC level currently (to be) used by this vcpu
       __u8  pad[6];
       __u64 fac_list[256];   # set of cpu facilities currently (to be) used
			      # by this vcpu
  }

KVM does not enforce or limit the cpu model data in any form. Take the information
retrieved by means of KVM_S390_VM_CPU_MACHINE as hint for reasonable configuration
setups. Instruction interceptions triggered by additionally set facility bits that
are not handled by KVM need to by implemented in the VM driver code.

:Parameters: address of buffer to store/set the processor related cpu
	     data of type struct kvm_s390_vm_cpu_processor*.
:Returns:  -EBUSY in case 1 or more vcpus are already activated (only in write case);
	   -EFAULT if the given address is not accessible from kernel space;
	   -ENOMEM if not enough memory is available to process the ioctl;
	   0 in case of success.

.. _KVM_S390_VM_CPU_MACHINE_FEAT:

2.3. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_FEAT (r/o)
--------------------------------------------------

Allows user space to retrieve available cpu features. A feature is available if
provided by the hardware and supported by kvm. In theory, cpu features could
even be completely emulated by kvm.

::

  struct kvm_s390_vm_cpu_feat {
	__u64 feat[16]; # Bitmap (1 = feature available), MSB 0 bit numbering
  };

:Parameters: address of a buffer to load the feature list from.
:Returns:  -EFAULT if the given address is not accessible from kernel space;
	   0 in case of success.

2.4. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_FEAT (r/w)
----------------------------------------------------

Allows user space to retrieve or change enabled cpu features for all VCPUs of a
VM. Features that are not available cannot be enabled.

See :ref:`KVM_S390_VM_CPU_MACHINE_FEAT` for
a description of the parameter struct.

:Parameters: address of a buffer to store/load the feature list from.
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    -EINVAL if a cpu feature that is not available is to be enabled;
	    -EBUSY if at least one VCPU has already been defined;
	    0 in case of success.

.. _KVM_S390_VM_CPU_MACHINE_SUBFUNC:

2.5. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE_SUBFUNC (r/o)
-----------------------------------------------------

Allows user space to retrieve available cpu subfunctions without any filtering
done by a set IBC. These subfunctions are indicated to the guest VCPU via
query or "test bit" subfunctions and used e.g. by cpacf functions, plo and ptff.

A subfunction block is only valid if KVM_S390_VM_CPU_MACHINE contains the
STFL(E) bit introducing the affected instruction. If the affected instruction
indicates subfunctions via a "query subfunction", the response block is
contained in the returned struct. If the affected instruction
indicates subfunctions via a "test bit" mechanism, the subfunction codes are
contained in the returned struct in MSB 0 bit numbering.

::

  struct kvm_s390_vm_cpu_subfunc {
       u8 plo[32];           # always valid (ESA/390 feature)
       u8 ptff[16];          # valid with TOD-clock steering
       u8 kmac[16];          # valid with Message-Security-Assist
       u8 kmc[16];           # valid with Message-Security-Assist
       u8 km[16];            # valid with Message-Security-Assist
       u8 kimd[16];          # valid with Message-Security-Assist
       u8 klmd[16];          # valid with Message-Security-Assist
       u8 pckmo[16];         # valid with Message-Security-Assist-Extension 3
       u8 kmctr[16];         # valid with Message-Security-Assist-Extension 4
       u8 kmf[16];           # valid with Message-Security-Assist-Extension 4
       u8 kmo[16];           # valid with Message-Security-Assist-Extension 4
       u8 pcc[16];           # valid with Message-Security-Assist-Extension 4
       u8 ppno[16];          # valid with Message-Security-Assist-Extension 5
       u8 kma[16];           # valid with Message-Security-Assist-Extension 8
       u8 kdsa[16];          # valid with Message-Security-Assist-Extension 9
       u8 reserved[1792];    # reserved for future instructions
  };

:Parameters: address of a buffer to load the subfunction blocks from.
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    0 in case of success.

2.6. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR_SUBFUNC (r/w)
-------------------------------------------------------

Allows user space to retrieve or change cpu subfunctions to be indicated for
all VCPUs of a VM. This attribute will only be available if kernel and
hardware support are in place.

The kernel uses the configured subfunction blocks for indication to
the guest. A subfunction block will only be used if the associated STFL(E) bit
has not been disabled by user space (so the instruction to be queried is
actually available for the guest).

As long as no data has been written, a read will fail. The IBC will be used
to determine available subfunctions in this case, this will guarantee backward
compatibility.

See :ref:`KVM_S390_VM_CPU_MACHINE_SUBFUNC` for a
description of the parameter struct.

:Parameters: address of a buffer to store/load the subfunction blocks from.
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    -EINVAL when reading, if there was no write yet;
	    -EBUSY if at least one VCPU has already been defined;
	    0 in case of success.

s390 TOD clock

204-243
s390 TOD attribute
Attribute
`KVM_S390_VM_TOD_HIGH`TOD extension `u8`; `TOD_EXT`로 대체됨. Nonzero extension 미지원이면 `-EINVAL`
`KVM_S390_VM_TOD_LOW`POP가 정의한 TOD clock register bit 0-63 `u64`
`KVM_S390_VM_TOD_EXT``kvm_s390_vm_tod_clock`으로 TOD low 64-bit와 지원 시 extension get/set

Protected guest의 TOD는 Ultravisor가 관리하므로 모두 `-EOPNOTSUPP`입니다.

Guest CPU model이 TOD extension을 지원하지 않으면 extension은 0으로 저장되고 nonzero로 설정할 수 없습니다. Userspace buffer access 실패는 `-EFAULT`입니다.

3. GROUP: KVM_S390_VM_TOD
=========================

:Architectures: s390

3.1. ATTRIBUTE: KVM_S390_VM_TOD_HIGH
------------------------------------

Allows user space to set/get the TOD clock extension (u8) (superseded by
KVM_S390_VM_TOD_EXT).

:Parameters: address of a buffer in user space to store the data (u8) to
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    -EINVAL if setting the TOD clock extension to != 0 is not supported
	    -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)

3.2. ATTRIBUTE: KVM_S390_VM_TOD_LOW
-----------------------------------

Allows user space to set/get bits 0-63 of the TOD clock register as defined in
the POP (u64).

:Parameters: address of a buffer in user space to store the data (u64) to
:Returns:    -EFAULT if the given address is not accessible from kernel space
	     -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)

3.3. ATTRIBUTE: KVM_S390_VM_TOD_EXT
-----------------------------------

Allows user space to set/get bits 0-63 of the TOD clock register as defined in
the POP (u64). If the guest CPU model supports the TOD clock extension (u8), it
also allows user space to get/set it. If the guest CPU model does not support
it, it is stored as 0 and not allowed to be set to a value != 0.

:Parameters: address of a buffer in user space to store the data
	     (kvm_s390_vm_tod_clock) to
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    -EINVAL if setting the TOD clock extension to != 0 is not supported
	    -EOPNOTSUPP for a PV guest (TOD managed by the ultravisor)

s390 wrapping-key control

244-282
s390 crypto attribute
Attribute동작
`KVM_S390_VM_CRYPTO_ENABLE_AES_KW`AES key wrapping enable 및 새 wrapping key 생성
`KVM_S390_VM_CRYPTO_ENABLE_DEA_KW`DEA key wrapping enable 및 새 wrapping key 생성
`KVM_S390_VM_CRYPTO_DISABLE_AES_KW`AES key wrapping disable 및 key clear
`KVM_S390_VM_CRYPTO_DISABLE_DEA_KW`DEA key wrapping disable 및 key clear

모든 attribute는 write-only이고 parameter 없이 성공 시 0을 반환합니다.

4. GROUP: KVM_S390_VM_CRYPTO
============================

:Architectures: s390

4.1. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_AES_KW (w/o)
------------------------------------------------------

Allows user space to enable aes key wrapping, including generating a new
wrapping key.

:Parameters: none
:Returns:    0

4.2. ATTRIBUTE: KVM_S390_VM_CRYPTO_ENABLE_DEA_KW (w/o)
------------------------------------------------------

Allows user space to enable dea key wrapping, including generating a new
wrapping key.

:Parameters: none
:Returns:    0

4.3. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_AES_KW (w/o)
-------------------------------------------------------

Allows user space to disable aes key wrapping, clearing the wrapping key.

:Parameters: none
:Returns:    0

4.4. ATTRIBUTE: KVM_S390_VM_CRYPTO_DISABLE_DEA_KW (w/o)
-------------------------------------------------------

Allows user space to disable dea key wrapping, clearing the wrapping key.

:Parameters: none
:Returns:    0

s390 PGSTE migration mode

283-324

`KVM_S390_VM_MIGRATION_START`와 STOP은 PGSTE migration mode를 제어합니다. 이미 같은 상태이면 operation은 아무 효과 없이 성공합니다.

START 전 모든 memslot에서 dirty tracking이 enable되어야 하며 하나라도 아니면 `-EINVAL`입니다. Migration mode 도중 어느 memslot의 dirty tracking이 disable되면 mode는 자동으로 중지됩니다.

s390 migration attribute
Attribute계약
`KVM_S390_VM_MIGRATION_START`Memory 정의 등 VM state가 invalid하면 `-EINVAL`, free memory 부족은 `-ENOMEM`
`KVM_S390_VM_MIGRATION_STOP`Mode 중지; 이미 disabled이면 no-op
`KVM_S390_VM_MIGRATION_STATUS`Userspace `u64`에 disabled=0, enabled=1; inaccessible pointer는 `-EFAULT`

Mode lifecycle과 status query입니다.

5. GROUP: KVM_S390_VM_MIGRATION
===============================

:Architectures: s390

5.1. ATTRIBUTE: KVM_S390_VM_MIGRATION_STOP (w/o)
------------------------------------------------

Allows userspace to stop migration mode, needed for PGSTE migration.
Setting this attribute when migration mode is not active will have no
effects.

:Parameters: none
:Returns:    0

5.2. ATTRIBUTE: KVM_S390_VM_MIGRATION_START (w/o)
-------------------------------------------------

Allows userspace to start migration mode, needed for PGSTE migration.
Setting this attribute when migration mode is already active will have
no effects.

Dirty tracking must be enabled on all memslots, else -EINVAL is returned. When
dirty tracking is disabled on any memslot, migration mode is automatically
stopped.

:Parameters: none
:Returns:   -ENOMEM if there is not enough free memory to start migration mode;
	    -EINVAL if the state of the VM is invalid (e.g. no memory defined);
	    0 in case of success.

5.3. ATTRIBUTE: KVM_S390_VM_MIGRATION_STATUS (r/o)
--------------------------------------------------

Allows userspace to query the status of migration mode.

:Parameters: address of a buffer in user space to store the data (u64) to;
	     the data itself is either 0 if migration mode is disabled or 1
	     if it is enabled
:Returns:   -EFAULT if the given address is not accessible from kernel space;
	    0 in case of success.

arm64 SMCCC call filter

325-402

`KVM_ARM_VM_SMCCC_FILTER`은 VM의 guest SMC와 HVC call에 공통 적용되는 write-only filter입니다. `kvm_smccc_filter`의 `base`, `nr_functions`, `action`으로 non-overlapping half-open range `[base, base + nr_functions)`를 추가합니다.

여러 attribute call로 sparse range를 설치할 수 있습니다. KVM default는 구현된 SMCCC call을 모두 허용하므로 userspace는 default와 다른 range만 기술하는 것이 좋습니다. Range는 32-bit wraparound를 허용하지 않습니다.

SMCCC filter action
Action동작
`KVM_SMCCC_FILTER_HANDLE`Guest call을 in-kernel 처리. 허용 range를 명시적으로 나열하지 않는 것이 강하게 권장됨
`KVM_SMCCC_FILTER_DENY`Guest call을 kernel에서 거부하고 guest로 반환
`KVM_SMCCC_FILTER_FWD_TO_USER``KVM_EXIT_HYPERCALL` exit로 userspace에 전달

Filter는 hypercall bitmap 같은 다른 SMCCC interface보다 먼저 in-kernel emulation을 gate합니다.

`pad[15]`는 미래 확장용이며 모두 0이어야 합니다. Nonzero면 `-EINVAL`이 될 수 있습니다.

SMCCC filter error
Error조건
`-EEXIST`기존 또는 reserved range와 겹침
`-EBUSY`VM의 vCPU가 이미 실행됨
`-EINVAL`잘못된 range·action·padding
`-ENOMEM`In-kernel filter representation allocation 실패

Range 설치 실패 조건입니다.

KVM은 Arm Architecture Calls function-ID range `0x80000000-0x8000FFFF`와 `0xC0000000-0xC000FFFF`를 예약하며 이 범위 일부라도 filter로 정의하려는 시도를 거부합니다.

6. GROUP: KVM_ARM_VM_SMCCC_CTRL
===============================

:Architectures: arm64

6.1. ATTRIBUTE: KVM_ARM_VM_SMCCC_FILTER (w/o)
---------------------------------------------

:Parameters: Pointer to a ``struct kvm_smccc_filter``

:Returns:

        ======  ===========================================
        EEXIST  Range intersects with a previously inserted
                or reserved range
        EBUSY   A vCPU in the VM has already run
        EINVAL  Invalid filter configuration
        ENOMEM  Failed to allocate memory for the in-kernel
                representation of the SMCCC filter
        ======  ===========================================

Requests the installation of an SMCCC call filter described as follows::

    enum kvm_smccc_filter_action {
            KVM_SMCCC_FILTER_HANDLE = 0,
            KVM_SMCCC_FILTER_DENY,
            KVM_SMCCC_FILTER_FWD_TO_USER,
    };

    struct kvm_smccc_filter {
            __u32 base;
            __u32 nr_functions;
            __u8 action;
            __u8 pad[15];
    };

The filter is defined as a set of non-overlapping ranges. Each
range defines an action to be applied to SMCCC calls within the range.
Userspace can insert multiple ranges into the filter by using
successive calls to this attribute.

The default configuration of KVM is such that all implemented SMCCC
calls are allowed. Thus, the SMCCC filter can be defined sparsely
by userspace, only describing ranges that modify the default behavior.

The range expressed by ``struct kvm_smccc_filter`` is
[``base``, ``base + nr_functions``). The range is not allowed to wrap,
i.e. userspace cannot rely on ``base + nr_functions`` overflowing.

The SMCCC filter applies to both SMC and HVC calls initiated by the
guest. The SMCCC filter gates the in-kernel emulation of SMCCC calls
and as such takes effect before other interfaces that interact with
SMCCC calls (e.g. hypercall bitmap registers).

Actions:

 - ``KVM_SMCCC_FILTER_HANDLE``: Allows the guest SMCCC call to be
   handled in-kernel. It is strongly recommended that userspace *not*
   explicitly describe the allowed SMCCC call ranges.

 - ``KVM_SMCCC_FILTER_DENY``: Rejects the guest SMCCC call in-kernel
   and returns to the guest.

 - ``KVM_SMCCC_FILTER_FWD_TO_USER``: The guest SMCCC call is forwarded
   to userspace with an exit reason of ``KVM_EXIT_HYPERCALL``.

The ``pad`` field is reserved for future use and must be zero. KVM may
return ``-EINVAL`` if the field is nonzero.

KVM reserves the 'Arm Architecture Calls' range of function IDs and
will reject attempts to define a filter for any portion of these ranges:

        =========== ===============
        Start       End (inclusive)
        =========== ===============
        0x8000_0000 0x8000_FFFF
        0xC000_0000 0xC000_FFFF
        =========== ===============