From: Kris Van Hees <kris.van.hees@oracle.com>
To: eugene.loh@oracle.com
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH v2 05/22] Set the ERROR PRID in BPF code
Date: Fri, 13 Sep 2024 15:50:09 -0400 [thread overview]
Message-ID: <ZuSXcRs7UMsl3EW7@oracle.com> (raw)
In-Reply-To: <20240913171535.18630-1-eugene.loh@oracle.com>
On Fri, Sep 13, 2024 at 01:15:35PM -0400, eugene.loh@oracle.com wrote:
> From: Eugene Loh <eugene.loh@oracle.com>
>
> 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.
>
> Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> 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
>
> diff --git a/bpf/probe_error.c b/bpf/probe_error.c
> index cad161fd7..1081ee71d 100644
> --- a/bpf/probe_error.c
> +++ b/bpf/probe_error.c
> @@ -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;
> diff --git a/libdtrace/dt_dctx.h b/libdtrace/dt_dctx.h
> index 633c529f3..d8232868d 100644
> --- a/libdtrace/dt_dctx.h
> +++ b/libdtrace/dt_dctx.h
> @@ -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.
> */
> diff --git a/libdtrace/dt_prov_dtrace.c b/libdtrace/dt_prov_dtrace.c
> index bf87cb054..9f0d72b78 100644
> --- a/libdtrace/dt_prov_dtrace.c
> +++ b/libdtrace/dt_prov_dtrace.c
> @@ -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;
> diff --git a/test/unittest/builtinvar/tst.id_ERROR.r b/test/unittest/builtinvar/tst.id_ERROR.r
> new file mode 100644
> index 000000000..2e9ba477f
> --- /dev/null
> +++ b/test/unittest/builtinvar/tst.id_ERROR.r
> @@ -0,0 +1 @@
> +success
> diff --git a/test/unittest/builtinvar/tst.id_ERROR.sh b/test/unittest/builtinvar/tst.id_ERROR.sh
> new file mode 100755
> index 000000000..082ebd0c4
> --- /dev/null
> +++ b/test/unittest/builtinvar/tst.id_ERROR.sh
> @@ -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
> --
> 2.43.5
>
prev parent reply other threads:[~2024-09-13 19:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-13 17:15 [PATCH v2 05/22] Set the ERROR PRID in BPF code eugene.loh
2024-09-13 19:50 ` Kris Van Hees [this message]
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=ZuSXcRs7UMsl3EW7@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=eugene.loh@oracle.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.