From: "Suresh E. Warrier" <warrier@linux.vnet.ibm.com>
To: Alexander Graf <agraf@suse.de>, Paul Mackerras <paulus@samba.org>,
kvm-ppc@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 5/5] KVM: PPC: Book3S HV: Check wait conditions before sleeping in kvmppc_vcore_blocked
Date: Thu, 20 Nov 2014 19:31:24 +0000 [thread overview]
Message-ID: <546E418C.1080105@linux.vnet.ibm.com> (raw)
In-Reply-To: <546E26A8.1080904@suse.de>
On 11/20/2014 11:36 AM, Alexander Graf wrote:
>
>
> On 03.11.14 05:52, Paul Mackerras wrote:
>> From: "Suresh E. Warrier" <warrier@linux.vnet.ibm.com>
>>
>> The kvmppc_vcore_blocked() code does not check for the wait condition
>> after putting the process on the wait queue. This means that it is
>> possible for an external interrupt to become pending, but the vcpu to
>> remain asleep until the next decrementer interrupt. The fix is to
>> make one last check for pending exceptions and ceded state before
>> calling schedule().
>>
>> Signed-off-by: Suresh Warrier <warrier@linux.vnet.ibm.com>
>> Signed-off-by: Paul Mackerras <paulus@samba.org>
>
> I don't understand the race you're fixing here. Can you please explain it?
>
When a virtual interrupt needs to be delivered to the guest, and the
virtual ICS state for the interrupt and virtual ICP state for the VCPU
allow for the VCPU to be immediately interrupted, we
1. Set the BOOK3S_INTERRUPT_EXTERNAL_LEVEL bit in pending_exceptions.
2. Call kvmppc_fast_vcpu_kick_hv(), which checks the wait queue at vcpu->wq
to wake the VCPU up.
The caller of kvmppc_vcore_blocked() does the check for pending exceptions, but
there is a race condition here and we do need to check again after the VCPU
is put on the wait queue.
-suresh
>
> Alex
>
>> ---
>> arch/powerpc/kvm/book3s_hv.c | 20 ++++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>>
>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>> index cd7e030..1a7a281 100644
>> --- a/arch/powerpc/kvm/book3s_hv.c
>> +++ b/arch/powerpc/kvm/book3s_hv.c
>> @@ -1828,9 +1828,29 @@ static void kvmppc_wait_for_exec(struct kvm_vcpu *vcpu, int wait_state)
>> */
>> static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
>> {
>> + struct kvm_vcpu *vcpu;
>> + int do_sleep = 1;
>> +
>> DEFINE_WAIT(wait);
>>
>> prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
>> +
>> + /*
>> + * Check one last time for pending exceptions and ceded state after
>> + * we put ourselves on the wait queue
>> + */
>> + list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
>> + if (vcpu->arch.pending_exceptions || !vcpu->arch.ceded) {
>> + do_sleep = 0;
>> + break;
>> + }
>> + }
>> +
>> + if (!do_sleep) {
>> + finish_wait(&vc->wq, &wait);
>> + return;
>> + }
>> +
>> vc->vcore_state = VCORE_SLEEPING;
>> spin_unlock(&vc->lock);
>> schedule();
>>
>
WARNING: multiple messages have this Message-ID (diff)
From: "Suresh E. Warrier" <warrier@linux.vnet.ibm.com>
To: Alexander Graf <agraf@suse.de>, Paul Mackerras <paulus@samba.org>,
kvm-ppc@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 5/5] KVM: PPC: Book3S HV: Check wait conditions before sleeping in kvmppc_vcore_blocked
Date: Thu, 20 Nov 2014 13:31:24 -0600 [thread overview]
Message-ID: <546E418C.1080105@linux.vnet.ibm.com> (raw)
In-Reply-To: <546E26A8.1080904@suse.de>
On 11/20/2014 11:36 AM, Alexander Graf wrote:
>
>
> On 03.11.14 05:52, Paul Mackerras wrote:
>> From: "Suresh E. Warrier" <warrier@linux.vnet.ibm.com>
>>
>> The kvmppc_vcore_blocked() code does not check for the wait condition
>> after putting the process on the wait queue. This means that it is
>> possible for an external interrupt to become pending, but the vcpu to
>> remain asleep until the next decrementer interrupt. The fix is to
>> make one last check for pending exceptions and ceded state before
>> calling schedule().
>>
>> Signed-off-by: Suresh Warrier <warrier@linux.vnet.ibm.com>
>> Signed-off-by: Paul Mackerras <paulus@samba.org>
>
> I don't understand the race you're fixing here. Can you please explain it?
>
When a virtual interrupt needs to be delivered to the guest, and the
virtual ICS state for the interrupt and virtual ICP state for the VCPU
allow for the VCPU to be immediately interrupted, we
1. Set the BOOK3S_INTERRUPT_EXTERNAL_LEVEL bit in pending_exceptions.
2. Call kvmppc_fast_vcpu_kick_hv(), which checks the wait queue at vcpu->wq
to wake the VCPU up.
The caller of kvmppc_vcore_blocked() does the check for pending exceptions, but
there is a race condition here and we do need to check again after the VCPU
is put on the wait queue.
-suresh
>
> Alex
>
>> ---
>> arch/powerpc/kvm/book3s_hv.c | 20 ++++++++++++++++++++
>> 1 file changed, 20 insertions(+)
>>
>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>> index cd7e030..1a7a281 100644
>> --- a/arch/powerpc/kvm/book3s_hv.c
>> +++ b/arch/powerpc/kvm/book3s_hv.c
>> @@ -1828,9 +1828,29 @@ static void kvmppc_wait_for_exec(struct kvm_vcpu *vcpu, int wait_state)
>> */
>> static void kvmppc_vcore_blocked(struct kvmppc_vcore *vc)
>> {
>> + struct kvm_vcpu *vcpu;
>> + int do_sleep = 1;
>> +
>> DEFINE_WAIT(wait);
>>
>> prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
>> +
>> + /*
>> + * Check one last time for pending exceptions and ceded state after
>> + * we put ourselves on the wait queue
>> + */
>> + list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) {
>> + if (vcpu->arch.pending_exceptions || !vcpu->arch.ceded) {
>> + do_sleep = 0;
>> + break;
>> + }
>> + }
>> +
>> + if (!do_sleep) {
>> + finish_wait(&vc->wq, &wait);
>> + return;
>> + }
>> +
>> vc->vcore_state = VCORE_SLEEPING;
>> spin_unlock(&vc->lock);
>> schedule();
>>
>
next prev parent reply other threads:[~2014-11-20 19:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-03 4:51 [PATCH 0/5] Some fixes for HV KVM on PPC Paul Mackerras
2014-11-03 4:51 ` Paul Mackerras
2014-11-03 4:51 ` [PATCH 1/5] KVM: PPC: Book3S HV: Fix computation of tlbie operand Paul Mackerras
2014-11-03 4:51 ` Paul Mackerras
2014-11-03 5:59 ` Aneesh Kumar K.V
2014-11-03 6:11 ` Aneesh Kumar K.V
2014-11-03 6:29 ` Aneesh Kumar K.V
2014-11-03 6:41 ` Aneesh Kumar K.V
2014-11-03 4:51 ` [PATCH 2/5] KVM: PPC: Book3S HV: Fix an issue where guest is paused on receiving HMI Paul Mackerras
2014-11-03 4:51 ` Paul Mackerras
2014-11-20 17:32 ` Alexander Graf
2014-11-20 17:32 ` Alexander Graf
2014-11-03 4:51 ` [PATCH 3/5] KVM: PPC: Book3S HV: Fix KSM memory corruption Paul Mackerras
2014-11-03 4:51 ` Paul Mackerras
2014-11-03 4:51 ` [PATCH 4/5] KVM: PPC: Book3S HV: Fix inaccuracies in ICP emulation for H_IPI Paul Mackerras
2014-11-03 4:51 ` Paul Mackerras
2014-11-03 4:52 ` [PATCH 5/5] KVM: PPC: Book3S HV: Check wait conditions before sleeping in kvmppc_vcore_blocked Paul Mackerras
2014-11-03 4:52 ` Paul Mackerras
2014-11-20 17:36 ` Alexander Graf
2014-11-20 17:36 ` Alexander Graf
2014-11-20 19:31 ` Suresh E. Warrier [this message]
2014-11-20 19:31 ` Suresh E. Warrier
2014-11-23 0:41 ` Alexander Graf
2014-11-23 0:41 ` Alexander Graf
2014-11-20 17:36 ` [PATCH 0/5] Some fixes for HV KVM on PPC Alexander Graf
2014-11-20 17:36 ` Alexander Graf
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=546E418C.1080105@linux.vnet.ibm.com \
--to=warrier@linux.vnet.ibm.com \
--cc=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=paulus@samba.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 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.