From: Andrew Jones <drjones@redhat.com>
To: kvmarm@lists.cs.columbia.edu
Cc: Levente Kurusa <lkurusa@redhat.com>,
marc.zyngier@arm.com, ashoks@broadcom.com, imammedo@redhat.com
Subject: [PATCH 4/5] KVM: arm/arm64: fix race in kvm_psci_vcpu_on
Date: Mon, 27 Feb 2017 18:55:03 +0100 [thread overview]
Message-ID: <20170227175504.15751-5-drjones@redhat.com> (raw)
In-Reply-To: <20170227175504.15751-1-drjones@redhat.com>
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 ++--
include/linux/kvm_host.h | 5 +++++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
index 6c6255f9d8ff..1fccbeb1c0be 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 (!__kvm_request_test(KVM_REQ_VCPU_POWER_OFF, vcpu)) {
+
+ if (!__kvm_request_test_and_clear(KVM_REQ_VCPU_POWER_OFF, vcpu)) {
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);
- __kvm_request_clear(KVM_REQ_VCPU_POWER_OFF, vcpu);
wq = kvm_arch_vcpu_wq(vcpu);
swake_up(wq);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 97b6bd6318e5..df9df7677510 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -1135,6 +1135,11 @@ static inline void __kvm_request_clear(unsigned req, struct kvm_vcpu *vcpu)
clear_bit(req, &vcpu->requests);
}
+static inline bool __kvm_request_test_and_clear(unsigned req, struct kvm_vcpu *vcpu)
+{
+ return test_and_clear_bit(req, &vcpu->requests);
+}
+
static inline bool kvm_request_test_and_clear(unsigned req, struct kvm_vcpu *vcpu)
{
if (__kvm_request_test(req, vcpu)) {
--
2.9.3
next prev parent reply other threads:[~2017-02-27 17:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 17:54 [PATCH 0/5] KVM: arm/arm64: fix some races and allow userspace to set MPIDR Andrew Jones
2017-02-27 17:55 ` [PATCH 1/5] KVM: arm/arm64: prepare to use vcpu requests Andrew Jones
2017-03-08 13:21 ` Christoffer Dall
2017-02-27 17:55 ` [PATCH 2/5] KVM: arm/arm64: replace vcpu->arch.pause with a vcpu-request Andrew Jones
2017-03-08 14:33 ` Christoffer Dall
2017-03-08 14:44 ` Andrew Jones
2017-03-13 10:30 ` Christoffer Dall
2017-03-13 17:27 ` Andrew Jones
2017-03-13 18:22 ` Christoffer Dall
2017-02-27 17:55 ` [PATCH 3/5] KVM: arm/arm64: replace vcpu->arch.power_off " Andrew Jones
2017-02-27 17:55 ` Andrew Jones [this message]
2017-02-27 17:55 ` [PATCH 5/5] KVM: arm/arm64: allow userspace to set MPIDR Andrew Jones
2017-03-08 13:19 ` Christoffer Dall
2017-03-08 14:27 ` Peter Maydell
2017-03-08 17:21 ` Christoffer Dall
2017-03-08 20:48 ` Peter Maydell
2017-03-08 17:27 ` [PATCH 0/5] KVM: arm/arm64: fix some races and " Christoffer Dall
2017-03-08 17:53 ` Andrew Jones
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=20170227175504.15751-5-drjones@redhat.com \
--to=drjones@redhat.com \
--cc=ashoks@broadcom.com \
--cc=imammedo@redhat.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=lkurusa@redhat.com \
--cc=marc.zyngier@arm.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