Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1242925
| From | Kosuke Tatsukawa <tatsu@ab.jp.nec.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c |
| Date | 2015-10-09 02:40 +0200 |
| Message-ID | <qhtT7-2Qh-83@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
async_pf_execute() seems to be missing a memory barrier which might
cause the waker to not notice the waiter and miss sending a wake_up as
in the following figure.
async_pf_execute kvm_vcpu_block
------------------------------------------------------------------------
spin_lock(&vcpu->async_pf.lock);
if (waitqueue_active(&vcpu->wq))
/* The CPU might reorder the test for
the waitqueue up here, before
prior writes complete */
prepare_to_wait(&vcpu->wq, &wait,
TASK_INTERRUPTIBLE);
/*if (kvm_vcpu_check_block(vcpu) < 0) */
/*if (kvm_arch_vcpu_runnable(vcpu)) { */
...
return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE &&
!vcpu->arch.apf.halted)
|| !list_empty_careful(&vcpu->async_pf.done)
...
return 0;
list_add_tail(&apf->link,
&vcpu->async_pf.done);
spin_unlock(&vcpu->async_pf.lock);
waited = true;
schedule();
------------------------------------------------------------------------
The attached patch adds the missing memory barrier.
I found this issue when I was looking through the linux source code
for places calling waitqueue_active() before wake_up*(), but without
preceding memory barriers, after sending a patch to fix a similar
issue in drivers/tty/n_tty.c (Details about the original issue can be
found here: https://lkml.org/lkml/2015/9/28/849).
Signed-off-by: Kosuke Tatsukawa <tatsu@ab.jp.nec.com>
---
virt/kvm/async_pf.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index 44660ae..303fc7f 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -94,6 +94,11 @@ static void async_pf_execute(struct work_struct *work)
trace_kvm_async_pf_completed(addr, gva);
+ /*
+ * Memory barrier is required here to make sure change to
+ * vcpu->async_pf.done is visible from other CPUs
+ */
+ smp_mb();
if (waitqueue_active(&vcpu->wq))
wake_up_interruptible(&vcpu->wq);
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Kosuke Tatsukawa <tatsu@ab.jp.nec.com> - 2015-10-09 02:40 +0200
Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Paolo Bonzini <pbonzini@redhat.com> - 2015-10-09 10:50 +0200
Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Peter Zijlstra <peterz@infradead.org> - 2015-10-09 11:00 +0200
Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Paolo Bonzini <pbonzini@redhat.com> - 2015-10-09 12:30 +0200
Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Kosuke Tatsukawa <tatsu@ab.jp.nec.com> - 2015-10-09 11:10 +0200
Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Paolo Bonzini <pbonzini@redhat.com> - 2015-10-09 12:30 +0200
Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Kosuke Tatsukawa <tatsu@ab.jp.nec.com> - 2015-10-09 14:30 +0200
csiph-web