From patchwork Fri Jul 15 06:10:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12918769 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 8ACF7C43334 for ; Fri, 15 Jul 2022 06:13:52 +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=HV9HAuV7Riq71o399NDeJDAiiOlpmkmIHDiFbfF/17Q=; b=Bo2S4C3D3itkvEsrf4OJqNeLFk 9PjcYM2IHvdKfLc5MwQ920dTHXDQnHtqfvXKRsygw7EVepzBYPpfksUgCFua7ll64K/78iKA9BN9O 4Mrtjk7yeB3QKT+SbsuMZbiafa1MkVw9gjDUOEMzN9FooI/zI7CBPw94WE7hD0X21cFhIv3p3fFwY YoSoeAF+UwUdddT5WMMx/pyyDUbQGjJlRHjYk0joIku4az4X6Mp3qmyWhCcxQFM7Y7krOf9IGk/z2 NVwtwmES8B6pPAkhK5hni5JDh3E5IhzY3bnPkS77clqXzsLG1YWavLE1wuFh7KQZ3qelFDrxF9ZAW YC5655dA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCEZ9-004WxM-0z; Fri, 15 Jul 2022 06:12:43 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCEXo-004WKf-Ng for linux-arm-kernel@lists.infradead.org; Fri, 15 Jul 2022 06:11:22 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31c9f68d48cso33851807b3.0 for ; Thu, 14 Jul 2022 23:11:19 -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=l1XnM4q3x1ewVUNvHs0HuWFtRu/IpcbYPtIh1O0D3HY=; b=HAos/OmCJvgcvlVr+l4rgZ529Zy9AgZUmxRT5wAwy49nbAxCFX1OoZOy/MbJm5YfaI MRjaNeuCZinL0cnj7NX8XMcpCfHHUqWQbv0RAohFcbRY1T4dBE3coMErpa8THr3j468g 2Mni4CUr/d6Yiy2Xf8toN4vxOmJ8Zi7NDsSuV9FH7qDcmxJowgkg5gzsyeIOlz9g3CCJ +cjX93wr1FiRJEKVcXe5xqj+sIUGsei1iANx4eYiKCQ/VZ1DqzZW87VQZnOwwT+6vm2L NAve5p5YpRJ6utTnsbjjTignNi4kvQ9AH/UAD2WaDja1b7TkTUFdfYo7/bXdsqoyTW8F JnJA== 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=l1XnM4q3x1ewVUNvHs0HuWFtRu/IpcbYPtIh1O0D3HY=; b=E0QRmeeh2sTvU19894mUAXEVXYAH/nMkY/dPcPyc4oO7z66oX0YHxB2y3cEhxc4JQz MomkLrC7dYEIisRZtkcLNJ16fbEZbBDfaBtqw1xBrnrp43Js6v7kTFaCpYz/yozcAF4U IJ2x1U6YQNn0UFtQzhEvwyEOspfF9IPSxzJiFCJgnOD+JDAI3H39XeeF76BVX3yV2rF8 hdP12yxPLmnWjUz2hz3YgQ3X8H17ghuMcbfhyNDeqR4TpYbo747Y4YJnjHzpAHQpo/sf vsO/sID93h4rRx1M8klgLN54Jskxhmw4rV7njpRiWnYT2tgqpavfJ/jiWuYOsQGTaM2m /5bw== X-Gm-Message-State: AJIora9MBR2z7eUyMgDfqJYQAG+LELOWILzrbT+snSFs7Ny4AmgVgdqc +eH5yXydQvPXu3v5Kstm8vfmJK05mUR7Ax8kxQ== X-Google-Smtp-Source: AGRyM1sFpdc9SV33p7szlsb0+to9mu3jgVu9zuERuzC22gv4CQEQSvN6S0V0TElCV8Mv01JeqbR8z7tOfs91AebCxA== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:f010:455b:62ce:19e]) (user=kaleshsingh job=sendgmr) by 2002:a25:d18b:0:b0:66f:3536:c35a with SMTP id i133-20020a25d18b000000b0066f3536c35amr12561943ybg.546.1657865479300; Thu, 14 Jul 2022 23:11:19 -0700 (PDT) Date: Thu, 14 Jul 2022 23:10:16 -0700 In-Reply-To: <20220715061027.1612149-1-kaleshsingh@google.com> Message-Id: <20220715061027.1612149-8-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220715061027.1612149-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v4 07/18] 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 Cc: will@kernel.org, qperret@google.com, tabba@google.com, kaleshsingh@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, andreyknvl@gmail.com, russell.king@oracle.com, vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org, drjones@redhat.com, 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-20220714_231120_821902_A7DD497A X-CRM114-Status: GOOD ( 15.52 ) 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 --- 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);