Skip to content

Commit b47ffd1

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Write MDCR_EL2 directly from kvm_arm_setup_mdcr_el2()
Expecting the callee to know when MDCR_EL2 needs to be written to hardware asking for trouble. Do the deed from kvm_arm_setup_mdcr_el2() instead. Signed-off-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent d381e53 commit b47ffd1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

arch/arm64/kvm/debug.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ static void restore_guest_debug_regs(struct kvm_vcpu *vcpu)
7373
*/
7474
static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu)
7575
{
76+
preempt_disable();
77+
7678
/*
7779
* This also clears MDCR_EL2_E2PB_MASK and MDCR_EL2_E2TB_MASK
7880
* to disable guest access to the profiling and trace buffers
@@ -103,6 +105,12 @@ static void kvm_arm_setup_mdcr_el2(struct kvm_vcpu *vcpu)
103105
kvm_vcpu_os_lock_enabled(vcpu))
104106
vcpu->arch.mdcr_el2 |= MDCR_EL2_TDA;
105107

108+
/* Write MDCR_EL2 directly if we're already at EL2 */
109+
if (has_vhe())
110+
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
111+
112+
preempt_enable();
113+
106114
trace_kvm_arm_set_dreg32("MDCR_EL2", vcpu->arch.mdcr_el2);
107115
}
108116

@@ -148,7 +156,7 @@ void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu)
148156

149157
void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
150158
{
151-
unsigned long mdscr, orig_mdcr_el2 = vcpu->arch.mdcr_el2;
159+
unsigned long mdscr;
152160

153161
trace_kvm_arm_setup_debug(vcpu, vcpu->guest_debug);
154162

@@ -250,10 +258,6 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
250258
if (vcpu_read_sys_reg(vcpu, MDSCR_EL1) & (DBG_MDSCR_KDE | DBG_MDSCR_MDE))
251259
vcpu_set_flag(vcpu, DEBUG_DIRTY);
252260

253-
/* Write mdcr_el2 changes since vcpu_load on VHE systems */
254-
if (has_vhe() && orig_mdcr_el2 != vcpu->arch.mdcr_el2)
255-
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
256-
257261
trace_kvm_arm_set_dreg32("MDSCR_EL1", vcpu_read_sys_reg(vcpu, MDSCR_EL1));
258262
}
259263

0 commit comments

Comments
 (0)