From: Marc Zyngier Date: Tue, 13 Apr 2021 14:34:15 +0000 (+0100) Subject: Merge branch 'kvm-arm64/debug-5.13' into kvmarm-master/next X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=fbb31e5f3ace5386aa13236be77d1b4d481c8c89;p=linux.git Merge branch 'kvm-arm64/debug-5.13' into kvmarm-master/next Signed-off-by: Marc Zyngier --- fbb31e5f3ace5386aa13236be77d1b4d481c8c89 diff --cc arch/arm64/kvm/debug.c index 6f992c6969116,2484b2cca74bc..d5e79d7ee6e90 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@@ -68,6 -68,64 +68,65 @@@ void kvm_arm_init_debug(void __this_cpu_write(mdcr_el2, kvm_call_hyp_ret(__kvm_get_mdcr_el2)); } + /** + * kvm_arm_setup_mdcr_el2 - configure vcpu mdcr_el2 value + * + * @vcpu: the vcpu pointer + * + * This ensures we will trap access to: + * - Performance monitors (MDCR_EL2_TPM/MDCR_EL2_TPMCR) + * - Debug ROM Address (MDCR_EL2_TDRA) + * - OS related registers (MDCR_EL2_TDOSA) + * - Statistical profiler (MDCR_EL2_TPMS/MDCR_EL2_E2PB) + * - Self-hosted Trace Filter controls (MDCR_EL2_TTRF) ++ * - Self-hosted Trace (MDCR_EL2_TTRF/MDCR_EL2_E2TB) + */ + static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu) + { + /* - * This also clears MDCR_EL2_E2PB_MASK to disable guest access - * to the profiling buffer. ++ * This also clears MDCR_EL2_E2PB_MASK and MDCR_EL2_E2TB_MASK ++ * to disable guest access to the profiling and trace buffers + */ + vcpu->arch.mdcr_el2 = __this_cpu_read(mdcr_el2) & MDCR_EL2_HPMN_MASK; + vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | + MDCR_EL2_TPMS | + MDCR_EL2_TTRF | + MDCR_EL2_TPMCR | + MDCR_EL2_TDRA | + MDCR_EL2_TDOSA); + + /* Is the VM being debugged by userspace? */ + if (vcpu->guest_debug) + /* Route all software debug exceptions to EL2 */ + vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE; + + /* + * Trap debug register access when one of the following is true: + * - Userspace is using the hardware to debug the guest + * (KVM_GUESTDBG_USE_HW is set). + * - The guest is not using debug (KVM_ARM64_DEBUG_DIRTY is clear). + */ + if ((vcpu->guest_debug & KVM_GUESTDBG_USE_HW) || + !(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY)) + vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA; + + trace_kvm_arm_set_dreg32("MDCR_EL2", vcpu->arch.mdcr_el2); + } + + /** + * kvm_arm_vcpu_init_debug - setup vcpu debug traps + * + * @vcpu: the vcpu pointer + * + * Set vcpu initial mdcr_el2 value. + */ + void kvm_arm_vcpu_init_debug(struct kvm_vcpu *vcpu) + { + preempt_disable(); + kvm_arm_setup_mdcr_el2(vcpu); + preempt_enable(); + } + /** * kvm_arm_reset_debug_ptr - reset the debug ptr to point to the vcpu state */