From patchwork Mon May 4 01:25: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: 47923 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 245F120553 for ; Mon, 4 May 2015 01:27:26 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf40943165wgt.1 for ; Sun, 03 May 2015 18:27:25 -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=XDwBd7qnkWilo4UYy4msK1u+b6MiC710iJyR5z1Ca5o=; b=BwVmZtUZxXLqqkuaYULmczKGbGTXWfml6gHyqqLFLJonOtXdDq1eF22i7wMjnvaP6z wI1U+ND0Fly9zAk6cFyeVMYbj6vYi7/mFANnCWfwT74FWfRSWv09ybhWLClvC3CSUPxK 5j4LSlNGq6Kg+Cj6RF2SjPW06JTAGnAXY0lA+L7l0d3ArQiF1dtujebOYse33GWcX4b8 ele/cgRapp4fUVAVY81Vx9WssLxrZDAMvibOowW/AarYTysiHgrN69+UlP0RZGRaiSRf jLDB7knKycWrXVu7FjjO11WoaH4JbEZHHzWTpR8fC1ACX8LOjcOuE/CkpxKs5F6956pc bS1Q== X-Gm-Message-State: ALoCoQnns6kXfE4+/Q8RM8pJZDc9XbZdZ66ovNolXhdqNKF8l0tJtywwW+MPEek2vLZgDHS2wL7x X-Received: by 10.180.96.6 with SMTP id do6mr6827651wib.4.1430702845487; Sun, 03 May 2015 18:27:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.101 with SMTP id i5ls594945laa.58.gmail; Sun, 03 May 2015 18:27:25 -0700 (PDT) X-Received: by 10.112.47.73 with SMTP id b9mr17388551lbn.46.1430702845322; Sun, 03 May 2015 18:27:25 -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 j2si9043107lam.114.2015.05.03.18.27.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:27:24 -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 v1so94729841lag.3 for ; Sun, 03 May 2015 18:27:24 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr17221356lbc.41.1430702844558; Sun, 03 May 2015 18:27:24 -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 l1csp1405902lbt; Sun, 3 May 2015 18:27:23 -0700 (PDT) X-Received: by 10.70.135.168 with SMTP id pt8mr38133160pdb.8.1430702842800; Sun, 03 May 2015 18:27:22 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id es7si17680936pbd.123.2015.05.03.18.27.21; Sun, 03 May 2015 18:27:22 -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 S1751756AbbEDB1V (ORCPT + 2 others); Sun, 3 May 2015 21:27:21 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:35561 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751718AbbEDB1U (ORCPT ); Sun, 3 May 2015 21:27:20 -0400 Received: by pabtp1 with SMTP id tp1so147357443pab.2 for ; Sun, 03 May 2015 18:27:20 -0700 (PDT) X-Received: by 10.68.65.1 with SMTP id t1mr38364547pbs.63.1430702839997; Sun, 03 May 2015 18:27:19 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id fl4sm11012269pab.8.2015.05.03.18.27.18 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:27:19 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: sasha.levin@oracle.com, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.18.y stable 07/22] arm/arm64: KVM: Turn off vcpus on PSCI shutdown/reboot Date: Mon, 4 May 2015 09:25:11 +0800 Message-Id: <1430702726-2056-8-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430702726-2056-1-git-send-email-shannon.zhao@linaro.org> References: <1430702726-2056-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 cf5d318865e25f887d49a0c6083bbc6dcd1905b1 upstream. When a vcpu calls SYSTEM_OFF or SYSTEM_RESET with PSCI v0.2, the vcpus should really be turned off for the VM adhering to the suggestions in the PSCI spec, and it's the sane thing to do. Also, clarify the behavior and expectations for exits to user space with the KVM_EXIT_SYSTEM_EVENT case. Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- Documentation/virtual/kvm/api.txt | 9 +++++++++ arch/arm/kvm/psci.c | 18 ++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 1 + 3 files changed, 28 insertions(+) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index bb82a90..702bb25 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -2952,6 +2952,15 @@ HVC instruction based PSCI call from the vcpu. The 'type' field describes the system-level event type. The 'flags' field describes architecture specific flags for the system-level event. +Valid values for 'type' are: + KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the + VM. Userspace is not obliged to honour this, and if it does honour + this does not need to destroy the VM synchronously (ie it may call + KVM_RUN again before shutdown finally occurs). + KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM. + As with SHUTDOWN, userspace can choose to ignore the request, or + to schedule the reset to occur in the future and may call KVM_RUN again. + /* Fix the size of the union. */ char padding[256]; }; diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 09cf377..58cb324 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -166,6 +167,23 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu) static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type) { + int i; + struct kvm_vcpu *tmp; + + /* + * The KVM ABI specifies that a system event exit may call KVM_RUN + * again and may perform shutdown/reboot at a later time that when the + * actual request is made. Since we are implementing PSCI and a + * caller of PSCI reboot and shutdown expects that the system shuts + * down or reboots immediately, let's make sure that VCPUs are not run + * after this call is handled and before the VCPUs have been + * re-initialized. + */ + kvm_for_each_vcpu(i, tmp, vcpu->kvm) { + tmp->arch.pause = true; + kvm_vcpu_kick(tmp); + } + memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); vcpu->run->system_event.type = type; vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 2012c4b..dbd3212 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -200,6 +200,7 @@ struct kvm_vcpu *kvm_arm_get_running_vcpu(void); struct kvm_vcpu * __percpu *kvm_get_running_vcpus(void); u64 kvm_call_hyp(void *hypfn, ...); +void force_vm_exit(const cpumask_t *mask); int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, int exception_index);