Skip to content

Commit 4942dc6

Browse files
Andrew Murrayctmarinas
authored andcommitted
KVM: arm64: Write arch.mdcr_el2 changes since last vcpu_load on VHE
On VHE systems arch.mdcr_el2 is written to mdcr_el2 at vcpu_load time to set options for self-hosted debug and the performance monitors extension. Unfortunately the value of arch.mdcr_el2 is not calculated until kvm_arm_setup_debug() in the run loop after the vcpu has been loaded. This means that the initial brief iterations of the run loop use a zero value of mdcr_el2 - until the vcpu is preempted. This also results in a delay between changes to vcpu->guest_debug taking effect. Fix this by writing to mdcr_el2 in kvm_arm_setup_debug() on VHE systems when a change to arch.mdcr_el2 has been detected. Fixes: d5a21bc ("KVM: arm64: Move common VHE/non-VHE trap config in separate functions") Cc: <[email protected]> # 4.17.x- Suggested-by: James Morse <[email protected]> Acked-by: Will Deacon <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Signed-off-by: Andrew Murray <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent def9d27 commit 4942dc6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/arm64/kvm/debug.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu)
101101
void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
102102
{
103103
bool trap_debug = !(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY);
104-
unsigned long mdscr;
104+
unsigned long mdscr, orig_mdcr_el2 = vcpu->arch.mdcr_el2;
105105

106106
trace_kvm_arm_setup_debug(vcpu, vcpu->guest_debug);
107107

@@ -197,6 +197,10 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
197197
if (vcpu_read_sys_reg(vcpu, MDSCR_EL1) & (DBG_MDSCR_KDE | DBG_MDSCR_MDE))
198198
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
199199

200+
/* Write mdcr_el2 changes since vcpu_load on VHE systems */
201+
if (has_vhe() && orig_mdcr_el2 != vcpu->arch.mdcr_el2)
202+
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
203+
200204
trace_kvm_arm_set_dreg32("MDCR_EL2", vcpu->arch.mdcr_el2);
201205
trace_kvm_arm_set_dreg32("MDSCR_EL1", vcpu_read_sys_reg(vcpu, MDSCR_EL1));
202206
}

0 commit comments

Comments
 (0)