kvm_host.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. *
  4. * Copyright IBM Corp. 2007
  5. *
  6. * Authors: Hollis Blanchard <[email protected]>
  7. */
  8. #ifndef __POWERPC_KVM_HOST_H__
  9. #define __POWERPC_KVM_HOST_H__
  10. #include <linux/mutex.h>
  11. #include <linux/hrtimer.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/types.h>
  14. #include <linux/kvm_types.h>
  15. #include <linux/threads.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/kvm_para.h>
  18. #include <linux/list.h>
  19. #include <linux/atomic.h>
  20. #include <asm/kvm_asm.h>
  21. #include <asm/processor.h>
  22. #include <asm/page.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/hvcall.h>
  25. #include <asm/mce.h>
  26. #define __KVM_HAVE_ARCH_VCPU_DEBUGFS
  27. #define KVM_MAX_VCPUS NR_CPUS
  28. #define KVM_MAX_VCORES NR_CPUS
  29. #include <asm/cputhreads.h>
  30. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  31. #include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */
  32. #define KVM_MAX_VCPU_IDS (MAX_SMT_THREADS * KVM_MAX_VCORES)
  33. /*
  34. * Limit the nested partition table to 4096 entries (because that's what
  35. * hardware supports). Both guest and host use this value.
  36. */
  37. #define KVM_MAX_NESTED_GUESTS_SHIFT 12
  38. #else
  39. #define KVM_MAX_VCPU_IDS KVM_MAX_VCPUS
  40. #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  41. #define __KVM_HAVE_ARCH_INTC_INITIALIZED
  42. #define KVM_HALT_POLL_NS_DEFAULT 10000 /* 10 us */
  43. /* These values are internal and can be increased later */
  44. #define KVM_NR_IRQCHIPS 1
  45. #define KVM_IRQCHIP_NUM_PINS 256
  46. /* PPC-specific vcpu->requests bit members */
  47. #define KVM_REQ_WATCHDOG KVM_ARCH_REQ(0)
  48. #define KVM_REQ_EPR_EXIT KVM_ARCH_REQ(1)
  49. #define KVM_REQ_PENDING_TIMER KVM_ARCH_REQ(2)
  50. #include <linux/mmu_notifier.h>
  51. #define KVM_ARCH_WANT_MMU_NOTIFIER
  52. #define HPTEG_CACHE_NUM (1 << 15)
  53. #define HPTEG_HASH_BITS_PTE 13
  54. #define HPTEG_HASH_BITS_PTE_LONG 12
  55. #define HPTEG_HASH_BITS_VPTE 13
  56. #define HPTEG_HASH_BITS_VPTE_LONG 5
  57. #define HPTEG_HASH_BITS_VPTE_64K 11
  58. #define HPTEG_HASH_NUM_PTE (1 << HPTEG_HASH_BITS_PTE)
  59. #define HPTEG_HASH_NUM_PTE_LONG (1 << HPTEG_HASH_BITS_PTE_LONG)
  60. #define HPTEG_HASH_NUM_VPTE (1 << HPTEG_HASH_BITS_VPTE)
  61. #define HPTEG_HASH_NUM_VPTE_LONG (1 << HPTEG_HASH_BITS_VPTE_LONG)
  62. #define HPTEG_HASH_NUM_VPTE_64K (1 << HPTEG_HASH_BITS_VPTE_64K)
  63. /* Physical Address Mask - allowed range of real mode RAM access */
  64. #define KVM_PAM 0x0fffffffffffffffULL
  65. struct lppaca;
  66. struct slb_shadow;
  67. struct dtl_entry;
  68. struct kvmppc_vcpu_book3s;
  69. struct kvmppc_book3s_shadow_vcpu;
  70. struct kvm_nested_guest;
  71. struct kvm_vm_stat {
  72. struct kvm_vm_stat_generic generic;
  73. u64 num_2M_pages;
  74. u64 num_1G_pages;
  75. };
  76. struct kvm_vcpu_stat {
  77. struct kvm_vcpu_stat_generic generic;
  78. u64 sum_exits;
  79. u64 mmio_exits;
  80. u64 signal_exits;
  81. u64 light_exits;
  82. /* Account for special types of light exits: */
  83. u64 itlb_real_miss_exits;
  84. u64 itlb_virt_miss_exits;
  85. u64 dtlb_real_miss_exits;
  86. u64 dtlb_virt_miss_exits;
  87. u64 syscall_exits;
  88. u64 isi_exits;
  89. u64 dsi_exits;
  90. u64 emulated_inst_exits;
  91. u64 dec_exits;
  92. u64 ext_intr_exits;
  93. u64 halt_successful_wait;
  94. u64 dbell_exits;
  95. u64 gdbell_exits;
  96. u64 ld;
  97. u64 st;
  98. #ifdef CONFIG_PPC_BOOK3S
  99. u64 pf_storage;
  100. u64 pf_instruc;
  101. u64 sp_storage;
  102. u64 sp_instruc;
  103. u64 queue_intr;
  104. u64 ld_slow;
  105. u64 st_slow;
  106. #endif
  107. u64 pthru_all;
  108. u64 pthru_host;
  109. u64 pthru_bad_aff;
  110. };
  111. enum kvm_exit_types {
  112. MMIO_EXITS,
  113. SIGNAL_EXITS,
  114. ITLB_REAL_MISS_EXITS,
  115. ITLB_VIRT_MISS_EXITS,
  116. DTLB_REAL_MISS_EXITS,
  117. DTLB_VIRT_MISS_EXITS,
  118. SYSCALL_EXITS,
  119. ISI_EXITS,
  120. DSI_EXITS,
  121. EMULATED_INST_EXITS,
  122. EMULATED_MTMSRWE_EXITS,
  123. EMULATED_WRTEE_EXITS,
  124. EMULATED_MTSPR_EXITS,
  125. EMULATED_MFSPR_EXITS,
  126. EMULATED_MTMSR_EXITS,
  127. EMULATED_MFMSR_EXITS,
  128. EMULATED_TLBSX_EXITS,
  129. EMULATED_TLBWE_EXITS,
  130. EMULATED_RFI_EXITS,
  131. EMULATED_RFCI_EXITS,
  132. EMULATED_RFDI_EXITS,
  133. DEC_EXITS,
  134. EXT_INTR_EXITS,
  135. HALT_WAKEUP,
  136. USR_PR_INST,
  137. FP_UNAVAIL,
  138. DEBUG_EXITS,
  139. TIMEINGUEST,
  140. DBELL_EXITS,
  141. GDBELL_EXITS,
  142. __NUMBER_OF_KVM_EXIT_TYPES
  143. };
  144. /* allow access to big endian 32bit upper/lower parts and 64bit var */
  145. struct kvmppc_exit_timing {
  146. union {
  147. u64 tv64;
  148. struct {
  149. u32 tbu, tbl;
  150. } tv32;
  151. };
  152. };
  153. struct kvmppc_pginfo {
  154. unsigned long pfn;
  155. atomic_t refcnt;
  156. };
  157. struct kvmppc_spapr_tce_iommu_table {
  158. struct rcu_head rcu;
  159. struct list_head next;
  160. struct iommu_table *tbl;
  161. struct kref kref;
  162. };
  163. #define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64))
  164. struct kvmppc_spapr_tce_table {
  165. struct list_head list;
  166. struct kvm *kvm;
  167. u64 liobn;
  168. struct rcu_head rcu;
  169. u32 page_shift;
  170. u64 offset; /* in pages */
  171. u64 size; /* window size in pages */
  172. struct list_head iommu_tables;
  173. struct mutex alloc_lock;
  174. struct page *pages[];
  175. };
  176. /* XICS components, defined in book3s_xics.c */
  177. struct kvmppc_xics;
  178. struct kvmppc_icp;
  179. extern struct kvm_device_ops kvm_xics_ops;
  180. /* XIVE components, defined in book3s_xive.c */
  181. struct kvmppc_xive;
  182. struct kvmppc_xive_vcpu;
  183. extern struct kvm_device_ops kvm_xive_ops;
  184. extern struct kvm_device_ops kvm_xive_native_ops;
  185. struct kvmppc_passthru_irqmap;
  186. /*
  187. * The reverse mapping array has one entry for each HPTE,
  188. * which stores the guest's view of the second word of the HPTE
  189. * (including the guest physical address of the mapping),
  190. * plus forward and backward pointers in a doubly-linked ring
  191. * of HPTEs that map the same host page. The pointers in this
  192. * ring are 32-bit HPTE indexes, to save space.
  193. */
  194. struct revmap_entry {
  195. unsigned long guest_rpte;
  196. unsigned int forw, back;
  197. };
  198. /*
  199. * The rmap array of size number of guest pages is allocated for each memslot.
  200. * This array is used to store usage specific information about the guest page.
  201. * Below are the encodings of the various possible usage types.
  202. */
  203. /* Free bits which can be used to define a new usage */
  204. #define KVMPPC_RMAP_TYPE_MASK 0xff00000000000000
  205. #define KVMPPC_RMAP_NESTED 0xc000000000000000 /* Nested rmap array */
  206. #define KVMPPC_RMAP_HPT 0x0100000000000000 /* HPT guest */
  207. /*
  208. * rmap usage definition for a hash page table (hpt) guest:
  209. * 0x0000080000000000 Lock bit
  210. * 0x0000018000000000 RC bits
  211. * 0x0000000100000000 Present bit
  212. * 0x00000000ffffffff HPT index bits
  213. * The bottom 32 bits are the index in the guest HPT of a HPTE that points to
  214. * the page.
  215. */
  216. #define KVMPPC_RMAP_LOCK_BIT 43
  217. #define KVMPPC_RMAP_RC_SHIFT 32
  218. #define KVMPPC_RMAP_REFERENCED (HPTE_R_R << KVMPPC_RMAP_RC_SHIFT)
  219. #define KVMPPC_RMAP_PRESENT 0x100000000ul
  220. #define KVMPPC_RMAP_INDEX 0xfffffffful
  221. struct kvm_arch_memory_slot {
  222. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  223. unsigned long *rmap;
  224. #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  225. };
  226. struct kvm_hpt_info {
  227. /* Host virtual (linear mapping) address of guest HPT */
  228. unsigned long virt;
  229. /* Array of reverse mapping entries for each guest HPTE */
  230. struct revmap_entry *rev;
  231. /* Guest HPT size is 2**(order) bytes */
  232. u32 order;
  233. /* 1 if HPT allocated with CMA, 0 otherwise */
  234. int cma;
  235. };
  236. struct kvm_resize_hpt;
  237. /* Flag values for kvm_arch.secure_guest */
  238. #define KVMPPC_SECURE_INIT_START 0x1 /* H_SVM_INIT_START has been called */
  239. #define KVMPPC_SECURE_INIT_DONE 0x2 /* H_SVM_INIT_DONE completed */
  240. #define KVMPPC_SECURE_INIT_ABORT 0x4 /* H_SVM_INIT_ABORT issued */
  241. struct kvm_arch {
  242. unsigned int lpid;
  243. unsigned int smt_mode; /* # vcpus per virtual core */
  244. unsigned int emul_smt_mode; /* emualted SMT mode, on P9 */
  245. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  246. unsigned int tlb_sets;
  247. struct kvm_hpt_info hpt;
  248. atomic64_t mmio_update;
  249. unsigned int host_lpid;
  250. unsigned long host_lpcr;
  251. unsigned long sdr1;
  252. unsigned long host_sdr1;
  253. unsigned long lpcr;
  254. unsigned long vrma_slb_v;
  255. int mmu_ready;
  256. atomic_t vcpus_running;
  257. u32 online_vcores;
  258. atomic_t hpte_mod_interest;
  259. cpumask_t need_tlb_flush;
  260. u8 radix;
  261. u8 fwnmi_enabled;
  262. u8 secure_guest;
  263. u8 svm_enabled;
  264. bool nested_enable;
  265. bool dawr1_enabled;
  266. pgd_t *pgtable;
  267. u64 process_table;
  268. struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */
  269. #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  270. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  271. struct mutex hpt_mutex;
  272. #endif
  273. #ifdef CONFIG_PPC_BOOK3S_64
  274. struct list_head spapr_tce_tables;
  275. struct list_head rtas_tokens;
  276. struct mutex rtas_token_lock;
  277. DECLARE_BITMAP(enabled_hcalls, MAX_HCALL_OPCODE/4 + 1);
  278. #endif
  279. #ifdef CONFIG_KVM_MPIC
  280. struct openpic *mpic;
  281. #endif
  282. #ifdef CONFIG_KVM_XICS
  283. struct kvmppc_xics *xics;
  284. struct kvmppc_xics *xics_device;
  285. struct kvmppc_xive *xive; /* Current XIVE device in use */
  286. struct {
  287. struct kvmppc_xive *native;
  288. struct kvmppc_xive *xics_on_xive;
  289. } xive_devices;
  290. struct kvmppc_passthru_irqmap *pimap;
  291. #endif
  292. struct kvmppc_ops *kvm_ops;
  293. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  294. struct mutex uvmem_lock;
  295. struct list_head uvmem_pfns;
  296. struct mutex mmu_setup_lock; /* nests inside vcpu mutexes */
  297. u64 l1_ptcr;
  298. struct idr kvm_nested_guest_idr;
  299. /* This array can grow quite large, keep it at the end */
  300. struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
  301. #endif
  302. };
  303. #define VCORE_ENTRY_MAP(vc) ((vc)->entry_exit_map & 0xff)
  304. #define VCORE_EXIT_MAP(vc) ((vc)->entry_exit_map >> 8)
  305. #define VCORE_IS_EXITING(vc) (VCORE_EXIT_MAP(vc) != 0)
  306. /* This bit is used when a vcore exit is triggered from outside the vcore */
  307. #define VCORE_EXIT_REQ 0x10000
  308. /*
  309. * Values for vcore_state.
  310. * Note that these are arranged such that lower values
  311. * (< VCORE_SLEEPING) don't require stolen time accounting
  312. * on load/unload, and higher values do.
  313. */
  314. #define VCORE_INACTIVE 0
  315. #define VCORE_PREEMPT 1
  316. #define VCORE_PIGGYBACK 2
  317. #define VCORE_SLEEPING 3
  318. #define VCORE_RUNNING 4
  319. #define VCORE_EXITING 5
  320. #define VCORE_POLLING 6
  321. /*
  322. * Struct used to manage memory for a virtual processor area
  323. * registered by a PAPR guest. There are three types of area
  324. * that a guest can register.
  325. */
  326. struct kvmppc_vpa {
  327. unsigned long gpa; /* Current guest phys addr */
  328. void *pinned_addr; /* Address in kernel linear mapping */
  329. void *pinned_end; /* End of region */
  330. unsigned long next_gpa; /* Guest phys addr for update */
  331. unsigned long len; /* Number of bytes required */
  332. u8 update_pending; /* 1 => update pinned_addr from next_gpa */
  333. bool dirty; /* true => area has been modified by kernel */
  334. };
  335. struct kvmppc_pte {
  336. ulong eaddr;
  337. u64 vpage;
  338. ulong raddr;
  339. bool may_read : 1;
  340. bool may_write : 1;
  341. bool may_execute : 1;
  342. unsigned long wimg;
  343. unsigned long rc;
  344. u8 page_size; /* MMU_PAGE_xxx */
  345. u8 page_shift;
  346. };
  347. struct kvmppc_mmu {
  348. /* book3s_64 only */
  349. void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
  350. u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
  351. u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
  352. int (*slbfee)(struct kvm_vcpu *vcpu, gva_t eaddr, ulong *ret_slb);
  353. void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
  354. void (*slbia)(struct kvm_vcpu *vcpu);
  355. /* book3s */
  356. void (*mtsrin)(struct kvm_vcpu *vcpu, u32 srnum, ulong value);
  357. u32 (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
  358. int (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr,
  359. struct kvmppc_pte *pte, bool data, bool iswrite);
  360. void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
  361. int (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid);
  362. u64 (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);
  363. bool (*is_dcbz32)(struct kvm_vcpu *vcpu);
  364. };
  365. struct kvmppc_slb {
  366. u64 esid;
  367. u64 vsid;
  368. u64 orige;
  369. u64 origv;
  370. bool valid : 1;
  371. bool Ks : 1;
  372. bool Kp : 1;
  373. bool nx : 1;
  374. bool large : 1; /* PTEs are 16MB */
  375. bool tb : 1; /* 1TB segment */
  376. bool class : 1;
  377. u8 base_page_size; /* MMU_PAGE_xxx */
  378. };
  379. /* Struct used to accumulate timing information in HV real mode code */
  380. struct kvmhv_tb_accumulator {
  381. u64 seqcount; /* used to synchronize access, also count * 2 */
  382. u64 tb_total; /* total time in timebase ticks */
  383. u64 tb_min; /* min time */
  384. u64 tb_max; /* max time */
  385. };
  386. #ifdef CONFIG_PPC_BOOK3S_64
  387. struct kvmppc_irq_map {
  388. u32 r_hwirq;
  389. u32 v_hwirq;
  390. struct irq_desc *desc;
  391. };
  392. #define KVMPPC_PIRQ_MAPPED 1024
  393. struct kvmppc_passthru_irqmap {
  394. int n_mapped;
  395. struct kvmppc_irq_map mapped[KVMPPC_PIRQ_MAPPED];
  396. };
  397. #endif
  398. # ifdef CONFIG_PPC_E500
  399. #define KVMPPC_BOOKE_IAC_NUM 2
  400. #define KVMPPC_BOOKE_DAC_NUM 2
  401. # else
  402. #define KVMPPC_BOOKE_IAC_NUM 4
  403. #define KVMPPC_BOOKE_DAC_NUM 2
  404. # endif
  405. #define KVMPPC_BOOKE_MAX_IAC 4
  406. #define KVMPPC_BOOKE_MAX_DAC 2
  407. /* KVMPPC_EPR_USER takes precedence over KVMPPC_EPR_KERNEL */
  408. #define KVMPPC_EPR_NONE 0 /* EPR not supported */
  409. #define KVMPPC_EPR_USER 1 /* exit to userspace to fill EPR */
  410. #define KVMPPC_EPR_KERNEL 2 /* in-kernel irqchip */
  411. #define KVMPPC_IRQ_DEFAULT 0
  412. #define KVMPPC_IRQ_MPIC 1
  413. #define KVMPPC_IRQ_XICS 2 /* Includes a XIVE option */
  414. #define KVMPPC_IRQ_XIVE 3 /* XIVE native exploitation mode */
  415. #define MMIO_HPTE_CACHE_SIZE 4
  416. struct mmio_hpte_cache_entry {
  417. unsigned long hpte_v;
  418. unsigned long hpte_r;
  419. unsigned long rpte;
  420. unsigned long pte_index;
  421. unsigned long eaddr;
  422. unsigned long slb_v;
  423. long mmio_update;
  424. unsigned int slb_base_pshift;
  425. };
  426. struct mmio_hpte_cache {
  427. struct mmio_hpte_cache_entry entry[MMIO_HPTE_CACHE_SIZE];
  428. unsigned int index;
  429. };
  430. #define KVMPPC_VSX_COPY_NONE 0
  431. #define KVMPPC_VSX_COPY_WORD 1
  432. #define KVMPPC_VSX_COPY_DWORD 2
  433. #define KVMPPC_VSX_COPY_DWORD_LOAD_DUMP 3
  434. #define KVMPPC_VSX_COPY_WORD_LOAD_DUMP 4
  435. #define KVMPPC_VMX_COPY_BYTE 8
  436. #define KVMPPC_VMX_COPY_HWORD 9
  437. #define KVMPPC_VMX_COPY_WORD 10
  438. #define KVMPPC_VMX_COPY_DWORD 11
  439. struct openpic;
  440. /* W0 and W1 of a XIVE thread management context */
  441. union xive_tma_w01 {
  442. struct {
  443. u8 nsr;
  444. u8 cppr;
  445. u8 ipb;
  446. u8 lsmfb;
  447. u8 ack;
  448. u8 inc;
  449. u8 age;
  450. u8 pipr;
  451. };
  452. __be64 w01;
  453. };
  454. struct kvm_vcpu_arch {
  455. ulong host_stack;
  456. u32 host_pid;
  457. #ifdef CONFIG_PPC_BOOK3S
  458. struct kvmppc_slb slb[64];
  459. int slb_max; /* 1 + index of last valid entry in slb[] */
  460. int slb_nr; /* total number of entries in SLB */
  461. struct kvmppc_mmu mmu;
  462. struct kvmppc_vcpu_book3s *book3s;
  463. #endif
  464. #ifdef CONFIG_PPC_BOOK3S_32
  465. struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
  466. #endif
  467. /*
  468. * This is passed along to the HV via H_ENTER_NESTED. Align to
  469. * prevent it crossing a real 4K page.
  470. */
  471. struct pt_regs regs __aligned(512);
  472. struct thread_fp_state fp;
  473. #ifdef CONFIG_SPE
  474. ulong evr[32];
  475. ulong spefscr;
  476. ulong host_spefscr;
  477. u64 acc;
  478. #endif
  479. #ifdef CONFIG_ALTIVEC
  480. struct thread_vr_state vr;
  481. #endif
  482. #ifdef CONFIG_KVM_BOOKE_HV
  483. u32 host_mas4;
  484. u32 host_mas6;
  485. u32 shadow_epcr;
  486. u32 shadow_msrp;
  487. u32 eplc;
  488. u32 epsc;
  489. u32 oldpir;
  490. #endif
  491. #if defined(CONFIG_BOOKE)
  492. #if defined(CONFIG_KVM_BOOKE_HV) || defined(CONFIG_64BIT)
  493. u32 epcr;
  494. #endif
  495. #endif
  496. #ifdef CONFIG_PPC_BOOK3S
  497. /* For Gekko paired singles */
  498. u32 qpr[32];
  499. #endif
  500. #ifdef CONFIG_PPC_BOOK3S
  501. ulong tar;
  502. #endif
  503. #ifdef CONFIG_PPC_BOOK3S
  504. ulong hflags;
  505. ulong guest_owned_ext;
  506. ulong purr;
  507. ulong spurr;
  508. ulong ic;
  509. ulong dscr;
  510. ulong amr;
  511. ulong uamor;
  512. ulong iamr;
  513. u32 ctrl;
  514. u32 dabrx;
  515. ulong dabr;
  516. ulong dawr0;
  517. ulong dawrx0;
  518. ulong dawr1;
  519. ulong dawrx1;
  520. ulong ciabr;
  521. ulong cfar;
  522. ulong ppr;
  523. u32 pspb;
  524. u8 load_ebb;
  525. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  526. u8 load_tm;
  527. #endif
  528. ulong fscr;
  529. ulong shadow_fscr;
  530. ulong ebbhr;
  531. ulong ebbrr;
  532. ulong bescr;
  533. ulong csigr;
  534. ulong tacr;
  535. ulong tcscr;
  536. ulong acop;
  537. ulong wort;
  538. ulong tid;
  539. ulong psscr;
  540. ulong hfscr;
  541. ulong shadow_srr1;
  542. #endif
  543. u32 vrsave; /* also USPRG0 */
  544. u32 mmucr;
  545. /* shadow_msr is unused for BookE HV */
  546. ulong shadow_msr;
  547. ulong csrr0;
  548. ulong csrr1;
  549. ulong dsrr0;
  550. ulong dsrr1;
  551. ulong mcsrr0;
  552. ulong mcsrr1;
  553. ulong mcsr;
  554. ulong dec;
  555. #ifdef CONFIG_BOOKE
  556. u32 decar;
  557. #endif
  558. /* Time base value when we entered the guest */
  559. u64 entry_tb;
  560. u64 entry_vtb;
  561. u64 entry_ic;
  562. u32 tcr;
  563. ulong tsr; /* we need to perform set/clr_bits() which requires ulong */
  564. u32 ivor[64];
  565. ulong ivpr;
  566. u32 pvr;
  567. u32 shadow_pid;
  568. u32 shadow_pid1;
  569. u32 pid;
  570. u32 swap_pid;
  571. u32 ccr0;
  572. u32 ccr1;
  573. u32 dbsr;
  574. u64 mmcr[4]; /* MMCR0, MMCR1, MMCR2, MMCR3 */
  575. u64 mmcra;
  576. u64 mmcrs;
  577. u32 pmc[8];
  578. u32 spmc[2];
  579. u64 siar;
  580. u64 sdar;
  581. u64 sier[3];
  582. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  583. u64 tfhar;
  584. u64 texasr;
  585. u64 tfiar;
  586. u64 orig_texasr;
  587. u32 cr_tm;
  588. u64 xer_tm;
  589. u64 lr_tm;
  590. u64 ctr_tm;
  591. u64 amr_tm;
  592. u64 ppr_tm;
  593. u64 dscr_tm;
  594. u64 tar_tm;
  595. ulong gpr_tm[32];
  596. struct thread_fp_state fp_tm;
  597. struct thread_vr_state vr_tm;
  598. u32 vrsave_tm; /* also USPRG0 */
  599. #endif
  600. #ifdef CONFIG_KVM_EXIT_TIMING
  601. struct mutex exit_timing_lock;
  602. struct kvmppc_exit_timing timing_exit;
  603. struct kvmppc_exit_timing timing_last_enter;
  604. u32 last_exit_type;
  605. u32 timing_count_type[__NUMBER_OF_KVM_EXIT_TYPES];
  606. u64 timing_sum_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  607. u64 timing_sum_quad_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  608. u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  609. u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  610. u64 timing_last_exit;
  611. #endif
  612. #ifdef CONFIG_PPC_BOOK3S
  613. ulong fault_dar;
  614. u32 fault_dsisr;
  615. unsigned long intr_msr;
  616. /*
  617. * POWER9 and later: fault_gpa contains the guest real address of page
  618. * fault for a radix guest, or segment descriptor (equivalent to result
  619. * from slbmfev of SLB entry that translated the EA) for hash guests.
  620. */
  621. ulong fault_gpa;
  622. #endif
  623. #ifdef CONFIG_BOOKE
  624. ulong fault_dear;
  625. ulong fault_esr;
  626. ulong queued_dear;
  627. ulong queued_esr;
  628. spinlock_t wdt_lock;
  629. struct timer_list wdt_timer;
  630. u32 tlbcfg[4];
  631. u32 tlbps[4];
  632. u32 mmucfg;
  633. u32 eptcfg;
  634. u32 epr;
  635. u64 sprg9;
  636. u32 pwrmgtcr0;
  637. u32 crit_save;
  638. /* guest debug registers*/
  639. struct debug_reg dbg_reg;
  640. #endif
  641. gpa_t paddr_accessed;
  642. gva_t vaddr_accessed;
  643. pgd_t *pgdir;
  644. u16 io_gpr; /* GPR used as IO source/target */
  645. u8 mmio_host_swabbed;
  646. u8 mmio_sign_extend;
  647. /* conversion between single and double precision */
  648. u8 mmio_sp64_extend;
  649. /*
  650. * Number of simulations for vsx.
  651. * If we use 2*8bytes to simulate 1*16bytes,
  652. * then the number should be 2 and
  653. * mmio_copy_type=KVMPPC_VSX_COPY_DWORD.
  654. * If we use 4*4bytes to simulate 1*16bytes,
  655. * the number should be 4 and
  656. * mmio_vsx_copy_type=KVMPPC_VSX_COPY_WORD.
  657. */
  658. u8 mmio_vsx_copy_nums;
  659. u8 mmio_vsx_offset;
  660. u8 mmio_vmx_copy_nums;
  661. u8 mmio_vmx_offset;
  662. u8 mmio_copy_type;
  663. u8 osi_needed;
  664. u8 osi_enabled;
  665. u8 papr_enabled;
  666. u8 watchdog_enabled;
  667. u8 sane;
  668. u8 cpu_type;
  669. u8 hcall_needed;
  670. u8 epr_flags; /* KVMPPC_EPR_xxx */
  671. u8 epr_needed;
  672. u8 external_oneshot; /* clear external irq after delivery */
  673. u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
  674. struct hrtimer dec_timer;
  675. u64 dec_jiffies;
  676. u64 dec_expires; /* Relative to guest timebase. */
  677. unsigned long pending_exceptions;
  678. u8 ceded;
  679. u8 prodded;
  680. u8 doorbell_request;
  681. u8 irq_pending; /* Used by XIVE to signal pending guest irqs */
  682. u32 last_inst;
  683. struct rcuwait wait;
  684. struct rcuwait *waitp;
  685. struct kvmppc_vcore *vcore;
  686. int ret;
  687. int trap;
  688. int state;
  689. int ptid;
  690. int thread_cpu;
  691. int prev_cpu;
  692. bool timer_running;
  693. wait_queue_head_t cpu_run;
  694. struct machine_check_event mce_evt; /* Valid if trap == 0x200 */
  695. struct kvm_vcpu_arch_shared *shared;
  696. #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
  697. bool shared_big_endian;
  698. #endif
  699. unsigned long magic_page_pa; /* phys addr to map the magic page to */
  700. unsigned long magic_page_ea; /* effect. addr to map the magic page to */
  701. bool disable_kernel_nx;
  702. int irq_type; /* one of KVM_IRQ_* */
  703. int irq_cpu_id;
  704. struct openpic *mpic; /* KVM_IRQ_MPIC */
  705. #ifdef CONFIG_KVM_XICS
  706. struct kvmppc_icp *icp; /* XICS presentation controller */
  707. struct kvmppc_xive_vcpu *xive_vcpu; /* XIVE virtual CPU data */
  708. __be32 xive_cam_word; /* Cooked W2 in proper endian with valid bit */
  709. u8 xive_pushed; /* Is the VP pushed on the physical CPU ? */
  710. u8 xive_esc_on; /* Is the escalation irq enabled ? */
  711. union xive_tma_w01 xive_saved_state; /* W0..1 of XIVE thread state */
  712. u64 xive_esc_raddr; /* Escalation interrupt ESB real addr */
  713. u64 xive_esc_vaddr; /* Escalation interrupt ESB virt addr */
  714. #endif
  715. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  716. struct kvm_vcpu_arch_shared shregs;
  717. struct mmio_hpte_cache mmio_cache;
  718. unsigned long pgfault_addr;
  719. long pgfault_index;
  720. unsigned long pgfault_hpte[2];
  721. struct mmio_hpte_cache_entry *pgfault_cache;
  722. struct task_struct *run_task;
  723. spinlock_t vpa_update_lock;
  724. struct kvmppc_vpa vpa;
  725. struct kvmppc_vpa dtl;
  726. struct dtl_entry *dtl_ptr;
  727. unsigned long dtl_index;
  728. u64 stolen_logged;
  729. struct kvmppc_vpa slb_shadow;
  730. spinlock_t tbacct_lock;
  731. u64 busy_stolen;
  732. u64 busy_preempt;
  733. u32 emul_inst;
  734. u32 online;
  735. u64 hfscr_permitted; /* A mask of permitted HFSCR facilities */
  736. /* For support of nested guests */
  737. struct kvm_nested_guest *nested;
  738. u64 nested_hfscr; /* HFSCR that the L1 requested for the nested guest */
  739. u32 nested_vcpu_id;
  740. gpa_t nested_io_gpr;
  741. #endif
  742. #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING
  743. struct kvmhv_tb_accumulator *cur_activity; /* What we're timing */
  744. u64 cur_tb_start; /* when it started */
  745. #ifdef CONFIG_KVM_BOOK3S_HV_P9_TIMING
  746. struct kvmhv_tb_accumulator vcpu_entry;
  747. struct kvmhv_tb_accumulator vcpu_exit;
  748. struct kvmhv_tb_accumulator in_guest;
  749. struct kvmhv_tb_accumulator hcall;
  750. struct kvmhv_tb_accumulator pg_fault;
  751. struct kvmhv_tb_accumulator guest_entry;
  752. struct kvmhv_tb_accumulator guest_exit;
  753. #else
  754. struct kvmhv_tb_accumulator rm_entry; /* real-mode entry code */
  755. struct kvmhv_tb_accumulator rm_intr; /* real-mode intr handling */
  756. struct kvmhv_tb_accumulator rm_exit; /* real-mode exit code */
  757. struct kvmhv_tb_accumulator guest_time; /* guest execution */
  758. struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */
  759. #endif
  760. #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
  761. };
  762. #define VCPU_FPR(vcpu, i) (vcpu)->arch.fp.fpr[i][TS_FPROFFSET]
  763. #define VCPU_VSX_FPR(vcpu, i, j) ((vcpu)->arch.fp.fpr[i][j])
  764. #define VCPU_VSX_VR(vcpu, i) ((vcpu)->arch.vr.vr[i])
  765. /* Values for vcpu->arch.state */
  766. #define KVMPPC_VCPU_NOTREADY 0
  767. #define KVMPPC_VCPU_RUNNABLE 1
  768. #define KVMPPC_VCPU_BUSY_IN_HOST 2
  769. /* Values for vcpu->arch.io_gpr */
  770. #define KVM_MMIO_REG_MASK 0x003f
  771. #define KVM_MMIO_REG_EXT_MASK 0xffc0
  772. #define KVM_MMIO_REG_GPR 0x0000
  773. #define KVM_MMIO_REG_FPR 0x0040
  774. #define KVM_MMIO_REG_QPR 0x0080
  775. #define KVM_MMIO_REG_FQPR 0x00c0
  776. #define KVM_MMIO_REG_VSX 0x0100
  777. #define KVM_MMIO_REG_VMX 0x0180
  778. #define KVM_MMIO_REG_NESTED_GPR 0xffc0
  779. #define __KVM_HAVE_ARCH_WQP
  780. #define __KVM_HAVE_CREATE_DEVICE
  781. static inline void kvm_arch_hardware_disable(void) {}
  782. static inline void kvm_arch_hardware_unsetup(void) {}
  783. static inline void kvm_arch_sync_events(struct kvm *kvm) {}
  784. static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {}
  785. static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
  786. static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
  787. static inline void kvm_arch_exit(void) {}
  788. static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
  789. static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
  790. #endif /* __POWERPC_KVM_HOST_H__ */