[DTrace-devel] [PATCH v2] Make DCTX_RODATA available to BPF functions
Kris Van Hees
kris.van.hees at oracle.com
Fri Jan 26 01:34:10 UTC 2024
On Thu, Dec 21, 2023 at 04:37:48PM -0500, eugene.loh at oracle.com wrote:
>
> Use DCTX_RODATA in inet_ntoa.S.
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
... though I wish we could just use ldxdw %r6, [%r6 + DCTX_RODATA] and have
a reloc for DCTX_RODATA so that the actual value can be put in during
linking. Oh well.
> ---
> bpf/inet_ntoa6.S | 12 +++---------
> libdtrace/dt_bpf.h | 9 +++++----
> libdtrace/dt_cc.c | 3 +++
> libdtrace/dt_dlibs.c | 1 +
> 4 files changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/bpf/inet_ntoa6.S b/bpf/inet_ntoa6.S
> index 24b7232d..d00acbfe 100644
> --- a/bpf/inet_ntoa6.S
> +++ b/bpf/inet_ntoa6.S
> @@ -5,14 +5,6 @@
>
> #define BPF_FUNC_probe_read 4
>
> -/*
> - * We sadly cannot include struct declarations in assembler input files, so we
> - * cannot use offsetof() to programmatically determine the offset of the rodata
> - * member in the DTrace context (dt_ctx_t). If that structure changes, the
> - * following define must be updated as well.
> - */
> -#define DCTX_RODATA 56
> -
> #define OUTPUT_LEN 40
> #define INPUT_LEN 16
>
> @@ -225,7 +217,9 @@ dt_inet_ntoa6:
> * have the code below output the address in two parts: a 7 word
> * prefix followed by a 1 word suffix.
> */
> - ldxdw %r6, [%r6 + DCTX_RODATA]
> + lddw %r1, DCTX_RODATA
> + add %r1, %r6
> + ldxdw %r6, [%r1 + 0]
> ldxw %r1, [%fp + -4] /* restore tbloff */
> lddw %r0, RODATA_SIZE
> jge %r1, %r0, .Ldone
> diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
> index bd87869e..0d96fd43 100644
> --- a/libdtrace/dt_bpf.h
> +++ b/libdtrace/dt_bpf.h
> @@ -37,10 +37,11 @@ extern "C" {
> #define DT_CONST_TASK_COMM 16
> #define DT_CONST_MUTEX_OWNER 17
> #define DT_CONST_RWLOCK_CNTS 18
> -#define DT_CONST_RODATA_OFF 19
> -#define DT_CONST_RODATA_SIZE 20
> -#define DT_CONST_ZERO_OFF 21
> -#define DT_CONST_STACK_OFF 22
> +#define DT_CONST_DCTX_RODATA 19
> +#define DT_CONST_RODATA_OFF 20
> +#define DT_CONST_RODATA_SIZE 21
> +#define DT_CONST_ZERO_OFF 22
> +#define DT_CONST_STACK_OFF 23
>
> #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 b90c42d8..f5632cba 100644
> --- a/libdtrace/dt_cc.c
> +++ b/libdtrace/dt_cc.c
> @@ -1164,6 +1164,9 @@ dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
> nrp->dofr_data = total_offset;
> continue;
> }
> + case DT_CONST_DCTX_RODATA:
> + nrp->dofr_data = DCTX_RODATA;
> + continue;
> case DT_CONST_RODATA_OFF:
> nrp->dofr_data = dtp->dt_rooffset;
> continue;
> diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
> index 54d96b89..5d82f30c 100644
> --- a/libdtrace/dt_dlibs.c
> +++ b/libdtrace/dt_dlibs.c
> @@ -91,6 +91,7 @@ static const dt_ident_t dt_bpf_symbols[] = {
> DT_BPF_SYMBOL_ID(TASK_COMM, DT_IDENT_SCALAR, DT_CONST_TASK_COMM),
> DT_BPF_SYMBOL_ID(MUTEX_OWNER, DT_IDENT_SCALAR, DT_CONST_MUTEX_OWNER),
> DT_BPF_SYMBOL_ID(RWLOCK_CNTS, DT_IDENT_SCALAR, DT_CONST_RWLOCK_CNTS),
> + DT_BPF_SYMBOL_ID(DCTX_RODATA, DT_IDENT_SCALAR, DT_CONST_DCTX_RODATA),
> DT_BPF_SYMBOL_ID(RODATA_OFF, DT_IDENT_SCALAR, DT_CONST_RODATA_OFF),
> DT_BPF_SYMBOL_ID(RODATA_SIZE, DT_IDENT_SCALAR, DT_CONST_RODATA_SIZE),
> DT_BPF_SYMBOL_ID(ZERO_OFF, DT_IDENT_SCALAR, DT_CONST_ZERO_OFF),
> --
> 2.18.4
>
>
More information about the DTrace-devel
mailing list