From nobody Mon Jul 15 12:38:08 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 4WN1vN43w7z5QrRR; Mon, 15 Jul 2024 12:38:08 +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 4WN1vN2D5Jz4H7t; Mon, 15 Jul 2024 12:38:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721047088; 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=CggST6yvJ6AKqyHXmJeO6VN1HQlHMtXkdl0VU5uHfVo=; b=W2/Eo6iytdj7b16bcDBONSByfEHZnY8T5btD/rvuiJR7Ep2Kw/ebBLspPHANoIJgD9pMS2 +sEXKI5N7kuny8M3dHDa+Z8pdHhM33BqXqpQZ6dxmt2TaTg07bdi/5Kz9tUwTq2F5XVnvR A07zYZZPUOKCtLJ9q/XP2jNG4G9X473ilivLPBSuq5CFzh1OFqOxPSKdIgk+vHf+xC4DIh wcPqBJP2dNMwYAEx1rvahtdoyDQ9+DsYJwfJvaD8CqL1iju8qMDCmK4Z2dWeurFhx2fV39 qWntip5tKscqZRB5Rfqw0KWGujUoB/RuT7EIHuOadElVAJ240KKzXWeeyiWIuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721047088; a=rsa-sha256; cv=none; b=u0NOVn9J3JpjKX8Ry1ktkHP8zt6bWkPUJkE/kehng/9R1+BvZnPV6t4R1EDogJZrKKpSj2 okTG6iHokSyD12GGwE5JQA400sZi7t5zrBhq3X2pkr5wuqS+7Jfh1h4RrxBwH7GNdrDM/S 2IOcedqMPoEnnS37lhOK+ZfdrPzZ034O7JKLWCf5mHmb+dZtln4r7rMDqIDTztgPP2CBVR xsK3g1HKDq8YpieA7bMpviiEFO9TXBfWEOUVMOS+Zvnf7jvlkKdCbRU8h+nQYOQy+MUVb0 Yrxle+QOaQ7ynB1MixiZtUjt+uN+Fcrl7vpz91hSRJq18CC4jnOhcFTOyo7K1w== 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=1721047088; 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=CggST6yvJ6AKqyHXmJeO6VN1HQlHMtXkdl0VU5uHfVo=; b=oV3i1Mdww68sO5TYZsnML/cy4nIdKzSWviIs6dLmOg8mb5QGwjez9fj6iFaU/Uh7jljSeO 9mDEl5j1VVrjVyM5mIAESjlC6oL/o0jjqZ0CWPXrCHuWI3I19Ulh4o/p8gauw4xGoiBCrZ 5eDMs1AawjJRVt443ol/G8Attak5Bmq3KYOlht5vdcHgGftm3ZzvgbRJpm6pZ9z20Eqge/ sWtfaUO5v1EWlExZ0hMtwPaZ4g7zZo6pM2iYaMtUu3KCptVIKJG46EbL2f99f+8C2vgRI7 4KUP5ISFa4pxRFy4dIxtpFDWFgA39xA6KH9aR6qwo5JhJ08UZgRGxB4UNYt6HA== 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 4WN1vN1qktzt3D; Mon, 15 Jul 2024 12:38:08 +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 46FCc8OP059832; Mon, 15 Jul 2024 12:38:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46FCc8J0059829; Mon, 15 Jul 2024 12:38:08 GMT (envelope-from git) Date: Mon, 15 Jul 2024 12:38:08 GMT Message-Id: <202407151238.46FCc8J0059829@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: d8db6b4f079e - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: d8db6b4f079efc2de3195392a624ac2d47c3997f Auto-Submitted: auto-generated The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=d8db6b4f079efc2de3195392a624ac2d47c3997f commit d8db6b4f079efc2de3195392a624ac2d47c3997f Author: Andrew Turner AuthorDate: 2024-03-14 14:02:56 +0000 Commit: Andrew Turner CommitDate: 2024-07-15 12:34:28 +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 812f44398a67..6de148161a7f 100644 --- a/sys/arm64/arm64/debug_monitor.c +++ b/sys/arm64/arm64/debug_monitor.c @@ -188,6 +188,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); @@ -209,6 +218,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));