From: Paolo Bonzini <pbonzini@redhat.com>
To: Kosuke Tatsukawa <tatsu@ab.jp.nec.com>, Gleb Natapov <gleb@kernel.org>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c
Date: Fri, 9 Oct 2015 10:45:32 +0200 [thread overview]
Message-ID: <56177EAC.2070601@redhat.com> (raw)
In-Reply-To: <17EC94B0A072C34B8DCF0D30AD16044A028747C1@BPXM09GP.gisp.nec.co.jp>
On 09/10/2015 02:35, Kosuke Tatsukawa wrote:
> 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)
> ...
The new memory barrier isn't "paired" with any other, and in
fact I think that the same issue exists on the other side:
list_empty_careful(&vcpu->async_pf.done) may be reordered up,
before the prepare_to_wait:
spin_lock(&vcpu->async_pf.lock);
(vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE &&
!vcpu->arch.apf.halted)
|| !list_empty_careful(&vcpu->async_pf.done)
...
prepare_to_wait(&vcpu->wq, &wait,
TASK_INTERRUPTIBLE);
/*if (kvm_vcpu_check_block(vcpu) < 0) */
/*if (kvm_arch_vcpu_runnable(vcpu)) { */
...
return 0;
list_add_tail(&apf->link,
&vcpu->async_pf.done);
spin_unlock(&vcpu->async_pf.lock);
waited = true;
schedule();
if (waitqueue_active(&vcpu->wq))
So you need another smp_mb() after prepare_to_wait(). I'm not sure
if it's needed also for your original tty report, but I think it is
for https://lkml.org/lkml/2015/10/8/989 ("mei: fix waitqueue_active
without memory barrier in mei drivers").
I wonder if it makes sense to introduce smp_mb__before_spin_lock()
and smp_mb__after_spin_unlock(). On x86 the former could be a
simple compiler barrier, and on s390 both of them could. But that
should be a separate patch.
Thanks,
Paolo
next prev parent reply other threads:[~2015-10-09 8:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-09 0:35 [PATCH] kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c Kosuke Tatsukawa
2015-10-09 8:45 ` Paolo Bonzini [this message]
2015-10-09 8:50 ` Peter Zijlstra
2015-10-09 10:24 ` Paolo Bonzini
2015-10-09 9:04 ` Kosuke Tatsukawa
2015-10-09 10:26 ` Paolo Bonzini
2015-10-09 12:21 ` Kosuke Tatsukawa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56177EAC.2070601@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tatsu@ab.jp.nec.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.