kvm_emulate.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012,2013 - ARM Ltd
  4. * Author: Marc Zyngier <[email protected]>
  5. *
  6. * Derived from arch/arm/include/kvm_emulate.h
  7. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  8. * Author: Christoffer Dall <[email protected]>
  9. */
  10. #ifndef __ARM64_KVM_EMULATE_H__
  11. #define __ARM64_KVM_EMULATE_H__
  12. #include <linux/kvm_host.h>
  13. #include <asm/debug-monitors.h>
  14. #include <asm/esr.h>
  15. #include <asm/kvm_arm.h>
  16. #include <asm/kvm_hyp.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/cputype.h>
  19. #include <asm/virt.h>
  20. #define CURRENT_EL_SP_EL0_VECTOR 0x0
  21. #define CURRENT_EL_SP_ELx_VECTOR 0x200
  22. #define LOWER_EL_AArch64_VECTOR 0x400
  23. #define LOWER_EL_AArch32_VECTOR 0x600
  24. enum exception_type {
  25. except_type_sync = 0,
  26. except_type_irq = 0x80,
  27. except_type_fiq = 0x100,
  28. except_type_serror = 0x180,
  29. };
  30. bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
  31. void kvm_skip_instr32(struct kvm_vcpu *vcpu);
  32. void kvm_inject_undefined(struct kvm_vcpu *vcpu);
  33. void kvm_inject_vabt(struct kvm_vcpu *vcpu);
  34. void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
  35. void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
  36. void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
  37. unsigned long get_except64_offset(unsigned long psr, unsigned long target_mode,
  38. enum exception_type type);
  39. unsigned long get_except64_cpsr(unsigned long old, bool has_mte,
  40. unsigned long sctlr, unsigned long mode);
  41. void kvm_vcpu_wfi(struct kvm_vcpu *vcpu);
  42. #if defined(__KVM_VHE_HYPERVISOR__) || defined(__KVM_NVHE_HYPERVISOR__)
  43. static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
  44. {
  45. return !(vcpu->arch.hcr_el2 & HCR_RW);
  46. }
  47. #else
  48. static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu)
  49. {
  50. struct kvm *kvm = vcpu->kvm;
  51. WARN_ON_ONCE(!test_bit(KVM_ARCH_FLAG_REG_WIDTH_CONFIGURED,
  52. &kvm->arch.flags));
  53. return test_bit(KVM_ARCH_FLAG_EL1_32BIT, &kvm->arch.flags);
  54. }
  55. #endif
  56. static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
  57. {
  58. vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
  59. if (is_kernel_in_hyp_mode())
  60. vcpu->arch.hcr_el2 |= HCR_E2H;
  61. if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN)) {
  62. /* route synchronous external abort exceptions to EL2 */
  63. vcpu->arch.hcr_el2 |= HCR_TEA;
  64. /* trap error record accesses */
  65. vcpu->arch.hcr_el2 |= HCR_TERR;
  66. }
  67. if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) {
  68. vcpu->arch.hcr_el2 |= HCR_FWB;
  69. } else {
  70. /*
  71. * For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C
  72. * get set in SCTLR_EL1 such that we can detect when the guest
  73. * MMU gets turned on and do the necessary cache maintenance
  74. * then.
  75. */
  76. vcpu->arch.hcr_el2 |= HCR_TVM;
  77. }
  78. if (vcpu_el1_is_32bit(vcpu))
  79. vcpu->arch.hcr_el2 &= ~HCR_RW;
  80. if (cpus_have_const_cap(ARM64_MISMATCHED_CACHE_TYPE) ||
  81. vcpu_el1_is_32bit(vcpu))
  82. vcpu->arch.hcr_el2 |= HCR_TID2;
  83. if (kvm_has_mte(vcpu->kvm))
  84. vcpu->arch.hcr_el2 |= HCR_ATA;
  85. }
  86. static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu)
  87. {
  88. return (unsigned long *)&vcpu->arch.hcr_el2;
  89. }
  90. static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu)
  91. {
  92. vcpu->arch.hcr_el2 &= ~HCR_TWE;
  93. if (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) ||
  94. vcpu->kvm->arch.vgic.nassgireq)
  95. vcpu->arch.hcr_el2 &= ~HCR_TWI;
  96. else
  97. vcpu->arch.hcr_el2 |= HCR_TWI;
  98. }
  99. static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu)
  100. {
  101. vcpu->arch.hcr_el2 |= HCR_TWE;
  102. vcpu->arch.hcr_el2 |= HCR_TWI;
  103. }
  104. static inline void vcpu_ptrauth_enable(struct kvm_vcpu *vcpu)
  105. {
  106. vcpu->arch.hcr_el2 |= (HCR_API | HCR_APK);
  107. }
  108. static inline void vcpu_ptrauth_disable(struct kvm_vcpu *vcpu)
  109. {
  110. vcpu->arch.hcr_el2 &= ~(HCR_API | HCR_APK);
  111. }
  112. static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu)
  113. {
  114. return vcpu->arch.vsesr_el2;
  115. }
  116. static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr)
  117. {
  118. vcpu->arch.vsesr_el2 = vsesr;
  119. }
  120. static __always_inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu)
  121. {
  122. return (unsigned long *)&vcpu_gp_regs(vcpu)->pc;
  123. }
  124. static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu)
  125. {
  126. return (unsigned long *)&vcpu_gp_regs(vcpu)->pstate;
  127. }
  128. static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu)
  129. {
  130. return !!(*vcpu_cpsr(vcpu) & PSR_MODE32_BIT);
  131. }
  132. static __always_inline bool kvm_condition_valid(const struct kvm_vcpu *vcpu)
  133. {
  134. if (vcpu_mode_is_32bit(vcpu))
  135. return kvm_condition_valid32(vcpu);
  136. return true;
  137. }
  138. static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu)
  139. {
  140. *vcpu_cpsr(vcpu) |= PSR_AA32_T_BIT;
  141. }
  142. /*
  143. * vcpu_get_reg and vcpu_set_reg should always be passed a register number
  144. * coming from a read of ESR_EL2. Otherwise, it may give the wrong result on
  145. * AArch32 with banked registers.
  146. */
  147. static __always_inline unsigned long vcpu_get_reg(const struct kvm_vcpu *vcpu,
  148. u8 reg_num)
  149. {
  150. return (reg_num == 31) ? 0 : vcpu_gp_regs(vcpu)->regs[reg_num];
  151. }
  152. static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num,
  153. unsigned long val)
  154. {
  155. if (reg_num != 31)
  156. vcpu_gp_regs(vcpu)->regs[reg_num] = val;
  157. }
  158. /*
  159. * The layout of SPSR for an AArch32 state is different when observed from an
  160. * AArch64 SPSR_ELx or an AArch32 SPSR_*. This function generates the AArch32
  161. * view given an AArch64 view.
  162. *
  163. * In ARM DDI 0487E.a see:
  164. *
  165. * - The AArch64 view (SPSR_EL2) in section C5.2.18, page C5-426
  166. * - The AArch32 view (SPSR_abt) in section G8.2.126, page G8-6256
  167. * - The AArch32 view (SPSR_und) in section G8.2.132, page G8-6280
  168. *
  169. * Which show the following differences:
  170. *
  171. * | Bit | AA64 | AA32 | Notes |
  172. * +-----+------+------+-----------------------------|
  173. * | 24 | DIT | J | J is RES0 in ARMv8 |
  174. * | 21 | SS | DIT | SS doesn't exist in AArch32 |
  175. *
  176. * ... and all other bits are (currently) common.
  177. */
  178. static inline unsigned long host_spsr_to_spsr32(unsigned long spsr)
  179. {
  180. const unsigned long overlap = BIT(24) | BIT(21);
  181. unsigned long dit = !!(spsr & PSR_AA32_DIT_BIT);
  182. spsr &= ~overlap;
  183. spsr |= dit << 21;
  184. return spsr;
  185. }
  186. static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu)
  187. {
  188. u32 mode;
  189. if (vcpu_mode_is_32bit(vcpu)) {
  190. mode = *vcpu_cpsr(vcpu) & PSR_AA32_MODE_MASK;
  191. return mode > PSR_AA32_MODE_USR;
  192. }
  193. mode = *vcpu_cpsr(vcpu) & PSR_MODE_MASK;
  194. return mode != PSR_MODE_EL0t;
  195. }
  196. static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
  197. {
  198. return vcpu->arch.fault.esr_el2;
  199. }
  200. static __always_inline int kvm_vcpu_get_condition(const struct kvm_vcpu *vcpu)
  201. {
  202. u64 esr = kvm_vcpu_get_esr(vcpu);
  203. if (esr & ESR_ELx_CV)
  204. return (esr & ESR_ELx_COND_MASK) >> ESR_ELx_COND_SHIFT;
  205. return -1;
  206. }
  207. static __always_inline unsigned long kvm_vcpu_get_hfar(const struct kvm_vcpu *vcpu)
  208. {
  209. return vcpu->arch.fault.far_el2;
  210. }
  211. static __always_inline phys_addr_t kvm_vcpu_get_fault_ipa(const struct kvm_vcpu *vcpu)
  212. {
  213. return ((phys_addr_t)vcpu->arch.fault.hpfar_el2 & HPFAR_MASK) << 8;
  214. }
  215. static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu)
  216. {
  217. return vcpu->arch.fault.disr_el1;
  218. }
  219. static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu)
  220. {
  221. return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK;
  222. }
  223. static __always_inline bool kvm_vcpu_dabt_isvalid(const struct kvm_vcpu *vcpu)
  224. {
  225. return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_ISV);
  226. }
  227. static inline unsigned long kvm_vcpu_dabt_iss_nisv_sanitized(const struct kvm_vcpu *vcpu)
  228. {
  229. return kvm_vcpu_get_esr(vcpu) & (ESR_ELx_CM | ESR_ELx_WNR | ESR_ELx_FSC);
  230. }
  231. static inline bool kvm_vcpu_dabt_issext(const struct kvm_vcpu *vcpu)
  232. {
  233. return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_SSE);
  234. }
  235. static inline bool kvm_vcpu_dabt_issf(const struct kvm_vcpu *vcpu)
  236. {
  237. return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_SF);
  238. }
  239. static __always_inline int kvm_vcpu_dabt_get_rd(const struct kvm_vcpu *vcpu)
  240. {
  241. return (kvm_vcpu_get_esr(vcpu) & ESR_ELx_SRT_MASK) >> ESR_ELx_SRT_SHIFT;
  242. }
  243. static __always_inline bool kvm_vcpu_abt_iss1tw(const struct kvm_vcpu *vcpu)
  244. {
  245. return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_S1PTW);
  246. }
  247. /* Always check for S1PTW *before* using this. */
  248. static __always_inline bool kvm_vcpu_dabt_iswrite(const struct kvm_vcpu *vcpu)
  249. {
  250. return kvm_vcpu_get_esr(vcpu) & ESR_ELx_WNR;
  251. }
  252. static inline bool kvm_vcpu_dabt_is_cm(const struct kvm_vcpu *vcpu)
  253. {
  254. return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_CM);
  255. }
  256. static __always_inline unsigned int kvm_vcpu_dabt_get_as(const struct kvm_vcpu *vcpu)
  257. {
  258. return 1 << ((kvm_vcpu_get_esr(vcpu) & ESR_ELx_SAS) >> ESR_ELx_SAS_SHIFT);
  259. }
  260. /* This one is not specific to Data Abort */
  261. static __always_inline bool kvm_vcpu_trap_il_is32bit(const struct kvm_vcpu *vcpu)
  262. {
  263. return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_IL);
  264. }
  265. static __always_inline u8 kvm_vcpu_trap_get_class(const struct kvm_vcpu *vcpu)
  266. {
  267. return ESR_ELx_EC(kvm_vcpu_get_esr(vcpu));
  268. }
  269. static inline bool kvm_vcpu_trap_is_iabt(const struct kvm_vcpu *vcpu)
  270. {
  271. return kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_IABT_LOW;
  272. }
  273. static inline bool kvm_vcpu_trap_is_exec_fault(const struct kvm_vcpu *vcpu)
  274. {
  275. return kvm_vcpu_trap_is_iabt(vcpu) && !kvm_vcpu_abt_iss1tw(vcpu);
  276. }
  277. static __always_inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu)
  278. {
  279. return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC;
  280. }
  281. static __always_inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vcpu)
  282. {
  283. return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC_TYPE;
  284. }
  285. static __always_inline u8 kvm_vcpu_trap_get_fault_level(const struct kvm_vcpu *vcpu)
  286. {
  287. return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC_LEVEL;
  288. }
  289. static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu)
  290. {
  291. switch (kvm_vcpu_trap_get_fault(vcpu)) {
  292. case FSC_SEA:
  293. case FSC_SEA_TTW0:
  294. case FSC_SEA_TTW1:
  295. case FSC_SEA_TTW2:
  296. case FSC_SEA_TTW3:
  297. case FSC_SECC:
  298. case FSC_SECC_TTW0:
  299. case FSC_SECC_TTW1:
  300. case FSC_SECC_TTW2:
  301. case FSC_SECC_TTW3:
  302. return true;
  303. default:
  304. return false;
  305. }
  306. }
  307. static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
  308. {
  309. u64 esr = kvm_vcpu_get_esr(vcpu);
  310. return ESR_ELx_SYS64_ISS_RT(esr);
  311. }
  312. static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
  313. {
  314. if (kvm_vcpu_abt_iss1tw(vcpu)) {
  315. /*
  316. * Only a permission fault on a S1PTW should be
  317. * considered as a write. Otherwise, page tables baked
  318. * in a read-only memslot will result in an exception
  319. * being delivered in the guest.
  320. *
  321. * The drawback is that we end-up faulting twice if the
  322. * guest is using any of HW AF/DB: a translation fault
  323. * to map the page containing the PT (read only at
  324. * first), then a permission fault to allow the flags
  325. * to be set.
  326. */
  327. switch (kvm_vcpu_trap_get_fault_type(vcpu)) {
  328. case ESR_ELx_FSC_PERM:
  329. return true;
  330. default:
  331. return false;
  332. }
  333. }
  334. if (kvm_vcpu_trap_is_iabt(vcpu))
  335. return false;
  336. return kvm_vcpu_dabt_iswrite(vcpu);
  337. }
  338. static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
  339. {
  340. return vcpu_read_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;
  341. }
  342. static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu)
  343. {
  344. if (vcpu_mode_is_32bit(vcpu)) {
  345. *vcpu_cpsr(vcpu) |= PSR_AA32_E_BIT;
  346. } else {
  347. u64 sctlr = vcpu_read_sys_reg(vcpu, SCTLR_EL1);
  348. sctlr |= SCTLR_ELx_EE;
  349. vcpu_write_sys_reg(vcpu, sctlr, SCTLR_EL1);
  350. }
  351. }
  352. static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
  353. {
  354. if (vcpu_mode_is_32bit(vcpu))
  355. return !!(*vcpu_cpsr(vcpu) & PSR_AA32_E_BIT);
  356. if (vcpu_mode_priv(vcpu))
  357. return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_EE);
  358. else
  359. return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_EL1_E0E);
  360. }
  361. static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
  362. unsigned long data,
  363. unsigned int len)
  364. {
  365. if (kvm_vcpu_is_be(vcpu)) {
  366. switch (len) {
  367. case 1:
  368. return data & 0xff;
  369. case 2:
  370. return be16_to_cpu(data & 0xffff);
  371. case 4:
  372. return be32_to_cpu(data & 0xffffffff);
  373. default:
  374. return be64_to_cpu(data);
  375. }
  376. } else {
  377. switch (len) {
  378. case 1:
  379. return data & 0xff;
  380. case 2:
  381. return le16_to_cpu(data & 0xffff);
  382. case 4:
  383. return le32_to_cpu(data & 0xffffffff);
  384. default:
  385. return le64_to_cpu(data);
  386. }
  387. }
  388. return data; /* Leave LE untouched */
  389. }
  390. static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
  391. unsigned long data,
  392. unsigned int len)
  393. {
  394. if (kvm_vcpu_is_be(vcpu)) {
  395. switch (len) {
  396. case 1:
  397. return data & 0xff;
  398. case 2:
  399. return cpu_to_be16(data & 0xffff);
  400. case 4:
  401. return cpu_to_be32(data & 0xffffffff);
  402. default:
  403. return cpu_to_be64(data);
  404. }
  405. } else {
  406. switch (len) {
  407. case 1:
  408. return data & 0xff;
  409. case 2:
  410. return cpu_to_le16(data & 0xffff);
  411. case 4:
  412. return cpu_to_le32(data & 0xffffffff);
  413. default:
  414. return cpu_to_le64(data);
  415. }
  416. }
  417. return data; /* Leave LE untouched */
  418. }
  419. static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu)
  420. {
  421. WARN_ON(vcpu_get_flag(vcpu, PENDING_EXCEPTION));
  422. vcpu_set_flag(vcpu, INCREMENT_PC);
  423. }
  424. #define kvm_pend_exception(v, e) \
  425. do { \
  426. WARN_ON(vcpu_get_flag((v), INCREMENT_PC)); \
  427. vcpu_set_flag((v), PENDING_EXCEPTION); \
  428. vcpu_set_flag((v), e); \
  429. } while (0)
  430. static inline bool vcpu_has_feature(struct kvm_vcpu *vcpu, int feature)
  431. {
  432. return test_bit(feature, vcpu->arch.features);
  433. }
  434. static inline int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)
  435. {
  436. /*
  437. * For now make sure that both address/generic pointer authentication
  438. * features are requested by the userspace together and the system
  439. * supports these capabilities.
  440. */
  441. if (!vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_ADDRESS) ||
  442. !vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_GENERIC) ||
  443. !system_has_full_ptr_auth())
  444. return -EINVAL;
  445. vcpu_set_flag(vcpu, GUEST_HAS_PTRAUTH);
  446. return 0;
  447. }
  448. /* Reset a vcpu's core registers. */
  449. static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu)
  450. {
  451. u32 pstate;
  452. if (vcpu_el1_is_32bit(vcpu)) {
  453. pstate = VCPU_RESET_PSTATE_SVC;
  454. } else {
  455. pstate = VCPU_RESET_PSTATE_EL1;
  456. }
  457. /* Reset core registers */
  458. memset(vcpu_gp_regs(vcpu), 0, sizeof(*vcpu_gp_regs(vcpu)));
  459. memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));
  460. vcpu->arch.ctxt.spsr_abt = 0;
  461. vcpu->arch.ctxt.spsr_und = 0;
  462. vcpu->arch.ctxt.spsr_irq = 0;
  463. vcpu->arch.ctxt.spsr_fiq = 0;
  464. vcpu_gp_regs(vcpu)->pstate = pstate;
  465. }
  466. /* PSCI reset handling for a vcpu. */
  467. static inline void kvm_reset_vcpu_psci(struct kvm_vcpu *vcpu,
  468. struct vcpu_reset_state *reset_state)
  469. {
  470. unsigned long target_pc = reset_state->pc;
  471. /* Gracefully handle Thumb2 entry point */
  472. if (vcpu_mode_is_32bit(vcpu) && (target_pc & 1)) {
  473. target_pc &= ~1UL;
  474. vcpu_set_thumb(vcpu);
  475. }
  476. /* Propagate caller endianness */
  477. if (reset_state->be)
  478. kvm_vcpu_set_be(vcpu);
  479. *vcpu_pc(vcpu) = target_pc;
  480. vcpu_set_reg(vcpu, 0, reset_state->r0);
  481. }
  482. #endif /* __ARM64_KVM_EMULATE_H__ */