hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/s390/include/asm/kvm_host.h
....@@ -18,6 +18,7 @@
1818 #include <linux/kvm_host.h>
1919 #include <linux/kvm.h>
2020 #include <linux/seqlock.h>
21
+#include <linux/module.h>
2122 #include <asm/debug.h>
2223 #include <asm/cpu.h>
2324 #include <asm/fpu/api.h>
....@@ -36,7 +37,7 @@
3637 */
3738 #define KVM_NR_IRQCHIPS 1
3839 #define KVM_IRQCHIP_NUM_PINS 1
39
-#define KVM_HALT_POLL_NS_DEFAULT 80000
40
+#define KVM_HALT_POLL_NS_DEFAULT 50000
4041
4142 /* s390-specific vcpu->requests bit members */
4243 #define KVM_REQ_ENABLE_IBS KVM_ARCH_REQ(0)
....@@ -44,6 +45,7 @@
4445 #define KVM_REQ_ICPT_OPEREXC KVM_ARCH_REQ(2)
4546 #define KVM_REQ_START_MIGRATION KVM_ARCH_REQ(3)
4647 #define KVM_REQ_STOP_MIGRATION KVM_ARCH_REQ(4)
48
+#define KVM_REQ_VSIE_RESTART KVM_ARCH_REQ(5)
4749
4850 #define SIGP_CTRL_C 0x80
4951 #define SIGP_CTRL_SCN_MASK 0x3f
....@@ -120,6 +122,17 @@
120122 __u32 reserved;
121123 };
122124
125
+#define CR0_INITIAL_MASK (CR0_UNUSED_56 | CR0_INTERRUPT_KEY_SUBMASK | \
126
+ CR0_MEASUREMENT_ALERT_SUBMASK)
127
+#define CR14_INITIAL_MASK (CR14_UNUSED_32 | CR14_UNUSED_33 | \
128
+ CR14_EXTERNAL_DAMAGE_SUBMASK)
129
+
130
+#define SIDAD_SIZE_MASK 0xff
131
+#define sida_origin(sie_block) \
132
+ ((sie_block)->sidad & PAGE_MASK)
133
+#define sida_size(sie_block) \
134
+ ((((sie_block)->sidad & SIDAD_SIZE_MASK) + 1) * PAGE_SIZE)
135
+
123136 #define CPUSTAT_STOPPED 0x80000000
124137 #define CPUSTAT_WAIT 0x10000000
125138 #define CPUSTAT_ECALL_PEND 0x08000000
....@@ -153,7 +166,13 @@
153166 __u8 reserved08[4]; /* 0x0008 */
154167 #define PROG_IN_SIE (1<<0)
155168 __u32 prog0c; /* 0x000c */
156
- __u8 reserved10[16]; /* 0x0010 */
169
+ union {
170
+ __u8 reserved10[16]; /* 0x0010 */
171
+ struct {
172
+ __u64 pv_handle_cpu;
173
+ __u64 pv_handle_config;
174
+ };
175
+ };
157176 #define PROG_BLOCK_SIE (1<<0)
158177 #define PROG_REQUEST (1<<1)
159178 atomic_t prog20; /* 0x0020 */
....@@ -186,6 +205,7 @@
186205 #define ECA_AIV 0x00200000
187206 #define ECA_VX 0x00020000
188207 #define ECA_PROTEXCI 0x00002000
208
+#define ECA_APIE 0x00000008
189209 #define ECA_SII 0x00000001
190210 __u32 eca; /* 0x004c */
191211 #define ICPT_INST 0x04
....@@ -201,10 +221,23 @@
201221 #define ICPT_PARTEXEC 0x38
202222 #define ICPT_IOINST 0x40
203223 #define ICPT_KSS 0x5c
224
+#define ICPT_MCHKREQ 0x60
225
+#define ICPT_INT_ENABLE 0x64
226
+#define ICPT_PV_INSTR 0x68
227
+#define ICPT_PV_NOTIFY 0x6c
228
+#define ICPT_PV_PREF 0x70
204229 __u8 icptcode; /* 0x0050 */
205230 __u8 icptstatus; /* 0x0051 */
206231 __u16 ihcpu; /* 0x0052 */
207
- __u8 reserved54[2]; /* 0x0054 */
232
+ __u8 reserved54; /* 0x0054 */
233
+#define IICTL_CODE_NONE 0x00
234
+#define IICTL_CODE_MCHK 0x01
235
+#define IICTL_CODE_EXT 0x02
236
+#define IICTL_CODE_IO 0x03
237
+#define IICTL_CODE_RESTART 0x04
238
+#define IICTL_CODE_SPECIFICATION 0x10
239
+#define IICTL_CODE_OPERAND 0x11
240
+ __u8 iictl; /* 0x0055 */
208241 __u16 ipa; /* 0x0056 */
209242 __u32 ipb; /* 0x0058 */
210243 __u32 scaoh; /* 0x005c */
....@@ -225,9 +258,10 @@
225258 #define ECB3_RI 0x01
226259 __u8 ecb3; /* 0x0063 */
227260 __u32 scaol; /* 0x0064 */
228
- __u8 reserved68; /* 0x0068 */
261
+ __u8 sdf; /* 0x0068 */
229262 __u8 epdx; /* 0x0069 */
230
- __u8 reserved6a[2]; /* 0x006a */
263
+ __u8 cpnc; /* 0x006a */
264
+ __u8 reserved6b; /* 0x006b */
231265 __u32 todpr; /* 0x006c */
232266 #define GISA_FORMAT1 0x00000001
233267 __u32 gd; /* 0x0070 */
....@@ -237,29 +271,62 @@
237271 psw_t gpsw; /* 0x0090 */
238272 __u64 gg14; /* 0x00a0 */
239273 __u64 gg15; /* 0x00a8 */
240
- __u8 reservedb0[20]; /* 0x00b0 */
241
- __u16 extcpuaddr; /* 0x00c4 */
242
- __u16 eic; /* 0x00c6 */
274
+ __u8 reservedb0[8]; /* 0x00b0 */
275
+#define HPID_KVM 0x4
276
+#define HPID_VSIE 0x5
277
+ __u8 hpid; /* 0x00b8 */
278
+ __u8 reservedb9[7]; /* 0x00b9 */
279
+ union {
280
+ struct {
281
+ __u32 eiparams; /* 0x00c0 */
282
+ __u16 extcpuaddr; /* 0x00c4 */
283
+ __u16 eic; /* 0x00c6 */
284
+ };
285
+ __u64 mcic; /* 0x00c0 */
286
+ } __packed;
243287 __u32 reservedc8; /* 0x00c8 */
244
- __u16 pgmilc; /* 0x00cc */
245
- __u16 iprcc; /* 0x00ce */
246
- __u32 dxc; /* 0x00d0 */
247
- __u16 mcn; /* 0x00d4 */
248
- __u8 perc; /* 0x00d6 */
249
- __u8 peratmid; /* 0x00d7 */
288
+ union {
289
+ struct {
290
+ __u16 pgmilc; /* 0x00cc */
291
+ __u16 iprcc; /* 0x00ce */
292
+ };
293
+ __u32 edc; /* 0x00cc */
294
+ } __packed;
295
+ union {
296
+ struct {
297
+ __u32 dxc; /* 0x00d0 */
298
+ __u16 mcn; /* 0x00d4 */
299
+ __u8 perc; /* 0x00d6 */
300
+ __u8 peratmid; /* 0x00d7 */
301
+ };
302
+ __u64 faddr; /* 0x00d0 */
303
+ } __packed;
250304 __u64 peraddr; /* 0x00d8 */
251305 __u8 eai; /* 0x00e0 */
252306 __u8 peraid; /* 0x00e1 */
253307 __u8 oai; /* 0x00e2 */
254308 __u8 armid; /* 0x00e3 */
255309 __u8 reservede4[4]; /* 0x00e4 */
256
- __u64 tecmc; /* 0x00e8 */
257
- __u8 reservedf0[12]; /* 0x00f0 */
310
+ union {
311
+ __u64 tecmc; /* 0x00e8 */
312
+ struct {
313
+ __u16 subchannel_id; /* 0x00e8 */
314
+ __u16 subchannel_nr; /* 0x00ea */
315
+ __u32 io_int_parm; /* 0x00ec */
316
+ __u32 io_int_word; /* 0x00f0 */
317
+ };
318
+ } __packed;
319
+ __u8 reservedf4[8]; /* 0x00f4 */
320
+#define CRYCB_FORMAT_MASK 0x00000003
321
+#define CRYCB_FORMAT0 0x00000000
258322 #define CRYCB_FORMAT1 0x00000001
259323 #define CRYCB_FORMAT2 0x00000003
260324 __u32 crycbd; /* 0x00fc */
261325 __u64 gcr[16]; /* 0x0100 */
262
- __u64 gbea; /* 0x0180 */
326
+ union {
327
+ __u64 gbea; /* 0x0180 */
328
+ __u64 sidad;
329
+ };
263330 __u8 reserved188[8]; /* 0x0188 */
264331 __u64 sdnxo; /* 0x0190 */
265332 __u8 reserved198[8]; /* 0x0198 */
....@@ -270,6 +337,7 @@
270337 #define ECD_HOSTREGMGMT 0x20000000
271338 #define ECD_MEF 0x08000000
272339 #define ECD_ETOKENF 0x02000000
340
+#define ECD_ECC 0x00200000
273341 __u32 ecd; /* 0x01c8 */
274342 __u8 reserved1cc[18]; /* 0x01cc */
275343 __u64 pp; /* 0x01de */
....@@ -277,7 +345,7 @@
277345 __u64 itdba; /* 0x01e8 */
278346 __u64 riccbd; /* 0x01f0 */
279347 __u64 gvrd; /* 0x01f8 */
280
-} __attribute__((packed));
348
+} __packed __aligned(512);
281349
282350 struct kvm_s390_itdb {
283351 __u8 data[256];
....@@ -286,7 +354,9 @@
286354 struct sie_page {
287355 struct kvm_s390_sie_block sie_block;
288356 struct mcck_volatile_info mcck_info; /* 0x0200 */
289
- __u8 reserved218[1000]; /* 0x0218 */
357
+ __u8 reserved218[360]; /* 0x0218 */
358
+ __u64 pv_grregs[16]; /* 0x0380 */
359
+ __u8 reserved400[512]; /* 0x0400 */
290360 struct kvm_s390_itdb itdb; /* 0x0600 */
291361 __u8 reserved700[2304]; /* 0x0700 */
292362 };
....@@ -304,7 +374,10 @@
304374 u64 halt_successful_poll;
305375 u64 halt_attempted_poll;
306376 u64 halt_poll_invalid;
377
+ u64 halt_no_poll_steal;
307378 u64 halt_wakeup;
379
+ u64 halt_poll_success_ns;
380
+ u64 halt_poll_fail_ns;
308381 u64 instruction_lctl;
309382 u64 instruction_lctlg;
310383 u64 instruction_stctl;
....@@ -381,6 +454,7 @@
381454 u64 diagnose_10;
382455 u64 diagnose_44;
383456 u64 diagnose_9c;
457
+ u64 diagnose_9c_ignored;
384458 u64 diagnose_258;
385459 u64 diagnose_308;
386460 u64 diagnose_500;
....@@ -459,6 +533,7 @@
459533 IRQ_PEND_PFAULT_INIT,
460534 IRQ_PEND_EXT_HOST,
461535 IRQ_PEND_EXT_SERVICE,
536
+ IRQ_PEND_EXT_SERVICE_EV,
462537 IRQ_PEND_EXT_TIMING,
463538 IRQ_PEND_EXT_CPU_TIMER,
464539 IRQ_PEND_EXT_CLOCK_COMP,
....@@ -503,6 +578,7 @@
503578 (1UL << IRQ_PEND_EXT_TIMING) | \
504579 (1UL << IRQ_PEND_EXT_HOST) | \
505580 (1UL << IRQ_PEND_EXT_SERVICE) | \
581
+ (1UL << IRQ_PEND_EXT_SERVICE_EV) | \
506582 (1UL << IRQ_PEND_VIRTIO) | \
507583 (1UL << IRQ_PEND_PFAULT_INIT) | \
508584 (1UL << IRQ_PEND_PFAULT_DONE))
....@@ -518,6 +594,13 @@
518594
519595 #define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
520596 (1UL << IRQ_PEND_MCHK_EX))
597
+
598
+#define IRQ_PEND_EXT_II_MASK ((1UL << IRQ_PEND_EXT_CPU_TIMER) | \
599
+ (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
600
+ (1UL << IRQ_PEND_EXT_EMERGENCY) | \
601
+ (1UL << IRQ_PEND_EXT_EXTERNAL) | \
602
+ (1UL << IRQ_PEND_EXT_SERVICE) | \
603
+ (1UL << IRQ_PEND_EXT_SERVICE_EV))
521604
522605 struct kvm_s390_interrupt_info {
523606 struct list_head list;
....@@ -577,13 +660,13 @@
577660
578661 struct kvm_s390_float_interrupt {
579662 unsigned long pending_irqs;
663
+ unsigned long masked_irqs;
580664 spinlock_t lock;
581665 struct list_head lists[FIRQ_LIST_COUNT];
582666 int counters[FIRQ_MAX_COUNT];
583667 struct kvm_s390_mchk_info mchk;
584668 struct kvm_s390_ext_info srv_signal;
585669 int next_rr_cpu;
586
- unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
587670 struct mutex ais_lock;
588671 u8 simm;
589672 u8 nimm;
....@@ -629,6 +712,11 @@
629712 unsigned long last_bp;
630713 };
631714
715
+struct kvm_s390_pv_vcpu {
716
+ u64 handle;
717
+ unsigned long stor_base;
718
+};
719
+
632720 struct kvm_vcpu_arch {
633721 struct kvm_s390_sie_block *sie_block;
634722 /* if vsie is active, currently executed shadow sie control block */
....@@ -657,6 +745,8 @@
657745 __u64 cputm_start;
658746 bool gs_enabled;
659747 bool skey_enabled;
748
+ struct kvm_s390_pv_vcpu pv;
749
+ union diag318_info diag318_info;
660750 };
661751
662752 struct kvm_vm_stat {
....@@ -685,9 +775,6 @@
685775 bool masked;
686776 bool swap;
687777 bool suppressible;
688
- struct rw_semaphore maps_lock;
689
- struct list_head maps;
690
- atomic_t nr_maps;
691778 };
692779
693780 #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
....@@ -704,17 +791,25 @@
704791 struct kvm_s390_cpu_model {
705792 /* facility mask supported by kvm & hosting machine */
706793 __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64];
794
+ struct kvm_s390_vm_cpu_subfunc subfuncs;
707795 /* facility list requested by guest (in dma page) */
708796 __u64 *fac_list;
709797 u64 cpuid;
710798 unsigned short ibc;
711799 };
712800
801
+struct kvm_s390_module_hook {
802
+ int (*hook)(struct kvm_vcpu *vcpu);
803
+ struct module *owner;
804
+};
805
+
713806 struct kvm_s390_crypto {
714807 struct kvm_s390_crypto_cb *crycb;
808
+ struct kvm_s390_module_hook *pqap_hook;
715809 __u32 crycbd;
716810 __u8 aes_kw;
717811 __u8 dea_kw;
812
+ __u8 apie;
718813 };
719814
720815 #define APCB0_MASK_SIZE 1
....@@ -773,7 +868,19 @@
773868 u8 reserved03[11];
774869 u32 airq_count;
775870 } g1;
871
+ struct {
872
+ u64 word[4];
873
+ } u64;
776874 };
875
+};
876
+
877
+struct kvm_s390_gib {
878
+ u32 alert_list_origin;
879
+ u32 reserved01;
880
+ u8:5;
881
+ u8 nisc:3;
882
+ u8 reserved03[3];
883
+ u32 reserved04[5];
777884 };
778885
779886 /*
....@@ -784,7 +891,8 @@
784891 __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */
785892 struct kvm_s390_crypto_cb crycb; /* 0x0800 */
786893 struct kvm_s390_gisa gisa; /* 0x0900 */
787
- u8 reserved920[0x1000 - 0x920]; /* 0x0920 */
894
+ struct kvm *kvm; /* 0x0920 */
895
+ u8 reserved928[0x1000 - 0x928]; /* 0x0928 */
788896 };
789897
790898 struct kvm_s390_vsie {
....@@ -793,6 +901,27 @@
793901 int page_count;
794902 int next;
795903 struct page *pages[KVM_MAX_VCPUS];
904
+};
905
+
906
+struct kvm_s390_gisa_iam {
907
+ u8 mask;
908
+ spinlock_t ref_lock;
909
+ u32 ref_count[MAX_ISC + 1];
910
+};
911
+
912
+struct kvm_s390_gisa_interrupt {
913
+ struct kvm_s390_gisa *origin;
914
+ struct kvm_s390_gisa_iam alert;
915
+ struct hrtimer timer;
916
+ u64 expires;
917
+ DECLARE_BITMAP(kicked_mask, KVM_MAX_VCPUS);
918
+};
919
+
920
+struct kvm_s390_pv {
921
+ u64 handle;
922
+ u64 guest_len;
923
+ unsigned long stor_base;
924
+ void *stor_var;
796925 };
797926
798927 struct kvm_arch{
....@@ -828,7 +957,10 @@
828957 atomic64_t cmma_dirty_pages;
829958 /* subset of available cpu features enabled by user space */
830959 DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
831
- struct kvm_s390_gisa *gisa;
960
+ /* indexed by vcpu_idx */
961
+ DECLARE_BITMAP(idle_mask, KVM_MAX_VCPUS);
962
+ struct kvm_s390_gisa_interrupt gisa_int;
963
+ struct kvm_s390_pv pv;
832964 };
833965
834966 #define KVM_HVA_ERR_BAD (-1UL)
....@@ -844,27 +976,34 @@
844976 unsigned long pfault_token;
845977 };
846978
847
-bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
979
+bool kvm_arch_can_dequeue_async_page_present(struct kvm_vcpu *vcpu);
848980
849981 void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
850982 struct kvm_async_pf *work);
851983
852
-void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
984
+bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
853985 struct kvm_async_pf *work);
854986
855987 void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
856988 struct kvm_async_pf *work);
857989
990
+static inline void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu) {}
991
+
992
+void kvm_arch_crypto_clear_masks(struct kvm *kvm);
993
+void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
994
+ unsigned long *aqm, unsigned long *adm);
995
+
858996 extern int sie64a(struct kvm_s390_sie_block *, u64 *);
859997 extern char sie_exit;
860998
999
+extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc);
1000
+extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc);
1001
+
8611002 static inline void kvm_arch_hardware_disable(void) {}
862
-static inline void kvm_arch_check_processor_compat(void *rtn) {}
8631003 static inline void kvm_arch_sync_events(struct kvm *kvm) {}
864
-static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
8651004 static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
8661005 static inline void kvm_arch_free_memslot(struct kvm *kvm,
867
- struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
1006
+ struct kvm_memory_slot *slot) {}
8681007 static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
8691008 static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
8701009 static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,