From patchwork Mon Mar 7 18:49:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12772243 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 BBE4AC433EF for ; Mon, 7 Mar 2022 18:54: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=6TZUSWdclwESL9Ow4NnrGa4c44gUps1KSApRrwZ/1gs=; b=Osa6ZVaHwMYrhG CPm6T/iPcEIitQ38g82C+PGVmnkFLgzFm3AhWnj6tEXHQIzWQDy8wc/Pc49N4i8XgUXwtPAOhOHQN OfiCW0HI8KxoSYV7RIHWFTApumIPNi25dv7kHZNDlrE00m+XVVmC7G8wnjqP2lphkVsqJYqDB7bF0 v+b4bfJlGUdwg6OyguAqLVn++kKIxUQqBb2BT4Tj5EA6sNhy/nsJr5Xuk9VZy36KHXQ1m5mmH1F1U YxRVmGLav6CUqcxhHsHNxUsnyo7Alq2FX4syEp9EbaDxU8mnTwARO3g2WTl2JcHVwa8UfJ6Mn4frT LLntFLpeWb2JMgyKXG6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nRITj-001EXg-3P; Mon, 07 Mar 2022 18:53:07 +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 1nRITe-001EVW-Rg for linux-arm-kernel@lists.infradead.org; Mon, 07 Mar 2022 18:53:04 +0000 Received: by mail-yb1-xb49.google.com with SMTP id n66-20020a254045000000b0062883b59ddbso14302677yba.12 for ; Mon, 07 Mar 2022 10:53:01 -0800 (PST) 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=UdruCL33ZZYFGiCR380CmESQcj657VbKKdTgZ1Wg8kc=; b=bTmhJBEGbQH5zpBf4K3Tji6NNSug2HBwU66gLQY4V5NmqKRyZhideePdARpKiCOF1c OOXrO4Me1fvF4pmpx411lsWI36L53KeZD78//0S7lZr7sWRneIo6LIZnHduanDKHirrp cW/4+mBILBdF49NaYQQ0ozFhlZCcywn/DUEVKJhd4GnfmL1mzgkqZ3czm1wYzJZkNXS4 qW0Xc4qp7wwzIJVMA4t3smwcBSiVYJXN3TcTP/hWgqOHXc334UibH9+IWo75N0qlPwVC YmStcjlKcadCn3EjrZpBFiXMXsvKRboTwre/t2KGu5JqT/eDWY7BZogvQhmzrK9+elF8 Tk5Q== 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=UdruCL33ZZYFGiCR380CmESQcj657VbKKdTgZ1Wg8kc=; b=Wc0mPsRI9cMOwsjUv8ouMqGUqfI12Et8PnPKxWeoYl7EMG7QSJMWufRpZDcqheLqAW LRjpq/CQv8Hd8vPNBvlncudGUgyNgKkZMx5j4x0MhFcbHzXG1e4pjpRZBEVWIwfYgirj 30WI7ez1389lqOglP5jVxG3WXsKulioyPK3B7C/VfL8BXLx1Z2b30xdXd38cxlmXEkxO vtV2I4juq6tPpiFTHaE65qxhy+RjUgn5gPU/+I7jfiIZtGdZ41bJwoeNKn0AEwBHHCAU 7kuo/G+Qd8bmHlW2TYUCG+50kma3BHSd0dK4dN2P+MD84/EFJatmTCkSqsNOke9aVs67 N/Ig== X-Gm-Message-State: AOAM533ASKqNWyUXknKe8eCKUeslbhkLj88P5r9XBGQtsF3w4hVLodVN iRpDObd1G9UaYC4IswympP4g7JEkkrwc+WY/mQ== X-Google-Smtp-Source: ABdhPJwG45Vn5BAyOQ+RCPGdUX9ElV2nKbX47V20HlQVVZhmpw653i9aEL2BOEqCy0uZFwnil4o/gkljjwS9kfExXA== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:dd66:1e7d:1858:4587]) (user=kaleshsingh job=sendgmr) by 2002:a25:be85:0:b0:61d:7838:c9a2 with SMTP id i5-20020a25be85000000b0061d7838c9a2mr9060538ybk.364.1646679180921; Mon, 07 Mar 2022 10:53:00 -0800 (PST) Date: Mon, 7 Mar 2022 10:49:04 -0800 In-Reply-To: <20220307184935.1704614-1-kaleshsingh@google.com> Message-Id: <20220307184935.1704614-7-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220307184935.1704614-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v5 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" , Stephen Boyd , Andrew Walbran , Andrew Scull , Ard Biesheuvel , 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-20220307_105302_941264_A32F2DC5 X-CRM114-Status: GOOD ( 14.77 ) 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 --- 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;