Skip to content

Commit b2d9e99

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
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
2 parents 9e574b7 + b533137 commit b2d9e99

File tree

12 files changed

+36
-18
lines changed

12 files changed

+36
-18
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
473473

474474
#define KVM_ARCH_WANT_MMU_NOTIFIER
475475
int kvm_unmap_hva_range(struct kvm *kvm,
476-
unsigned long start, unsigned long end);
476+
unsigned long start, unsigned long end, unsigned flags);
477477
int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
478478
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
479479
int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);

arch/arm64/kvm/mmu.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ static void unmap_stage2_p4ds(struct kvm_s2_mmu *mmu, pgd_t *pgd,
343343
* destroying the VM), otherwise another faulting VCPU may come in and mess
344344
* with things behind our backs.
345345
*/
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)
347348
{
348349
struct kvm *kvm = mmu->kvm;
349350
pgd_t *pgd;
@@ -369,11 +370,16 @@ static void unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 si
369370
* If the range is too large, release the kvm->mmu_lock
370371
* to prevent starvation and lockup detector warnings.
371372
*/
372-
if (next != end)
373+
if (may_block && next != end)
373374
cond_resched_lock(&kvm->mmu_lock);
374375
} while (pgd++, addr = next, addr != end);
375376
}
376377

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+
377383
static void stage2_flush_ptes(struct kvm_s2_mmu *mmu, pmd_t *pmd,
378384
phys_addr_t addr, phys_addr_t end)
379385
{
@@ -2208,18 +2214,21 @@ static int handle_hva_to_gpa(struct kvm *kvm,
22082214

22092215
static int kvm_unmap_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void *data)
22102216
{
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);
22122221
return 0;
22132222
}
22142223

22152224
int kvm_unmap_hva_range(struct kvm *kvm,
2216-
unsigned long start, unsigned long end)
2225+
unsigned long start, unsigned long end, unsigned flags)
22172226
{
22182227
if (!kvm->arch.mmu.pgd)
22192228
return 0;
22202229

22212230
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);
22232232
return 0;
22242233
}
22252234

arch/mips/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ enum kvm_mips_fault_result kvm_trap_emul_gva_fault(struct kvm_vcpu *vcpu,
969969

970970
#define KVM_ARCH_WANT_MMU_NOTIFIER
971971
int kvm_unmap_hva_range(struct kvm *kvm,
972-
unsigned long start, unsigned long end);
972+
unsigned long start, unsigned long end, unsigned flags);
973973
int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
974974
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
975975
int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);

arch/mips/kvm/mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ static int kvm_unmap_hva_handler(struct kvm *kvm, gfn_t gfn, gfn_t gfn_end,
486486
return 1;
487487
}
488488

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)
490491
{
491492
handle_hva_to_gpa(kvm, start, end, &kvm_unmap_hva_handler, NULL);
492493

arch/powerpc/include/asm/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
#define KVM_ARCH_WANT_MMU_NOTIFIER
5959

6060
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);
6263
extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
6364
extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
6465
extern int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);

arch/powerpc/kvm/book3s.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm,
834834
kvm->arch.kvm_ops->commit_memory_region(kvm, mem, old, new, change);
835835
}
836836

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)
838839
{
839840
return kvm->arch.kvm_ops->unmap_hva_range(kvm, start, end);
840841
}

arch/powerpc/kvm/e500_mmu_host.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ static int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
734734
return 0;
735735
}
736736

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)
738739
{
739740
/* kvm_unmap_hva flushes everything anyways */
740741
kvm_unmap_hva(kvm, start);

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,8 @@ asmlinkage void kvm_spurious_fault(void);
15961596
_ASM_EXTABLE(666b, 667b)
15971597

15981598
#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);
16001601
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
16011602
int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
16021603
int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);

arch/x86/kvm/mmu/mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,8 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
19161916
return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler);
19171917
}
19181918

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)
19201921
{
19211922
return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp);
19221923
}

arch/x86/kvm/x86.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
975975
{
976976
unsigned long old_cr4 = kvm_read_cr4(vcpu);
977977
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;
979979

980980
if (kvm_valid_cr4(vcpu, cr4))
981981
return 1;
@@ -10751,9 +10751,11 @@ EXPORT_SYMBOL_GPL(kvm_spec_ctrl_test_value);
1075110751
void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_code)
1075210752
{
1075310753
struct x86_exception fault;
10754+
u32 access = error_code &
10755+
(PFERR_WRITE_MASK | PFERR_FETCH_MASK | PFERR_USER_MASK);
1075410756

1075510757
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) {
1075710759
/*
1075810760
* If vcpu->arch.walk_mmu->gva_to_gpa succeeded, the page
1075910761
* tables probably do not match the TLB. Just proceed

0 commit comments

Comments
 (0)