From patchwork Tue Jul 26 07:37:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12928982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06A50C433EF for ; Tue, 26 Jul 2022 07:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=oU/C4AIIZ12yaj1tt3wIohsVre3bPSJruqMmjN4Edz0=; b=nbCszMXYnHjPq1psmkw488iOla +mtxPA2ESxDrm7VvQfVwSQE6b4UXTXPDfN4C7HH9eLeAgIrSvIOB8+6WT49yczYf3PFoYraZ/B/7t zYKr13myD5NVY+rXKZU1fTNn4fwQJ8EK7UmMJG4U9qlnmPJ167ViLnQSIH/0u9HQqsxU1OU1j1Jgf IZwvXH0iLLuPIg1/ujdsE+lST4qEHLwN2LDRcG/UHamIun2l1NzWeDSEUowY1T805NT5lqW2rMFAk vTCx4HyA0CRj9IJNa02JgkJtCzvMnOwyHS3zOx2VEOZGyEkun7HQWMMvxHSAraXF13Tm+IZCN4Zxc fINCCrug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oGFB3-009XI1-Ns; Tue, 26 Jul 2022 07:40:25 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oGF8v-009VkQ-W4 for linux-arm-kernel@lists.infradead.org; Tue, 26 Jul 2022 07:38:16 +0000 Received: by mail-yb1-xb49.google.com with SMTP id z6-20020a056902054600b00670e3c8b43fso8388756ybs.23 for ; Tue, 26 Jul 2022 00:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=jVgz/szeSDEehPkBGFOtiG6TH4cWoSnAE1JEiuFeF4M=; b=C8Yf1l5/uTkII4CdB1cNpCvsxEc+28PsYTXUIba+64kfS7ozSMTCfLNCiyBvwQNoYx v4tLxHFGn1NugmrjBRhPGqOdAZyJXo6plyN8kY2kxqrqmVq3LsXugD6jJievh78HX1KU 8SV94Q4buvRguuD8HdNpI5/LLT4QrCi5nivUYVxFdpMWinuWqv8Wjo2CCaEzyts5qj2l xJc8atY4LJrRDy1iJjqOnQ7dmFBLYGMRuagGcaTc0e7clYvr/Z70nvyA4TtGSrPQOrH8 Y5fQN/ePeHrKVVNVIg/c62DaamTj1boYjZ/CNnJsQw/brcmyDLOOKu7s7UrMm8NQL9ED RE3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jVgz/szeSDEehPkBGFOtiG6TH4cWoSnAE1JEiuFeF4M=; b=UlV5/NIRx6FftvdrPYq7D0qu+PzFVwbzmZgd1yNn095e+EHcRqKUAYwM9X1IPgd3V6 /RPslCTmwm0NVrUnZK4FrpTvv2GubmB5b/BOfH7Ab5dKBI5s0rxO5Cnmsn9lXVh2H6bb x+na5CZVXK9Dy6gBHyHEiszbWaefzYhtOoEm2VwUC+olIsoNl6ztQxHnLyyliv2DPbau zUA7GBADHMD5Ef4eFWizr+H6zUjaB6Qd/WGHrcBSKmaVGV1Kj2Y5mSxK15tU8D5xNEGe kUMzCvjpuqBzxTQPmcU5Cu867LN6kisKxlu1a4PLhWnjO1pgWzH8mqceOK57amBs+v7g LKpw== X-Gm-Message-State: AJIora8oaEbCA5Ii+bjwg+BX+Vd0J/QOZXqOaU/7FJuU7/xPrObUWhH2 EzalbcsQGzorC6+0Nn9ZSc+hHJbxSc39IkofWg== X-Google-Smtp-Source: AGRyM1u/sM09rRaGMw6Yf5N3cXgpcmHXKZVyWJE18QaDwOtW5yaQPATPB7V5gHdj9ore7niZ9XvnVO65RXiiNAWyfg== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:4f77:3b64:736a:394e]) (user=kaleshsingh job=sendgmr) by 2002:a05:6902:1613:b0:671:2e0c:dda1 with SMTP id bw19-20020a056902161300b006712e0cdda1mr7585688ybb.514.1658821092633; Tue, 26 Jul 2022 00:38:12 -0700 (PDT) Date: Tue, 26 Jul 2022 00:37:40 -0700 In-Reply-To: <20220726073750.3219117-1-kaleshsingh@google.com> Message-Id: <20220726073750.3219117-8-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220726073750.3219117-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog Subject: [PATCH v6 07/17] KVM: arm64: On stack overflow switch to hyp overflow_stack From: Kalesh Singh To: maz@kernel.org, mark.rutland@arm.com, broonie@kernel.org, madvenka@linux.microsoft.com, tabba@google.com, oliver.upton@linux.dev Cc: will@kernel.org, qperret@google.com, kaleshsingh@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, andreyknvl@gmail.com, vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org, wangkefeng.wang@huawei.com, elver@google.com, keirf@google.com, yuzenghui@huawei.com, ardb@kernel.org, oupton@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, android-mm@google.com, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220726_003814_061178_0572C7E0 X-CRM114-Status: GOOD ( 16.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On hyp stack overflow switch to 16-byte aligned secondary stack. This provides us stack space to better handle overflows; and is used in a subsequent patch to dump the hypervisor stacktrace. Signed-off-by: Kalesh Singh Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba --- Changes in v6: - Add Fuad's Tested-by tag Changes in v5: - Add Reviewed-by tag from Fuad arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- arch/arm64/kvm/hyp/nvhe/host.S | 9 ++------- arch/arm64/kvm/hyp/nvhe/stacktrace.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/stacktrace.c diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index f9fe4dc21b1f..524e7dad5739 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -14,7 +14,7 @@ lib-objs := $(addprefix ../../../lib/, $(lib-objs)) obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \ - cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o + cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o stacktrace.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o obj-$(CONFIG_DEBUG_LIST) += list_debug.o diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index ea6a397b64a6..b6c0188c4b35 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -177,13 +177,8 @@ SYM_FUNC_END(__host_hvc) b hyp_panic .L__hyp_sp_overflow\@: - /* - * Reset SP to the top of the stack, to allow handling the hyp_panic. - * This corrupts the stack but is ok, since we won't be attempting - * any unwinding here. - */ - ldr_this_cpu x0, kvm_init_params + NVHE_INIT_STACK_HYP_VA, x1 - mov sp, x0 + /* Switch to the overflow stack */ + adr_this_cpu sp, overflow_stack + OVERFLOW_STACK_SIZE, x0 b hyp_panic_bad_stack ASM_BUG() diff --git a/arch/arm64/kvm/hyp/nvhe/stacktrace.c b/arch/arm64/kvm/hyp/nvhe/stacktrace.c new file mode 100644 index 000000000000..a3d5b34e1249 --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/stacktrace.c @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * KVM nVHE hypervisor stack tracing support. + * + * Copyright (C) 2022 Google LLC + */ +#include +#include + +DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack) + __aligned(16);