Merge branch 'kvm-arm64/debug-5.13' into kvmarm-master/next
authorMarc Zyngier <maz@kernel.org>
Tue, 13 Apr 2021 14:34:15 +0000 (15:34 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 13 Apr 2021 14:34:15 +0000 (15:34 +0100)
Signed-off-by: Marc Zyngier <maz@kernel.org>
1  2 
arch/arm64/include/asm/kvm_host.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kvm/arm.c
arch/arm64/kvm/debug.c
arch/arm64/kvm/sys_regs.c

Simple merge
Simple merge
Simple merge
@@@ -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));
  }
  
 -       * This also clears MDCR_EL2_E2PB_MASK to disable guest access
 -       * to the profiling buffer.
+ /**
+  * 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 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
   */
Simple merge