#include <asm/stacktrace/common.h>
 
+/*
+ * kvm_nvhe_unwind_init - Start an unwind from the given nVHE HYP fp and pc
+ *
+ * @state : unwind_state to initialize
+ * @fp    : frame pointer at which to start the unwinding.
+ * @pc    : program counter at which to start the unwinding.
+ */
+static inline void kvm_nvhe_unwind_init(struct unwind_state *state,
+                                       unsigned long fp,
+                                       unsigned long pc)
+{
+       unwind_init_common(state, NULL);
+
+       state->fp = fp;
+       state->pc = pc;
+}
+
 static inline bool on_hyp_stack(unsigned long sp, unsigned long size,
                                struct stack_info *info);
 
 
 #include <asm/kvm_emulate.h>
 #include <asm/kvm_mmu.h>
 #include <asm/debug-monitors.h>
+#include <asm/stacktrace/nvhe.h>
 #include <asm/traps.h>
 
 #include <kvm/arm_hypercalls.h>
                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();
+}
+
+/*
+ * 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())
+               return;
+       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,
                                (void *)panic_addr);
        }
 
+       /* Dump the nVHE hypervisor backtrace */
+       kvm_nvhe_dump_backtrace(hyp_offset);
+
        /*
         * Hyp has panicked and we're going to handle that by panicking the
         * kernel. The kernel offset will be revealed in the panic so we're