From: Levente Kurusa <lkurusa@xxxxxxxxxx> 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@xxxxxxxxxx> Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx> --- 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 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm