git: a44a95b00199 - releng/15.0 - arm64/vmm: Don't set MDSCR_EL1.KDE when enabling single-stepping

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Sun, 16 Nov 2025 02:00:44 UTC
The branch releng/15.0 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=a44a95b00199dbf97c2b22cfb59a610c07f0af58

commit a44a95b00199dbf97c2b22cfb59a610c07f0af58
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-05 20:54:30 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-16 02:00:30 +0000

    arm64/vmm: Don't set MDSCR_EL1.KDE when enabling single-stepping
    
    When VHE mode is enabled, this results in a hang on the host.  In
    particular, when MDSCR_EL2.KDE is set to 1 and the CPU is executing at
    EL_D, i.e., EL2, debug exceptions are enabled. In non-VHE mode, we call
    into the guest by trapping to EL2, which implicitly masks debug
    exceptions by setting PSTATE.D. However, in VHE mode, PSTATE.D remains
    clear, so when the guest's MDSCR_EL1 value is loaded, we immediately
    begin single-stepping.
    
    In non-VHE mode there is no need to set KDE either, so just stop setting
    it.
    
    Approved by:    re (cperciva)
    Reviewed by:    andrew
    MFC after:      3 days
    Sponsored by:   CHERI Research Centre (EPSRC grant UKRI3001)
    Differential Revision:  https://reviews.freebsd.org/D48965
    
    (cherry picked from commit ac0032344ca256f758a5eeb0fd6089dd647b0496)
    (cherry picked from commit 47fdacee69ec8ccb18df76b7584ffc5ce9862ec2)
---
 sys/arm64/vmm/vmm_arm64.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sys/arm64/vmm/vmm_arm64.c b/sys/arm64/vmm/vmm_arm64.c
index e293c99a6646..5bb038dec2d3 100644
--- a/sys/arm64/vmm/vmm_arm64.c
+++ b/sys/arm64/vmm/vmm_arm64.c
@@ -1365,19 +1365,18 @@ vmmops_setcap(void *vcpui, int num, int val)
 
 		if (val != 0) {
 			hypctx->debug_spsr |= (hypctx->tf.tf_spsr & PSR_SS);
-			hypctx->debug_mdscr |= hypctx->mdscr_el1 &
-			    (MDSCR_SS | MDSCR_KDE);
+			hypctx->debug_mdscr |= (hypctx->mdscr_el1 & MDSCR_SS);
 
 			hypctx->tf.tf_spsr |= PSR_SS;
-			hypctx->mdscr_el1 |= MDSCR_SS | MDSCR_KDE;
+			hypctx->mdscr_el1 |= MDSCR_SS;
 			hypctx->mdcr_el2 |= MDCR_EL2_TDE;
 		} else {
 			hypctx->tf.tf_spsr &= ~PSR_SS;
 			hypctx->tf.tf_spsr |= hypctx->debug_spsr;
 			hypctx->debug_spsr &= ~PSR_SS;
-			hypctx->mdscr_el1 &= ~(MDSCR_SS | MDSCR_KDE);
+			hypctx->mdscr_el1 &= ~MDSCR_SS;
 			hypctx->mdscr_el1 |= hypctx->debug_mdscr;
-			hypctx->debug_mdscr &= ~(MDSCR_SS | MDSCR_KDE);
+			hypctx->debug_mdscr &= ~MDSCR_SS;
 			hypctx->mdcr_el2 &= ~MDCR_EL2_TDE;
 		}
 		break;