Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'kvm-5.16-fixes' into kvm-master

* Fix misuse of gfn-to-pfn cache when recording guest steal time / preempted status

* Fix selftests on APICv machines

* Fix sparse warnings

* Fix detection of KVM features in CPUID

* Cleanups for bogus writes to MSR_KVM_PV_EOI_EN

* Fixes and cleanups for MSR bitmap handling

* Cleanups for INVPCID

* Make x86 KVM_SOFT_MAX_VCPUS consistent with other architectures

+319 -266
+3 -2
arch/x86/include/asm/kvm_host.h
··· 38 38 #define __KVM_HAVE_ARCH_VCPU_DEBUGFS 39 39 40 40 #define KVM_MAX_VCPUS 1024 41 - #define KVM_SOFT_MAX_VCPUS 710 42 41 43 42 /* 44 43 * In x86, the VCPU ID corresponds to the APIC ID, and APIC IDs ··· 724 725 725 726 int cpuid_nent; 726 727 struct kvm_cpuid_entry2 *cpuid_entries; 728 + u32 kvm_cpuid_base; 727 729 728 730 u64 reserved_gpa_bits; 729 731 int maxphyaddr; ··· 748 748 u8 preempted; 749 749 u64 msr_val; 750 750 u64 last_steal; 751 - struct gfn_to_pfn_cache cache; 751 + struct gfn_to_hva_cache cache; 752 752 } st; 753 753 754 754 u64 l1_tsc_offset; ··· 1034 1034 #define APICV_INHIBIT_REASON_IRQWIN 3 1035 1035 #define APICV_INHIBIT_REASON_PIT_REINJ 4 1036 1036 #define APICV_INHIBIT_REASON_X2APIC 5 1037 + #define APICV_INHIBIT_REASON_BLOCKIRQ 6 1037 1038 1038 1039 struct kvm_arch { 1039 1040 unsigned long n_used_mmu_pages;
+4 -1
arch/x86/include/asm/processor.h
··· 806 806 static inline u32 amd_get_highest_perf(void) { return 0; } 807 807 #endif 808 808 809 + #define for_each_possible_hypervisor_cpuid_base(function) \ 810 + for (function = 0x40000000; function < 0x40010000; function += 0x100) 811 + 809 812 static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) 810 813 { 811 814 uint32_t base, eax, signature[3]; 812 815 813 - for (base = 0x40000000; base < 0x40010000; base += 0x100) { 816 + for_each_possible_hypervisor_cpuid_base(base) { 814 817 cpuid(base, &eax, &signature[0], &signature[1], &signature[2]); 815 818 816 819 if (!memcmp(sig, signature, 12) &&
+1
arch/x86/include/uapi/asm/kvm_para.h
··· 8 8 * should be used to determine that a VM is running under KVM. 9 9 */ 10 10 #define KVM_CPUID_SIGNATURE 0x40000000 11 + #define KVM_SIGNATURE "KVMKVMKVM\0\0\0" 11 12 12 13 /* This CPUID returns two feature bitmaps in eax, edx. Before enabling 13 14 * a particular paravirtualization, the appropriate feature bit should
+1 -1
arch/x86/kernel/kvm.c
··· 809 809 return 0; /* So we don't blow up on old processors */ 810 810 811 811 if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) 812 - return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0); 812 + return hypervisor_cpuid_base(KVM_SIGNATURE, 0); 813 813 814 814 return 0; 815 815 }
+64 -29
arch/x86/kvm/cpuid.c
··· 99 99 return 0; 100 100 } 101 101 102 + static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *vcpu) 103 + { 104 + u32 function; 105 + struct kvm_cpuid_entry2 *entry; 106 + 107 + vcpu->arch.kvm_cpuid_base = 0; 108 + 109 + for_each_possible_hypervisor_cpuid_base(function) { 110 + entry = kvm_find_cpuid_entry(vcpu, function, 0); 111 + 112 + if (entry) { 113 + u32 signature[3]; 114 + 115 + signature[0] = entry->ebx; 116 + signature[1] = entry->ecx; 117 + signature[2] = entry->edx; 118 + 119 + BUILD_BUG_ON(sizeof(signature) > sizeof(KVM_SIGNATURE)); 120 + if (!memcmp(signature, KVM_SIGNATURE, sizeof(signature))) { 121 + vcpu->arch.kvm_cpuid_base = function; 122 + break; 123 + } 124 + } 125 + } 126 + } 127 + 128 + struct kvm_cpuid_entry2 *kvm_find_kvm_cpuid_features(struct kvm_vcpu *vcpu) 129 + { 130 + u32 base = vcpu->arch.kvm_cpuid_base; 131 + 132 + if (!base) 133 + return NULL; 134 + 135 + return kvm_find_cpuid_entry(vcpu, base | KVM_CPUID_FEATURES, 0); 136 + } 137 + 102 138 void kvm_update_pv_runtime(struct kvm_vcpu *vcpu) 103 139 { 104 - struct kvm_cpuid_entry2 *best; 105 - 106 - best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0); 140 + struct kvm_cpuid_entry2 *best = kvm_find_kvm_cpuid_features(vcpu); 107 141 108 142 /* 109 143 * save the feature bitmap to avoid cpuid lookup for every PV ··· 176 142 cpuid_entry_has(best, X86_FEATURE_XSAVEC))) 177 143 best->ebx = xstate_required_size(vcpu->arch.xcr0, true); 178 144 179 - best = kvm_find_cpuid_entry(vcpu, KVM_CPUID_FEATURES, 0); 145 + best = kvm_find_kvm_cpuid_features(vcpu); 180 146 if (kvm_hlt_in_guest(vcpu->kvm) && best && 181 147 (best->eax & (1 << KVM_FEATURE_PV_UNHALT))) 182 148 best->eax &= ~(1 << KVM_FEATURE_PV_UNHALT); ··· 273 239 return rsvd_bits(cpuid_maxphyaddr(vcpu), 63); 274 240 } 275 241 242 + static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2, 243 + int nent) 244 + { 245 + int r; 246 + 247 + r = kvm_check_cpuid(e2, nent); 248 + if (r) 249 + return r; 250 + 251 + kvfree(vcpu->arch.cpuid_entries); 252 + vcpu->arch.cpuid_entries = e2; 253 + vcpu->arch.cpuid_nent = nent; 254 + 255 + kvm_update_kvm_cpuid_base(vcpu); 256 + kvm_update_cpuid_runtime(vcpu); 257 + kvm_vcpu_after_set_cpuid(vcpu); 258 + 259 + return 0; 260 + } 261 + 276 262 /* when an old userspace process fills a new kernel module */ 277 263 int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, 278 264 struct kvm_cpuid *cpuid, ··· 329 275 e2[i].padding[2] = 0; 330 276 } 331 277 332 - r = kvm_check_cpuid(e2, cpuid->nent); 333 - if (r) { 278 + r = kvm_set_cpuid(vcpu, e2, cpuid->nent); 279 + if (r) 334 280 kvfree(e2); 335 - goto out_free_cpuid; 336 - } 337 - 338 - kvfree(vcpu->arch.cpuid_entries); 339 - vcpu->arch.cpuid_entries = e2; 340 - vcpu->arch.cpuid_nent = cpuid->nent; 341 - 342 - kvm_update_cpuid_runtime(vcpu); 343 - kvm_vcpu_after_set_cpuid(vcpu); 344 281 345 282 out_free_cpuid: 346 283 kvfree(e); ··· 355 310 return PTR_ERR(e2); 356 311 } 357 312 358 - r = kvm_check_cpuid(e2, cpuid->nent); 359 - if (r) { 313 + r = kvm_set_cpuid(vcpu, e2, cpuid->nent); 314 + if (r) 360 315 kvfree(e2); 361 - return r; 362 - } 363 316 364 - kvfree(vcpu->arch.cpuid_entries); 365 - vcpu->arch.cpuid_entries = e2; 366 - vcpu->arch.cpuid_nent = cpuid->nent; 367 - 368 - kvm_update_cpuid_runtime(vcpu); 369 - kvm_vcpu_after_set_cpuid(vcpu); 370 - 371 - return 0; 317 + return r; 372 318 } 373 319 374 320 int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, ··· 907 871 } 908 872 break; 909 873 case KVM_CPUID_SIGNATURE: { 910 - static const char signature[12] = "KVMKVMKVM\0\0"; 911 - const u32 *sigptr = (const u32 *)signature; 874 + const u32 *sigptr = (const u32 *)KVM_SIGNATURE; 912 875 entry->eax = KVM_CPUID_FEATURES; 913 876 entry->ebx = sigptr[0]; 914 877 entry->ecx = sigptr[1];
+2 -2
arch/x86/kvm/hyperv.c
··· 1472 1472 1473 1473 if (!(data & HV_X64_MSR_VP_ASSIST_PAGE_ENABLE)) { 1474 1474 hv_vcpu->hv_vapic = data; 1475 - if (kvm_lapic_enable_pv_eoi(vcpu, 0, 0)) 1475 + if (kvm_lapic_set_pv_eoi(vcpu, 0, 0)) 1476 1476 return 1; 1477 1477 break; 1478 1478 } ··· 1490 1490 return 1; 1491 1491 hv_vcpu->hv_vapic = data; 1492 1492 kvm_vcpu_mark_page_dirty(vcpu, gfn); 1493 - if (kvm_lapic_enable_pv_eoi(vcpu, 1493 + if (kvm_lapic_set_pv_eoi(vcpu, 1494 1494 gfn_to_gpa(gfn) | KVM_MSR_ENABLED, 1495 1495 sizeof(struct hv_vp_assist_page))) 1496 1496 return 1;
+14 -9
arch/x86/kvm/lapic.c
··· 2856 2856 return 0; 2857 2857 } 2858 2858 2859 - int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len) 2859 + int kvm_lapic_set_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len) 2860 2860 { 2861 2861 u64 addr = data & ~KVM_MSR_ENABLED; 2862 2862 struct gfn_to_hva_cache *ghc = &vcpu->arch.pv_eoi.data; 2863 2863 unsigned long new_len; 2864 + int ret; 2864 2865 2865 2866 if (!IS_ALIGNED(addr, 4)) 2866 2867 return 1; 2867 2868 2869 + if (data & KVM_MSR_ENABLED) { 2870 + if (addr == ghc->gpa && len <= ghc->len) 2871 + new_len = ghc->len; 2872 + else 2873 + new_len = len; 2874 + 2875 + ret = kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, addr, new_len); 2876 + if (ret) 2877 + return ret; 2878 + } 2879 + 2868 2880 vcpu->arch.pv_eoi.msr_val = data; 2869 - if (!pv_eoi_enabled(vcpu)) 2870 - return 0; 2871 2881 2872 - if (addr == ghc->gpa && len <= ghc->len) 2873 - new_len = ghc->len; 2874 - else 2875 - new_len = len; 2876 - 2877 - return kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, addr, new_len); 2882 + return 0; 2878 2883 } 2879 2884 2880 2885 int kvm_apic_accept_events(struct kvm_vcpu *vcpu)
+1 -1
arch/x86/kvm/lapic.h
··· 127 127 int kvm_hv_vapic_msr_write(struct kvm_vcpu *vcpu, u32 msr, u64 data); 128 128 int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data); 129 129 130 - int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len); 130 + int kvm_lapic_set_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len); 131 131 void kvm_lapic_exit(void); 132 132 133 133 #define VEC_POS(v) ((v) & (32 - 1))
+5 -5
arch/x86/kvm/mmu/mmu.c
··· 3191 3191 new_spte |= PT_WRITABLE_MASK; 3192 3192 3193 3193 /* 3194 - * Do not fix write-permission on the large spte. Since 3195 - * we only dirty the first page into the dirty-bitmap in 3194 + * Do not fix write-permission on the large spte when 3195 + * dirty logging is enabled. Since we only dirty the 3196 + * first page into the dirty-bitmap in 3196 3197 * fast_pf_fix_direct_spte(), other pages are missed 3197 3198 * if its slot has dirty logging enabled. 3198 3199 * 3199 3200 * Instead, we let the slow page fault path create a 3200 3201 * normal spte to fix the access. 3201 - * 3202 - * See the comments in kvm_arch_commit_memory_region(). 3203 3202 */ 3204 - if (sp->role.level > PG_LEVEL_4K) 3203 + if (sp->role.level > PG_LEVEL_4K && 3204 + kvm_slot_dirty_track_enabled(fault->slot)) 3205 3205 break; 3206 3206 } 3207 3207
+1 -1
arch/x86/kvm/mmu/tdp_mmu.c
··· 897 897 struct kvm_page_fault *fault, 898 898 struct tdp_iter *iter) 899 899 { 900 - struct kvm_mmu_page *sp = sptep_to_sp(iter->sptep); 900 + struct kvm_mmu_page *sp = sptep_to_sp(rcu_dereference(iter->sptep)); 901 901 u64 new_spte; 902 902 int ret = RET_PF_FIXED; 903 903 bool wrprot = false;
+1 -1
arch/x86/kvm/pmu.c
··· 319 319 } 320 320 321 321 /* check if idx is a valid index to access PMU */ 322 - int kvm_pmu_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 322 + bool kvm_pmu_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 323 323 { 324 324 return kvm_x86_ops.pmu_ops->is_valid_rdpmc_ecx(vcpu, idx); 325 325 }
+2 -2
arch/x86/kvm/pmu.h
··· 32 32 struct kvm_pmc *(*rdpmc_ecx_to_pmc)(struct kvm_vcpu *vcpu, 33 33 unsigned int idx, u64 *mask); 34 34 struct kvm_pmc *(*msr_idx_to_pmc)(struct kvm_vcpu *vcpu, u32 msr); 35 - int (*is_valid_rdpmc_ecx)(struct kvm_vcpu *vcpu, unsigned int idx); 35 + bool (*is_valid_rdpmc_ecx)(struct kvm_vcpu *vcpu, unsigned int idx); 36 36 bool (*is_valid_msr)(struct kvm_vcpu *vcpu, u32 msr); 37 37 int (*get_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr_info); 38 38 int (*set_msr)(struct kvm_vcpu *vcpu, struct msr_data *msr_info); ··· 149 149 void kvm_pmu_deliver_pmi(struct kvm_vcpu *vcpu); 150 150 void kvm_pmu_handle_event(struct kvm_vcpu *vcpu); 151 151 int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data); 152 - int kvm_pmu_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx); 152 + bool kvm_pmu_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx); 153 153 bool kvm_pmu_is_valid_msr(struct kvm_vcpu *vcpu, u32 msr); 154 154 int kvm_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info); 155 155 int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info);
+2 -1
arch/x86/kvm/svm/avic.c
··· 904 904 BIT(APICV_INHIBIT_REASON_NESTED) | 905 905 BIT(APICV_INHIBIT_REASON_IRQWIN) | 906 906 BIT(APICV_INHIBIT_REASON_PIT_REINJ) | 907 - BIT(APICV_INHIBIT_REASON_X2APIC); 907 + BIT(APICV_INHIBIT_REASON_X2APIC) | 908 + BIT(APICV_INHIBIT_REASON_BLOCKIRQ); 908 909 909 910 return supported & BIT(bit); 910 911 }
+2 -3
arch/x86/kvm/svm/pmu.c
··· 181 181 return get_gp_pmc_amd(pmu, base + pmc_idx, PMU_TYPE_COUNTER); 182 182 } 183 183 184 - /* returns 0 if idx's corresponding MSR exists; otherwise returns 1. */ 185 - static int amd_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 184 + static bool amd_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 186 185 { 187 186 struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 188 187 189 188 idx &= ~(3u << 30); 190 189 191 - return (idx >= pmu->nr_arch_gp_counters); 190 + return idx < pmu->nr_arch_gp_counters; 192 191 } 193 192 194 193 /* idx is the ECX register of RDPMC instruction */
-5
arch/x86/kvm/svm/svm.c
··· 3121 3121 type = svm->vmcb->control.exit_info_2; 3122 3122 gva = svm->vmcb->control.exit_info_1; 3123 3123 3124 - if (type > 3) { 3125 - kvm_inject_gp(vcpu, 0); 3126 - return 1; 3127 - } 3128 - 3129 3124 return kvm_handle_invpcid(vcpu, type, gva); 3130 3125 } 3131 3126
+68 -102
arch/x86/kvm/vmx/nested.c
··· 525 525 } 526 526 527 527 /* 528 - * Check if MSR is intercepted for L01 MSR bitmap. 528 + * For x2APIC MSRs, ignore the vmcs01 bitmap. L1 can enable x2APIC without L1 529 + * itself utilizing x2APIC. All MSRs were previously set to be intercepted, 530 + * only the "disable intercept" case needs to be handled. 529 531 */ 530 - static bool msr_write_intercepted_l01(struct kvm_vcpu *vcpu, u32 msr) 532 + static void nested_vmx_disable_intercept_for_x2apic_msr(unsigned long *msr_bitmap_l1, 533 + unsigned long *msr_bitmap_l0, 534 + u32 msr, int type) 531 535 { 532 - unsigned long *msr_bitmap; 533 - int f = sizeof(unsigned long); 536 + if (type & MSR_TYPE_R && !vmx_test_msr_bitmap_read(msr_bitmap_l1, msr)) 537 + vmx_clear_msr_bitmap_read(msr_bitmap_l0, msr); 534 538 535 - if (!cpu_has_vmx_msr_bitmap()) 536 - return true; 537 - 538 - msr_bitmap = to_vmx(vcpu)->vmcs01.msr_bitmap; 539 - 540 - if (msr <= 0x1fff) { 541 - return !!test_bit(msr, msr_bitmap + 0x800 / f); 542 - } else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) { 543 - msr &= 0x1fff; 544 - return !!test_bit(msr, msr_bitmap + 0xc00 / f); 545 - } 546 - 547 - return true; 548 - } 549 - 550 - /* 551 - * If a msr is allowed by L0, we should check whether it is allowed by L1. 552 - * The corresponding bit will be cleared unless both of L0 and L1 allow it. 553 - */ 554 - static void nested_vmx_disable_intercept_for_msr(unsigned long *msr_bitmap_l1, 555 - unsigned long *msr_bitmap_nested, 556 - u32 msr, int type) 557 - { 558 - int f = sizeof(unsigned long); 559 - 560 - /* 561 - * See Intel PRM Vol. 3, 20.6.9 (MSR-Bitmap Address). Early manuals 562 - * have the write-low and read-high bitmap offsets the wrong way round. 563 - * We can control MSRs 0x00000000-0x00001fff and 0xc0000000-0xc0001fff. 564 - */ 565 - if (msr <= 0x1fff) { 566 - if (type & MSR_TYPE_R && 567 - !test_bit(msr, msr_bitmap_l1 + 0x000 / f)) 568 - /* read-low */ 569 - __clear_bit(msr, msr_bitmap_nested + 0x000 / f); 570 - 571 - if (type & MSR_TYPE_W && 572 - !test_bit(msr, msr_bitmap_l1 + 0x800 / f)) 573 - /* write-low */ 574 - __clear_bit(msr, msr_bitmap_nested + 0x800 / f); 575 - 576 - } else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) { 577 - msr &= 0x1fff; 578 - if (type & MSR_TYPE_R && 579 - !test_bit(msr, msr_bitmap_l1 + 0x400 / f)) 580 - /* read-high */ 581 - __clear_bit(msr, msr_bitmap_nested + 0x400 / f); 582 - 583 - if (type & MSR_TYPE_W && 584 - !test_bit(msr, msr_bitmap_l1 + 0xc00 / f)) 585 - /* write-high */ 586 - __clear_bit(msr, msr_bitmap_nested + 0xc00 / f); 587 - 588 - } 539 + if (type & MSR_TYPE_W && !vmx_test_msr_bitmap_write(msr_bitmap_l1, msr)) 540 + vmx_clear_msr_bitmap_write(msr_bitmap_l0, msr); 589 541 } 590 542 591 543 static inline void enable_x2apic_msr_intercepts(unsigned long *msr_bitmap) ··· 552 600 } 553 601 } 554 602 603 + #define BUILD_NVMX_MSR_INTERCEPT_HELPER(rw) \ 604 + static inline \ 605 + void nested_vmx_set_msr_##rw##_intercept(struct vcpu_vmx *vmx, \ 606 + unsigned long *msr_bitmap_l1, \ 607 + unsigned long *msr_bitmap_l0, u32 msr) \ 608 + { \ 609 + if (vmx_test_msr_bitmap_##rw(vmx->vmcs01.msr_bitmap, msr) || \ 610 + vmx_test_msr_bitmap_##rw(msr_bitmap_l1, msr)) \ 611 + vmx_set_msr_bitmap_##rw(msr_bitmap_l0, msr); \ 612 + else \ 613 + vmx_clear_msr_bitmap_##rw(msr_bitmap_l0, msr); \ 614 + } 615 + BUILD_NVMX_MSR_INTERCEPT_HELPER(read) 616 + BUILD_NVMX_MSR_INTERCEPT_HELPER(write) 617 + 618 + static inline void nested_vmx_set_intercept_for_msr(struct vcpu_vmx *vmx, 619 + unsigned long *msr_bitmap_l1, 620 + unsigned long *msr_bitmap_l0, 621 + u32 msr, int types) 622 + { 623 + if (types & MSR_TYPE_R) 624 + nested_vmx_set_msr_read_intercept(vmx, msr_bitmap_l1, 625 + msr_bitmap_l0, msr); 626 + if (types & MSR_TYPE_W) 627 + nested_vmx_set_msr_write_intercept(vmx, msr_bitmap_l1, 628 + msr_bitmap_l0, msr); 629 + } 630 + 555 631 /* 556 632 * Merge L0's and L1's MSR bitmap, return false to indicate that 557 633 * we do not use the hardware. ··· 587 607 static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu, 588 608 struct vmcs12 *vmcs12) 589 609 { 610 + struct vcpu_vmx *vmx = to_vmx(vcpu); 590 611 int msr; 591 612 unsigned long *msr_bitmap_l1; 592 - unsigned long *msr_bitmap_l0 = to_vmx(vcpu)->nested.vmcs02.msr_bitmap; 593 - struct kvm_host_map *map = &to_vmx(vcpu)->nested.msr_bitmap_map; 613 + unsigned long *msr_bitmap_l0 = vmx->nested.vmcs02.msr_bitmap; 614 + struct kvm_host_map *map = &vmx->nested.msr_bitmap_map; 594 615 595 616 /* Nothing to do if the MSR bitmap is not in use. */ 596 617 if (!cpu_has_vmx_msr_bitmap() || ··· 606 625 /* 607 626 * To keep the control flow simple, pay eight 8-byte writes (sixteen 608 627 * 4-byte writes on 32-bit systems) up front to enable intercepts for 609 - * the x2APIC MSR range and selectively disable them below. 628 + * the x2APIC MSR range and selectively toggle those relevant to L2. 610 629 */ 611 630 enable_x2apic_msr_intercepts(msr_bitmap_l0); 612 631 ··· 625 644 } 626 645 } 627 646 628 - nested_vmx_disable_intercept_for_msr( 647 + nested_vmx_disable_intercept_for_x2apic_msr( 629 648 msr_bitmap_l1, msr_bitmap_l0, 630 649 X2APIC_MSR(APIC_TASKPRI), 631 650 MSR_TYPE_R | MSR_TYPE_W); 632 651 633 652 if (nested_cpu_has_vid(vmcs12)) { 634 - nested_vmx_disable_intercept_for_msr( 653 + nested_vmx_disable_intercept_for_x2apic_msr( 635 654 msr_bitmap_l1, msr_bitmap_l0, 636 655 X2APIC_MSR(APIC_EOI), 637 656 MSR_TYPE_W); 638 - nested_vmx_disable_intercept_for_msr( 657 + nested_vmx_disable_intercept_for_x2apic_msr( 639 658 msr_bitmap_l1, msr_bitmap_l0, 640 659 X2APIC_MSR(APIC_SELF_IPI), 641 660 MSR_TYPE_W); 642 661 } 643 662 } 644 663 645 - /* KVM unconditionally exposes the FS/GS base MSRs to L1. */ 646 - #ifdef CONFIG_X86_64 647 - nested_vmx_disable_intercept_for_msr(msr_bitmap_l1, msr_bitmap_l0, 648 - MSR_FS_BASE, MSR_TYPE_RW); 649 - 650 - nested_vmx_disable_intercept_for_msr(msr_bitmap_l1, msr_bitmap_l0, 651 - MSR_GS_BASE, MSR_TYPE_RW); 652 - 653 - nested_vmx_disable_intercept_for_msr(msr_bitmap_l1, msr_bitmap_l0, 654 - MSR_KERNEL_GS_BASE, MSR_TYPE_RW); 655 - #endif 656 - 657 664 /* 658 - * Checking the L0->L1 bitmap is trying to verify two things: 659 - * 660 - * 1. L0 gave a permission to L1 to actually passthrough the MSR. This 661 - * ensures that we do not accidentally generate an L02 MSR bitmap 662 - * from the L12 MSR bitmap that is too permissive. 663 - * 2. That L1 or L2s have actually used the MSR. This avoids 664 - * unnecessarily merging of the bitmap if the MSR is unused. This 665 - * works properly because we only update the L01 MSR bitmap lazily. 666 - * So even if L0 should pass L1 these MSRs, the L01 bitmap is only 667 - * updated to reflect this when L1 (or its L2s) actually write to 668 - * the MSR. 665 + * Always check vmcs01's bitmap to honor userspace MSR filters and any 666 + * other runtime changes to vmcs01's bitmap, e.g. dynamic pass-through. 669 667 */ 670 - if (!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL)) 671 - nested_vmx_disable_intercept_for_msr( 672 - msr_bitmap_l1, msr_bitmap_l0, 673 - MSR_IA32_SPEC_CTRL, 674 - MSR_TYPE_R | MSR_TYPE_W); 668 + #ifdef CONFIG_X86_64 669 + nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0, 670 + MSR_FS_BASE, MSR_TYPE_RW); 675 671 676 - if (!msr_write_intercepted_l01(vcpu, MSR_IA32_PRED_CMD)) 677 - nested_vmx_disable_intercept_for_msr( 678 - msr_bitmap_l1, msr_bitmap_l0, 679 - MSR_IA32_PRED_CMD, 680 - MSR_TYPE_W); 672 + nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0, 673 + MSR_GS_BASE, MSR_TYPE_RW); 681 674 682 - kvm_vcpu_unmap(vcpu, &to_vmx(vcpu)->nested.msr_bitmap_map, false); 675 + nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0, 676 + MSR_KERNEL_GS_BASE, MSR_TYPE_RW); 677 + #endif 678 + nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0, 679 + MSR_IA32_SPEC_CTRL, MSR_TYPE_RW); 680 + 681 + nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0, 682 + MSR_IA32_PRED_CMD, MSR_TYPE_W); 683 + 684 + kvm_vcpu_unmap(vcpu, &vmx->nested.msr_bitmap_map, false); 683 685 684 686 return true; 685 687 } ··· 5343 5379 struct { 5344 5380 u64 eptp, gpa; 5345 5381 } operand; 5346 - int i, r; 5382 + int i, r, gpr_index; 5347 5383 5348 5384 if (!(vmx->nested.msrs.secondary_ctls_high & 5349 5385 SECONDARY_EXEC_ENABLE_EPT) || ··· 5356 5392 return 1; 5357 5393 5358 5394 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); 5359 - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); 5395 + gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); 5396 + type = kvm_register_read(vcpu, gpr_index); 5360 5397 5361 5398 types = (vmx->nested.msrs.ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6; 5362 5399 ··· 5424 5459 u64 gla; 5425 5460 } operand; 5426 5461 u16 vpid02; 5427 - int r; 5462 + int r, gpr_index; 5428 5463 5429 5464 if (!(vmx->nested.msrs.secondary_ctls_high & 5430 5465 SECONDARY_EXEC_ENABLE_VPID) || ··· 5437 5472 return 1; 5438 5473 5439 5474 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); 5440 - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); 5475 + gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); 5476 + type = kvm_register_read(vcpu, gpr_index); 5441 5477 5442 5478 types = (vmx->nested.msrs.vpid_caps & 5443 5479 VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8;
+3 -4
arch/x86/kvm/vmx/pmu_intel.c
··· 118 118 } 119 119 } 120 120 121 - /* returns 0 if idx's corresponding MSR exists; otherwise returns 1. */ 122 - static int intel_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 121 + static bool intel_is_valid_rdpmc_ecx(struct kvm_vcpu *vcpu, unsigned int idx) 123 122 { 124 123 struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); 125 124 bool fixed = idx & (1u << 30); 126 125 127 126 idx &= ~(3u << 30); 128 127 129 - return (!fixed && idx >= pmu->nr_arch_gp_counters) || 130 - (fixed && idx >= pmu->nr_arch_fixed_counters); 128 + return fixed ? idx < pmu->nr_arch_fixed_counters 129 + : idx < pmu->nr_arch_gp_counters; 131 130 } 132 131 133 132 static struct kvm_pmc *intel_rdpmc_ecx_to_pmc(struct kvm_vcpu *vcpu,
+10 -63
arch/x86/kvm/vmx/vmx.c
··· 769 769 /* 770 770 * Check if MSR is intercepted for currently loaded MSR bitmap. 771 771 */ 772 - static bool msr_write_intercepted(struct kvm_vcpu *vcpu, u32 msr) 772 + static bool msr_write_intercepted(struct vcpu_vmx *vmx, u32 msr) 773 773 { 774 - unsigned long *msr_bitmap; 775 - int f = sizeof(unsigned long); 776 - 777 - if (!cpu_has_vmx_msr_bitmap()) 774 + if (!(exec_controls_get(vmx) & CPU_BASED_USE_MSR_BITMAPS)) 778 775 return true; 779 776 780 - msr_bitmap = to_vmx(vcpu)->loaded_vmcs->msr_bitmap; 781 - 782 - if (msr <= 0x1fff) { 783 - return !!test_bit(msr, msr_bitmap + 0x800 / f); 784 - } else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) { 785 - msr &= 0x1fff; 786 - return !!test_bit(msr, msr_bitmap + 0xc00 / f); 787 - } 788 - 789 - return true; 777 + return vmx_test_msr_bitmap_write(vmx->loaded_vmcs->msr_bitmap, 778 + MSR_IA32_SPEC_CTRL); 790 779 } 791 780 792 781 static void clear_atomic_switch_msr_special(struct vcpu_vmx *vmx, ··· 3686 3697 spin_unlock(&vmx_vpid_lock); 3687 3698 } 3688 3699 3689 - static void vmx_clear_msr_bitmap_read(ulong *msr_bitmap, u32 msr) 3690 - { 3691 - int f = sizeof(unsigned long); 3692 - 3693 - if (msr <= 0x1fff) 3694 - __clear_bit(msr, msr_bitmap + 0x000 / f); 3695 - else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) 3696 - __clear_bit(msr & 0x1fff, msr_bitmap + 0x400 / f); 3697 - } 3698 - 3699 - static void vmx_clear_msr_bitmap_write(ulong *msr_bitmap, u32 msr) 3700 - { 3701 - int f = sizeof(unsigned long); 3702 - 3703 - if (msr <= 0x1fff) 3704 - __clear_bit(msr, msr_bitmap + 0x800 / f); 3705 - else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) 3706 - __clear_bit(msr & 0x1fff, msr_bitmap + 0xc00 / f); 3707 - } 3708 - 3709 - static void vmx_set_msr_bitmap_read(ulong *msr_bitmap, u32 msr) 3710 - { 3711 - int f = sizeof(unsigned long); 3712 - 3713 - if (msr <= 0x1fff) 3714 - __set_bit(msr, msr_bitmap + 0x000 / f); 3715 - else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) 3716 - __set_bit(msr & 0x1fff, msr_bitmap + 0x400 / f); 3717 - } 3718 - 3719 - static void vmx_set_msr_bitmap_write(ulong *msr_bitmap, u32 msr) 3720 - { 3721 - int f = sizeof(unsigned long); 3722 - 3723 - if (msr <= 0x1fff) 3724 - __set_bit(msr, msr_bitmap + 0x800 / f); 3725 - else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) 3726 - __set_bit(msr & 0x1fff, msr_bitmap + 0xc00 / f); 3727 - } 3728 - 3729 3700 void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type) 3730 3701 { 3731 3702 struct vcpu_vmx *vmx = to_vmx(vcpu); ··· 5443 5494 u64 pcid; 5444 5495 u64 gla; 5445 5496 } operand; 5497 + int gpr_index; 5446 5498 5447 5499 if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID)) { 5448 5500 kvm_queue_exception(vcpu, UD_VECTOR); ··· 5451 5501 } 5452 5502 5453 5503 vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); 5454 - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); 5455 - 5456 - if (type > 3) { 5457 - kvm_inject_gp(vcpu, 0); 5458 - return 1; 5459 - } 5504 + gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); 5505 + type = kvm_register_read(vcpu, gpr_index); 5460 5506 5461 5507 /* According to the Intel instruction reference, the memory operand 5462 5508 * is read even if it isn't needed (e.g., for type==all) ··· 6695 6749 * If the L02 MSR bitmap does not intercept the MSR, then we need to 6696 6750 * save it. 6697 6751 */ 6698 - if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))) 6752 + if (unlikely(!msr_write_intercepted(vmx, MSR_IA32_SPEC_CTRL))) 6699 6753 vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL); 6700 6754 6701 6755 x86_spec_ctrl_restore_host(vmx->spec_ctrl, 0); ··· 7509 7563 static bool vmx_check_apicv_inhibit_reasons(ulong bit) 7510 7564 { 7511 7565 ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) | 7512 - BIT(APICV_INHIBIT_REASON_HYPERV); 7566 + BIT(APICV_INHIBIT_REASON_HYPERV) | 7567 + BIT(APICV_INHIBIT_REASON_BLOCKIRQ); 7513 7568 7514 7569 return supported & BIT(bit); 7515 7570 }
+33
arch/x86/kvm/vmx/vmx.h
··· 400 400 401 401 void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu); 402 402 403 + /* 404 + * Note, early Intel manuals have the write-low and read-high bitmap offsets 405 + * the wrong way round. The bitmaps control MSRs 0x00000000-0x00001fff and 406 + * 0xc0000000-0xc0001fff. The former (low) uses bytes 0-0x3ff for reads and 407 + * 0x800-0xbff for writes. The latter (high) uses 0x400-0x7ff for reads and 408 + * 0xc00-0xfff for writes. MSRs not covered by either of the ranges always 409 + * VM-Exit. 410 + */ 411 + #define __BUILD_VMX_MSR_BITMAP_HELPER(rtype, action, bitop, access, base) \ 412 + static inline rtype vmx_##action##_msr_bitmap_##access(unsigned long *bitmap, \ 413 + u32 msr) \ 414 + { \ 415 + int f = sizeof(unsigned long); \ 416 + \ 417 + if (msr <= 0x1fff) \ 418 + return bitop##_bit(msr, bitmap + base / f); \ 419 + else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) \ 420 + return bitop##_bit(msr & 0x1fff, bitmap + (base + 0x400) / f); \ 421 + return (rtype)true; \ 422 + } 423 + #define BUILD_VMX_MSR_BITMAP_HELPERS(ret_type, action, bitop) \ 424 + __BUILD_VMX_MSR_BITMAP_HELPER(ret_type, action, bitop, read, 0x0) \ 425 + __BUILD_VMX_MSR_BITMAP_HELPER(ret_type, action, bitop, write, 0x800) 426 + 427 + BUILD_VMX_MSR_BITMAP_HELPERS(bool, test, test) 428 + BUILD_VMX_MSR_BITMAP_HELPERS(void, clear, __clear) 429 + BUILD_VMX_MSR_BITMAP_HELPERS(void, set, __set) 430 + 403 431 static inline u8 vmx_get_rvi(void) 404 432 { 405 433 return vmcs_read16(GUEST_INTR_STATUS) & 0xff; ··· 549 521 } 550 522 551 523 void dump_vmcs(struct kvm_vcpu *vcpu); 524 + 525 + static inline int vmx_get_instr_info_reg2(u32 vmx_instr_info) 526 + { 527 + return (vmx_instr_info >> 28) & 0xf; 528 + } 552 529 553 530 #endif /* __KVM_X86_VMX_H */
+102 -34
arch/x86/kvm/x86.c
··· 3260 3260 3261 3261 static void record_steal_time(struct kvm_vcpu *vcpu) 3262 3262 { 3263 - struct kvm_host_map map; 3264 - struct kvm_steal_time *st; 3263 + struct gfn_to_hva_cache *ghc = &vcpu->arch.st.cache; 3264 + struct kvm_steal_time __user *st; 3265 + struct kvm_memslots *slots; 3266 + u64 steal; 3267 + u32 version; 3265 3268 3266 3269 if (kvm_xen_msr_enabled(vcpu->kvm)) { 3267 3270 kvm_xen_runstate_set_running(vcpu); ··· 3274 3271 if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) 3275 3272 return; 3276 3273 3277 - /* -EAGAIN is returned in atomic context so we can just return. */ 3278 - if (kvm_map_gfn(vcpu, vcpu->arch.st.msr_val >> PAGE_SHIFT, 3279 - &map, &vcpu->arch.st.cache, false)) 3274 + if (WARN_ON_ONCE(current->mm != vcpu->kvm->mm)) 3280 3275 return; 3281 3276 3282 - st = map.hva + 3283 - offset_in_page(vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS); 3277 + slots = kvm_memslots(vcpu->kvm); 3278 + 3279 + if (unlikely(slots->generation != ghc->generation || 3280 + kvm_is_error_hva(ghc->hva) || !ghc->memslot)) { 3281 + gfn_t gfn = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS; 3282 + 3283 + /* We rely on the fact that it fits in a single page. */ 3284 + BUILD_BUG_ON((sizeof(*st) - 1) & KVM_STEAL_VALID_BITS); 3285 + 3286 + if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gfn, sizeof(*st)) || 3287 + kvm_is_error_hva(ghc->hva) || !ghc->memslot) 3288 + return; 3289 + } 3290 + 3291 + st = (struct kvm_steal_time __user *)ghc->hva; 3292 + if (!user_access_begin(st, sizeof(*st))) 3293 + return; 3284 3294 3285 3295 /* 3286 3296 * Doing a TLB flush here, on the guest's behalf, can avoid 3287 3297 * expensive IPIs. 3288 3298 */ 3289 3299 if (guest_pv_has(vcpu, KVM_FEATURE_PV_TLB_FLUSH)) { 3290 - u8 st_preempted = xchg(&st->preempted, 0); 3300 + u8 st_preempted = 0; 3301 + int err = -EFAULT; 3302 + 3303 + asm volatile("1: xchgb %0, %2\n" 3304 + "xor %1, %1\n" 3305 + "2:\n" 3306 + _ASM_EXTABLE_UA(1b, 2b) 3307 + : "+r" (st_preempted), 3308 + "+&r" (err) 3309 + : "m" (st->preempted)); 3310 + if (err) 3311 + goto out; 3312 + 3313 + user_access_end(); 3314 + 3315 + vcpu->arch.st.preempted = 0; 3291 3316 3292 3317 trace_kvm_pv_tlb_flush(vcpu->vcpu_id, 3293 3318 st_preempted & KVM_VCPU_FLUSH_TLB); 3294 3319 if (st_preempted & KVM_VCPU_FLUSH_TLB) 3295 3320 kvm_vcpu_flush_tlb_guest(vcpu); 3321 + 3322 + if (!user_access_begin(st, sizeof(*st))) 3323 + goto dirty; 3296 3324 } else { 3297 - st->preempted = 0; 3325 + unsafe_put_user(0, &st->preempted, out); 3326 + vcpu->arch.st.preempted = 0; 3298 3327 } 3299 3328 3300 - vcpu->arch.st.preempted = 0; 3329 + unsafe_get_user(version, &st->version, out); 3330 + if (version & 1) 3331 + version += 1; /* first time write, random junk */ 3301 3332 3302 - if (st->version & 1) 3303 - st->version += 1; /* first time write, random junk */ 3304 - 3305 - st->version += 1; 3333 + version += 1; 3334 + unsafe_put_user(version, &st->version, out); 3306 3335 3307 3336 smp_wmb(); 3308 3337 3309 - st->steal += current->sched_info.run_delay - 3338 + unsafe_get_user(steal, &st->steal, out); 3339 + steal += current->sched_info.run_delay - 3310 3340 vcpu->arch.st.last_steal; 3311 3341 vcpu->arch.st.last_steal = current->sched_info.run_delay; 3342 + unsafe_put_user(steal, &st->steal, out); 3312 3343 3313 - smp_wmb(); 3344 + version += 1; 3345 + unsafe_put_user(version, &st->version, out); 3314 3346 3315 - st->version += 1; 3316 - 3317 - kvm_unmap_gfn(vcpu, &map, &vcpu->arch.st.cache, true, false); 3347 + out: 3348 + user_access_end(); 3349 + dirty: 3350 + mark_page_dirty_in_slot(vcpu->kvm, ghc->memslot, gpa_to_gfn(ghc->gpa)); 3318 3351 } 3319 3352 3320 3353 int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ··· 3556 3517 if (!guest_pv_has(vcpu, KVM_FEATURE_PV_EOI)) 3557 3518 return 1; 3558 3519 3559 - if (kvm_lapic_enable_pv_eoi(vcpu, data, sizeof(u8))) 3520 + if (kvm_lapic_set_pv_eoi(vcpu, data, sizeof(u8))) 3560 3521 return 1; 3561 3522 break; 3562 3523 ··· 4176 4137 r = !static_call(kvm_x86_cpu_has_accelerated_tpr)(); 4177 4138 break; 4178 4139 case KVM_CAP_NR_VCPUS: 4179 - r = KVM_SOFT_MAX_VCPUS; 4140 + r = num_online_cpus(); 4180 4141 break; 4181 4142 case KVM_CAP_MAX_VCPUS: 4182 4143 r = KVM_MAX_VCPUS; ··· 4390 4351 4391 4352 static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu) 4392 4353 { 4393 - struct kvm_host_map map; 4394 - struct kvm_steal_time *st; 4354 + struct gfn_to_hva_cache *ghc = &vcpu->arch.st.cache; 4355 + struct kvm_steal_time __user *st; 4356 + struct kvm_memslots *slots; 4357 + static const u8 preempted = KVM_VCPU_PREEMPTED; 4395 4358 4396 4359 if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) 4397 4360 return; ··· 4401 4360 if (vcpu->arch.st.preempted) 4402 4361 return; 4403 4362 4404 - if (kvm_map_gfn(vcpu, vcpu->arch.st.msr_val >> PAGE_SHIFT, &map, 4405 - &vcpu->arch.st.cache, true)) 4363 + /* This happens on process exit */ 4364 + if (unlikely(current->mm != vcpu->kvm->mm)) 4406 4365 return; 4407 4366 4408 - st = map.hva + 4409 - offset_in_page(vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS); 4367 + slots = kvm_memslots(vcpu->kvm); 4410 4368 4411 - st->preempted = vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED; 4369 + if (unlikely(slots->generation != ghc->generation || 4370 + kvm_is_error_hva(ghc->hva) || !ghc->memslot)) 4371 + return; 4412 4372 4413 - kvm_unmap_gfn(vcpu, &map, &vcpu->arch.st.cache, true, true); 4373 + st = (struct kvm_steal_time __user *)ghc->hva; 4374 + BUILD_BUG_ON(sizeof(st->preempted) != sizeof(preempted)); 4375 + 4376 + if (!copy_to_user_nofault(&st->preempted, &preempted, sizeof(preempted))) 4377 + vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED; 4378 + 4379 + mark_page_dirty_in_slot(vcpu->kvm, ghc->memslot, gpa_to_gfn(ghc->gpa)); 4414 4380 } 4415 4381 4416 4382 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) ··· 7382 7334 static int emulator_check_pmc(struct x86_emulate_ctxt *ctxt, 7383 7335 u32 pmc) 7384 7336 { 7385 - return kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc); 7337 + if (kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc)) 7338 + return 0; 7339 + return -EINVAL; 7386 7340 } 7387 7341 7388 7342 static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt, ··· 10620 10570 return ret; 10621 10571 } 10622 10572 10573 + static void kvm_arch_vcpu_guestdbg_update_apicv_inhibit(struct kvm *kvm) 10574 + { 10575 + bool inhibit = false; 10576 + struct kvm_vcpu *vcpu; 10577 + int i; 10578 + 10579 + down_write(&kvm->arch.apicv_update_lock); 10580 + 10581 + kvm_for_each_vcpu(i, vcpu, kvm) { 10582 + if (vcpu->guest_debug & KVM_GUESTDBG_BLOCKIRQ) { 10583 + inhibit = true; 10584 + break; 10585 + } 10586 + } 10587 + __kvm_request_apicv_update(kvm, !inhibit, APICV_INHIBIT_REASON_BLOCKIRQ); 10588 + up_write(&kvm->arch.apicv_update_lock); 10589 + } 10590 + 10623 10591 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 10624 10592 struct kvm_guest_debug *dbg) 10625 10593 { ··· 10689 10621 kvm_set_rflags(vcpu, rflags); 10690 10622 10691 10623 static_call(kvm_x86_update_exception_bitmap)(vcpu); 10624 + 10625 + kvm_arch_vcpu_guestdbg_update_apicv_inhibit(vcpu->kvm); 10692 10626 10693 10627 r = 0; 10694 10628 ··· 10935 10865 10936 10866 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) 10937 10867 { 10938 - struct gfn_to_pfn_cache *cache = &vcpu->arch.st.cache; 10939 10868 int idx; 10940 - 10941 - kvm_release_pfn(cache->pfn, cache->dirty, cache); 10942 10869 10943 10870 kvmclock_reset(vcpu); 10944 10871 ··· 12348 12281 return kvm_skip_emulated_instruction(vcpu); 12349 12282 12350 12283 default: 12351 - BUG(); /* We have already checked above that type <= 3 */ 12284 + kvm_inject_gp(vcpu, 0); 12285 + return 1; 12352 12286 } 12353 12287 } 12354 12288 EXPORT_SYMBOL_GPL(kvm_handle_invpcid);