From: eugene.loh@oracle.com
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH v2 29/38] Set the ERROR PRID in BPF code
Date: Thu, 27 Jun 2024 22:03:12 -0400 [thread overview]
Message-ID: <20240628020316.32544-2-eugene.loh@oracle.com> (raw)
In-Reply-To: <20240628020316.32544-1-eugene.loh@oracle.com>
From: Eugene Loh <eugene.loh@oracle.com>
The patch can be simplified if we are willing to assume the
ERROR PRID is always 3, which is probably safe.
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
---
bpf/probe_error.c | 5 ++++
libdtrace/dt_bpf.h | 1 +
libdtrace/dt_cc.c | 3 +++
libdtrace/dt_dlibs.c | 1 +
test/unittest/builtinvar/tst.id_ERROR.d | 32 +++++++++++++++++++++++
test/unittest/builtinvar/tst.id_ERROR.r | 3 +++
test/unittest/builtinvar/tst.id_ERROR.r.p | 4 +++
7 files changed, 49 insertions(+)
create mode 100644 test/unittest/builtinvar/tst.id_ERROR.d
create mode 100644 test/unittest/builtinvar/tst.id_ERROR.r
create mode 100755 test/unittest/builtinvar/tst.id_ERROR.r.p
diff --git a/bpf/probe_error.c b/bpf/probe_error.c
index c8ddcdfa..a6616c2f 100644
--- a/bpf/probe_error.c
+++ b/bpf/probe_error.c
@@ -7,6 +7,8 @@
#include <bpf/bpf_helpers.h>
#include <dt_dctx.h>
+extern uint64_t ERROR_PRID;
+
#ifndef noinline
# define noinline __attribute__((noinline))
#endif
@@ -26,6 +28,7 @@ noinline void dt_probe_error(const dt_dctx_t *dctx, uint64_t pc, uint64_t fault,
uint64_t illval)
{
dt_mstate_t *mst = dctx->mst;
+ int oldprid = mst->prid;
mst->argv[0] = 0;
mst->argv[1] = mst->epid;
@@ -34,7 +37,9 @@ noinline void dt_probe_error(const dt_dctx_t *dctx, uint64_t pc, uint64_t fault,
mst->argv[4] = fault;
mst->argv[5] = illval;
+ mst->prid = ((uint64_t)&ERROR_PRID);
dt_error(dctx);
+ mst->prid = oldprid;
mst->fault = fault;
}
diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
index 5b2df264..58cf29cc 100644
--- a/libdtrace/dt_bpf.h
+++ b/libdtrace/dt_bpf.h
@@ -56,6 +56,7 @@ extern "C" {
#define DT_CONST_ZERO_OFF 22
#define DT_CONST_STACK_OFF 23
#define DT_CONST_STACK_SKIP 24
+#define DT_CONST_ERROR_PRID 25
#define DT_BPF_LOG_SIZE_DEFAULT (UINT32_MAX >> 8)
#define DT_BPF_LOG_SIZE_SMALL 4096
diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index d1ee3843..3d9a9c79 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -1076,6 +1076,9 @@ dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
nrp->dofr_data = sizeof(uint64_t)
* dtp->dt_options[DTRACEOPT_MAXFRAMES];
continue;
+ case DT_CONST_ERROR_PRID:
+ nrp->dofr_data = dtp->dt_error->desc->id;
+ continue;
case DT_CONST_BOOTTM:
if (boottime == 0 && get_boottime())
return -1;
diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
index bc883e11..1fb561ad 100644
--- a/libdtrace/dt_dlibs.c
+++ b/libdtrace/dt_dlibs.c
@@ -80,6 +80,7 @@ static const dt_ident_t dt_bpf_symbols[] = {
DT_BPF_SYMBOL_ID(STBSZ, DT_IDENT_SCALAR, DT_CONST_STBSZ),
DT_BPF_SYMBOL_ID(STRSZ, DT_IDENT_SCALAR, DT_CONST_STRSZ),
DT_BPF_SYMBOL_ID(STKSIZ, DT_IDENT_SCALAR, DT_CONST_STKSIZ),
+ DT_BPF_SYMBOL_ID(ERROR_PRID, DT_IDENT_SCALAR, DT_CONST_ERROR_PRID),
DT_BPF_SYMBOL_ID(BOOTTM, DT_IDENT_SCALAR, DT_CONST_BOOTTM),
DT_BPF_SYMBOL_ID(NSPEC, DT_IDENT_SCALAR, DT_CONST_NSPEC),
DT_BPF_SYMBOL_ID(NCPUS, DT_IDENT_SCALAR, DT_CONST_NCPUS),
diff --git a/test/unittest/builtinvar/tst.id_ERROR.d b/test/unittest/builtinvar/tst.id_ERROR.d
new file mode 100644
index 00000000..59021c60
--- /dev/null
+++ b/test/unittest/builtinvar/tst.id_ERROR.d
@@ -0,0 +1,32 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION:
+ * The id in the ERROR probe is 3.
+ *
+ * SECTION: Variables/Built-in Variables
+ */
+
+#pragma D option quiet
+
+tick-1s
+{
+ /* trigger the ERROR probe */
+ trace(*((int*)0));
+}
+
+tick-2s
+{
+ exit(1);
+}
+
+ERROR
+{
+ printf("id of the ERROR probe = %d\n", id);
+ exit(0);
+}
diff --git a/test/unittest/builtinvar/tst.id_ERROR.r b/test/unittest/builtinvar/tst.id_ERROR.r
new file mode 100644
index 00000000..95974abe
--- /dev/null
+++ b/test/unittest/builtinvar/tst.id_ERROR.r
@@ -0,0 +1,3 @@
+id of the ERROR probe = 3
+
+-- @@stderr --
diff --git a/test/unittest/builtinvar/tst.id_ERROR.r.p b/test/unittest/builtinvar/tst.id_ERROR.r.p
new file mode 100755
index 00000000..884b43f4
--- /dev/null
+++ b/test/unittest/builtinvar/tst.id_ERROR.r.p
@@ -0,0 +1,4 @@
+#!/usr/bin/gawk -f
+
+# Drop the line with run-dependent PRID for profile probe.
+!/error on enabled probe ID/ { print }
--
2.43.5
next prev parent reply other threads:[~2024-06-28 2:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 2:03 some v2 patches eugene.loh
2024-06-28 2:03 ` eugene.loh [this message]
2024-06-28 2:03 ` [PATCH v2 32/38] Widen the EPID to include the PRID eugene.loh
2024-07-20 3:58 ` [DTrace-devel] " Kris Van Hees
2024-07-20 23:26 ` Eugene Loh
2024-07-22 21:09 ` Kris Van Hees
2024-06-28 2:03 ` [PATCH v2 35/38] Use uprobes map to call clauses conditionally eugene.loh
2024-06-28 2:03 ` [PATCH v2 36/38] Simplify trampoline_is_enabled() eugene.loh
2024-06-28 2:03 ` [PATCH v2 38/38] Systemwide USDT WIP eugene.loh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240628020316.32544-2-eugene.loh@oracle.com \
--to=eugene.loh@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox