Skip to content

Commit 35af577

Browse files
author
Gleb Natapov
committed
KVM: MMU: clenaup locking in mmu_free_roots()
Do locking around each case separately instead of having one lock and two unlocks. Move root_hpa assignment out of the lock. Signed-off-by: Gleb Natapov <gleb@redhat.com>
1 parent 0061d53 commit 35af577

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎arch/x86/kvm/mmu.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,22 +2869,25 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu)
28692869

28702870
if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
28712871
return;
2872-
spin_lock(&vcpu->kvm->mmu_lock);
2872+
28732873
if (vcpu->arch.mmu.shadow_root_level == PT64_ROOT_LEVEL &&
28742874
(vcpu->arch.mmu.root_level == PT64_ROOT_LEVEL ||
28752875
vcpu->arch.mmu.direct_map)) {
28762876
hpa_t root = vcpu->arch.mmu.root_hpa;
28772877

2878+
spin_lock(&vcpu->kvm->mmu_lock);
28782879
sp = page_header(root);
28792880
--sp->root_count;
28802881
if (!sp->root_count && sp->role.invalid) {
28812882
kvm_mmu_prepare_zap_page(vcpu->kvm, sp, &invalid_list);
28822883
kvm_mmu_commit_zap_page(vcpu->kvm, &invalid_list);
28832884
}
2884-
vcpu->arch.mmu.root_hpa = INVALID_PAGE;
28852885
spin_unlock(&vcpu->kvm->mmu_lock);
2886+
vcpu->arch.mmu.root_hpa = INVALID_PAGE;
28862887
return;
28872888
}
2889+
2890+
spin_lock(&vcpu->kvm->mmu_lock);
28882891
for (i = 0; i < 4; ++i) {
28892892
hpa_t root = vcpu->arch.mmu.pae_root[i];
28902893

0 commit comments

Comments
 (0)