Skip to content

Commit

Permalink
KVM: fix the race while wakeup all pv guest
Browse files Browse the repository at this point in the history
In kvm_async_pf_wakeup_all(), we add a dummy apf to vcpu->async_pf.done
without holding vcpu->async_pf.lock, it will break if we are handling apfs
at this time.

Also use 'list_empty_careful()' instead of 'list_empty()'

Signed-off-by: Xiao Guangrong <[email protected]>
Acked-by: Gleb Natapov <[email protected]>
Signed-off-by: Marcelo Tosatti <[email protected]>
  • Loading branch information
Xiao Guangrong authored and avikivity committed Jan 12, 2011
1 parent 15096ff commit 64f638c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion virt/kvm/async_pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)
{
struct kvm_async_pf *work;

if (!list_empty(&vcpu->async_pf.done))
if (!list_empty_careful(&vcpu->async_pf.done))
return 0;

work = kmem_cache_zalloc(async_pf_cache, GFP_ATOMIC);
Expand All @@ -207,7 +207,10 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)
get_page(bad_page);
INIT_LIST_HEAD(&work->queue); /* for list_del to work */

spin_lock(&vcpu->async_pf.lock);
list_add_tail(&work->link, &vcpu->async_pf.done);
spin_unlock(&vcpu->async_pf.lock);

vcpu->async_pf.queued++;
return 0;
}

0 comments on commit 64f638c

Please sign in to comment.