From patchwork Thu Feb 20 15:26:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 25072 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E49BB20AE6 for ; Thu, 20 Feb 2014 16:27:27 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id c41sf1182690yho.9 for ; Thu, 20 Feb 2014 08:27:27 -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:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=1Z52jZkgFs0YS3lDY/Gtvk17Mc+Eic8KXIFtjVpLjcM=; b=KIO140QWkdsnU7ev0UbiwzCb+MTs/homDf+v6o+34YgMSC0PZxiQ98iPmJSyZsMi0A WlzQjd8XAbe6vA3gT9nB6Qui/xNRkBKpcOJ6QuIE1nyvmgG3676wlgO+GHodqAR4g5ug goqV69rsXZTFTNikH9NMBS8fNBygUiClfgMrkf65Ry5cktKuOv4IcSfmzqzQI7GmHzep 7/gyQageK3tbdFTNvJzsZKwcqCaImMSCMAWkDO4cQx3Q/Br56IBIvvHsr/kkiVRi7gSG HwUAiyQaWyYMY+LMD6ze5JU9EmZmi9SeZOwez962hoLAHjedN/Wr1j4qkpuXNQnbUauV RewA== X-Gm-Message-State: ALoCoQmMe++jNkXTLBCcrNAAvx1iCv5S4KB/IhBxGFKtFq+dCNYuHGzXcMdjB6wteDGSSLISAbSK X-Received: by 10.236.98.104 with SMTP id u68mr899551yhf.1.1392913646767; Thu, 20 Feb 2014 08:27:26 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.69 with SMTP id s63ls602060qgd.28.gmail; Thu, 20 Feb 2014 08:27:26 -0800 (PST) X-Received: by 10.220.110.69 with SMTP id m5mr1467093vcp.55.1392913646544; Thu, 20 Feb 2014 08:27:26 -0800 (PST) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id yt16si1653860vcb.117.2014.02.20.08.27.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 08:27:26 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id cz12so819010veb.11 for ; Thu, 20 Feb 2014 08:27:26 -0800 (PST) X-Received: by 10.52.185.196 with SMTP id fe4mr1250151vdc.27.1392913646441; Thu, 20 Feb 2014 08:27:26 -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.220.174.196 with SMTP id u4csp71010vcz; Thu, 20 Feb 2014 08:27:25 -0800 (PST) X-Received: by 10.180.37.178 with SMTP id z18mr7952891wij.46.1392913628472; Thu, 20 Feb 2014 08:27:08 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id r4si5336924wjz.63.2014.02.20.08.27.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Feb 2014 08:27:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGVjR-0000bv-4W; Thu, 20 Feb 2014 15:40:14 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGVXE-0002D0-4J; Thu, 20 Feb 2014 15:27:36 +0000 Received: from fw-tnat.austin.arm.com ([217.140.110.23] helo=collaborate-mta1.arm.com) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGVWx-0002AP-DO for linux-arm-kernel@lists.infradead.org; Thu, 20 Feb 2014 15:27:20 +0000 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.166]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 3CA6F13F61A; Thu, 20 Feb 2014 09:26:55 -0600 (CST) From: Marc Zyngier To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm/arm64: KVM: detect CPU reset on CPU_PM_EXIT Date: Thu, 20 Feb 2014 15:26:54 +0000 Message-Id: <1392910014-15495-1-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140220_102719_581456_562DC8A2 X-CRM114-Status: GOOD ( 13.12 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Rob Herring , Lorenzo Pieralisi , Andre Przywara X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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: marc.zyngier@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 Commit 1fcf7ce0c602 (arm: kvm: implement CPU PM notifier) added support for CPU power-management, using a cpu_nofigier to re-init KVM on a CPU that entered CPU idle. The code assumed that a CPU entering idle would actually be powered off, loosing its state entierely, and would then need to be reinitialized. It turns out that this is not always the case, and some HW performs CPU PM without actually killing the core. In this case, we try to reinitialize KVM while it still live. It ends up badly, as reported by Andre Przywara (using a Calxeda Midway): [ 3.663897] Kernel panic - not syncing: unexpected prefetch abort in Hyp mode at: 0x685760 [ 3.663897] unexpected data abort in Hyp mode at: 0xc067d150 [ 3.663897] unexpected HVC/SVC trap in Hyp mode at: 0xc0901dd0 The trick here is to detect if we've been through a full re-init or not by looking at HVBAR (VBAR_EL2 on arm64). This involves implementing the backend for __hyp_get_vectors in the main KVM HYP code (rather small), and checking the return value against the default one when the CPU notifier is called on CPU_PM_EXIT. Reported-by: Andre Przywara Cc: Lorenzo Pieralisi Cc: Rob Herring Signed-off-by: Marc Zyngier Acked-by: Christoffer Dall --- arch/arm/kvm/arm.c | 3 ++- arch/arm/kvm/interrupts.S | 7 ++++++- arch/arm64/kvm/hyp.S | 9 +++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 1d8248e..bd18bb8 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -878,7 +878,8 @@ static int hyp_init_cpu_pm_notifier(struct notifier_block *self, unsigned long cmd, void *v) { - if (cmd == CPU_PM_EXIT) { + if (cmd == CPU_PM_EXIT && + __hyp_get_vectors() == hyp_default_vectors) { cpu_init_hyp_mode(NULL); return NOTIFY_OK; } diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S index ddc1553..9b0ff68 100644 --- a/arch/arm/kvm/interrupts.S +++ b/arch/arm/kvm/interrupts.S @@ -363,6 +363,11 @@ hyp_hvc: host_switch_to_hyp: pop {r0, r1, r2} + /* Check for __hyp_get_vectors */ + cmp r0, #-1 + mrceq p15, 4, r0, c12, c0, 0 @ get HVBAR + beq 1f + push {lr} mrs lr, SPSR push {lr} @@ -378,7 +383,7 @@ THUMB( orr lr, #1) pop {lr} msr SPSR_csxf, lr pop {lr} - eret +1: eret guest_trap: load_vcpu @ Load VCPU pointer to r0 diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index 3b47c36..f1cbabe 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S @@ -737,7 +737,12 @@ el1_sync: // Guest trapped into EL2 pop x2, x3 pop x0, x1 - push lr, xzr + /* Check for __hyp_get_vectors */ + cbnz x0, 1f + mrs x0, vbar_el2 + b 2f + +1: push lr, xzr /* * Compute the function address in EL2, and shuffle the parameters. @@ -750,7 +755,7 @@ el1_sync: // Guest trapped into EL2 blr lr pop lr, xzr - eret +2: eret el1_trap: /*