kvm_host.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /*
  2. * definition for kernel virtual machines on s390
  3. *
  4. * Copyright IBM Corp. 2008, 2009
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License (version 2 only)
  8. * as published by the Free Software Foundation.
  9. *
  10. * Author(s): Carsten Otte <cotte@de.ibm.com>
  11. */
  12. #ifndef ASM_KVM_HOST_H
  13. #define ASM_KVM_HOST_H
  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_host.h>
  19. #include <linux/kvm.h>
  20. #include <linux/seqlock.h>
  21. #include <asm/debug.h>
  22. #include <asm/cpu.h>
  23. #include <asm/fpu/api.h>
  24. #include <asm/isc.h>
  25. #define KVM_S390_BSCA_CPU_SLOTS 64
  26. #define KVM_S390_ESCA_CPU_SLOTS 248
  27. #define KVM_MAX_VCPUS 255
  28. #define KVM_USER_MEM_SLOTS 32
  29. /*
  30. * These seem to be used for allocating ->chip in the routing table,
  31. * which we don't use. 4096 is an out-of-thin-air value. If we need
  32. * to look at ->chip later on, we'll need to revisit this.
  33. */
  34. #define KVM_NR_IRQCHIPS 1
  35. #define KVM_IRQCHIP_NUM_PINS 4096
  36. #define KVM_HALT_POLL_NS_DEFAULT 80000
  37. /* s390-specific vcpu->requests bit members */
  38. #define KVM_REQ_ENABLE_IBS 8
  39. #define KVM_REQ_DISABLE_IBS 9
  40. #define KVM_REQ_ICPT_OPEREXC 10
  41. #define SIGP_CTRL_C 0x80
  42. #define SIGP_CTRL_SCN_MASK 0x3f
  43. union bsca_sigp_ctrl {
  44. __u8 value;
  45. struct {
  46. __u8 c : 1;
  47. __u8 r : 1;
  48. __u8 scn : 6;
  49. };
  50. } __packed;
  51. union esca_sigp_ctrl {
  52. __u16 value;
  53. struct {
  54. __u8 c : 1;
  55. __u8 reserved: 7;
  56. __u8 scn;
  57. };
  58. } __packed;
  59. struct esca_entry {
  60. union esca_sigp_ctrl sigp_ctrl;
  61. __u16 reserved1[3];
  62. __u64 sda;
  63. __u64 reserved2[6];
  64. } __packed;
  65. struct bsca_entry {
  66. __u8 reserved0;
  67. union bsca_sigp_ctrl sigp_ctrl;
  68. __u16 reserved[3];
  69. __u64 sda;
  70. __u64 reserved2[2];
  71. } __attribute__((packed));
  72. union ipte_control {
  73. unsigned long val;
  74. struct {
  75. unsigned long k : 1;
  76. unsigned long kh : 31;
  77. unsigned long kg : 32;
  78. };
  79. };
  80. struct bsca_block {
  81. union ipte_control ipte_control;
  82. __u64 reserved[5];
  83. __u64 mcn;
  84. __u64 reserved2;
  85. struct bsca_entry cpu[KVM_S390_BSCA_CPU_SLOTS];
  86. } __attribute__((packed));
  87. struct esca_block {
  88. union ipte_control ipte_control;
  89. __u64 reserved1[7];
  90. __u64 mcn[4];
  91. __u64 reserved2[20];
  92. struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
  93. } __packed;
  94. #define CPUSTAT_STOPPED 0x80000000
  95. #define CPUSTAT_WAIT 0x10000000
  96. #define CPUSTAT_ECALL_PEND 0x08000000
  97. #define CPUSTAT_STOP_INT 0x04000000
  98. #define CPUSTAT_IO_INT 0x02000000
  99. #define CPUSTAT_EXT_INT 0x01000000
  100. #define CPUSTAT_RUNNING 0x00800000
  101. #define CPUSTAT_RETAINED 0x00400000
  102. #define CPUSTAT_TIMING_SUB 0x00020000
  103. #define CPUSTAT_SIE_SUB 0x00010000
  104. #define CPUSTAT_RRF 0x00008000
  105. #define CPUSTAT_SLSV 0x00004000
  106. #define CPUSTAT_SLSR 0x00002000
  107. #define CPUSTAT_ZARCH 0x00000800
  108. #define CPUSTAT_MCDS 0x00000100
  109. #define CPUSTAT_SM 0x00000080
  110. #define CPUSTAT_IBS 0x00000040
  111. #define CPUSTAT_GED2 0x00000010
  112. #define CPUSTAT_G 0x00000008
  113. #define CPUSTAT_GED 0x00000004
  114. #define CPUSTAT_J 0x00000002
  115. #define CPUSTAT_P 0x00000001
  116. struct kvm_s390_sie_block {
  117. atomic_t cpuflags; /* 0x0000 */
  118. __u32 : 1; /* 0x0004 */
  119. __u32 prefix : 18;
  120. __u32 : 1;
  121. __u32 ibc : 12;
  122. __u8 reserved08[4]; /* 0x0008 */
  123. #define PROG_IN_SIE (1<<0)
  124. __u32 prog0c; /* 0x000c */
  125. __u8 reserved10[16]; /* 0x0010 */
  126. #define PROG_BLOCK_SIE (1<<0)
  127. #define PROG_REQUEST (1<<1)
  128. atomic_t prog20; /* 0x0020 */
  129. __u8 reserved24[4]; /* 0x0024 */
  130. __u64 cputm; /* 0x0028 */
  131. __u64 ckc; /* 0x0030 */
  132. __u64 epoch; /* 0x0038 */
  133. __u32 svcc; /* 0x0040 */
  134. #define LCTL_CR0 0x8000
  135. #define LCTL_CR6 0x0200
  136. #define LCTL_CR9 0x0040
  137. #define LCTL_CR10 0x0020
  138. #define LCTL_CR11 0x0010
  139. #define LCTL_CR14 0x0002
  140. __u16 lctl; /* 0x0044 */
  141. __s16 icpua; /* 0x0046 */
  142. #define ICTL_OPEREXC 0x80000000
  143. #define ICTL_PINT 0x20000000
  144. #define ICTL_LPSW 0x00400000
  145. #define ICTL_STCTL 0x00040000
  146. #define ICTL_ISKE 0x00004000
  147. #define ICTL_SSKE 0x00002000
  148. #define ICTL_RRBE 0x00001000
  149. #define ICTL_TPROT 0x00000200
  150. __u32 ictl; /* 0x0048 */
  151. __u32 eca; /* 0x004c */
  152. #define ICPT_INST 0x04
  153. #define ICPT_PROGI 0x08
  154. #define ICPT_INSTPROGI 0x0C
  155. #define ICPT_EXTINT 0x14
  156. #define ICPT_VALIDITY 0x20
  157. #define ICPT_STOP 0x28
  158. #define ICPT_OPEREXC 0x2C
  159. #define ICPT_PARTEXEC 0x38
  160. #define ICPT_IOINST 0x40
  161. __u8 icptcode; /* 0x0050 */
  162. __u8 icptstatus; /* 0x0051 */
  163. __u16 ihcpu; /* 0x0052 */
  164. __u8 reserved54[2]; /* 0x0054 */
  165. __u16 ipa; /* 0x0056 */
  166. __u32 ipb; /* 0x0058 */
  167. __u32 scaoh; /* 0x005c */
  168. __u8 reserved60; /* 0x0060 */
  169. __u8 ecb; /* 0x0061 */
  170. __u8 ecb2; /* 0x0062 */
  171. #define ECB3_AES 0x04
  172. #define ECB3_DEA 0x08
  173. __u8 ecb3; /* 0x0063 */
  174. __u32 scaol; /* 0x0064 */
  175. __u8 reserved68[4]; /* 0x0068 */
  176. __u32 todpr; /* 0x006c */
  177. __u8 reserved70[16]; /* 0x0070 */
  178. __u64 mso; /* 0x0080 */
  179. __u64 msl; /* 0x0088 */
  180. psw_t gpsw; /* 0x0090 */
  181. __u64 gg14; /* 0x00a0 */
  182. __u64 gg15; /* 0x00a8 */
  183. __u8 reservedb0[20]; /* 0x00b0 */
  184. __u16 extcpuaddr; /* 0x00c4 */
  185. __u16 eic; /* 0x00c6 */
  186. __u32 reservedc8; /* 0x00c8 */
  187. __u16 pgmilc; /* 0x00cc */
  188. __u16 iprcc; /* 0x00ce */
  189. __u32 dxc; /* 0x00d0 */
  190. __u16 mcn; /* 0x00d4 */
  191. __u8 perc; /* 0x00d6 */
  192. __u8 peratmid; /* 0x00d7 */
  193. __u64 peraddr; /* 0x00d8 */
  194. __u8 eai; /* 0x00e0 */
  195. __u8 peraid; /* 0x00e1 */
  196. __u8 oai; /* 0x00e2 */
  197. __u8 armid; /* 0x00e3 */
  198. __u8 reservede4[4]; /* 0x00e4 */
  199. __u64 tecmc; /* 0x00e8 */
  200. __u8 reservedf0[12]; /* 0x00f0 */
  201. #define CRYCB_FORMAT1 0x00000001
  202. #define CRYCB_FORMAT2 0x00000003
  203. __u32 crycbd; /* 0x00fc */
  204. __u64 gcr[16]; /* 0x0100 */
  205. __u64 gbea; /* 0x0180 */
  206. __u8 reserved188[24]; /* 0x0188 */
  207. __u32 fac; /* 0x01a0 */
  208. __u8 reserved1a4[20]; /* 0x01a4 */
  209. __u64 cbrlo; /* 0x01b8 */
  210. __u8 reserved1c0[8]; /* 0x01c0 */
  211. __u32 ecd; /* 0x01c8 */
  212. __u8 reserved1cc[18]; /* 0x01cc */
  213. __u64 pp; /* 0x01de */
  214. __u8 reserved1e6[2]; /* 0x01e6 */
  215. __u64 itdba; /* 0x01e8 */
  216. __u64 riccbd; /* 0x01f0 */
  217. __u64 gvrd; /* 0x01f8 */
  218. } __attribute__((packed));
  219. struct kvm_s390_itdb {
  220. __u8 data[256];
  221. } __packed;
  222. struct sie_page {
  223. struct kvm_s390_sie_block sie_block;
  224. __u8 reserved200[1024]; /* 0x0200 */
  225. struct kvm_s390_itdb itdb; /* 0x0600 */
  226. __u8 reserved700[2304]; /* 0x0700 */
  227. } __packed;
  228. struct kvm_vcpu_stat {
  229. u64 exit_userspace;
  230. u64 exit_null;
  231. u64 exit_external_request;
  232. u64 exit_external_interrupt;
  233. u64 exit_stop_request;
  234. u64 exit_validity;
  235. u64 exit_instruction;
  236. u64 exit_pei;
  237. u64 halt_successful_poll;
  238. u64 halt_attempted_poll;
  239. u64 halt_poll_invalid;
  240. u64 halt_wakeup;
  241. u64 instruction_lctl;
  242. u64 instruction_lctlg;
  243. u64 instruction_stctl;
  244. u64 instruction_stctg;
  245. u64 exit_program_interruption;
  246. u64 exit_instr_and_program;
  247. u64 exit_operation_exception;
  248. u64 deliver_external_call;
  249. u64 deliver_emergency_signal;
  250. u64 deliver_service_signal;
  251. u64 deliver_virtio_interrupt;
  252. u64 deliver_stop_signal;
  253. u64 deliver_prefix_signal;
  254. u64 deliver_restart_signal;
  255. u64 deliver_program_int;
  256. u64 deliver_io_int;
  257. u64 exit_wait_state;
  258. u64 instruction_pfmf;
  259. u64 instruction_stidp;
  260. u64 instruction_spx;
  261. u64 instruction_stpx;
  262. u64 instruction_stap;
  263. u64 instruction_storage_key;
  264. u64 instruction_ipte_interlock;
  265. u64 instruction_stsch;
  266. u64 instruction_chsc;
  267. u64 instruction_stsi;
  268. u64 instruction_stfl;
  269. u64 instruction_tprot;
  270. u64 instruction_sie;
  271. u64 instruction_essa;
  272. u64 instruction_sthyi;
  273. u64 instruction_sigp_sense;
  274. u64 instruction_sigp_sense_running;
  275. u64 instruction_sigp_external_call;
  276. u64 instruction_sigp_emergency;
  277. u64 instruction_sigp_cond_emergency;
  278. u64 instruction_sigp_start;
  279. u64 instruction_sigp_stop;
  280. u64 instruction_sigp_stop_store_status;
  281. u64 instruction_sigp_store_status;
  282. u64 instruction_sigp_store_adtl_status;
  283. u64 instruction_sigp_arch;
  284. u64 instruction_sigp_prefix;
  285. u64 instruction_sigp_restart;
  286. u64 instruction_sigp_init_cpu_reset;
  287. u64 instruction_sigp_cpu_reset;
  288. u64 instruction_sigp_unknown;
  289. u64 diagnose_10;
  290. u64 diagnose_44;
  291. u64 diagnose_9c;
  292. u64 diagnose_258;
  293. u64 diagnose_308;
  294. u64 diagnose_500;
  295. };
  296. #define PGM_OPERATION 0x01
  297. #define PGM_PRIVILEGED_OP 0x02
  298. #define PGM_EXECUTE 0x03
  299. #define PGM_PROTECTION 0x04
  300. #define PGM_ADDRESSING 0x05
  301. #define PGM_SPECIFICATION 0x06
  302. #define PGM_DATA 0x07
  303. #define PGM_FIXED_POINT_OVERFLOW 0x08
  304. #define PGM_FIXED_POINT_DIVIDE 0x09
  305. #define PGM_DECIMAL_OVERFLOW 0x0a
  306. #define PGM_DECIMAL_DIVIDE 0x0b
  307. #define PGM_HFP_EXPONENT_OVERFLOW 0x0c
  308. #define PGM_HFP_EXPONENT_UNDERFLOW 0x0d
  309. #define PGM_HFP_SIGNIFICANCE 0x0e
  310. #define PGM_HFP_DIVIDE 0x0f
  311. #define PGM_SEGMENT_TRANSLATION 0x10
  312. #define PGM_PAGE_TRANSLATION 0x11
  313. #define PGM_TRANSLATION_SPEC 0x12
  314. #define PGM_SPECIAL_OPERATION 0x13
  315. #define PGM_OPERAND 0x15
  316. #define PGM_TRACE_TABEL 0x16
  317. #define PGM_VECTOR_PROCESSING 0x1b
  318. #define PGM_SPACE_SWITCH 0x1c
  319. #define PGM_HFP_SQUARE_ROOT 0x1d
  320. #define PGM_PC_TRANSLATION_SPEC 0x1f
  321. #define PGM_AFX_TRANSLATION 0x20
  322. #define PGM_ASX_TRANSLATION 0x21
  323. #define PGM_LX_TRANSLATION 0x22
  324. #define PGM_EX_TRANSLATION 0x23
  325. #define PGM_PRIMARY_AUTHORITY 0x24
  326. #define PGM_SECONDARY_AUTHORITY 0x25
  327. #define PGM_LFX_TRANSLATION 0x26
  328. #define PGM_LSX_TRANSLATION 0x27
  329. #define PGM_ALET_SPECIFICATION 0x28
  330. #define PGM_ALEN_TRANSLATION 0x29
  331. #define PGM_ALE_SEQUENCE 0x2a
  332. #define PGM_ASTE_VALIDITY 0x2b
  333. #define PGM_ASTE_SEQUENCE 0x2c
  334. #define PGM_EXTENDED_AUTHORITY 0x2d
  335. #define PGM_LSTE_SEQUENCE 0x2e
  336. #define PGM_ASTE_INSTANCE 0x2f
  337. #define PGM_STACK_FULL 0x30
  338. #define PGM_STACK_EMPTY 0x31
  339. #define PGM_STACK_SPECIFICATION 0x32
  340. #define PGM_STACK_TYPE 0x33
  341. #define PGM_STACK_OPERATION 0x34
  342. #define PGM_ASCE_TYPE 0x38
  343. #define PGM_REGION_FIRST_TRANS 0x39
  344. #define PGM_REGION_SECOND_TRANS 0x3a
  345. #define PGM_REGION_THIRD_TRANS 0x3b
  346. #define PGM_MONITOR 0x40
  347. #define PGM_PER 0x80
  348. #define PGM_CRYPTO_OPERATION 0x119
  349. /* irq types in order of priority */
  350. enum irq_types {
  351. IRQ_PEND_MCHK_EX = 0,
  352. IRQ_PEND_SVC,
  353. IRQ_PEND_PROG,
  354. IRQ_PEND_MCHK_REP,
  355. IRQ_PEND_EXT_IRQ_KEY,
  356. IRQ_PEND_EXT_MALFUNC,
  357. IRQ_PEND_EXT_EMERGENCY,
  358. IRQ_PEND_EXT_EXTERNAL,
  359. IRQ_PEND_EXT_CLOCK_COMP,
  360. IRQ_PEND_EXT_CPU_TIMER,
  361. IRQ_PEND_EXT_TIMING,
  362. IRQ_PEND_EXT_SERVICE,
  363. IRQ_PEND_EXT_HOST,
  364. IRQ_PEND_PFAULT_INIT,
  365. IRQ_PEND_PFAULT_DONE,
  366. IRQ_PEND_VIRTIO,
  367. IRQ_PEND_IO_ISC_0,
  368. IRQ_PEND_IO_ISC_1,
  369. IRQ_PEND_IO_ISC_2,
  370. IRQ_PEND_IO_ISC_3,
  371. IRQ_PEND_IO_ISC_4,
  372. IRQ_PEND_IO_ISC_5,
  373. IRQ_PEND_IO_ISC_6,
  374. IRQ_PEND_IO_ISC_7,
  375. IRQ_PEND_SIGP_STOP,
  376. IRQ_PEND_RESTART,
  377. IRQ_PEND_SET_PREFIX,
  378. IRQ_PEND_COUNT
  379. };
  380. /* We have 2M for virtio device descriptor pages. Smallest amount of
  381. * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381
  382. */
  383. #define KVM_S390_MAX_VIRTIO_IRQS 87381
  384. /*
  385. * Repressible (non-floating) machine check interrupts
  386. * subclass bits in MCIC
  387. */
  388. #define MCHK_EXTD_BIT 58
  389. #define MCHK_DEGR_BIT 56
  390. #define MCHK_WARN_BIT 55
  391. #define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \
  392. (1UL << MCHK_EXTD_BIT) | \
  393. (1UL << MCHK_WARN_BIT))
  394. /* Exigent machine check interrupts subclass bits in MCIC */
  395. #define MCHK_SD_BIT 63
  396. #define MCHK_PD_BIT 62
  397. #define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT))
  398. #define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY) | \
  399. (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
  400. (1UL << IRQ_PEND_EXT_CPU_TIMER) | \
  401. (1UL << IRQ_PEND_EXT_MALFUNC) | \
  402. (1UL << IRQ_PEND_EXT_EMERGENCY) | \
  403. (1UL << IRQ_PEND_EXT_EXTERNAL) | \
  404. (1UL << IRQ_PEND_EXT_TIMING) | \
  405. (1UL << IRQ_PEND_EXT_HOST) | \
  406. (1UL << IRQ_PEND_EXT_SERVICE) | \
  407. (1UL << IRQ_PEND_VIRTIO) | \
  408. (1UL << IRQ_PEND_PFAULT_INIT) | \
  409. (1UL << IRQ_PEND_PFAULT_DONE))
  410. #define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \
  411. (1UL << IRQ_PEND_IO_ISC_1) | \
  412. (1UL << IRQ_PEND_IO_ISC_2) | \
  413. (1UL << IRQ_PEND_IO_ISC_3) | \
  414. (1UL << IRQ_PEND_IO_ISC_4) | \
  415. (1UL << IRQ_PEND_IO_ISC_5) | \
  416. (1UL << IRQ_PEND_IO_ISC_6) | \
  417. (1UL << IRQ_PEND_IO_ISC_7))
  418. #define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
  419. (1UL << IRQ_PEND_MCHK_EX))
  420. struct kvm_s390_interrupt_info {
  421. struct list_head list;
  422. u64 type;
  423. union {
  424. struct kvm_s390_io_info io;
  425. struct kvm_s390_ext_info ext;
  426. struct kvm_s390_pgm_info pgm;
  427. struct kvm_s390_emerg_info emerg;
  428. struct kvm_s390_extcall_info extcall;
  429. struct kvm_s390_prefix_info prefix;
  430. struct kvm_s390_stop_info stop;
  431. struct kvm_s390_mchk_info mchk;
  432. };
  433. };
  434. struct kvm_s390_irq_payload {
  435. struct kvm_s390_io_info io;
  436. struct kvm_s390_ext_info ext;
  437. struct kvm_s390_pgm_info pgm;
  438. struct kvm_s390_emerg_info emerg;
  439. struct kvm_s390_extcall_info extcall;
  440. struct kvm_s390_prefix_info prefix;
  441. struct kvm_s390_stop_info stop;
  442. struct kvm_s390_mchk_info mchk;
  443. };
  444. struct kvm_s390_local_interrupt {
  445. spinlock_t lock;
  446. struct kvm_s390_float_interrupt *float_int;
  447. struct swait_queue_head *wq;
  448. atomic_t *cpuflags;
  449. DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
  450. struct kvm_s390_irq_payload irq;
  451. unsigned long pending_irqs;
  452. };
  453. #define FIRQ_LIST_IO_ISC_0 0
  454. #define FIRQ_LIST_IO_ISC_1 1
  455. #define FIRQ_LIST_IO_ISC_2 2
  456. #define FIRQ_LIST_IO_ISC_3 3
  457. #define FIRQ_LIST_IO_ISC_4 4
  458. #define FIRQ_LIST_IO_ISC_5 5
  459. #define FIRQ_LIST_IO_ISC_6 6
  460. #define FIRQ_LIST_IO_ISC_7 7
  461. #define FIRQ_LIST_PFAULT 8
  462. #define FIRQ_LIST_VIRTIO 9
  463. #define FIRQ_LIST_COUNT 10
  464. #define FIRQ_CNTR_IO 0
  465. #define FIRQ_CNTR_SERVICE 1
  466. #define FIRQ_CNTR_VIRTIO 2
  467. #define FIRQ_CNTR_PFAULT 3
  468. #define FIRQ_MAX_COUNT 4
  469. struct kvm_s390_float_interrupt {
  470. unsigned long pending_irqs;
  471. spinlock_t lock;
  472. struct list_head lists[FIRQ_LIST_COUNT];
  473. int counters[FIRQ_MAX_COUNT];
  474. struct kvm_s390_mchk_info mchk;
  475. struct kvm_s390_ext_info srv_signal;
  476. int next_rr_cpu;
  477. unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
  478. };
  479. struct kvm_hw_wp_info_arch {
  480. unsigned long addr;
  481. unsigned long phys_addr;
  482. int len;
  483. char *old_data;
  484. };
  485. struct kvm_hw_bp_info_arch {
  486. unsigned long addr;
  487. int len;
  488. };
  489. /*
  490. * Only the upper 16 bits of kvm_guest_debug->control are arch specific.
  491. * Further KVM_GUESTDBG flags which an be used from userspace can be found in
  492. * arch/s390/include/uapi/asm/kvm.h
  493. */
  494. #define KVM_GUESTDBG_EXIT_PENDING 0x10000000
  495. #define guestdbg_enabled(vcpu) \
  496. (vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
  497. #define guestdbg_sstep_enabled(vcpu) \
  498. (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
  499. #define guestdbg_hw_bp_enabled(vcpu) \
  500. (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
  501. #define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
  502. (vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
  503. struct kvm_guestdbg_info_arch {
  504. unsigned long cr0;
  505. unsigned long cr9;
  506. unsigned long cr10;
  507. unsigned long cr11;
  508. struct kvm_hw_bp_info_arch *hw_bp_info;
  509. struct kvm_hw_wp_info_arch *hw_wp_info;
  510. int nr_hw_bp;
  511. int nr_hw_wp;
  512. unsigned long last_bp;
  513. };
  514. struct kvm_vcpu_arch {
  515. struct kvm_s390_sie_block *sie_block;
  516. /* if vsie is active, currently executed shadow sie control block */
  517. struct kvm_s390_sie_block *vsie_block;
  518. unsigned int host_acrs[NUM_ACRS];
  519. struct fpu host_fpregs;
  520. struct kvm_s390_local_interrupt local_int;
  521. struct hrtimer ckc_timer;
  522. struct kvm_s390_pgm_info pgm;
  523. struct gmap *gmap;
  524. /* backup location for the currently enabled gmap when scheduled out */
  525. struct gmap *enabled_gmap;
  526. struct kvm_guestdbg_info_arch guestdbg;
  527. unsigned long pfault_token;
  528. unsigned long pfault_select;
  529. unsigned long pfault_compare;
  530. bool cputm_enabled;
  531. /*
  532. * The seqcount protects updates to cputm_start and sie_block.cputm,
  533. * this way we can have non-blocking reads with consistent values.
  534. * Only the owning VCPU thread (vcpu->cpu) is allowed to change these
  535. * values and to start/stop/enable/disable cpu timer accounting.
  536. */
  537. seqcount_t cputm_seqcount;
  538. __u64 cputm_start;
  539. };
  540. struct kvm_vm_stat {
  541. ulong remote_tlb_flush;
  542. };
  543. struct kvm_arch_memory_slot {
  544. };
  545. struct s390_map_info {
  546. struct list_head list;
  547. __u64 guest_addr;
  548. __u64 addr;
  549. struct page *page;
  550. };
  551. struct s390_io_adapter {
  552. unsigned int id;
  553. int isc;
  554. bool maskable;
  555. bool masked;
  556. bool swap;
  557. struct rw_semaphore maps_lock;
  558. struct list_head maps;
  559. atomic_t nr_maps;
  560. };
  561. #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
  562. #define MAX_S390_ADAPTER_MAPS 256
  563. /* maximum size of facilities and facility mask is 2k bytes */
  564. #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
  565. #define S390_ARCH_FAC_LIST_SIZE_U64 \
  566. (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
  567. #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
  568. #define S390_ARCH_FAC_MASK_SIZE_U64 \
  569. (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
  570. struct kvm_s390_cpu_model {
  571. /* facility mask supported by kvm & hosting machine */
  572. __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64];
  573. /* facility list requested by guest (in dma page) */
  574. __u64 *fac_list;
  575. u64 cpuid;
  576. unsigned short ibc;
  577. };
  578. struct kvm_s390_crypto {
  579. struct kvm_s390_crypto_cb *crycb;
  580. __u32 crycbd;
  581. __u8 aes_kw;
  582. __u8 dea_kw;
  583. };
  584. struct kvm_s390_crypto_cb {
  585. __u8 reserved00[72]; /* 0x0000 */
  586. __u8 dea_wrapping_key_mask[24]; /* 0x0048 */
  587. __u8 aes_wrapping_key_mask[32]; /* 0x0060 */
  588. __u8 reserved80[128]; /* 0x0080 */
  589. };
  590. /*
  591. * sie_page2 has to be allocated as DMA because fac_list and crycb need
  592. * 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. u8 reserved900[0x1000 - 0x900]; /* 0x0900 */
  598. } __packed;
  599. struct kvm_s390_vsie {
  600. struct mutex mutex;
  601. struct radix_tree_root addr_to_page;
  602. int page_count;
  603. int next;
  604. struct page *pages[KVM_MAX_VCPUS];
  605. };
  606. struct kvm_arch{
  607. void *sca;
  608. int use_esca;
  609. rwlock_t sca_lock;
  610. debug_info_t *dbf;
  611. struct kvm_s390_float_interrupt float_int;
  612. struct kvm_device *flic;
  613. struct gmap *gmap;
  614. unsigned long mem_limit;
  615. int css_support;
  616. int use_irqchip;
  617. int use_cmma;
  618. int user_cpu_state_ctrl;
  619. int user_sigp;
  620. int user_stsi;
  621. int user_instr0;
  622. struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
  623. wait_queue_head_t ipte_wq;
  624. int ipte_lock_count;
  625. struct mutex ipte_mutex;
  626. struct ratelimit_state sthyi_limit;
  627. spinlock_t start_stop_lock;
  628. struct sie_page2 *sie_page2;
  629. struct kvm_s390_cpu_model model;
  630. struct kvm_s390_crypto crypto;
  631. struct kvm_s390_vsie vsie;
  632. u64 epoch;
  633. /* subset of available cpu features enabled by user space */
  634. DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
  635. };
  636. #define KVM_HVA_ERR_BAD (-1UL)
  637. #define KVM_HVA_ERR_RO_BAD (-2UL)
  638. static inline bool kvm_is_error_hva(unsigned long addr)
  639. {
  640. return IS_ERR_VALUE(addr);
  641. }
  642. #define ASYNC_PF_PER_VCPU 64
  643. struct kvm_arch_async_pf {
  644. unsigned long pfault_token;
  645. };
  646. bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
  647. void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
  648. struct kvm_async_pf *work);
  649. void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
  650. struct kvm_async_pf *work);
  651. void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
  652. struct kvm_async_pf *work);
  653. extern int sie64a(struct kvm_s390_sie_block *, u64 *);
  654. extern char sie_exit;
  655. static inline void kvm_arch_hardware_disable(void) {}
  656. static inline void kvm_arch_check_processor_compat(void *rtn) {}
  657. static inline void kvm_arch_sync_events(struct kvm *kvm) {}
  658. static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
  659. static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
  660. static inline void kvm_arch_free_memslot(struct kvm *kvm,
  661. struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
  662. static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {}
  663. static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
  664. static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
  665. struct kvm_memory_slot *slot) {}
  666. static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
  667. static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
  668. void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu);
  669. #endif