Skip to content

Commit 3a7e1b5

Browse files
Kalesh SinghMarc Zyngier
authored andcommitted
KVM: arm64: Introduce pkvm_dump_backtrace()
Dumps the pKVM hypervisor backtrace from EL1 by reading the unwinded addresses from the shared stacktrace buffer. The nVHE hyp backtrace is dumped on hyp_panic(), before panicking the host. [ 111.623091] kvm [367]: nVHE call trace: [ 111.623215] kvm [367]: [<ffff8000090a6570>] __kvm_nvhe_hyp_panic+0xac/0xf8 [ 111.623448] kvm [367]: [<ffff8000090a65cc>] __kvm_nvhe_hyp_panic_bad_stack+0x10/0x10 [ 111.623642] kvm [367]: [<ffff8000090a61e4>] __kvm_nvhe_recursive_death+0x24/0x34 . . . [ 111.640366] kvm [367]: [<ffff8000090a61e4>] __kvm_nvhe_recursive_death+0x24/0x34 [ 111.640467] kvm [367]: [<ffff8000090a61e4>] __kvm_nvhe_recursive_death+0x24/0x34 [ 111.640574] kvm [367]: [<ffff8000090a5de4>] __kvm_nvhe___kvm_vcpu_run+0x30/0x40c [ 111.640676] kvm [367]: [<ffff8000090a8b64>] __kvm_nvhe_handle___kvm_vcpu_run+0x30/0x48 [ 111.640778] kvm [367]: [<ffff8000090a88b8>] __kvm_nvhe_handle_trap+0xc4/0x128 [ 111.640880] kvm [367]: [<ffff8000090a7864>] __kvm_nvhe___host_exit+0x64/0x64 [ 111.640996] kvm [367]: ---[ end nVHE call trace ]--- Signed-off-by: Kalesh Singh <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 75e9459 commit 3a7e1b5

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

arch/arm64/kvm/handle_exit.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,39 @@ static void hyp_dump_backtrace(unsigned long hyp_offset)
371371
kvm_nvhe_dump_backtrace_end();
372372
}
373373

374+
#ifdef CONFIG_PROTECTED_NVHE_STACKTRACE
375+
DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)],
376+
pkvm_stacktrace);
377+
378+
/*
379+
* pkvm_dump_backtrace - Dump the protected nVHE HYP backtrace.
380+
*
381+
* @hyp_offset: hypervisor offset, used for address translation.
382+
*
383+
* Dumping of the pKVM HYP backtrace is done by reading the
384+
* stack addresses from the shared stacktrace buffer, since the
385+
* host cannot directly access hypervisor memory in protected
386+
* mode.
387+
*/
388+
static void pkvm_dump_backtrace(unsigned long hyp_offset)
389+
{
390+
unsigned long *stacktrace
391+
= (unsigned long *) this_cpu_ptr_nvhe_sym(pkvm_stacktrace);
392+
int i, size = NVHE_STACKTRACE_SIZE / sizeof(long);
393+
394+
kvm_nvhe_dump_backtrace_start();
395+
/* The saved stacktrace is terminated by a null entry */
396+
for (i = 0; i < size && stacktrace[i]; i++)
397+
kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]);
398+
kvm_nvhe_dump_backtrace_end();
399+
}
400+
#else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */
401+
static void pkvm_dump_backtrace(unsigned long hyp_offset)
402+
{
403+
kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n");
404+
}
405+
#endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */
406+
374407
/*
375408
* kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.
376409
*
@@ -379,7 +412,7 @@ static void hyp_dump_backtrace(unsigned long hyp_offset)
379412
static void kvm_nvhe_dump_backtrace(unsigned long hyp_offset)
380413
{
381414
if (is_protected_kvm_enabled())
382-
return;
415+
pkvm_dump_backtrace(hyp_offset);
383416
else
384417
hyp_dump_backtrace(hyp_offset);
385418
}

0 commit comments

Comments
 (0)