Skip to content

Dump instructions on panic for pKVM/nvhe

Mostafa Saleh kvmarm linux-arm-kernel lkml 2 versions – Applied

Status from this message: Applied to next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 2 repliesApplied
  2. v12 patches 9 repliesSuperseded

Changes in v2 from the cover letter

- Harden instr dumping based on Will's feedback.
- Collected tags

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/2KVM: arm64: Dump instruction on hyp panicarch/arm64/include/asm/traps.h arch/arm64/kernel/traps.c arch/arm64/kvm/handle_exit.c+15 -61 reply
2/2KVM: arm64: Map hyp text as RO and dump instr on panicarch/arm64/kvm/handle_exit.c arch/arm64/kvm/hyp/nvhe/setup.c+11 -50 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchKunwu ChanWill Deacon
1/2T-b R-b A-b
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] Dump instructions on panic for pKVM/nvhe

This small series, adds support for dumping the faulting instructions on panic in pKVM and nvhe, similarly to what the kernel does as follow:

[   12.012126] kvm [190]: nVHE hyp BUG at: [<ffff8000811c5f64>] __kvm_nvhe_handle___kvm_vcpu_run+0x4/0x8!
[   12.015747] kvm [190]: Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE
[   12.016044] Code: a8c17bfd d50323bf d65f03c0 d503245f (d4210000)
[   12.016082] kvm [190]: Hyp Offset: 0xffeff6887fe00000
[   12.016325] Kernel panic - not syncing: HYP panic:
[   12.016325] PS:204023c9 PC:000f8978013c5f64 ESR:00000000f2000800
[   12.016325] FAR:fff00000c016e01c HPFAR:00000000010016e0 PAR:0000000000000000

This can be useful in debugging cases of memory corruption.

The first patch adds this for nvhe and CONFIG_NVHE_EL2_DEBUG which is straightforward as at the point of panic there is no stage-2 for the host CPU, so it can re-use the kernel code to read and dump the faulting instructions.

The second patch adds this support for pKVM, I splitted that into patches as the pKVM changes are more fundamental, as now the hypervisor text would be mapped in the host stage-2 as RO all the time.
An alternative is to make the hypervisor read its instructions on panic and passes it to the kernel panic handler, but as we are out of registers (X0-X7 used) for the arguments we would have to move that code to assembly.

Changes in v2:
- Harden instr dumping based on Will's feedback.
- Collected tags

Mostafa Saleh (2):
KVM: arm64: Dump instruction on hyp panic
KVM: arm64: Map hyp text as RO and dump instr on panic

 arch/arm64/include/asm/traps.h  |  1 +
 arch/arm64/kernel/traps.c       | 15 +++++++++------
 arch/arm64/kvm/handle_exit.c    |  3 +++
 arch/arm64/kvm/hyp/nvhe/setup.c | 12 ++++++++++--
 4 files changed, 23 insertions(+), 8 deletions(-)
Signature · 1 line
2.51.0.384.g4c02a37b29-goog