KVM: arm64: Allocate shared pKVM hyp stacktrace buffers
authorKalesh Singh <kaleshsingh@google.com>
Tue, 26 Jul 2022 07:37:46 +0000 (00:37 -0700)
committerMarc Zyngier <maz@kernel.org>
Tue, 26 Jul 2022 09:50:12 +0000 (10:50 +0100)
In protected nVHE mode the host cannot directly access
hypervisor memory, so we will dump the hypervisor stacktrace
to a shared buffer with the host.

The minimum size for the buffer required, assuming the min frame
size of [x29, x30] (2 * sizeof(long)), is half the combined size of
the hypervisor and overflow stacks plus an additional entry to
delimit the end of the stacktrace.

The stacktrace buffers are used later in the series to dump the
nVHE hypervisor stacktrace when using protected-mode.

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-14-kaleshsingh@google.com
arch/arm64/include/asm/memory.h
arch/arm64/kvm/hyp/nvhe/stacktrace.c

index 0af70d9abede3d9d65163101da185b4f9d749fa8..cab80a9a4086fa765b5617b93e73065d439c2fc4 100644 (file)
 
 #define OVERFLOW_STACK_SIZE    SZ_4K
 
+/*
+ * With the minimum frame size of [x29, x30], exactly half the combined
+ * sizes of the hyp and overflow stacks is the maximum size needed to
+ * save the unwinded stacktrace; plus an additional entry to delimit the
+ * end.
+ */
+#define NVHE_STACKTRACE_SIZE   ((OVERFLOW_STACK_SIZE + PAGE_SIZE) / 2 + sizeof(long))
+
 /*
  * Alignment of kernel segments (e.g. .text, .data).
  *
index b8a280aa026a8d56baea7b8719f7c80dbc4afc0a..e2edda92a108687acbbd26d174a064ad9656cacb 100644 (file)
@@ -34,6 +34,10 @@ static void hyp_prepare_backtrace(unsigned long fp, unsigned long pc)
        stacktrace_info->pc = pc;
 }
 
+#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
+DEFINE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], pkvm_stacktrace);
+#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
+
 /*
  * kvm_nvhe_prepare_backtrace - prepare to dump the nVHE backtrace
  *