git: 837bb27c93a5 - main - amd64 FRED: clear %dr6 on #DB from kernel

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 29 Oct 2026 01:35:00 UTC
The branch main has been updated by kib:

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

commit 837bb27c93a58a2df2f5203393ffa245b93caf31
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-29 00:57:52 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-10-29 01:33:47 +0000

    amd64 FRED: clear %dr6 on #DB from kernel
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 sys/amd64/amd64/trap.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
index 480728e9749f..d59b689c56b6 100644
--- a/sys/amd64/amd64/trap.c
+++ b/sys/amd64/amd64/trap.c
@@ -1785,6 +1785,14 @@ trap_fred_handle_k_exc(struct thread *td, struct trapframe_fred *frame,
 	case IDT_DE:
 		break;
 	case IDT_DB:
+		/*
+		 * Clear %dr6 when #DB trapped from kernel mode, so
+		 * that PT_GETDBREGS does not report stale value.  FRED updates
+		 * %dr6 despite providing the same information in the
+		 * tf_fred_evdata field.
+		 */
+		load_dr6(0);
+
 		if (user_dbreg_trap(frame->tf_fred_evdata))
 			return;
 		/* FALLTHROUGH */