]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
KVM: arm64: On stack overflow switch to hyp overflow_stack
authorKalesh Singh <kaleshsingh@google.com>
Tue, 26 Jul 2022 07:37:40 +0000 (00:37 -0700)
committerMarc Zyngier <maz@kernel.org>
Tue, 26 Jul 2022 09:49:05 +0000 (10:49 +0100)
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 <kaleshsingh@google.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220726073750.3219117-8-kaleshsingh@google.com
arch/arm64/kvm/hyp/nvhe/Makefile
arch/arm64/kvm/hyp/nvhe/host.S
arch/arm64/kvm/hyp/nvhe/stacktrace.c [new file with mode: 0644]

index f9fe4dc21b1f00896d4a6818ed5304aacd3030d4..524e7dad57399ef1ae092b1b96b7ba153ac9c2f0 100644 (file)
@@ -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
index ea6a397b64a6639242a65d31e114104e1857adbb..b6c0188c4b35a9d6f92d061be09b59030c7cc962 100644 (file)
@@ -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 (file)
index 0000000..a3d5b34
--- /dev/null
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * KVM nVHE hypervisor stack tracing support.
+ *
+ * Copyright (C) 2022 Google LLC
+ */
+#include <asm/memory.h>
+#include <asm/percpu.h>
+
+DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack)
+       __aligned(16);