Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 *
4 * Copyright IBM Corp. 2008
5 *
6 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
7 */
8
9#ifndef __POWERPC_KVM_PPC_H__
10#define __POWERPC_KVM_PPC_H__
11
12/* This file exists just so we can dereference kvm_vcpu, avoiding nested header
13 * dependencies. */
14
15#include <linux/mutex.h>
16#include <linux/timer.h>
17#include <linux/types.h>
18#include <linux/kvm_types.h>
19#include <linux/kvm_host.h>
20#include <linux/bug.h>
21#ifdef CONFIG_PPC_BOOK3S
22#include <asm/kvm_book3s.h>
23#else
24#include <asm/kvm_booke.h>
25#endif
26#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
27#include <asm/paca.h>
28#include <asm/xive.h>
29#include <asm/cpu_has_feature.h>
30#endif
31
32/*
33 * KVMPPC_INST_SW_BREAKPOINT is debug Instruction
34 * for supporting software breakpoint.
35 */
36#define KVMPPC_INST_SW_BREAKPOINT 0x00dddd00
37
38enum emulation_result {
39 EMULATE_DONE, /* no further processing */
40 EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */
41 EMULATE_FAIL, /* can't emulate this instruction */
42 EMULATE_AGAIN, /* something went wrong. go again */
43 EMULATE_EXIT_USER, /* emulation requires exit to user-space */
44};
45
46enum instruction_fetch_type {
47 INST_GENERIC,
48 INST_SC, /* system call */
49};
50
51enum xlate_instdata {
52 XLATE_INST, /* translate instruction address */
53 XLATE_DATA /* translate data address */
54};
55
56enum xlate_readwrite {
57 XLATE_READ, /* check for read permissions */
58 XLATE_WRITE /* check for write permissions */
59};
60
61extern int kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
62extern int __kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
63extern void kvmppc_handler_highmem(void);
64
65extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
66extern int kvmppc_handle_load(struct kvm_vcpu *vcpu,
67 unsigned int rt, unsigned int bytes,
68 int is_default_endian);
69extern int kvmppc_handle_loads(struct kvm_vcpu *vcpu,
70 unsigned int rt, unsigned int bytes,
71 int is_default_endian);
72extern int kvmppc_handle_vsx_load(struct kvm_vcpu *vcpu,
73 unsigned int rt, unsigned int bytes,
74 int is_default_endian, int mmio_sign_extend);
75extern int kvmppc_handle_vmx_load(struct kvm_vcpu *vcpu,
76 unsigned int rt, unsigned int bytes, int is_default_endian);
77extern int kvmppc_handle_vmx_store(struct kvm_vcpu *vcpu,
78 unsigned int rs, unsigned int bytes, int is_default_endian);
79extern int kvmppc_handle_store(struct kvm_vcpu *vcpu,
80 u64 val, unsigned int bytes,
81 int is_default_endian);
82extern int kvmppc_handle_vsx_store(struct kvm_vcpu *vcpu,
83 int rs, unsigned int bytes,
84 int is_default_endian);
85
86extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu,
87 enum instruction_fetch_type type, u32 *inst);
88
89extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
90 bool data);
91extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
92 bool data);
93extern int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu);
94extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu);
95extern int kvmppc_emulate_mmio(struct kvm_vcpu *vcpu);
96extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
97extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
98extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu);
99extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
100extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu);
101extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu);
102
103/* Core-specific hooks */
104
105extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr,
106 unsigned int gtlb_idx);
107extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
108extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
109extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
110extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
111extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
112 gva_t eaddr);
113extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu);
114extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu);
115extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr,
116 enum xlate_instdata xlid, enum xlate_readwrite xlrw,
117 struct kvmppc_pte *pte);
118
119extern int kvmppc_core_vcpu_create(struct kvm_vcpu *vcpu);
120extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu);
121extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu);
122extern int kvmppc_core_check_processor_compat(void);
123extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
124 struct kvm_translation *tr);
125
126extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
127extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);
128
129extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
130extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
131extern void kvmppc_core_queue_machine_check(struct kvm_vcpu *vcpu, ulong flags);
132extern void kvmppc_core_queue_syscall(struct kvm_vcpu *vcpu);
133extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
134extern void kvmppc_core_queue_fpunavail(struct kvm_vcpu *vcpu);
135extern void kvmppc_core_queue_vec_unavail(struct kvm_vcpu *vcpu);
136extern void kvmppc_core_queue_vsx_unavail(struct kvm_vcpu *vcpu);
137extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
138extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu);
139extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
140 struct kvm_interrupt *irq);
141extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu);
142extern void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, ulong dear_flags,
143 ulong esr_flags);
144extern void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu,
145 ulong dear_flags,
146 ulong esr_flags);
147extern void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu);
148extern void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu,
149 ulong esr_flags);
150extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu);
151extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
152
153extern int kvmppc_booke_init(void);
154extern void kvmppc_booke_exit(void);
155
156extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu);
157extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu);
158extern void kvmppc_map_magic(struct kvm_vcpu *vcpu);
159
160extern int kvmppc_allocate_hpt(struct kvm_hpt_info *info, u32 order);
161extern void kvmppc_set_hpt(struct kvm *kvm, struct kvm_hpt_info *info);
162extern long kvmppc_alloc_reset_hpt(struct kvm *kvm, int order);
163extern void kvmppc_free_hpt(struct kvm_hpt_info *info);
164extern void kvmppc_rmap_reset(struct kvm *kvm);
165extern long kvmppc_prepare_vrma(struct kvm *kvm,
166 struct kvm_userspace_memory_region *mem);
167extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,
168 struct kvm_memory_slot *memslot, unsigned long porder);
169extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu);
170extern long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd,
171 struct iommu_group *grp);
172extern void kvm_spapr_tce_release_iommu_group(struct kvm *kvm,
173 struct iommu_group *grp);
174extern int kvmppc_switch_mmu_to_hpt(struct kvm *kvm);
175extern int kvmppc_switch_mmu_to_radix(struct kvm *kvm);
176extern void kvmppc_setup_partition_table(struct kvm *kvm);
177
178extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
179 struct kvm_create_spapr_tce_64 *args);
180extern struct kvmppc_spapr_tce_table *kvmppc_find_table(
181 struct kvm *kvm, unsigned long liobn);
182#define kvmppc_ioba_validate(stt, ioba, npages) \
183 (iommu_tce_check_ioba((stt)->page_shift, (stt)->offset, \
184 (stt)->size, (ioba), (npages)) ? \
185 H_PARAMETER : H_SUCCESS)
186extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
187 unsigned long ioba, unsigned long tce);
188extern long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,
189 unsigned long liobn, unsigned long ioba,
190 unsigned long tce_list, unsigned long npages);
191extern long kvmppc_h_stuff_tce(struct kvm_vcpu *vcpu,
192 unsigned long liobn, unsigned long ioba,
193 unsigned long tce_value, unsigned long npages);
194extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
195 unsigned long ioba);
196extern struct page *kvm_alloc_hpt_cma(unsigned long nr_pages);
197extern void kvm_free_hpt_cma(struct page *page, unsigned long nr_pages);
198extern int kvmppc_core_init_vm(struct kvm *kvm);
199extern void kvmppc_core_destroy_vm(struct kvm *kvm);
200extern void kvmppc_core_free_memslot(struct kvm *kvm,
201 struct kvm_memory_slot *slot);
202extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
203 const struct kvm_memory_slot *old,
204 struct kvm_memory_slot *new,
205 enum kvm_mr_change change);
206extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
207 struct kvm_memory_slot *old,
208 const struct kvm_memory_slot *new,
209 enum kvm_mr_change change);
210extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
211 struct kvm_ppc_smmu_info *info);
212extern void kvmppc_core_flush_memslot(struct kvm *kvm,
213 struct kvm_memory_slot *memslot);
214
215extern int kvmppc_bookehv_init(void);
216extern void kvmppc_bookehv_exit(void);
217
218extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu);
219
220extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *);
221extern long kvm_vm_ioctl_resize_hpt_prepare(struct kvm *kvm,
222 struct kvm_ppc_resize_hpt *rhpt);
223extern long kvm_vm_ioctl_resize_hpt_commit(struct kvm *kvm,
224 struct kvm_ppc_resize_hpt *rhpt);
225
226int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq);
227
228extern int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp);
229extern int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu);
230extern void kvmppc_rtas_tokens_free(struct kvm *kvm);
231
232extern int kvmppc_xics_set_xive(struct kvm *kvm, u32 irq, u32 server,
233 u32 priority);
234extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server,
235 u32 *priority);
236extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq);
237extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq);
238
239void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu);
240void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu);
241
242union kvmppc_one_reg {
243 u32 wval;
244 u64 dval;
245 vector128 vval;
246 u64 vsxval[2];
247 u32 vsx32val[4];
248 u16 vsx16val[8];
249 u8 vsx8val[16];
250 struct {
251 u64 addr;
252 u64 length;
253 } vpaval;
254 u64 xive_timaval[2];
255};
256
257struct kvmppc_ops {
258 struct module *owner;
259 int (*get_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
260 int (*set_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
261 int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
262 union kvmppc_one_reg *val);
263 int (*set_one_reg)(struct kvm_vcpu *vcpu, u64 id,
264 union kvmppc_one_reg *val);
265 void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
266 void (*vcpu_put)(struct kvm_vcpu *vcpu);
267 void (*inject_interrupt)(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags);
268 void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr);
269 int (*vcpu_run)(struct kvm_vcpu *vcpu);
270 int (*vcpu_create)(struct kvm_vcpu *vcpu);
271 void (*vcpu_free)(struct kvm_vcpu *vcpu);
272 int (*check_requests)(struct kvm_vcpu *vcpu);
273 int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log);
274 void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot);
275 int (*prepare_memory_region)(struct kvm *kvm,
276 const struct kvm_memory_slot *old,
277 struct kvm_memory_slot *new,
278 enum kvm_mr_change change);
279 void (*commit_memory_region)(struct kvm *kvm,
280 struct kvm_memory_slot *old,
281 const struct kvm_memory_slot *new,
282 enum kvm_mr_change change);
283 bool (*unmap_gfn_range)(struct kvm *kvm, struct kvm_gfn_range *range);
284 bool (*age_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
285 bool (*test_age_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
286 bool (*set_spte_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
287 void (*free_memslot)(struct kvm_memory_slot *slot);
288 int (*init_vm)(struct kvm *kvm);
289 void (*destroy_vm)(struct kvm *kvm);
290 int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info);
291 int (*emulate_op)(struct kvm_vcpu *vcpu,
292 unsigned int inst, int *advance);
293 int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
294 int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
295 void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu);
296 long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl,
297 unsigned long arg);
298 int (*hcall_implemented)(unsigned long hcall);
299 int (*irq_bypass_add_producer)(struct irq_bypass_consumer *,
300 struct irq_bypass_producer *);
301 void (*irq_bypass_del_producer)(struct irq_bypass_consumer *,
302 struct irq_bypass_producer *);
303 int (*configure_mmu)(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg);
304 int (*get_rmmu_info)(struct kvm *kvm, struct kvm_ppc_rmmu_info *info);
305 int (*set_smt_mode)(struct kvm *kvm, unsigned long mode,
306 unsigned long flags);
307 void (*giveup_ext)(struct kvm_vcpu *vcpu, ulong msr);
308 int (*enable_nested)(struct kvm *kvm);
309 int (*load_from_eaddr)(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,
310 int size);
311 int (*store_to_eaddr)(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,
312 int size);
313 int (*enable_svm)(struct kvm *kvm);
314 int (*svm_off)(struct kvm *kvm);
315 int (*enable_dawr1)(struct kvm *kvm);
316 bool (*hash_v3_possible)(void);
317 int (*create_vm_debugfs)(struct kvm *kvm);
318 int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry);
319};
320
321extern struct kvmppc_ops *kvmppc_hv_ops;
322extern struct kvmppc_ops *kvmppc_pr_ops;
323
324static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu,
325 enum instruction_fetch_type type, u32 *inst)
326{
327 int ret = EMULATE_DONE;
328 u32 fetched_inst;
329
330 /* Load the instruction manually if it failed to do so in the
331 * exit path */
332 if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED)
333 ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst);
334
335 /* Write fetch_failed unswapped if the fetch failed */
336 if (ret == EMULATE_DONE)
337 fetched_inst = kvmppc_need_byteswap(vcpu) ?
338 swab32(vcpu->arch.last_inst) :
339 vcpu->arch.last_inst;
340 else
341 fetched_inst = vcpu->arch.last_inst;
342
343 *inst = fetched_inst;
344 return ret;
345}
346
347static inline bool is_kvmppc_hv_enabled(struct kvm *kvm)
348{
349 return kvm->arch.kvm_ops == kvmppc_hv_ops;
350}
351
352extern int kvmppc_hwrng_present(void);
353
354/*
355 * Cuts out inst bits with ordering according to spec.
356 * That means the leftmost bit is zero. All given bits are included.
357 */
358static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb)
359{
360 u32 r;
361 u32 mask;
362
363 BUG_ON(msb > lsb);
364
365 mask = (1 << (lsb - msb + 1)) - 1;
366 r = (inst >> (63 - lsb)) & mask;
367
368 return r;
369}
370
371/*
372 * Replaces inst bits with ordering according to spec.
373 */
374static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
375{
376 u32 r;
377 u32 mask;
378
379 BUG_ON(msb > lsb);
380
381 mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb);
382 r = (inst & ~mask) | ((value << (63 - lsb)) & mask);
383
384 return r;
385}
386
387#define one_reg_size(id) \
388 (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
389
390#define get_reg_val(id, reg) ({ \
391 union kvmppc_one_reg __u; \
392 switch (one_reg_size(id)) { \
393 case 4: __u.wval = (reg); break; \
394 case 8: __u.dval = (reg); break; \
395 default: BUG(); \
396 } \
397 __u; \
398})
399
400
401#define set_reg_val(id, val) ({ \
402 u64 __v; \
403 switch (one_reg_size(id)) { \
404 case 4: __v = (val).wval; break; \
405 case 8: __v = (val).dval; break; \
406 default: BUG(); \
407 } \
408 __v; \
409})
410
411int kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
412int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
413
414int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
415int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
416
417int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
418int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
419int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
420int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
421
422void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
423
424struct openpic;
425
426#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
427extern void kvm_cma_reserve(void) __init;
428static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
429{
430 paca_ptrs[cpu]->kvm_hstate.xics_phys = (void __iomem *)addr;
431}
432
433static inline void kvmppc_set_xive_tima(int cpu,
434 unsigned long phys_addr,
435 void __iomem *virt_addr)
436{
437 paca_ptrs[cpu]->kvm_hstate.xive_tima_phys = (void __iomem *)phys_addr;
438 paca_ptrs[cpu]->kvm_hstate.xive_tima_virt = virt_addr;
439}
440
441static inline u32 kvmppc_get_xics_latch(void)
442{
443 u32 xirr;
444
445 xirr = get_paca()->kvm_hstate.saved_xirr;
446 get_paca()->kvm_hstate.saved_xirr = 0;
447 return xirr;
448}
449
450/*
451 * To avoid the need to unnecessarily exit fully to the host kernel, an IPI to
452 * a CPU thread that's running/napping inside of a guest is by default regarded
453 * as a request to wake the CPU (if needed) and continue execution within the
454 * guest, potentially to process new state like externally-generated
455 * interrupts or IPIs sent from within the guest itself (e.g. H_PROD/H_IPI).
456 *
457 * To force an exit to the host kernel, kvmppc_set_host_ipi() must be called
458 * prior to issuing the IPI to set the corresponding 'host_ipi' flag in the
459 * target CPU's PACA. To avoid unnecessary exits to the host, this flag should
460 * be immediately cleared via kvmppc_clear_host_ipi() by the IPI handler on
461 * the receiving side prior to processing the IPI work.
462 *
463 * NOTE:
464 *
465 * We currently issue an smp_mb() at the beginning of kvmppc_set_host_ipi().
466 * This is to guard against sequences such as the following:
467 *
468 * CPU
469 * X: smp_muxed_ipi_set_message():
470 * X: smp_mb()
471 * X: message[RESCHEDULE] = 1
472 * X: doorbell_global_ipi(42):
473 * X: kvmppc_set_host_ipi(42)
474 * X: ppc_msgsnd_sync()/smp_mb()
475 * X: ppc_msgsnd() -> 42
476 * 42: doorbell_exception(): // from CPU X
477 * 42: ppc_msgsync()
478 * 105: smp_muxed_ipi_set_message():
479 * 105: smb_mb()
480 * // STORE DEFERRED DUE TO RE-ORDERING
481 * --105: message[CALL_FUNCTION] = 1
482 * | 105: doorbell_global_ipi(42):
483 * | 105: kvmppc_set_host_ipi(42)
484 * | 42: kvmppc_clear_host_ipi(42)
485 * | 42: smp_ipi_demux_relaxed()
486 * | 42: // returns to executing guest
487 * | // RE-ORDERED STORE COMPLETES
488 * ->105: message[CALL_FUNCTION] = 1
489 * 105: ppc_msgsnd_sync()/smp_mb()
490 * 105: ppc_msgsnd() -> 42
491 * 42: local_paca->kvm_hstate.host_ipi == 0 // IPI ignored
492 * 105: // hangs waiting on 42 to process messages/call_single_queue
493 *
494 * We also issue an smp_mb() at the end of kvmppc_clear_host_ipi(). This is
495 * to guard against sequences such as the following (as well as to create
496 * a read-side pairing with the barrier in kvmppc_set_host_ipi()):
497 *
498 * CPU
499 * X: smp_muxed_ipi_set_message():
500 * X: smp_mb()
501 * X: message[RESCHEDULE] = 1
502 * X: doorbell_global_ipi(42):
503 * X: kvmppc_set_host_ipi(42)
504 * X: ppc_msgsnd_sync()/smp_mb()
505 * X: ppc_msgsnd() -> 42
506 * 42: doorbell_exception(): // from CPU X
507 * 42: ppc_msgsync()
508 * // STORE DEFERRED DUE TO RE-ORDERING
509 * -- 42: kvmppc_clear_host_ipi(42)
510 * | 42: smp_ipi_demux_relaxed()
511 * | 105: smp_muxed_ipi_set_message():
512 * | 105: smb_mb()
513 * | 105: message[CALL_FUNCTION] = 1
514 * | 105: doorbell_global_ipi(42):
515 * | 105: kvmppc_set_host_ipi(42)
516 * | // RE-ORDERED STORE COMPLETES
517 * -> 42: kvmppc_clear_host_ipi(42)
518 * 42: // returns to executing guest
519 * 105: ppc_msgsnd_sync()/smp_mb()
520 * 105: ppc_msgsnd() -> 42
521 * 42: local_paca->kvm_hstate.host_ipi == 0 // IPI ignored
522 * 105: // hangs waiting on 42 to process messages/call_single_queue
523 */
524static inline void kvmppc_set_host_ipi(int cpu)
525{
526 /*
527 * order stores of IPI messages vs. setting of host_ipi flag
528 *
529 * pairs with the barrier in kvmppc_clear_host_ipi()
530 */
531 smp_mb();
532 paca_ptrs[cpu]->kvm_hstate.host_ipi = 1;
533}
534
535static inline void kvmppc_clear_host_ipi(int cpu)
536{
537 paca_ptrs[cpu]->kvm_hstate.host_ipi = 0;
538 /*
539 * order clearing of host_ipi flag vs. processing of IPI messages
540 *
541 * pairs with the barrier in kvmppc_set_host_ipi()
542 */
543 smp_mb();
544}
545
546static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
547{
548 vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu);
549}
550
551extern void kvm_hv_vm_activated(void);
552extern void kvm_hv_vm_deactivated(void);
553extern bool kvm_hv_mode_active(void);
554
555extern void kvmppc_check_need_tlb_flush(struct kvm *kvm, int pcpu);
556
557#else
558static inline void __init kvm_cma_reserve(void)
559{}
560
561static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
562{}
563
564static inline void kvmppc_set_xive_tima(int cpu,
565 unsigned long phys_addr,
566 void __iomem *virt_addr)
567{}
568
569static inline u32 kvmppc_get_xics_latch(void)
570{
571 return 0;
572}
573
574static inline void kvmppc_set_host_ipi(int cpu)
575{}
576
577static inline void kvmppc_clear_host_ipi(int cpu)
578{}
579
580static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
581{
582 kvm_vcpu_kick(vcpu);
583}
584
585static inline bool kvm_hv_mode_active(void) { return false; }
586
587#endif
588
589#ifdef CONFIG_KVM_XICS
590static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
591{
592 return vcpu->arch.irq_type == KVMPPC_IRQ_XICS;
593}
594
595static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
596 struct kvm *kvm)
597{
598 if (kvm && kvm_irq_bypass)
599 return kvm->arch.pimap;
600 return NULL;
601}
602
603extern void kvmppc_alloc_host_rm_ops(void);
604extern void kvmppc_free_host_rm_ops(void);
605extern void kvmppc_free_pimap(struct kvm *kvm);
606extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall);
607extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu);
608extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
609extern int kvmppc_xive_xics_hcall(struct kvm_vcpu *vcpu, u32 req);
610extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
611extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
612extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev,
613 struct kvm_vcpu *vcpu, u32 cpu);
614extern void kvmppc_xics_ipi_action(void);
615extern void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long guest_irq,
616 unsigned long host_irq);
617extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
618 unsigned long host_irq);
619extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, __be32 xirr,
620 struct kvmppc_irq_map *irq_map,
621 struct kvmppc_passthru_irqmap *pimap,
622 bool *again);
623
624extern int kvmppc_xics_set_irq(struct kvm *kvm, int irq_source_id, u32 irq,
625 int level, bool line_status);
626
627extern int h_ipi_redirect;
628#else
629static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
630 struct kvm *kvm)
631 { return NULL; }
632static inline void kvmppc_alloc_host_rm_ops(void) {}
633static inline void kvmppc_free_host_rm_ops(void) {}
634static inline void kvmppc_free_pimap(struct kvm *kvm) {}
635static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall)
636 { return 0; }
637static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
638 { return 0; }
639static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { }
640static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd)
641 { return 0; }
642static inline int kvmppc_xive_xics_hcall(struct kvm_vcpu *vcpu, u32 req)
643 { return 0; }
644#endif
645
646#ifdef CONFIG_KVM_XIVE
647/*
648 * Below the first "xive" is the "eXternal Interrupt Virtualization Engine"
649 * ie. P9 new interrupt controller, while the second "xive" is the legacy
650 * "eXternal Interrupt Vector Entry" which is the configuration of an
651 * interrupt on the "xics" interrupt controller on P8 and earlier. Those
652 * two function consume or produce a legacy "XIVE" state from the
653 * new "XIVE" interrupt controller.
654 */
655extern int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server,
656 u32 priority);
657extern int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server,
658 u32 *priority);
659extern int kvmppc_xive_int_on(struct kvm *kvm, u32 irq);
660extern int kvmppc_xive_int_off(struct kvm *kvm, u32 irq);
661
662extern int kvmppc_xive_connect_vcpu(struct kvm_device *dev,
663 struct kvm_vcpu *vcpu, u32 cpu);
664extern void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu);
665extern int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq,
666 unsigned long host_irq);
667extern int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
668 unsigned long host_irq);
669extern u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu);
670extern int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
671
672extern int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq,
673 int level, bool line_status);
674extern void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu);
675extern void kvmppc_xive_pull_vcpu(struct kvm_vcpu *vcpu);
676extern void kvmppc_xive_rearm_escalation(struct kvm_vcpu *vcpu);
677
678static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)
679{
680 return vcpu->arch.irq_type == KVMPPC_IRQ_XIVE;
681}
682
683extern int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
684 struct kvm_vcpu *vcpu, u32 cpu);
685extern void kvmppc_xive_native_cleanup_vcpu(struct kvm_vcpu *vcpu);
686extern int kvmppc_xive_native_get_vp(struct kvm_vcpu *vcpu,
687 union kvmppc_one_reg *val);
688extern int kvmppc_xive_native_set_vp(struct kvm_vcpu *vcpu,
689 union kvmppc_one_reg *val);
690extern bool kvmppc_xive_native_supported(void);
691
692#else
693static inline int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server,
694 u32 priority) { return -1; }
695static inline int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server,
696 u32 *priority) { return -1; }
697static inline int kvmppc_xive_int_on(struct kvm *kvm, u32 irq) { return -1; }
698static inline int kvmppc_xive_int_off(struct kvm *kvm, u32 irq) { return -1; }
699
700static inline int kvmppc_xive_connect_vcpu(struct kvm_device *dev,
701 struct kvm_vcpu *vcpu, u32 cpu) { return -EBUSY; }
702static inline void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu) { }
703static inline int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq,
704 struct irq_desc *host_desc) { return -ENODEV; }
705static inline int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
706 struct irq_desc *host_desc) { return -ENODEV; }
707static inline u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu) { return 0; }
708static inline int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval) { return -ENOENT; }
709
710static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq,
711 int level, bool line_status) { return -ENODEV; }
712static inline void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu) { }
713static inline void kvmppc_xive_pull_vcpu(struct kvm_vcpu *vcpu) { }
714static inline void kvmppc_xive_rearm_escalation(struct kvm_vcpu *vcpu) { }
715
716static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)
717 { return 0; }
718static inline int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
719 struct kvm_vcpu *vcpu, u32 cpu) { return -EBUSY; }
720static inline void kvmppc_xive_native_cleanup_vcpu(struct kvm_vcpu *vcpu) { }
721static inline int kvmppc_xive_native_get_vp(struct kvm_vcpu *vcpu,
722 union kvmppc_one_reg *val)
723{ return 0; }
724static inline int kvmppc_xive_native_set_vp(struct kvm_vcpu *vcpu,
725 union kvmppc_one_reg *val)
726{ return -ENOENT; }
727
728#endif /* CONFIG_KVM_XIVE */
729
730#if defined(CONFIG_PPC_POWERNV) && defined(CONFIG_KVM_BOOK3S_64_HANDLER)
731static inline bool xics_on_xive(void)
732{
733 return xive_enabled() && cpu_has_feature(CPU_FTR_HVMODE);
734}
735#else
736static inline bool xics_on_xive(void)
737{
738 return false;
739}
740#endif
741
742/*
743 * Prototypes for functions called only from assembler code.
744 * Having prototypes reduces sparse errors.
745 */
746long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
747 unsigned long ioba, unsigned long tce);
748long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
749 unsigned long liobn, unsigned long ioba,
750 unsigned long tce_list, unsigned long npages);
751long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu,
752 unsigned long liobn, unsigned long ioba,
753 unsigned long tce_value, unsigned long npages);
754long int kvmppc_rm_h_confer(struct kvm_vcpu *vcpu, int target,
755 unsigned int yield_count);
756long kvmppc_rm_h_random(struct kvm_vcpu *vcpu);
757void kvmhv_commence_exit(int trap);
758void kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu);
759void kvmppc_subcore_enter_guest(void);
760void kvmppc_subcore_exit_guest(void);
761long kvmppc_realmode_hmi_handler(void);
762long kvmppc_p9_realmode_hmi_handler(struct kvm_vcpu *vcpu);
763long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
764 long pte_index, unsigned long pteh, unsigned long ptel);
765long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,
766 unsigned long pte_index, unsigned long avpn);
767long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu);
768long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
769 unsigned long pte_index, unsigned long avpn);
770long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags,
771 unsigned long pte_index);
772long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags,
773 unsigned long pte_index);
774long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,
775 unsigned long pte_index);
776long kvmppc_rm_h_page_init(struct kvm_vcpu *vcpu, unsigned long flags,
777 unsigned long dest, unsigned long src);
778long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr,
779 unsigned long slb_v, unsigned int status, bool data);
780unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu);
781unsigned long kvmppc_rm_h_xirr_x(struct kvm_vcpu *vcpu);
782unsigned long kvmppc_rm_h_ipoll(struct kvm_vcpu *vcpu, unsigned long server);
783int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
784 unsigned long mfrr);
785int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr);
786int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr);
787void kvmppc_guest_entry_inject_int(struct kvm_vcpu *vcpu);
788
789/*
790 * Host-side operations we want to set up while running in real
791 * mode in the guest operating on the xics.
792 * Currently only VCPU wakeup is supported.
793 */
794
795union kvmppc_rm_state {
796 unsigned long raw;
797 struct {
798 u32 in_host;
799 u32 rm_action;
800 };
801};
802
803struct kvmppc_host_rm_core {
804 union kvmppc_rm_state rm_state;
805 void *rm_data;
806 char pad[112];
807};
808
809struct kvmppc_host_rm_ops {
810 struct kvmppc_host_rm_core *rm_core;
811 void (*vcpu_kick)(struct kvm_vcpu *vcpu);
812};
813
814extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv;
815
816static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu)
817{
818#ifdef CONFIG_KVM_BOOKE_HV
819 return mfspr(SPRN_GEPR);
820#elif defined(CONFIG_BOOKE)
821 return vcpu->arch.epr;
822#else
823 return 0;
824#endif
825}
826
827static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr)
828{
829#ifdef CONFIG_KVM_BOOKE_HV
830 mtspr(SPRN_GEPR, epr);
831#elif defined(CONFIG_BOOKE)
832 vcpu->arch.epr = epr;
833#endif
834}
835
836#ifdef CONFIG_KVM_MPIC
837
838void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu);
839int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu,
840 u32 cpu);
841void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu);
842
843#else
844
845static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu)
846{
847}
848
849static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev,
850 struct kvm_vcpu *vcpu, u32 cpu)
851{
852 return -EINVAL;
853}
854
855static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp,
856 struct kvm_vcpu *vcpu)
857{
858}
859
860#endif /* CONFIG_KVM_MPIC */
861
862int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
863 struct kvm_config_tlb *cfg);
864int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
865 struct kvm_dirty_tlb *cfg);
866
867long kvmppc_alloc_lpid(void);
868void kvmppc_claim_lpid(long lpid);
869void kvmppc_free_lpid(long lpid);
870void kvmppc_init_lpid(unsigned long nr_lpids);
871
872static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn)
873{
874 struct page *page;
875 /*
876 * We can only access pages that the kernel maps
877 * as memory. Bail out for unmapped ones.
878 */
879 if (!pfn_valid(pfn))
880 return;
881
882 /* Clear i-cache for new pages */
883 page = pfn_to_page(pfn);
884 if (!test_bit(PG_dcache_clean, &page->flags)) {
885 flush_dcache_icache_page(page);
886 set_bit(PG_dcache_clean, &page->flags);
887 }
888}
889
890/*
891 * Shared struct helpers. The shared struct can be little or big endian,
892 * depending on the guest endianness. So expose helpers to all of them.
893 */
894static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu)
895{
896#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
897 /* Only Book3S_64 PR supports bi-endian for now */
898 return vcpu->arch.shared_big_endian;
899#elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__)
900 /* Book3s_64 HV on little endian is always little endian */
901 return false;
902#else
903 return true;
904#endif
905}
906
907#define SPRNG_WRAPPER_GET(reg, bookehv_spr) \
908static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
909{ \
910 return mfspr(bookehv_spr); \
911} \
912
913#define SPRNG_WRAPPER_SET(reg, bookehv_spr) \
914static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \
915{ \
916 mtspr(bookehv_spr, val); \
917} \
918
919#define SHARED_WRAPPER_GET(reg, size) \
920static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
921{ \
922 if (kvmppc_shared_big_endian(vcpu)) \
923 return be##size##_to_cpu(vcpu->arch.shared->reg); \
924 else \
925 return le##size##_to_cpu(vcpu->arch.shared->reg); \
926} \
927
928#define SHARED_WRAPPER_SET(reg, size) \
929static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \
930{ \
931 if (kvmppc_shared_big_endian(vcpu)) \
932 vcpu->arch.shared->reg = cpu_to_be##size(val); \
933 else \
934 vcpu->arch.shared->reg = cpu_to_le##size(val); \
935} \
936
937#define SHARED_WRAPPER(reg, size) \
938 SHARED_WRAPPER_GET(reg, size) \
939 SHARED_WRAPPER_SET(reg, size) \
940
941#define SPRNG_WRAPPER(reg, bookehv_spr) \
942 SPRNG_WRAPPER_GET(reg, bookehv_spr) \
943 SPRNG_WRAPPER_SET(reg, bookehv_spr) \
944
945#ifdef CONFIG_KVM_BOOKE_HV
946
947#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
948 SPRNG_WRAPPER(reg, bookehv_spr) \
949
950#else
951
952#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
953 SHARED_WRAPPER(reg, size) \
954
955#endif
956
957SHARED_WRAPPER(critical, 64)
958SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0)
959SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1)
960SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2)
961SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3)
962SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0)
963SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1)
964SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR)
965SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR)
966SHARED_WRAPPER_GET(msr, 64)
967static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val)
968{
969 if (kvmppc_shared_big_endian(vcpu))
970 vcpu->arch.shared->msr = cpu_to_be64(val);
971 else
972 vcpu->arch.shared->msr = cpu_to_le64(val);
973}
974SHARED_WRAPPER(dsisr, 32)
975SHARED_WRAPPER(int_pending, 32)
976SHARED_WRAPPER(sprg4, 64)
977SHARED_WRAPPER(sprg5, 64)
978SHARED_WRAPPER(sprg6, 64)
979SHARED_WRAPPER(sprg7, 64)
980
981static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr)
982{
983 if (kvmppc_shared_big_endian(vcpu))
984 return be32_to_cpu(vcpu->arch.shared->sr[nr]);
985 else
986 return le32_to_cpu(vcpu->arch.shared->sr[nr]);
987}
988
989static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val)
990{
991 if (kvmppc_shared_big_endian(vcpu))
992 vcpu->arch.shared->sr[nr] = cpu_to_be32(val);
993 else
994 vcpu->arch.shared->sr[nr] = cpu_to_le32(val);
995}
996
997/*
998 * Please call after prepare_to_enter. This function puts the lazy ee and irq
999 * disabled tracking state back to normal mode, without actually enabling
1000 * interrupts.
1001 */
1002static inline void kvmppc_fix_ee_before_entry(void)
1003{
1004 trace_hardirqs_on();
1005
1006#ifdef CONFIG_PPC64
1007 /*
1008 * To avoid races, the caller must have gone directly from having
1009 * interrupts fully-enabled to hard-disabled.
1010 */
1011 WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);
1012
1013 /* Only need to enable IRQs by hard enabling them after this */
1014 local_paca->irq_happened = 0;
1015 irq_soft_mask_set(IRQS_ENABLED);
1016#endif
1017}
1018
1019static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)
1020{
1021 ulong ea;
1022 ulong msr_64bit = 0;
1023
1024 ea = kvmppc_get_gpr(vcpu, rb);
1025 if (ra)
1026 ea += kvmppc_get_gpr(vcpu, ra);
1027
1028#if defined(CONFIG_PPC_BOOK3E_64)
1029 msr_64bit = MSR_CM;
1030#elif defined(CONFIG_PPC_BOOK3S_64)
1031 msr_64bit = MSR_SF;
1032#endif
1033
1034 if (!(kvmppc_get_msr(vcpu) & msr_64bit))
1035 ea = (uint32_t)ea;
1036
1037 return ea;
1038}
1039
1040extern void xics_wake_cpu(int cpu);
1041
1042#endif /* __POWERPC_KVM_PPC_H__ */