From patchwork Mon Mar 14 20:01:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12780749 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 C4DF0C433EF for ; Mon, 14 Mar 2022 20:07:35 +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:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SODJqK22wp0MfE6ytQ8AmKLB9IxVj+tlfJVuYE2Hh3w=; b=d3QR4HF0M+0YdO LfwWmuJ508HEekK/A2qu1+3WLrZVIZREibfYTnmITr/YjD4JVDb1dtbH1grW6hxqN+UtTupJh+Uka LUhD2x/LTH7++n5Mq9IsraQAs3+Uy+k35fBu5eT6rjwXS9itc/Y5udOasftgc+BVIC857J5j8JB8j 6+5x8RsH//YFyq+veFSpR+UXJ7kKCZ7/E/+yQpNIgl3ZxmG/OIh767Jd0URmPPsT/O/9w1iPhIo0f xzCsi6n5VWG1HAK9wnVjZCNYs1Ciujhkwc5fVcbJ3RO5UHW1W2AB8pK2cH+UFcp73GpvQpJy7/VEr kYSAjfMPiUIYhDnhJ6EQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTqxC-006iX8-6x; Mon, 14 Mar 2022 20:06:06 +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 1nTqwy-006iRJ-Jv for linux-arm-kernel@lists.infradead.org; Mon, 14 Mar 2022 20:05:54 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2d6994a6942so140677677b3.17 for ; Mon, 14 Mar 2022 13:05:51 -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:cc; bh=8f0s79ka6K+xZLjhEa6v9OQwM+zc/G84NFUgH0amXtY=; b=oWMxFcmEuQa7Oz8Msf5z2d2F/+cxSvJeY2AkshA00cCwmDongR92lT++R6u+2wswp/ KeHuRfDuIINh7QuVpmgim0OtP9TVidSBRd8VA4FhF9ErV1otSCPmz+AkktixGdSZwzT8 LCfWw99uiLBPTLjaM7e2GesV6Vr95aJhEjo56x1iSRDgcy1Pi4qC604b7DxcZjF0+c7w /2K0o8E7BBCgilr6vRGvf156M3tc+fnB8epOT0a5sLqt3zWx7hzNiJnGvxaWsM5waXja J6OMDvqIkNbTk3t3YyDVaC5Q3RlFOFXcGH/fE9ejjisH84XYUlCL+8IflYOkwpId7Erp aQEQ== 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:cc; bh=8f0s79ka6K+xZLjhEa6v9OQwM+zc/G84NFUgH0amXtY=; b=dT6tslna2Z+Y30bfle2Bbv8jiowGb+trRwateIr0YprmfcQm5VTlADGVr9/WjblqNQ plA7JsDDDar8dHoI/aFZZ0bYVn0DmRoFsE221kk0hQFLh6rjKlEoVI2I4CIjPGMhMSDf dFtUwvNob0Ski3bed04oFKkp8QYmgge9WDR4B44Wtgd8lX87EXtZLpNXLw4fuOfHJ//h t2Q4UuIv4GQ5H7RA9uQ9WLEcihnSvWzM+HDFwFlOZjlzqugWywK5t07u4PFNYm/h5uld KdRE8YNrHsW4AxHE8LJKAccu5Xv4Sns6LX6FqTgZhsh9HocUTXNNUzSU9XRzv05Q6r+U vLEw== X-Gm-Message-State: AOAM531BtY7i+EIfCoB6PYd3P3gA+Pjl3CZKm2Ugg7Cs8Vg76+Q+aNAz gcrYRdnDYbdycBelQMgoLi5+SblDMC6+TEYQRQ== X-Google-Smtp-Source: ABdhPJxeJ4ERpyXJrRQxcj/bYJNsQODEu20+d8yn9qPL1N8ZlV6KyQDHbDeVHPvOyZo+/DauOEQQySrLcRIvNw+kpA== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:500a:9ac2:e73e:69e3]) (user=kaleshsingh job=sendgmr) by 2002:a5b:712:0:b0:629:5d03:4b1b with SMTP id g18-20020a5b0712000000b006295d034b1bmr19139174ybq.380.1647288351094; Mon, 14 Mar 2022 13:05:51 -0700 (PDT) Date: Mon, 14 Mar 2022 13:01:15 -0700 In-Reply-To: <20220314200148.2695206-1-kaleshsingh@google.com> Message-Id: <20220314200148.2695206-7-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220314200148.2695206-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH v6 6/8] KVM: arm64: Add hypervisor overflow stack From: Kalesh Singh Cc: will@kernel.org, maz@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Mark Rutland , Mark Brown , Masami Hiramatsu , Peter Collingbourne , "Madhavan T. Venkataraman" , Andrew Walbran , Andrew Scull , Andrew Jones , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_130552_699692_963C58E3 X-CRM114-Status: GOOD ( 14.40 ) 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 Allocate and switch to 16-byte aligned secondary stack on overflow. This provides us stack space to better handle overflows; and is used in a subsequent patch to dump the hypervisor stacktrace. The overflow stack is only allocated if CONFIG_NVHE_EL2_DEBUG is enabled, as hypervisor stacktraces is a debug feature dependent on CONFIG_NVHE_EL2_DEBUG. Signed-off-by: Kalesh Singh Tested-by: Fuad Tabba Reviewed-by: Fuad Tabba --- Changes in v4: - Update comment to clarify resetting the SP to the top of the stack only happens if CONFIG_NVHE_EL2_DEBUG is disabled, per Fuad arch/arm64/kvm/hyp/nvhe/host.S | 11 ++++++++--- arch/arm64/kvm/hyp/nvhe/switch.c | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index be6d844279b1..a0c4b4f1549f 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -179,13 +179,18 @@ SYM_FUNC_END(__host_hvc) b hyp_panic .L__hyp_sp_overflow\@: +#ifdef CONFIG_NVHE_EL2_DEBUG + /* Switch to the overflow stack */ + adr_this_cpu sp, hyp_overflow_stack + PAGE_SIZE, x0 +#else /* - * 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. + * If !CONFIG_NVHE_EL2_DEBUG, 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 +#endif bl hyp_panic_bad_stack ASM_BUG() diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index 703a5d3f611b..efc20273a352 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -34,6 +34,11 @@ DEFINE_PER_CPU(struct kvm_host_data, kvm_host_data); DEFINE_PER_CPU(struct kvm_cpu_context, kvm_hyp_ctxt); DEFINE_PER_CPU(unsigned long, kvm_hyp_vector); +#ifdef CONFIG_NVHE_EL2_DEBUG +DEFINE_PER_CPU(unsigned long [PAGE_SIZE/sizeof(long)], hyp_overflow_stack) + __aligned(16); +#endif + static void __activate_traps(struct kvm_vcpu *vcpu) { u64 val;