]> www.infradead.org Git - nvme.git/commit
KVM: arm64: Fix clobbered ELR in sync abort/SError
authorPierre-Clément Tosi <ptosi@google.com>
Mon, 10 Jun 2024 06:32:30 +0000 (07:32 +0100)
committerOliver Upton <oliver.upton@linux.dev>
Thu, 20 Jun 2024 17:40:53 +0000 (17:40 +0000)
commita8f0655887cc86db9d65fd5fbaf99d62424eb9b4
tree22bdb2ec5c29ec9902a33304aa2cea8e5dbfd47e
parent83a7eefedc9b56fe7bfeff13b6c7356688ffa670
KVM: arm64: Fix clobbered ELR in sync abort/SError

When the hypervisor receives a SError or synchronous exception (EL2h)
while running with the __kvm_hyp_vector and if ELR_EL2 doesn't point to
an extable entry, it panics indirectly by overwriting ELR with the
address of a panic handler in order for the asm routine it returns to to
ERET into the handler.

However, this clobbers ELR_EL2 for the handler itself. As a result,
hyp_panic(), when retrieving what it believes to be the PC where the
exception happened, actually ends up reading the address of the panic
handler that called it! This results in an erroneous and confusing panic
message where the source of any synchronous exception (e.g. BUG() or
kCFI) appears to be __guest_exit_panic, making it hard to locate the
actual BRK instruction.

Therefore, store the original ELR_EL2 in the per-CPU kvm_hyp_ctxt and
point the sysreg to a routine that first restores it to its previous
value before running __guest_exit_panic.

Fixes: 7db21530479f ("KVM: arm64: Restore hyp when panicking in guest context")
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20240610063244.2828978-2-ptosi@google.com
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kernel/asm-offsets.c
arch/arm64/kvm/hyp/entry.S
arch/arm64/kvm/hyp/include/hyp/switch.h