Lines Matching full:vcpu

44 bool kvm_condition_valid32(const struct kvm_vcpu *vcpu);
45 void kvm_skip_instr32(struct kvm_vcpu *vcpu);
47 void kvm_inject_undefined(struct kvm_vcpu *vcpu);
48 void kvm_inject_vabt(struct kvm_vcpu *vcpu);
49 void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
50 void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
51 void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
53 void kvm_vcpu_wfi(struct kvm_vcpu *vcpu);
55 void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu);
56 int kvm_inject_nested_sync(struct kvm_vcpu *vcpu, u64 esr_el2);
57 int kvm_inject_nested_irq(struct kvm_vcpu *vcpu);
59 static inline void kvm_inject_nested_sve_trap(struct kvm_vcpu *vcpu) in kvm_inject_nested_sve_trap() argument
64 kvm_inject_nested_sync(vcpu, esr); in kvm_inject_nested_sve_trap()
68 static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu) in vcpu_el1_is_32bit() argument
70 return !(vcpu->arch.hcr_el2 & HCR_RW); in vcpu_el1_is_32bit()
73 static __always_inline bool vcpu_el1_is_32bit(struct kvm_vcpu *vcpu) in vcpu_el1_is_32bit() argument
75 return vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT); in vcpu_el1_is_32bit()
79 static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) in vcpu_reset_hcr() argument
81 if (!vcpu_has_run_once(vcpu)) in vcpu_reset_hcr()
82 vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS; in vcpu_reset_hcr()
91 vcpu->arch.hcr_el2 |= HCR_TVM; in vcpu_reset_hcr()
94 static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu) in vcpu_hcr() argument
96 return (unsigned long *)&vcpu->arch.hcr_el2; in vcpu_hcr()
99 static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu) in vcpu_clear_wfx_traps() argument
101 vcpu->arch.hcr_el2 &= ~HCR_TWE; in vcpu_clear_wfx_traps()
102 if (atomic_read(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count) || in vcpu_clear_wfx_traps()
103 vcpu->kvm->arch.vgic.nassgireq) in vcpu_clear_wfx_traps()
104 vcpu->arch.hcr_el2 &= ~HCR_TWI; in vcpu_clear_wfx_traps()
106 vcpu->arch.hcr_el2 |= HCR_TWI; in vcpu_clear_wfx_traps()
109 static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu) in vcpu_set_wfx_traps() argument
111 vcpu->arch.hcr_el2 |= HCR_TWE; in vcpu_set_wfx_traps()
112 vcpu->arch.hcr_el2 |= HCR_TWI; in vcpu_set_wfx_traps()
115 static inline unsigned long vcpu_get_vsesr(struct kvm_vcpu *vcpu) in vcpu_get_vsesr() argument
117 return vcpu->arch.vsesr_el2; in vcpu_get_vsesr()
120 static inline void vcpu_set_vsesr(struct kvm_vcpu *vcpu, u64 vsesr) in vcpu_set_vsesr() argument
122 vcpu->arch.vsesr_el2 = vsesr; in vcpu_set_vsesr()
125 static __always_inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu) in vcpu_pc() argument
127 return (unsigned long *)&vcpu_gp_regs(vcpu)->pc; in vcpu_pc()
130 static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu) in vcpu_cpsr() argument
132 return (unsigned long *)&vcpu_gp_regs(vcpu)->pstate; in vcpu_cpsr()
135 static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu) in vcpu_mode_is_32bit() argument
137 return !!(*vcpu_cpsr(vcpu) & PSR_MODE32_BIT); in vcpu_mode_is_32bit()
140 static __always_inline bool kvm_condition_valid(const struct kvm_vcpu *vcpu) in kvm_condition_valid() argument
142 if (vcpu_mode_is_32bit(vcpu)) in kvm_condition_valid()
143 return kvm_condition_valid32(vcpu); in kvm_condition_valid()
148 static inline void vcpu_set_thumb(struct kvm_vcpu *vcpu) in vcpu_set_thumb() argument
150 *vcpu_cpsr(vcpu) |= PSR_AA32_T_BIT; in vcpu_set_thumb()
158 static __always_inline unsigned long vcpu_get_reg(const struct kvm_vcpu *vcpu, in vcpu_get_reg() argument
161 return (reg_num == 31) ? 0 : vcpu_gp_regs(vcpu)->regs[reg_num]; in vcpu_get_reg()
164 static __always_inline void vcpu_set_reg(struct kvm_vcpu *vcpu, u8 reg_num, in vcpu_set_reg() argument
168 vcpu_gp_regs(vcpu)->regs[reg_num] = val; in vcpu_set_reg()
182 static inline bool vcpu_is_el2(const struct kvm_vcpu *vcpu) in vcpu_is_el2() argument
184 return vcpu_is_el2_ctxt(&vcpu->arch.ctxt); in vcpu_is_el2()
193 static inline bool vcpu_el2_e2h_is_set(const struct kvm_vcpu *vcpu) in vcpu_el2_e2h_is_set() argument
195 return __vcpu_el2_e2h_is_set(&vcpu->arch.ctxt); in vcpu_el2_e2h_is_set()
203 static inline bool vcpu_el2_tge_is_set(const struct kvm_vcpu *vcpu) in vcpu_el2_tge_is_set() argument
205 return __vcpu_el2_tge_is_set(&vcpu->arch.ctxt); in vcpu_el2_tge_is_set()
211 * We are in a hypervisor context if the vcpu mode is EL2 or in __is_hyp_ctxt()
223 static inline bool is_hyp_ctxt(const struct kvm_vcpu *vcpu) in is_hyp_ctxt() argument
225 return vcpu_has_nv(vcpu) && __is_hyp_ctxt(&vcpu->arch.ctxt); in is_hyp_ctxt()
260 static inline bool vcpu_mode_priv(const struct kvm_vcpu *vcpu) in vcpu_mode_priv() argument
264 if (vcpu_mode_is_32bit(vcpu)) { in vcpu_mode_priv()
265 mode = *vcpu_cpsr(vcpu) & PSR_AA32_MODE_MASK; in vcpu_mode_priv()
269 mode = *vcpu_cpsr(vcpu) & PSR_MODE_MASK; in vcpu_mode_priv()
274 static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu) in kvm_vcpu_get_esr() argument
276 return vcpu->arch.fault.esr_el2; in kvm_vcpu_get_esr()
279 static __always_inline int kvm_vcpu_get_condition(const struct kvm_vcpu *vcpu) in kvm_vcpu_get_condition() argument
281 u64 esr = kvm_vcpu_get_esr(vcpu); in kvm_vcpu_get_condition()
289 static __always_inline unsigned long kvm_vcpu_get_hfar(const struct kvm_vcpu *vcpu) in kvm_vcpu_get_hfar() argument
291 return vcpu->arch.fault.far_el2; in kvm_vcpu_get_hfar()
294 static __always_inline phys_addr_t kvm_vcpu_get_fault_ipa(const struct kvm_vcpu *vcpu) in kvm_vcpu_get_fault_ipa() argument
296 return ((phys_addr_t)vcpu->arch.fault.hpfar_el2 & HPFAR_MASK) << 8; in kvm_vcpu_get_fault_ipa()
299 static inline u64 kvm_vcpu_get_disr(const struct kvm_vcpu *vcpu) in kvm_vcpu_get_disr() argument
301 return vcpu->arch.fault.disr_el1; in kvm_vcpu_get_disr()
304 static inline u32 kvm_vcpu_hvc_get_imm(const struct kvm_vcpu *vcpu) in kvm_vcpu_hvc_get_imm() argument
306 return kvm_vcpu_get_esr(vcpu) & ESR_ELx_xVC_IMM_MASK; in kvm_vcpu_hvc_get_imm()
309 static __always_inline bool kvm_vcpu_dabt_isvalid(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_isvalid() argument
311 return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_ISV); in kvm_vcpu_dabt_isvalid()
314 static inline unsigned long kvm_vcpu_dabt_iss_nisv_sanitized(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_iss_nisv_sanitized() argument
316 return kvm_vcpu_get_esr(vcpu) & (ESR_ELx_CM | ESR_ELx_WNR | ESR_ELx_FSC); in kvm_vcpu_dabt_iss_nisv_sanitized()
319 static inline bool kvm_vcpu_dabt_issext(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_issext() argument
321 return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_SSE); in kvm_vcpu_dabt_issext()
324 static inline bool kvm_vcpu_dabt_issf(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_issf() argument
326 return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_SF); in kvm_vcpu_dabt_issf()
329 static __always_inline int kvm_vcpu_dabt_get_rd(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_get_rd() argument
331 return (kvm_vcpu_get_esr(vcpu) & ESR_ELx_SRT_MASK) >> ESR_ELx_SRT_SHIFT; in kvm_vcpu_dabt_get_rd()
334 static __always_inline bool kvm_vcpu_abt_iss1tw(const struct kvm_vcpu *vcpu) in kvm_vcpu_abt_iss1tw() argument
336 return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_S1PTW); in kvm_vcpu_abt_iss1tw()
340 static __always_inline bool kvm_vcpu_dabt_iswrite(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_iswrite() argument
342 return kvm_vcpu_get_esr(vcpu) & ESR_ELx_WNR; in kvm_vcpu_dabt_iswrite()
345 static inline bool kvm_vcpu_dabt_is_cm(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_is_cm() argument
347 return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_CM); in kvm_vcpu_dabt_is_cm()
350 static __always_inline unsigned int kvm_vcpu_dabt_get_as(const struct kvm_vcpu *vcpu) in kvm_vcpu_dabt_get_as() argument
352 return 1 << ((kvm_vcpu_get_esr(vcpu) & ESR_ELx_SAS) >> ESR_ELx_SAS_SHIFT); in kvm_vcpu_dabt_get_as()
356 static __always_inline bool kvm_vcpu_trap_il_is32bit(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_il_is32bit() argument
358 return !!(kvm_vcpu_get_esr(vcpu) & ESR_ELx_IL); in kvm_vcpu_trap_il_is32bit()
361 static __always_inline u8 kvm_vcpu_trap_get_class(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_get_class() argument
363 return ESR_ELx_EC(kvm_vcpu_get_esr(vcpu)); in kvm_vcpu_trap_get_class()
366 static inline bool kvm_vcpu_trap_is_iabt(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_is_iabt() argument
368 return kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_IABT_LOW; in kvm_vcpu_trap_is_iabt()
371 static inline bool kvm_vcpu_trap_is_exec_fault(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_is_exec_fault() argument
373 return kvm_vcpu_trap_is_iabt(vcpu) && !kvm_vcpu_abt_iss1tw(vcpu); in kvm_vcpu_trap_is_exec_fault()
376 static __always_inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_get_fault() argument
378 return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC; in kvm_vcpu_trap_get_fault()
382 bool kvm_vcpu_trap_is_permission_fault(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_is_permission_fault() argument
384 return esr_fsc_is_permission_fault(kvm_vcpu_get_esr(vcpu)); in kvm_vcpu_trap_is_permission_fault()
388 bool kvm_vcpu_trap_is_translation_fault(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_is_translation_fault() argument
390 return esr_fsc_is_translation_fault(kvm_vcpu_get_esr(vcpu)); in kvm_vcpu_trap_is_translation_fault()
394 u64 kvm_vcpu_trap_get_perm_fault_granule(const struct kvm_vcpu *vcpu) in kvm_vcpu_trap_get_perm_fault_granule() argument
396 unsigned long esr = kvm_vcpu_get_esr(vcpu); in kvm_vcpu_trap_get_perm_fault_granule()
402 static __always_inline bool kvm_vcpu_abt_issea(const struct kvm_vcpu *vcpu) in kvm_vcpu_abt_issea() argument
404 switch (kvm_vcpu_trap_get_fault(vcpu)) { in kvm_vcpu_abt_issea()
415 static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu) in kvm_vcpu_sys_get_rt() argument
417 u64 esr = kvm_vcpu_get_esr(vcpu); in kvm_vcpu_sys_get_rt()
421 static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu) in kvm_is_write_fault() argument
423 if (kvm_vcpu_abt_iss1tw(vcpu)) { in kvm_is_write_fault()
436 return kvm_vcpu_trap_is_permission_fault(vcpu); in kvm_is_write_fault()
439 if (kvm_vcpu_trap_is_iabt(vcpu)) in kvm_is_write_fault()
442 return kvm_vcpu_dabt_iswrite(vcpu); in kvm_is_write_fault()
445 static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu) in kvm_vcpu_get_mpidr_aff() argument
447 return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK; in kvm_vcpu_get_mpidr_aff()
450 static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu) in kvm_vcpu_set_be() argument
452 if (vcpu_mode_is_32bit(vcpu)) { in kvm_vcpu_set_be()
453 *vcpu_cpsr(vcpu) |= PSR_AA32_E_BIT; in kvm_vcpu_set_be()
455 u64 sctlr = vcpu_read_sys_reg(vcpu, SCTLR_EL1); in kvm_vcpu_set_be()
457 vcpu_write_sys_reg(vcpu, sctlr, SCTLR_EL1); in kvm_vcpu_set_be()
461 static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) in kvm_vcpu_is_be() argument
463 if (vcpu_mode_is_32bit(vcpu)) in kvm_vcpu_is_be()
464 return !!(*vcpu_cpsr(vcpu) & PSR_AA32_E_BIT); in kvm_vcpu_is_be()
466 if (vcpu_mode_priv(vcpu)) in kvm_vcpu_is_be()
467 return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_EE); in kvm_vcpu_is_be()
469 return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_EL1_E0E); in kvm_vcpu_is_be()
472 static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu, in vcpu_data_guest_to_host() argument
476 if (kvm_vcpu_is_be(vcpu)) { in vcpu_data_guest_to_host()
503 static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu, in vcpu_data_host_to_guest() argument
507 if (kvm_vcpu_is_be(vcpu)) { in vcpu_data_host_to_guest()
534 static __always_inline void kvm_incr_pc(struct kvm_vcpu *vcpu) in kvm_incr_pc() argument
536 WARN_ON(vcpu_get_flag(vcpu, PENDING_EXCEPTION)); in kvm_incr_pc()
537 vcpu_set_flag(vcpu, INCREMENT_PC); in kvm_incr_pc()
617 static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu) in kvm_get_reset_cptr_el2() argument
628 if (!vcpu_has_sve(vcpu) || !guest_owns_fp_regs()) in kvm_get_reset_cptr_el2()
635 if (vcpu_has_sve(vcpu) && guest_owns_fp_regs()) in kvm_get_reset_cptr_el2()
644 static __always_inline void kvm_reset_cptr_el2(struct kvm_vcpu *vcpu) in kvm_reset_cptr_el2() argument
646 u64 val = kvm_get_reset_cptr_el2(vcpu); in kvm_reset_cptr_el2()
655 static inline u64 vcpu_sanitised_cptr_el2(const struct kvm_vcpu *vcpu) in vcpu_sanitised_cptr_el2() argument
657 u64 cptr = __vcpu_sys_reg(vcpu, CPTR_EL2); in vcpu_sanitised_cptr_el2()
659 if (!vcpu_el2_e2h_is_set(vcpu)) in vcpu_sanitised_cptr_el2()
665 static inline bool ____cptr_xen_trap_enabled(const struct kvm_vcpu *vcpu, in ____cptr_xen_trap_enabled() argument
673 return vcpu_el2_tge_is_set(vcpu) && !vcpu_is_el2(vcpu); in ____cptr_xen_trap_enabled()
680 #define __guest_hyp_cptr_xen_trap_enabled(vcpu, xen) \ argument
681 (!vcpu_has_nv(vcpu) ? false : \
682 ____cptr_xen_trap_enabled(vcpu, \
684 vcpu_sanitised_cptr_el2(vcpu))))
686 static inline bool guest_hyp_fpsimd_traps_enabled(const struct kvm_vcpu *vcpu) in guest_hyp_fpsimd_traps_enabled() argument
688 return __guest_hyp_cptr_xen_trap_enabled(vcpu, FPEN); in guest_hyp_fpsimd_traps_enabled()
691 static inline bool guest_hyp_sve_traps_enabled(const struct kvm_vcpu *vcpu) in guest_hyp_sve_traps_enabled() argument
693 return __guest_hyp_cptr_xen_trap_enabled(vcpu, ZEN); in guest_hyp_sve_traps_enabled()