kvm,x86: Fix apf_task_wake_one() wq serialization
authorDavidlohr Bueso <dave@stgolabs.net>
Wed, 13 Sep 2017 20:08:21 +0000 (13:08 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 15 Sep 2017 14:57:12 +0000 (16:57 +0200)
During code inspection, the following potential race was seen:

CPU0                    CPU1
kvm_async_pf_task_wait apf_task_wake_one
  [L] swait_active(&n->wq)
  [S] prepare_to_swait(&n.wq)
  [L] if (!hlist_unhahed(&n.link))
schedule()   [S] hlist_del_init(&n->link);

Properly serialize swait_active() checks such that a wakeup is
not missed.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kernel/kvm.c

index 874827b0d7ca2e3a0f79d40ee7c2b9e84e9bb583..aa60a08b65b1090392b542ec7dc642e9827b7606 100644 (file)
@@ -180,7 +180,7 @@ static void apf_task_wake_one(struct kvm_task_sleep_node *n)
        hlist_del_init(&n->link);
        if (n->halted)
                smp_send_reschedule(n->cpu);
-       else if (swait_active(&n->wq))
+       else if (swq_has_sleeper(&n->wq))
                swake_up(&n->wq);
 }