kvm_host.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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. #ifndef ASM_KVM_HOST_H
  10. #define ASM_KVM_HOST_H
  11. #include <linux/types.h>
  12. #include <linux/hrtimer.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kvm_types.h>
  15. #include <linux/kvm_host.h>
  16. #include <linux/kvm.h>
  17. #include <linux/seqlock.h>
  18. #include <asm/debug.h>
  19. #include <asm/cpu.h>
  20. #include <asm/fpu/api.h>
  21. #include <asm/isc.h>
  22. #include <asm/guarded_storage.h>
  23. #define KVM_S390_BSCA_CPU_SLOTS 64
  24. #define KVM_S390_ESCA_CPU_SLOTS 248
  25. #define KVM_MAX_VCPUS 255
  26. #define KVM_USER_MEM_SLOTS 32
  27. /*
  28. * These seem to be used for allocating ->chip in the routing table,
  29. * which we don't use. 4096 is an out-of-thin-air value. If we need
  30. * to look at ->chip later on, we'll need to revisit this.
  31. */
  32. #define KVM_NR_IRQCHIPS 1
  33. #define KVM_IRQCHIP_NUM_PINS 4096
  34. #define KVM_HALT_POLL_NS_DEFAULT 80000
  35. /* s390-specific vcpu->requests bit members */
  36. #define KVM_REQ_ENABLE_IBS KVM_ARCH_REQ(0)
  37. #define KVM_REQ_DISABLE_IBS KVM_ARCH_REQ(1)
  38. #define KVM_REQ_ICPT_OPEREXC KVM_ARCH_REQ(2)
  39. #define KVM_REQ_START_MIGRATION KVM_ARCH_REQ(3)
  40. #define KVM_REQ_STOP_MIGRATION KVM_ARCH_REQ(4)
  41. #define KVM_REQ_VSIE_RESTART KVM_ARCH_REQ(5)
  42. #define SIGP_CTRL_C 0x80
  43. #define SIGP_CTRL_SCN_MASK 0x3f
  44. union bsca_sigp_ctrl {
  45. __u8 value;
  46. struct {
  47. __u8 c : 1;
  48. __u8 r : 1;
  49. __u8 scn : 6;
  50. };
  51. };
  52. union esca_sigp_ctrl {
  53. __u16 value;
  54. struct {
  55. __u8 c : 1;
  56. __u8 reserved: 7;
  57. __u8 scn;
  58. };
  59. };
  60. struct esca_entry {
  61. union esca_sigp_ctrl sigp_ctrl;
  62. __u16 reserved1[3];
  63. __u64 sda;
  64. __u64 reserved2[6];
  65. };
  66. struct bsca_entry {
  67. __u8 reserved0;
  68. union bsca_sigp_ctrl sigp_ctrl;
  69. __u16 reserved[3];
  70. __u64 sda;
  71. __u64 reserved2[2];
  72. };
  73. union ipte_control {
  74. unsigned long val;
  75. struct {
  76. unsigned long k : 1;
  77. unsigned long kh : 31;
  78. unsigned long kg : 32;
  79. };
  80. };
  81. struct bsca_block {
  82. union ipte_control ipte_control;
  83. __u64 reserved[5];
  84. __u64 mcn;
  85. __u64 reserved2;
  86. struct bsca_entry cpu[KVM_S390_BSCA_CPU_SLOTS];
  87. };
  88. struct esca_block {
  89. union ipte_control ipte_control;
  90. __u64 reserved1[7];
  91. __u64 mcn[4];
  92. __u64 reserved2[20];
  93. struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
  94. };
  95. /*
  96. * This struct is used to store some machine check info from lowcore
  97. * for machine checks that happen while the guest is running.
  98. * This info in host's lowcore might be overwritten by a second machine
  99. * check from host when host is in the machine check's high-level handling.
  100. * The size is 24 bytes.
  101. */
  102. struct mcck_volatile_info {
  103. __u64 mcic;
  104. __u64 failing_storage_address;
  105. __u32 ext_damage_code;
  106. __u32 reserved;
  107. };
  108. #define CPUSTAT_STOPPED 0x80000000
  109. #define CPUSTAT_WAIT 0x10000000
  110. #define CPUSTAT_ECALL_PEND 0x08000000
  111. #define CPUSTAT_STOP_INT 0x04000000
  112. #define CPUSTAT_IO_INT 0x02000000
  113. #define CPUSTAT_EXT_INT 0x01000000
  114. #define CPUSTAT_RUNNING 0x00800000
  115. #define CPUSTAT_RETAINED 0x00400000
  116. #define CPUSTAT_TIMING_SUB 0x00020000
  117. #define CPUSTAT_SIE_SUB 0x00010000
  118. #define CPUSTAT_RRF 0x00008000
  119. #define CPUSTAT_SLSV 0x00004000
  120. #define CPUSTAT_SLSR 0x00002000
  121. #define CPUSTAT_ZARCH 0x00000800
  122. #define CPUSTAT_MCDS 0x00000100
  123. #define CPUSTAT_KSS 0x00000200
  124. #define CPUSTAT_SM 0x00000080
  125. #define CPUSTAT_IBS 0x00000040
  126. #define CPUSTAT_GED2 0x00000010
  127. #define CPUSTAT_G 0x00000008
  128. #define CPUSTAT_GED 0x00000004
  129. #define CPUSTAT_J 0x00000002
  130. #define CPUSTAT_P 0x00000001
  131. struct kvm_s390_sie_block {
  132. atomic_t cpuflags; /* 0x0000 */
  133. __u32 : 1; /* 0x0004 */
  134. __u32 prefix : 18;
  135. __u32 : 1;
  136. __u32 ibc : 12;
  137. __u8 reserved08[4]; /* 0x0008 */
  138. #define PROG_IN_SIE (1<<0)
  139. __u32 prog0c; /* 0x000c */
  140. __u8 reserved10[16]; /* 0x0010 */
  141. #define PROG_BLOCK_SIE (1<<0)
  142. #define PROG_REQUEST (1<<1)
  143. atomic_t prog20; /* 0x0020 */
  144. __u8 reserved24[4]; /* 0x0024 */
  145. __u64 cputm; /* 0x0028 */
  146. __u64 ckc; /* 0x0030 */
  147. __u64 epoch; /* 0x0038 */
  148. __u32 svcc; /* 0x0040 */
  149. #define LCTL_CR0 0x8000
  150. #define LCTL_CR6 0x0200
  151. #define LCTL_CR9 0x0040
  152. #define LCTL_CR10 0x0020
  153. #define LCTL_CR11 0x0010
  154. #define LCTL_CR14 0x0002
  155. __u16 lctl; /* 0x0044 */
  156. __s16 icpua; /* 0x0046 */
  157. #define ICTL_OPEREXC 0x80000000
  158. #define ICTL_PINT 0x20000000
  159. #define ICTL_LPSW 0x00400000
  160. #define ICTL_STCTL 0x00040000
  161. #define ICTL_ISKE 0x00004000
  162. #define ICTL_SSKE 0x00002000
  163. #define ICTL_RRBE 0x00001000
  164. #define ICTL_TPROT 0x00000200
  165. __u32 ictl; /* 0x0048 */
  166. #define ECA_CEI 0x80000000
  167. #define ECA_IB 0x40000000
  168. #define ECA_SIGPI 0x10000000
  169. #define ECA_MVPGI 0x01000000
  170. #define ECA_AIV 0x00200000
  171. #define ECA_VX 0x00020000
  172. #define ECA_PROTEXCI 0x00002000
  173. #define ECA_APIE 0x00000008
  174. #define ECA_SII 0x00000001
  175. __u32 eca; /* 0x004c */
  176. #define ICPT_INST 0x04
  177. #define ICPT_PROGI 0x08
  178. #define ICPT_INSTPROGI 0x0C
  179. #define ICPT_EXTREQ 0x10
  180. #define ICPT_EXTINT 0x14
  181. #define ICPT_IOREQ 0x18
  182. #define ICPT_WAIT 0x1c
  183. #define ICPT_VALIDITY 0x20
  184. #define ICPT_STOP 0x28
  185. #define ICPT_OPEREXC 0x2C
  186. #define ICPT_PARTEXEC 0x38
  187. #define ICPT_IOINST 0x40
  188. #define ICPT_KSS 0x5c
  189. __u8 icptcode; /* 0x0050 */
  190. __u8 icptstatus; /* 0x0051 */
  191. __u16 ihcpu; /* 0x0052 */
  192. __u8 reserved54[2]; /* 0x0054 */
  193. __u16 ipa; /* 0x0056 */
  194. __u32 ipb; /* 0x0058 */
  195. __u32 scaoh; /* 0x005c */
  196. #define FPF_BPBC 0x20
  197. __u8 fpf; /* 0x0060 */
  198. #define ECB_GS 0x40
  199. #define ECB_TE 0x10
  200. #define ECB_SRSI 0x04
  201. #define ECB_HOSTPROTINT 0x02
  202. __u8 ecb; /* 0x0061 */
  203. #define ECB2_CMMA 0x80
  204. #define ECB2_IEP 0x20
  205. #define ECB2_PFMFI 0x08
  206. #define ECB2_ESCA 0x04
  207. __u8 ecb2; /* 0x0062 */
  208. #define ECB3_DEA 0x08
  209. #define ECB3_AES 0x04
  210. #define ECB3_RI 0x01
  211. __u8 ecb3; /* 0x0063 */
  212. __u32 scaol; /* 0x0064 */
  213. __u8 reserved68; /* 0x0068 */
  214. __u8 epdx; /* 0x0069 */
  215. __u8 reserved6a[2]; /* 0x006a */
  216. __u32 todpr; /* 0x006c */
  217. #define GISA_FORMAT1 0x00000001
  218. __u32 gd; /* 0x0070 */
  219. __u8 reserved74[12]; /* 0x0074 */
  220. __u64 mso; /* 0x0080 */
  221. __u64 msl; /* 0x0088 */
  222. psw_t gpsw; /* 0x0090 */
  223. __u64 gg14; /* 0x00a0 */
  224. __u64 gg15; /* 0x00a8 */
  225. __u8 reservedb0[8]; /* 0x00b0 */
  226. #define HPID_KVM 0x4
  227. #define HPID_VSIE 0x5
  228. __u8 hpid; /* 0x00b8 */
  229. __u8 reservedb9[11]; /* 0x00b9 */
  230. __u16 extcpuaddr; /* 0x00c4 */
  231. __u16 eic; /* 0x00c6 */
  232. __u32 reservedc8; /* 0x00c8 */
  233. __u16 pgmilc; /* 0x00cc */
  234. __u16 iprcc; /* 0x00ce */
  235. __u32 dxc; /* 0x00d0 */
  236. __u16 mcn; /* 0x00d4 */
  237. __u8 perc; /* 0x00d6 */
  238. __u8 peratmid; /* 0x00d7 */
  239. __u64 peraddr; /* 0x00d8 */
  240. __u8 eai; /* 0x00e0 */
  241. __u8 peraid; /* 0x00e1 */
  242. __u8 oai; /* 0x00e2 */
  243. __u8 armid; /* 0x00e3 */
  244. __u8 reservede4[4]; /* 0x00e4 */
  245. __u64 tecmc; /* 0x00e8 */
  246. __u8 reservedf0[12]; /* 0x00f0 */
  247. #define CRYCB_FORMAT_MASK 0x00000003
  248. #define CRYCB_FORMAT0 0x00000000
  249. #define CRYCB_FORMAT1 0x00000001
  250. #define CRYCB_FORMAT2 0x00000003
  251. __u32 crycbd; /* 0x00fc */
  252. __u64 gcr[16]; /* 0x0100 */
  253. __u64 gbea; /* 0x0180 */
  254. __u8 reserved188[8]; /* 0x0188 */
  255. __u64 sdnxo; /* 0x0190 */
  256. __u8 reserved198[8]; /* 0x0198 */
  257. __u32 fac; /* 0x01a0 */
  258. __u8 reserved1a4[20]; /* 0x01a4 */
  259. __u64 cbrlo; /* 0x01b8 */
  260. __u8 reserved1c0[8]; /* 0x01c0 */
  261. #define ECD_HOSTREGMGMT 0x20000000
  262. #define ECD_MEF 0x08000000
  263. #define ECD_ETOKENF 0x02000000
  264. __u32 ecd; /* 0x01c8 */
  265. __u8 reserved1cc[18]; /* 0x01cc */
  266. __u64 pp; /* 0x01de */
  267. __u8 reserved1e6[2]; /* 0x01e6 */
  268. __u64 itdba; /* 0x01e8 */
  269. __u64 riccbd; /* 0x01f0 */
  270. __u64 gvrd; /* 0x01f8 */
  271. } __attribute__((packed));
  272. struct kvm_s390_itdb {
  273. __u8 data[256];
  274. };
  275. struct sie_page {
  276. struct kvm_s390_sie_block sie_block;
  277. struct mcck_volatile_info mcck_info; /* 0x0200 */
  278. __u8 reserved218[1000]; /* 0x0218 */
  279. struct kvm_s390_itdb itdb; /* 0x0600 */
  280. __u8 reserved700[2304]; /* 0x0700 */
  281. };
  282. struct kvm_vcpu_stat {
  283. u64 exit_userspace;
  284. u64 exit_null;
  285. u64 exit_external_request;
  286. u64 exit_io_request;
  287. u64 exit_external_interrupt;
  288. u64 exit_stop_request;
  289. u64 exit_validity;
  290. u64 exit_instruction;
  291. u64 exit_pei;
  292. u64 halt_successful_poll;
  293. u64 halt_attempted_poll;
  294. u64 halt_poll_invalid;
  295. u64 halt_wakeup;
  296. u64 instruction_lctl;
  297. u64 instruction_lctlg;
  298. u64 instruction_stctl;
  299. u64 instruction_stctg;
  300. u64 exit_program_interruption;
  301. u64 exit_instr_and_program;
  302. u64 exit_operation_exception;
  303. u64 deliver_ckc;
  304. u64 deliver_cputm;
  305. u64 deliver_external_call;
  306. u64 deliver_emergency_signal;
  307. u64 deliver_service_signal;
  308. u64 deliver_virtio;
  309. u64 deliver_stop_signal;
  310. u64 deliver_prefix_signal;
  311. u64 deliver_restart_signal;
  312. u64 deliver_program;
  313. u64 deliver_io;
  314. u64 deliver_machine_check;
  315. u64 exit_wait_state;
  316. u64 inject_ckc;
  317. u64 inject_cputm;
  318. u64 inject_external_call;
  319. u64 inject_emergency_signal;
  320. u64 inject_mchk;
  321. u64 inject_pfault_init;
  322. u64 inject_program;
  323. u64 inject_restart;
  324. u64 inject_set_prefix;
  325. u64 inject_stop_signal;
  326. u64 instruction_epsw;
  327. u64 instruction_gs;
  328. u64 instruction_io_other;
  329. u64 instruction_lpsw;
  330. u64 instruction_lpswe;
  331. u64 instruction_pfmf;
  332. u64 instruction_ptff;
  333. u64 instruction_sck;
  334. u64 instruction_sckpf;
  335. u64 instruction_stidp;
  336. u64 instruction_spx;
  337. u64 instruction_stpx;
  338. u64 instruction_stap;
  339. u64 instruction_iske;
  340. u64 instruction_ri;
  341. u64 instruction_rrbe;
  342. u64 instruction_sske;
  343. u64 instruction_ipte_interlock;
  344. u64 instruction_stsi;
  345. u64 instruction_stfl;
  346. u64 instruction_tb;
  347. u64 instruction_tpi;
  348. u64 instruction_tprot;
  349. u64 instruction_tsch;
  350. u64 instruction_sie;
  351. u64 instruction_essa;
  352. u64 instruction_sthyi;
  353. u64 instruction_sigp_sense;
  354. u64 instruction_sigp_sense_running;
  355. u64 instruction_sigp_external_call;
  356. u64 instruction_sigp_emergency;
  357. u64 instruction_sigp_cond_emergency;
  358. u64 instruction_sigp_start;
  359. u64 instruction_sigp_stop;
  360. u64 instruction_sigp_stop_store_status;
  361. u64 instruction_sigp_store_status;
  362. u64 instruction_sigp_store_adtl_status;
  363. u64 instruction_sigp_arch;
  364. u64 instruction_sigp_prefix;
  365. u64 instruction_sigp_restart;
  366. u64 instruction_sigp_init_cpu_reset;
  367. u64 instruction_sigp_cpu_reset;
  368. u64 instruction_sigp_unknown;
  369. u64 diagnose_10;
  370. u64 diagnose_44;
  371. u64 diagnose_9c;
  372. u64 diagnose_258;
  373. u64 diagnose_308;
  374. u64 diagnose_500;
  375. u64 diagnose_other;
  376. };
  377. #define PGM_OPERATION 0x01
  378. #define PGM_PRIVILEGED_OP 0x02
  379. #define PGM_EXECUTE 0x03
  380. #define PGM_PROTECTION 0x04
  381. #define PGM_ADDRESSING 0x05
  382. #define PGM_SPECIFICATION 0x06
  383. #define PGM_DATA 0x07
  384. #define PGM_FIXED_POINT_OVERFLOW 0x08
  385. #define PGM_FIXED_POINT_DIVIDE 0x09
  386. #define PGM_DECIMAL_OVERFLOW 0x0a
  387. #define PGM_DECIMAL_DIVIDE 0x0b
  388. #define PGM_HFP_EXPONENT_OVERFLOW 0x0c
  389. #define PGM_HFP_EXPONENT_UNDERFLOW 0x0d
  390. #define PGM_HFP_SIGNIFICANCE 0x0e
  391. #define PGM_HFP_DIVIDE 0x0f
  392. #define PGM_SEGMENT_TRANSLATION 0x10
  393. #define PGM_PAGE_TRANSLATION 0x11
  394. #define PGM_TRANSLATION_SPEC 0x12
  395. #define PGM_SPECIAL_OPERATION 0x13
  396. #define PGM_OPERAND 0x15
  397. #define PGM_TRACE_TABEL 0x16
  398. #define PGM_VECTOR_PROCESSING 0x1b
  399. #define PGM_SPACE_SWITCH 0x1c
  400. #define PGM_HFP_SQUARE_ROOT 0x1d
  401. #define PGM_PC_TRANSLATION_SPEC 0x1f
  402. #define PGM_AFX_TRANSLATION 0x20
  403. #define PGM_ASX_TRANSLATION 0x21
  404. #define PGM_LX_TRANSLATION 0x22
  405. #define PGM_EX_TRANSLATION 0x23
  406. #define PGM_PRIMARY_AUTHORITY 0x24
  407. #define PGM_SECONDARY_AUTHORITY 0x25
  408. #define PGM_LFX_TRANSLATION 0x26
  409. #define PGM_LSX_TRANSLATION 0x27
  410. #define PGM_ALET_SPECIFICATION 0x28
  411. #define PGM_ALEN_TRANSLATION 0x29
  412. #define PGM_ALE_SEQUENCE 0x2a
  413. #define PGM_ASTE_VALIDITY 0x2b
  414. #define PGM_ASTE_SEQUENCE 0x2c
  415. #define PGM_EXTENDED_AUTHORITY 0x2d
  416. #define PGM_LSTE_SEQUENCE 0x2e
  417. #define PGM_ASTE_INSTANCE 0x2f
  418. #define PGM_STACK_FULL 0x30
  419. #define PGM_STACK_EMPTY 0x31
  420. #define PGM_STACK_SPECIFICATION 0x32
  421. #define PGM_STACK_TYPE 0x33
  422. #define PGM_STACK_OPERATION 0x34
  423. #define PGM_ASCE_TYPE 0x38
  424. #define PGM_REGION_FIRST_TRANS 0x39
  425. #define PGM_REGION_SECOND_TRANS 0x3a
  426. #define PGM_REGION_THIRD_TRANS 0x3b
  427. #define PGM_MONITOR 0x40
  428. #define PGM_PER 0x80
  429. #define PGM_CRYPTO_OPERATION 0x119
  430. /* irq types in ascend order of priorities */
  431. enum irq_types {
  432. IRQ_PEND_SET_PREFIX = 0,
  433. IRQ_PEND_RESTART,
  434. IRQ_PEND_SIGP_STOP,
  435. IRQ_PEND_IO_ISC_7,
  436. IRQ_PEND_IO_ISC_6,
  437. IRQ_PEND_IO_ISC_5,
  438. IRQ_PEND_IO_ISC_4,
  439. IRQ_PEND_IO_ISC_3,
  440. IRQ_PEND_IO_ISC_2,
  441. IRQ_PEND_IO_ISC_1,
  442. IRQ_PEND_IO_ISC_0,
  443. IRQ_PEND_VIRTIO,
  444. IRQ_PEND_PFAULT_DONE,
  445. IRQ_PEND_PFAULT_INIT,
  446. IRQ_PEND_EXT_HOST,
  447. IRQ_PEND_EXT_SERVICE,
  448. IRQ_PEND_EXT_TIMING,
  449. IRQ_PEND_EXT_CPU_TIMER,
  450. IRQ_PEND_EXT_CLOCK_COMP,
  451. IRQ_PEND_EXT_EXTERNAL,
  452. IRQ_PEND_EXT_EMERGENCY,
  453. IRQ_PEND_EXT_MALFUNC,
  454. IRQ_PEND_EXT_IRQ_KEY,
  455. IRQ_PEND_MCHK_REP,
  456. IRQ_PEND_PROG,
  457. IRQ_PEND_SVC,
  458. IRQ_PEND_MCHK_EX,
  459. IRQ_PEND_COUNT
  460. };
  461. /* We have 2M for virtio device descriptor pages. Smallest amount of
  462. * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381
  463. */
  464. #define KVM_S390_MAX_VIRTIO_IRQS 87381
  465. /*
  466. * Repressible (non-floating) machine check interrupts
  467. * subclass bits in MCIC
  468. */
  469. #define MCHK_EXTD_BIT 58
  470. #define MCHK_DEGR_BIT 56
  471. #define MCHK_WARN_BIT 55
  472. #define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \
  473. (1UL << MCHK_EXTD_BIT) | \
  474. (1UL << MCHK_WARN_BIT))
  475. /* Exigent machine check interrupts subclass bits in MCIC */
  476. #define MCHK_SD_BIT 63
  477. #define MCHK_PD_BIT 62
  478. #define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT))
  479. #define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY) | \
  480. (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
  481. (1UL << IRQ_PEND_EXT_CPU_TIMER) | \
  482. (1UL << IRQ_PEND_EXT_MALFUNC) | \
  483. (1UL << IRQ_PEND_EXT_EMERGENCY) | \
  484. (1UL << IRQ_PEND_EXT_EXTERNAL) | \
  485. (1UL << IRQ_PEND_EXT_TIMING) | \
  486. (1UL << IRQ_PEND_EXT_HOST) | \
  487. (1UL << IRQ_PEND_EXT_SERVICE) | \
  488. (1UL << IRQ_PEND_VIRTIO) | \
  489. (1UL << IRQ_PEND_PFAULT_INIT) | \
  490. (1UL << IRQ_PEND_PFAULT_DONE))
  491. #define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \
  492. (1UL << IRQ_PEND_IO_ISC_1) | \
  493. (1UL << IRQ_PEND_IO_ISC_2) | \
  494. (1UL << IRQ_PEND_IO_ISC_3) | \
  495. (1UL << IRQ_PEND_IO_ISC_4) | \
  496. (1UL << IRQ_PEND_IO_ISC_5) | \
  497. (1UL << IRQ_PEND_IO_ISC_6) | \
  498. (1UL << IRQ_PEND_IO_ISC_7))
  499. #define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
  500. (1UL << IRQ_PEND_MCHK_EX))
  501. struct kvm_s390_interrupt_info {
  502. struct list_head list;
  503. u64 type;
  504. union {
  505. struct kvm_s390_io_info io;
  506. struct kvm_s390_ext_info ext;
  507. struct kvm_s390_pgm_info pgm;
  508. struct kvm_s390_emerg_info emerg;
  509. struct kvm_s390_extcall_info extcall;
  510. struct kvm_s390_prefix_info prefix;
  511. struct kvm_s390_stop_info stop;
  512. struct kvm_s390_mchk_info mchk;
  513. };
  514. };
  515. struct kvm_s390_irq_payload {
  516. struct kvm_s390_io_info io;
  517. struct kvm_s390_ext_info ext;
  518. struct kvm_s390_pgm_info pgm;
  519. struct kvm_s390_emerg_info emerg;
  520. struct kvm_s390_extcall_info extcall;
  521. struct kvm_s390_prefix_info prefix;
  522. struct kvm_s390_stop_info stop;
  523. struct kvm_s390_mchk_info mchk;
  524. };
  525. struct kvm_s390_local_interrupt {
  526. spinlock_t lock;
  527. DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
  528. struct kvm_s390_irq_payload irq;
  529. unsigned long pending_irqs;
  530. };
  531. #define FIRQ_LIST_IO_ISC_0 0
  532. #define FIRQ_LIST_IO_ISC_1 1
  533. #define FIRQ_LIST_IO_ISC_2 2
  534. #define FIRQ_LIST_IO_ISC_3 3
  535. #define FIRQ_LIST_IO_ISC_4 4
  536. #define FIRQ_LIST_IO_ISC_5 5
  537. #define FIRQ_LIST_IO_ISC_6 6
  538. #define FIRQ_LIST_IO_ISC_7 7
  539. #define FIRQ_LIST_PFAULT 8
  540. #define FIRQ_LIST_VIRTIO 9
  541. #define FIRQ_LIST_COUNT 10
  542. #define FIRQ_CNTR_IO 0
  543. #define FIRQ_CNTR_SERVICE 1
  544. #define FIRQ_CNTR_VIRTIO 2
  545. #define FIRQ_CNTR_PFAULT 3
  546. #define FIRQ_MAX_COUNT 4
  547. /* mask the AIS mode for a given ISC */
  548. #define AIS_MODE_MASK(isc) (0x80 >> isc)
  549. #define KVM_S390_AIS_MODE_ALL 0
  550. #define KVM_S390_AIS_MODE_SINGLE 1
  551. struct kvm_s390_float_interrupt {
  552. unsigned long pending_irqs;
  553. spinlock_t lock;
  554. struct list_head lists[FIRQ_LIST_COUNT];
  555. int counters[FIRQ_MAX_COUNT];
  556. struct kvm_s390_mchk_info mchk;
  557. struct kvm_s390_ext_info srv_signal;
  558. int next_rr_cpu;
  559. unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
  560. struct mutex ais_lock;
  561. u8 simm;
  562. u8 nimm;
  563. };
  564. struct kvm_hw_wp_info_arch {
  565. unsigned long addr;
  566. unsigned long phys_addr;
  567. int len;
  568. char *old_data;
  569. };
  570. struct kvm_hw_bp_info_arch {
  571. unsigned long addr;
  572. int len;
  573. };
  574. /*
  575. * Only the upper 16 bits of kvm_guest_debug->control are arch specific.
  576. * Further KVM_GUESTDBG flags which an be used from userspace can be found in
  577. * arch/s390/include/uapi/asm/kvm.h
  578. */
  579. #define KVM_GUESTDBG_EXIT_PENDING 0x10000000
  580. #define guestdbg_enabled(vcpu) \
  581. (vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
  582. #define guestdbg_sstep_enabled(vcpu) \
  583. (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
  584. #define guestdbg_hw_bp_enabled(vcpu) \
  585. (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
  586. #define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
  587. (vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
  588. struct kvm_guestdbg_info_arch {
  589. unsigned long cr0;
  590. unsigned long cr9;
  591. unsigned long cr10;
  592. unsigned long cr11;
  593. struct kvm_hw_bp_info_arch *hw_bp_info;
  594. struct kvm_hw_wp_info_arch *hw_wp_info;
  595. int nr_hw_bp;
  596. int nr_hw_wp;
  597. unsigned long last_bp;
  598. };
  599. struct kvm_vcpu_arch {
  600. struct kvm_s390_sie_block *sie_block;
  601. /* if vsie is active, currently executed shadow sie control block */
  602. struct kvm_s390_sie_block *vsie_block;
  603. unsigned int host_acrs[NUM_ACRS];
  604. struct gs_cb *host_gscb;
  605. struct fpu host_fpregs;
  606. struct kvm_s390_local_interrupt local_int;
  607. struct hrtimer ckc_timer;
  608. struct kvm_s390_pgm_info pgm;
  609. struct gmap *gmap;
  610. /* backup location for the currently enabled gmap when scheduled out */
  611. struct gmap *enabled_gmap;
  612. struct kvm_guestdbg_info_arch guestdbg;
  613. unsigned long pfault_token;
  614. unsigned long pfault_select;
  615. unsigned long pfault_compare;
  616. bool cputm_enabled;
  617. /*
  618. * The seqcount protects updates to cputm_start and sie_block.cputm,
  619. * this way we can have non-blocking reads with consistent values.
  620. * Only the owning VCPU thread (vcpu->cpu) is allowed to change these
  621. * values and to start/stop/enable/disable cpu timer accounting.
  622. */
  623. seqcount_t cputm_seqcount;
  624. __u64 cputm_start;
  625. bool gs_enabled;
  626. bool skey_enabled;
  627. };
  628. struct kvm_vm_stat {
  629. u64 inject_io;
  630. u64 inject_float_mchk;
  631. u64 inject_pfault_done;
  632. u64 inject_service_signal;
  633. u64 inject_virtio;
  634. u64 remote_tlb_flush;
  635. };
  636. struct kvm_arch_memory_slot {
  637. };
  638. struct s390_map_info {
  639. struct list_head list;
  640. __u64 guest_addr;
  641. __u64 addr;
  642. struct page *page;
  643. };
  644. struct s390_io_adapter {
  645. unsigned int id;
  646. int isc;
  647. bool maskable;
  648. bool masked;
  649. bool swap;
  650. bool suppressible;
  651. struct rw_semaphore maps_lock;
  652. struct list_head maps;
  653. atomic_t nr_maps;
  654. };
  655. #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
  656. #define MAX_S390_ADAPTER_MAPS 256
  657. /* maximum size of facilities and facility mask is 2k bytes */
  658. #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
  659. #define S390_ARCH_FAC_LIST_SIZE_U64 \
  660. (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
  661. #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
  662. #define S390_ARCH_FAC_MASK_SIZE_U64 \
  663. (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
  664. struct kvm_s390_cpu_model {
  665. /* facility mask supported by kvm & hosting machine */
  666. __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64];
  667. /* facility list requested by guest (in dma page) */
  668. __u64 *fac_list;
  669. u64 cpuid;
  670. unsigned short ibc;
  671. };
  672. struct kvm_s390_crypto {
  673. struct kvm_s390_crypto_cb *crycb;
  674. __u32 crycbd;
  675. __u8 aes_kw;
  676. __u8 dea_kw;
  677. __u8 apie;
  678. };
  679. #define APCB0_MASK_SIZE 1
  680. struct kvm_s390_apcb0 {
  681. __u64 apm[APCB0_MASK_SIZE]; /* 0x0000 */
  682. __u64 aqm[APCB0_MASK_SIZE]; /* 0x0008 */
  683. __u64 adm[APCB0_MASK_SIZE]; /* 0x0010 */
  684. __u64 reserved18; /* 0x0018 */
  685. };
  686. #define APCB1_MASK_SIZE 4
  687. struct kvm_s390_apcb1 {
  688. __u64 apm[APCB1_MASK_SIZE]; /* 0x0000 */
  689. __u64 aqm[APCB1_MASK_SIZE]; /* 0x0020 */
  690. __u64 adm[APCB1_MASK_SIZE]; /* 0x0040 */
  691. __u64 reserved60[4]; /* 0x0060 */
  692. };
  693. struct kvm_s390_crypto_cb {
  694. struct kvm_s390_apcb0 apcb0; /* 0x0000 */
  695. __u8 reserved20[0x0048 - 0x0020]; /* 0x0020 */
  696. __u8 dea_wrapping_key_mask[24]; /* 0x0048 */
  697. __u8 aes_wrapping_key_mask[32]; /* 0x0060 */
  698. struct kvm_s390_apcb1 apcb1; /* 0x0080 */
  699. };
  700. struct kvm_s390_gisa {
  701. union {
  702. struct { /* common to all formats */
  703. u32 next_alert;
  704. u8 ipm;
  705. u8 reserved01[2];
  706. u8 iam;
  707. };
  708. struct { /* format 0 */
  709. u32 next_alert;
  710. u8 ipm;
  711. u8 reserved01;
  712. u8 : 6;
  713. u8 g : 1;
  714. u8 c : 1;
  715. u8 iam;
  716. u8 reserved02[4];
  717. u32 airq_count;
  718. } g0;
  719. struct { /* format 1 */
  720. u32 next_alert;
  721. u8 ipm;
  722. u8 simm;
  723. u8 nimm;
  724. u8 iam;
  725. u8 aism[8];
  726. u8 : 6;
  727. u8 g : 1;
  728. u8 c : 1;
  729. u8 reserved03[11];
  730. u32 airq_count;
  731. } g1;
  732. };
  733. };
  734. /*
  735. * sie_page2 has to be allocated as DMA because fac_list, crycb and
  736. * gisa need 31bit addresses in the sie control block.
  737. */
  738. struct sie_page2 {
  739. __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */
  740. struct kvm_s390_crypto_cb crycb; /* 0x0800 */
  741. struct kvm_s390_gisa gisa; /* 0x0900 */
  742. u8 reserved920[0x1000 - 0x920]; /* 0x0920 */
  743. };
  744. struct kvm_s390_vsie {
  745. struct mutex mutex;
  746. struct radix_tree_root addr_to_page;
  747. int page_count;
  748. int next;
  749. struct page *pages[KVM_MAX_VCPUS];
  750. };
  751. struct kvm_arch{
  752. void *sca;
  753. int use_esca;
  754. rwlock_t sca_lock;
  755. debug_info_t *dbf;
  756. struct kvm_s390_float_interrupt float_int;
  757. struct kvm_device *flic;
  758. struct gmap *gmap;
  759. unsigned long mem_limit;
  760. int css_support;
  761. int use_irqchip;
  762. int use_cmma;
  763. int use_pfmfi;
  764. int use_skf;
  765. int user_cpu_state_ctrl;
  766. int user_sigp;
  767. int user_stsi;
  768. int user_instr0;
  769. struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
  770. wait_queue_head_t ipte_wq;
  771. int ipte_lock_count;
  772. struct mutex ipte_mutex;
  773. spinlock_t start_stop_lock;
  774. struct sie_page2 *sie_page2;
  775. struct kvm_s390_cpu_model model;
  776. struct kvm_s390_crypto crypto;
  777. struct kvm_s390_vsie vsie;
  778. u8 epdx;
  779. u64 epoch;
  780. int migration_mode;
  781. atomic64_t cmma_dirty_pages;
  782. /* subset of available cpu features enabled by user space */
  783. DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
  784. struct kvm_s390_gisa *gisa;
  785. };
  786. #define KVM_HVA_ERR_BAD (-1UL)
  787. #define KVM_HVA_ERR_RO_BAD (-2UL)
  788. static inline bool kvm_is_error_hva(unsigned long addr)
  789. {
  790. return IS_ERR_VALUE(addr);
  791. }
  792. #define ASYNC_PF_PER_VCPU 64
  793. struct kvm_arch_async_pf {
  794. unsigned long pfault_token;
  795. };
  796. bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
  797. void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
  798. struct kvm_async_pf *work);
  799. void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
  800. struct kvm_async_pf *work);
  801. void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
  802. struct kvm_async_pf *work);
  803. void kvm_arch_crypto_clear_masks(struct kvm *kvm);
  804. void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm,
  805. unsigned long *aqm, unsigned long *adm);
  806. extern int sie64a(struct kvm_s390_sie_block *, u64 *);
  807. extern char sie_exit;
  808. static inline void kvm_arch_hardware_disable(void) {}
  809. static inline void kvm_arch_check_processor_compat(void *rtn) {}
  810. static inline void kvm_arch_sync_events(struct kvm *kvm) {}
  811. static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
  812. static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
  813. static inline void kvm_arch_free_memslot(struct kvm *kvm,
  814. struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
  815. static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {}
  816. static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
  817. static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
  818. struct kvm_memory_slot *slot) {}
  819. static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
  820. static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
  821. void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu);
  822. #endif