Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Mar 2026 22:51:06 +0000
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 914a53570750 - main - amd64: move efirt trap checks into the helper
Message-ID:  <69b494da.1d7bf.7cef39b3@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by kib:

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

commit 914a53570750ce5a104a5870403d7669656fddc3
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-03-11 11:53:52 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-03-13 22:47:13 +0000

    amd64: move efirt trap checks into the helper
    
    Reviewed by:    imp, jhb
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D55808
---
 sys/amd64/amd64/trap.c | 55 ++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 29 deletions(-)

diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c
index d173f57e2e4f..a4676f156431 100644
--- a/sys/amd64/amd64/trap.c
+++ b/sys/amd64/amd64/trap.c
@@ -218,6 +218,30 @@ trap_uprintf_signal(struct thread *td, struct trapframe *frame, register_t addr,
 	    fubyte((void *)(frame->tf_rip + 7)));
 }
 
+static bool
+trap_check_efirt(struct thread *td, struct trapframe *frame)
+{
+	/*
+	 * Most likely, EFI RT faulted.  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) {
+		u_long cnt = atomic_fetchadd_long(&cnt_efirt_faults, 1);
+
+		if ((print_efirt_faults == 1 && cnt == 0) ||
+		    print_efirt_faults == 2) {
+			printf("EFI RT fault %s\n",
+			    traptype_to_msg(frame->tf_trapno));
+			trap_diag(frame, 0);
+		}
+		frame->tf_rip = (long)curpcb->pcb_onfault;
+		return (true);
+	}
+	return (false);
+}
+
 /*
  * Table of handlers for various segment load faults.
  */
@@ -465,24 +489,8 @@ trap(struct trapframe *frame)
 		KASSERT(cold || td->td_ucred != NULL,
 		    ("kernel trap doesn't have ucred"));
 
-		/*
-		 * Most likely, EFI RT faulted.  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 && type != T_PAGEFLT) {
-			u_long cnt = atomic_fetchadd_long(&cnt_efirt_faults, 1);
-
-			if ((print_efirt_faults == 1 && cnt == 0) ||
-			    print_efirt_faults == 2) {
-				printf("EFI RT fault %s\n",
-				    traptype_to_msg(type));
-				trap_diag(frame, 0);
-			}
-			frame->tf_rip = (long)curpcb->pcb_onfault;
+		if (type != T_PAGEFLT && trap_check_efirt(td, frame))
 			return;
-		}
 
 		switch (type) {
 		case T_PAGEFLT:			/* page fault */
@@ -891,19 +899,8 @@ trap_pfault(struct trapframe *frame, bool usermode, int *signo, int *ucode)
 		return (1);
 after_vmfault:
 	if (td->td_intr_nesting_level == 0 &&
-	    curpcb->pcb_onfault != NULL) {
-		if ((td->td_pflags & TDP_EFIRT) != 0) {
-			u_long cnt = atomic_fetchadd_long(&cnt_efirt_faults, 1);
-
-			if ((print_efirt_faults == 1 && cnt == 0) ||
-			    print_efirt_faults == 2) {
-				printf("EFI RT page fault\n");
-				trap_diag(frame, eva);
-			}
-		}
-		frame->tf_rip = (long)curpcb->pcb_onfault;
+	    trap_check_efirt(td, frame))
 		return (0);
-	}
 	trap_fatal(frame, eva);
 	return (-1);
 }


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69b494da.1d7bf.7cef39b3>