From: Paolo Bonzini <pbonzini@redhat.com>
To: Davidlohr Bueso <dave@stgolabs.net>,
mingo@redhat.com, peterz@infradead.org
Cc: npiggin@gmail.com, paulmck@linux.vnet.ibm.com,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH 4/6] x86,kvm: Fix apf_task_wake_one() serialization
Date: Sun, 10 Sep 2017 11:20:40 +0200 [thread overview]
Message-ID: <c3f126ad-4248-69a7-4b31-141c39f66988@redhat.com> (raw)
In-Reply-To: <20170905190022.1474-5-dave@stgolabs.net>
On 05/09/2017 21:00, Davidlohr Bueso wrote:
> During code inspection, the following potential race was seen:
>
> CPU0 CPU1
> kvm_async_pf_task_wait apf_task_wake_one
> [S] prepare_to_swait(&n.wq)
> [L] swait_active(&n->wq)
> [S] hlist_del_init(&n->link);
> [L] if (!hlist_unhahed(&n.link))
> schedule()
>
> Properly serialize swait_active() checks such that a wakeup is
> not missed.
>
> Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
> ---
> arch/x86/kernel/kvm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 874827b0d7ca..aa60a08b65b1 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -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);
> }
After Nick's patch, swake_up starts with:
smp_mb();
if (!swait_active(q))
return;
so we can just remove the test here (and in patch 2).
The other patches could also use a better swait API, for example:
1) add a public __swake_up routine that omits the memory barrier, and
which can be used in patch 3. Perhaps better: omit the out-of-lock
check in __swake_up: then the caller can use it if it knows there is a
waiter. In those cases the memory barrier is expensive.
2) change swake_up and __swake_up to return true if they woke up a
process (or alternatively 0/-EAGAIN). Patches 5 and 6 now need not call
anymore either swq_has_sleepers or swait_active, and that saves a memory
barrier too.
What do you think?
Thanks,
Paolo
next prev parent reply other threads:[~2017-09-10 9:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-05 19:00 [PATCH 0/6] swait: Introduce and use swq_has_sleepers Davidlohr Bueso
2017-09-05 19:00 ` [PATCH 1/6] sched/wait: Add swq_has_sleepers() Davidlohr Bueso
2017-10-11 8:27 ` Peter Zijlstra
2017-10-11 11:21 ` Paolo Bonzini
2017-10-11 11:29 ` Peter Zijlstra
2017-09-05 19:00 ` [PATCH 2/6] kvm,async_pf: Use swq_has_sleepers() Davidlohr Bueso
2017-09-05 19:00 ` [PATCH 3/6] kvm,lapic: Justify use of swait_activate() Davidlohr Bueso
2017-09-05 19:00 ` [PATCH 4/6] x86,kvm: Fix apf_task_wake_one() serialization Davidlohr Bueso
2017-09-10 9:20 ` Paolo Bonzini [this message]
2017-09-10 9:24 ` Paolo Bonzini
2017-10-12 8:23 ` Peter Zijlstra
2017-09-05 19:00 ` [PATCH 5/6] kvm: Serialize wq active checks in kvm_vcpu_wake_up() Davidlohr Bueso
2017-09-05 19:00 ` [PATCH 6/6] kvm,powerpc: Serialize wq active checks in ops->vcpu_kick Davidlohr Bueso
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=c3f126ad-4248-69a7-4b31-141c39f66988@redhat.com \
--to=pbonzini@redhat.com \
--cc=dave@stgolabs.net \
--cc=dbueso@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=npiggin@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®