Pull kvm fixes from Paolo Bonzini: - PAE and PKU bugfixes for x86 - selftests fix for new binutils - MMU notifier fix for arm64 * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: arm64: Only reschedule if MMU_NOTIFIER_RANGE_BLOCKABLE is not set KVM: Pass MMU notifier range flags to kvm_unmap_hva_range() kvm: x86: Toggling CR4.PKE does not load PDPTEs in PAE mode kvm: x86: Toggling CR4.SMAP does not load PDPTEs in PAE mode KVM: x86: fix access code passed to gva_to_gpa selftests: kvm: Use a shorter encoding to clear RAX
Unified · Split
| @@ -473,7 +473,7 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, · 472 unmodified lines | |||
| 473 | 473 | ||
| 474 | #define KVM_ARCH_WANT_MMU_NOTIFIER | 474 | #define KVM_ARCH_WANT_MMU_NOTIFIER |
| 475 | int kvm_unmap_hva_range(struct kvm *kvm, | 475 | int kvm_unmap_hva_range(struct kvm *kvm, |
| 476 | unsigned long start, unsigned long end); | 476 | unsigned long start, unsigned long end, unsigned flags); |
| 477 | int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); | 477 | int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); |
| 478 | int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); | 478 | int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); |
| 479 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); | 479 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); |
| @@ -343,7 +343,8 @@ static void unmap_stage2_p4ds(struct kvm_s2_mmu *mmu, pgd_t *pgd, · 342 unmodified lines | |||
| 343 | * destroying the VM), otherwise another faulting VCPU may come in and mess | 343 | * destroying the VM), otherwise another faulting VCPU may come in and mess |
| 344 | * with things behind our backs. | 344 | * with things behind our backs. |
| 345 | */ | 345 | */ |
| 346 | static void unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 size) | 346 | static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 size, |
| 347 | bool may_block) | ||
| 347 | { | 348 | { |
| 348 | struct kvm *kvm = mmu->kvm; | 349 | struct kvm *kvm = mmu->kvm; |
| 349 | pgd_t *pgd; | 350 | pgd_t *pgd; |
| @@ -369,11 +370,16 @@ static void unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 si · 19 unmodified lines | |||
| 369 | * If the range is too large, release the kvm->mmu_lock | 370 | * If the range is too large, release the kvm->mmu_lock |
| 370 | * to prevent starvation and lockup detector warnings. | 371 | * to prevent starvation and lockup detector warnings. |
| 371 | */ | 372 | */ |
| 372 | if (next != end) | 373 | if (may_block && next != end) |
| 373 | cond_resched_lock(&kvm->mmu_lock); | 374 | cond_resched_lock(&kvm->mmu_lock); |
| 374 | } while (pgd++, addr = next, addr != end); | 375 | } while (pgd++, addr = next, addr != end); |
| 375 | } | 376 | } |
| 376 | 377 | ||
| 378 | static void unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 size) | ||
| 379 | { | ||
| 380 | __unmap_stage2_range(mmu, start, size, true); | ||
| 381 | } | ||
| 382 | |||
| 377 | static void stage2_flush_ptes(struct kvm_s2_mmu *mmu, pmd_t *pmd, | 383 | static void stage2_flush_ptes(struct kvm_s2_mmu *mmu, pmd_t *pmd, |
| 378 | phys_addr_t addr, phys_addr_t end) | 384 | phys_addr_t addr, phys_addr_t end) |
| 379 | { | 385 | { |
| @@ -2208,18 +2214,21 @@ static int handle_hva_to_gpa(struct kvm *kvm, · 1828 unmodified lines | |||
| 2208 | 2214 | ||
| 2209 | static int kvm_unmap_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data) | 2215 | static int kvm_unmap_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data) |
| 2210 | { | 2216 | { |
| 2211 | unmap_stage2_range(&kvm->arch.mmu, gpa, size); | 2217 | unsigned flags = *(unsigned *)data; |
| 2218 | bool may_block = flags & MMU_NOTIFIER_RANGE_BLOCKABLE; | ||
| 2219 | |||
| 2220 | __unmap_stage2_range(&kvm->arch.mmu, gpa, size, may_block); | ||
| 2212 | return 0; | 2221 | return 0; |
| 2213 | } | 2222 | } |
| 2214 | 2223 | ||
| 2215 | int kvm_unmap_hva_range(struct kvm *kvm, | 2224 | int kvm_unmap_hva_range(struct kvm *kvm, |
| 2216 | unsigned long start, unsigned long end) | 2225 | unsigned long start, unsigned long end, unsigned flags) |
| 2217 | { | 2226 | { |
| 2218 | if (!kvm->arch.mmu.pgd) | 2227 | if (!kvm->arch.mmu.pgd) |
| 2219 | return 0; | 2228 | return 0; |
| 2220 | 2229 | ||
| 2221 | trace_kvm_unmap_hva_range(start, end); | 2230 | trace_kvm_unmap_hva_range(start, end); |
| 2222 | handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL); | 2231 | handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, &flags); |
| 2223 | return 0; | 2232 | return 0; |
| 2224 | } | 2233 | } |
| 2225 | 2234 | ||
| @@ -969,7 +969,7 @@ enum kvm_mips_fault_result kvm_trap_emul_gva_fault(struct kvm_vcpu *vcpu, · 968 unmodified lines | |||
| 969 | 969 | ||
| 970 | #define KVM_ARCH_WANT_MMU_NOTIFIER | 970 | #define KVM_ARCH_WANT_MMU_NOTIFIER |
| 971 | int kvm_unmap_hva_range(struct kvm *kvm, | 971 | int kvm_unmap_hva_range(struct kvm *kvm, |
| 972 | unsigned long start, unsigned long end); | 972 | unsigned long start, unsigned long end, unsigned flags); |
| 973 | int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); | 973 | int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); |
| 974 | int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); | 974 | int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); |
| 975 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); | 975 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); |
| @@ -486,7 +486,8 @@ static int kvm_unmap_hva_handler(struct kvm *kvm, gfn_t gfn, gfn_t gfn_end, · 485 unmodified lines | |||
| 486 | return 1; | 486 | return 1; |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) | 489 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, |
| 490 | unsigned flags) | ||
| 490 | { | 491 | { |
| 491 | handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL); | 492 | handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL); |
| 492 | 493 | ||
| @@ -58,7 +58,8 @@ · 57 unmodified lines | |||
| 58 | #define KVM_ARCH_WANT_MMU_NOTIFIER | 58 | #define KVM_ARCH_WANT_MMU_NOTIFIER |
| 59 | 59 | ||
| 60 | extern int kvm_unmap_hva_range(struct kvm *kvm, | 60 | extern int kvm_unmap_hva_range(struct kvm *kvm, |
| 61 | unsigned long start, unsigned long end); | 61 | unsigned long start, unsigned long end, |
| 62 | unsigned flags); | ||
| 62 | extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); | 63 | extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); |
| 63 | extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); | 64 | extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); |
| 64 | extern int 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); |
| @@ -834,7 +834,8 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm, · 833 unmodified lines | |||
| 834 | kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new, change); | 834 | kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new, change); |
| 835 | } | 835 | } |
| 836 | 836 | ||
| 837 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) | 837 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, |
| 838 | unsigned flags) | ||
| 838 | { | 839 | { |
| 839 | return kvm->arch.kvm_ops->unmap_hva_range(kvm, start, end); | 840 | return kvm->arch.kvm_ops->unmap_hva_range(kvm, start, end); |
| 840 | } | 841 | } |
| @@ -734,7 +734,8 @@ static int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) · 733 unmodified lines | |||
| 734 | return 0; | 734 | return 0; |
| 735 | } | 735 | } |
| 736 | 736 | ||
| 737 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) | 737 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, |
| 738 | unsigned flags) | ||
| 738 | { | 739 | { |
| 739 | /* kvm_unmap_hva flushes everything anyways */ | 740 | /* kvm_unmap_hva flushes everything anyways */ |
| 740 | kvm_unmap_hva(kvm, start); | 741 | kvm_unmap_hva(kvm, start); |
| @@ -1596,7 +1596,8 @@ asmlinkage void kvm_spurious_fault(void); · 1595 unmodified lines | |||
| 1596 | _ASM_EXTABLE(666b, 667b) | 1596 | _ASM_EXTABLE(666b, 667b) |
| 1597 | 1597 | ||
| 1598 | #define KVM_ARCH_WANT_MMU_NOTIFIER | 1598 | #define KVM_ARCH_WANT_MMU_NOTIFIER |
| 1599 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); | 1599 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, |
| 1600 | unsigned flags); | ||
| 1600 | int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); | 1601 | int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); |
| 1601 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); | 1602 | int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); |
| 1602 | int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); | 1603 | int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); |
| @@ -1916,7 +1916,8 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva, · 1915 unmodified lines | |||
| 1916 | return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler); | 1916 | return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler); |
| 1917 | } | 1917 | } |
| 1918 | 1918 | ||
| 1919 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) | 1919 | int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end, |
| 1920 | unsigned flags) | ||
| 1920 | { | 1921 | { |
| 1921 | return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp); | 1922 | return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp); |
| 1922 | } | 1923 | } |
| @@ -975,7 +975,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) · 974 unmodified lines | |||
| 975 | { | 975 | { |
| 976 | unsigned long old_cr4 = kvm_read_cr4(vcpu); | 976 | unsigned long old_cr4 = kvm_read_cr4(vcpu); |
| 977 | unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE | | 977 | unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE | |
| 978 | X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE; | 978 | X86_CR4_SMEP; |
| 979 | 979 | ||
| 980 | if (kvm_valid_cr4(vcpu, cr4)) | 980 | if (kvm_valid_cr4(vcpu, cr4)) |
| 981 | return 1; | 981 | return 1; |
| @@ -10751,9 +10751,11 @@ EXPORT_SYMBOL_GPL(kvm_spec_ctrl_test_value); · 9769 unmodified lines | |||
| 10751 | void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_code) | 10751 | void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_code) |
| 10752 | { | 10752 | { |
| 10753 | struct x86_exception fault; | 10753 | struct x86_exception fault; |
| 10754 | u32 access = error_code & | ||
| 10755 | (PFERR_WRITE_MASK | PFERR_FETCH_MASK | PFERR_USER_MASK); | ||
| 10754 | 10756 | ||
| 10755 | if (!(error_code & PFERR_PRESENT_MASK) || | 10757 | if (!(error_code & PFERR_PRESENT_MASK) || |
| 10756 | vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, error_code, &fault) != UNMAPPED_GVA) { | 10758 | vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, &fault) != UNMAPPED_GVA) { |
| 10757 | /* | 10759 | /* |
| 10758 | * If vcpu->arch.walk_mmu->gva_to_gpa succeeded, the page | 10760 | * If vcpu->arch.walk_mmu->gva_to_gpa succeeded, the page |
| 10759 | * tables probably do not match the TLB. Just proceed | 10761 | * tables probably do not match the TLB. Just proceed |
| @@ -40,11 +40,11 @@ static void guest_code(void) · 39 unmodified lines | |||
| 40 | 40 | ||
| 41 | /* Single step test, covers 2 basic instructions and 2 emulated */ | 41 | /* Single step test, covers 2 basic instructions and 2 emulated */ |
| 42 | asm volatile("ss_start: " | 42 | asm volatile("ss_start: " |
| 43 | "xor %%rax,%%rax\n\t" | 43 | "xor %%eax,%%eax\n\t" |
| 44 | "cpuid\n\t" | 44 | "cpuid\n\t" |
| 45 | "movl $0x1a0,%%ecx\n\t" | 45 | "movl $0x1a0,%%ecx\n\t" |
| 46 | "rdmsr\n\t" | 46 | "rdmsr\n\t" |
| 47 | : : : "rax", "ecx"); | 47 | : : : "eax", "ebx", "ecx", "edx"); |
| 48 | 48 | ||
| 49 | /* DR6.BD test */ | 49 | /* DR6.BD test */ |
| 50 | asm volatile("bd_start: mov %%dr0, %%rax" : : : "rax"); | 50 | asm volatile("bd_start: mov %%dr0, %%rax" : : : "rax"); |
| @@ -482,7 +482,8 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, · 481 unmodified lines | |||
| 482 | * count is also read inside the mmu_lock critical section. | 482 | * count is also read inside the mmu_lock critical section. |
| 483 | */ | 483 | */ |
| 484 | kvm->mmu_notifier_count++; | 484 | kvm->mmu_notifier_count++; |
| 485 | need_tlb_flush = kvm_unmap_hva_range(kvm, range->start, range->end); | 485 | need_tlb_flush = kvm_unmap_hva_range(kvm, range->start, range->end, |
| 486 | range->flags); | ||
| 486 | need_tlb_flush |= kvm->tlbs_dirty; | 487 | need_tlb_flush |= kvm->tlbs_dirty; |
| 487 | /* we've to flush the tlb before the pages can be freed */ | 488 | /* we've to flush the tlb before the pages can be freed */ |
| 488 | if (need_tlb_flush) | 489 | if (need_tlb_flush) |