Skip to content

Commit 7863e34

Browse files
vittyvkbonzini
authored andcommitted
KVM: async_pf: Cleanup kvm_setup_async_pf()
schedule_work() returns 'false' only when the work is already on the queue and this can't happen as kvm_setup_async_pf() always allocates a new one. Also, to avoid potential race, it makes sense to to schedule_work() at the very end after we've added it to the queue. While on it, do some minor cleanup. gfn_to_pfn_async() mentioned in a comment does not currently exist and, moreover, we can check kvm_is_error_hva() at the very beginning, before we try to allocate work so 'retry_sync' label can go away completely. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Message-Id: <20200610175532.779793-1-vkuznets@redhat.com> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent cd18eae commit 7863e34

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

virt/kvm/async_pf.c

+6-13
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
164164
if (vcpu->async_pf.queued >= ASYNC_PF_PER_VCPU)
165165
return 0;
166166

167-
/* setup delayed work */
167+
/* Arch specific code should not do async PF in this case */
168+
if (unlikely(kvm_is_error_hva(hva)))
169+
return 0;
168170

169171
/*
170172
* do alloc nowait since if we are going to sleep anyway we
@@ -183,24 +185,15 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
183185
mmget(work->mm);
184186
kvm_get_kvm(work->vcpu->kvm);
185187

186-
/* this can't really happen otherwise gfn_to_pfn_async
187-
would succeed */
188-
if (unlikely(kvm_is_error_hva(work->addr)))
189-
goto retry_sync;
190-
191188
INIT_WORK(&work->work, async_pf_execute);
192-
if (!schedule_work(&work->work))
193-
goto retry_sync;
194189

195190
list_add_tail(&work->queue, &vcpu->async_pf.queue);
196191
vcpu->async_pf.queued++;
197192
kvm_arch_async_page_not_present(vcpu, work);
193+
194+
schedule_work(&work->work);
195+
198196
return 1;
199-
retry_sync:
200-
kvm_put_kvm(work->vcpu->kvm);
201-
mmput(work->mm);
202-
kmem_cache_free(async_pf_cache, work);
203-
return 0;
204197
}
205198

206199
int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)