From nobody Mon Jul 15 12:38:02 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WN1vG471sz5QrJs; Mon, 15 Jul 2024 12:38:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WN1vG27mRz4GpN; Mon, 15 Jul 2024 12:38:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721047082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OYK+ss12/1ZMWopZCTBAX/M3im9G/f+pTBuZexPmTTw=; b=EIE4pf+rvd61taKcOIyS8p2JZfQ0V4qUN9cM/iNBdyestD8up9WpMB2iRRj3oZdN192ojl f4VBqP0fTR4ar+83E7aRBvLeyh4tk0vf+wXI/PyGtJo6PYJtw28ID0A1bOfzwEuCG/y0dz 0otws/cLi1ZXtlVGUCR0fQRvOvZJyNhgjPlUjYicQde6c/Id5GN0735mv6oalnEmFtRSd/ 6r81oaIGn4ATEWYpBWm/vgCZljd/fr+kvX6bHPmS+XmAiAhe52BMb9I+Ymg/lNoqg5J8XS zhNDDDxRgZBcqadrScBxis7zS8mPIviWt6K6A5itjiZ5GmcrFbmlgBNXP6r2mg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721047082; a=rsa-sha256; cv=none; b=PSZfrHjsle48vW00F0li8XZMuIprRXt4DqZ6rVaKms+RV79XDYz6ZnzSSxs2XlANBMauUA FdU/ZmEyFECddb4efp0dyG5AHdR93Dg9rVy0RVkJXP5Gnq60NJOJYj3WA3B2k6NAeqD+YS 2JNyccdtjmkXZHJ8B2MqSlctSBE8ryaWEhvVZ/xHNAVgh+ZCGGLHg4mikN7q6CaQHcimfT x6/5KzXAVBjx8TsuzdAU4S818E1EQXZDW9RHD71KfA5F2ahM9agPLDRvp5xtzlAwF2Qokt jOjirxqLmCIdzCyzDulErGxhG5bjmrpBkZX22V3AKNpgdoBgqIpHPrZuVs3iKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721047082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=OYK+ss12/1ZMWopZCTBAX/M3im9G/f+pTBuZexPmTTw=; b=kxy1ZJq4SczhszgvflcSBsH+8Vvf+mBJArsoCZclvaMytxG6gorHONdPghsjc9+uIMIPna jdsaasFPeREBWOD91nWwaSqEt1L+bbcm5xCnitWBoiV0rW1XV5MT1p0fHZPsArU2hD+/TO 7JxuIdsBtWjm+bnnRkJccldIWjF0TgSOKa0pJDIyz6c3xMgxndhd2JY0hgOUv6+BxcXoK9 3o3z/sCb7gV3IZj1atqHuhAIh6mXOtjL9PI8uGuONybGAiDXVAiAObUkYXD6B9IJOHCvS9 R/NMti0iTTrkF5xf+FNIeJoLgBPw2rZwJSMA3FJVgfu/J8cToV1hbMtaXwgUPQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WN1vG1mSmzsp7; Mon, 15 Jul 2024 12:38:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46FCc2hs059285; Mon, 15 Jul 2024 12:38:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46FCc2eF059282; Mon, 15 Jul 2024 12:38:02 GMT (envelope-from git) Date: Mon, 15 Jul 2024 12:38:02 GMT Message-Id: <202407151238.46FCc2eF059282@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: 64b0acf87c97 - stable/14 - arm64: Mask non-debug exceptions when single stepping List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 64b0acf87c97d02929f99a14e9d47a4eba2958b4 Auto-Submitted: auto-generated The branch stable/14 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=64b0acf87c97d02929f99a14e9d47a4eba2958b4 commit 64b0acf87c97d02929f99a14e9d47a4eba2958b4 Author: Andrew Turner AuthorDate: 2024-03-14 14:02:56 +0000 Commit: Andrew Turner CommitDate: 2024-07-15 12:23:21 +0000 arm64: Mask non-debug exceptions when single stepping When an exception is pending when single stepping we may execute the handler for that exception rather than the single step handler. This could cause the scheduler to fire to run a new thread. This will mean we single step to a new thread causing unexpected results. Handle this by masking non-debug exceptions. This will cause issues when stepping over instructions that access the DAIF values so future work is needed to handle these cases, but for most code this now works as expected. Reviewed by: jhb Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D44350 (cherry picked from commit ed3c6cd76de8560c46607abe506a03568e9acab2) --- sys/arm64/arm64/debug_monitor.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/arm64/arm64/debug_monitor.c b/sys/arm64/arm64/debug_monitor.c index 271f6fc47ea4..380915d5163a 100644 --- a/sys/arm64/arm64/debug_monitor.c +++ b/sys/arm64/arm64/debug_monitor.c @@ -194,6 +194,15 @@ kdb_cpu_set_singlestep(void) ("%s: debug exceptions are not masked", __func__)); kdb_frame->tf_spsr |= PSR_SS; + + /* + * TODO: Handle single stepping over instructions that access + * the DAIF values. On a read the value will be incorrect. + */ + kernel_monitor.dbg_flags &= ~PSR_DAIF; + kernel_monitor.dbg_flags |= kdb_frame->tf_spsr & PSR_DAIF; + kdb_frame->tf_spsr |= (PSR_A | PSR_I | PSR_F); + WRITE_SPECIALREG(mdscr_el1, READ_SPECIALREG(mdscr_el1) | MDSCR_SS | MDSCR_KDE); @@ -215,6 +224,9 @@ kdb_cpu_clear_singlestep(void) KASSERT((READ_SPECIALREG(daif) & PSR_D) == PSR_D, ("%s: debug exceptions are not masked", __func__)); + kdb_frame->tf_spsr &= ~PSR_DAIF; + kdb_frame->tf_spsr |= kernel_monitor.dbg_flags & PSR_DAIF; + WRITE_SPECIALREG(mdscr_el1, READ_SPECIALREG(mdscr_el1) & ~(MDSCR_SS | MDSCR_KDE));