hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/powerpc/include/asm/kvm_host.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. 2007
165 *
....@@ -46,6 +35,7 @@
4635 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
4736 #include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */
4837 #define KVM_MAX_VCPU_ID (MAX_SMT_THREADS * KVM_MAX_VCORES)
38
+#define KVM_MAX_NESTED_GUESTS KVMPPC_NR_LPIDS
4939
5040 #else
5141 #define KVM_MAX_VCPU_ID KVM_MAX_VCPUS
....@@ -69,10 +59,10 @@
6959
7060 extern int kvm_unmap_hva_range(struct kvm *kvm,
7161 unsigned long start, unsigned long end,
72
- bool blockable);
62
+ unsigned flags);
7363 extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
7464 extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
75
-extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
65
+extern int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
7666
7767 #define HPTEG_CACHE_NUM (1 << 15)
7868 #define HPTEG_HASH_BITS_PTE 13
....@@ -95,9 +85,12 @@
9585
9686 struct kvmppc_vcpu_book3s;
9787 struct kvmppc_book3s_shadow_vcpu;
88
+struct kvm_nested_guest;
9889
9990 struct kvm_vm_stat {
10091 ulong remote_tlb_flush;
92
+ ulong num_2M_pages;
93
+ ulong num_1G_pages;
10194 };
10295
10396 struct kvm_vcpu_stat {
....@@ -198,6 +191,8 @@
198191 struct kref kref;
199192 };
200193
194
+#define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64))
195
+
201196 struct kvmppc_spapr_tce_table {
202197 struct list_head list;
203198 struct kvm *kvm;
....@@ -207,6 +202,7 @@
207202 u64 offset; /* in pages */
208203 u64 size; /* window size in pages */
209204 struct list_head iommu_tables;
205
+ struct mutex alloc_lock;
210206 struct page *pages[0];
211207 };
212208
....@@ -219,6 +215,7 @@
219215 struct kvmppc_xive;
220216 struct kvmppc_xive_vcpu;
221217 extern struct kvm_device_ops kvm_xive_ops;
218
+extern struct kvm_device_ops kvm_xive_native_ops;
222219
223220 struct kvmppc_passthru_irqmap;
224221
....@@ -236,11 +233,25 @@
236233 };
237234
238235 /*
239
- * We use the top bit of each memslot->arch.rmap entry as a lock bit,
240
- * and bit 32 as a present flag. The bottom 32 bits are the
241
- * index in the guest HPT of a HPTE that points to the page.
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.
242239 */
243
-#define KVMPPC_RMAP_LOCK_BIT 63
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
244255 #define KVMPPC_RMAP_RC_SHIFT 32
245256 #define KVMPPC_RMAP_REFERENCED (HPTE_R_R << KVMPPC_RMAP_RC_SHIFT)
246257 #define KVMPPC_RMAP_PRESENT 0x100000000ul
....@@ -265,6 +276,11 @@
265276
266277 struct kvm_resize_hpt;
267278
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
+
268284 struct kvm_arch {
269285 unsigned int lpid;
270286 unsigned int smt_mode; /* # vcpus per virtual core */
....@@ -287,11 +303,13 @@
287303 cpumask_t cpu_in_guest;
288304 u8 radix;
289305 u8 fwnmi_enabled;
306
+ u8 secure_guest;
307
+ u8 svm_enabled;
290308 bool threads_indep;
309
+ bool nested_enable;
291310 pgd_t *pgtable;
292311 u64 process_table;
293312 struct dentry *debugfs_dir;
294
- struct dentry *htab_dentry;
295313 struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */
296314 #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
297315 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
....@@ -308,11 +326,22 @@
308326 #endif
309327 #ifdef CONFIG_KVM_XICS
310328 struct kvmppc_xics *xics;
311
- struct kvmppc_xive *xive;
329
+ struct kvmppc_xics *xics_device;
330
+ struct kvmppc_xive *xive; /* Current XIVE device in use */
331
+ struct {
332
+ struct kvmppc_xive *native;
333
+ struct kvmppc_xive *xics_on_xive;
334
+ } xive_devices;
312335 struct kvmppc_passthru_irqmap *pimap;
313336 #endif
314337 struct kvmppc_ops *kvm_ops;
315338 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
339
+ struct mutex uvmem_lock;
340
+ struct list_head uvmem_pfns;
341
+ struct mutex mmu_setup_lock; /* nests inside vcpu mutexes */
342
+ u64 l1_ptcr;
343
+ int max_nested_lpid;
344
+ struct kvm_nested_guest *nested_guests[KVM_MAX_NESTED_GUESTS];
316345 /* This array can grow quite large, keep it at the end */
317346 struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
318347 #endif
....@@ -362,7 +391,9 @@
362391 bool may_write : 1;
363392 bool may_execute : 1;
364393 unsigned long wimg;
394
+ unsigned long rc;
365395 u8 page_size; /* MMU_PAGE_xxx */
396
+ u8 page_shift;
366397 };
367398
368399 struct kvmppc_mmu {
....@@ -370,6 +401,7 @@
370401 void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
371402 u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
372403 u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
404
+ int (*slbfee)(struct kvm_vcpu *vcpu, gva_t eaddr, ulong *ret_slb);
373405 void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
374406 void (*slbia)(struct kvm_vcpu *vcpu);
375407 /* book3s */
....@@ -377,7 +409,6 @@
377409 u32 (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
378410 int (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr,
379411 struct kvmppc_pte *pte, bool data, bool iswrite);
380
- void (*reset_msr)(struct kvm_vcpu *vcpu);
381412 void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
382413 int (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid);
383414 u64 (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);
....@@ -439,6 +470,7 @@
439470 #define KVMPPC_IRQ_DEFAULT 0
440471 #define KVMPPC_IRQ_MPIC 1
441472 #define KVMPPC_IRQ_XICS 2 /* Includes a XIVE option */
473
+#define KVMPPC_IRQ_XIVE 3 /* XIVE native exploitation mode */
442474
443475 #define MMIO_HPTE_CACHE_SIZE 4
444476
....@@ -607,12 +639,14 @@
607639 u32 ccr1;
608640 u32 dbsr;
609641
610
- u64 mmcr[5];
642
+ u64 mmcr[4]; /* MMCR0, MMCR1, MMCR2, MMCR3 */
643
+ u64 mmcra;
644
+ u64 mmcrs;
611645 u32 pmc[8];
612646 u32 spmc[2];
613647 u64 siar;
614648 u64 sdar;
615
- u64 sier;
649
+ u64 sier[3];
616650 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
617651 u64 tfhar;
618652 u64 texasr;
....@@ -707,6 +741,7 @@
707741 u8 hcall_needed;
708742 u8 epr_flags; /* KVMPPC_EPR_xxx */
709743 u8 epr_needed;
744
+ u8 external_oneshot; /* clear external irq after delivery */
710745
711746 u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
712747
....@@ -720,7 +755,7 @@
720755 u8 irq_pending; /* Used by XIVE to signal pending guest irqs */
721756 u32 last_inst;
722757
723
- struct swait_queue_head *wqp;
758
+ struct rcuwait *waitp;
724759 struct kvmppc_vcore *vcore;
725760 int ret;
726761 int trap;
....@@ -764,7 +799,6 @@
764799 struct mmio_hpte_cache_entry *pgfault_cache;
765800
766801 struct task_struct *run_task;
767
- struct kvm_run *kvm_run;
768802
769803 spinlock_t vpa_update_lock;
770804 struct kvmppc_vpa vpa;
....@@ -781,6 +815,11 @@
781815 u32 emul_inst;
782816
783817 u32 online;
818
+
819
+ /* For support of nested guests */
820
+ struct kvm_nested_guest *nested;
821
+ u32 nested_vcpu_id;
822
+ gpa_t nested_io_gpr;
784823 #endif
785824
786825 #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING
....@@ -793,7 +832,6 @@
793832 struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */
794833
795834 struct dentry *debugfs_dir;
796
- struct dentry *debugfs_timings;
797835 #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
798836 };
799837
....@@ -815,6 +853,8 @@
815853 #define KVM_MMIO_REG_FQPR 0x00c0
816854 #define KVM_MMIO_REG_VSX 0x0100
817855 #define KVM_MMIO_REG_VMX 0x0180
856
+#define KVM_MMIO_REG_NESTED_GPR 0xffc0
857
+
818858
819859 #define __KVM_HAVE_ARCH_WQP
820860 #define __KVM_HAVE_CREATE_DEVICE