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