kvm_host.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright IBM Corp. 2007
  16. *
  17. * Authors: Hollis Blanchard <hollisb@us.ibm.com>
  18. */
  19. #ifndef __POWERPC_KVM_HOST_H__
  20. #define __POWERPC_KVM_HOST_H__
  21. #include <linux/mutex.h>
  22. #include <linux/hrtimer.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/types.h>
  25. #include <linux/kvm_types.h>
  26. #include <linux/threads.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/kvm_para.h>
  29. #include <linux/list.h>
  30. #include <linux/atomic.h>
  31. #include <asm/kvm_asm.h>
  32. #include <asm/processor.h>
  33. #include <asm/page.h>
  34. #include <asm/cacheflush.h>
  35. #include <asm/hvcall.h>
  36. #define KVM_MAX_VCPUS NR_CPUS
  37. #define KVM_MAX_VCORES NR_CPUS
  38. #define KVM_USER_MEM_SLOTS 512
  39. #include <asm/cputhreads.h>
  40. #define KVM_MAX_VCPU_ID (threads_per_subcore * KVM_MAX_VCORES)
  41. #define __KVM_HAVE_ARCH_INTC_INITIALIZED
  42. #ifdef CONFIG_KVM_MMIO
  43. #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
  44. #endif
  45. #define KVM_HALT_POLL_NS_DEFAULT 500000
  46. /* These values are internal and can be increased later */
  47. #define KVM_NR_IRQCHIPS 1
  48. #define KVM_IRQCHIP_NUM_PINS 256
  49. /* PPC-specific vcpu->requests bit members */
  50. #define KVM_REQ_WATCHDOG 8
  51. #define KVM_REQ_EPR_EXIT 9
  52. #include <linux/mmu_notifier.h>
  53. #define KVM_ARCH_WANT_MMU_NOTIFIER
  54. extern int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
  55. extern int kvm_unmap_hva_range(struct kvm *kvm,
  56. unsigned long start, unsigned long end);
  57. extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
  58. extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
  59. extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
  60. static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
  61. unsigned long address)
  62. {
  63. }
  64. #define HPTEG_CACHE_NUM (1 << 15)
  65. #define HPTEG_HASH_BITS_PTE 13
  66. #define HPTEG_HASH_BITS_PTE_LONG 12
  67. #define HPTEG_HASH_BITS_VPTE 13
  68. #define HPTEG_HASH_BITS_VPTE_LONG 5
  69. #define HPTEG_HASH_BITS_VPTE_64K 11
  70. #define HPTEG_HASH_NUM_PTE (1 << HPTEG_HASH_BITS_PTE)
  71. #define HPTEG_HASH_NUM_PTE_LONG (1 << HPTEG_HASH_BITS_PTE_LONG)
  72. #define HPTEG_HASH_NUM_VPTE (1 << HPTEG_HASH_BITS_VPTE)
  73. #define HPTEG_HASH_NUM_VPTE_LONG (1 << HPTEG_HASH_BITS_VPTE_LONG)
  74. #define HPTEG_HASH_NUM_VPTE_64K (1 << HPTEG_HASH_BITS_VPTE_64K)
  75. /* Physical Address Mask - allowed range of real mode RAM access */
  76. #define KVM_PAM 0x0fffffffffffffffULL
  77. struct lppaca;
  78. struct slb_shadow;
  79. struct dtl_entry;
  80. struct kvmppc_vcpu_book3s;
  81. struct kvmppc_book3s_shadow_vcpu;
  82. struct kvm_vm_stat {
  83. ulong remote_tlb_flush;
  84. };
  85. struct kvm_vcpu_stat {
  86. u64 sum_exits;
  87. u64 mmio_exits;
  88. u64 signal_exits;
  89. u64 light_exits;
  90. /* Account for special types of light exits: */
  91. u64 itlb_real_miss_exits;
  92. u64 itlb_virt_miss_exits;
  93. u64 dtlb_real_miss_exits;
  94. u64 dtlb_virt_miss_exits;
  95. u64 syscall_exits;
  96. u64 isi_exits;
  97. u64 dsi_exits;
  98. u64 emulated_inst_exits;
  99. u64 dec_exits;
  100. u64 ext_intr_exits;
  101. u64 halt_poll_success_ns;
  102. u64 halt_poll_fail_ns;
  103. u64 halt_wait_ns;
  104. u64 halt_successful_poll;
  105. u64 halt_attempted_poll;
  106. u64 halt_successful_wait;
  107. u64 halt_poll_invalid;
  108. u64 halt_wakeup;
  109. u64 dbell_exits;
  110. u64 gdbell_exits;
  111. u64 ld;
  112. u64 st;
  113. #ifdef CONFIG_PPC_BOOK3S
  114. u64 pf_storage;
  115. u64 pf_instruc;
  116. u64 sp_storage;
  117. u64 sp_instruc;
  118. u64 queue_intr;
  119. u64 ld_slow;
  120. u64 st_slow;
  121. #endif
  122. u64 pthru_all;
  123. u64 pthru_host;
  124. u64 pthru_bad_aff;
  125. };
  126. enum kvm_exit_types {
  127. MMIO_EXITS,
  128. SIGNAL_EXITS,
  129. ITLB_REAL_MISS_EXITS,
  130. ITLB_VIRT_MISS_EXITS,
  131. DTLB_REAL_MISS_EXITS,
  132. DTLB_VIRT_MISS_EXITS,
  133. SYSCALL_EXITS,
  134. ISI_EXITS,
  135. DSI_EXITS,
  136. EMULATED_INST_EXITS,
  137. EMULATED_MTMSRWE_EXITS,
  138. EMULATED_WRTEE_EXITS,
  139. EMULATED_MTSPR_EXITS,
  140. EMULATED_MFSPR_EXITS,
  141. EMULATED_MTMSR_EXITS,
  142. EMULATED_MFMSR_EXITS,
  143. EMULATED_TLBSX_EXITS,
  144. EMULATED_TLBWE_EXITS,
  145. EMULATED_RFI_EXITS,
  146. EMULATED_RFCI_EXITS,
  147. EMULATED_RFDI_EXITS,
  148. DEC_EXITS,
  149. EXT_INTR_EXITS,
  150. HALT_WAKEUP,
  151. USR_PR_INST,
  152. FP_UNAVAIL,
  153. DEBUG_EXITS,
  154. TIMEINGUEST,
  155. DBELL_EXITS,
  156. GDBELL_EXITS,
  157. __NUMBER_OF_KVM_EXIT_TYPES
  158. };
  159. /* allow access to big endian 32bit upper/lower parts and 64bit var */
  160. struct kvmppc_exit_timing {
  161. union {
  162. u64 tv64;
  163. struct {
  164. u32 tbu, tbl;
  165. } tv32;
  166. };
  167. };
  168. struct kvmppc_pginfo {
  169. unsigned long pfn;
  170. atomic_t refcnt;
  171. };
  172. struct kvmppc_spapr_tce_table {
  173. struct list_head list;
  174. struct kvm *kvm;
  175. u64 liobn;
  176. struct rcu_head rcu;
  177. u32 page_shift;
  178. u64 offset; /* in pages */
  179. u64 size; /* window size in pages */
  180. struct page *pages[0];
  181. };
  182. /* XICS components, defined in book3s_xics.c */
  183. struct kvmppc_xics;
  184. struct kvmppc_icp;
  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. * We use the top bit of each memslot->arch.rmap entry as a lock bit,
  200. * and bit 32 as a present flag. The bottom 32 bits are the
  201. * index in the guest HPT of a HPTE that points to the page.
  202. */
  203. #define KVMPPC_RMAP_LOCK_BIT 63
  204. #define KVMPPC_RMAP_RC_SHIFT 32
  205. #define KVMPPC_RMAP_CHG_SHIFT 48
  206. #define KVMPPC_RMAP_REFERENCED (HPTE_R_R << KVMPPC_RMAP_RC_SHIFT)
  207. #define KVMPPC_RMAP_CHANGED (HPTE_R_C << KVMPPC_RMAP_RC_SHIFT)
  208. #define KVMPPC_RMAP_CHG_ORDER (0x3ful << KVMPPC_RMAP_CHG_SHIFT)
  209. #define KVMPPC_RMAP_PRESENT 0x100000000ul
  210. #define KVMPPC_RMAP_INDEX 0xfffffffful
  211. struct kvm_arch_memory_slot {
  212. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  213. unsigned long *rmap;
  214. #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  215. };
  216. struct kvm_arch {
  217. unsigned int lpid;
  218. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  219. unsigned long hpt_virt;
  220. struct revmap_entry *revmap;
  221. unsigned int host_lpid;
  222. unsigned long host_lpcr;
  223. unsigned long sdr1;
  224. unsigned long host_sdr1;
  225. int tlbie_lock;
  226. unsigned long lpcr;
  227. unsigned long vrma_slb_v;
  228. int hpte_setup_done;
  229. u32 hpt_order;
  230. atomic_t vcpus_running;
  231. u32 online_vcores;
  232. unsigned long hpt_npte;
  233. unsigned long hpt_mask;
  234. atomic_t hpte_mod_interest;
  235. cpumask_t need_tlb_flush;
  236. int hpt_cma_alloc;
  237. struct dentry *debugfs_dir;
  238. struct dentry *htab_dentry;
  239. #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  240. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  241. struct mutex hpt_mutex;
  242. #endif
  243. #ifdef CONFIG_PPC_BOOK3S_64
  244. struct list_head spapr_tce_tables;
  245. struct list_head rtas_tokens;
  246. DECLARE_BITMAP(enabled_hcalls, MAX_HCALL_OPCODE/4 + 1);
  247. #endif
  248. #ifdef CONFIG_KVM_MPIC
  249. struct openpic *mpic;
  250. #endif
  251. #ifdef CONFIG_KVM_XICS
  252. struct kvmppc_xics *xics;
  253. struct kvmppc_passthru_irqmap *pimap;
  254. #endif
  255. struct kvmppc_ops *kvm_ops;
  256. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  257. /* This array can grow quite large, keep it at the end */
  258. struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
  259. #endif
  260. };
  261. #define VCORE_ENTRY_MAP(vc) ((vc)->entry_exit_map & 0xff)
  262. #define VCORE_EXIT_MAP(vc) ((vc)->entry_exit_map >> 8)
  263. #define VCORE_IS_EXITING(vc) (VCORE_EXIT_MAP(vc) != 0)
  264. /* This bit is used when a vcore exit is triggered from outside the vcore */
  265. #define VCORE_EXIT_REQ 0x10000
  266. /*
  267. * Values for vcore_state.
  268. * Note that these are arranged such that lower values
  269. * (< VCORE_SLEEPING) don't require stolen time accounting
  270. * on load/unload, and higher values do.
  271. */
  272. #define VCORE_INACTIVE 0
  273. #define VCORE_PREEMPT 1
  274. #define VCORE_PIGGYBACK 2
  275. #define VCORE_SLEEPING 3
  276. #define VCORE_RUNNING 4
  277. #define VCORE_EXITING 5
  278. #define VCORE_POLLING 6
  279. /*
  280. * Struct used to manage memory for a virtual processor area
  281. * registered by a PAPR guest. There are three types of area
  282. * that a guest can register.
  283. */
  284. struct kvmppc_vpa {
  285. unsigned long gpa; /* Current guest phys addr */
  286. void *pinned_addr; /* Address in kernel linear mapping */
  287. void *pinned_end; /* End of region */
  288. unsigned long next_gpa; /* Guest phys addr for update */
  289. unsigned long len; /* Number of bytes required */
  290. u8 update_pending; /* 1 => update pinned_addr from next_gpa */
  291. bool dirty; /* true => area has been modified by kernel */
  292. };
  293. struct kvmppc_pte {
  294. ulong eaddr;
  295. u64 vpage;
  296. ulong raddr;
  297. bool may_read : 1;
  298. bool may_write : 1;
  299. bool may_execute : 1;
  300. u8 page_size; /* MMU_PAGE_xxx */
  301. };
  302. struct kvmppc_mmu {
  303. /* book3s_64 only */
  304. void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
  305. u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
  306. u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
  307. void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
  308. void (*slbia)(struct kvm_vcpu *vcpu);
  309. /* book3s */
  310. void (*mtsrin)(struct kvm_vcpu *vcpu, u32 srnum, ulong value);
  311. u32 (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
  312. int (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr,
  313. struct kvmppc_pte *pte, bool data, bool iswrite);
  314. void (*reset_msr)(struct kvm_vcpu *vcpu);
  315. void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
  316. int (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid);
  317. u64 (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);
  318. bool (*is_dcbz32)(struct kvm_vcpu *vcpu);
  319. };
  320. struct kvmppc_slb {
  321. u64 esid;
  322. u64 vsid;
  323. u64 orige;
  324. u64 origv;
  325. bool valid : 1;
  326. bool Ks : 1;
  327. bool Kp : 1;
  328. bool nx : 1;
  329. bool large : 1; /* PTEs are 16MB */
  330. bool tb : 1; /* 1TB segment */
  331. bool class : 1;
  332. u8 base_page_size; /* MMU_PAGE_xxx */
  333. };
  334. /* Struct used to accumulate timing information in HV real mode code */
  335. struct kvmhv_tb_accumulator {
  336. u64 seqcount; /* used to synchronize access, also count * 2 */
  337. u64 tb_total; /* total time in timebase ticks */
  338. u64 tb_min; /* min time */
  339. u64 tb_max; /* max time */
  340. };
  341. #ifdef CONFIG_PPC_BOOK3S_64
  342. struct kvmppc_irq_map {
  343. u32 r_hwirq;
  344. u32 v_hwirq;
  345. struct irq_desc *desc;
  346. };
  347. #define KVMPPC_PIRQ_MAPPED 1024
  348. struct kvmppc_passthru_irqmap {
  349. int n_mapped;
  350. struct kvmppc_irq_map mapped[KVMPPC_PIRQ_MAPPED];
  351. };
  352. #endif
  353. # ifdef CONFIG_PPC_FSL_BOOK3E
  354. #define KVMPPC_BOOKE_IAC_NUM 2
  355. #define KVMPPC_BOOKE_DAC_NUM 2
  356. # else
  357. #define KVMPPC_BOOKE_IAC_NUM 4
  358. #define KVMPPC_BOOKE_DAC_NUM 2
  359. # endif
  360. #define KVMPPC_BOOKE_MAX_IAC 4
  361. #define KVMPPC_BOOKE_MAX_DAC 2
  362. /* KVMPPC_EPR_USER takes precedence over KVMPPC_EPR_KERNEL */
  363. #define KVMPPC_EPR_NONE 0 /* EPR not supported */
  364. #define KVMPPC_EPR_USER 1 /* exit to userspace to fill EPR */
  365. #define KVMPPC_EPR_KERNEL 2 /* in-kernel irqchip */
  366. #define KVMPPC_IRQ_DEFAULT 0
  367. #define KVMPPC_IRQ_MPIC 1
  368. #define KVMPPC_IRQ_XICS 2
  369. struct openpic;
  370. struct kvm_vcpu_arch {
  371. ulong host_stack;
  372. u32 host_pid;
  373. #ifdef CONFIG_PPC_BOOK3S
  374. struct kvmppc_slb slb[64];
  375. int slb_max; /* 1 + index of last valid entry in slb[] */
  376. int slb_nr; /* total number of entries in SLB */
  377. struct kvmppc_mmu mmu;
  378. struct kvmppc_vcpu_book3s *book3s;
  379. #endif
  380. #ifdef CONFIG_PPC_BOOK3S_32
  381. struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
  382. #endif
  383. ulong gpr[32];
  384. struct thread_fp_state fp;
  385. #ifdef CONFIG_SPE
  386. ulong evr[32];
  387. ulong spefscr;
  388. ulong host_spefscr;
  389. u64 acc;
  390. #endif
  391. #ifdef CONFIG_ALTIVEC
  392. struct thread_vr_state vr;
  393. #endif
  394. #ifdef CONFIG_KVM_BOOKE_HV
  395. u32 host_mas4;
  396. u32 host_mas6;
  397. u32 shadow_epcr;
  398. u32 shadow_msrp;
  399. u32 eplc;
  400. u32 epsc;
  401. u32 oldpir;
  402. #endif
  403. #if defined(CONFIG_BOOKE)
  404. #if defined(CONFIG_KVM_BOOKE_HV) || defined(CONFIG_64BIT)
  405. u32 epcr;
  406. #endif
  407. #endif
  408. #ifdef CONFIG_PPC_BOOK3S
  409. /* For Gekko paired singles */
  410. u32 qpr[32];
  411. #endif
  412. ulong pc;
  413. ulong ctr;
  414. ulong lr;
  415. #ifdef CONFIG_PPC_BOOK3S
  416. ulong tar;
  417. #endif
  418. ulong xer;
  419. u32 cr;
  420. #ifdef CONFIG_PPC_BOOK3S
  421. ulong hflags;
  422. ulong guest_owned_ext;
  423. ulong purr;
  424. ulong spurr;
  425. ulong ic;
  426. ulong dscr;
  427. ulong amr;
  428. ulong uamor;
  429. ulong iamr;
  430. u32 ctrl;
  431. u32 dabrx;
  432. ulong dabr;
  433. ulong dawr;
  434. ulong dawrx;
  435. ulong ciabr;
  436. ulong cfar;
  437. ulong ppr;
  438. u32 pspb;
  439. ulong fscr;
  440. ulong shadow_fscr;
  441. ulong ebbhr;
  442. ulong ebbrr;
  443. ulong bescr;
  444. ulong csigr;
  445. ulong tacr;
  446. ulong tcscr;
  447. ulong acop;
  448. ulong wort;
  449. ulong shadow_srr1;
  450. #endif
  451. u32 vrsave; /* also USPRG0 */
  452. u32 mmucr;
  453. /* shadow_msr is unused for BookE HV */
  454. ulong shadow_msr;
  455. ulong csrr0;
  456. ulong csrr1;
  457. ulong dsrr0;
  458. ulong dsrr1;
  459. ulong mcsrr0;
  460. ulong mcsrr1;
  461. ulong mcsr;
  462. u32 dec;
  463. #ifdef CONFIG_BOOKE
  464. u32 decar;
  465. #endif
  466. /* Time base value when we entered the guest */
  467. u64 entry_tb;
  468. u64 entry_vtb;
  469. u64 entry_ic;
  470. u32 tcr;
  471. ulong tsr; /* we need to perform set/clr_bits() which requires ulong */
  472. u32 ivor[64];
  473. ulong ivpr;
  474. u32 pvr;
  475. u32 shadow_pid;
  476. u32 shadow_pid1;
  477. u32 pid;
  478. u32 swap_pid;
  479. u32 ccr0;
  480. u32 ccr1;
  481. u32 dbsr;
  482. u64 mmcr[5];
  483. u32 pmc[8];
  484. u32 spmc[2];
  485. u64 siar;
  486. u64 sdar;
  487. u64 sier;
  488. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  489. u64 tfhar;
  490. u64 texasr;
  491. u64 tfiar;
  492. u32 cr_tm;
  493. u64 xer_tm;
  494. u64 lr_tm;
  495. u64 ctr_tm;
  496. u64 amr_tm;
  497. u64 ppr_tm;
  498. u64 dscr_tm;
  499. u64 tar_tm;
  500. ulong gpr_tm[32];
  501. struct thread_fp_state fp_tm;
  502. struct thread_vr_state vr_tm;
  503. u32 vrsave_tm; /* also USPRG0 */
  504. #endif
  505. #ifdef CONFIG_KVM_EXIT_TIMING
  506. struct mutex exit_timing_lock;
  507. struct kvmppc_exit_timing timing_exit;
  508. struct kvmppc_exit_timing timing_last_enter;
  509. u32 last_exit_type;
  510. u32 timing_count_type[__NUMBER_OF_KVM_EXIT_TYPES];
  511. u64 timing_sum_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  512. u64 timing_sum_quad_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  513. u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  514. u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];
  515. u64 timing_last_exit;
  516. struct dentry *debugfs_exit_timing;
  517. #endif
  518. #ifdef CONFIG_PPC_BOOK3S
  519. ulong fault_dar;
  520. u32 fault_dsisr;
  521. unsigned long intr_msr;
  522. #endif
  523. #ifdef CONFIG_BOOKE
  524. ulong fault_dear;
  525. ulong fault_esr;
  526. ulong queued_dear;
  527. ulong queued_esr;
  528. spinlock_t wdt_lock;
  529. struct timer_list wdt_timer;
  530. u32 tlbcfg[4];
  531. u32 tlbps[4];
  532. u32 mmucfg;
  533. u32 eptcfg;
  534. u32 epr;
  535. u64 sprg9;
  536. u32 pwrmgtcr0;
  537. u32 crit_save;
  538. /* guest debug registers*/
  539. struct debug_reg dbg_reg;
  540. #endif
  541. gpa_t paddr_accessed;
  542. gva_t vaddr_accessed;
  543. pgd_t *pgdir;
  544. u8 io_gpr; /* GPR used as IO source/target */
  545. u8 mmio_host_swabbed;
  546. u8 mmio_sign_extend;
  547. u8 osi_needed;
  548. u8 osi_enabled;
  549. u8 papr_enabled;
  550. u8 watchdog_enabled;
  551. u8 sane;
  552. u8 cpu_type;
  553. u8 hcall_needed;
  554. u8 epr_flags; /* KVMPPC_EPR_xxx */
  555. u8 epr_needed;
  556. u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
  557. struct hrtimer dec_timer;
  558. u64 dec_jiffies;
  559. u64 dec_expires;
  560. unsigned long pending_exceptions;
  561. u8 ceded;
  562. u8 prodded;
  563. u32 last_inst;
  564. struct swait_queue_head *wqp;
  565. struct kvmppc_vcore *vcore;
  566. int ret;
  567. int trap;
  568. int state;
  569. int ptid;
  570. int thread_cpu;
  571. bool timer_running;
  572. wait_queue_head_t cpu_run;
  573. struct kvm_vcpu_arch_shared *shared;
  574. #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
  575. bool shared_big_endian;
  576. #endif
  577. unsigned long magic_page_pa; /* phys addr to map the magic page to */
  578. unsigned long magic_page_ea; /* effect. addr to map the magic page to */
  579. bool disable_kernel_nx;
  580. int irq_type; /* one of KVM_IRQ_* */
  581. int irq_cpu_id;
  582. struct openpic *mpic; /* KVM_IRQ_MPIC */
  583. #ifdef CONFIG_KVM_XICS
  584. struct kvmppc_icp *icp; /* XICS presentation controller */
  585. #endif
  586. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  587. struct kvm_vcpu_arch_shared shregs;
  588. unsigned long pgfault_addr;
  589. long pgfault_index;
  590. unsigned long pgfault_hpte[2];
  591. struct task_struct *run_task;
  592. struct kvm_run *kvm_run;
  593. spinlock_t vpa_update_lock;
  594. struct kvmppc_vpa vpa;
  595. struct kvmppc_vpa dtl;
  596. struct dtl_entry *dtl_ptr;
  597. unsigned long dtl_index;
  598. u64 stolen_logged;
  599. struct kvmppc_vpa slb_shadow;
  600. spinlock_t tbacct_lock;
  601. u64 busy_stolen;
  602. u64 busy_preempt;
  603. u32 emul_inst;
  604. #endif
  605. #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING
  606. struct kvmhv_tb_accumulator *cur_activity; /* What we're timing */
  607. u64 cur_tb_start; /* when it started */
  608. struct kvmhv_tb_accumulator rm_entry; /* real-mode entry code */
  609. struct kvmhv_tb_accumulator rm_intr; /* real-mode intr handling */
  610. struct kvmhv_tb_accumulator rm_exit; /* real-mode exit code */
  611. struct kvmhv_tb_accumulator guest_time; /* guest execution */
  612. struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */
  613. struct dentry *debugfs_dir;
  614. struct dentry *debugfs_timings;
  615. #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
  616. };
  617. #define VCPU_FPR(vcpu, i) (vcpu)->arch.fp.fpr[i][TS_FPROFFSET]
  618. /* Values for vcpu->arch.state */
  619. #define KVMPPC_VCPU_NOTREADY 0
  620. #define KVMPPC_VCPU_RUNNABLE 1
  621. #define KVMPPC_VCPU_BUSY_IN_HOST 2
  622. /* Values for vcpu->arch.io_gpr */
  623. #define KVM_MMIO_REG_MASK 0x001f
  624. #define KVM_MMIO_REG_EXT_MASK 0xffe0
  625. #define KVM_MMIO_REG_GPR 0x0000
  626. #define KVM_MMIO_REG_FPR 0x0020
  627. #define KVM_MMIO_REG_QPR 0x0040
  628. #define KVM_MMIO_REG_FQPR 0x0060
  629. #define __KVM_HAVE_ARCH_WQP
  630. #define __KVM_HAVE_CREATE_DEVICE
  631. static inline void kvm_arch_hardware_disable(void) {}
  632. static inline void kvm_arch_hardware_unsetup(void) {}
  633. static inline void kvm_arch_sync_events(struct kvm *kvm) {}
  634. static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {}
  635. static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
  636. static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
  637. static inline void kvm_arch_exit(void) {}
  638. static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
  639. static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
  640. static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}
  641. #endif /* __POWERPC_KVM_HOST_H__ */