xref: /linux/arch/s390/include/asm/kvm_host.h (revision c27e360545373b7aee9862a5beef3b9fb3df0c25)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * definition for kernel virtual machines on s390
4  *
5  * Copyright IBM Corp. 2008, 2018
6  *
7  *    Author(s): Carsten Otte <cotte@de.ibm.com>
8  */
9 
10 
11 #ifndef ASM_KVM_HOST_H
12 #define ASM_KVM_HOST_H
13 
14 #include <linux/types.h>
15 #include <linux/hrtimer.h>
16 #include <linux/interrupt.h>
17 #include <linux/kvm_types.h>
18 #include <linux/kvm.h>
19 #include <linux/seqlock.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/mmu_notifier.h>
23 #include <asm/kvm_host_types.h>
24 #include <asm/debug.h>
25 #include <asm/cpu.h>
26 #include <asm/fpu.h>
27 #include <asm/isc.h>
28 #include <asm/guarded_storage.h>
29 
30 #define KVM_HAVE_MMU_RWLOCK
31 #define KVM_MAX_VCPUS 255
32 
33 #define KVM_INTERNAL_MEM_SLOTS 1
34 
35 /*
36  * These seem to be used for allocating ->chip in the routing table, which we
37  * don't use. 1 is as small as we can get to reduce the needed memory. If we
38  * need to look at ->chip later on, we'll need to revisit this.
39  */
40 #define KVM_NR_IRQCHIPS 1
41 #define KVM_IRQCHIP_NUM_PINS 1
42 #define KVM_HALT_POLL_NS_DEFAULT 50000
43 
44 /* s390-specific vcpu->requests bit members */
45 #define KVM_REQ_ENABLE_IBS	KVM_ARCH_REQ(0)
46 #define KVM_REQ_DISABLE_IBS	KVM_ARCH_REQ(1)
47 #define KVM_REQ_ICPT_OPEREXC	KVM_ARCH_REQ(2)
48 #define KVM_REQ_START_MIGRATION KVM_ARCH_REQ(3)
49 #define KVM_REQ_STOP_MIGRATION  KVM_ARCH_REQ(4)
50 #define KVM_REQ_VSIE_RESTART	KVM_ARCH_REQ(5)
51 #define KVM_REQ_REFRESH_GUEST_PREFIX	\
52 	KVM_ARCH_REQ_FLAGS(6, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
53 
54 struct kvm_vcpu_stat {
55 	struct kvm_vcpu_stat_generic generic;
56 	u64 exit_userspace;
57 	u64 exit_null;
58 	u64 exit_external_request;
59 	u64 exit_io_request;
60 	u64 exit_external_interrupt;
61 	u64 exit_stop_request;
62 	u64 exit_validity;
63 	u64 exit_instruction;
64 	u64 exit_pei;
65 	u64 halt_no_poll_steal;
66 	u64 instruction_lctl;
67 	u64 instruction_lctlg;
68 	u64 instruction_stctl;
69 	u64 instruction_stctg;
70 	u64 exit_program_interruption;
71 	u64 exit_instr_and_program;
72 	u64 exit_operation_exception;
73 	u64 deliver_ckc;
74 	u64 deliver_cputm;
75 	u64 deliver_external_call;
76 	u64 deliver_emergency_signal;
77 	u64 deliver_service_signal;
78 	u64 deliver_virtio;
79 	u64 deliver_stop_signal;
80 	u64 deliver_prefix_signal;
81 	u64 deliver_restart_signal;
82 	u64 deliver_program;
83 	u64 deliver_io;
84 	u64 deliver_machine_check;
85 	u64 exit_wait_state;
86 	u64 inject_ckc;
87 	u64 inject_cputm;
88 	u64 inject_external_call;
89 	u64 inject_emergency_signal;
90 	u64 inject_mchk;
91 	u64 inject_pfault_init;
92 	u64 inject_program;
93 	u64 inject_restart;
94 	u64 inject_set_prefix;
95 	u64 inject_stop_signal;
96 	u64 instruction_epsw;
97 	u64 instruction_gs;
98 	u64 instruction_io_other;
99 	u64 instruction_lpsw;
100 	u64 instruction_lpswe;
101 	u64 instruction_lpswey;
102 	u64 instruction_pfmf;
103 	u64 instruction_ptff;
104 	u64 instruction_sck;
105 	u64 instruction_sckpf;
106 	u64 instruction_stidp;
107 	u64 instruction_spx;
108 	u64 instruction_stpx;
109 	u64 instruction_stap;
110 	u64 instruction_iske;
111 	u64 instruction_ri;
112 	u64 instruction_rrbe;
113 	u64 instruction_sske;
114 	u64 instruction_ipte_interlock;
115 	u64 instruction_stsi;
116 	u64 instruction_stfl;
117 	u64 instruction_tb;
118 	u64 instruction_tpi;
119 	u64 instruction_tprot;
120 	u64 instruction_tsch;
121 	u64 instruction_sie;
122 	u64 instruction_essa;
123 	u64 instruction_sthyi;
124 	u64 instruction_sigp_sense;
125 	u64 instruction_sigp_sense_running;
126 	u64 instruction_sigp_external_call;
127 	u64 instruction_sigp_emergency;
128 	u64 instruction_sigp_cond_emergency;
129 	u64 instruction_sigp_start;
130 	u64 instruction_sigp_stop;
131 	u64 instruction_sigp_stop_store_status;
132 	u64 instruction_sigp_store_status;
133 	u64 instruction_sigp_store_adtl_status;
134 	u64 instruction_sigp_arch;
135 	u64 instruction_sigp_prefix;
136 	u64 instruction_sigp_restart;
137 	u64 instruction_sigp_init_cpu_reset;
138 	u64 instruction_sigp_cpu_reset;
139 	u64 instruction_sigp_unknown;
140 	u64 instruction_diagnose_10;
141 	u64 instruction_diagnose_44;
142 	u64 instruction_diagnose_9c;
143 	u64 diag_9c_ignored;
144 	u64 diag_9c_forward;
145 	u64 instruction_diagnose_258;
146 	u64 instruction_diagnose_308;
147 	u64 instruction_diagnose_500;
148 	u64 instruction_diagnose_other;
149 	u64 pfault_sync;
150 	u64 signal_exits;
151 };
152 
153 #define PGM_OPERATION			0x01
154 #define PGM_PRIVILEGED_OP		0x02
155 #define PGM_EXECUTE			0x03
156 #define PGM_PROTECTION			0x04
157 #define PGM_ADDRESSING			0x05
158 #define PGM_SPECIFICATION		0x06
159 #define PGM_DATA			0x07
160 #define PGM_FIXED_POINT_OVERFLOW	0x08
161 #define PGM_FIXED_POINT_DIVIDE		0x09
162 #define PGM_DECIMAL_OVERFLOW		0x0a
163 #define PGM_DECIMAL_DIVIDE		0x0b
164 #define PGM_HFP_EXPONENT_OVERFLOW	0x0c
165 #define PGM_HFP_EXPONENT_UNDERFLOW	0x0d
166 #define PGM_HFP_SIGNIFICANCE		0x0e
167 #define PGM_HFP_DIVIDE			0x0f
168 #define PGM_SEGMENT_TRANSLATION		0x10
169 #define PGM_PAGE_TRANSLATION		0x11
170 #define PGM_TRANSLATION_SPEC		0x12
171 #define PGM_SPECIAL_OPERATION		0x13
172 #define PGM_OPERAND			0x15
173 #define PGM_TRACE_TABEL			0x16
174 #define PGM_VECTOR_PROCESSING		0x1b
175 #define PGM_SPACE_SWITCH		0x1c
176 #define PGM_HFP_SQUARE_ROOT		0x1d
177 #define PGM_PC_TRANSLATION_SPEC		0x1f
178 #define PGM_AFX_TRANSLATION		0x20
179 #define PGM_ASX_TRANSLATION		0x21
180 #define PGM_LX_TRANSLATION		0x22
181 #define PGM_EX_TRANSLATION		0x23
182 #define PGM_PRIMARY_AUTHORITY		0x24
183 #define PGM_SECONDARY_AUTHORITY		0x25
184 #define PGM_LFX_TRANSLATION		0x26
185 #define PGM_LSX_TRANSLATION		0x27
186 #define PGM_ALET_SPECIFICATION		0x28
187 #define PGM_ALEN_TRANSLATION		0x29
188 #define PGM_ALE_SEQUENCE		0x2a
189 #define PGM_ASTE_VALIDITY		0x2b
190 #define PGM_ASTE_SEQUENCE		0x2c
191 #define PGM_EXTENDED_AUTHORITY		0x2d
192 #define PGM_LSTE_SEQUENCE		0x2e
193 #define PGM_ASTE_INSTANCE		0x2f
194 #define PGM_STACK_FULL			0x30
195 #define PGM_STACK_EMPTY			0x31
196 #define PGM_STACK_SPECIFICATION		0x32
197 #define PGM_STACK_TYPE			0x33
198 #define PGM_STACK_OPERATION		0x34
199 #define PGM_ASCE_TYPE			0x38
200 #define PGM_REGION_FIRST_TRANS		0x39
201 #define PGM_REGION_SECOND_TRANS		0x3a
202 #define PGM_REGION_THIRD_TRANS		0x3b
203 #define PGM_SECURE_STORAGE_ACCESS	0x3d
204 #define PGM_NON_SECURE_STORAGE_ACCESS	0x3e
205 #define PGM_SECURE_STORAGE_VIOLATION	0x3f
206 #define PGM_MONITOR			0x40
207 #define PGM_PER				0x80
208 #define PGM_CRYPTO_OPERATION		0x119
209 
210 /* irq types in ascend order of priorities */
211 enum irq_types {
212 	IRQ_PEND_SET_PREFIX = 0,
213 	IRQ_PEND_RESTART,
214 	IRQ_PEND_SIGP_STOP,
215 	IRQ_PEND_IO_ISC_7,
216 	IRQ_PEND_IO_ISC_6,
217 	IRQ_PEND_IO_ISC_5,
218 	IRQ_PEND_IO_ISC_4,
219 	IRQ_PEND_IO_ISC_3,
220 	IRQ_PEND_IO_ISC_2,
221 	IRQ_PEND_IO_ISC_1,
222 	IRQ_PEND_IO_ISC_0,
223 	IRQ_PEND_VIRTIO,
224 	IRQ_PEND_PFAULT_DONE,
225 	IRQ_PEND_PFAULT_INIT,
226 	IRQ_PEND_EXT_HOST,
227 	IRQ_PEND_EXT_SERVICE,
228 	IRQ_PEND_EXT_SERVICE_EV,
229 	IRQ_PEND_EXT_TIMING,
230 	IRQ_PEND_EXT_CPU_TIMER,
231 	IRQ_PEND_EXT_CLOCK_COMP,
232 	IRQ_PEND_EXT_EXTERNAL,
233 	IRQ_PEND_EXT_EMERGENCY,
234 	IRQ_PEND_EXT_MALFUNC,
235 	IRQ_PEND_EXT_IRQ_KEY,
236 	IRQ_PEND_MCHK_REP,
237 	IRQ_PEND_PROG,
238 	IRQ_PEND_SVC,
239 	IRQ_PEND_MCHK_EX,
240 	IRQ_PEND_COUNT
241 };
242 
243 /* We have 2M for virtio device descriptor pages. Smallest amount of
244  * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381
245  */
246 #define KVM_S390_MAX_VIRTIO_IRQS 87381
247 
248 /*
249  * Repressible (non-floating) machine check interrupts
250  * subclass bits in MCIC
251  */
252 #define MCHK_EXTD_BIT 58
253 #define MCHK_DEGR_BIT 56
254 #define MCHK_WARN_BIT 55
255 #define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \
256 		       (1UL << MCHK_EXTD_BIT) | \
257 		       (1UL << MCHK_WARN_BIT))
258 
259 /* Exigent machine check interrupts subclass bits in MCIC */
260 #define MCHK_SD_BIT 63
261 #define MCHK_PD_BIT 62
262 #define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT))
263 
264 #define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY)    | \
265 			   (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
266 			   (1UL << IRQ_PEND_EXT_CPU_TIMER)  | \
267 			   (1UL << IRQ_PEND_EXT_MALFUNC)    | \
268 			   (1UL << IRQ_PEND_EXT_EMERGENCY)  | \
269 			   (1UL << IRQ_PEND_EXT_EXTERNAL)   | \
270 			   (1UL << IRQ_PEND_EXT_TIMING)     | \
271 			   (1UL << IRQ_PEND_EXT_HOST)       | \
272 			   (1UL << IRQ_PEND_EXT_SERVICE)    | \
273 			   (1UL << IRQ_PEND_EXT_SERVICE_EV) | \
274 			   (1UL << IRQ_PEND_VIRTIO)         | \
275 			   (1UL << IRQ_PEND_PFAULT_INIT)    | \
276 			   (1UL << IRQ_PEND_PFAULT_DONE))
277 
278 #define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \
279 			  (1UL << IRQ_PEND_IO_ISC_1) | \
280 			  (1UL << IRQ_PEND_IO_ISC_2) | \
281 			  (1UL << IRQ_PEND_IO_ISC_3) | \
282 			  (1UL << IRQ_PEND_IO_ISC_4) | \
283 			  (1UL << IRQ_PEND_IO_ISC_5) | \
284 			  (1UL << IRQ_PEND_IO_ISC_6) | \
285 			  (1UL << IRQ_PEND_IO_ISC_7))
286 
287 #define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
288 			    (1UL << IRQ_PEND_MCHK_EX))
289 
290 #define IRQ_PEND_EXT_II_MASK ((1UL << IRQ_PEND_EXT_CPU_TIMER)  | \
291 			      (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
292 			      (1UL << IRQ_PEND_EXT_EMERGENCY)  | \
293 			      (1UL << IRQ_PEND_EXT_EXTERNAL)   | \
294 			      (1UL << IRQ_PEND_EXT_SERVICE)    | \
295 			      (1UL << IRQ_PEND_EXT_SERVICE_EV))
296 
297 struct kvm_s390_interrupt_info {
298 	struct list_head list;
299 	u64	type;
300 	union {
301 		struct kvm_s390_io_info io;
302 		struct kvm_s390_ext_info ext;
303 		struct kvm_s390_pgm_info pgm;
304 		struct kvm_s390_emerg_info emerg;
305 		struct kvm_s390_extcall_info extcall;
306 		struct kvm_s390_prefix_info prefix;
307 		struct kvm_s390_stop_info stop;
308 		struct kvm_s390_mchk_info mchk;
309 	};
310 };
311 
312 struct kvm_s390_irq_payload {
313 	struct kvm_s390_io_info io;
314 	struct kvm_s390_ext_info ext;
315 	struct kvm_s390_pgm_info pgm;
316 	struct kvm_s390_emerg_info emerg;
317 	struct kvm_s390_extcall_info extcall;
318 	struct kvm_s390_prefix_info prefix;
319 	struct kvm_s390_stop_info stop;
320 	struct kvm_s390_mchk_info mchk;
321 };
322 
323 struct kvm_s390_local_interrupt {
324 	spinlock_t lock;
325 	DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
326 	struct kvm_s390_irq_payload irq;
327 	unsigned long pending_irqs;
328 };
329 
330 #define FIRQ_LIST_IO_ISC_0 0
331 #define FIRQ_LIST_IO_ISC_1 1
332 #define FIRQ_LIST_IO_ISC_2 2
333 #define FIRQ_LIST_IO_ISC_3 3
334 #define FIRQ_LIST_IO_ISC_4 4
335 #define FIRQ_LIST_IO_ISC_5 5
336 #define FIRQ_LIST_IO_ISC_6 6
337 #define FIRQ_LIST_IO_ISC_7 7
338 #define FIRQ_LIST_PFAULT   8
339 #define FIRQ_LIST_VIRTIO   9
340 #define FIRQ_LIST_COUNT   10
341 #define FIRQ_CNTR_IO       0
342 #define FIRQ_CNTR_SERVICE  1
343 #define FIRQ_CNTR_VIRTIO   2
344 #define FIRQ_CNTR_PFAULT   3
345 #define FIRQ_MAX_COUNT     4
346 
347 /* mask the AIS mode for a given ISC */
348 #define AIS_MODE_MASK(isc) (0x80 >> isc)
349 
350 #define KVM_S390_AIS_MODE_ALL    0
351 #define KVM_S390_AIS_MODE_SINGLE 1
352 
353 struct kvm_s390_float_interrupt {
354 	unsigned long pending_irqs;
355 	unsigned long masked_irqs;
356 	spinlock_t lock;
357 	struct list_head lists[FIRQ_LIST_COUNT];
358 	int counters[FIRQ_MAX_COUNT];
359 	struct kvm_s390_mchk_info mchk;
360 	struct kvm_s390_ext_info srv_signal;
361 	int last_sleep_cpu;
362 	spinlock_t ais_lock;
363 	u8 simm;
364 	u8 nimm;
365 };
366 
367 struct kvm_hw_wp_info_arch {
368 	unsigned long addr;
369 	unsigned long phys_addr;
370 	int len;
371 	char *old_data;
372 };
373 
374 struct kvm_hw_bp_info_arch {
375 	unsigned long addr;
376 	int len;
377 };
378 
379 /*
380  * Only the upper 16 bits of kvm_guest_debug->control are arch specific.
381  * Further KVM_GUESTDBG flags which an be used from userspace can be found in
382  * arch/s390/include/uapi/asm/kvm.h
383  */
384 #define KVM_GUESTDBG_EXIT_PENDING 0x10000000
385 
386 #define guestdbg_enabled(vcpu) \
387 		(vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
388 #define guestdbg_sstep_enabled(vcpu) \
389 		(vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
390 #define guestdbg_hw_bp_enabled(vcpu) \
391 		(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
392 #define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
393 		(vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
394 
395 #define KVM_GUESTDBG_VALID_MASK \
396 		(KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP |\
397 		KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_EXIT_PENDING)
398 
399 struct kvm_guestdbg_info_arch {
400 	unsigned long cr0;
401 	unsigned long cr9;
402 	unsigned long cr10;
403 	unsigned long cr11;
404 	struct kvm_hw_bp_info_arch *hw_bp_info;
405 	struct kvm_hw_wp_info_arch *hw_wp_info;
406 	int nr_hw_bp;
407 	int nr_hw_wp;
408 	unsigned long last_bp;
409 };
410 
411 struct kvm_s390_pv_vcpu {
412 	u64 handle;
413 	unsigned long stor_base;
414 };
415 
416 struct kvm_vcpu_arch {
417 	struct kvm_s390_sie_block *sie_block;
418 	/* if vsie is active, currently executed shadow sie control block */
419 	struct kvm_s390_sie_block *vsie_block;
420 	unsigned int      host_acrs[NUM_ACRS];
421 	struct gs_cb      *host_gscb;
422 	struct kvm_s390_local_interrupt local_int;
423 	struct hrtimer    ckc_timer;
424 	struct kvm_s390_pgm_info pgm;
425 	struct gmap *gmap;
426 	struct kvm_guestdbg_info_arch guestdbg;
427 	unsigned long pfault_token;
428 	unsigned long pfault_select;
429 	unsigned long pfault_compare;
430 	bool cputm_enabled;
431 	/*
432 	 * The seqcount protects updates to cputm_start and sie_block.cputm,
433 	 * this way we can have non-blocking reads with consistent values.
434 	 * Only the owning VCPU thread (vcpu->cpu) is allowed to change these
435 	 * values and to start/stop/enable/disable cpu timer accounting.
436 	 */
437 	seqcount_t cputm_seqcount;
438 	__u64 cputm_start;
439 	bool gs_enabled;
440 	bool skey_enabled;
441 	/* Indicator if the access registers have been loaded from guest */
442 	bool acrs_loaded;
443 	struct kvm_s390_pv_vcpu pv;
444 	union diag318_info diag318_info;
445 	struct kvm_s390_mmu_cache *mc;
446 };
447 
448 struct kvm_vm_stat {
449 	struct kvm_vm_stat_generic generic;
450 	u64 inject_io;
451 	u64 io_390_adapter_map;
452 	u64 io_390_adapter_unmap;
453 	u64 io_390_inatomic;
454 	u64 io_flic_inject_airq;
455 	u64 io_set_adapter_int;
456 	u64 io_390_inatomic_no_inject;
457 	u64 inject_float_mchk;
458 	u64 inject_pfault_done;
459 	u64 inject_service_signal;
460 	u64 inject_virtio;
461 	u64 aen_forward;
462 	u64 gmap_shadow_create;
463 	u64 gmap_shadow_reuse;
464 	u64 gmap_shadow_r1_entry;
465 	u64 gmap_shadow_r2_entry;
466 	u64 gmap_shadow_r3_entry;
467 	u64 gmap_shadow_sg_entry;
468 	u64 gmap_shadow_pg_entry;
469 };
470 
471 struct kvm_arch_memory_slot {
472 };
473 
474 struct s390_map_info {
475 	struct list_head list;
476 	__u64 guest_addr;
477 	__u64 addr;
478 	struct page *page;
479 	/*
480 	 * True if the page is long-term pinned. False if long-term pinning
481 	 * failed and this entry exists only to preserve MAP/UNMAP symmetry.
482 	 */
483 	bool pinned;
484 };
485 
486 struct s390_io_adapter {
487 	unsigned int id;
488 	int isc;
489 	bool maskable;
490 	bool masked;
491 	bool swap;
492 	bool suppressible;
493 	spinlock_t maps_lock;
494 	struct list_head maps;
495 	unsigned int nr_maps;
496 };
497 
498 #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
499 #define MAX_S390_ADAPTER_MAPS 256
500 
501 /* maximum size of facilities and facility mask is 2k bytes */
502 #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
503 #define S390_ARCH_FAC_LIST_SIZE_U64 \
504 	(S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
505 #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
506 #define S390_ARCH_FAC_MASK_SIZE_U64 \
507 	(S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
508 
509 struct kvm_s390_cpu_model {
510 	/* facility mask supported by kvm & hosting machine */
511 	__u64 fac_mask[S390_ARCH_FAC_MASK_SIZE_U64];
512 	struct kvm_s390_vm_cpu_subfunc subfuncs;
513 	/* facility list requested by guest (in dma page) */
514 	__u64 *fac_list;
515 	u64 cpuid;
516 	unsigned short ibc;
517 	/* subset of available UV-features for pv-guests enabled by user space */
518 	struct kvm_s390_vm_cpu_uv_feat uv_feat_guest;
519 };
520 
521 #define S390_ARCH_FAC_FORMAT_2 2
522 struct kvm_s390_flcb2 {
523 	union {
524 		struct {
525 			u8 reserved0[7];
526 			u8 length;
527 		};
528 		u64 header_val;
529 	};
530 	u64 facilities[S390_ARCH_FAC_LIST_SIZE_U64];
531 };
532 
533 typedef int (*crypto_hook)(struct kvm_vcpu *vcpu);
534 
535 struct kvm_s390_crypto {
536 	struct kvm_s390_crypto_cb *crycb;
537 	struct rw_semaphore pqap_hook_rwsem;
538 	crypto_hook *pqap_hook;
539 	__u32 crycbd;
540 	__u8 aes_kw;
541 	__u8 dea_kw;
542 	__u8 apie;
543 };
544 
545 #define APCB0_MASK_SIZE 1
546 struct kvm_s390_apcb0 {
547 	__u64 apm[APCB0_MASK_SIZE];		/* 0x0000 */
548 	__u64 aqm[APCB0_MASK_SIZE];		/* 0x0008 */
549 	__u64 adm[APCB0_MASK_SIZE];		/* 0x0010 */
550 	__u64 reserved18;			/* 0x0018 */
551 };
552 
553 #define APCB1_MASK_SIZE 4
554 struct kvm_s390_apcb1 {
555 	__u64 apm[APCB1_MASK_SIZE];		/* 0x0000 */
556 	__u64 aqm[APCB1_MASK_SIZE];		/* 0x0020 */
557 	__u64 adm[APCB1_MASK_SIZE];		/* 0x0040 */
558 	__u64 reserved60[4];			/* 0x0060 */
559 };
560 
561 struct kvm_s390_crypto_cb {
562 	struct kvm_s390_apcb0 apcb0;		/* 0x0000 */
563 	__u8   reserved20[0x0048 - 0x0020];	/* 0x0020 */
564 	__u8   dea_wrapping_key_mask[24];	/* 0x0048 */
565 	__u8   aes_wrapping_key_mask[32];	/* 0x0060 */
566 	struct kvm_s390_apcb1 apcb1;		/* 0x0080 */
567 };
568 
569 struct kvm_s390_gisa {
570 	union {
571 		struct { /* common to all formats */
572 			u32 next_alert;
573 			u8  ipm;
574 			u8  reserved01[2];
575 			u8  iam;
576 		};
577 		struct { /* format 0 */
578 			u32 next_alert;
579 			u8  ipm;
580 			u8  reserved01;
581 			u8  : 6;
582 			u8  g : 1;
583 			u8  c : 1;
584 			u8  iam;
585 			u8  reserved02[4];
586 			u32 airq_count;
587 		} g0;
588 		struct { /* format 1 */
589 			u32 next_alert;
590 			u8  ipm;
591 			u8  simm;
592 			u8  nimm;
593 			u8  iam;
594 			u8  aism[8];
595 			u8  : 6;
596 			u8  g : 1;
597 			u8  c : 1;
598 			u8  reserved03[11];
599 			u32 airq_count;
600 		} g1;
601 		struct {
602 			u64 word[4];
603 		} u64;
604 	};
605 };
606 
607 struct kvm_s390_gib {
608 	u32 alert_list_origin;
609 	u32 reserved01;
610 	u8:5;
611 	u8  nisc:3;
612 	u8  reserved03[3];
613 	u32 reserved04[5];
614 };
615 
616 /*
617  * sie_page2 has to be allocated as DMA because fac_list, crycb and
618  * gisa need 31bit addresses in the sie control block.
619  */
620 struct sie_page2 {
621 	__u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64];	/* 0x0000 */
622 	struct kvm_s390_crypto_cb crycb;		/* 0x0800 */
623 	struct kvm_s390_gisa gisa;			/* 0x0900 */
624 	struct kvm *kvm;				/* 0x0920 */
625 	u8 reserved928[0x1000 - 0x928];			/* 0x0928 */
626 };
627 
628 struct vsie_page;
629 
630 struct kvm_s390_vsie {
631 	struct mutex mutex;
632 	struct radix_tree_root addr_to_page;
633 	int page_count;
634 	int next;
635 	struct vsie_page *pages[KVM_MAX_VCPUS];
636 };
637 
638 struct kvm_s390_gisa_iam {
639 	u8 mask;
640 	spinlock_t ref_lock;
641 	u32 ref_count[MAX_ISC + 1];
642 };
643 
644 struct kvm_s390_gisa_interrupt {
645 	struct kvm_s390_gisa *origin;
646 	struct kvm_s390_gisa_iam alert;
647 	struct hrtimer timer;
648 	u64 expires;
649 	DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS);
650 };
651 
652 struct kvm_s390_pv {
653 	u64 handle;
654 	u64 guest_len;
655 	unsigned long stor_base;
656 	void *stor_var;
657 	bool dumping;
658 	void *set_aside;
659 	struct list_head need_cleanup;
660 	struct mmu_notifier mmu_notifier;
661 	/* Protects against concurrent import-like operations */
662 	struct mutex import_lock;
663 };
664 
665 struct kvm_s390_mmu_cache;
666 
667 struct kvm_arch {
668 	struct esca_block *sca;
669 	debug_info_t *dbf;
670 	struct kvm_s390_float_interrupt float_int;
671 	struct kvm_device *flic;
672 	struct gmap *gmap;
673 	unsigned long mem_limit;
674 	int css_support;
675 	int use_irqchip;
676 	int use_cmma;
677 	int use_pfmfi;
678 	int use_skf;
679 	int use_zpci_interp;
680 	int user_cpu_state_ctrl;
681 	int user_sigp;
682 	int user_stsi;
683 	int user_instr0;
684 	int user_operexec;
685 	int allow_vsie_esamode;
686 	struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
687 	wait_queue_head_t ipte_wq;
688 	int ipte_lock_count;
689 	struct mutex ipte_mutex;
690 	spinlock_t start_stop_lock;
691 	struct sie_page2 *sie_page2;
692 	struct kvm_s390_cpu_model model;
693 	struct kvm_s390_crypto crypto;
694 	struct kvm_s390_vsie vsie;
695 	u8 epdx;
696 	u64 epoch;
697 	int migration_mode;
698 	atomic64_t cmma_dirty_pages;
699 	/* subset of available cpu features enabled by user space */
700 	DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
701 	/* indexed by vcpu_idx */
702 	DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
703 	struct kvm_s390_gisa_interrupt gisa_int;
704 	struct kvm_s390_pv pv;
705 	struct list_head kzdev_list;
706 	spinlock_t kzdev_list_lock;
707 	struct kvm_s390_mmu_cache *mc;
708 };
709 
710 #define KVM_HVA_ERR_BAD		(-1UL)
711 #define KVM_HVA_ERR_RO_BAD	(-2UL)
712 
713 static inline bool kvm_is_error_hva(unsigned long addr)
714 {
715 	return IS_ERR_VALUE(addr);
716 }
717 
718 #define ASYNC_PF_PER_VCPU	64
719 struct kvm_arch_async_pf {
720 	unsigned long pfault_token;
721 };
722 
723 bool kvm_arch_can_dequeue_async_page_present(struct kvm_vcpu *vcpu);
724 
725 void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
726 			       struct kvm_async_pf *work);
727 
728 bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
729 				     struct kvm_async_pf *work);
730 
731 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
732 				 struct kvm_async_pf *work);
733 
734 static inline void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu) {}
735 
736 void kvm_arch_crypto_clear_masks(struct kvm *kvm);
737 void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
738 			       unsigned long *aqm, unsigned long *adm);
739 
740 #define SIE64_RETURN_NORMAL	0
741 #define SIE64_RETURN_MCCK	1
742 
743 int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa,
744 	     unsigned long gasce);
745 
746 static inline int sie64a(struct kvm_s390_sie_block *sie_block, u64 *rsa, unsigned long gasce)
747 {
748 	return __sie64a(virt_to_phys(sie_block), sie_block, rsa, gasce);
749 }
750 
751 extern char sie_exit;
752 
753 bool kvm_s390_pv_is_protected(struct kvm *kvm);
754 bool kvm_s390_pv_cpu_is_protected(struct kvm_vcpu *vcpu);
755 
756 extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
757 				   u64 *gprs, unsigned long gasce);
758 
759 extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
760 extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
761 
762 bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa);
763 
764 static inline void kvm_arch_free_memslot(struct kvm *kvm,
765 					 struct kvm_memory_slot *slot) {}
766 static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
767 static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
768 static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
769 		struct kvm_memory_slot *slot) {}
770 static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
771 static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
772 
773 #define __KVM_HAVE_ARCH_VM_FREE
774 void kvm_arch_free_vm(struct kvm *kvm);
775 
776 struct zpci_kvm_hook {
777 	int (*kvm_register)(void *opaque, struct kvm *kvm);
778 	void (*kvm_unregister)(void *opaque);
779 };
780 
781 extern struct zpci_kvm_hook zpci_kvm_hook;
782 
783 #endif
784