From patchwork Thu Nov 27 18:41:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 41646 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E74232486D for ; Thu, 27 Nov 2014 18:43:33 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf3503476eek.10 for ; Thu, 27 Nov 2014 10:43:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=vadSs3BNTSk/KiAXdMOzYjY0JhhjrVMp6x3w8scFJbI=; b=kbQ0Ds7a3wPGm/TRJ0jIcnJdQJEdZ0bre5E4lVLmXbXzYCC2CXMp+epVhUoSmBu1IK ilwPD0bbmotWw1BgsskCSNisXqgcWkqULEEY1gu5zN3VsJYEtIMKrTGDKvLHdKsgE0r5 /Fy1UgGFJ6BTbvNDhEcCIMbL6oHFhibS1FzLaNknIuUwvfkqyOSlRWA1jEaVwBtr0eAU +wn9TEdAy36t5nwqh7qqAEzdjSUfZRafzuCXLYeDSGxusDAY8J/xvj0UbXtyuIHZ9nXy pBx2qmjYglixiobV61b5RkNimsfeSNfNR6cW/jkHQYejmrYrJJ9Cl29sbx6f9cefSRAy C7Hw== X-Gm-Message-State: ALoCoQmk1N/spKaZaH/vjLGSF+6NiZb5ZcjnBpQz9GbK0S4Vg5qUe8X+8G276+xscKKwbH9v3Oov X-Received: by 10.180.105.97 with SMTP id gl1mr7745478wib.7.1417113812786; Thu, 27 Nov 2014 10:43:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.41 with SMTP id t9ls93850lal.51.gmail; Thu, 27 Nov 2014 10:43:32 -0800 (PST) X-Received: by 10.152.42.172 with SMTP id p12mr40412428lal.11.1417113812457; Thu, 27 Nov 2014 10:43:32 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id u8si7939222lau.133.2014.11.27.10.43.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Nov 2014 10:43:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id w7so4492470lbi.5 for ; Thu, 27 Nov 2014 10:43:32 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr39813048lbo.32.1417113812116; Thu, 27 Nov 2014 10:43:32 -0800 (PST) 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.184.201 with SMTP id ew9csp838069lbc; Thu, 27 Nov 2014 10:43:30 -0800 (PST) X-Received: by 10.70.89.174 with SMTP id bp14mr8108915pdb.136.1417113809993; Thu, 27 Nov 2014 10:43:29 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id jy15si12772680pad.148.2014.11.27.10.43.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Nov 2014 10:43:29 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xu40s-00018Y-Iz; Thu, 27 Nov 2014 18:41:58 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xu3zq-0000fU-VV for linux-arm-kernel@lists.infradead.org; Thu, 27 Nov 2014 18:40:56 +0000 Received: by mail-la0-f42.google.com with SMTP id s18so4655060lam.15 for ; Thu, 27 Nov 2014 10:40:35 -0800 (PST) X-Received: by 10.152.7.193 with SMTP id l1mr40079962laa.57.1417113635849; Thu, 27 Nov 2014 10:40:35 -0800 (PST) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id x1sm1682425lae.42.2014.11.27.10.40.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Nov 2014 10:40:35 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/5] arm/arm64: KVM: Turn off vcpus and flush stage-2 pgtables on sytem exit events Date: Thu, 27 Nov 2014 19:41:00 +0100 Message-Id: <1417113660-23610-6-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty In-Reply-To: <1417113660-23610-1-git-send-email-christoffer.dall@linaro.org> References: <1417113660-23610-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141127_104055_230476_2528A53F X-CRM114-Status: GOOD ( 16.76 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.42 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.42 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Marc Zyngier , Peter Maydell , Christoffer Dall , kvm@vger.kernel.org, Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@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.217.174 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 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, to ensure a coherent icache/dcache/ram situation when restarting with the guest MMU off, flush all stage-2 page table entries so we start taking aborts when the guest reboots, and flush/invalidate the necessary cache lines. Clarify the behavior and expectations for arm/arm64 in the KVM_EXIT_SYSTEM_EVENT case. Signed-off-by: Christoffer Dall --- Documentation/virtual/kvm/api.txt | 4 ++++ arch/arm/kvm/psci.c | 18 ++++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 1 + 3 files changed, 23 insertions(+) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index fc12b4f..c67e4956 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -2955,6 +2955,10 @@ 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. +In the case of ARM/ARM64, all vcpus will be powered off when requesting shutdown +or reset, and it is the responsibility of userspace to reinitialize the vcpus +using KVM_ARM_VCPU_INIT. + /* 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..b4ab613 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -15,11 +15,13 @@ * along with this program. If not, see . */ +#include #include #include #include #include +#include #include /* @@ -166,6 +168,22 @@ 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; + + /* Stop all vcpus */ + kvm_for_each_vcpu(i, tmp, vcpu->kvm) + tmp->arch.pause = true; + preempt_disable(); + force_vm_exit(cpu_all_mask); + preempt_enable(); + + /* + * Ensure a rebooted VM will fault in RAM pages and detect if the + * guest MMU is turned off and flush the caches as needed. + */ + stage2_unmap_vm(vcpu->kvm); + 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);