1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 256c7f5e7SAlex Bennée /* 356c7f5e7SAlex Bennée * Debug and Guest Debug support 456c7f5e7SAlex Bennée * 556c7f5e7SAlex Bennée * Copyright (C) 2015 - Linaro Ltd 656c7f5e7SAlex Bennée * Author: Alex Bennée <alex.bennee@linaro.org> 756c7f5e7SAlex Bennée */ 856c7f5e7SAlex Bennée 956c7f5e7SAlex Bennée #include <linux/kvm_host.h> 10eef8c85aSAlex Bennée #include <linux/hw_breakpoint.h> 1156c7f5e7SAlex Bennée 12337b99bfSAlex Bennée #include <asm/debug-monitors.h> 13337b99bfSAlex Bennée #include <asm/kvm_asm.h> 1456c7f5e7SAlex Bennée #include <asm/kvm_arm.h> 15337b99bfSAlex Bennée #include <asm/kvm_emulate.h> 16337b99bfSAlex Bennée 17eef8c85aSAlex Bennée #include "trace.h" 18eef8c85aSAlex Bennée 19337b99bfSAlex Bennée /* These are the bits of MDSCR_EL1 we may manipulate */ 20337b99bfSAlex Bennée #define MDSCR_EL1_DEBUG_MASK (DBG_MDSCR_SS | \ 21337b99bfSAlex Bennée DBG_MDSCR_KDE | \ 22337b99bfSAlex Bennée DBG_MDSCR_MDE) 2356c7f5e7SAlex Bennée 24d6c850ddSFuad Tabba static DEFINE_PER_CPU(u64, mdcr_el2); 2556c7f5e7SAlex Bennée 2656c7f5e7SAlex Bennée /** 27337b99bfSAlex Bennée * save/restore_guest_debug_regs 28337b99bfSAlex Bennée * 29337b99bfSAlex Bennée * For some debug operations we need to tweak some guest registers. As 30337b99bfSAlex Bennée * a result we need to save the state of those registers before we 31337b99bfSAlex Bennée * make those modifications. 32337b99bfSAlex Bennée * 33337b99bfSAlex Bennée * Guest access to MDSCR_EL1 is trapped by the hypervisor and handled 34337b99bfSAlex Bennée * after we have restored the preserved value to the main context. 3534fbdee0SReiji Watanabe * 3634fbdee0SReiji Watanabe * When single-step is enabled by userspace, we tweak PSTATE.SS on every 3734fbdee0SReiji Watanabe * guest entry. Preserve PSTATE.SS so we can restore the original value 3834fbdee0SReiji Watanabe * for the vcpu after the single-step is disabled. 39337b99bfSAlex Bennée */ 40337b99bfSAlex Bennée static void save_guest_debug_regs(struct kvm_vcpu *vcpu) 41337b99bfSAlex Bennée { 428d404c4cSChristoffer Dall u64 val = vcpu_read_sys_reg(vcpu, MDSCR_EL1); 438d404c4cSChristoffer Dall 448d404c4cSChristoffer Dall vcpu->arch.guest_debug_preserved.mdscr_el1 = val; 45eef8c85aSAlex Bennée 46eef8c85aSAlex Bennée trace_kvm_arm_set_dreg32("Saved MDSCR_EL1", 47eef8c85aSAlex Bennée vcpu->arch.guest_debug_preserved.mdscr_el1); 4834fbdee0SReiji Watanabe 4934fbdee0SReiji Watanabe vcpu->arch.guest_debug_preserved.pstate_ss = 5034fbdee0SReiji Watanabe (*vcpu_cpsr(vcpu) & DBG_SPSR_SS); 51337b99bfSAlex Bennée } 52337b99bfSAlex Bennée 53337b99bfSAlex Bennée static void restore_guest_debug_regs(struct kvm_vcpu *vcpu) 54337b99bfSAlex Bennée { 558d404c4cSChristoffer Dall u64 val = vcpu->arch.guest_debug_preserved.mdscr_el1; 568d404c4cSChristoffer Dall 578d404c4cSChristoffer Dall vcpu_write_sys_reg(vcpu, val, MDSCR_EL1); 58eef8c85aSAlex Bennée 59eef8c85aSAlex Bennée trace_kvm_arm_set_dreg32("Restored MDSCR_EL1", 608d404c4cSChristoffer Dall vcpu_read_sys_reg(vcpu, MDSCR_EL1)); 6134fbdee0SReiji Watanabe 6234fbdee0SReiji Watanabe if (vcpu->arch.guest_debug_preserved.pstate_ss) 6334fbdee0SReiji Watanabe *vcpu_cpsr(vcpu) |= DBG_SPSR_SS; 6434fbdee0SReiji Watanabe else 6534fbdee0SReiji Watanabe *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; 66337b99bfSAlex Bennée } 67337b99bfSAlex Bennée 68337b99bfSAlex Bennée /** 6956c7f5e7SAlex Bennée * kvm_arm_init_debug - grab what we need for debug 7056c7f5e7SAlex Bennée * 7156c7f5e7SAlex Bennée * Currently the sole task of this function is to retrieve the initial 7256c7f5e7SAlex Bennée * value of mdcr_el2 so we can preserve MDCR_EL2.HPMN which has 7356c7f5e7SAlex Bennée * presumably been set-up by some knowledgeable bootcode. 7456c7f5e7SAlex Bennée * 7556c7f5e7SAlex Bennée * It is called once per-cpu during CPU hyp initialisation. 7656c7f5e7SAlex Bennée */ 7756c7f5e7SAlex Bennée 7856c7f5e7SAlex Bennée void kvm_arm_init_debug(void) 7956c7f5e7SAlex Bennée { 807aa8d146SMarc Zyngier __this_cpu_write(mdcr_el2, kvm_call_hyp_ret(__kvm_get_mdcr_el2)); 8156c7f5e7SAlex Bennée } 8256c7f5e7SAlex Bennée 8356c7f5e7SAlex Bennée /** 84263d6287SAlexandru Elisei * kvm_arm_setup_mdcr_el2 - configure vcpu mdcr_el2 value 85263d6287SAlexandru Elisei * 86263d6287SAlexandru Elisei * @vcpu: the vcpu pointer 87263d6287SAlexandru Elisei * 88263d6287SAlexandru Elisei * This ensures we will trap access to: 89263d6287SAlexandru Elisei * - Performance monitors (MDCR_EL2_TPM/MDCR_EL2_TPMCR) 90263d6287SAlexandru Elisei * - Debug ROM Address (MDCR_EL2_TDRA) 91263d6287SAlexandru Elisei * - OS related registers (MDCR_EL2_TDOSA) 92263d6287SAlexandru Elisei * - Statistical profiler (MDCR_EL2_TPMS/MDCR_EL2_E2PB) 93263d6287SAlexandru Elisei * - Self-hosted Trace Filter controls (MDCR_EL2_TTRF) 94fbb31e5fSMarc Zyngier * - Self-hosted Trace (MDCR_EL2_TTRF/MDCR_EL2_E2TB) 95263d6287SAlexandru Elisei */ 96263d6287SAlexandru Elisei static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu) 97263d6287SAlexandru Elisei { 98263d6287SAlexandru Elisei /* 99fbb31e5fSMarc Zyngier * This also clears MDCR_EL2_E2PB_MASK and MDCR_EL2_E2TB_MASK 100fbb31e5fSMarc Zyngier * to disable guest access to the profiling and trace buffers 101263d6287SAlexandru Elisei */ 102263d6287SAlexandru Elisei vcpu->arch.mdcr_el2 = __this_cpu_read(mdcr_el2) & MDCR_EL2_HPMN_MASK; 103263d6287SAlexandru Elisei vcpu->arch.mdcr_el2 |= (MDCR_EL2_TPM | 104263d6287SAlexandru Elisei MDCR_EL2_TPMS | 105263d6287SAlexandru Elisei MDCR_EL2_TTRF | 106263d6287SAlexandru Elisei MDCR_EL2_TPMCR | 107263d6287SAlexandru Elisei MDCR_EL2_TDRA | 108263d6287SAlexandru Elisei MDCR_EL2_TDOSA); 109263d6287SAlexandru Elisei 110263d6287SAlexandru Elisei /* Is the VM being debugged by userspace? */ 111263d6287SAlexandru Elisei if (vcpu->guest_debug) 112263d6287SAlexandru Elisei /* Route all software debug exceptions to EL2 */ 113263d6287SAlexandru Elisei vcpu->arch.mdcr_el2 |= MDCR_EL2_TDE; 114263d6287SAlexandru Elisei 115263d6287SAlexandru Elisei /* 116263d6287SAlexandru Elisei * Trap debug register access when one of the following is true: 117263d6287SAlexandru Elisei * - Userspace is using the hardware to debug the guest 118263d6287SAlexandru Elisei * (KVM_GUESTDBG_USE_HW is set). 119b1da4908SMarc Zyngier * - The guest is not using debug (DEBUG_DIRTY clear). 1207dabf02fSOliver Upton * - The guest has enabled the OS Lock (debug exceptions are blocked). 121263d6287SAlexandru Elisei */ 122263d6287SAlexandru Elisei if ((vcpu->guest_debug & KVM_GUESTDBG_USE_HW) || 123b1da4908SMarc Zyngier !vcpu_get_flag(vcpu, DEBUG_DIRTY) || 1247dabf02fSOliver Upton kvm_vcpu_os_lock_enabled(vcpu)) 125263d6287SAlexandru Elisei vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA; 126263d6287SAlexandru Elisei 127263d6287SAlexandru Elisei trace_kvm_arm_set_dreg32("MDCR_EL2", vcpu->arch.mdcr_el2); 128263d6287SAlexandru Elisei } 129263d6287SAlexandru Elisei 130263d6287SAlexandru Elisei /** 131263d6287SAlexandru Elisei * kvm_arm_vcpu_init_debug - setup vcpu debug traps 132263d6287SAlexandru Elisei * 133263d6287SAlexandru Elisei * @vcpu: the vcpu pointer 134263d6287SAlexandru Elisei * 135263d6287SAlexandru Elisei * Set vcpu initial mdcr_el2 value. 136263d6287SAlexandru Elisei */ 137263d6287SAlexandru Elisei void kvm_arm_vcpu_init_debug(struct kvm_vcpu *vcpu) 138263d6287SAlexandru Elisei { 139263d6287SAlexandru Elisei preempt_disable(); 140263d6287SAlexandru Elisei kvm_arm_setup_mdcr_el2(vcpu); 141263d6287SAlexandru Elisei preempt_enable(); 142263d6287SAlexandru Elisei } 143263d6287SAlexandru Elisei 144263d6287SAlexandru Elisei /** 14584e690bfSAlex Bennée * kvm_arm_reset_debug_ptr - reset the debug ptr to point to the vcpu state 14684e690bfSAlex Bennée */ 14784e690bfSAlex Bennée 14884e690bfSAlex Bennée void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu) 14984e690bfSAlex Bennée { 15084e690bfSAlex Bennée vcpu->arch.debug_ptr = &vcpu->arch.vcpu_debug_state; 15184e690bfSAlex Bennée } 15284e690bfSAlex Bennée 15384e690bfSAlex Bennée /** 15456c7f5e7SAlex Bennée * kvm_arm_setup_debug - set up debug related stuff 15556c7f5e7SAlex Bennée * 15656c7f5e7SAlex Bennée * @vcpu: the vcpu pointer 15756c7f5e7SAlex Bennée * 15856c7f5e7SAlex Bennée * This is called before each entry into the hypervisor to setup any 159263d6287SAlexandru Elisei * debug related registers. 16056c7f5e7SAlex Bennée * 16156c7f5e7SAlex Bennée * Additionally, KVM only traps guest accesses to the debug registers if 162b1da4908SMarc Zyngier * the guest is not actively using them (see the DEBUG_DIRTY 163b1da4908SMarc Zyngier * flag on vcpu->arch.iflags). Since the guest must not interfere 16456c7f5e7SAlex Bennée * with the hardware state when debugging the guest, we must ensure that 16556c7f5e7SAlex Bennée * trapping is enabled whenever we are debugging the guest using the 16656c7f5e7SAlex Bennée * debug registers. 16756c7f5e7SAlex Bennée */ 16856c7f5e7SAlex Bennée 16956c7f5e7SAlex Bennée void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) 17056c7f5e7SAlex Bennée { 1714942dc66SAndrew Murray unsigned long mdscr, orig_mdcr_el2 = vcpu->arch.mdcr_el2; 17256c7f5e7SAlex Bennée 173eef8c85aSAlex Bennée trace_kvm_arm_setup_debug(vcpu, vcpu->guest_debug); 174eef8c85aSAlex Bennée 175263d6287SAlexandru Elisei kvm_arm_setup_mdcr_el2(vcpu); 17656c7f5e7SAlex Bennée 1777dabf02fSOliver Upton /* Check if we need to use the debug registers. */ 1787dabf02fSOliver Upton if (vcpu->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) { 179337b99bfSAlex Bennée /* Save guest debug state */ 180337b99bfSAlex Bennée save_guest_debug_regs(vcpu); 181337b99bfSAlex Bennée 182337b99bfSAlex Bennée /* 183337b99bfSAlex Bennée * Single Step (ARM ARM D2.12.3 The software step state 184337b99bfSAlex Bennée * machine) 185337b99bfSAlex Bennée * 186337b99bfSAlex Bennée * If we are doing Single Step we need to manipulate 187337b99bfSAlex Bennée * the guest's MDSCR_EL1.SS and PSTATE.SS. Once the 188337b99bfSAlex Bennée * step has occurred the hypervisor will trap the 189337b99bfSAlex Bennée * debug exception and we return to userspace. 190337b99bfSAlex Bennée * 191337b99bfSAlex Bennée * If the guest attempts to single step its userspace 192337b99bfSAlex Bennée * we would have to deal with a trapped exception 193337b99bfSAlex Bennée * while in the guest kernel. Because this would be 194337b99bfSAlex Bennée * hard to unwind we suppress the guest's ability to 195337b99bfSAlex Bennée * do so by masking MDSCR_EL.SS. 196337b99bfSAlex Bennée * 197337b99bfSAlex Bennée * This confuses guest debuggers which use 198337b99bfSAlex Bennée * single-step behind the scenes but everything 199337b99bfSAlex Bennée * returns to normal once the host is no longer 200337b99bfSAlex Bennée * debugging the system. 201337b99bfSAlex Bennée */ 202337b99bfSAlex Bennée if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { 203*370531d1SReiji Watanabe /* 204*370531d1SReiji Watanabe * If the software step state at the last guest exit 205*370531d1SReiji Watanabe * was Active-pending, we don't set DBG_SPSR_SS so 206*370531d1SReiji Watanabe * that the state is maintained (to not run another 207*370531d1SReiji Watanabe * single-step until the pending Software Step 208*370531d1SReiji Watanabe * exception is taken). 209*370531d1SReiji Watanabe */ 210*370531d1SReiji Watanabe if (!vcpu_get_flag(vcpu, DBG_SS_ACTIVE_PENDING)) 211337b99bfSAlex Bennée *vcpu_cpsr(vcpu) |= DBG_SPSR_SS; 212*370531d1SReiji Watanabe else 213*370531d1SReiji Watanabe *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS; 214*370531d1SReiji Watanabe 2158d404c4cSChristoffer Dall mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); 2168d404c4cSChristoffer Dall mdscr |= DBG_MDSCR_SS; 2178d404c4cSChristoffer Dall vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); 218337b99bfSAlex Bennée } else { 2198d404c4cSChristoffer Dall mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); 2208d404c4cSChristoffer Dall mdscr &= ~DBG_MDSCR_SS; 2218d404c4cSChristoffer Dall vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); 222337b99bfSAlex Bennée } 223834bf887SAlex Bennée 224eef8c85aSAlex Bennée trace_kvm_arm_set_dreg32("SPSR_EL2", *vcpu_cpsr(vcpu)); 225eef8c85aSAlex Bennée 226834bf887SAlex Bennée /* 227834bf887SAlex Bennée * HW Breakpoints and watchpoints 228834bf887SAlex Bennée * 229834bf887SAlex Bennée * We simply switch the debug_ptr to point to our new 230834bf887SAlex Bennée * external_debug_state which has been populated by the 231b1da4908SMarc Zyngier * debug ioctl. The existing DEBUG_DIRTY mechanism ensures 232b1da4908SMarc Zyngier * the registers are updated on the world switch. 233834bf887SAlex Bennée */ 234834bf887SAlex Bennée if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) { 235834bf887SAlex Bennée /* Enable breakpoints/watchpoints */ 2368d404c4cSChristoffer Dall mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); 2378d404c4cSChristoffer Dall mdscr |= DBG_MDSCR_MDE; 2388d404c4cSChristoffer Dall vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); 239834bf887SAlex Bennée 240834bf887SAlex Bennée vcpu->arch.debug_ptr = &vcpu->arch.external_debug_state; 241b1da4908SMarc Zyngier vcpu_set_flag(vcpu, DEBUG_DIRTY); 242eef8c85aSAlex Bennée 243eef8c85aSAlex Bennée trace_kvm_arm_set_regset("BKPTS", get_num_brps(), 244eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_bcr[0], 245eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_bvr[0]); 246eef8c85aSAlex Bennée 247eef8c85aSAlex Bennée trace_kvm_arm_set_regset("WAPTS", get_num_wrps(), 248eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_wcr[0], 249eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_wvr[0]); 2507dabf02fSOliver Upton 2517dabf02fSOliver Upton /* 2527dabf02fSOliver Upton * The OS Lock blocks debug exceptions in all ELs when it is 2537dabf02fSOliver Upton * enabled. If the guest has enabled the OS Lock, constrain its 2547dabf02fSOliver Upton * effects to the guest. Emulate the behavior by clearing 2557dabf02fSOliver Upton * MDSCR_EL1.MDE. In so doing, we ensure that host debug 2567dabf02fSOliver Upton * exceptions are unaffected by guest configuration of the OS 2577dabf02fSOliver Upton * Lock. 2587dabf02fSOliver Upton */ 2597dabf02fSOliver Upton } else if (kvm_vcpu_os_lock_enabled(vcpu)) { 2607dabf02fSOliver Upton mdscr = vcpu_read_sys_reg(vcpu, MDSCR_EL1); 2617dabf02fSOliver Upton mdscr &= ~DBG_MDSCR_MDE; 2627dabf02fSOliver Upton vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1); 263337b99bfSAlex Bennée } 26456c7f5e7SAlex Bennée } 26556c7f5e7SAlex Bennée 266834bf887SAlex Bennée BUG_ON(!vcpu->guest_debug && 267834bf887SAlex Bennée vcpu->arch.debug_ptr != &vcpu->arch.vcpu_debug_state); 268834bf887SAlex Bennée 26954ceb1bcSChristoffer Dall /* If KDE or MDE are set, perform a full save/restore cycle. */ 2708d404c4cSChristoffer Dall if (vcpu_read_sys_reg(vcpu, MDSCR_EL1) & (DBG_MDSCR_KDE | DBG_MDSCR_MDE)) 271b1da4908SMarc Zyngier vcpu_set_flag(vcpu, DEBUG_DIRTY); 27254ceb1bcSChristoffer Dall 2734942dc66SAndrew Murray /* Write mdcr_el2 changes since vcpu_load on VHE systems */ 2744942dc66SAndrew Murray if (has_vhe() && orig_mdcr_el2 != vcpu->arch.mdcr_el2) 2754942dc66SAndrew Murray write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); 2764942dc66SAndrew Murray 2778d404c4cSChristoffer Dall trace_kvm_arm_set_dreg32("MDSCR_EL1", vcpu_read_sys_reg(vcpu, MDSCR_EL1)); 278834bf887SAlex Bennée } 279834bf887SAlex Bennée 28056c7f5e7SAlex Bennée void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) 28156c7f5e7SAlex Bennée { 282eef8c85aSAlex Bennée trace_kvm_arm_clear_debug(vcpu->guest_debug); 283eef8c85aSAlex Bennée 2847dabf02fSOliver Upton /* 2857dabf02fSOliver Upton * Restore the guest's debug registers if we were using them. 2867dabf02fSOliver Upton */ 2877dabf02fSOliver Upton if (vcpu->guest_debug || kvm_vcpu_os_lock_enabled(vcpu)) { 288*370531d1SReiji Watanabe if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { 289*370531d1SReiji Watanabe if (!(*vcpu_cpsr(vcpu) & DBG_SPSR_SS)) 290*370531d1SReiji Watanabe /* 291*370531d1SReiji Watanabe * Mark the vcpu as ACTIVE_PENDING 292*370531d1SReiji Watanabe * until Software Step exception is taken. 293*370531d1SReiji Watanabe */ 294*370531d1SReiji Watanabe vcpu_set_flag(vcpu, DBG_SS_ACTIVE_PENDING); 295*370531d1SReiji Watanabe } 296*370531d1SReiji Watanabe 297337b99bfSAlex Bennée restore_guest_debug_regs(vcpu); 298834bf887SAlex Bennée 299834bf887SAlex Bennée /* 300834bf887SAlex Bennée * If we were using HW debug we need to restore the 301834bf887SAlex Bennée * debug_ptr to the guest debug state. 302834bf887SAlex Bennée */ 303eef8c85aSAlex Bennée if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW) { 304834bf887SAlex Bennée kvm_arm_reset_debug_ptr(vcpu); 305834bf887SAlex Bennée 306eef8c85aSAlex Bennée trace_kvm_arm_set_regset("BKPTS", get_num_brps(), 307eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_bcr[0], 308eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_bvr[0]); 309eef8c85aSAlex Bennée 310eef8c85aSAlex Bennée trace_kvm_arm_set_regset("WAPTS", get_num_wrps(), 311eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_wcr[0], 312eef8c85aSAlex Bennée &vcpu->arch.debug_ptr->dbg_wvr[0]); 313eef8c85aSAlex Bennée } 314834bf887SAlex Bennée } 31556c7f5e7SAlex Bennée } 316d2602bb4SSuzuki K Poulose 317d2602bb4SSuzuki K Poulose void kvm_arch_vcpu_load_debug_state_flags(struct kvm_vcpu *vcpu) 318d2602bb4SSuzuki K Poulose { 319d2602bb4SSuzuki K Poulose u64 dfr0; 320d2602bb4SSuzuki K Poulose 321d2602bb4SSuzuki K Poulose /* For VHE, there is nothing to do */ 322d2602bb4SSuzuki K Poulose if (has_vhe()) 323d2602bb4SSuzuki K Poulose return; 324d2602bb4SSuzuki K Poulose 325d2602bb4SSuzuki K Poulose dfr0 = read_sysreg(id_aa64dfr0_el1); 326d2602bb4SSuzuki K Poulose /* 327d2602bb4SSuzuki K Poulose * If SPE is present on this CPU and is available at current EL, 328d2602bb4SSuzuki K Poulose * we may need to check if the host state needs to be saved. 329d2602bb4SSuzuki K Poulose */ 330d2602bb4SSuzuki K Poulose if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_PMSVER_SHIFT) && 331d2602bb4SSuzuki K Poulose !(read_sysreg_s(SYS_PMBIDR_EL1) & BIT(SYS_PMBIDR_EL1_P_SHIFT))) 332b1da4908SMarc Zyngier vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_SPE); 333a1319260SSuzuki K Poulose 334a1319260SSuzuki K Poulose /* Check if we have TRBE implemented and available at the host */ 335a1319260SSuzuki K Poulose if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_TRBE_SHIFT) && 336a1319260SSuzuki K Poulose !(read_sysreg_s(SYS_TRBIDR_EL1) & TRBIDR_PROG)) 337b1da4908SMarc Zyngier vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_TRBE); 338d2602bb4SSuzuki K Poulose } 339d2602bb4SSuzuki K Poulose 340d2602bb4SSuzuki K Poulose void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu) 341d2602bb4SSuzuki K Poulose { 342b1da4908SMarc Zyngier vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_SPE); 343b1da4908SMarc Zyngier vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRBE); 344d2602bb4SSuzuki K Poulose } 345