]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Dump instruction on hyp panic
authorMostafa Saleh <smostafa@google.com>
Tue, 9 Sep 2025 13:36:30 +0000 (13:36 +0000)
committerMarc Zyngier <maz@kernel.org>
Mon, 15 Sep 2025 12:04:22 +0000 (13:04 +0100)
Similar to the kernel panic, where the instruction code is printed,
we can do the same for hypervisor panics.

This patch does that only in case of “CONFIG_NVHE_EL2_DEBUG” or nvhe.

The next patch adds support for pKVM.

Also, remove the hardcoded argument dump_kernel_instr().

Signed-off-by: Mostafa Saleh <smostafa@google.com>
Tested-by: Kunwu Chan <chentao@kylinos.cn>
Reviewed-by: Kunwu Chan <chentao@kylinos.cn>
Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/traps.h
arch/arm64/kernel/traps.c
arch/arm64/kvm/handle_exit.c

index e3e8944a71c3e6fb572e42f17efe606661e6efb5..e92e4a0e48fc406f8b8b5ce7de9fb9b8e4c45bdd 100644 (file)
@@ -36,6 +36,7 @@ int kasan_brk_handler(struct pt_regs *regs, unsigned long esr);
 int ubsan_brk_handler(struct pt_regs *regs, unsigned long esr);
 
 int early_brk64(unsigned long addr, unsigned long esr, struct pt_regs *regs);
+void dump_kernel_instr(unsigned long kaddr);
 
 /*
  * Move regs->pc to next instruction and do necessary setup before it
index f528b6041f6a809da72ddf9393d91383f1add528..83e6d1409e1f1a4b675f1de32ccc646899ed5db1 100644 (file)
@@ -149,19 +149,18 @@ pstate_check_t * const aarch32_opcode_cond_checks[16] = {
 
 int show_unhandled_signals = 0;
 
-static void dump_kernel_instr(const char *lvl, struct pt_regs *regs)
+void dump_kernel_instr(unsigned long kaddr)
 {
-       unsigned long addr = instruction_pointer(regs);
        char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
        int i;
 
-       if (user_mode(regs))
+       if (!is_ttbr1_addr(kaddr))
                return;
 
        for (i = -4; i < 1; i++) {
                unsigned int val, bad;
 
-               bad = aarch64_insn_read(&((u32 *)addr)[i], &val);
+               bad = aarch64_insn_read(&((u32 *)kaddr)[i], &val);
 
                if (!bad)
                        p += sprintf(p, i == 0 ? "(%08x) " : "%08x ", val);
@@ -169,7 +168,7 @@ static void dump_kernel_instr(const char *lvl, struct pt_regs *regs)
                        p += sprintf(p, i == 0 ? "(????????) " : "???????? ");
        }
 
-       printk("%sCode: %s\n", lvl, str);
+       printk(KERN_EMERG "Code: %s\n", str);
 }
 
 #define S_SMP " SMP"
@@ -178,6 +177,7 @@ static int __die(const char *str, long err, struct pt_regs *regs)
 {
        static int die_counter;
        int ret;
+       unsigned long addr = instruction_pointer(regs);
 
        pr_emerg("Internal error: %s: %016lx [#%d] " S_SMP "\n",
                 str, err, ++die_counter);
@@ -190,7 +190,10 @@ static int __die(const char *str, long err, struct pt_regs *regs)
        print_modules();
        show_regs(regs);
 
-       dump_kernel_instr(KERN_EMERG, regs);
+       if (user_mode(regs))
+               return ret;
+
+       dump_kernel_instr(addr);
 
        return ret;
 }
index a598072f36d2ca5049e9a3f29f5beb58a86b41c8..99a8205fc10425708062c62fb9faf293b81020a8 100644 (file)
@@ -559,6 +559,11 @@ void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
        /* Dump the nVHE hypervisor backtrace */
        kvm_nvhe_dump_backtrace(hyp_offset);
 
+       /* Dump the faulting instruction */
+       if (!is_protected_kvm_enabled() ||
+           IS_ENABLED(CONFIG_NVHE_EL2_DEBUG))
+               dump_kernel_instr(panic_addr + kaslr_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