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 u64 signal_exits;
150 };
151
152 #define PGM_OPERATION 0x01
153 #define PGM_PRIVILEGED_OP 0x02
154 #define PGM_EXECUTE 0x03
155 #define PGM_PROTECTION 0x04
156 #define PGM_ADDRESSING 0x05
157 #define PGM_SPECIFICATION 0x06
158 #define PGM_DATA 0x07
159 #define PGM_FIXED_POINT_OVERFLOW 0x08
160 #define PGM_FIXED_POINT_DIVIDE 0x09
161 #define PGM_DECIMAL_OVERFLOW 0x0a
162 #define PGM_DECIMAL_DIVIDE 0x0b
163 #define PGM_HFP_EXPONENT_OVERFLOW 0x0c
164 #define PGM_HFP_EXPONENT_UNDERFLOW 0x0d
165 #define PGM_HFP_SIGNIFICANCE 0x0e
166 #define PGM_HFP_DIVIDE 0x0f
167 #define PGM_SEGMENT_TRANSLATION 0x10
168 #define PGM_PAGE_TRANSLATION 0x11
169 #define PGM_TRANSLATION_SPEC 0x12
170 #define PGM_SPECIAL_OPERATION 0x13
171 #define PGM_OPERAND 0x15
172 #define PGM_TRACE_TABEL 0x16
173 #define PGM_VECTOR_PROCESSING 0x1b
174 #define PGM_SPACE_SWITCH 0x1c
175 #define PGM_HFP_SQUARE_ROOT 0x1d
176 #define PGM_PC_TRANSLATION_SPEC 0x1f
177 #define PGM_AFX_TRANSLATION 0x20
178 #define PGM_ASX_TRANSLATION 0x21
179 #define PGM_LX_TRANSLATION 0x22
180 #define PGM_EX_TRANSLATION 0x23
181 #define PGM_PRIMARY_AUTHORITY 0x24
182 #define PGM_SECONDARY_AUTHORITY 0x25
183 #define PGM_LFX_TRANSLATION 0x26
184 #define PGM_LSX_TRANSLATION 0x27
185 #define PGM_ALET_SPECIFICATION 0x28
186 #define PGM_ALEN_TRANSLATION 0x29
187 #define PGM_ALE_SEQUENCE 0x2a
188 #define PGM_ASTE_VALIDITY 0x2b
189 #define PGM_ASTE_SEQUENCE 0x2c
190 #define PGM_EXTENDED_AUTHORITY 0x2d
191 #define PGM_LSTE_SEQUENCE 0x2e
192 #define PGM_ASTE_INSTANCE 0x2f
193 #define PGM_STACK_FULL 0x30
194 #define PGM_STACK_EMPTY 0x31
195 #define PGM_STACK_SPECIFICATION 0x32
196 #define PGM_STACK_TYPE 0x33
197 #define PGM_STACK_OPERATION 0x34
198 #define PGM_ASCE_TYPE 0x38
199 #define PGM_REGION_FIRST_TRANS 0x39
200 #define PGM_REGION_SECOND_TRANS 0x3a
201 #define PGM_REGION_THIRD_TRANS 0x3b
202 #define PGM_SECURE_STORAGE_ACCESS 0x3d
203 #define PGM_NON_SECURE_STORAGE_ACCESS 0x3e
204 #define PGM_SECURE_STORAGE_VIOLATION 0x3f
205 #define PGM_MONITOR 0x40
206 #define PGM_PER 0x80
207 #define PGM_CRYPTO_OPERATION 0x119
208
209 /* irq types in ascend order of priorities */
210 enum irq_types {
211 IRQ_PEND_SET_PREFIX = 0,
212 IRQ_PEND_RESTART,
213 IRQ_PEND_SIGP_STOP,
214 IRQ_PEND_IO_ISC_7,
215 IRQ_PEND_IO_ISC_6,
216 IRQ_PEND_IO_ISC_5,
217 IRQ_PEND_IO_ISC_4,
218 IRQ_PEND_IO_ISC_3,
219 IRQ_PEND_IO_ISC_2,
220 IRQ_PEND_IO_ISC_1,
221 IRQ_PEND_IO_ISC_0,
222 IRQ_PEND_VIRTIO,
223 IRQ_PEND_PFAULT_DONE,
224 IRQ_PEND_PFAULT_INIT,
225 IRQ_PEND_EXT_HOST,
226 IRQ_PEND_EXT_SERVICE,
227 IRQ_PEND_EXT_SERVICE_EV,
228 IRQ_PEND_EXT_TIMING,
229 IRQ_PEND_EXT_CPU_TIMER,
230 IRQ_PEND_EXT_CLOCK_COMP,
231 IRQ_PEND_EXT_EXTERNAL,
232 IRQ_PEND_EXT_EMERGENCY,
233 IRQ_PEND_EXT_MALFUNC,
234 IRQ_PEND_EXT_IRQ_KEY,
235 IRQ_PEND_MCHK_REP,
236 IRQ_PEND_PROG,
237 IRQ_PEND_SVC,
238 IRQ_PEND_MCHK_EX,
239 IRQ_PEND_COUNT
240 };
241
242 /* We have 2M for virtio device descriptor pages. Smallest amount of
243 * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381
244 */
245 #define KVM_S390_MAX_VIRTIO_IRQS 87381
246
247 /*
248 * Repressible (non-floating) machine check interrupts
249 * subclass bits in MCIC
250 */
251 #define MCHK_EXTD_BIT 58
252 #define MCHK_DEGR_BIT 56
253 #define MCHK_WARN_BIT 55
254 #define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \
255 (1UL << MCHK_EXTD_BIT) | \
256 (1UL << MCHK_WARN_BIT))
257
258 /* Exigent machine check interrupts subclass bits in MCIC */
259 #define MCHK_SD_BIT 63
260 #define MCHK_PD_BIT 62
261 #define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT))
262
263 #define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY) | \
264 (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
265 (1UL << IRQ_PEND_EXT_CPU_TIMER) | \
266 (1UL << IRQ_PEND_EXT_MALFUNC) | \
267 (1UL << IRQ_PEND_EXT_EMERGENCY) | \
268 (1UL << IRQ_PEND_EXT_EXTERNAL) | \
269 (1UL << IRQ_PEND_EXT_TIMING) | \
270 (1UL << IRQ_PEND_EXT_HOST) | \
271 (1UL << IRQ_PEND_EXT_SERVICE) | \
272 (1UL << IRQ_PEND_EXT_SERVICE_EV) | \
273 (1UL << IRQ_PEND_VIRTIO) | \
274 (1UL << IRQ_PEND_PFAULT_INIT) | \
275 (1UL << IRQ_PEND_PFAULT_DONE))
276
277 #define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \
278 (1UL << IRQ_PEND_IO_ISC_1) | \
279 (1UL << IRQ_PEND_IO_ISC_2) | \
280 (1UL << IRQ_PEND_IO_ISC_3) | \
281 (1UL << IRQ_PEND_IO_ISC_4) | \
282 (1UL << IRQ_PEND_IO_ISC_5) | \
283 (1UL << IRQ_PEND_IO_ISC_6) | \
284 (1UL << IRQ_PEND_IO_ISC_7))
285
286 #define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
287 (1UL << IRQ_PEND_MCHK_EX))
288
289 #define IRQ_PEND_EXT_II_MASK ((1UL << IRQ_PEND_EXT_CPU_TIMER) | \
290 (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
291 (1UL << IRQ_PEND_EXT_EMERGENCY) | \
292 (1UL << IRQ_PEND_EXT_EXTERNAL) | \
293 (1UL << IRQ_PEND_EXT_SERVICE) | \
294 (1UL << IRQ_PEND_EXT_SERVICE_EV))
295
296 struct kvm_s390_interrupt_info {
297 struct list_head list;
298 u64 type;
299 union {
300 struct kvm_s390_io_info io;
301 struct kvm_s390_ext_info ext;
302 struct kvm_s390_pgm_info pgm;
303 struct kvm_s390_emerg_info emerg;
304 struct kvm_s390_extcall_info extcall;
305 struct kvm_s390_prefix_info prefix;
306 struct kvm_s390_stop_info stop;
307 struct kvm_s390_mchk_info mchk;
308 };
309 };
310
311 struct kvm_s390_irq_payload {
312 struct kvm_s390_io_info io;
313 struct kvm_s390_ext_info ext;
314 struct kvm_s390_pgm_info pgm;
315 struct kvm_s390_emerg_info emerg;
316 struct kvm_s390_extcall_info extcall;
317 struct kvm_s390_prefix_info prefix;
318 struct kvm_s390_stop_info stop;
319 struct kvm_s390_mchk_info mchk;
320 };
321
322 struct kvm_s390_local_interrupt {
323 spinlock_t lock;
324 DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
325 struct kvm_s390_irq_payload irq;
326 unsigned long pending_irqs;
327 };
328
329 #define FIRQ_LIST_IO_ISC_0 0
330 #define FIRQ_LIST_IO_ISC_1 1
331 #define FIRQ_LIST_IO_ISC_2 2
332 #define FIRQ_LIST_IO_ISC_3 3
333 #define FIRQ_LIST_IO_ISC_4 4
334 #define FIRQ_LIST_IO_ISC_5 5
335 #define FIRQ_LIST_IO_ISC_6 6
336 #define FIRQ_LIST_IO_ISC_7 7
337 #define FIRQ_LIST_PFAULT 8
338 #define FIRQ_LIST_VIRTIO 9
339 #define FIRQ_LIST_COUNT 10
340 #define FIRQ_CNTR_IO 0
341 #define FIRQ_CNTR_SERVICE 1
342 #define FIRQ_CNTR_VIRTIO 2
343 #define FIRQ_CNTR_PFAULT 3
344 #define FIRQ_MAX_COUNT 4
345
346 /* mask the AIS mode for a given ISC */
347 #define AIS_MODE_MASK(isc) (0x80 >> isc)
348
349 #define KVM_S390_AIS_MODE_ALL 0
350 #define KVM_S390_AIS_MODE_SINGLE 1
351
352 struct kvm_s390_float_interrupt {
353 unsigned long pending_irqs;
354 unsigned long masked_irqs;
355 spinlock_t lock;
356 struct list_head lists[FIRQ_LIST_COUNT];
357 int counters[FIRQ_MAX_COUNT];
358 struct kvm_s390_mchk_info mchk;
359 struct kvm_s390_ext_info srv_signal;
360 int last_sleep_cpu;
361 struct mutex ais_lock;
362 u8 simm;
363 u8 nimm;
364 };
365
366 struct kvm_hw_wp_info_arch {
367 unsigned long addr;
368 unsigned long phys_addr;
369 int len;
370 char *old_data;
371 };
372
373 struct kvm_hw_bp_info_arch {
374 unsigned long addr;
375 int len;
376 };
377
378 /*
379 * Only the upper 16 bits of kvm_guest_debug->control are arch specific.
380 * Further KVM_GUESTDBG flags which an be used from userspace can be found in
381 * arch/s390/include/uapi/asm/kvm.h
382 */
383 #define KVM_GUESTDBG_EXIT_PENDING 0x10000000
384
385 #define guestdbg_enabled(vcpu) \
386 (vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
387 #define guestdbg_sstep_enabled(vcpu) \
388 (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
389 #define guestdbg_hw_bp_enabled(vcpu) \
390 (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
391 #define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
392 (vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
393
394 #define KVM_GUESTDBG_VALID_MASK \
395 (KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP |\
396 KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_EXIT_PENDING)
397
398 struct kvm_guestdbg_info_arch {
399 unsigned long cr0;
400 unsigned long cr9;
401 unsigned long cr10;
402 unsigned long cr11;
403 struct kvm_hw_bp_info_arch *hw_bp_info;
404 struct kvm_hw_wp_info_arch *hw_wp_info;
405 int nr_hw_bp;
406 int nr_hw_wp;
407 unsigned long last_bp;
408 };
409
410 struct kvm_s390_pv_vcpu {
411 u64 handle;
412 unsigned long stor_base;
413 };
414
415 struct kvm_vcpu_arch {
416 struct kvm_s390_sie_block *sie_block;
417 /* if vsie is active, currently executed shadow sie control block */
418 struct kvm_s390_sie_block *vsie_block;
419 unsigned int host_acrs[NUM_ACRS];
420 struct gs_cb *host_gscb;
421 struct kvm_s390_local_interrupt local_int;
422 struct hrtimer ckc_timer;
423 struct kvm_s390_pgm_info pgm;
424 struct gmap *gmap;
425 struct kvm_guestdbg_info_arch guestdbg;
426 unsigned long pfault_token;
427 unsigned long pfault_select;
428 unsigned long pfault_compare;
429 bool cputm_enabled;
430 /*
431 * The seqcount protects updates to cputm_start and sie_block.cputm,
432 * this way we can have non-blocking reads with consistent values.
433 * Only the owning VCPU thread (vcpu->cpu) is allowed to change these
434 * values and to start/stop/enable/disable cpu timer accounting.
435 */
436 seqcount_t cputm_seqcount;
437 __u64 cputm_start;
438 bool gs_enabled;
439 bool skey_enabled;
440 /* Indicator if the access registers have been loaded from guest */
441 bool acrs_loaded;
442 struct kvm_s390_pv_vcpu pv;
443 union diag318_info diag318_info;
444 };
445
446 struct kvm_vm_stat {
447 struct kvm_vm_stat_generic generic;
448 u64 inject_io;
449 u64 inject_float_mchk;
450 u64 inject_pfault_done;
451 u64 inject_service_signal;
452 u64 inject_virtio;
453 u64 aen_forward;
454 u64 gmap_shadow_create;
455 u64 gmap_shadow_reuse;
456 u64 gmap_shadow_r1_entry;
457 u64 gmap_shadow_r2_entry;
458 u64 gmap_shadow_r3_entry;
459 u64 gmap_shadow_sg_entry;
460 u64 gmap_shadow_pg_entry;
461 };
462
463 struct kvm_arch_memory_slot {
464 };
465
466 struct s390_map_info {
467 struct list_head list;
468 __u64 guest_addr;
469 __u64 addr;
470 struct page *page;
471 };
472
473 struct s390_io_adapter {
474 unsigned int id;
475 int isc;
476 bool maskable;
477 bool masked;
478 bool swap;
479 bool suppressible;
480 };
481
482 #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
483 #define MAX_S390_ADAPTER_MAPS 256
484
485 /* maximum size of facilities and facility mask is 2k bytes */
486 #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
487 #define S390_ARCH_FAC_LIST_SIZE_U64 \
488 (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
489 #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
490 #define S390_ARCH_FAC_MASK_SIZE_U64 \
491 (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
492
493 struct kvm_s390_cpu_model {
494 /* facility mask supported by kvm & hosting machine */
495 __u64 fac_mask[S390_ARCH_FAC_MASK_SIZE_U64];
496 struct kvm_s390_vm_cpu_subfunc subfuncs;
497 /* facility list requested by guest (in dma page) */
498 __u64 *fac_list;
499 u64 cpuid;
500 unsigned short ibc;
501 /* subset of available UV-features for pv-guests enabled by user space */
502 struct kvm_s390_vm_cpu_uv_feat uv_feat_guest;
503 };
504
505 typedef int (*crypto_hook)(struct kvm_vcpu *vcpu);
506
507 struct kvm_s390_crypto {
508 struct kvm_s390_crypto_cb *crycb;
509 struct rw_semaphore pqap_hook_rwsem;
510 crypto_hook *pqap_hook;
511 __u32 crycbd;
512 __u8 aes_kw;
513 __u8 dea_kw;
514 __u8 apie;
515 };
516
517 #define APCB0_MASK_SIZE 1
518 struct kvm_s390_apcb0 {
519 __u64 apm[APCB0_MASK_SIZE]; /* 0x0000 */
520 __u64 aqm[APCB0_MASK_SIZE]; /* 0x0008 */
521 __u64 adm[APCB0_MASK_SIZE]; /* 0x0010 */
522 __u64 reserved18; /* 0x0018 */
523 };
524
525 #define APCB1_MASK_SIZE 4
526 struct kvm_s390_apcb1 {
527 __u64 apm[APCB1_MASK_SIZE]; /* 0x0000 */
528 __u64 aqm[APCB1_MASK_SIZE]; /* 0x0020 */
529 __u64 adm[APCB1_MASK_SIZE]; /* 0x0040 */
530 __u64 reserved60[4]; /* 0x0060 */
531 };
532
533 struct kvm_s390_crypto_cb {
534 struct kvm_s390_apcb0 apcb0; /* 0x0000 */
535 __u8 reserved20[0x0048 - 0x0020]; /* 0x0020 */
536 __u8 dea_wrapping_key_mask[24]; /* 0x0048 */
537 __u8 aes_wrapping_key_mask[32]; /* 0x0060 */
538 struct kvm_s390_apcb1 apcb1; /* 0x0080 */
539 };
540
541 struct kvm_s390_gisa {
542 union {
543 struct { /* common to all formats */
544 u32 next_alert;
545 u8 ipm;
546 u8 reserved01[2];
547 u8 iam;
548 };
549 struct { /* format 0 */
550 u32 next_alert;
551 u8 ipm;
552 u8 reserved01;
553 u8 : 6;
554 u8 g : 1;
555 u8 c : 1;
556 u8 iam;
557 u8 reserved02[4];
558 u32 airq_count;
559 } g0;
560 struct { /* format 1 */
561 u32 next_alert;
562 u8 ipm;
563 u8 simm;
564 u8 nimm;
565 u8 iam;
566 u8 aism[8];
567 u8 : 6;
568 u8 g : 1;
569 u8 c : 1;
570 u8 reserved03[11];
571 u32 airq_count;
572 } g1;
573 struct {
574 u64 word[4];
575 } u64;
576 };
577 };
578
579 struct kvm_s390_gib {
580 u32 alert_list_origin;
581 u32 reserved01;
582 u8:5;
583 u8 nisc:3;
584 u8 reserved03[3];
585 u32 reserved04[5];
586 };
587
588 /*
589 * sie_page2 has to be allocated as DMA because fac_list, crycb and
590 * gisa need 31bit addresses in the sie control block.
591 */
592 struct sie_page2 {
593 __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */
594 struct kvm_s390_crypto_cb crycb; /* 0x0800 */
595 struct kvm_s390_gisa gisa; /* 0x0900 */
596 struct kvm *kvm; /* 0x0920 */
597 u8 reserved928[0x1000 - 0x928]; /* 0x0928 */
598 };
599
600 struct vsie_page;
601
602 struct kvm_s390_vsie {
603 struct mutex mutex;
604 struct radix_tree_root addr_to_page;
605 int page_count;
606 int next;
607 struct vsie_page *pages[KVM_MAX_VCPUS];
608 };
609
610 struct kvm_s390_gisa_iam {
611 u8 mask;
612 spinlock_t ref_lock;
613 u32 ref_count[MAX_ISC + 1];
614 };
615
616 struct kvm_s390_gisa_interrupt {
617 struct kvm_s390_gisa *origin;
618 struct kvm_s390_gisa_iam alert;
619 struct hrtimer timer;
620 u64 expires;
621 DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS);
622 };
623
624 struct kvm_s390_pv {
625 u64 handle;
626 u64 guest_len;
627 unsigned long stor_base;
628 void *stor_var;
629 bool dumping;
630 void *set_aside;
631 struct list_head need_cleanup;
632 struct mmu_notifier mmu_notifier;
633 };
634
635 struct kvm_arch {
636 struct esca_block *sca;
637 debug_info_t *dbf;
638 struct kvm_s390_float_interrupt float_int;
639 struct kvm_device *flic;
640 struct gmap *gmap;
641 unsigned long mem_limit;
642 int css_support;
643 int use_irqchip;
644 int use_cmma;
645 int use_pfmfi;
646 int use_skf;
647 int use_zpci_interp;
648 int user_cpu_state_ctrl;
649 int user_sigp;
650 int user_stsi;
651 int user_instr0;
652 int user_operexec;
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_enter_exit_sie(struct kvm_s390_sie_block *scb,
720 u64 *gprs, unsigned long gasce);
721
722 extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
723 extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
724
725 bool kvm_s390_is_gpa_in_memslot(struct kvm *kvm, gpa_t gpa);
726
kvm_arch_free_memslot(struct kvm * kvm,struct kvm_memory_slot * slot)727 static inline void kvm_arch_free_memslot(struct kvm *kvm,
728 struct kvm_memory_slot *slot) {}
kvm_arch_memslots_updated(struct kvm * kvm,u64 gen)729 static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
kvm_arch_flush_shadow_all(struct kvm * kvm)730 static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
kvm_arch_flush_shadow_memslot(struct kvm * kvm,struct kvm_memory_slot * slot)731 static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
732 struct kvm_memory_slot *slot) {}
kvm_arch_vcpu_blocking(struct kvm_vcpu * vcpu)733 static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
kvm_arch_vcpu_unblocking(struct kvm_vcpu * vcpu)734 static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
735
736 #define __KVM_HAVE_ARCH_VM_FREE
737 void kvm_arch_free_vm(struct kvm *kvm);
738
739 struct zpci_kvm_hook {
740 int (*kvm_register)(void *opaque, struct kvm *kvm);
741 void (*kvm_unregister)(void *opaque);
742 };
743
744 extern struct zpci_kvm_hook zpci_kvm_hook;
745
746 #endif
747