Commit 41c22f62 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Paolo Bonzini

KVM: async_pf: mm->mm_users can not pin apf->mm

get_user_pages(mm) is simply wrong if mm->mm_users == 0 and exit_mmap/etc
was already called (or is in progress), mm->mm_count can only pin mm->pgd
and mm_struct itself.

Change kvm_setup_async_pf/async_pf_execute to inc/dec mm->mm_users.

kvm_create_vm/kvm_destroy_vm play with ->mm_count too but this case looks
fine at first glance, it seems that this ->mm is only used to verify that
current->mm == kvm->mm.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5c8818b4
...@@ -101,7 +101,7 @@ static void async_pf_execute(struct work_struct *work) ...@@ -101,7 +101,7 @@ static void async_pf_execute(struct work_struct *work)
if (waitqueue_active(&vcpu->wq)) if (waitqueue_active(&vcpu->wq))
wake_up_interruptible(&vcpu->wq); wake_up_interruptible(&vcpu->wq);
mmdrop(mm); mmput(mm);
kvm_put_kvm(vcpu->kvm); kvm_put_kvm(vcpu->kvm);
} }
...@@ -118,7 +118,7 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) ...@@ -118,7 +118,7 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)
flush_work(&work->work); flush_work(&work->work);
#else #else
if (cancel_work_sync(&work->work)) { if (cancel_work_sync(&work->work)) {
mmdrop(work->mm); mmput(work->mm);
kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */ kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */
kmem_cache_free(async_pf_cache, work); kmem_cache_free(async_pf_cache, work);
} }
...@@ -183,7 +183,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva, ...@@ -183,7 +183,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,
work->addr = hva; work->addr = hva;
work->arch = *arch; work->arch = *arch;
work->mm = current->mm; work->mm = current->mm;
atomic_inc(&work->mm->mm_count); atomic_inc(&work->mm->mm_users);
kvm_get_kvm(work->vcpu->kvm); kvm_get_kvm(work->vcpu->kvm);
/* this can't really happen otherwise gfn_to_pfn_async /* this can't really happen otherwise gfn_to_pfn_async
...@@ -201,7 +201,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva, ...@@ -201,7 +201,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,
return 1; return 1;
retry_sync: retry_sync:
kvm_put_kvm(work->vcpu->kvm); kvm_put_kvm(work->vcpu->kvm);
mmdrop(work->mm); mmput(work->mm);
kmem_cache_free(async_pf_cache, work); kmem_cache_free(async_pf_cache, work);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment