| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 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 | 3 | * |
|---|
| 15 | 4 | * Copyright IBM Corp. 2007 |
|---|
| 16 | 5 | * |
|---|
| .. | .. |
|---|
| 46 | 35 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
|---|
| 47 | 36 | #include <asm/kvm_book3s_asm.h> /* for MAX_SMT_THREADS */ |
|---|
| 48 | 37 | #define KVM_MAX_VCPU_ID (MAX_SMT_THREADS * KVM_MAX_VCORES) |
|---|
| 38 | +#define KVM_MAX_NESTED_GUESTS KVMPPC_NR_LPIDS |
|---|
| 49 | 39 | |
|---|
| 50 | 40 | #else |
|---|
| 51 | 41 | #define KVM_MAX_VCPU_ID KVM_MAX_VCPUS |
|---|
| .. | .. |
|---|
| 69 | 59 | |
|---|
| 70 | 60 | extern int kvm_unmap_hva_range(struct kvm *kvm, |
|---|
| 71 | 61 | unsigned long start, unsigned long end, |
|---|
| 72 | | - bool blockable); |
|---|
| 62 | + unsigned flags); |
|---|
| 73 | 63 | extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); |
|---|
| 74 | 64 | 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); |
|---|
| 76 | 66 | |
|---|
| 77 | 67 | #define HPTEG_CACHE_NUM (1 << 15) |
|---|
| 78 | 68 | #define HPTEG_HASH_BITS_PTE 13 |
|---|
| .. | .. |
|---|
| 95 | 85 | |
|---|
| 96 | 86 | struct kvmppc_vcpu_book3s; |
|---|
| 97 | 87 | struct kvmppc_book3s_shadow_vcpu; |
|---|
| 88 | +struct kvm_nested_guest; |
|---|
| 98 | 89 | |
|---|
| 99 | 90 | struct kvm_vm_stat { |
|---|
| 100 | 91 | ulong remote_tlb_flush; |
|---|
| 92 | + ulong num_2M_pages; |
|---|
| 93 | + ulong num_1G_pages; |
|---|
| 101 | 94 | }; |
|---|
| 102 | 95 | |
|---|
| 103 | 96 | struct kvm_vcpu_stat { |
|---|
| .. | .. |
|---|
| 198 | 191 | struct kref kref; |
|---|
| 199 | 192 | }; |
|---|
| 200 | 193 | |
|---|
| 194 | +#define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64)) |
|---|
| 195 | + |
|---|
| 201 | 196 | struct kvmppc_spapr_tce_table { |
|---|
| 202 | 197 | struct list_head list; |
|---|
| 203 | 198 | struct kvm *kvm; |
|---|
| .. | .. |
|---|
| 207 | 202 | u64 offset; /* in pages */ |
|---|
| 208 | 203 | u64 size; /* window size in pages */ |
|---|
| 209 | 204 | struct list_head iommu_tables; |
|---|
| 205 | + struct mutex alloc_lock; |
|---|
| 210 | 206 | struct page *pages[0]; |
|---|
| 211 | 207 | }; |
|---|
| 212 | 208 | |
|---|
| .. | .. |
|---|
| 219 | 215 | struct kvmppc_xive; |
|---|
| 220 | 216 | struct kvmppc_xive_vcpu; |
|---|
| 221 | 217 | extern struct kvm_device_ops kvm_xive_ops; |
|---|
| 218 | +extern struct kvm_device_ops kvm_xive_native_ops; |
|---|
| 222 | 219 | |
|---|
| 223 | 220 | struct kvmppc_passthru_irqmap; |
|---|
| 224 | 221 | |
|---|
| .. | .. |
|---|
| 236 | 233 | }; |
|---|
| 237 | 234 | |
|---|
| 238 | 235 | /* |
|---|
| 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. |
|---|
| 242 | 239 | */ |
|---|
| 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 |
|---|
| 244 | 255 | #define KVMPPC_RMAP_RC_SHIFT 32 |
|---|
| 245 | 256 | #define KVMPPC_RMAP_REFERENCED (HPTE_R_R << KVMPPC_RMAP_RC_SHIFT) |
|---|
| 246 | 257 | #define KVMPPC_RMAP_PRESENT 0x100000000ul |
|---|
| .. | .. |
|---|
| 265 | 276 | |
|---|
| 266 | 277 | struct kvm_resize_hpt; |
|---|
| 267 | 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 | + |
|---|
| 268 | 284 | struct kvm_arch { |
|---|
| 269 | 285 | unsigned int lpid; |
|---|
| 270 | 286 | unsigned int smt_mode; /* # vcpus per virtual core */ |
|---|
| .. | .. |
|---|
| 287 | 303 | cpumask_t cpu_in_guest; |
|---|
| 288 | 304 | u8 radix; |
|---|
| 289 | 305 | u8 fwnmi_enabled; |
|---|
| 306 | + u8 secure_guest; |
|---|
| 307 | + u8 svm_enabled; |
|---|
| 290 | 308 | bool threads_indep; |
|---|
| 309 | + bool nested_enable; |
|---|
| 291 | 310 | pgd_t *pgtable; |
|---|
| 292 | 311 | u64 process_table; |
|---|
| 293 | 312 | struct dentry *debugfs_dir; |
|---|
| 294 | | - struct dentry *htab_dentry; |
|---|
| 295 | 313 | struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */ |
|---|
| 296 | 314 | #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ |
|---|
| 297 | 315 | #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE |
|---|
| .. | .. |
|---|
| 308 | 326 | #endif |
|---|
| 309 | 327 | #ifdef CONFIG_KVM_XICS |
|---|
| 310 | 328 | 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; |
|---|
| 312 | 335 | struct kvmppc_passthru_irqmap *pimap; |
|---|
| 313 | 336 | #endif |
|---|
| 314 | 337 | struct kvmppc_ops *kvm_ops; |
|---|
| 315 | 338 | #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]; |
|---|
| 316 | 345 | /* This array can grow quite large, keep it at the end */ |
|---|
| 317 | 346 | struct kvmppc_vcore *vcores[KVM_MAX_VCORES]; |
|---|
| 318 | 347 | #endif |
|---|
| .. | .. |
|---|
| 362 | 391 | bool may_write : 1; |
|---|
| 363 | 392 | bool may_execute : 1; |
|---|
| 364 | 393 | unsigned long wimg; |
|---|
| 394 | + unsigned long rc; |
|---|
| 365 | 395 | u8 page_size; /* MMU_PAGE_xxx */ |
|---|
| 396 | + u8 page_shift; |
|---|
| 366 | 397 | }; |
|---|
| 367 | 398 | |
|---|
| 368 | 399 | struct kvmppc_mmu { |
|---|
| .. | .. |
|---|
| 370 | 401 | void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs); |
|---|
| 371 | 402 | u64 (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr); |
|---|
| 372 | 403 | u64 (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr); |
|---|
| 404 | + int (*slbfee)(struct kvm_vcpu *vcpu, gva_t eaddr, ulong *ret_slb); |
|---|
| 373 | 405 | void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr); |
|---|
| 374 | 406 | void (*slbia)(struct kvm_vcpu *vcpu); |
|---|
| 375 | 407 | /* book3s */ |
|---|
| .. | .. |
|---|
| 377 | 409 | u32 (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum); |
|---|
| 378 | 410 | int (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr, |
|---|
| 379 | 411 | struct kvmppc_pte *pte, bool data, bool iswrite); |
|---|
| 380 | | - void (*reset_msr)(struct kvm_vcpu *vcpu); |
|---|
| 381 | 412 | void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large); |
|---|
| 382 | 413 | int (*esid_to_vsid)(struct kvm_vcpu *vcpu, ulong esid, u64 *vsid); |
|---|
| 383 | 414 | u64 (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data); |
|---|
| .. | .. |
|---|
| 439 | 470 | #define KVMPPC_IRQ_DEFAULT 0 |
|---|
| 440 | 471 | #define KVMPPC_IRQ_MPIC 1 |
|---|
| 441 | 472 | #define KVMPPC_IRQ_XICS 2 /* Includes a XIVE option */ |
|---|
| 473 | +#define KVMPPC_IRQ_XIVE 3 /* XIVE native exploitation mode */ |
|---|
| 442 | 474 | |
|---|
| 443 | 475 | #define MMIO_HPTE_CACHE_SIZE 4 |
|---|
| 444 | 476 | |
|---|
| .. | .. |
|---|
| 607 | 639 | u32 ccr1; |
|---|
| 608 | 640 | u32 dbsr; |
|---|
| 609 | 641 | |
|---|
| 610 | | - u64 mmcr[5]; |
|---|
| 642 | + u64 mmcr[4]; /* MMCR0, MMCR1, MMCR2, MMCR3 */ |
|---|
| 643 | + u64 mmcra; |
|---|
| 644 | + u64 mmcrs; |
|---|
| 611 | 645 | u32 pmc[8]; |
|---|
| 612 | 646 | u32 spmc[2]; |
|---|
| 613 | 647 | u64 siar; |
|---|
| 614 | 648 | u64 sdar; |
|---|
| 615 | | - u64 sier; |
|---|
| 649 | + u64 sier[3]; |
|---|
| 616 | 650 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
|---|
| 617 | 651 | u64 tfhar; |
|---|
| 618 | 652 | u64 texasr; |
|---|
| .. | .. |
|---|
| 707 | 741 | u8 hcall_needed; |
|---|
| 708 | 742 | u8 epr_flags; /* KVMPPC_EPR_xxx */ |
|---|
| 709 | 743 | u8 epr_needed; |
|---|
| 744 | + u8 external_oneshot; /* clear external irq after delivery */ |
|---|
| 710 | 745 | |
|---|
| 711 | 746 | u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */ |
|---|
| 712 | 747 | |
|---|
| .. | .. |
|---|
| 720 | 755 | u8 irq_pending; /* Used by XIVE to signal pending guest irqs */ |
|---|
| 721 | 756 | u32 last_inst; |
|---|
| 722 | 757 | |
|---|
| 723 | | - struct swait_queue_head *wqp; |
|---|
| 758 | + struct rcuwait *waitp; |
|---|
| 724 | 759 | struct kvmppc_vcore *vcore; |
|---|
| 725 | 760 | int ret; |
|---|
| 726 | 761 | int trap; |
|---|
| .. | .. |
|---|
| 764 | 799 | struct mmio_hpte_cache_entry *pgfault_cache; |
|---|
| 765 | 800 | |
|---|
| 766 | 801 | struct task_struct *run_task; |
|---|
| 767 | | - struct kvm_run *kvm_run; |
|---|
| 768 | 802 | |
|---|
| 769 | 803 | spinlock_t vpa_update_lock; |
|---|
| 770 | 804 | struct kvmppc_vpa vpa; |
|---|
| .. | .. |
|---|
| 781 | 815 | u32 emul_inst; |
|---|
| 782 | 816 | |
|---|
| 783 | 817 | 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; |
|---|
| 784 | 823 | #endif |
|---|
| 785 | 824 | |
|---|
| 786 | 825 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
|---|
| .. | .. |
|---|
| 793 | 832 | struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */ |
|---|
| 794 | 833 | |
|---|
| 795 | 834 | struct dentry *debugfs_dir; |
|---|
| 796 | | - struct dentry *debugfs_timings; |
|---|
| 797 | 835 | #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ |
|---|
| 798 | 836 | }; |
|---|
| 799 | 837 | |
|---|
| .. | .. |
|---|
| 815 | 853 | #define KVM_MMIO_REG_FQPR 0x00c0 |
|---|
| 816 | 854 | #define KVM_MMIO_REG_VSX 0x0100 |
|---|
| 817 | 855 | #define KVM_MMIO_REG_VMX 0x0180 |
|---|
| 856 | +#define KVM_MMIO_REG_NESTED_GPR 0xffc0 |
|---|
| 857 | + |
|---|
| 818 | 858 | |
|---|
| 819 | 859 | #define __KVM_HAVE_ARCH_WQP |
|---|
| 820 | 860 | #define __KVM_HAVE_CREATE_DEVICE |
|---|