From: Christoffer Dall <cdall@linaro.org>
To: Andrew Jones <drjones@redhat.com>
Cc: Levente Kurusa <lkurusa@redhat.com>,
kvm@vger.kernel.org, marc.zyngier@arm.com, pbonzini@redhat.com,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v2 8/9] KVM: arm/arm64: fix race in kvm_psci_vcpu_on
Date: Wed, 5 Apr 2017 11:30:27 +0200 [thread overview]
Message-ID: <20170405093027.GD1526@cbox> (raw)
In-Reply-To: <20170405091212.kblfdghzj4e4zooc@kamzik.brq.redhat.com>
On Wed, Apr 05, 2017 at 11:12:12AM +0200, Andrew Jones wrote:
> On Wed, Apr 05, 2017 at 10:50:05AM +0200, Christoffer Dall wrote:
> > On Wed, Apr 05, 2017 at 10:35:59AM +0200, Andrew Jones wrote:
> > > On Tue, Apr 04, 2017 at 09:42:08PM +0200, Christoffer Dall wrote:
> > > > On Fri, Mar 31, 2017 at 06:06:57PM +0200, Andrew Jones wrote:
> > > > > From: Levente Kurusa <lkurusa@redhat.com>
> > > > >
> > > > > When two vcpus issue PSCI_CPU_ON on the same core at the same time,
> > > > > then it's possible for them to both enter the target vcpu's setup
> > > > > at the same time. This results in unexpected behaviors at best,
> > > > > and the potential for some nasty bugs at worst.
> > > > >
> > > > > Signed-off-by: Levente Kurusa <lkurusa@redhat.com>
> > > > > Signed-off-by: Andrew Jones <drjones@redhat.com>
> > > > > ---
> > > > > arch/arm/kvm/psci.c | 4 ++--
> > > > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
> > > > > index f732484abc7a..0204daa899b1 100644
> > > > > --- a/arch/arm/kvm/psci.c
> > > > > +++ b/arch/arm/kvm/psci.c
> > > > > @@ -88,7 +88,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
> > > > > */
> > > > > if (!vcpu)
> > > > > return PSCI_RET_INVALID_PARAMS;
> > > > > - if (!test_bit(KVM_REQ_POWER_OFF, &vcpu->requests)) {
> > > > > +
> > > > > + if (!test_and_clear_bit(KVM_REQ_POWER_OFF, &vcpu->requests)) {
> > > > > if (kvm_psci_version(source_vcpu) != KVM_ARM_PSCI_0_1)
> > > > > return PSCI_RET_ALREADY_ON;
> > > > > else
> > > > > @@ -116,7 +117,6 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
> > > > > * the general puspose registers are undefined upon CPU_ON.
> > > > > */
> > > > > vcpu_set_reg(vcpu, 0, context_id);
> > > > > - clear_bit(KVM_REQ_POWER_OFF, &vcpu->requests);
> > > > >
> > > > > wq = kvm_arch_vcpu_wq(vcpu);
> > > > > swake_up(wq);
> > > > > --
> > > > > 2.9.3
> > > > >
> > > >
> > > > Depending on what you end up doing with the requests, if you keep the
> > > > bool flag you could just use the kvm->lock mutex instead.
> > > >
> > > > Have you considered if there are any potential races between
> > > > kvm_psci_system_off() being called on one VCPU while two other VPCUs are
> > > > turning on the same CPU that is being turend off as part of system-wide
> > > > power down as well?
> > >
> > > Sounds like a nice unit test. I haven't considered it, but I guess
> > > the kvm_psci_system_off/reset calling VCPU will ultimately "win", as
> > > it'll cause an exit to userspace that initiates a shutdown/reset.
> > > When the VCPUs are restarted then vcpu init should reset the power_off
> > > state correctly. As long as the race this patch addresses is fixed, then
> > > I'm not sure there should be any risk with the actual system_off/reset
> > > being delayed wrt a vcpu being "on'ed" again, nor with there being more
> > > than one VCPU trying to "on" it at the same time.
> > >
> > > >
> > > > I'm wondering if this means we should take the kvm->lock at a higher
> > > > level when handling PSCI events...
> > >
> > > That would simplify our analysis of the PSCI emulation, but I'm not
> > > sure we want to give a guest the power to constantly acquire that
> > > mutex with a barrage of PSCI calls. Maybe we should create a PSCI
> > > mutex? In order to avoid holding it too long we may want power_off to
> > > be more than a boolean though, i.e. the PENDING state might also be
> > > a good idea to represent.
> > >
> >
> > Hmm, the kvm->lock mutex is per-VM, so if a VM wants to use its CPU
> > resources by taking its own mutex, I don't really see the problem.
>
> I was worried about management paths that lead to a need for that
> lock. For example, I see x86's kvm_free_vcpus(), called from
> kvm_arch_destroy_vm(), acquires it. A quick grep of ARM code doesn't
> reveal anything though.
>
Even in that case, PSCI is guaranteed to make progress, right? So I
still don't understand the challenge.
In any case, I'll have a look over this patch again when you respin.
Thanks,
-Christoffer
next prev parent reply other threads:[~2017-04-05 9:28 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-31 16:06 [PATCH v2 0/9] KVM: arm/arm64: race fixes and vcpu requests Andrew Jones
2017-03-31 16:06 ` [PATCH v2 1/9] KVM: add kvm_request_pending Andrew Jones
2017-04-04 15:30 ` Christoffer Dall
2017-04-04 16:41 ` Andrew Jones
2017-04-05 13:10 ` Radim Krčmář
2017-04-05 17:39 ` Christoffer Dall
2017-04-05 18:30 ` Paolo Bonzini
2017-04-05 20:20 ` Radim Krčmář
2017-04-06 12:02 ` Andrew Jones
2017-04-06 14:37 ` Christoffer Dall
2017-04-06 15:08 ` Andrew Jones
2017-04-07 15:33 ` Paolo Bonzini
2017-04-08 18:19 ` Christoffer Dall
2017-04-06 14:25 ` Christoffer Dall
2017-04-07 13:15 ` Radim Krčmář
2017-04-08 18:23 ` Christoffer Dall
2017-04-08 19:32 ` Paolo Bonzini
2017-04-11 21:06 ` Radim Krčmář
2017-03-31 16:06 ` [PATCH v2 2/9] KVM: Add documentation for VCPU requests Andrew Jones
2017-04-04 15:24 ` Christoffer Dall
2017-04-04 17:06 ` Andrew Jones
2017-04-04 17:23 ` Christoffer Dall
2017-04-04 17:36 ` Paolo Bonzini
2017-04-05 14:11 ` Radim Krčmář
2017-04-05 17:45 ` Christoffer Dall
2017-04-05 18:29 ` Paolo Bonzini
2017-04-05 20:46 ` Radim Krčmář
2017-04-06 14:29 ` Christoffer Dall
2017-04-07 11:44 ` Paolo Bonzini
2017-04-06 14:27 ` Christoffer Dall
2017-04-06 10:18 ` Christian Borntraeger
2017-04-06 12:08 ` Andrew Jones
2017-04-06 12:29 ` Radim Krčmář
2017-03-31 16:06 ` [PATCH v2 3/9] KVM: arm/arm64: prepare to use vcpu requests Andrew Jones
2017-04-04 15:34 ` Christoffer Dall
2017-04-04 17:06 ` Andrew Jones
2017-03-31 16:06 ` [PATCH v2 4/9] KVM: arm/arm64: replace vcpu->arch.pause with a vcpu request Andrew Jones
2017-04-04 13:39 ` Marc Zyngier
2017-04-04 14:47 ` Andrew Jones
2017-04-04 14:51 ` Paolo Bonzini
2017-04-04 15:05 ` Marc Zyngier
2017-04-04 17:07 ` Andrew Jones
2017-04-04 16:04 ` Christoffer Dall
2017-04-04 16:24 ` Paolo Bonzini
2017-04-04 17:19 ` Christoffer Dall
2017-04-04 17:35 ` Paolo Bonzini
2017-04-04 17:57 ` Christoffer Dall
2017-04-04 18:15 ` Paolo Bonzini
2017-04-04 18:38 ` Christoffer Dall
2017-04-04 18:18 ` Andrew Jones
2017-04-04 18:59 ` Paolo Bonzini
2017-04-04 17:57 ` Andrew Jones
2017-04-04 19:04 ` Christoffer Dall
2017-04-04 20:10 ` Paolo Bonzini
2017-04-05 7:09 ` Christoffer Dall
2017-04-05 11:37 ` Paolo Bonzini
2017-04-06 14:14 ` Christoffer Dall
2017-04-07 11:47 ` Paolo Bonzini
2017-04-08 8:35 ` Christoffer Dall
2017-03-31 16:06 ` [PATCH v2 5/9] KVM: arm/arm64: replace vcpu->arch.power_off " Andrew Jones
2017-04-04 17:37 ` Christoffer Dall
2017-03-31 16:06 ` [PATCH v2 6/9] KVM: arm/arm64: use a vcpu request on irq injection Andrew Jones
2017-04-04 17:42 ` Christoffer Dall
2017-04-04 18:27 ` Andrew Jones
2017-04-04 18:59 ` Paolo Bonzini
2017-04-04 18:51 ` Paolo Bonzini
2017-03-31 16:06 ` [PATCH v2 7/9] KVM: arm/arm64: PMU: remove request-less vcpu kick Andrew Jones
2017-04-04 17:46 ` Christoffer Dall
2017-04-04 18:29 ` Andrew Jones
2017-04-04 19:35 ` Christoffer Dall
2017-03-31 16:06 ` [PATCH v2 8/9] KVM: arm/arm64: fix race in kvm_psci_vcpu_on Andrew Jones
2017-04-04 19:42 ` Christoffer Dall
2017-04-05 8:35 ` Andrew Jones
2017-04-05 8:50 ` Christoffer Dall
2017-04-05 9:12 ` Andrew Jones
2017-04-05 9:30 ` Christoffer Dall [this message]
2017-03-31 16:06 ` [PATCH v2 9/9] KVM: arm/arm64: avoid race by caching MPIDR Andrew Jones
2017-04-04 19:44 ` Christoffer Dall
2017-04-05 8:50 ` Andrew Jones
2017-04-05 11:03 ` Christoffer Dall
2017-04-05 11:14 ` Andrew Jones
2017-04-03 15:28 ` [PATCH v2 0/9] KVM: arm/arm64: race fixes and vcpu requests Christoffer Dall
2017-04-03 17:11 ` Paolo Bonzini
2017-04-04 7:27 ` Andrew Jones
2017-04-04 16:05 ` Christoffer Dall
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=20170405093027.GD1526@cbox \
--to=cdall@linaro.org \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=lkurusa@redhat.com \
--cc=marc.zyngier@arm.com \
--cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).