From nobody Tue Oct 18 14:03:27 2022 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 4MsFvM6WX4z4ft0l; Tue, 18 Oct 2022 14:03:27 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MsFvM5sz2z3FqR; Tue, 18 Oct 2022 14:03:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666101807; 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=028n/3wDAMP8TicGGkzNxZcQzy7wcW9wHdlFkdHvPQ8=; b=EjM1Vv6Q0QSROjQ/lHiY5kGMY3wLcBKJKeCr2DRsO9YgUp3VLCpchXgRzf3srq09S8Grrp H/TCh82T304JWH0iTRynxfACpBMBeyY+jOOntrTBZ2G2E8T97UVvCbT3e1oJ2XQkZ6TCpb JEIFBPBEtZC0jfpoH25Kx7lqPjcQU/1rs49SR5Q7qJmqiK4PMa4JpIxH2D+e7k056ZtxWM Mmpz/bI2qRzL8exZwndYhnw7LX7jwIReSyKi+nJEFw7eou1SttYw4oE7Awn43ANoKGvr5Z PSgRWUHFyA8KEoPuo1IL8cepjeVmYzkKwXtxS/36zp8EXB4dG9lPMHtS4/frLg== 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 4MsFvM4zYNz1Bnv; Tue, 18 Oct 2022 14:03:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29IE3RE0092380; Tue, 18 Oct 2022 14:03:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29IE3Rbs092379; Tue, 18 Oct 2022 14:03:27 GMT (envelope-from git) Date: Tue, 18 Oct 2022 14:03:27 GMT Message-Id: <202210181403.29IE3Rbs092379@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 247ea4381bf7 - stable/13 - dtrace: Add a "regs" variable 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 247ea4381bf72e9b1be725810df63928583641f7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666101807; 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=028n/3wDAMP8TicGGkzNxZcQzy7wcW9wHdlFkdHvPQ8=; b=erVwagsZY+kdmn6n6aNtGIqS+z4/xpKKr4Lfh9rwt+HPo8170LlWFGaRwCxd6yp7lvNmYs l8geGtOINXsSnDh5J7Yx/76fJ1LEjF5zdXwa2X7SXmuVLRm6XapRkS1dfyt1Txv3x6JLHn 9q2ysr0pGTw8WeGpjmAPIkk9ANzgGWSr4NtCAPfbaAAILTTkLYBDZ4rBR7NWJay1RN7ujK usoHjJH+jxnUWBWAuByHQLxjGh7VSmTIQrR6Ok0Qgxc5sFc1MifjuG24dkPsMOiS95NOAJ vvplayWQWN4tLPsdnN8ZmP8jt1z+UR/E8j9bVk4EIb1gwpjWKtBdwVaUeqbB5g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666101807; a=rsa-sha256; cv=none; b=Id+SAMkOlVpgdEjAlR0wHenyFzkBHaYptlkKzEkDqrfGmGLYtjowcPdWkpqwxsyhcR5jt3 54oMthowJvz0lJxhm0M2CTLK2XDflwTSddoQl+qmWSV4hzoyKXszF7yOS7b4WeiRRzaibQ 4pKB4RHi27SpwGHEqLyUQGJoa8ecGmvcZa+t0yCKd+FWkDuoTLg7DTtgMwGm5g3q8KabLF 2aM9KA3cE2NJQ5ytnnMUOtBW109Xon2zimRNFa9x3GSrEIpt0XSvCvv/nG0l98VmhdljuE 74kK5wGhD7JLmBDVeKJBj4bGgi1ZUBS3n+KxIOOnyi3/Y71BZJCcoE5Dzw0cjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=247ea4381bf72e9b1be725810df63928583641f7 commit 247ea4381bf72e9b1be725810df63928583641f7 Author: Mark Johnston AuthorDate: 2022-10-04 16:54:36 +0000 Commit: Mark Johnston CommitDate: 2022-10-18 13:58:11 +0000 dtrace: Add a "regs" variable This allows invop-based providers (i.e., fbt and kinst) to expose the register file of the CPU at the point where the probe fired. It does not work for SDT providers because their probes are implemented as plain function calls and so don't save registers. It's not clear what semantics "regs" should have for them anyway. This is akin to "uregs", which nominally provides access to the userspace registers. In fact, DIF already had a DIF_VAR_REGS variable defined, it was simply unimplemented. Usage example: print the contents of %rdi upon each call to amd64_syscall(): fbt::amd64_syscall:entry {printf("%x", regs[R_RDI]);} Note that the R_* constants are defined in /usr/lib/dtrace/regs_x86.d. Currently there are no similar definitions for non-x86 platforms. Reviewed by: christos (cherry picked from commit bdd101c4d4aeab6c9e76250c310c16f5704b8b8c) --- .../opensolaris/lib/libdtrace/common/dt_open.c | 2 ++ .../contrib/opensolaris/uts/common/dtrace/dtrace.c | 26 ++++++---------------- sys/cddl/dev/dtrace/aarch64/dtrace_subr.c | 17 +++++++------- sys/cddl/dev/dtrace/amd64/dtrace_subr.c | 12 +++++++--- sys/cddl/dev/dtrace/arm/dtrace_subr.c | 16 +++++++------ sys/cddl/dev/dtrace/dtrace_cddl.h | 2 ++ sys/cddl/dev/dtrace/i386/dtrace_subr.c | 13 +++++++---- sys/cddl/dev/dtrace/mips/dtrace_subr.c | 16 +++++++------ sys/cddl/dev/dtrace/powerpc/dtrace_subr.c | 16 +++++++------ sys/cddl/dev/dtrace/riscv/dtrace_subr.c | 16 +++++++------ 10 files changed, 74 insertions(+), 62 deletions(-) diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c index f55d488f4d91..9621a0fcb391 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c @@ -416,6 +416,8 @@ static const dt_ident_t _dtrace_globals[] = { &dt_idops_func, "void(int)" }, { "rand", DT_IDENT_FUNC, 0, DIF_SUBR_RAND, DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_func, "int()" }, +{ "regs", DT_IDENT_ARRAY, 0, DIF_VAR_REGS, DT_ATTR_STABCMN, DT_VERS_1_13, + &dt_idops_regs, NULL }, { "rindex", DT_IDENT_FUNC, 0, DIF_SUBR_RINDEX, DT_ATTR_STABCMN, DT_VERS_1_1, &dt_idops_func, "int(const char *, const char *, [int])" }, #ifdef illumos diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c index 8163b85a8202..292326fb8efd 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c +++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c @@ -3360,30 +3360,19 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v, return (mstate->dtms_arg[ndx]); -#ifdef illumos - case DIF_VAR_UREGS: { - klwp_t *lwp; - - if (!dtrace_priv_proc(state)) - return (0); - - if ((lwp = curthread->t_lwp) == NULL) { - DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); - cpu_core[curcpu].cpuc_dtrace_illval = NULL; - return (0); - } - - return (dtrace_getreg(lwp->lwp_regs, ndx)); - return (0); - } -#else + case DIF_VAR_REGS: case DIF_VAR_UREGS: { struct trapframe *tframe; if (!dtrace_priv_proc(state)) return (0); - if ((tframe = curthread->td_frame) == NULL) { + if (v == DIF_VAR_REGS) + tframe = curthread->t_dtrace_trapframe; + else + tframe = curthread->td_frame; + + if (tframe == NULL) { DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR); cpu_core[curcpu].cpuc_dtrace_illval = 0; return (0); @@ -3391,7 +3380,6 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v, return (dtrace_getreg(tframe, ndx)); } -#endif case DIF_VAR_CURTHREAD: if (!dtrace_priv_proc(state)) diff --git a/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c b/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c index 74b3bf7ed7d1..694e3c70ae2d 100644 --- a/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/aarch64/dtrace_subr.c @@ -27,18 +27,16 @@ * Use is subject to license terms. */ -#include -__FBSDID("$FreeBSD$"); - #include #include -#include #include #include #include +#include #include #include #include +#include #include #include #include @@ -65,17 +63,20 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t eax) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + rval = 0; + td = curthread; + td->t_dtrace_trapframe = frame; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) if ((rval = hdlr->dtih_func(addr, frame, eax)) != 0) - return (rval); - - return (0); + break; + td->t_dtrace_trapframe = NULL; + return (rval); } - void dtrace_invop_add(int (*func)(uintptr_t, struct trapframe *, uintptr_t)) { diff --git a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c index f4fb70f80a6b..2521afc7b443 100644 --- a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c @@ -33,12 +33,13 @@ #include #include -#include #include #include +#include #include #include #include +#include #include #include #include @@ -65,15 +66,20 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *frame, void **scratch) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + td = curthread; + td->t_dtrace_trapframe = frame; + rval = 0; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) { rval = hdlr->dtih_func(addr, frame, (uintptr_t)scratch); if (rval != 0) - return (rval); + break; } - return (0); + td->t_dtrace_trapframe = NULL; + return (rval); } void diff --git a/sys/cddl/dev/dtrace/arm/dtrace_subr.c b/sys/cddl/dev/dtrace/arm/dtrace_subr.c index 367d8d75eea4..d39bc8a54288 100644 --- a/sys/cddl/dev/dtrace/arm/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/arm/dtrace_subr.c @@ -27,18 +27,16 @@ * Use is subject to license terms. */ -#include -__FBSDID("$FreeBSD$"); - #include #include -#include #include #include #include +#include #include #include #include +#include #include #include #include @@ -70,14 +68,18 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t eax) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + rval = 0; + td = curthread; + td->t_dtrace_trapframe = frame; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) if ((rval = hdlr->dtih_func(addr, frame, eax)) != 0) - return (rval); - - return (0); + break; + td->t_dtrace_trapframe = NULL; + return (rval); } diff --git a/sys/cddl/dev/dtrace/dtrace_cddl.h b/sys/cddl/dev/dtrace/dtrace_cddl.h index 344fe562bff9..3ad737b90f09 100644 --- a/sys/cddl/dev/dtrace/dtrace_cddl.h +++ b/sys/cddl/dev/dtrace/dtrace_cddl.h @@ -87,6 +87,7 @@ typedef struct kdtrace_thread { void *td_dtrace_sscr; /* Saved scratch space location. */ void *td_systrace_args; /* syscall probe arguments. */ uint64_t td_fasttrap_tp_gen; /* Tracepoint hash table gen. */ + struct trapframe *td_dtrace_trapframe; /* Trap frame from invop. */ } kdtrace_thread_t; /* @@ -115,6 +116,7 @@ typedef struct kdtrace_thread { #define t_dtrace_sscr td_dtrace->td_dtrace_sscr #define t_dtrace_systrace_args td_dtrace->td_systrace_args #define t_fasttrap_tp_gen td_dtrace->td_fasttrap_tp_gen +#define t_dtrace_trapframe td_dtrace->td_dtrace_trapframe #define p_dtrace_helpers p_dtrace->p_dtrace_helpers #define p_dtrace_count p_dtrace->p_dtrace_count #define p_dtrace_probes p_dtrace->p_dtrace_probes diff --git a/sys/cddl/dev/dtrace/i386/dtrace_subr.c b/sys/cddl/dev/dtrace/i386/dtrace_subr.c index 37cc7601bef5..69a07e8ee968 100644 --- a/sys/cddl/dev/dtrace/i386/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/i386/dtrace_subr.c @@ -33,14 +33,15 @@ #include #include -#include #include #include #include #include +#include #include #include #include +#include #include #include #include @@ -68,14 +69,18 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t eax) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + rval = 0; + td = curthread; + td->t_dtrace_trapframe = frame; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) if ((rval = hdlr->dtih_func(addr, frame, eax)) != 0) - return (rval); - - return (0); + break; + td->t_dtrace_trapframe = NULL; + return (rval); } void diff --git a/sys/cddl/dev/dtrace/mips/dtrace_subr.c b/sys/cddl/dev/dtrace/mips/dtrace_subr.c index c5ebe778b82d..b4e01f3858a8 100644 --- a/sys/cddl/dev/dtrace/mips/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/mips/dtrace_subr.c @@ -27,18 +27,16 @@ * Use is subject to license terms. */ -#include -__FBSDID("$FreeBSD$"); - #include #include -#include #include #include #include +#include #include #include #include +#include #include #include #include @@ -63,14 +61,18 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *stack, uintptr_t eax) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + rval = 0; + td = curthread; + td->t_dtrace_trapframe = frame; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) if ((rval = hdlr->dtih_func(addr, stack, eax)) != 0) - return (rval); - - return (0); + break; + td->t_dtrace_trapframe = NULL; + return (rval); } void diff --git a/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c b/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c index 0707a40aa22e..7a19a0b6caec 100644 --- a/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c @@ -27,18 +27,16 @@ * Use is subject to license terms. */ -#include -__FBSDID("$FreeBSD$"); - #include #include -#include #include #include #include +#include #include #include #include +#include #include #include #include @@ -65,14 +63,18 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *frame, uintptr_t arg0) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + rval = 0; + td = curthread; + td->t_dtrace_trapframe = frame; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) if ((rval = hdlr->dtih_func(addr, frame, arg0)) != 0) - return (rval); - - return (0); + break; + td->t_dtrace_trapframe = NULL; + return (rval); } void diff --git a/sys/cddl/dev/dtrace/riscv/dtrace_subr.c b/sys/cddl/dev/dtrace/riscv/dtrace_subr.c index 964be9571098..1e24a88f6c75 100644 --- a/sys/cddl/dev/dtrace/riscv/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/riscv/dtrace_subr.c @@ -29,18 +29,16 @@ * Use is subject to license terms. */ -#include -__FBSDID("$FreeBSD$"); - #include #include -#include #include #include #include +#include #include #include #include +#include #include #include #include @@ -68,14 +66,18 @@ dtrace_invop_hdlr_t *dtrace_invop_hdlr; int dtrace_invop(uintptr_t addr, struct trapframe *frame) { + struct thread *td; dtrace_invop_hdlr_t *hdlr; int rval; + rval = 0; + td = curthread; + td->t_dtrace_trapframe = frame; for (hdlr = dtrace_invop_hdlr; hdlr != NULL; hdlr = hdlr->dtih_next) if ((rval = hdlr->dtih_func(addr, frame, 0)) != 0) - return (rval); - - return (0); + break; + td->t_dtrace_trapframe = NULL; + return (rval); } void