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