hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/arch/powerpc/include/asm/kvm_ppc.h
....@@ -1,16 +1,5 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
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.
143 *
154 * Copyright IBM Corp. 2008
165 *
....@@ -36,6 +25,8 @@
3625 #endif
3726 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
3827 #include <asm/paca.h>
28
+#include <asm/xive.h>
29
+#include <asm/cpu_has_feature.h>
3930 #endif
4031
4132 /*
....@@ -67,28 +58,28 @@
6758 XLATE_WRITE /* check for write permissions */
6859 };
6960
70
-extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
71
-extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
61
+extern int kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
62
+extern int __kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
7263 extern void kvmppc_handler_highmem(void);
7364
7465 extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
75
-extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
66
+extern int kvmppc_handle_load(struct kvm_vcpu *vcpu,
7667 unsigned int rt, unsigned int bytes,
7768 int is_default_endian);
78
-extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
69
+extern int kvmppc_handle_loads(struct kvm_vcpu *vcpu,
7970 unsigned int rt, unsigned int bytes,
8071 int is_default_endian);
81
-extern int kvmppc_handle_vsx_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
72
+extern int kvmppc_handle_vsx_load(struct kvm_vcpu *vcpu,
8273 unsigned int rt, unsigned int bytes,
8374 int is_default_endian, int mmio_sign_extend);
84
-extern int kvmppc_handle_vmx_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
75
+extern int kvmppc_handle_vmx_load(struct kvm_vcpu *vcpu,
8576 unsigned int rt, unsigned int bytes, int is_default_endian);
86
-extern int kvmppc_handle_vmx_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
77
+extern int kvmppc_handle_vmx_store(struct kvm_vcpu *vcpu,
8778 unsigned int rs, unsigned int bytes, int is_default_endian);
88
-extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
79
+extern int kvmppc_handle_store(struct kvm_vcpu *vcpu,
8980 u64 val, unsigned int bytes,
9081 int is_default_endian);
91
-extern int kvmppc_handle_vsx_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
82
+extern int kvmppc_handle_vsx_store(struct kvm_vcpu *vcpu,
9283 int rs, unsigned int bytes,
9384 int is_default_endian);
9485
....@@ -99,10 +90,9 @@
9990 bool data);
10091 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
10192 bool data);
102
-extern int kvmppc_emulate_instruction(struct kvm_run *run,
103
- struct kvm_vcpu *vcpu);
93
+extern int kvmppc_emulate_instruction(struct kvm_vcpu *vcpu);
10494 extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu);
105
-extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
95
+extern int kvmppc_emulate_mmio(struct kvm_vcpu *vcpu);
10696 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
10797 extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
10898 extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu);
....@@ -116,8 +106,6 @@
116106 unsigned int gtlb_idx);
117107 extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
118108 extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
119
-extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu);
120
-extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu);
121109 extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
122110 extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
123111 extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
....@@ -128,8 +116,7 @@
128116 enum xlate_instdata xlid, enum xlate_readwrite xlrw,
129117 struct kvmppc_pte *pte);
130118
131
-extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm,
132
- unsigned int id);
119
+extern int kvmppc_core_vcpu_create(struct kvm_vcpu *vcpu);
133120 extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu);
134121 extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu);
135122 extern int kvmppc_core_check_processor_compat(void);
....@@ -141,6 +128,7 @@
141128
142129 extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
143130 extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
131
+extern void kvmppc_core_queue_machine_check(struct kvm_vcpu *vcpu, ulong flags);
144132 extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
145133 extern void kvmppc_core_queue_fpunavail(struct kvm_vcpu *vcpu);
146134 extern void kvmppc_core_queue_vec_unavail(struct kvm_vcpu *vcpu);
....@@ -194,12 +182,6 @@
194182 (iommu_tce_check_ioba((stt)->page_shift, (stt)->offset, \
195183 (stt)->size, (ioba), (npages)) ? \
196184 H_PARAMETER : H_SUCCESS)
197
-extern long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *tt,
198
- unsigned long tce);
199
-extern long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa,
200
- unsigned long *ua, unsigned long **prmap);
201
-extern void kvmppc_tce_put(struct kvmppc_spapr_tce_table *tt,
202
- unsigned long idx, unsigned long tce);
203185 extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
204186 unsigned long ioba, unsigned long tce);
205187 extern long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,
....@@ -215,18 +197,16 @@
215197 extern int kvmppc_core_init_vm(struct kvm *kvm);
216198 extern void kvmppc_core_destroy_vm(struct kvm *kvm);
217199 extern void kvmppc_core_free_memslot(struct kvm *kvm,
218
- struct kvm_memory_slot *free,
219
- struct kvm_memory_slot *dont);
220
-extern int kvmppc_core_create_memslot(struct kvm *kvm,
221
- struct kvm_memory_slot *slot,
222
- unsigned long npages);
200
+ struct kvm_memory_slot *slot);
223201 extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
224202 struct kvm_memory_slot *memslot,
225
- const struct kvm_userspace_memory_region *mem);
203
+ const struct kvm_userspace_memory_region *mem,
204
+ enum kvm_mr_change change);
226205 extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
227206 const struct kvm_userspace_memory_region *mem,
228207 const struct kvm_memory_slot *old,
229
- const struct kvm_memory_slot *new);
208
+ const struct kvm_memory_slot *new,
209
+ enum kvm_mr_change change);
230210 extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
231211 struct kvm_ppc_smmu_info *info);
232212 extern void kvmppc_core_flush_memslot(struct kvm *kvm,
....@@ -271,6 +251,7 @@
271251 u64 addr;
272252 u64 length;
273253 } vpaval;
254
+ u64 xive_timaval[2];
274255 };
275256
276257 struct kvmppc_ops {
....@@ -283,34 +264,33 @@
283264 union kvmppc_one_reg *val);
284265 void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
285266 void (*vcpu_put)(struct kvm_vcpu *vcpu);
267
+ void (*inject_interrupt)(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags);
286268 void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr);
287
- int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
288
- struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id);
269
+ int (*vcpu_run)(struct kvm_vcpu *vcpu);
270
+ int (*vcpu_create)(struct kvm_vcpu *vcpu);
289271 void (*vcpu_free)(struct kvm_vcpu *vcpu);
290272 int (*check_requests)(struct kvm_vcpu *vcpu);
291273 int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log);
292274 void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot);
293275 int (*prepare_memory_region)(struct kvm *kvm,
294276 struct kvm_memory_slot *memslot,
295
- const struct kvm_userspace_memory_region *mem);
277
+ const struct kvm_userspace_memory_region *mem,
278
+ enum kvm_mr_change change);
296279 void (*commit_memory_region)(struct kvm *kvm,
297280 const struct kvm_userspace_memory_region *mem,
298281 const struct kvm_memory_slot *old,
299
- const struct kvm_memory_slot *new);
282
+ const struct kvm_memory_slot *new,
283
+ enum kvm_mr_change change);
300284 int (*unmap_hva_range)(struct kvm *kvm, unsigned long start,
301285 unsigned long end);
302286 int (*age_hva)(struct kvm *kvm, unsigned long start, unsigned long end);
303287 int (*test_age_hva)(struct kvm *kvm, unsigned long hva);
304288 void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte);
305
- void (*mmu_destroy)(struct kvm_vcpu *vcpu);
306
- void (*free_memslot)(struct kvm_memory_slot *free,
307
- struct kvm_memory_slot *dont);
308
- int (*create_memslot)(struct kvm_memory_slot *slot,
309
- unsigned long npages);
289
+ void (*free_memslot)(struct kvm_memory_slot *slot);
310290 int (*init_vm)(struct kvm *kvm);
311291 void (*destroy_vm)(struct kvm *kvm);
312292 int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info);
313
- int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu,
293
+ int (*emulate_op)(struct kvm_vcpu *vcpu,
314294 unsigned int inst, int *advance);
315295 int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
316296 int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
....@@ -327,6 +307,13 @@
327307 int (*set_smt_mode)(struct kvm *kvm, unsigned long mode,
328308 unsigned long flags);
329309 void (*giveup_ext)(struct kvm_vcpu *vcpu, ulong msr);
310
+ int (*enable_nested)(struct kvm *kvm);
311
+ int (*load_from_eaddr)(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,
312
+ int size);
313
+ int (*store_to_eaddr)(struct kvm_vcpu *vcpu, ulong *eaddr, void *ptr,
314
+ int size);
315
+ int (*enable_svm)(struct kvm *kvm);
316
+ int (*svm_off)(struct kvm *kvm);
330317 };
331318
332319 extern struct kvmppc_ops *kvmppc_hv_ops;
....@@ -563,6 +550,9 @@
563550 extern void kvm_hv_vm_deactivated(void);
564551 extern bool kvm_hv_mode_active(void);
565552
553
+extern void kvmppc_check_need_tlb_flush(struct kvm *kvm, int pcpu,
554
+ struct kvm_nested_guest *nested);
555
+
566556 #else
567557 static inline void __init kvm_cma_reserve(void)
568558 {}
....@@ -679,6 +669,24 @@
679669
680670 extern int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq,
681671 int level, bool line_status);
672
+extern void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu);
673
+
674
+static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)
675
+{
676
+ return vcpu->arch.irq_type == KVMPPC_IRQ_XIVE;
677
+}
678
+
679
+extern int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
680
+ struct kvm_vcpu *vcpu, u32 cpu);
681
+extern void kvmppc_xive_native_cleanup_vcpu(struct kvm_vcpu *vcpu);
682
+extern void kvmppc_xive_native_init_module(void);
683
+extern void kvmppc_xive_native_exit_module(void);
684
+extern int kvmppc_xive_native_get_vp(struct kvm_vcpu *vcpu,
685
+ union kvmppc_one_reg *val);
686
+extern int kvmppc_xive_native_set_vp(struct kvm_vcpu *vcpu,
687
+ union kvmppc_one_reg *val);
688
+extern bool kvmppc_xive_native_supported(void);
689
+
682690 #else
683691 static inline int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server,
684692 u32 priority) { return -1; }
....@@ -701,7 +709,35 @@
701709
702710 static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq,
703711 int level, bool line_status) { return -ENODEV; }
712
+static inline void kvmppc_xive_push_vcpu(struct kvm_vcpu *vcpu) { }
713
+
714
+static inline int kvmppc_xive_enabled(struct kvm_vcpu *vcpu)
715
+ { return 0; }
716
+static inline int kvmppc_xive_native_connect_vcpu(struct kvm_device *dev,
717
+ struct kvm_vcpu *vcpu, u32 cpu) { return -EBUSY; }
718
+static inline void kvmppc_xive_native_cleanup_vcpu(struct kvm_vcpu *vcpu) { }
719
+static inline void kvmppc_xive_native_init_module(void) { }
720
+static inline void kvmppc_xive_native_exit_module(void) { }
721
+static inline int kvmppc_xive_native_get_vp(struct kvm_vcpu *vcpu,
722
+ union kvmppc_one_reg *val)
723
+{ return 0; }
724
+static inline int kvmppc_xive_native_set_vp(struct kvm_vcpu *vcpu,
725
+ union kvmppc_one_reg *val)
726
+{ return -ENOENT; }
727
+
704728 #endif /* CONFIG_KVM_XIVE */
729
+
730
+#if defined(CONFIG_PPC_POWERNV) && defined(CONFIG_KVM_BOOK3S_64_HANDLER)
731
+static inline bool xics_on_xive(void)
732
+{
733
+ return xive_enabled() && cpu_has_feature(CPU_FTR_HVMODE);
734
+}
735
+#else
736
+static inline bool xics_on_xive(void)
737
+{
738
+ return false;
739
+}
740
+#endif
705741
706742 /*
707743 * Prototypes for functions called only from assembler code.
....@@ -719,7 +755,7 @@
719755 unsigned int yield_count);
720756 long kvmppc_h_random(struct kvm_vcpu *vcpu);
721757 void kvmhv_commence_exit(int trap);
722
-long kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu);
758
+void kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu);
723759 void kvmppc_subcore_enter_guest(void);
724760 void kvmppc_subcore_exit_guest(void);
725761 long kvmppc_realmode_hmi_handler(void);
....@@ -737,6 +773,8 @@
737773 unsigned long pte_index);
738774 long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,
739775 unsigned long pte_index);
776
+long kvmppc_rm_h_page_init(struct kvm_vcpu *vcpu, unsigned long flags,
777
+ unsigned long dest, unsigned long src);
740778 long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr,
741779 unsigned long slb_v, unsigned int status, bool data);
742780 unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu);
....@@ -746,6 +784,7 @@
746784 unsigned long mfrr);
747785 int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr);
748786 int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr);
787
+void kvmppc_guest_entry_inject_int(struct kvm_vcpu *vcpu);
749788
750789 /*
751790 * Host-side operations we want to set up while running in real