Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: Use BUG and BUG_ON in nVHE hyp

hyp_panic() reports the address of the panic by using ELR_EL2, but this
isn't a useful address when hyp_panic() is called directly. Replace such
direct calls with BUG() and BUG_ON() which use BRK to trigger an
exception that then goes to hyp_panic() with the correct address. Also
remove the hyp_panic() declaration from the header file to avoid
accidental misuse.

Signed-off-by: Andrew Scull <ascull@google.com>
Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210318143311.839894-5-ascull@google.com

authored by

Andrew Scull and committed by
Marc Zyngier
f79e616f 5b8be5d8

+3 -6
-1
arch/arm64/include/asm/kvm_hyp.h
··· 100 100 101 101 bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt); 102 102 103 - void __noreturn hyp_panic(void); 104 103 #ifdef __KVM_NVHE_HYPERVISOR__ 105 104 void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr, 106 105 u64 elr, u64 par);
+1 -1
arch/arm64/kvm/hyp/nvhe/hyp-main.c
··· 178 178 handle_host_smc(host_ctxt); 179 179 break; 180 180 default: 181 - hyp_panic(); 181 + BUG(); 182 182 } 183 183 }
+2 -4
arch/arm64/kvm/hyp/nvhe/hyp-smp.c
··· 18 18 19 19 u64 cpu_logical_map(unsigned int cpu) 20 20 { 21 - if (cpu >= ARRAY_SIZE(hyp_cpu_logical_map)) 22 - hyp_panic(); 21 + BUG_ON(cpu >= ARRAY_SIZE(hyp_cpu_logical_map)); 23 22 24 23 return hyp_cpu_logical_map[cpu]; 25 24 } ··· 29 30 unsigned long this_cpu_base; 30 31 unsigned long elf_base; 31 32 32 - if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)) 33 - hyp_panic(); 33 + BUG_ON(cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)); 34 34 35 35 cpu_base_array = (unsigned long *)&kvm_arm_hyp_percpu_base; 36 36 this_cpu_base = kern_hyp_va(cpu_base_array[cpu]);