git: e6ec41fa86d8 - main - amd64 efi rt: handle #BP

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 21 Nov 2024 22:05:59 UTC
The branch main has been updated by kib:

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

commit e6ec41fa86d88f80bd663e55455a6844619a9b24
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-11-21 04:57:58 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-11-21 22:05:28 +0000

    amd64 efi rt: handle #BP
    
    PR:     282860
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D47694
---
 sys/amd64/amd64/trap.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
index a6d6c792ee92..6ceeea41ea91 100644
--- a/sys/amd64/amd64/trap.c
+++ b/sys/amd64/amd64/trap.c
@@ -598,6 +598,18 @@ trap(struct trapframe *frame)
 			 * FALLTHROUGH (TRCTRAP kernel mode, kernel address)
 			 */
 		case T_BPTFLT:
+			/*
+			 * Most likely, EFI RT hitting INT3.  This
+			 * check prevents kdb from handling
+			 * breakpoints set on the BIOS text, if such
+			 * option is ever needed.
+			 */
+			if ((td->td_pflags & TDP_EFIRT) != 0 &&
+			    curpcb->pcb_onfault != NULL) {
+				frame->tf_rip = (long)curpcb->pcb_onfault;
+				return;
+			}
+
 			/*
 			 * If KDB is enabled, let it handle the debugger trap.
 			 * Otherwise, debugger traps "can't happen".