diff options
author | Oleg Nesterov <oleg@redhat.com> | 2014-04-21 09:26:01 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-04-28 07:04:46 -0400 |
commit | 41c22f626254b9dc0376928cae009e73d1b6a49a (patch) | |
tree | 6c3318644f52be8cff8ddc91c12773465a394060 /virt/kvm | |
parent | 5c8818b46e067120d33bbb2f610313240d76ba02 (diff) |
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: Oleg Nesterov <oleg@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/async_pf.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c index 10df100c4514..06e6401d6ef4 100644 --- a/virt/kvm/async_pf.c +++ b/virt/kvm/async_pf.c | |||
@@ -101,7 +101,7 @@ static void async_pf_execute(struct work_struct *work) | |||
101 | if (waitqueue_active(&vcpu->wq)) | 101 | if (waitqueue_active(&vcpu->wq)) |
102 | wake_up_interruptible(&vcpu->wq); | 102 | wake_up_interruptible(&vcpu->wq); |
103 | 103 | ||
104 | mmdrop(mm); | 104 | mmput(mm); |
105 | kvm_put_kvm(vcpu->kvm); | 105 | kvm_put_kvm(vcpu->kvm); |
106 | } | 106 | } |
107 | 107 | ||
@@ -118,7 +118,7 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) | |||
118 | flush_work(&work->work); | 118 | flush_work(&work->work); |
119 | #else | 119 | #else |
120 | if (cancel_work_sync(&work->work)) { | 120 | if (cancel_work_sync(&work->work)) { |
121 | mmdrop(work->mm); | 121 | mmput(work->mm); |
122 | kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */ | 122 | kvm_put_kvm(vcpu->kvm); /* == work->vcpu->kvm */ |
123 | kmem_cache_free(async_pf_cache, work); | 123 | kmem_cache_free(async_pf_cache, work); |
124 | } | 124 | } |
@@ -183,7 +183,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva, | |||
183 | work->addr = hva; | 183 | work->addr = hva; |
184 | work->arch = *arch; | 184 | work->arch = *arch; |
185 | work->mm = current->mm; | 185 | work->mm = current->mm; |
186 | atomic_inc(&work->mm->mm_count); | 186 | atomic_inc(&work->mm->mm_users); |
187 | kvm_get_kvm(work->vcpu->kvm); | 187 | kvm_get_kvm(work->vcpu->kvm); |
188 | 188 | ||
189 | /* this can't really happen otherwise gfn_to_pfn_async | 189 | /* 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 | return 1; | 201 | return 1; |
202 | retry_sync: | 202 | retry_sync: |
203 | kvm_put_kvm(work->vcpu->kvm); | 203 | kvm_put_kvm(work->vcpu->kvm); |
204 | mmdrop(work->mm); | 204 | mmput(work->mm); |
205 | kmem_cache_free(async_pf_cache, work); | 205 | kmem_cache_free(async_pf_cache, work); |
206 | return 0; | 206 | return 0; |
207 | } | 207 | } |