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 struct mutex 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 inject_float_mchk;
452 u64 inject_pfault_done;
453 u64 inject_service_signal;
454 u64 inject_virtio;
455 u64 aen_forward;
456 u64 gmap_shadow_create;
457 u64 gmap_shadow_reuse;
458 u64 gmap_shadow_r1_entry;
459 u64 gmap_shadow_r2_entry;
460 u64 gmap_shadow_r3_entry;
461 u64 gmap_shadow_sg_entry;
462 u64 gmap_shadow_pg_entry;
463 };
464
465 struct kvm_arch_memory_slot {
466 };
467
468 struct s390_map_info {
469 struct list_head list;
470 __u64 guest_addr;
471 __u64 addr;
472 struct page *page;
473 };
474
475 struct s390_io_adapter {
476 unsigned int id;
477 int isc;
478 bool maskable;
479 bool masked;
480 bool swap;
481 bool suppressible;
482 };
483
484 #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
485 #define MAX_S390_ADAPTER_MAPS 256
486
487 /* maximum size of facilities and facility mask is 2k bytes */
488 #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
489 #define S390_ARCH_FAC_LIST_SIZE_U64 \
490 (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
491 #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
492 #define S390_ARCH_FAC_MASK_SIZE_U64 \
493 (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
494
495 struct kvm_s390_cpu_model {
496 /* facility mask supported by kvm & hosting machine */
497 __u64 fac_mask[S390_ARCH_FAC_MASK_SIZE_U64];
498 struct kvm_s390_vm_cpu_subfunc subfuncs;
499 /* facility list requested by guest (in dma page) */
500 __u64 *fac_list;
501 u64 cpuid;
502 unsigned short ibc;
503 /* subset of available UV-features for pv-guests enabled by user space */
504 struct kvm_s390_vm_cpu_uv_feat uv_feat_guest;
505 };
506
507 typedef int (*crypto_hook)(struct kvm_vcpu *vcpu);
508
509 struct kvm_s390_crypto {
510 struct kvm_s390_crypto_cb *crycb;
511 struct rw_semaphore pqap_hook_rwsem;
512 crypto_hook *pqap_hook;
513 __u32 crycbd;
514 __u8 aes_kw;
515 __u8 dea_kw;
516 __u8 apie;
517 };
518
519 #define APCB0_MASK_SIZE 1
520 struct kvm_s390_apcb0 {
521 __u64 apm[APCB0_MASK_SIZE]; /* 0x0000 */
522 __u64 aqm[APCB0_MASK_SIZE]; /* 0x0008 */
523 __u64 adm[APCB0_MASK_SIZE]; /* 0x0010 */
524 __u64 reserved18; /* 0x0018 */
525 };
526
527 #define APCB1_MASK_SIZE 4
528 struct kvm_s390_apcb1 {
529 __u64 apm[APCB1_MASK_SIZE]; /* 0x0000 */
530 __u64 aqm[APCB1_MASK_SIZE]; /* 0x0020 */
531 __u64 adm[APCB1_MASK_SIZE]; /* 0x0040 */
532 __u64 reserved60[4]; /* 0x0060 */
533 };
534
535 struct kvm_s390_crypto_cb {
536 struct kvm_s390_apcb0 apcb0; /* 0x0000 */
537 __u8 reserved20[0x0048 - 0x0020]; /* 0x0020 */
538 __u8 dea_wrapping_key_mask[24]; /* 0x0048 */
539 __u8 aes_wrapping_key_mask[32]; /* 0x0060 */
540 struct kvm_s390_apcb1 apcb1; /* 0x0080 */
541 };
542
543 struct kvm_s390_gisa {
544 union {
545 struct { /* common to all formats */
546 u32 next_alert;
547 u8 ipm;
548 u8 reserved01[2];
549 u8 iam;
550 };
551 struct { /* format 0 */
552 u32 next_alert;
553 u8 ipm;
554 u8 reserved01;
555 u8 : 6;
556 u8 g : 1;
557 u8 c : 1;
558 u8 iam;
559 u8 reserved02[4];
560 u32 airq_count;
561 } g0;
562 struct { /* format 1 */
563 u32 next_alert;
564 u8 ipm;
565 u8 simm;
566 u8 nimm;
567 u8 iam;
568 u8 aism[8];
569 u8 : 6;
570 u8 g : 1;
571 u8 c : 1;
572 u8 reserved03[11];
573 u32 airq_count;
574 } g1;
575 struct {
576 u64 word[4];
577 } u64;
578 };
579 };
580
581 struct kvm_s390_gib {
582 u32 alert_list_origin;
583 u32 reserved01;
584 u8:5;
585 u8 nisc:3;
586 u8 reserved03[3];
587 u32 reserved04[5];
588 };
589
590 /*
591 * sie_page2 has to be allocated as DMA because fac_list, crycb and
592 * gisa need 31bit addresses in the sie control block.
593 */
594 struct sie_page2 {
595 __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */
596 struct kvm_s390_crypto_cb crycb; /* 0x0800 */
597 struct kvm_s390_gisa gisa; /* 0x0900 */
598 struct kvm *kvm; /* 0x0920 */
599 u8 reserved928[0x1000 - 0x928]; /* 0x0928 */
600 };
601
602 struct vsie_page;
603
604 struct kvm_s390_vsie {
605 struct mutex mutex;
606 struct radix_tree_root addr_to_page;
607 int page_count;
608 int next;
609 struct vsie_page *pages[KVM_MAX_VCPUS];
610 };
611
612 struct kvm_s390_gisa_iam {
613 u8 mask;
614 spinlock_t ref_lock;
615 u32 ref_count[MAX_ISC + 1];
616 };
617
618 struct kvm_s390_gisa_interrupt {
619 struct kvm_s390_gisa *origin;
620 struct kvm_s390_gisa_iam alert;
621 struct hrtimer timer;
622 u64 expires;
623 DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS);
624 };
625
626 struct kvm_s390_pv {
627 u64 handle;
628 u64 guest_len;
629 unsigned long stor_base;
630 void *stor_var;
631 bool dumping;
632 void *set_aside;
633 struct list_head need_cleanup;
634 struct mmu_notifier mmu_notifier;
635 /* Protects against concurrent import-like operations */
636 struct mutex import_lock;
637 };
638
639 struct kvm_s390_mmu_cache;
640
641 struct kvm_arch {
642 struct esca_block *sca;
643 debug_info_t *dbf;
644 struct kvm_s390_float_interrupt float_int;
645 struct kvm_device *flic;
646 struct gmap *gmap;
647 unsigned long mem_limit;
648 int css_support;
649 int use_irqchip;
650 int use_cmma;
651 int use_pfmfi;
652 int use_skf;
653 int use_zpci_interp;
654 int user_cpu_state_ctrl;
655 int user_sigp;
656 int user_stsi;
657 int user_instr0;
658 int user_operexec;
659 struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
660 wait_queue_head_t ipte_wq;
661 int ipte_lock_count;
662 struct mutex ipte_mutex;
663 spinlock_t start_stop_lock;
664 struct sie_page2 *sie_page2;
665 struct kvm_s390_cpu_model model;
666 struct kvm_s390_crypto crypto;
667 struct kvm_s390_vsie vsie;
668 u8 epdx;
669 u64 epoch;
670 int migration_mode;
671 atomic64_t cmma_dirty_pages;
672 /* subset of available cpu features enabled by user space */
673 DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
674 /* indexed by vcpu_idx */
675 DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
676 struct kvm_s390_gisa_interrupt gisa_int;
677 struct kvm_s390_pv pv;
678 struct list_head kzdev_list;
679 spinlock_t kzdev_list_lock;
680 struct kvm_s390_mmu_cache *mc;
681 };
682
683 #define KVM_HVA_ERR_BAD (-1UL)
684 #define KVM_HVA_ERR_RO_BAD (-2UL)
685
kvm_is_error_hva(unsigned long addr)686 static inline bool kvm_is_error_hva(unsigned long addr)
687 {
688 return IS_ERR_VALUE(addr);
689 }
690
691 #define ASYNC_PF_PER_VCPU 64
692 struct kvm_arch_async_pf {
693 unsigned long pfault_token;
694 };
695
696 bool kvm_arch_can_dequeue_async_page_present(struct kvm_vcpu *vcpu);
697
698 void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
699 struct kvm_async_pf *work);
700
701 bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
702 struct kvm_async_pf *work);
703
704 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
705 struct kvm_async_pf *work);
706
kvm_arch_async_page_present_queued(struct kvm_vcpu * vcpu)707 static inline void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu) {}
708
709 void kvm_arch_crypto_clear_masks(struct kvm *kvm);
710 void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
711 unsigned long *aqm, unsigned long *adm);
712
713 #define SIE64_RETURN_NORMAL 0
714 #define SIE64_RETURN_MCCK 1
715
716 int __sie64a(phys_addr_t sie_block_phys, struct kvm_s390_sie_block *sie_block, u64 *rsa,
717 unsigned long gasce);
718
sie64a(struct kvm_s390_sie_block * sie_block,u64 * rsa,unsigned long gasce)719 static inline int sie64a(struct kvm_s390_sie_block *sie_block, u64 *rsa, unsigned long gasce)
720 {
721 return __sie64a(virt_to_phys(sie_block), sie_block, rsa, gasce);
722 }
723
724 extern char sie_exit;
725
726 bool kvm_s390_pv_is_protected(struct kvm *kvm);
727 bool kvm_s390_pv_cpu_is_protected(struct kvm_vcpu *vcpu);
728
729 extern int kvm_s390_enter_exit_sie(struct kvm_s390_sie_block *scb,
730 u64 *gprs, unsigned long gasce);
731
732 extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
733 extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
734
735 bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa);
736
kvm_arch_free_memslot(struct kvm * kvm,struct kvm_memory_slot * slot)737 static inline void kvm_arch_free_memslot(struct kvm *kvm,
738 struct kvm_memory_slot *slot) {}
kvm_arch_memslots_updated(struct kvm * kvm,u64 gen)739 static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
kvm_arch_flush_shadow_all(struct kvm * kvm)740 static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
kvm_arch_flush_shadow_memslot(struct kvm * kvm,struct kvm_memory_slot * slot)741 static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
742 struct kvm_memory_slot *slot) {}
kvm_arch_vcpu_blocking(struct kvm_vcpu * vcpu)743 static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
kvm_arch_vcpu_unblocking(struct kvm_vcpu * vcpu)744 static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
745
746 #define __KVM_HAVE_ARCH_VM_FREE
747 void kvm_arch_free_vm(struct kvm *kvm);
748
749 struct zpci_kvm_hook {
750 int (*kvm_register)(void *opaque, struct kvm *kvm);
751 void (*kvm_unregister)(void *opaque);
752 };
753
754 extern struct zpci_kvm_hook zpci_kvm_hook;
755
756 #endif
757