handle_exit.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2012,2013 - ARM Ltd
  4. * Author: Marc Zyngier <marc.zyngier@arm.com>
  5. *
  6. * Derived from arch/arm/kvm/handle_exit.c:
  7. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  8. * Author: Christoffer Dall <c.dall@virtualopensystems.com>
  9. */
  10. #include <linux/kvm.h>
  11. #include <linux/kvm_host.h>
  12. #include <linux/ubsan.h>
  13. #include <asm/esr.h>
  14. #include <asm/exception.h>
  15. #include <asm/kvm_asm.h>
  16. #include <asm/kvm_emulate.h>
  17. #include <asm/kvm_mmu.h>
  18. #include <asm/kvm_nested.h>
  19. #include <asm/debug-monitors.h>
  20. #include <asm/stacktrace/nvhe.h>
  21. #include <asm/traps.h>
  22. #include <kvm/arm_hypercalls.h>
  23. #define CREATE_TRACE_POINTS
  24. #include "trace_handle_exit.h"
  25. typedef int (*exit_handle_fn)(struct kvm_vcpu *);
  26. static void kvm_handle_guest_serror(struct kvm_vcpu *vcpu, u64 esr)
  27. {
  28. if (!arm64_is_ras_serror(esr) || arm64_is_fatal_ras_serror(NULL, esr))
  29. kvm_inject_serror(vcpu);
  30. }
  31. static int handle_hvc(struct kvm_vcpu *vcpu)
  32. {
  33. trace_kvm_hvc_arm64(*vcpu_pc(vcpu), vcpu_get_reg(vcpu, 0),
  34. kvm_vcpu_hvc_get_imm(vcpu));
  35. vcpu->stat.hvc_exit_stat++;
  36. /* Forward hvc instructions to the virtual EL2 if the guest has EL2. */
  37. if (vcpu_has_nv(vcpu)) {
  38. if (vcpu_read_sys_reg(vcpu, HCR_EL2) & HCR_HCD)
  39. kvm_inject_undefined(vcpu);
  40. else
  41. kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  42. return 1;
  43. }
  44. return kvm_smccc_call_handler(vcpu);
  45. }
  46. static int handle_smc(struct kvm_vcpu *vcpu)
  47. {
  48. /*
  49. * Forward this trapped smc instruction to the virtual EL2 if
  50. * the guest has asked for it.
  51. */
  52. if (forward_smc_trap(vcpu))
  53. return 1;
  54. /*
  55. * "If an SMC instruction executed at Non-secure EL1 is
  56. * trapped to EL2 because HCR_EL2.TSC is 1, the exception is a
  57. * Trap exception, not a Secure Monitor Call exception [...]"
  58. *
  59. * We need to advance the PC after the trap, as it would
  60. * otherwise return to the same address. Furthermore, pre-incrementing
  61. * the PC before potentially exiting to userspace maintains the same
  62. * abstraction for both SMCs and HVCs.
  63. */
  64. kvm_incr_pc(vcpu);
  65. /*
  66. * SMCs with a nonzero immediate are reserved according to DEN0028E 2.9
  67. * "SMC and HVC immediate value".
  68. */
  69. if (kvm_vcpu_hvc_get_imm(vcpu)) {
  70. vcpu_set_reg(vcpu, 0, ~0UL);
  71. return 1;
  72. }
  73. /*
  74. * If imm is zero then it is likely an SMCCC call.
  75. *
  76. * Note that on ARMv8.3, even if EL3 is not implemented, SMC executed
  77. * at Non-secure EL1 is trapped to EL2 if HCR_EL2.TSC==1, rather than
  78. * being treated as UNDEFINED.
  79. */
  80. return kvm_smccc_call_handler(vcpu);
  81. }
  82. /*
  83. * This handles the cases where the system does not support FP/ASIMD or when
  84. * we are running nested virtualization and the guest hypervisor is trapping
  85. * FP/ASIMD accesses by its guest guest.
  86. *
  87. * All other handling of guest vs. host FP/ASIMD register state is handled in
  88. * fixup_guest_exit().
  89. */
  90. static int kvm_handle_fpasimd(struct kvm_vcpu *vcpu)
  91. {
  92. if (guest_hyp_fpsimd_traps_enabled(vcpu))
  93. return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  94. /* This is the case when the system doesn't support FP/ASIMD. */
  95. kvm_inject_undefined(vcpu);
  96. return 1;
  97. }
  98. /**
  99. * kvm_handle_wfx - handle a wait-for-interrupts or wait-for-event
  100. * instruction executed by a guest
  101. *
  102. * @vcpu: the vcpu pointer
  103. *
  104. * WFE[T]: Yield the CPU and come back to this vcpu when the scheduler
  105. * decides to.
  106. * WFI: Simply call kvm_vcpu_halt(), which will halt execution of
  107. * world-switches and schedule other host processes until there is an
  108. * incoming IRQ or FIQ to the VM.
  109. * WFIT: Same as WFI, with a timed wakeup implemented as a background timer
  110. *
  111. * WF{I,E}T can immediately return if the deadline has already expired.
  112. */
  113. static int kvm_handle_wfx(struct kvm_vcpu *vcpu)
  114. {
  115. u64 esr = kvm_vcpu_get_esr(vcpu);
  116. bool is_wfe = !!(esr & ESR_ELx_WFx_ISS_WFE);
  117. if (guest_hyp_wfx_traps_enabled(vcpu))
  118. return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  119. if (is_wfe) {
  120. trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true);
  121. vcpu->stat.wfe_exit_stat++;
  122. } else {
  123. trace_kvm_wfx_arm64(*vcpu_pc(vcpu), false);
  124. vcpu->stat.wfi_exit_stat++;
  125. }
  126. if (esr & ESR_ELx_WFx_ISS_WFxT) {
  127. if (esr & ESR_ELx_WFx_ISS_RV) {
  128. u64 val, now;
  129. now = kvm_phys_timer_read();
  130. if (is_hyp_ctxt(vcpu) && vcpu_el2_e2h_is_set(vcpu))
  131. now -= timer_get_offset(vcpu_hvtimer(vcpu));
  132. else
  133. now -= timer_get_offset(vcpu_vtimer(vcpu));
  134. val = vcpu_get_reg(vcpu, kvm_vcpu_sys_get_rt(vcpu));
  135. if (now >= val)
  136. goto out;
  137. } else {
  138. /* Treat WFxT as WFx if RN is invalid */
  139. esr &= ~ESR_ELx_WFx_ISS_WFxT;
  140. }
  141. }
  142. if (esr & ESR_ELx_WFx_ISS_WFE) {
  143. kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu));
  144. } else {
  145. if (esr & ESR_ELx_WFx_ISS_WFxT)
  146. vcpu_set_flag(vcpu, IN_WFIT);
  147. kvm_vcpu_wfi(vcpu);
  148. }
  149. out:
  150. kvm_incr_pc(vcpu);
  151. return 1;
  152. }
  153. /**
  154. * kvm_handle_guest_debug - handle a debug exception instruction
  155. *
  156. * @vcpu: the vcpu pointer
  157. *
  158. * We route all debug exceptions through the same handler. If both the
  159. * guest and host are using the same debug facilities it will be up to
  160. * userspace to re-inject the correct exception for guest delivery.
  161. *
  162. * @return: 0 (while setting vcpu->run->exit_reason)
  163. */
  164. static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
  165. {
  166. struct kvm_run *run = vcpu->run;
  167. u64 esr = kvm_vcpu_get_esr(vcpu);
  168. if (!vcpu->guest_debug && forward_debug_exception(vcpu))
  169. return 1;
  170. run->exit_reason = KVM_EXIT_DEBUG;
  171. run->debug.arch.hsr = lower_32_bits(esr);
  172. run->debug.arch.hsr_high = upper_32_bits(esr);
  173. run->flags = KVM_DEBUG_ARCH_HSR_HIGH_VALID;
  174. switch (ESR_ELx_EC(esr)) {
  175. case ESR_ELx_EC_WATCHPT_LOW:
  176. run->debug.arch.far = vcpu->arch.fault.far_el2;
  177. break;
  178. case ESR_ELx_EC_SOFTSTP_LOW:
  179. *vcpu_cpsr(vcpu) |= DBG_SPSR_SS;
  180. break;
  181. }
  182. return 0;
  183. }
  184. static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu)
  185. {
  186. u64 esr = kvm_vcpu_get_esr(vcpu);
  187. kvm_pr_unimpl("Unknown exception class: esr: %#016llx -- %s\n",
  188. esr, esr_get_class_string(esr));
  189. kvm_inject_undefined(vcpu);
  190. return 1;
  191. }
  192. /*
  193. * Guest access to SVE registers should be routed to this handler only
  194. * when the system doesn't support SVE.
  195. */
  196. static int handle_sve(struct kvm_vcpu *vcpu)
  197. {
  198. if (guest_hyp_sve_traps_enabled(vcpu))
  199. return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  200. kvm_inject_undefined(vcpu);
  201. return 1;
  202. }
  203. /*
  204. * Two possibilities to handle a trapping ptrauth instruction:
  205. *
  206. * - Guest usage of a ptrauth instruction (which the guest EL1 did not
  207. * turn into a NOP). If we get here, it is because we didn't enable
  208. * ptrauth for the guest. This results in an UNDEF, as it isn't
  209. * supposed to use ptrauth without being told it could.
  210. *
  211. * - Running an L2 NV guest while L1 has left HCR_EL2.API==0, and for
  212. * which we reinject the exception into L1.
  213. *
  214. * Anything else is an emulation bug (hence the WARN_ON + UNDEF).
  215. */
  216. static int kvm_handle_ptrauth(struct kvm_vcpu *vcpu)
  217. {
  218. if (!vcpu_has_ptrauth(vcpu)) {
  219. kvm_inject_undefined(vcpu);
  220. return 1;
  221. }
  222. if (is_nested_ctxt(vcpu)) {
  223. kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  224. return 1;
  225. }
  226. /* Really shouldn't be here! */
  227. WARN_ON_ONCE(1);
  228. kvm_inject_undefined(vcpu);
  229. return 1;
  230. }
  231. static int kvm_handle_eret(struct kvm_vcpu *vcpu)
  232. {
  233. if (esr_iss_is_eretax(kvm_vcpu_get_esr(vcpu)) &&
  234. !vcpu_has_ptrauth(vcpu))
  235. return kvm_handle_ptrauth(vcpu);
  236. /*
  237. * If we got here, two possibilities:
  238. *
  239. * - the guest is in EL2, and we need to fully emulate ERET
  240. *
  241. * - the guest is in EL1, and we need to reinject the
  242. * exception into the L1 hypervisor.
  243. *
  244. * If KVM ever traps ERET for its own use, we'll have to
  245. * revisit this.
  246. */
  247. if (is_hyp_ctxt(vcpu))
  248. kvm_emulate_nested_eret(vcpu);
  249. else
  250. kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  251. return 1;
  252. }
  253. static int handle_svc(struct kvm_vcpu *vcpu)
  254. {
  255. /*
  256. * So far, SVC traps only for NV via HFGITR_EL2. A SVC from a
  257. * 32bit guest would be caught by vpcu_mode_is_bad_32bit(), so
  258. * we should only have to deal with a 64 bit exception.
  259. */
  260. kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
  261. return 1;
  262. }
  263. static int kvm_handle_gcs(struct kvm_vcpu *vcpu)
  264. {
  265. /* We don't expect GCS, so treat it with contempt */
  266. if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, GCS, IMP))
  267. WARN_ON_ONCE(1);
  268. kvm_inject_undefined(vcpu);
  269. return 1;
  270. }
  271. static int handle_other(struct kvm_vcpu *vcpu)
  272. {
  273. bool allowed, fwd = is_nested_ctxt(vcpu);
  274. u64 hcrx = __vcpu_sys_reg(vcpu, HCRX_EL2);
  275. u64 esr = kvm_vcpu_get_esr(vcpu);
  276. u64 iss = ESR_ELx_ISS(esr);
  277. struct kvm *kvm = vcpu->kvm;
  278. /*
  279. * We only trap for two reasons:
  280. *
  281. * - the feature is disabled, and the only outcome is to
  282. * generate an UNDEF.
  283. *
  284. * - the feature is enabled, but a NV guest wants to trap the
  285. * feature used by its L2 guest. We forward the exception in
  286. * this case.
  287. *
  288. * What we don't expect is to end-up here if the guest is
  289. * expected be be able to directly use the feature, hence the
  290. * WARN_ON below.
  291. */
  292. switch (iss) {
  293. case ESR_ELx_ISS_OTHER_ST64BV:
  294. allowed = kvm_has_feat(kvm, ID_AA64ISAR1_EL1, LS64, LS64_V);
  295. fwd &= !(hcrx & HCRX_EL2_EnASR);
  296. break;
  297. case ESR_ELx_ISS_OTHER_ST64BV0:
  298. allowed = kvm_has_feat(kvm, ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA);
  299. fwd &= !(hcrx & HCRX_EL2_EnAS0);
  300. break;
  301. case ESR_ELx_ISS_OTHER_LDST64B:
  302. allowed = kvm_has_feat(kvm, ID_AA64ISAR1_EL1, LS64, LS64);
  303. fwd &= !(hcrx & HCRX_EL2_EnALS);
  304. break;
  305. case ESR_ELx_ISS_OTHER_TSBCSYNC:
  306. allowed = kvm_has_feat(kvm, ID_AA64DFR0_EL1, TraceBuffer, TRBE_V1P1);
  307. fwd &= (__vcpu_sys_reg(vcpu, HFGITR2_EL2) & HFGITR2_EL2_TSBCSYNC);
  308. break;
  309. case ESR_ELx_ISS_OTHER_PSBCSYNC:
  310. allowed = kvm_has_feat(kvm, ID_AA64DFR0_EL1, PMSVer, V1P5);
  311. fwd &= (__vcpu_sys_reg(vcpu, HFGITR_EL2) & HFGITR_EL2_PSBCSYNC);
  312. break;
  313. default:
  314. /* Clearly, we're missing something. */
  315. WARN_ON_ONCE(1);
  316. allowed = false;
  317. }
  318. WARN_ON_ONCE(allowed && !fwd);
  319. if (allowed && fwd)
  320. kvm_inject_nested_sync(vcpu, esr);
  321. else
  322. kvm_inject_undefined(vcpu);
  323. return 1;
  324. }
  325. static exit_handle_fn arm_exit_handlers[] = {
  326. [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec,
  327. [ESR_ELx_EC_WFx] = kvm_handle_wfx,
  328. [ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32,
  329. [ESR_ELx_EC_CP15_64] = kvm_handle_cp15_64,
  330. [ESR_ELx_EC_CP14_MR] = kvm_handle_cp14_32,
  331. [ESR_ELx_EC_CP14_LS] = kvm_handle_cp14_load_store,
  332. [ESR_ELx_EC_CP10_ID] = kvm_handle_cp10_id,
  333. [ESR_ELx_EC_CP14_64] = kvm_handle_cp14_64,
  334. [ESR_ELx_EC_OTHER] = handle_other,
  335. [ESR_ELx_EC_HVC32] = handle_hvc,
  336. [ESR_ELx_EC_SMC32] = handle_smc,
  337. [ESR_ELx_EC_HVC64] = handle_hvc,
  338. [ESR_ELx_EC_SMC64] = handle_smc,
  339. [ESR_ELx_EC_SVC64] = handle_svc,
  340. [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg,
  341. [ESR_ELx_EC_SVE] = handle_sve,
  342. [ESR_ELx_EC_ERET] = kvm_handle_eret,
  343. [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort,
  344. [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort,
  345. [ESR_ELx_EC_DABT_CUR] = kvm_handle_vncr_abort,
  346. [ESR_ELx_EC_SOFTSTP_LOW]= kvm_handle_guest_debug,
  347. [ESR_ELx_EC_WATCHPT_LOW]= kvm_handle_guest_debug,
  348. [ESR_ELx_EC_BREAKPT_LOW]= kvm_handle_guest_debug,
  349. [ESR_ELx_EC_BKPT32] = kvm_handle_guest_debug,
  350. [ESR_ELx_EC_BRK64] = kvm_handle_guest_debug,
  351. [ESR_ELx_EC_FP_ASIMD] = kvm_handle_fpasimd,
  352. [ESR_ELx_EC_PAC] = kvm_handle_ptrauth,
  353. [ESR_ELx_EC_GCS] = kvm_handle_gcs,
  354. };
  355. static exit_handle_fn kvm_get_exit_handler(struct kvm_vcpu *vcpu)
  356. {
  357. u64 esr = kvm_vcpu_get_esr(vcpu);
  358. u8 esr_ec = ESR_ELx_EC(esr);
  359. return arm_exit_handlers[esr_ec];
  360. }
  361. /*
  362. * We may be single-stepping an emulated instruction. If the emulation
  363. * has been completed in the kernel, we can return to userspace with a
  364. * KVM_EXIT_DEBUG, otherwise userspace needs to complete its
  365. * emulation first.
  366. */
  367. static int handle_trap_exceptions(struct kvm_vcpu *vcpu)
  368. {
  369. int handled;
  370. /*
  371. * See ARM ARM B1.14.1: "Hyp traps on instructions
  372. * that fail their condition code check"
  373. */
  374. if (!kvm_condition_valid(vcpu)) {
  375. kvm_incr_pc(vcpu);
  376. handled = 1;
  377. } else {
  378. exit_handle_fn exit_handler;
  379. exit_handler = kvm_get_exit_handler(vcpu);
  380. handled = exit_handler(vcpu);
  381. }
  382. return handled;
  383. }
  384. /*
  385. * Return > 0 to return to guest, < 0 on error, 0 (and set exit_reason) on
  386. * proper exit to userspace.
  387. */
  388. int handle_exit(struct kvm_vcpu *vcpu, int exception_index)
  389. {
  390. struct kvm_run *run = vcpu->run;
  391. if (ARM_SERROR_PENDING(exception_index)) {
  392. /*
  393. * The SError is handled by handle_exit_early(). If the guest
  394. * survives it will re-execute the original instruction.
  395. */
  396. return 1;
  397. }
  398. exception_index = ARM_EXCEPTION_CODE(exception_index);
  399. switch (exception_index) {
  400. case ARM_EXCEPTION_IRQ:
  401. return 1;
  402. case ARM_EXCEPTION_EL1_SERROR:
  403. return 1;
  404. case ARM_EXCEPTION_TRAP:
  405. return handle_trap_exceptions(vcpu);
  406. case ARM_EXCEPTION_HYP_GONE:
  407. /*
  408. * EL2 has been reset to the hyp-stub. This happens when a guest
  409. * is pre-emptied by kvm_reboot()'s shutdown call.
  410. */
  411. run->exit_reason = KVM_EXIT_FAIL_ENTRY;
  412. return 0;
  413. case ARM_EXCEPTION_IL:
  414. /*
  415. * We attempted an illegal exception return. Guest state must
  416. * have been corrupted somehow. Give up.
  417. */
  418. run->exit_reason = KVM_EXIT_FAIL_ENTRY;
  419. return -EINVAL;
  420. default:
  421. kvm_pr_unimpl("Unsupported exception type: %d",
  422. exception_index);
  423. run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
  424. return 0;
  425. }
  426. }
  427. /* For exit types that need handling before we can be preempted */
  428. void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index)
  429. {
  430. if (ARM_SERROR_PENDING(exception_index)) {
  431. if (this_cpu_has_cap(ARM64_HAS_RAS_EXTN)) {
  432. u64 disr = kvm_vcpu_get_disr(vcpu);
  433. kvm_handle_guest_serror(vcpu, disr_to_esr(disr));
  434. } else {
  435. kvm_inject_serror(vcpu);
  436. }
  437. return;
  438. }
  439. exception_index = ARM_EXCEPTION_CODE(exception_index);
  440. if (exception_index == ARM_EXCEPTION_EL1_SERROR)
  441. kvm_handle_guest_serror(vcpu, kvm_vcpu_get_esr(vcpu));
  442. }
  443. static void print_nvhe_hyp_panic(const char *name, u64 panic_addr)
  444. {
  445. kvm_err("nVHE hyp %s at: [<%016llx>] %pB!\n", name, panic_addr,
  446. (void *)(panic_addr + kaslr_offset()));
  447. }
  448. static void kvm_nvhe_report_cfi_failure(u64 panic_addr)
  449. {
  450. print_nvhe_hyp_panic("CFI failure", panic_addr);
  451. if (IS_ENABLED(CONFIG_CFI_PERMISSIVE))
  452. kvm_err(" (CONFIG_CFI_PERMISSIVE ignored for hyp failures)\n");
  453. }
  454. void __noreturn __cold nvhe_hyp_panic_handler(u64 esr, u64 spsr,
  455. u64 elr_virt, u64 elr_phys,
  456. u64 par, uintptr_t vcpu,
  457. u64 far, u64 hpfar) {
  458. u64 elr_in_kimg = __phys_to_kimg(elr_phys);
  459. u64 hyp_offset = elr_in_kimg - kaslr_offset() - elr_virt;
  460. u64 mode = spsr & PSR_MODE_MASK;
  461. u64 panic_addr = elr_virt + hyp_offset;
  462. if (mode != PSR_MODE_EL2t && mode != PSR_MODE_EL2h) {
  463. kvm_err("Invalid host exception to nVHE hyp!\n");
  464. } else if (ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
  465. esr_brk_comment(esr) == BUG_BRK_IMM) {
  466. const char *file = NULL;
  467. unsigned int line = 0;
  468. /* All hyp bugs, including warnings, are treated as fatal. */
  469. if (!is_protected_kvm_enabled() ||
  470. IS_ENABLED(CONFIG_NVHE_EL2_DEBUG)) {
  471. struct bug_entry *bug = find_bug(elr_in_kimg);
  472. if (bug)
  473. bug_get_file_line(bug, &file, &line);
  474. }
  475. if (file)
  476. kvm_err("nVHE hyp BUG at: %s:%u!\n", file, line);
  477. else
  478. print_nvhe_hyp_panic("BUG", panic_addr);
  479. } else if (IS_ENABLED(CONFIG_CFI) && esr_is_cfi_brk(esr)) {
  480. kvm_nvhe_report_cfi_failure(panic_addr);
  481. } else if (IS_ENABLED(CONFIG_UBSAN_KVM_EL2) &&
  482. ESR_ELx_EC(esr) == ESR_ELx_EC_BRK64 &&
  483. esr_is_ubsan_brk(esr)) {
  484. print_nvhe_hyp_panic(report_ubsan_failure(esr & UBSAN_BRK_MASK),
  485. panic_addr);
  486. } else {
  487. print_nvhe_hyp_panic("panic", panic_addr);
  488. }
  489. /* Dump the nVHE hypervisor backtrace */
  490. kvm_nvhe_dump_backtrace(hyp_offset);
  491. /* Dump the faulting instruction */
  492. dump_kernel_instr(panic_addr + kaslr_offset());
  493. /*
  494. * Hyp has panicked and we're going to handle that by panicking the
  495. * kernel. The kernel offset will be revealed in the panic so we're
  496. * also safe to reveal the hyp offset as a debugging aid for translating
  497. * hyp VAs to vmlinux addresses.
  498. */
  499. kvm_err("Hyp Offset: 0x%llx\n", hyp_offset);
  500. panic("HYP panic:\nPS:%08llx PC:%016llx ESR:%016llx\nFAR:%016llx HPFAR:%016llx PAR:%016llx\nVCPU:%016lx\n",
  501. spsr, elr_virt, esr, far, hpfar, par, vcpu);
  502. }