From: Marc Zyngier <maz@kernel.org>
To: linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: wangkefeng.wang@huawei.com, catalin.marinas@arm.com,
ast@kernel.org, vincenzo.frascino@arm.com,
madvenka@linux.microsoft.com, kernel-team@android.com,
elver@google.com, broonie@kernel.org, andreyknvl@gmail.com,
mhiramat@kernel.org
Subject: [PATCH 2/6] KVM: arm64: Move nVHE stacktrace unwinding into its own compilation unit
Date: Wed, 27 Jul 2022 15:29:02 +0100 [thread overview]
Message-ID: <20220727142906.1856759-3-maz@kernel.org> (raw)
In-Reply-To: <20220727142906.1856759-1-maz@kernel.org>
The unwinding code doesn't really belong to the exit handling
code. Instead, move it to a file (conveniently named stacktrace.c
to confuse the reviewer), and move all the stacktrace-related
stuff there.
It will be joined by more code very soon.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/stacktrace/nvhe.h | 2 +
arch/arm64/kvm/Makefile | 2 +-
arch/arm64/kvm/handle_exit.c | 98 ------------------
arch/arm64/kvm/stacktrace.c | 120 +++++++++++++++++++++++
4 files changed, 123 insertions(+), 99 deletions(-)
create mode 100644 arch/arm64/kvm/stacktrace.c
diff --git a/arch/arm64/include/asm/stacktrace/nvhe.h b/arch/arm64/include/asm/stacktrace/nvhe.h
index 600dbc2220b6..8a5cb96d7143 100644
--- a/arch/arm64/include/asm/stacktrace/nvhe.h
+++ b/arch/arm64/include/asm/stacktrace/nvhe.h
@@ -172,5 +172,7 @@ static inline int notrace unwind_next(struct unwind_state *state)
}
NOKPROBE_SYMBOL(unwind_next);
+void kvm_nvhe_dump_backtrace(unsigned long hyp_offset);
+
#endif /* __KVM_NVHE_HYPERVISOR__ */
#endif /* __ASM_STACKTRACE_NVHE_H */
diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
index aa127ae9f675..5e33c2d4645a 100644
--- a/arch/arm64/kvm/Makefile
+++ b/arch/arm64/kvm/Makefile
@@ -12,7 +12,7 @@ obj-$(CONFIG_KVM) += hyp/
kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
inject_fault.o va_layout.o handle_exit.o \
- guest.o debug.o reset.o sys_regs.o \
+ guest.o debug.o reset.o sys_regs.o stacktrace.o \
vgic-sys-reg-v3.o fpsimd.o pkvm.o \
arch_timer.o trng.o vmid.o \
vgic/vgic.o vgic/vgic-init.o \
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index c14fc4ba4422..ef8b57953aa2 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -319,104 +319,6 @@ void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index)
kvm_handle_guest_serror(vcpu, kvm_vcpu_get_esr(vcpu));
}
-/*
- * kvm_nvhe_dump_backtrace_entry - Symbolize and print an nVHE backtrace entry
- *
- * @arg : the hypervisor offset, used for address translation
- * @where : the program counter corresponding to the stack frame
- */
-static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
-{
- unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
- unsigned long hyp_offset = (unsigned long)arg;
-
- /* Mask tags and convert to kern addr */
- where = (where & va_mask) + hyp_offset;
- kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
-
- return true;
-}
-
-static inline void kvm_nvhe_dump_backtrace_start(void)
-{
- kvm_err("nVHE call trace:\n");
-}
-
-static inline void kvm_nvhe_dump_backtrace_end(void)
-{
- kvm_err("---[ end nVHE call trace ]---\n");
-}
-
-/*
- * hyp_dump_backtrace - Dump the non-protected nVHE backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- *
- * The host can directly access HYP stack pages in non-protected
- * mode, so the unwinding is done directly from EL1. This removes
- * the need for shared buffers between host and hypervisor for
- * the stacktrace.
- */
-static void hyp_dump_backtrace(unsigned long hyp_offset)
-{
- struct kvm_nvhe_stacktrace_info *stacktrace_info;
- struct unwind_state state;
-
- stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
-
- kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
-
- kvm_nvhe_dump_backtrace_start();
- unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
- kvm_nvhe_dump_backtrace_end();
-}
-
-#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
-DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
- pkvm_stacktrace);
-
-/*
- * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- *
- * Dumping of the pKVM HYP backtrace is done by reading the
- * stack addresses from the shared stacktrace buffer, since the
- * host cannot directly access hypervisor memory in protected
- * mode.
- */
-static void pkvm_dump_backtrace(unsigned long hyp_offset)
-{
- unsigned long *stacktrace
- = (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
- int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
-
- kvm_nvhe_dump_backtrace_start();
- /* The saved stacktrace is terminated by a null entry */
- for (i = 0; i < size && stacktrace[i]; i++)
- kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
- kvm_nvhe_dump_backtrace_end();
-}
-#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
-static void pkvm_dump_backtrace(unsigned long hyp_offset)
-{
- kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
-}
-#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
-
-/*
- * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- */
-static void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
-{
- if (is_protected_kvm_enabled())
- pkvm_dump_backtrace(hyp_offset);
- else
- hyp_dump_backtrace(hyp_offset);
-}
-
void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
u64 elr_virt, u64 elr_phys,
u64 par, uintptr_t vcpu,
diff --git a/arch/arm64/kvm/stacktrace.c b/arch/arm64/kvm/stacktrace.c
new file mode 100644
index 000000000000..9812aefdcfb4
--- /dev/null
+++ b/arch/arm64/kvm/stacktrace.c
@@ -0,0 +1,120 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * KVM nVHE hypervisor stack tracing support.
+ *
+ * The unwinder implementation depends on the nVHE mode:
+ *
+ * 1) Non-protected nVHE mode - the host can directly access the
+ * HYP stack pages and unwind the HYP stack in EL1. This saves having
+ * to allocate shared buffers for the host to read the unwinded
+ * stacktrace.
+ *
+ * 2) pKVM (protected nVHE) mode - the host cannot directly access
+ * the HYP memory. The stack is unwinded in EL2 and dumped to a shared
+ * buffer where the host can read and print the stacktrace.
+ *
+ * Copyright (C) 2022 Google LLC
+ */
+
+#include <linux/kvm.h>
+#include <linux/kvm_host.h>
+
+#include <asm/stacktrace/nvhe.h>
+
+/*
+ * kvm_nvhe_dump_backtrace_entry - Symbolize and print an nVHE backtrace entry
+ *
+ * @arg : the hypervisor offset, used for address translation
+ * @where : the program counter corresponding to the stack frame
+ */
+static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
+{
+ unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
+ unsigned long hyp_offset = (unsigned long)arg;
+
+ /* Mask tags and convert to kern addr */
+ where = (where & va_mask) + hyp_offset;
+ kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
+
+ return true;
+}
+
+static void kvm_nvhe_dump_backtrace_start(void)
+{
+ kvm_err("nVHE call trace:\n");
+}
+
+static void kvm_nvhe_dump_backtrace_end(void)
+{
+ kvm_err("---[ end nVHE call trace ]---\n");
+}
+
+/*
+ * hyp_dump_backtrace - Dump the non-protected nVHE backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ *
+ * The host can directly access HYP stack pages in non-protected
+ * mode, so the unwinding is done directly from EL1. This removes
+ * the need for shared buffers between host and hypervisor for
+ * the stacktrace.
+ */
+static void hyp_dump_backtrace(unsigned long hyp_offset)
+{
+ struct kvm_nvhe_stacktrace_info *stacktrace_info;
+ struct unwind_state state;
+
+ stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
+
+ kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
+
+ kvm_nvhe_dump_backtrace_start();
+ unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
+ kvm_nvhe_dump_backtrace_end();
+}
+
+#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
+DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
+ pkvm_stacktrace);
+
+/*
+ * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ *
+ * Dumping of the pKVM HYP backtrace is done by reading the
+ * stack addresses from the shared stacktrace buffer, since the
+ * host cannot directly access hypervisor memory in protected
+ * mode.
+ */
+static void pkvm_dump_backtrace(unsigned long hyp_offset)
+{
+ unsigned long *stacktrace
+ = (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
+ int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
+
+ kvm_nvhe_dump_backtrace_start();
+ /* The saved stacktrace is terminated by a null entry */
+ for (i = 0; i < size && stacktrace[i]; i++)
+ kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
+ kvm_nvhe_dump_backtrace_end();
+}
+#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
+static void pkvm_dump_backtrace(unsigned long hyp_offset)
+{
+ kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
+}
+#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
+
+/*
+ * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ */
+void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
+{
+ if (is_protected_kvm_enabled())
+ pkvm_dump_backtrace(hyp_offset);
+ else
+ hyp_dump_backtrace(hyp_offset);
+}
--
2.34.1
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: mark.rutland@arm.com, broonie@kernel.org,
madvenka@linux.microsoft.com, tabba@google.com,
oliver.upton@linux.dev, qperret@google.com,
kaleshsingh@google.com, james.morse@arm.com,
alexandru.elisei@arm.com, suzuki.poulose@arm.com,
catalin.marinas@arm.com, andreyknvl@gmail.com,
vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org,
wangkefeng.wang@huawei.com, elver@google.com, keirf@google.com,
yuzenghui@huawei.com, ardb@kernel.org, oupton@google.com,
kernel-team@android.com
Subject: [PATCH 2/6] KVM: arm64: Move nVHE stacktrace unwinding into its own compilation unit
Date: Wed, 27 Jul 2022 15:29:02 +0100 [thread overview]
Message-ID: <20220727142906.1856759-3-maz@kernel.org> (raw)
In-Reply-To: <20220727142906.1856759-1-maz@kernel.org>
The unwinding code doesn't really belong to the exit handling
code. Instead, move it to a file (conveniently named stacktrace.c
to confuse the reviewer), and move all the stacktrace-related
stuff there.
It will be joined by more code very soon.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/stacktrace/nvhe.h | 2 +
arch/arm64/kvm/Makefile | 2 +-
arch/arm64/kvm/handle_exit.c | 98 ------------------
arch/arm64/kvm/stacktrace.c | 120 +++++++++++++++++++++++
4 files changed, 123 insertions(+), 99 deletions(-)
create mode 100644 arch/arm64/kvm/stacktrace.c
diff --git a/arch/arm64/include/asm/stacktrace/nvhe.h b/arch/arm64/include/asm/stacktrace/nvhe.h
index 600dbc2220b6..8a5cb96d7143 100644
--- a/arch/arm64/include/asm/stacktrace/nvhe.h
+++ b/arch/arm64/include/asm/stacktrace/nvhe.h
@@ -172,5 +172,7 @@ static inline int notrace unwind_next(struct unwind_state *state)
}
NOKPROBE_SYMBOL(unwind_next);
+void kvm_nvhe_dump_backtrace(unsigned long hyp_offset);
+
#endif /* __KVM_NVHE_HYPERVISOR__ */
#endif /* __ASM_STACKTRACE_NVHE_H */
diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
index aa127ae9f675..5e33c2d4645a 100644
--- a/arch/arm64/kvm/Makefile
+++ b/arch/arm64/kvm/Makefile
@@ -12,7 +12,7 @@ obj-$(CONFIG_KVM) += hyp/
kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
inject_fault.o va_layout.o handle_exit.o \
- guest.o debug.o reset.o sys_regs.o \
+ guest.o debug.o reset.o sys_regs.o stacktrace.o \
vgic-sys-reg-v3.o fpsimd.o pkvm.o \
arch_timer.o trng.o vmid.o \
vgic/vgic.o vgic/vgic-init.o \
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index c14fc4ba4422..ef8b57953aa2 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -319,104 +319,6 @@ void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index)
kvm_handle_guest_serror(vcpu, kvm_vcpu_get_esr(vcpu));
}
-/*
- * kvm_nvhe_dump_backtrace_entry - Symbolize and print an nVHE backtrace entry
- *
- * @arg : the hypervisor offset, used for address translation
- * @where : the program counter corresponding to the stack frame
- */
-static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
-{
- unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
- unsigned long hyp_offset = (unsigned long)arg;
-
- /* Mask tags and convert to kern addr */
- where = (where & va_mask) + hyp_offset;
- kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
-
- return true;
-}
-
-static inline void kvm_nvhe_dump_backtrace_start(void)
-{
- kvm_err("nVHE call trace:\n");
-}
-
-static inline void kvm_nvhe_dump_backtrace_end(void)
-{
- kvm_err("---[ end nVHE call trace ]---\n");
-}
-
-/*
- * hyp_dump_backtrace - Dump the non-protected nVHE backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- *
- * The host can directly access HYP stack pages in non-protected
- * mode, so the unwinding is done directly from EL1. This removes
- * the need for shared buffers between host and hypervisor for
- * the stacktrace.
- */
-static void hyp_dump_backtrace(unsigned long hyp_offset)
-{
- struct kvm_nvhe_stacktrace_info *stacktrace_info;
- struct unwind_state state;
-
- stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
-
- kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
-
- kvm_nvhe_dump_backtrace_start();
- unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
- kvm_nvhe_dump_backtrace_end();
-}
-
-#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
-DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
- pkvm_stacktrace);
-
-/*
- * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- *
- * Dumping of the pKVM HYP backtrace is done by reading the
- * stack addresses from the shared stacktrace buffer, since the
- * host cannot directly access hypervisor memory in protected
- * mode.
- */
-static void pkvm_dump_backtrace(unsigned long hyp_offset)
-{
- unsigned long *stacktrace
- = (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
- int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
-
- kvm_nvhe_dump_backtrace_start();
- /* The saved stacktrace is terminated by a null entry */
- for (i = 0; i < size && stacktrace[i]; i++)
- kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
- kvm_nvhe_dump_backtrace_end();
-}
-#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
-static void pkvm_dump_backtrace(unsigned long hyp_offset)
-{
- kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
-}
-#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
-
-/*
- * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- */
-static void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
-{
- if (is_protected_kvm_enabled())
- pkvm_dump_backtrace(hyp_offset);
- else
- hyp_dump_backtrace(hyp_offset);
-}
-
void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
u64 elr_virt, u64 elr_phys,
u64 par, uintptr_t vcpu,
diff --git a/arch/arm64/kvm/stacktrace.c b/arch/arm64/kvm/stacktrace.c
new file mode 100644
index 000000000000..9812aefdcfb4
--- /dev/null
+++ b/arch/arm64/kvm/stacktrace.c
@@ -0,0 +1,120 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * KVM nVHE hypervisor stack tracing support.
+ *
+ * The unwinder implementation depends on the nVHE mode:
+ *
+ * 1) Non-protected nVHE mode - the host can directly access the
+ * HYP stack pages and unwind the HYP stack in EL1. This saves having
+ * to allocate shared buffers for the host to read the unwinded
+ * stacktrace.
+ *
+ * 2) pKVM (protected nVHE) mode - the host cannot directly access
+ * the HYP memory. The stack is unwinded in EL2 and dumped to a shared
+ * buffer where the host can read and print the stacktrace.
+ *
+ * Copyright (C) 2022 Google LLC
+ */
+
+#include <linux/kvm.h>
+#include <linux/kvm_host.h>
+
+#include <asm/stacktrace/nvhe.h>
+
+/*
+ * kvm_nvhe_dump_backtrace_entry - Symbolize and print an nVHE backtrace entry
+ *
+ * @arg : the hypervisor offset, used for address translation
+ * @where : the program counter corresponding to the stack frame
+ */
+static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
+{
+ unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
+ unsigned long hyp_offset = (unsigned long)arg;
+
+ /* Mask tags and convert to kern addr */
+ where = (where & va_mask) + hyp_offset;
+ kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
+
+ return true;
+}
+
+static void kvm_nvhe_dump_backtrace_start(void)
+{
+ kvm_err("nVHE call trace:\n");
+}
+
+static void kvm_nvhe_dump_backtrace_end(void)
+{
+ kvm_err("---[ end nVHE call trace ]---\n");
+}
+
+/*
+ * hyp_dump_backtrace - Dump the non-protected nVHE backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ *
+ * The host can directly access HYP stack pages in non-protected
+ * mode, so the unwinding is done directly from EL1. This removes
+ * the need for shared buffers between host and hypervisor for
+ * the stacktrace.
+ */
+static void hyp_dump_backtrace(unsigned long hyp_offset)
+{
+ struct kvm_nvhe_stacktrace_info *stacktrace_info;
+ struct unwind_state state;
+
+ stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
+
+ kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
+
+ kvm_nvhe_dump_backtrace_start();
+ unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
+ kvm_nvhe_dump_backtrace_end();
+}
+
+#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
+DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
+ pkvm_stacktrace);
+
+/*
+ * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ *
+ * Dumping of the pKVM HYP backtrace is done by reading the
+ * stack addresses from the shared stacktrace buffer, since the
+ * host cannot directly access hypervisor memory in protected
+ * mode.
+ */
+static void pkvm_dump_backtrace(unsigned long hyp_offset)
+{
+ unsigned long *stacktrace
+ = (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
+ int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
+
+ kvm_nvhe_dump_backtrace_start();
+ /* The saved stacktrace is terminated by a null entry */
+ for (i = 0; i < size && stacktrace[i]; i++)
+ kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
+ kvm_nvhe_dump_backtrace_end();
+}
+#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
+static void pkvm_dump_backtrace(unsigned long hyp_offset)
+{
+ kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
+}
+#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
+
+/*
+ * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ */
+void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
+{
+ if (is_protected_kvm_enabled())
+ pkvm_dump_backtrace(hyp_offset);
+ else
+ hyp_dump_backtrace(hyp_offset);
+}
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: mark.rutland@arm.com, broonie@kernel.org,
madvenka@linux.microsoft.com, tabba@google.com,
oliver.upton@linux.dev, qperret@google.com,
kaleshsingh@google.com, james.morse@arm.com,
alexandru.elisei@arm.com, suzuki.poulose@arm.com,
catalin.marinas@arm.com, andreyknvl@gmail.com,
vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org,
wangkefeng.wang@huawei.com, elver@google.com, keirf@google.com,
yuzenghui@huawei.com, ardb@kernel.org, oupton@google.com,
kernel-team@android.com
Subject: [PATCH 2/6] KVM: arm64: Move nVHE stacktrace unwinding into its own compilation unit
Date: Wed, 27 Jul 2022 15:29:02 +0100 [thread overview]
Message-ID: <20220727142906.1856759-3-maz@kernel.org> (raw)
In-Reply-To: <20220727142906.1856759-1-maz@kernel.org>
The unwinding code doesn't really belong to the exit handling
code. Instead, move it to a file (conveniently named stacktrace.c
to confuse the reviewer), and move all the stacktrace-related
stuff there.
It will be joined by more code very soon.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/stacktrace/nvhe.h | 2 +
arch/arm64/kvm/Makefile | 2 +-
arch/arm64/kvm/handle_exit.c | 98 ------------------
arch/arm64/kvm/stacktrace.c | 120 +++++++++++++++++++++++
4 files changed, 123 insertions(+), 99 deletions(-)
create mode 100644 arch/arm64/kvm/stacktrace.c
diff --git a/arch/arm64/include/asm/stacktrace/nvhe.h b/arch/arm64/include/asm/stacktrace/nvhe.h
index 600dbc2220b6..8a5cb96d7143 100644
--- a/arch/arm64/include/asm/stacktrace/nvhe.h
+++ b/arch/arm64/include/asm/stacktrace/nvhe.h
@@ -172,5 +172,7 @@ static inline int notrace unwind_next(struct unwind_state *state)
}
NOKPROBE_SYMBOL(unwind_next);
+void kvm_nvhe_dump_backtrace(unsigned long hyp_offset);
+
#endif /* __KVM_NVHE_HYPERVISOR__ */
#endif /* __ASM_STACKTRACE_NVHE_H */
diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile
index aa127ae9f675..5e33c2d4645a 100644
--- a/arch/arm64/kvm/Makefile
+++ b/arch/arm64/kvm/Makefile
@@ -12,7 +12,7 @@ obj-$(CONFIG_KVM) += hyp/
kvm-y += arm.o mmu.o mmio.o psci.o hypercalls.o pvtime.o \
inject_fault.o va_layout.o handle_exit.o \
- guest.o debug.o reset.o sys_regs.o \
+ guest.o debug.o reset.o sys_regs.o stacktrace.o \
vgic-sys-reg-v3.o fpsimd.o pkvm.o \
arch_timer.o trng.o vmid.o \
vgic/vgic.o vgic/vgic-init.o \
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index c14fc4ba4422..ef8b57953aa2 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -319,104 +319,6 @@ void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index)
kvm_handle_guest_serror(vcpu, kvm_vcpu_get_esr(vcpu));
}
-/*
- * kvm_nvhe_dump_backtrace_entry - Symbolize and print an nVHE backtrace entry
- *
- * @arg : the hypervisor offset, used for address translation
- * @where : the program counter corresponding to the stack frame
- */
-static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
-{
- unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
- unsigned long hyp_offset = (unsigned long)arg;
-
- /* Mask tags and convert to kern addr */
- where = (where & va_mask) + hyp_offset;
- kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
-
- return true;
-}
-
-static inline void kvm_nvhe_dump_backtrace_start(void)
-{
- kvm_err("nVHE call trace:\n");
-}
-
-static inline void kvm_nvhe_dump_backtrace_end(void)
-{
- kvm_err("---[ end nVHE call trace ]---\n");
-}
-
-/*
- * hyp_dump_backtrace - Dump the non-protected nVHE backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- *
- * The host can directly access HYP stack pages in non-protected
- * mode, so the unwinding is done directly from EL1. This removes
- * the need for shared buffers between host and hypervisor for
- * the stacktrace.
- */
-static void hyp_dump_backtrace(unsigned long hyp_offset)
-{
- struct kvm_nvhe_stacktrace_info *stacktrace_info;
- struct unwind_state state;
-
- stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
-
- kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
-
- kvm_nvhe_dump_backtrace_start();
- unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
- kvm_nvhe_dump_backtrace_end();
-}
-
-#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
-DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
- pkvm_stacktrace);
-
-/*
- * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- *
- * Dumping of the pKVM HYP backtrace is done by reading the
- * stack addresses from the shared stacktrace buffer, since the
- * host cannot directly access hypervisor memory in protected
- * mode.
- */
-static void pkvm_dump_backtrace(unsigned long hyp_offset)
-{
- unsigned long *stacktrace
- = (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
- int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
-
- kvm_nvhe_dump_backtrace_start();
- /* The saved stacktrace is terminated by a null entry */
- for (i = 0; i < size && stacktrace[i]; i++)
- kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
- kvm_nvhe_dump_backtrace_end();
-}
-#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
-static void pkvm_dump_backtrace(unsigned long hyp_offset)
-{
- kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
-}
-#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
-
-/*
- * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
- *
- * @hyp_offset: hypervisor offset, used for address translation.
- */
-static void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
-{
- if (is_protected_kvm_enabled())
- pkvm_dump_backtrace(hyp_offset);
- else
- hyp_dump_backtrace(hyp_offset);
-}
-
void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
u64 elr_virt, u64 elr_phys,
u64 par, uintptr_t vcpu,
diff --git a/arch/arm64/kvm/stacktrace.c b/arch/arm64/kvm/stacktrace.c
new file mode 100644
index 000000000000..9812aefdcfb4
--- /dev/null
+++ b/arch/arm64/kvm/stacktrace.c
@@ -0,0 +1,120 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * KVM nVHE hypervisor stack tracing support.
+ *
+ * The unwinder implementation depends on the nVHE mode:
+ *
+ * 1) Non-protected nVHE mode - the host can directly access the
+ * HYP stack pages and unwind the HYP stack in EL1. This saves having
+ * to allocate shared buffers for the host to read the unwinded
+ * stacktrace.
+ *
+ * 2) pKVM (protected nVHE) mode - the host cannot directly access
+ * the HYP memory. The stack is unwinded in EL2 and dumped to a shared
+ * buffer where the host can read and print the stacktrace.
+ *
+ * Copyright (C) 2022 Google LLC
+ */
+
+#include <linux/kvm.h>
+#include <linux/kvm_host.h>
+
+#include <asm/stacktrace/nvhe.h>
+
+/*
+ * kvm_nvhe_dump_backtrace_entry - Symbolize and print an nVHE backtrace entry
+ *
+ * @arg : the hypervisor offset, used for address translation
+ * @where : the program counter corresponding to the stack frame
+ */
+static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
+{
+ unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
+ unsigned long hyp_offset = (unsigned long)arg;
+
+ /* Mask tags and convert to kern addr */
+ where = (where & va_mask) + hyp_offset;
+ kvm_err(" [<%016lx>] %pB\n", where, (void *)(where + kaslr_offset()));
+
+ return true;
+}
+
+static void kvm_nvhe_dump_backtrace_start(void)
+{
+ kvm_err("nVHE call trace:\n");
+}
+
+static void kvm_nvhe_dump_backtrace_end(void)
+{
+ kvm_err("---[ end nVHE call trace ]---\n");
+}
+
+/*
+ * hyp_dump_backtrace - Dump the non-protected nVHE backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ *
+ * The host can directly access HYP stack pages in non-protected
+ * mode, so the unwinding is done directly from EL1. This removes
+ * the need for shared buffers between host and hypervisor for
+ * the stacktrace.
+ */
+static void hyp_dump_backtrace(unsigned long hyp_offset)
+{
+ struct kvm_nvhe_stacktrace_info *stacktrace_info;
+ struct unwind_state state;
+
+ stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
+
+ kvm_nvhe_unwind_init(&state, stacktrace_info->fp, stacktrace_info->pc);
+
+ kvm_nvhe_dump_backtrace_start();
+ unwind(&state, kvm_nvhe_dump_backtrace_entry, (void *)hyp_offset);
+ kvm_nvhe_dump_backtrace_end();
+}
+
+#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
+DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
+ pkvm_stacktrace);
+
+/*
+ * pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ *
+ * Dumping of the pKVM HYP backtrace is done by reading the
+ * stack addresses from the shared stacktrace buffer, since the
+ * host cannot directly access hypervisor memory in protected
+ * mode.
+ */
+static void pkvm_dump_backtrace(unsigned long hyp_offset)
+{
+ unsigned long *stacktrace
+ = (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
+ int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
+
+ kvm_nvhe_dump_backtrace_start();
+ /* The saved stacktrace is terminated by a null entry */
+ for (i = 0; i < size && stacktrace[i]; i++)
+ kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
+ kvm_nvhe_dump_backtrace_end();
+}
+#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
+static void pkvm_dump_backtrace(unsigned long hyp_offset)
+{
+ kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
+}
+#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
+
+/*
+ * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
+ *
+ * @hyp_offset: hypervisor offset, used for address translation.
+ */
+void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
+{
+ if (is_protected_kvm_enabled())
+ pkvm_dump_backtrace(hyp_offset);
+ else
+ hyp_dump_backtrace(hyp_offset);
+}
--
2.34.1
next prev parent reply other threads:[~2022-07-27 14:29 UTC|newest]
Thread overview: 112+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-26 7:37 [PATCH v6 00/17] KVM nVHE Hypervisor stack unwinder Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 01/17] arm64: stacktrace: Add shared header for common stack unwinding code Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 02/17] arm64: stacktrace: Factor out on_accessible_stack_common() Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 16:01 ` Marc Zyngier
2022-07-26 16:01 ` Marc Zyngier
2022-07-26 16:01 ` Marc Zyngier
2022-07-26 16:33 ` Kalesh Singh
2022-07-26 16:33 ` Kalesh Singh
2022-07-26 16:33 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 03/17] arm64: stacktrace: Factor out unwind_next_common() Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 04/17] arm64: stacktrace: Handle frame pointer from different address spaces Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 14:34 ` Mark Brown
2022-07-26 14:34 ` Mark Brown
2022-07-26 14:34 ` Mark Brown
2022-07-26 15:30 ` Kalesh Singh
2022-07-26 15:30 ` Kalesh Singh
2022-07-26 15:30 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 05/17] arm64: stacktrace: Factor out common unwind() Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 06/17] arm64: stacktrace: Add description of stacktrace/common.h Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 14:49 ` Mark Brown
2022-07-26 14:49 ` Mark Brown
2022-07-26 14:49 ` Mark Brown
2022-07-26 7:37 ` [PATCH v6 07/17] KVM: arm64: On stack overflow switch to hyp overflow_stack Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 08/17] KVM: arm64: Stub implementation of non-protected nVHE HYP stack unwinder Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 09/17] KVM: arm64: Prepare non-protected nVHE hypervisor stacktrace Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 16:26 ` kernel test robot
2022-07-26 7:37 ` [PATCH v6 10/17] KVM: arm64: Implement non-protected nVHE hyp stack unwinder Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 11/17] KVM: arm64: Introduce hyp_dump_backtrace() Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 12/17] KVM: arm64: Add PROTECTED_NVHE_STACKTRACE Kconfig Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 10:00 ` Marc Zyngier
2022-07-26 10:00 ` Marc Zyngier
2022-07-26 10:00 ` Marc Zyngier
2022-07-26 15:33 ` Kalesh Singh
2022-07-26 15:33 ` Kalesh Singh
2022-07-26 15:33 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 13/17] KVM: arm64: Allocate shared pKVM hyp stacktrace buffers Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 14/17] KVM: arm64: Stub implementation of pKVM HYP stack unwinder Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 15/17] KVM: arm64: Save protected-nVHE (pKVM) hyp stacktrace Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 16/17] KVM: arm64: Implement protected nVHE hyp stack unwinder Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` [PATCH v6 17/17] KVM: arm64: Introduce pkvm_dump_backtrace() Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-26 7:37 ` Kalesh Singh
2022-07-27 14:29 ` [PATCH 0/6] KVM: arm64: nVHE stack unwinder rework Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` [PATCH 1/6] KVM: arm64: Move PROTECTED_NVHE_STACKTRACE around Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier [this message]
2022-07-27 14:29 ` [PATCH 2/6] KVM: arm64: Move nVHE stacktrace unwinding into its own compilation unit Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` [PATCH 3/6] KVM: arm64: Make unwind()/on_accessible_stack() per-unwinder functions Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 17:32 ` Mark Brown
2022-07-27 17:32 ` Mark Brown
2022-07-27 17:32 ` Mark Brown
2022-07-27 14:29 ` [PATCH 4/6] KVM: arm64: Move nVHE-only helpers into kvm/stacktrace.c Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` [PATCH 5/6] KVM: arm64: Don't open code ARRAY_SIZE() Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` [PATCH 6/6] arm64: Update 'unwinder howto' Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 14:29 ` Marc Zyngier
2022-07-27 15:56 ` [PATCH 0/6] KVM: arm64: nVHE stack unwinder rework Kalesh Singh
2022-07-27 15:56 ` Kalesh Singh
2022-07-27 15:56 ` Kalesh Singh
2022-07-27 16:01 ` Oliver Upton
2022-07-27 16:01 ` Oliver Upton
2022-07-27 16:01 ` Oliver Upton
2022-07-27 17:45 ` Marc Zyngier
2022-07-27 17:45 ` Marc Zyngier
2022-07-27 17:45 ` Marc Zyngier
2022-07-27 17:44 ` [PATCH v6 00/17] KVM nVHE Hypervisor stack unwinder Marc Zyngier
2022-07-27 17:44 ` Marc Zyngier
2022-07-27 17:44 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220727142906.1856759-3-maz@kernel.org \
--to=maz@kernel.org \
--cc=andreyknvl@gmail.com \
--cc=ast@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=elver@google.com \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=madvenka@linux.microsoft.com \
--cc=mhiramat@kernel.org \
--cc=vincenzo.frascino@arm.com \
--cc=wangkefeng.wang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.