From patchwork Wed Nov 4 14:49:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 55993 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp2463770lbr; Wed, 4 Nov 2015 07:02:14 -0800 (PST) X-Received: by 10.68.135.73 with SMTP id pq9mr2335981pbb.53.1446649332492; Wed, 04 Nov 2015 07:02:12 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id c8si2690637pas.153.2015.11.04.07.02.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Nov 2015 07:02:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com 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 1ZtzY5-0005wa-Fi; Wed, 04 Nov 2015 15:00:29 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZtzRU-0005Gv-0Q for linux-arm-kernel@bombadil.infradead.org; Wed, 04 Nov 2015 14:53:40 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by merlin.infradead.org with esmtps (Exim 4.85 #2 (Red Hat Linux)) id 1ZtzRR-0001O0-O4 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2015 14:53:39 +0000 Received: by wmeg8 with SMTP id g8so112702580wme.0 for ; Wed, 04 Nov 2015 06:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mTtxRGwWmKfXrP6ztxPLIECX9lHeI5BKTP2WIZRQEMc=; b=z9shWfOWe3LgGIvRHa1GX4AvAib3eIKw9ALPjI4taxUUJk2O014m7XG79TeA+mkdzJ oj49/pNvmVghNej+iARp/uTE18SlBw9s8OeAIkMbIBc1SBVUZGNkJlAjl5bu8cJkzCSY mugAWOMYz/P4bUCrdYdRP+JaI9FXl0kcggnLq2qyJLMeT5vKvFpXHuqwxWcrHm2IJMoY 6INasq8FYPpOXAxfqD8swsXIK4yRK6B+anzRyUuXWBfxOjLuJF1XilrDJn9WaAHXkWeu JkQPphEdtBmH36qUkZohzfEm2M1TctxlzGW8ZyTRHctTXlichSsCB8eEdScPaQvAAOuv my6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mTtxRGwWmKfXrP6ztxPLIECX9lHeI5BKTP2WIZRQEMc=; b=PkCexgIW9AsDXHAEKKh/3jpzjvLIY/FI+ibRjo9HSbCeGllLuQBnK0ruYAI3MIKvzq 1pNRQGGByYz5Aoi8Miq5CZZ11NIdWbO6NJZXjo5rLC9m4suBBwG3/VbGaa8ZQhf2vbsU MHV09UeixIhqaX8KB1jjyKygONfzLEIbE7XEC6WME1y+dOjptoClbnoy4sUkb3jEgWrp Uujpkn7cMCatadWhQngpDzbY1xiCJtLuNBqDox7arvx3QPOMSL0J6e8T8zmFkajT23zV TmJulxCVIdDCZQ6e4HWBkS+P+kZ9aTfAnH6LuUQO4hEdodJ77a39zFHisS2q0/Sr9hKx 7ecA== X-Gm-Message-State: ALoCoQnC3e3N6NUZVJ41tKGqBduTqnWNvj4VOeVB0h/Ok96eGIOIFXcwo7YD1r4RUkxlOoitGmnL X-Received: by 10.28.140.208 with SMTP id o199mr4113946wmd.58.1446648795611; Wed, 04 Nov 2015 06:53:15 -0800 (PST) Received: from localhost.localdomain ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id e9sm1985081wjw.8.2015.11.04.06.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 06:53:14 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PULL 17/21] arm64: kvm: restore EL1N SP for panic Date: Wed, 4 Nov 2015 15:49:56 +0100 Message-Id: <1446648600-27297-18-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.1.2.330.g565301e.dirty In-Reply-To: <1446648600-27297-1-git-send-email-christoffer.dall@linaro.org> References: <1446648600-27297-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151104_095337_906092_F2C7B4F8 X-CRM114-Status: GOOD ( 15.69 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:22d listed in] [list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Mark Rutland , Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org From: Mark Rutland If we panic in hyp mode, we inject a call to panic() into the EL1N host kernel. If a guest context is active, we first attempt to restore the minimal amount of state necessary to execute the host kernel with restore_sysregs. However, the SP is restored as part of restore_common_regs, and so we may return to the host's panic() function with the SP of the guest. Any calculations based on the SP will be bogus, and any attempt to access the stack will result in recursive data aborts. When running Linux as a guest, the guest's EL1N SP is like to be some valid kernel address. In this case, the host kernel may use that region as a stack for panic(), corrupting it in the process. Avoid the problem by restoring the host SP prior to returning to the host. To prevent misleading backtraces in the host, the FP is zeroed at the same time. We don't need any of the other "common" registers in order to panic successfully. Signed-off-by: Mark Rutland Acked-by: Marc Zyngier Cc: Christoffer Dall Cc: Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp.S | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.1.2.330.g565301e.dirty _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S index e583613..1599701 100644 --- a/arch/arm64/kvm/hyp.S +++ b/arch/arm64/kvm/hyp.S @@ -880,6 +880,14 @@ __kvm_hyp_panic: bl __restore_sysregs + /* + * Make sure we have a valid host stack, and don't leave junk in the + * frame pointer that will give us a misleading host stack unwinding. + */ + ldr x22, [x2, #CPU_GP_REG_OFFSET(CPU_SP_EL1)] + msr sp_el1, x22 + mov x29, xzr + 1: adr x0, __hyp_panic_str adr x1, 2f ldp x2, x3, [x1]