git: 6f2a87c6f1f8 - stable/14 - dtrace/profile: Set t_dtrace_trapframe for profile probes

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 15 Jan 2024 14:56:10 UTC
The branch stable/14 has been updated by markj:

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

commit 6f2a87c6f1f869d60390952f35a4802bbce7ab7c
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-01-07 16:35:06 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-01-15 14:49:21 +0000

    dtrace/profile: Set t_dtrace_trapframe for profile probes
    
    profile provider probes fire in the context of a timer interrupt.  Thus,
    the "regs" action can make use of the interrupt trap frame to get
    register values when the interrupt happened in kernel mode.  Make that
    trap frame available when possible so that "regs" works more or less as
    it already does with the fbt and kinst providers.
    
    MFC after:      1 week
    
    (cherry picked from commit 7d35b389729ef5a3efcac75ad265139ada3f8e69)
---
 sys/cddl/dev/profile/profile.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/cddl/dev/profile/profile.c b/sys/cddl/dev/profile/profile.c
index d86c09ba06b5..a939c13aad45 100644
--- a/sys/cddl/dev/profile/profile.c
+++ b/sys/cddl/dev/profile/profile.c
@@ -58,6 +58,8 @@
 #include <sys/dtrace.h>
 #include <sys/dtrace_bsd.h>
 
+#include <cddl/dev/dtrace/dtrace_cddl.h>
+
 #define	PROF_NAMELEN		15
 
 #define	PROF_PROFILE		0
@@ -246,12 +248,15 @@ profile_probe(profile_probe_t *prof, hrtime_t late)
 	if (frame != NULL) {
 		if (TRAPF_USERMODE(frame))
 			upc = TRAPF_PC(frame);
-		else
+		else {
 			pc = TRAPF_PC(frame);
+			td->t_dtrace_trapframe = frame;
+		}
 	} else if (TD_IS_IDLETHREAD(td))
 		pc = (uintfptr_t)&cpu_idle;
 
 	dtrace_probe(prof->prof_id, pc, upc, late, 0, 0);
+	td->t_dtrace_trapframe = NULL;
 }
 
 static void