Lines Matching full:vcpu
38 * for the vcpu after the single-step is disabled.
40 static void save_guest_debug_regs(struct kvm_vcpu *vcpu) in save_guest_debug_regs() argument
42 u64 val = vcpu_read_sys_reg(vcpu, MDSCR_EL1); in save_guest_debug_regs()
44 vcpu->arch.guest_debug_preserved.mdscr_el1 = val; in save_guest_debug_regs()
47 vcpu->arch.guest_debug_preserved.mdscr_el1); in save_guest_debug_regs()
49 vcpu->arch.guest_debug_preserved.pstate_ss = in save_guest_debug_regs()
50 (*vcpu_cpsr(vcpu) & DBG_SPSR_SS); in save_guest_debug_regs()
53 static void restore_guest_debug_regs(struct kvm_vcpu *vcpu) in restore_guest_debug_regs() argument
55 u64 val = vcpu->arch.guest_debug_preserved.mdscr_el1; in restore_guest_debug_regs()
57 vcpu_write_sys_reg(vcpu, val, MDSCR_EL1); in restore_guest_debug_regs()
60 vcpu_read_sys_reg(vcpu, MDSCR_EL1)); in restore_guest_debug_regs()
62 if (vcpu->arch.guest_debug_preserved.pstate_ss) in restore_guest_debug_regs()
63 *vcpu_cpsr(vcpu) |= DBG_SPSR_SS; in restore_guest_debug_regs()
65 *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; in restore_guest_debug_regs()
84 * kvm_arm_setup_mdcr_el2 - configure vcpu mdcr_el2 value
86 * @vcpu: the vcpu pointer
96 static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu) in kvm_arm_setup_mdcr_el2() argument
102 vcpu->arch.mdcr_el2 = __this_cpu_read(mdcr_el2) & MDCR_EL2_HPMN_MASK; in kvm_arm_setup_mdcr_el2()
103 vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | in kvm_arm_setup_mdcr_el2()
111 if (vcpu->guest_debug) in kvm_arm_setup_mdcr_el2()
113 vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE; in kvm_arm_setup_mdcr_el2()
122 if ((vcpu->guest_debug & KVM_GUESTDBG_USE_HW) || in kvm_arm_setup_mdcr_el2()
123 !vcpu_get_flag(vcpu, DEBUG_DIRTY) || in kvm_arm_setup_mdcr_el2()
124 kvm_vcpu_os_lock_enabled(vcpu)) in kvm_arm_setup_mdcr_el2()
125 vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA; in kvm_arm_setup_mdcr_el2()
127 trace_kvm_arm_set_dreg32("MDCR_EL2", vcpu->arch.mdcr_el2); in kvm_arm_setup_mdcr_el2()
131 * kvm_arm_vcpu_init_debug - setup vcpu debug traps
133 * @vcpu: the vcpu pointer
135 * Set vcpu initial mdcr_el2 value.
137 void kvm_arm_vcpu_init_debug(struct kvm_vcpu *vcpu) in kvm_arm_vcpu_init_debug() argument
140 kvm_arm_setup_mdcr_el2(vcpu); in kvm_arm_vcpu_init_debug()
145 * kvm_arm_reset_debug_ptr - reset the debug ptr to point to the vcpu state
146 * @vcpu: the vcpu pointer
149 void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu) in kvm_arm_reset_debug_ptr() argument
151 vcpu->arch.debug_ptr = &vcpu->arch.vcpu_debug_state; in kvm_arm_reset_debug_ptr()
157 * @vcpu: the vcpu pointer
164 * flag on vcpu->arch.iflags). Since the guest must not interfere
170 void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) in kvm_arm_setup_debug() argument
172 unsigned long mdscr, orig_mdcr_el2 = vcpu->arch.mdcr_el2; in kvm_arm_setup_debug()
174 trace_kvm_arm_setup_debug(vcpu, vcpu->guest_debug); in kvm_arm_setup_debug()
176 kvm_arm_setup_mdcr_el2(vcpu); in kvm_arm_setup_debug()
179 if (vcpu->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) { in kvm_arm_setup_debug()
181 save_guest_debug_regs(vcpu); in kvm_arm_setup_debug()
203 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { in kvm_arm_setup_debug()
211 if (!vcpu_get_flag(vcpu, DBG_SS_ACTIVE_PENDING)) in kvm_arm_setup_debug()
212 *vcpu_cpsr(vcpu) |= DBG_SPSR_SS; in kvm_arm_setup_debug()
214 *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; in kvm_arm_setup_debug()
216 mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); in kvm_arm_setup_debug()
218 vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); in kvm_arm_setup_debug()
220 mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); in kvm_arm_setup_debug()
222 vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); in kvm_arm_setup_debug()
225 trace_kvm_arm_set_dreg32("SPSR_EL2", *vcpu_cpsr(vcpu)); in kvm_arm_setup_debug()
235 if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) { in kvm_arm_setup_debug()
237 mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); in kvm_arm_setup_debug()
239 vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); in kvm_arm_setup_debug()
241 vcpu->arch.debug_ptr = &vcpu->arch.external_debug_state; in kvm_arm_setup_debug()
242 vcpu_set_flag(vcpu, DEBUG_DIRTY); in kvm_arm_setup_debug()
245 &vcpu->arch.debug_ptr->dbg_bcr[0], in kvm_arm_setup_debug()
246 &vcpu->arch.debug_ptr->dbg_bvr[0]); in kvm_arm_setup_debug()
249 &vcpu->arch.debug_ptr->dbg_wcr[0], in kvm_arm_setup_debug()
250 &vcpu->arch.debug_ptr->dbg_wvr[0]); in kvm_arm_setup_debug()
260 } else if (kvm_vcpu_os_lock_enabled(vcpu)) { in kvm_arm_setup_debug()
261 mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); in kvm_arm_setup_debug()
263 vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); in kvm_arm_setup_debug()
267 BUG_ON(!vcpu->guest_debug && in kvm_arm_setup_debug()
268 vcpu->arch.debug_ptr != &vcpu->arch.vcpu_debug_state); in kvm_arm_setup_debug()
271 if (vcpu_read_sys_reg(vcpu, MDSCR_EL1) & (DBG_MDSCR_KDE | DBG_MDSCR_MDE)) in kvm_arm_setup_debug()
272 vcpu_set_flag(vcpu, DEBUG_DIRTY); in kvm_arm_setup_debug()
275 if (has_vhe() && orig_mdcr_el2 != vcpu->arch.mdcr_el2) in kvm_arm_setup_debug()
276 write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); in kvm_arm_setup_debug()
278 trace_kvm_arm_set_dreg32("MDSCR_EL1", vcpu_read_sys_reg(vcpu, MDSCR_EL1)); in kvm_arm_setup_debug()
281 void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) in kvm_arm_clear_debug() argument
283 trace_kvm_arm_clear_debug(vcpu->guest_debug); in kvm_arm_clear_debug()
288 if (vcpu->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) { in kvm_arm_clear_debug()
289 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { in kvm_arm_clear_debug()
290 if (!(*vcpu_cpsr(vcpu) & DBG_SPSR_SS)) in kvm_arm_clear_debug()
292 * Mark the vcpu as ACTIVE_PENDING in kvm_arm_clear_debug()
295 vcpu_set_flag(vcpu, DBG_SS_ACTIVE_PENDING); in kvm_arm_clear_debug()
298 restore_guest_debug_regs(vcpu); in kvm_arm_clear_debug()
304 if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) { in kvm_arm_clear_debug()
305 kvm_arm_reset_debug_ptr(vcpu); in kvm_arm_clear_debug()
308 &vcpu->arch.debug_ptr->dbg_bcr[0], in kvm_arm_clear_debug()
309 &vcpu->arch.debug_ptr->dbg_bvr[0]); in kvm_arm_clear_debug()
312 &vcpu->arch.debug_ptr->dbg_wcr[0], in kvm_arm_clear_debug()
313 &vcpu->arch.debug_ptr->dbg_wvr[0]); in kvm_arm_clear_debug()
318 void kvm_arch_vcpu_load_debug_state_flags(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_load_debug_state_flags() argument
333 vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_SPE); in kvm_arch_vcpu_load_debug_state_flags()
338 vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_TRBE); in kvm_arch_vcpu_load_debug_state_flags()
341 void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu) in kvm_arch_vcpu_put_debug_state_flags() argument
343 vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_SPE); in kvm_arch_vcpu_put_debug_state_flags()
344 vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRBE); in kvm_arch_vcpu_put_debug_state_flags()