From patchwork Fri Apr 24 05:27:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47498 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8EF5420553 for ; Fri, 24 Apr 2015 05:30:41 +0000 (UTC) Received: by laat2 with SMTP id t2sf9428797laa.2 for ; Thu, 23 Apr 2015 22:30:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=VdowtZbkyG8kmy7YBmdOsOVqbcQ7jA9lcY8m8iIP7xk=; b=lcODJ2bbpTvaanADwkVeNYJ/RzQk67xqa23NjwqpBeEB5XFilqU1bm6h+yx0LJhqt/ 679JQr3Jc1O+JSf1xUVy5ywvYqBCrRsZq/CLUW15s9BQYsFMXFlW4ceeG4T1O29UOQLA y4XIBvgLmNtk1FeWaYjZoUDI7k6pfSehpWi4ICBKPBNw5kYuOloPAeXpjxxjRbSizW1N hByWutTmOs8PiYk4Trz4qDKw0e7RPDLlTuxho3cFktyTsvssnJDnP2pKwnvIUIJgl0U9 fozui9tDInaNdV10Mpqb6kUVK5oNQsU4nQEj1pVIdITxIerAh4jjRGy/MM1vIB3o8Vq1 J0XA== X-Gm-Message-State: ALoCoQmk8jKktrzjhVyVKUIyetuPe/qwqaudiXR5U3uTxKZg0/VCGnlVqzOIbYypBiYji2kFAv7T X-Received: by 10.152.3.70 with SMTP id a6mr3217143laa.0.1429853440367; Thu, 23 Apr 2015 22:30:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.65 with SMTP id lu1ls405325lac.104.gmail; Thu, 23 Apr 2015 22:30:40 -0700 (PDT) X-Received: by 10.112.134.167 with SMTP id pl7mr5414900lbb.50.1429853440096; Thu, 23 Apr 2015 22:30:40 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id h1si2277993lae.45.2015.04.23.22.30.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:30:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lagv1 with SMTP id v1so27515775lag.3 for ; Thu, 23 Apr 2015 22:30:40 -0700 (PDT) X-Received: by 10.112.184.70 with SMTP id es6mr5342165lbc.117.1429853439999; Thu, 23 Apr 2015 22:30:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp977268lbt; Thu, 23 Apr 2015 22:30:39 -0700 (PDT) X-Received: by 10.70.131.193 with SMTP id oo1mr2948987pdb.63.1429853438217; Thu, 23 Apr 2015 22:30:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd10si15800741pdb.178.2015.04.23.22.30.37; Thu, 23 Apr 2015 22:30:38 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754514AbbDXFag (ORCPT + 2 others); Fri, 24 Apr 2015 01:30:36 -0400 Received: from mail-ob0-f177.google.com ([209.85.214.177]:33171 "EHLO mail-ob0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754417AbbDXFag (ORCPT ); Fri, 24 Apr 2015 01:30:36 -0400 Received: by oblw8 with SMTP id w8so30250759obl.0 for ; Thu, 23 Apr 2015 22:30:35 -0700 (PDT) X-Received: by 10.202.180.138 with SMTP id d132mr4828698oif.90.1429853435856; Thu, 23 Apr 2015 22:30:35 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id l140sm6081091oig.20.2015.04.23.22.30.33 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:30:34 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.12.y stable 13/63] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive Date: Fri, 24 Apr 2015 13:27:11 +0800 Message-Id: <1429853281-6136-14-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> References: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Christoffer Dall commit 478a8237f656d86d25b3e4e4bf3c48f590156294 upstream. The current KVM implementation of PSCI returns INVALID_PARAMETERS if the waitqueue for the corresponding CPU is not active. This does not seem correct, since KVM should not care what the specific thread is doing, for example, user space may not have called KVM_RUN on this VCPU yet or the thread may be busy looping to user space because it received a signal; this is really up to the user space implementation. Instead we should check specifically that the CPU is marked as being turned off, regardless of the VCPU thread state, and if it is, we shall simply clear the pause flag on the CPU and wake up the thread if it happens to be blocked for us. Further, the implementation seems to be racy when executing multiple VCPU threads. There really isn't a reasonable user space programming scheme to ensure all secondary CPUs have reached kvm_vcpu_first_run_init before turning on the boot CPU. Therefore, set the pause flag on the vcpu at VCPU init time (which can reasonably be expected to be completed for all CPUs by user space before running any VCPUs) and clear both this flag and the feature (in case the feature can somehow get set again in the future) and ping the waitqueue on turning on a VCPU using PSCI. Reported-by: Peter Maydell Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/kvm/arm.c | 30 +++++++++++++++++++----------- arch/arm/kvm/psci.c | 11 ++++++----- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index d45c36c..78ee10b 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -487,15 +487,6 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) return ret; } - /* - * Handle the "start in power-off" case by calling into the - * PSCI code. - */ - if (test_and_clear_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) { - *vcpu_reg(vcpu, 0) = KVM_PSCI_FN_CPU_OFF; - kvm_psci_call(vcpu); - } - return 0; } @@ -709,6 +700,24 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level, return -EINVAL; } +static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, + struct kvm_vcpu_init *init) +{ + int ret; + + ret = kvm_vcpu_set_target(vcpu, init); + if (ret) + return ret; + + /* + * Handle the "start in power-off" case by marking the VCPU as paused. + */ + if (__test_and_clear_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) + vcpu->arch.pause = true; + + return 0; +} + long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { @@ -722,8 +731,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, if (copy_from_user(&init, argp, sizeof(init))) return -EFAULT; - return kvm_vcpu_set_target(vcpu, &init); - + return kvm_arch_vcpu_ioctl_vcpu_init(vcpu, &init); } case KVM_SET_ONE_REG: case KVM_GET_ONE_REG: { diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 881c9fc..485387b 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -55,15 +55,15 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) } } - if (!vcpu) + /* + * Make sure the caller requested a valid CPU and that the CPU is + * turned off. + */ + if (!vcpu || !vcpu->arch.pause) return KVM_PSCI_RET_INVAL; target_pc = *vcpu_reg(source_vcpu, 2); - wq = kvm_arch_vcpu_wq(vcpu); - if (!waitqueue_active(wq)) - return KVM_PSCI_RET_INVAL; - kvm_reset_vcpu(vcpu); /* Gracefully handle Thumb2 entry point */ @@ -76,6 +76,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) vcpu->arch.pause = false; smp_mb(); /* Make sure the above is visible */ + wq = kvm_arch_vcpu_wq(vcpu); wake_up_interruptible(wq); return KVM_PSCI_RET_SUCCESS;