Skip to contentSkip to conversation

Set the ERROR PRID in BPF code

PATCH In review [email protected] 2 participants 2 messages Sep 13, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 5/22 Set the ERROR PRID in BPF code

From: Eugene Loh <[email protected]>

There are multiple options for how to set this value. One is to hardwire it to 3, its expected value. Another is to set the value during relocation. Here, we choose a middle ground: we define the value symbolically (to 3) and also check that value.

---
 bpf/probe_error.c                        |  3 ++
 libdtrace/dt_dctx.h                      |  7 ++++
 libdtrace/dt_prov_dtrace.c               |  3 ++
 test/unittest/builtinvar/tst.id_ERROR.r  |  1 +
 test/unittest/builtinvar/tst.id_ERROR.sh | 52 ++++++++++++++++++++++++
 5 files changed, 66 insertions(+)
 create mode 100644 test/unittest/builtinvar/tst.id_ERROR.r
 create mode 100755 test/unittest/builtinvar/tst.id_ERROR.sh
bpf/probe_error.c +3 -0
index cad161fd7..1081ee71d 100644
@@ -26,6 +26,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;
 
 	__builtin_memcpy(mst->saved_argv, mst->argv, sizeof(mst->saved_argv));
 	mst->argv[0] = 0;
@@ -35,7 +36,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 = DTRACE_ERROR_ID;
 	dt_error(dctx);
+	mst->prid = oldprid;
 
 	__builtin_memcpy(mst->argv, mst->saved_argv, sizeof(mst->saved_argv));
 	mst->fault = fault;
libdtrace/dt_dctx.h +7 -0
index 633c529f3..d8232868d 100644
@@ -14,6 +14,13 @@
 #include <dt_pt_regs.h>
 #include <dt_state.h>
 
+/*
+ * Static probe IDs for the dtrace provider.
+ */
+#define DTRACE_BEGIN_ID		1
+#define DTRACE_END_ID		2
+#define DTRACE_ERROR_ID		3
+
 /*
  * The DTrace machine state.
  */
libdtrace/dt_prov_dtrace.c +3 -0
index bf87cb054..9f0d72b78 100644
@@ -45,18 +45,21 @@ static int populate(dtrace_hdl_t *dtp)
 
 	prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "BEGIN");
 	if (prp) {
+		assert(prp->desc->id == DTRACE_BEGIN_ID);
 		n++;
 		dt_probe_enable(dtp, prp);
 	}
 
 	prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "END");
 	if (prp) {
+		assert(prp->desc->id == DTRACE_END_ID);
 		n++;
 		dt_probe_enable(dtp, prp);
 	}
 
 	prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "ERROR");
 	if (prp) {
+		assert(prp->desc->id == DTRACE_ERROR_ID);
 		n++;
 		dt_probe_enable(dtp, prp);
 		dtp->dt_error = prp;
test/unittest/builtinvar/tst.id_ERROR.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/builtinvar/tst.id_ERROR.sh new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.43.5
Reviewed-by on v2 5/22
#1 lore raw
Quoted 8 lines · On Fri, Sep 13, 2024 at 01:15:35PM -0400, [email protected] wrote:

From: Eugene Loh <[email protected]>

There are multiple options for how to set this value. One is to hardwire it to 3, its expected value. Another is to set the value during relocation. Here, we choose a middle ground: we define the value symbolically (to 3) and also check that value.

Quoted 144 lines
---
 bpf/probe_error.c                        |  3 ++
 libdtrace/dt_dctx.h                      |  7 ++++
 libdtrace/dt_prov_dtrace.c               |  3 ++
 test/unittest/builtinvar/tst.id_ERROR.r  |  1 +
 test/unittest/builtinvar/tst.id_ERROR.sh | 52 ++++++++++++++++++++++++
 5 files changed, 66 insertions(+)
 create mode 100644 test/unittest/builtinvar/tst.id_ERROR.r
 create mode 100755 test/unittest/builtinvar/tst.id_ERROR.sh
bpf/probe_error.c +3 -0
index cad161fd7..1081ee71d 100644
@@ -26,6 +26,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;
 
 	__builtin_memcpy(mst->saved_argv, mst->argv, sizeof(mst->saved_argv));
 	mst->argv[0] = 0;
@@ -35,7 +36,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 = DTRACE_ERROR_ID;
 	dt_error(dctx);
+	mst->prid = oldprid;
 
 	__builtin_memcpy(mst->argv, mst->saved_argv, sizeof(mst->saved_argv));
 	mst->fault = fault;
libdtrace/dt_dctx.h +7 -0
index 633c529f3..d8232868d 100644
@@ -14,6 +14,13 @@
 #include <dt_pt_regs.h>
 #include <dt_state.h>
 
+/*
+ * Static probe IDs for the dtrace provider.
+ */
+#define DTRACE_BEGIN_ID		1
+#define DTRACE_END_ID		2
+#define DTRACE_ERROR_ID		3
+
 /*
  * The DTrace machine state.
  */
libdtrace/dt_prov_dtrace.c +3 -0
index bf87cb054..9f0d72b78 100644
@@ -45,18 +45,21 @@ static int populate(dtrace_hdl_t *dtp)
 
 	prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "BEGIN");
 	if (prp) {
+		assert(prp->desc->id == DTRACE_BEGIN_ID);
 		n++;
 		dt_probe_enable(dtp, prp);
 	}
 
 	prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "END");
 	if (prp) {
+		assert(prp->desc->id == DTRACE_END_ID);
 		n++;
 		dt_probe_enable(dtp, prp);
 	}
 
 	prp = dt_tp_probe_insert(dtp, prv, prvname, modname, funname, "ERROR");
 	if (prp) {
+		assert(prp->desc->id == DTRACE_ERROR_ID);
 		n++;
 		dt_probe_enable(dtp, prp);
 		dtp->dt_error = prp;
test/unittest/builtinvar/tst.id_ERROR.r new file +1 -0
new file mode 100644
index 000000000..2e9ba477f
@@ -0,0 +1 @@
+success
test/unittest/builtinvar/tst.id_ERROR.sh new file +52 -0
new file mode 100755
index 000000000..082ebd0c4
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# 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.
+#
+
+dtrace=$1
+
+DIRNAME="$tmpdir/builtinvar-id_ERROR.$$.$RANDOM"
+mkdir -p $DIRNAME
+cd $DIRNAME
+
+# Have a D script report the probe ID within an ERROR probe.
+
+$dtrace $dt_flags -qn '
+BEGIN { *((int*)0) }
+BEGIN { exit(1) }
+ERROR { printf("ERROR probe id is %d\n", id); exit(0); }
+' -o D.out 2> D.err
+if [ $? -ne 0 ]; then
+    echo DTrace failed
+    echo ==== D.out
+    cat D.out
+    echo ==== D.err
+    cat D.err
+    exit 1
+fi
+
+# Get the ERROR probe ID from "dtrace -l" output.
+
+id=`$dtrace $dt_flags -ln dtrace:::ERROR |& awk '/^ *[0-9]* *dtrace *ERROR *$/ { print $1 }'`
+
+# Construct expected output.
+
+echo "ERROR probe id is $id" > D.out.chk
+echo >> D.out.chk
+
+# Check output.
+
+if ! diff -q D.out D.out.chk; then
+    echo output mismatches
+    echo ==== D.out
+    cat D.out
+    echo ==== D.out.chk
+    cat D.out.chk
+    exit 1
+fi
+
+echo success
+exit 0
Signature · 1 line
2.43.5